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 @@ -8,7 +8,7 @@ all: herbe
config.h: config.def.h
cp config.def.h config.h

herbe: herbe.c config.h
herbe: herbe.c config.h Makefile
$(CC) herbe.c $(CFLAGS) -o herbe

install: herbe
Expand Down
24 changes: 16 additions & 8 deletions herbe.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
#define EXIT_FAIL 1
#define EXIT_DISMISS 2

Display *display;
Window window;
int exit_code = EXIT_DISMISS;
static Display *display;
static Window window;
static int exit_code = EXIT_DISMISS;

static void die(const char *format, ...)
{
Expand All @@ -29,7 +29,7 @@ static void die(const char *format, ...)
exit(EXIT_FAIL);
}

int get_max_len(char *string, XftFont *font, int max_text_width)
static int get_max_len(char *string, XftFont *font, int max_text_width)
{
int eol = strlen(string);
XGlyphInfo info;
Expand Down Expand Up @@ -70,7 +70,7 @@ int get_max_len(char *string, XftFont *font, int max_text_width)
return ++eol;
}

void expire(int sig)
static void expire(int sig)
{
XEvent event;
event.type = ButtonPress;
Expand Down Expand Up @@ -117,9 +117,11 @@ int main(int argc, char *argv[])
XSetWindowAttributes attributes;
attributes.override_redirect = True;
XftColor color;
XftColorAllocName(display, visual, colormap, background_color, &color);
if (!XftColorAllocName(display, visual, colormap, background_color, &color))
die("Failed to allocate background color");
attributes.background_pixel = color.pixel;
XftColorAllocName(display, visual, colormap, border_color, &color);
if (!XftColorAllocName(display, visual, colormap, border_color, &color))
die("Failed to allocate border color");
attributes.border_pixel = color.pixel;

int num_of_lines = 0;
Expand All @@ -130,6 +132,8 @@ int main(int argc, char *argv[])
die("malloc failed");

XftFont *font = XftFontOpenName(display, screen, font_pattern);
if (!font)
die("Couldn't open font");

for (int i = 1; i < argc; i++)
{
Expand Down Expand Up @@ -166,12 +170,16 @@ int main(int argc, char *argv[])
CopyFromParent, visual, CWOverrideRedirect | CWBackPixel | CWBorderPixel, &attributes);

XftDraw *draw = XftDrawCreate(display, window, visual, colormap);
if (!draw)
die("Failed to create Xft drawable object");
XftColorAllocName(display, visual, colormap, font_color, &color);

XSelectInput(display, window, ExposureMask | ButtonPress);
XMapWindow(display, window);

sem_t *mutex = sem_open("/herbe", O_CREAT, 0644, 1);
if (mutex == SEM_FAILED)
die("Failed to open semaphore");
sem_wait(mutex);

sigaction(SIGUSR1, &act_expire, 0);
Expand Down Expand Up @@ -217,4 +225,4 @@ int main(int argc, char *argv[])
XCloseDisplay(display);

return exit_code;
}
}