diff --git a/src/client.c b/src/client.c index 520c4d2..07a6572 100644 --- a/src/client.c +++ b/src/client.c @@ -41,6 +41,8 @@ client_pertag(int tag) for(c = clients; c; c = c->next) if(c->tag == tag) ++i; + efree(c); + return i; } @@ -88,7 +90,6 @@ uicb_client_prev(uicb_t cmd) if(!c->tile) client_raise(c); } - arrange(); return; @@ -151,6 +152,8 @@ client_focus(Client *c) if(!ishide(cc)) titlebar_update(cc); + efree(cc); + return; } @@ -463,7 +466,7 @@ client_unmanage(Client *c) if(conf.titlebar.exist) bar_delete(c->tbar); - free(c); + efree(c); arrange(); diff --git a/src/config.c b/src/config.c index b294f21..fd3d5f6 100644 --- a/src/config.c +++ b/src/config.c @@ -316,6 +316,7 @@ init_conf(void) cfg_t *cfgtmp, *cfgtmp2, *cfgtmp3; char final_path[128]; char sfinal_path[128]; + char buf[256] = {0}; int ret, i, j, l; @@ -368,10 +369,11 @@ init_conf(void) conf.bartop = (strcmp(strdup(cfg_getstr(cfg_bar, "position")), "top") == 0) ? True : False; /* titlebar */ - if(strcmp(var_to_str(cfg_getstr(cfg_titlebar, "position")), "bottom") == 0) - conf.titlebar.pos = True; - else - conf.titlebar.pos = False; + strcpy(buf, var_to_str(cfg_getstr(cfg_titlebar, "position"))); + if(strcmp(buf, "bottom") == 0) + conf.titlebar.pos = Bottom; + else if(strcmp(buf, "top") == 0) + conf.titlebar.pos = Top; conf.titlebar.height = cfg_getint(cfg_titlebar, "height"); conf.titlebar.exist = conf.titlebar.height ? True : False; @@ -379,11 +381,12 @@ init_conf(void) conf.titlebar.fg_focus = var_to_str(cfg_getstr(cfg_titlebar, "fg_focus")); conf.titlebar.fg_normal = var_to_str(cfg_getstr(cfg_titlebar, "fg_normal")); - if(strcmp(var_to_str(cfg_getstr(cfg_titlebar, "text_align")), "center") == 0) + strcpy(buf, var_to_str(cfg_getstr(cfg_titlebar, "text_align"))); + if(strcmp(buf, "center") == 0) conf.titlebar.text_align = Center; - else if(strcmp(var_to_str(cfg_getstr(cfg_titlebar, "text_align")), "right") == 0) + else if(strcmp(buf, "right") == 0) conf.titlebar.text_align = Right; - else + else if(strcmp(buf, "left") == 0) conf.titlebar.text_align = Left; conf.titlebar.nmouse = cfg_size(cfg_titlebar, "mouse"); diff --git a/src/event.c b/src/event.c index 3742a89..6e80cd3 100644 --- a/src/event.c +++ b/src/event.c @@ -113,6 +113,7 @@ buttonpress(XEvent ev) } } } + efree(c); return; } diff --git a/src/layout.c b/src/layout.c index 516d500..b07fcad 100644 --- a/src/layout.c +++ b/src/layout.c @@ -52,6 +52,8 @@ arrange(void) updatebar(); + efree(c); + return; } @@ -77,6 +79,8 @@ freelayout(void) } } + efree(c); + return; } @@ -137,6 +141,8 @@ maxlayout(void) client_moveresize(c, geo, False); } + efree(c); + return; } @@ -267,6 +273,7 @@ tile(void) if(n > nmaster && tileheight != sgeo.height) cgeo.y = c->geo.y + c->geo.height + border + titlebarh; } + efree(c); return; } @@ -280,8 +287,7 @@ uicb_tile_switch(uicb_t cmd) return; if((c = sel) == nexttiled(clients)) if(!(c = nexttiled(c->next))) - return; - client_detach(c); + return; client_detach(c); client_attach(c); client_focus(c); arrange(); diff --git a/src/structs.h b/src/structs.h index 6a0fb8c..43100b4 100644 --- a/src/structs.h +++ b/src/structs.h @@ -40,17 +40,18 @@ #define MAXLAYOUT 3 /* Typedef */ -typedef const char* uicb_t; -typedef unsigned int uint; -typedef unsigned long ulong; +typedef const char* uicb_t; +typedef unsigned int uint; +typedef unsigned long ulong; typedef unsigned short ushort; -typedef unsigned char uchar; +typedef unsigned char uchar; /* Enum */ enum { CurNormal, CurResize, CurMove, CurLast }; enum { WMState, WMProtocols, WMName, WMDelete, WMLast }; enum { NetSupported, NetWMName, NetLast }; -enum { Left = 0, Center, Right, AlignLast}; +typedef enum { Left = 0, Center, Right, AlignLast} Align; +typedef enum { Top = 0, Bottom, PosLast } Position; /* BarWindow Structure * (titlebar, topbar..) */ @@ -173,12 +174,12 @@ typedef struct struct { Bool exist; - Bool pos; + Position pos; int height; uint bg; char *fg_focus; char *fg_normal; - int text_align; + Align text_align; MouseBinding *mouse; int nmouse; } titlebar; diff --git a/src/titlebar.c b/src/titlebar.c index 5da3f94..10f6c37 100644 --- a/src/titlebar.c +++ b/src/titlebar.c @@ -74,10 +74,17 @@ titlebar_update_position(Client *c) int y; /* Set titlebar position : Top/Bottom */ - if(conf.titlebar.pos) - y = c->geo.y + c->geo.height + conf.client.borderheight; - else + switch(conf.titlebar.pos) + { + default: + case Top: y = c->geo.y - conf.titlebar.height; + break; + case Bottom: + y = c->geo.y + c->geo.height + conf.client.borderheight; + break; + } + bar_moveresize(c->tbar, c->geo.x, y, c->geo.width, conf.titlebar.height - conf.client.borderheight); @@ -88,7 +95,6 @@ void titlebar_update(Client *c) { int pos_y, pos_x; - char *tmpcolor = NULL; XFetchName(dpy, c->win, &(c->title)); if(!c->title) @@ -119,10 +125,11 @@ titlebar_update(Client *c) /* Set y text position (always at the middle) and fg color */ pos_y = (fonth - (xftfont->descent )) + ((conf.titlebar.height - fonth) / 2); - tmpcolor = ((c == sel) ? conf.titlebar.fg_focus : conf.titlebar.fg_normal); /* Draw title */ - draw_text(c->tbar->dr, pos_x, pos_y, tmpcolor, conf.titlebar.bg, 0, c->title); + draw_text(c->tbar->dr, pos_x, pos_y, + (c == sel) ? conf.titlebar.fg_focus : conf.titlebar.fg_normal, + conf.titlebar.bg, 0, c->title); } bar_refresh(c->tbar); diff --git a/src/util.c b/src/util.c index dd4b468..39fdc3e 100644 --- a/src/util.c +++ b/src/util.c @@ -43,6 +43,15 @@ emalloc(uint element, uint size) return ret; } +void +efree(void *ptr) +{ + if(ptr) + free(ptr); + + return; +} + ulong getcolor(char *color) { diff --git a/src/wmfs.c b/src/wmfs.c index 7b293b1..5e96924 100644 --- a/src/wmfs.c +++ b/src/wmfs.c @@ -98,11 +98,10 @@ quit(void) if(conf.nbutton) for(i = 0; i < conf.nbutton; ++i) bar_delete(conf.barbutton[i].bw); - free(conf.barbutton); - free(keys); - free(clients); - free(conf.titlebar.mouse); - free(conf.client.mouse); + efree(conf.barbutton); + efree(keys); + efree(conf.titlebar.mouse); + efree(conf.client.mouse); XSync(dpy, False); return; diff --git a/src/wmfs.h b/src/wmfs.h index db631d5..0c68dc7 100644 --- a/src/wmfs.h +++ b/src/wmfs.h @@ -124,6 +124,7 @@ void getevent(void); /* util.c */ void *emalloc(uint element, uint size); +void efree(void *ptr); ulong getcolor(char *color); void setwinstate(Window win, long state); long getwinstate(Window win);