From 842bc7d3cec5ac5584288b6d30214a051dc3e8d1 Mon Sep 17 00:00:00 2001 From: Martin Duquesnoy Date: Wed, 24 Mar 2010 18:03:17 +0100 Subject: [PATCH] Infobar: Add selbar; title of selected client in infobar (Feature #31 requested by markand), conf: [bar] selbar = true/false --- src/barwin.c | 3 +++ src/client.c | 11 +++++++++-- src/config.c | 1 + src/draw.c | 3 +++ src/infobar.c | 38 ++++++++++++++++++++++++++++++++++++++ src/structs.h | 3 ++- src/wmfs.h | 1 + wmfsrc.in | 1 + 8 files changed, 58 insertions(+), 3 deletions(-) diff --git a/src/barwin.c b/src/barwin.c index 7143997..dba47f5 100644 --- a/src/barwin.c +++ b/src/barwin.c @@ -107,6 +107,9 @@ barwin_create(Window parent, void barwin_draw_text(BarWindow *bw, int x, int y, char *text) { + if(!text) + return; + /* Background color of the text if there is stipple */ if(bw->stipple) draw_rectangle(bw->dr, x - 4, 0, textw(text) + 8, bw->geo.height, bw->bg); diff --git a/src/client.c b/src/client.c index 21ce5c9..61e0d08 100644 --- a/src/client.c +++ b/src/client.c @@ -57,8 +57,8 @@ client_configure(Client *c) ev.type = ConfigureNotify; ev.event = c->win; ev.window = c->win; - ev.x = c->geo.x; - ev.y = c->geo.y; + ev.x = spgeo[c->screen].x + c->geo.x; + ev.y = spgeo[c->screen].y + c->geo.y; ev.width = c->geo.width; ev.height = c->geo.height; ev.above = None; @@ -270,9 +270,16 @@ client_focus(Client *c) client_above(sel); XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime); + + if(conf.bars.selbar) + infobar_draw_selbar(sel->screen); } else + { XSetInputFocus(dpy, ROOT, RevertToPointerRoot, CurrentTime); + if(conf.bars.selbar) + infobar_draw_selbar(selscreen); + } return; } diff --git a/src/config.c b/src/config.c index 871c32c..6fe9391 100644 --- a/src/config.c +++ b/src/config.c @@ -174,6 +174,7 @@ conf_bar_section(char *src) conf.bars.height = get_opt(src, "-1", "height").num; conf.colors.bar = getcolor(get_opt(src, "#000000", "bg").str); conf.colors.text = get_opt(src, "#ffffff", "fg").str; + conf.bars.selbar = get_opt(src, "false", "selbar").bool; if((conf.bars.nmouse = get_size_sec(src, "mouse"))) { diff --git a/src/draw.c b/src/draw.c index 9252227..30fa14e 100644 --- a/src/draw.c +++ b/src/draw.c @@ -46,6 +46,9 @@ draw_text(Drawable d, int x, int y, char* fg, int pad, char *str) XftColor xftcolor; XftDraw *xftd; + if(!str) + return; + /* Transform X Drawable -> Xft Drawable */ xftd = XftDrawCreate(dpy, d, DefaultVisual(dpy, SCREEN), DefaultColormap(dpy, SCREEN)); diff --git a/src/infobar.c b/src/infobar.c index 649bddc..393f276 100644 --- a/src/infobar.c +++ b/src/infobar.c @@ -100,6 +100,16 @@ infobar_init(void) conf.colors.layout_bg, conf.colors.layout_fg, False, False, conf.border.layout); + /* Selbar */ + if(conf.bars.selbar) + infobar[sc].selbar = barwin_create(infobar[sc].bar->win, + ((conf.layout_placement) + ? (j + PAD / 2) + : infobar[sc].layout_button->geo.x + infobar[sc].layout_button->geo.width + PAD / 2), 1, + (sel) ? textw(sel->title) + PAD : 1, + infobar[sc].geo.height - 2, + conf.colors.bar, conf.colors.text, False, False, False); + /* Map/Refresh all */ barwin_map(infobar[sc].bar); barwin_map_subwin(infobar[sc].bar); @@ -110,12 +120,16 @@ infobar_init(void) if(conf.border.layout) barwin_map_subwin(infobar[sc].layout_button); + if(conf.bars.selbar) + barwin_map(infobar[sc].selbar); + barwin_refresh_color(infobar[sc].bar); barwin_refresh(infobar[sc].bar); /* Default statustext is set here */ for(i = 0; i < s; ++i) infobar[i].statustext = _strdup(WMFS_VERSION); + infobar_draw(sc); } @@ -130,6 +144,7 @@ infobar_draw(int sc) { infobar_draw_taglist(sc); infobar_draw_layout(sc); + infobar_draw_selbar(sc); barwin_refresh_color(infobar[sc].bar); statustext_handle(sc, infobar[sc].statustext); @@ -151,6 +166,29 @@ infobar_draw_layout(int sc) return; } +/** Draw Selbar (selected client title bar in infobar + *\param sc Screen Number + */ +void +infobar_draw_selbar(int sc) +{ + if(!conf.bars.selbar) + return; + + barwin_move(infobar[sc].selbar, + ((conf.layout_placement) + ? (infobar[sc].tags_board->geo.x + infobar[sc].tags_board->geo.width + PAD / 2) + : (infobar[sc].layout_button->geo.x + infobar[sc].layout_button->geo.width + PAD / 2)), 1); + + barwin_resize(infobar[sc].selbar, textw(sel ? sel->title : NULL) + PAD, infobar[sc].geo.height - 2); + barwin_refresh_color(infobar[sc].selbar); + barwin_draw_text(infobar[sc].selbar, PAD / 2, FHINFOBAR - 1, (sel) ? sel->title : NULL); + + barwin_refresh(infobar[sc].selbar); + + return; +} + /** Draw the taglist in the InfoBar *\param sc Screen number */ diff --git a/src/structs.h b/src/structs.h index 58462a2..70e01a1 100644 --- a/src/structs.h +++ b/src/structs.h @@ -226,7 +226,7 @@ typedef struct /* InfoBar Struct */ typedef struct { - BarWindow *bar; + BarWindow *bar, *selbar; BarWindow *layout_button; BarWindow *tags_board, *tags[MAXTAG]; XRectangle geo; @@ -345,6 +345,7 @@ typedef struct int height; MouseBinding *mouse; int nmouse; + Bool selbar; } bars; struct { diff --git a/src/wmfs.h b/src/wmfs.h index 95e8914..252000e 100644 --- a/src/wmfs.h +++ b/src/wmfs.h @@ -133,6 +133,7 @@ ushort textw(const char *text); void infobar_init(void); void infobar_draw(int sc); void infobar_draw_layout(int sc); +void infobar_draw_selbar(int sc); void infobar_draw_taglist(int sc); void infobar_destroy(void); void infobar_set_position(int pos); diff --git a/wmfsrc.in b/wmfsrc.in index 71bcce5..23f90fc 100644 --- a/wmfsrc.in +++ b/wmfsrc.in @@ -14,6 +14,7 @@ bg = "#191919" fg = "#D4D4D4" border = true + selbar = false [/bar] [layouts]