From dece4e7c7c4666d5b274062d45045932c493804c Mon Sep 17 00:00:00 2001 From: Martin Duquesnoy Date: Wed, 5 Nov 2008 19:59:56 +0100 Subject: [PATCH] infobar: Add infobar.c and rename all infobar function --- CMakeLists.txt | 3 +- src/bar.c | 57 --------------------------------- src/config.c | 38 +++++++++++----------- src/draw.c | 85 -------------------------------------------------- src/event.c | 4 +-- src/layout.c | 2 +- src/wmfs.c | 4 +-- src/wmfs.h | 10 +++--- wmfsrc | 2 +- 9 files changed, 33 insertions(+), 172 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 77ac3da..5a6a5cf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,7 +36,8 @@ set(wmfs_src src/bar.c src/draw.c src/client.c - src/titlebar.c) + src/titlebar.c + src/infobar.c) # Set the executable from the wmfs_src add_executable(wmfs ${wmfs_src}) diff --git a/src/bar.c b/src/bar.c index 21690e9..aa91398 100644 --- a/src/bar.c +++ b/src/bar.c @@ -135,60 +135,3 @@ bar_refresh(BarWindow *bw) return; } - -/* Top/Bottom Bar Manage Function */ -void -updatebar(void) -{ - char buf[256]; - - /* Refresh bar color */ - bar_refresh_color(infobar.bar); - - /* Draw taglist */ - draw_taglist(infobar.bar->dr); - - /* Draw layout symbol */ - draw_layout(); - - /* Draw mwfact && nmaster info */ - sprintf(buf, "mwfact: %.2f - nmaster: %d", - tags[seltag].mwfact, - tags[seltag].nmaster); - draw_text(infobar.bar->dr, infobar.lastsep + PAD/1.5, fonth, conf.colors.text, conf.colors.bar, 0, buf); - draw_rectangle(infobar.bar->dr, textw(buf) + infobar.lastsep + PAD, - 0, conf.tagbordwidth, infobar.geo.height, conf.colors.tagbord); - - /* Draw status text */ - draw_text(infobar.bar->dr, mw - textw(infobar.statustext), fonth, conf.colors.text, conf.colors.bar, 0, infobar.statustext); - - /* Bar border */ - if(conf.tagbordwidth) - { - draw_rectangle(infobar.bar->dr, 0, ((conf.bartop) ? infobar.geo.height - 1: 0), - mw, 1, conf.colors.tagbord); - draw_rectangle(infobar.bar->dr, mw - textw(infobar.statustext) - 5, - 0, conf.tagbordwidth, infobar.geo.height, conf.colors.tagbord); - } - - /* Refresh the bar */ - bar_refresh(infobar.bar); - - return; -} - -void -uicb_togglebarpos(uicb_t cmd) -{ - conf.bartop = !conf.bartop; - if(conf.bartop) - sgeo.y = conf.titlebar.pos ? infobar.geo.height : infobar.geo.height + conf.titlebar.height; - else - sgeo.y = conf.titlebar.pos ? 0 : conf.titlebar.height; - infobar.geo.y = (conf.bartop) ? 0 : mh - infobar.geo.height; - bar_move(infobar.bar, 0, infobar.geo.y); - updatebar(); - arrange(); - - return; -} diff --git a/src/config.c b/src/config.c index 10cabc3..35d934c 100644 --- a/src/config.c +++ b/src/config.c @@ -36,25 +36,25 @@ func_name_list_t func_list[] = { - {"spawn", uicb_spawn }, - {"client_kill", uicb_client_kill }, - {"client_prev", uicb_client_prev }, - {"client_next", uicb_client_next }, - {"togglemax", uicb_togglemax }, - {"layout_next", uicb_layout_next }, - {"layout_prev", uicb_layout_prev }, - {"tag", uicb_tag }, - {"tag_next", uicb_tag_next }, - {"tag_prev", uicb_tag_prev }, - {"tagtransfert", uicb_tagtransfert }, - {"set_mwfact", uicb_set_mwfact }, - {"set_nmaster", uicb_set_nmaster }, - {"quit", uicb_quit }, - {"togglebarpos", uicb_togglebarpos }, - {"mouse_move", uicb_mousemove }, - {"mouse_resize", uicb_resizemouse }, - {"client_raise", uicb_client_raise }, - {"tile_switch", uicb_tile_switch } + {"spawn", uicb_spawn }, + {"client_kill", uicb_client_kill }, + {"client_prev", uicb_client_prev }, + {"client_next", uicb_client_next }, + {"togglemax", uicb_togglemax }, + {"layout_next", uicb_layout_next }, + {"layout_prev", uicb_layout_prev }, + {"tag", uicb_tag }, + {"tag_next", uicb_tag_next }, + {"tag_prev", uicb_tag_prev }, + {"tagtransfert", uicb_tagtransfert }, + {"set_mwfact", uicb_set_mwfact }, + {"set_nmaster", uicb_set_nmaster }, + {"quit", uicb_quit }, + {"toggle_infobar_position", uicb_infobar_togglepos }, + {"mouse_move", uicb_mousemove }, + {"mouse_resize", uicb_resizemouse }, + {"client_raise", uicb_client_raise }, + {"tile_switch", uicb_tile_switch } }; func_name_list_t layout_list[] = diff --git a/src/draw.c b/src/draw.c index 6aac6ed..17b188f 100644 --- a/src/draw.c +++ b/src/draw.c @@ -59,91 +59,6 @@ draw_text(Drawable d, int x, int y, char* fg, uint bg, int pad, char *str) return; } -void -draw_taglist(Drawable dr) -{ - int i; - char buf[conf.ntag][256]; - char p[4]; - taglen[0] = PAD/2; - - for(i = 0; i < conf.ntag; ++i) - { - /* Make the tags string */ - ITOA(p, client_pertag(i+1)); - sprintf(buf[i], "%s<%s>", tags[i+1].name, (client_pertag(i+1)) ? p : ""); - - /* Draw the string */ - draw_text(dr, taglen[i], fonth, - ((i+1 == seltag) ? conf.colors.tagselfg : conf.colors.text), - ((i+1 == seltag) ? conf.colors.tagselbg : conf.colors.bar), PAD, buf[i]); - - /* Draw the tag separation */ - draw_rectangle(dr, taglen[i] + textw(buf[i]) + PAD/2, - 0, conf.tagbordwidth, infobar.geo.height, conf.colors.tagbord); - - /* Edit taglen[i+1] for the next time */ - taglen[i+1] = taglen[i] + textw(buf[i]) + PAD + conf.tagbordwidth; - } - - return; -} - -void -draw_layout(void) -{ - int px, py, width; - char symbol[256]; - - /* Set symbol & position */ - px = width = taglen[conf.ntag]; - py = conf.bartop ? infobar.geo.y : infobar.geo.y + 1; - if(tags[seltag].layout.func == freelayout - || tags[seltag].layout.func == maxlayout) - strcpy(symbol, tags[seltag].layout.symbol); - else - strcpy(symbol, conf.tile_symbol); - - /* Draw layout name/symbol */ - bar_refresh_color(infobar.layout_switch); - - bar_move(infobar.layout_switch, px, py); - bar_resize(infobar.layout_switch, textw(symbol) + PAD, infobar.geo.height - 1); - draw_text(infobar.layout_switch->dr, PAD/2, fonth, - conf.colors.layout_fg, - conf.colors.layout_bg, - PAD, symbol); - width += textw(symbol) + PAD; - bar_refresh(infobar.layout_switch); - - if(tags[seltag].layout.func == tile - || tags[seltag].layout.func == tile_left - || tags[seltag].layout.func == tile_top - || tags[seltag].layout.func == tile_bottom - || tags[seltag].layout.func == grid) - { - bar_map(infobar.layout_type_switch); - bar_refresh_color(infobar.layout_type_switch); - bar_move(infobar.layout_type_switch, px + infobar.layout_switch->geo.width + PAD/2, py); - bar_resize(infobar.layout_type_switch, textw(tags[seltag].layout.symbol) + PAD, infobar.geo.height - 1); - draw_text(infobar.layout_type_switch->dr, PAD/2, fonth, - conf.colors.layout_fg, - conf.colors.layout_bg, - PAD, tags[seltag].layout.symbol); - width += textw(tags[seltag].layout.symbol) + PAD * 1.5; - - bar_refresh(infobar.layout_type_switch); - } - else - bar_unmap(infobar.layout_type_switch); - - /* Draw right separation */ - infobar.lastsep = width + PAD / 2; - draw_rectangle(infobar.bar->dr, infobar.lastsep, 0, conf.tagbordwidth, infobar.geo.height, conf.colors.tagbord); - - return; -} - void draw_rectangle(Drawable dr, int x, int y, uint w, uint h, uint color) { diff --git a/src/event.c b/src/event.c index f7eb766..4402ade 100644 --- a/src/event.c +++ b/src/event.c @@ -179,7 +179,7 @@ expose(XEvent ev) if(ev.xexpose.count == 0 && (ev.xexpose.window == infobar.bar->win)) - updatebar(); + infobar_draw(); if(conf.titlebar.exist) for(c = clients; c; c = c->next) @@ -345,7 +345,7 @@ mouseaction(Client *c, int x, int y, int type) if(type && !c->tile) XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->geo.width, c->geo.height); XUngrabPointer(dpy, CurrentTime); - updatebar(); + infobar_draw(); return; } else if(ev.type == MotionNotify) diff --git a/src/layout.c b/src/layout.c index 0ffa716..9454475 100644 --- a/src/layout.c +++ b/src/layout.c @@ -50,7 +50,7 @@ arrange(void) else client_focus(NULL); - updatebar(); + infobar_draw(); return; } diff --git a/src/wmfs.c b/src/wmfs.c index 27a4238..55917e7 100644 --- a/src/wmfs.c +++ b/src/wmfs.c @@ -179,7 +179,7 @@ init(void) bar_map(infobar.bar); bar_map(infobar.layout_switch); strcpy(infobar.statustext, "WMFS-" WMFS_VERSION); - updatebar(); + infobar_draw(); /* INIT WORKABLE SPACE GEOMETRY */ sgeo.x = 0; @@ -243,7 +243,7 @@ mainloop(void) strncpy(infobar.statustext, sbuf, strlen(sbuf)); readstdin = False; } - updatebar(); + infobar_draw(); } while(XPending(dpy)) { diff --git a/src/wmfs.h b/src/wmfs.h index 854649a..733a0a5 100644 --- a/src/wmfs.h +++ b/src/wmfs.h @@ -70,16 +70,18 @@ void bar_move(BarWindow *bw, int x, int y); void bar_resize(BarWindow *bw, uint w, uint h); void bar_refresh_color(BarWindow *bw); void bar_refresh(BarWindow *bw); -void updatebar(void); -void uicb_togglebarpos(uicb_t); /* draw.c */ void draw_text(Drawable d, int x, int y, char* fg, uint bg, int pad, char *str); -void draw_taglist(Drawable dr); -void draw_layout(void); void draw_rectangle(Drawable dr, int x, int y, uint w, uint h, uint color); ushort textw(const char *text); +/* infobar.c */ +void infobar_draw(void); +void infobar_draw_layout(void); +void infobar_draw_taglist(Drawable dr); +void uicb_infobar_togglepos(uicb_t cmd); + /* client.c */ int client_pertag(int tag); void client_attach(Client *c); diff --git a/wmfsrc b/wmfsrc index 8080401..00e7a2e 100644 --- a/wmfsrc +++ b/wmfsrc @@ -102,7 +102,7 @@ keys key { mod = {"Alt"} key = "q" func = "client_kill" } key { mod = {"Control", "Alt", "Shift"} key = "q" func = "quit" } key { mod = {"Control"} key = "m" func = "togglemax" } - key { mod = {"Control"} key = "b" func = "togglebarpos" } + key { mod = {"Control"} key = "b" func = "toggle_infobar_position" } key { mod = {"Alt"} key = "Tab" func = "client_next" } key { mod = {"Alt","Shift"} key = "Tab" func = "client_prev" } key { mod = {"Control"} key = "Right" func = "tag_next" }