diff options
Diffstat (limited to 'src/tsar.c')
| -rw-r--r-- | src/tsar.c | 34 |
1 files changed, 23 insertions, 11 deletions
@@ -9,15 +9,15 @@ #include <X11/Xlib.h> #include "pipe.h" +#include "bardata.h" Display* display; Window win; GC gc; -XftFont* font; +XftFont* font = NULL; XftColor fg_color; -static int height = 17; static int width = 1000; static float width_ratio = 1; @@ -34,7 +34,17 @@ void die(const char* fmt, ...) { exit(err_code); } -void draw_bar(void) { +void load_font(const char* font_name) { + XftFont* new_font = XftFontOpenName(display, DefaultScreen(display), font_name); + if (new_font == NULL) { + fprintf(stderr, "cannot open font %s\n", font_name); + return; + } + + if (font != NULL) { + XftFontClose(display, font); + } + font = new_font; } void init_x(void) { @@ -56,7 +66,7 @@ void init_x(void) { display, DefaultRootWindow(display), 0, 0, - width, height, + width, bar_height, 0, CopyFromParent, InputOutput, @@ -67,11 +77,7 @@ void init_x(void) { XMapRaised(display, win); - gc = XCreateGC(display, win, 0, NULL); - XSetForeground(display, gc, 0xFFFFFF); - - const char font_name[] = "CommitMono:style=Regular:antialias=true"; - font = XftFontOpenName(display, DefaultScreen(display), font_name); + load_font("monospace:size=10"); XftColorAllocName( display, @@ -81,6 +87,9 @@ void init_x(void) { &fg_color ); + gc = XCreateGC(display, win, 0, NULL); + XSetForeground(display, gc, 0xFFFFFF); + XFlush(display); } @@ -98,7 +107,7 @@ void draw_text(const char* text, int x, int y) { DefaultColormap(display, DefaultScreen(display)) ); - int dy = y + (height - font->height) / 2 + font->ascent; + int dy = y + (bar_height - font->height) / 2 + font->ascent; XftDrawString8(xft_draw, &fg_color, font, x, dy, (const FcChar8*)text, strlen(text)); XftDrawDestroy(xft_draw); @@ -110,10 +119,13 @@ int main(void) { while (true) { XEvent ev; - XNextEvent(display, &ev); + while (XPending(display)) + XNextEvent(display, &ev); XClearWindow(display, win); + XResizeWindow(display, win, width, bar_height); + draw_text("Hello, world!", 0, 0); XFlush(display); |
