From f3298400e6704844aeb1d3e0951e84b4236d2302 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bert=20M=C3=BCnnich?= Date: Mon, 11 Feb 2013 23:05:26 +0100 Subject: Spawn and read from info script without blocking --- window.c | 59 ++++++++++++++++++++++++++++++----------------------------- 1 file changed, 30 insertions(+), 29 deletions(-) (limited to 'window.c') diff --git a/window.c b/window.c index 0b1ce65..a51499e 100644 --- a/window.c +++ b/window.c @@ -414,31 +414,28 @@ void win_draw_bar(win_t *win) XSetForeground(e->dpy, gc, win->bar.fgcol); XSetBackground(e->dpy, gc, win->bar.bgcol); - if (win->bar.r != NULL) { - len = strlen(win->bar.r); - if (len > 0) { - if ((tw = win_textwidth(win->bar.r, len, true)) > w) - return; - x = win->w - tw + H_TEXT_PAD; - w -= tw; - if (font.set) - XmbDrawString(e->dpy, win->pm, font.set, gc, x, y, win->bar.r, len); - else - XDrawString(e->dpy, win->pm, gc, x, y, win->bar.r, len); - } + if ((len = strlen(win->bar.r)) > 0) { + if ((tw = win_textwidth(win->bar.r, len, true)) > w) + return; + x = win->w - tw + H_TEXT_PAD; + w -= tw; + if (font.set) + XmbDrawString(e->dpy, win->pm, font.set, gc, x, y, win->bar.r, len); + else + XDrawString(e->dpy, win->pm, gc, x, y, win->bar.r, len); } - if (win->bar.l != NULL) { - olen = len = strlen(win->bar.l); + if ((len = strlen(win->bar.l)) > 0) { + olen = len; while (len > 0 && (tw = win_textwidth(win->bar.l, len, true)) > w) len--; if (len > 0) { - if (len != olen) { - w = strlen(dots); - if (len <= w) - return; - memcpy(rest, win->bar.l + len - w, w); - memcpy(win->bar.l + len - w, dots, w); - } + if (len != olen) { + w = strlen(dots); + if (len <= w) + return; + memcpy(rest, win->bar.l + len - w, w); + memcpy(win->bar.l + len - w, dots, w); + } x = H_TEXT_PAD; if (font.set) XmbDrawString(e->dpy, win->pm, font.set, gc, x, y, win->bar.l, len); @@ -480,6 +477,18 @@ void win_draw_rect(win_t *win, Pixmap pm, int x, int y, int w, int h, XDrawRectangle(win->env.dpy, pm, gc, x, y, w, h); } +void win_update_bar(win_t *win) +{ + if (win == NULL || win->xwin == None || win->pm == None) + return; + + if (win->bar.h > 0) { + win_draw_bar(win); + XCopyArea(win->env.dpy, win->pm, win->xwin, gc, + 0, win->h, win->w, win->bar.h, 0, win->h); + } +} + int win_textwidth(const char *text, unsigned int len, bool with_padding) { XRectangle r; @@ -514,14 +523,6 @@ void win_set_title(win_t *win, const char *title) PropModeReplace, (unsigned char *) title, strlen(title)); } -void win_set_bar_info(win_t *win, char *linfo, char *rinfo) -{ - if (win != NULL) { - win->bar.l = linfo; - win->bar.r = rinfo; - } -} - void win_set_cursor(win_t *win, cursor_t cursor) { if (win == NULL || win->xwin == None) -- cgit v1.2.3 From 30802cec0f233aa9977256684cb749df6c7e28c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bert=20M=C3=BCnnich?= Date: Tue, 12 Feb 2013 17:55:47 +0100 Subject: Spawn info script & update bar contents only when needed --- window.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'window.c') diff --git a/window.c b/window.c index a51499e..30081de 100644 --- a/window.c +++ b/window.c @@ -119,12 +119,15 @@ void win_init(win_t *win) e->cmap = DefaultColormap(e->dpy, e->scr); e->depth = DefaultDepth(e->dpy, e->scr); + win_init_font(e->dpy, BAR_FONT); + win->white = WhitePixel(e->dpy, e->scr); win->bgcol = win_alloc_color(win, WIN_BG_COLOR); win->fscol = win_alloc_color(win, WIN_FS_COLOR); win->selcol = win_alloc_color(win, SEL_COLOR); win->bar.bgcol = win_alloc_color(win, BAR_BG_COLOR); win->bar.fgcol = win_alloc_color(win, BAR_FG_COLOR); + win->bar.h = options->hide_bar ? 0 : barheight; win->sizehints.flags = PWinGravity; win->sizehints.win_gravity = NorthWestGravity; @@ -135,8 +138,6 @@ void win_init(win_t *win) if (setlocale(LC_CTYPE, "") == NULL || XSupportsLocale() == 0) warn("no locale support"); - win_init_font(e->dpy, BAR_FONT); - wm_delete_win = XInternAtom(e->dpy, "WM_DELETE_WINDOW", False); } -- cgit v1.2.3