Skip to content

Commit db36375

Browse files
author
Owen McGrath
committed
Add option to use primary monitor intead of root…
screen dimensions, with Xresources support Modified from dudik#21 such that it applies on top of dudik#11 and use_primary_montior can be taken from xrdb
1 parent 078e168 commit db36375

3 files changed

Lines changed: 22 additions & 5 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CFLAGS = -Wall -Wextra -pedantic -lX11 -lXft -I/usr/include/freetype2 -pthread
1+
CFLAGS = -Wall -Wextra -pedantic -lX11 -lXft -lXrandr -I/usr/include/freetype2 -pthread
22

33
PREFIX ?= /usr/local
44
CC ?= cc

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 unsigned line_spacing = 5;
66
static unsigned int padding = 15;
7+
static int use_primary_monitor = 0;
78

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

herbe.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <X11/Xlib.h>
22
#include <X11/Xft/Xft.h>
33
#include <X11/Xresource.h>
4+
#include <X11/extensions/Xrandr.h>
45
#include <stdio.h>
56
#include <stdlib.h>
67
#include <signal.h>
@@ -136,13 +137,28 @@ int main(int argc, char *argv[])
136137
XRES_INT(pos_y);
137138
XRES_INT(corner);
138139
XRES_INT(duration);
140+
XRES_INT(use_primary_monitor);
139141

140142
int screen = DefaultScreen(display);
141143
Visual *visual = DefaultVisual(display, screen);
142144
Colormap colormap = DefaultColormap(display, screen);
143145

146+
int screen_x = 0;
147+
int screen_y = 0;
144148
int screen_width = DisplayWidth(display, screen);
145149
int screen_height = DisplayHeight(display, screen);
150+
if (use_primary_monitor) {
151+
int nMonitors;
152+
XRRMonitorInfo *info = XRRGetMonitors(display, RootWindow(display, screen), 1, &nMonitors);
153+
for (int i = 0; i < nMonitors; i++) {
154+
if (info[i].primary) {
155+
screen_x = info[i].x;
156+
screen_y = info[i].y;
157+
screen_width = info[i].width;
158+
screen_height = info[i].height;
159+
}
160+
}
161+
}
146162

147163
XSetWindowAttributes attributes;
148164
attributes.override_redirect = True;
@@ -181,16 +197,16 @@ int main(int argc, char *argv[])
181197
}
182198
}
183199

184-
unsigned int x = pos_x;
185-
unsigned int y = pos_y;
200+
unsigned int x = screen_x + pos_x;
201+
unsigned int y = screen_y + pos_y;
186202
unsigned int text_height = font->ascent - font->descent;
187203
unsigned int height = (num_of_lines - 1) * line_spacing + num_of_lines * text_height + 2 * padding;
188204

189205
if (corner == TOP_RIGHT || corner == BOTTOM_RIGHT)
190-
x = screen_width - width - border_size * 2 - pos_x;
206+
x = screen_x + screen_width - width - border_size * 2 - pos_x;
191207

192208
if (corner == BOTTOM_LEFT || corner == BOTTOM_RIGHT)
193-
y = screen_height - height - border_size * 2 - pos_y;
209+
y = screen_y + screen_height - height - border_size * 2 - pos_y;
194210

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

0 commit comments

Comments
 (0)