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 #include +#include #include #include #include @@ -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);