Skip to content

Commit f0b53ac

Browse files
committed
Patch: Use primary monitor
Added option to use primary monitor instead root screen to determine where to place notifications. This adds an Xrandr dependency. Closes: 20
1 parent a773e56 commit f0b53ac

3 files changed

Lines changed: 21 additions & 5 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ config.h: config.def.h
99
cp config.def.h config.h
1010

1111
herbe: herbe.c config.h
12-
$(CC) herbe.c $(CFLAGS) -o herbe
12+
$(CC) herbe.c $(CFLAGS) -o herbe -lXrandr
1313

1414
install: herbe
1515
mkdir -p ${DESTDIR}${PREFIX}/bin

config.def.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ static const char *font_color = "#ececec";
44
static const char *font_pattern = "monospace:size=10";
55
static const unsigned line_spacing = 5;
66
static const unsigned int padding = 15;
7+
static const int use_primary_monitor = 0;
78

89
static const unsigned int width = 450;
910
static const unsigned int border_size = 2;

herbe.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <X11/Xlib.h>
22
#include <X11/Xft/Xft.h>
3+
#include <X11/extensions/Xrandr.h>
34
#include <stdio.h>
45
#include <stdlib.h>
56
#include <signal.h>
@@ -111,8 +112,22 @@ int main(int argc, char *argv[])
111112
Visual *visual = DefaultVisual(display, screen);
112113
Colormap colormap = DefaultColormap(display, screen);
113114

115+
int screen_x = 0;
116+
int screen_y = 0;
114117
int screen_width = DisplayWidth(display, screen);
115118
int screen_height = DisplayHeight(display, screen);
119+
if(use_primary_monitor) {
120+
int nMonitors;
121+
XRRMonitorInfo* info = XRRGetMonitors(display, RootWindow(display, screen), 1, &nMonitors);
122+
for(int i = 0; i < nMonitors; i++) {
123+
if(info[i].primary) {
124+
screen_x = info[i].x;
125+
screen_y = info[i].y;
126+
screen_width = info[i].width;
127+
screen_height = info[i].height;
128+
}
129+
}
130+
}
116131

117132
XSetWindowAttributes attributes;
118133
attributes.override_redirect = True;
@@ -151,16 +166,16 @@ int main(int argc, char *argv[])
151166
}
152167
}
153168

154-
unsigned int x = pos_x;
155-
unsigned int y = pos_y;
169+
unsigned int x = screen_x + pos_x;
170+
unsigned int y = screen_y + pos_y;
156171
unsigned int text_height = font->ascent - font->descent;
157172
unsigned int height = (num_of_lines - 1) * line_spacing + num_of_lines * text_height + 2 * padding;
158173

159174
if (corner == TOP_RIGHT || corner == BOTTOM_RIGHT)
160-
x = screen_width - width - border_size * 2 - pos_x;
175+
x = screen_x + screen_width - width - border_size * 2 - pos_x;
161176

162177
if (corner == BOTTOM_LEFT || corner == BOTTOM_RIGHT)
163-
y = screen_height - height - border_size * 2 - pos_y;
178+
y = screen_y + screen_height - height - border_size * 2 - pos_y;
164179

165180
window = XCreateWindow(display, RootWindow(display, screen), x, y, width, height, border_size, DefaultDepth(display, screen),
166181
CopyFromParent, visual, CWOverrideRedirect | CWBackPixel | CWBorderPixel, &attributes);

0 commit comments

Comments
 (0)