aboutsummaryrefslogtreecommitdiffstats
path: root/applied/21.diff
blob: 412c03412c8ca2f9de79faf9cf255d2cdac5a77d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
diff --git a/Makefile b/Makefile
index 3225e36..55509cf 100644
--- a/Makefile
+++ b/Makefile
@@ -9,7 +9,7 @@ config.h: config.def.h
 	cp config.def.h config.h
 
 herbe: herbe.c config.h
-	$(CC) herbe.c $(CFLAGS) -o herbe
+	$(CC) herbe.c $(CFLAGS) -o herbe -lXrandr
 
 install: herbe
 	mkdir -p ${DESTDIR}${PREFIX}/bin
diff --git a/config.def.h b/config.def.h
index 86b7e76..f8bf499 100644
--- a/config.def.h
+++ b/config.def.h
@@ -4,6 +4,7 @@ static const char *font_color = "#ececec";
 static const char *font_pattern = "monospace:size=10";
 static const unsigned line_spacing = 5;
 static const unsigned int padding = 15;
+static const int use_primary_monitor = 0;
 
 static const unsigned int width = 450;
 static const unsigned int border_size = 2;
diff --git a/herbe.c b/herbe.c
index 51d3990..a2277f0 100644
--- a/herbe.c
+++ b/herbe.c
@@ -1,5 +1,6 @@
 #include <X11/Xlib.h>
 #include <X11/Xft/Xft.h>
+#include <X11/extensions/Xrandr.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <signal.h>
@@ -111,8 +112,22 @@ int main(int argc, char *argv[])
 	Visual *visual = DefaultVisual(display, screen);
 	Colormap colormap = DefaultColormap(display, screen);
 
+	int screen_x = 0;
+	int screen_y = 0;
 	int screen_width = DisplayWidth(display, screen);
 	int screen_height = DisplayHeight(display, screen);
+	if(use_primary_monitor) {
+		int nMonitors;
+		XRRMonitorInfo* info = XRRGetMonitors(display, RootWindow(display, screen), 1, &nMonitors);
+		for(int i = 0; i < nMonitors; i++) {
+			if(info[i].primary) {
+				screen_x = info[i].x;
+				screen_y = info[i].y;
+				screen_width = info[i].width;
+				screen_height = info[i].height;
+			}
+		}
+	}
 
 	XSetWindowAttributes attributes;
 	attributes.override_redirect = True;
@@ -151,16 +166,16 @@ int main(int argc, char *argv[])
 		}
 	}
 
-	unsigned int x = pos_x;
-	unsigned int y = pos_y;
+	unsigned int x = screen_x + pos_x;
+	unsigned int y = screen_y + pos_y;
 	unsigned int text_height = font->ascent - font->descent;
 	unsigned int height = (num_of_lines - 1) * line_spacing + num_of_lines * text_height + 2 * padding;
 
 	if (corner == TOP_RIGHT || corner == BOTTOM_RIGHT)
-		x = screen_width - width - border_size * 2 - pos_x;
+		x = screen_x + screen_width - width - border_size * 2 - pos_x;
 
 	if (corner == BOTTOM_LEFT || corner == BOTTOM_RIGHT)
-		y = screen_height - height - border_size * 2 - pos_y;
+		y = screen_y + screen_height - height - border_size * 2 - pos_y;
 
 	window = XCreateWindow(display, RootWindow(display, screen), x, y, width, height, border_size, DefaultDepth(display, screen),
 						   CopyFromParent, visual, CWOverrideRedirect | CWBackPixel | CWBorderPixel, &attributes);