Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions config.def.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
23 changes: 19 additions & 4 deletions herbe.c
Original file line number Diff line number Diff line change
@@ -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>
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down