From f3298400e6704844aeb1d3e0951e84b4236d2302 Mon Sep 17 00:00:00 2001 From: Bert Münnich 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-54-g00ecf