From 39080f9952de6ae5f0b550737e1d6e48bfaa61a9 Mon Sep 17 00:00:00 2001 From: Martin Duquesnoy Date: Mon, 1 Aug 2011 23:26:51 +0200 Subject: [PATCH] Status: Use InfoBar* instead of win in StatusMouse struct --- src/draw.c | 12 ++++++------ src/event.c | 2 +- src/status.c | 35 ++++++++++++++++++----------------- src/structs.h | 2 +- src/wmfs.h | 2 +- 5 files changed, 27 insertions(+), 26 deletions(-) diff --git a/src/draw.c b/src/draw.c index 5f5a3ea..7c70626 100644 --- a/src/draw.c +++ b/src/draw.c @@ -86,7 +86,7 @@ parse_image_block(Drawable dr, char *str) BarWindow *bw; Geo area; char as, mouse[512] = { 0 }; - int i = 0, j = 0, k, n; + int i = 0, j = 0, k = 0, n; for(; i < (int)strlen(str); ++i, ++j) if((n = sscanf(&str[i], "\\i[%d;%d;%d;%d;%512[^];]]%c", @@ -97,7 +97,7 @@ parse_image_block(Drawable dr, char *str) { draw_image(dr, im.x - sw, im.y, im.w, im.h, im.name); - /* Etablish clickable area on image */ + /* Etablish clickable area on image (on infobar wins only (status mouse bind) */ if(n == 7) { area.x = im.x - sw; @@ -105,11 +105,11 @@ parse_image_block(Drawable dr, char *str) area.width = im.w; area.height = im.h; - /* Associate drawable with window; travel barwins */ - SLIST_FOREACH(bw, &bwhead, next) - if(bw->dr == dr) + /* Associate drawable with window; travel infobars */ + for(; k < screen_count(); ++k) + if(infobar[k].bar->dr == dr) { - statustext_mouse(mouse, area, bw->win); + statustext_mouse(mouse, area, &infobar[k]); break; } } diff --git a/src/event.c b/src/event.c index 8794dbc..95eabca 100644 --- a/src/event.c +++ b/src/event.c @@ -161,7 +161,7 @@ buttonpress(XEvent *e) /* Status mouse bindings */ SLIST_FOREACH(sm, &smhead, next) - if(sm->win == ev->window && ev->button == sm->button) + if(sm->infobar->bar->win == ev->window && ev->button == sm->button) if(ev->x >= sm->area.x && ev->x <= sm->area.x + sm->area.width && ev->y >= sm->area.y && ev->y <= sm->area.y + sm->area.height) if(sm->func) diff --git a/src/status.c b/src/status.c index 6659f7f..b22bba0 100644 --- a/src/status.c +++ b/src/status.c @@ -39,10 +39,10 @@ static int sw = 0; * --> \[;;;;(button;func;cmd)]\ add a mouse bind on the block object *\param str String *\param area Area of clicking - *\param win Win to click + *\param infobar Infobar pointer */ void -statustext_mouse(char *str, Geo area, Window win) +statustext_mouse(char *str, Geo area, InfoBar *infobar) { StatusMouse *sm = NULL; int i = 0, button = 1, n; @@ -50,14 +50,14 @@ statustext_mouse(char *str, Geo area, Window win) char func[64] = { 0 }; for(; i < strlen(str); ++i) - if((n = sscanf(&str[i], "(%d;%64[^;];%256[^)])", &button, func, cmd) >= 2) && n <= 3) + if((n = sscanf(&str[i], "(%d;%64[^;];%256[^)])", &button, func, cmd) >= 2) && n < 4) { sm = zcalloc(sizeof(StatusMouse)); - sm->button = button; - sm->func = name_to_func((char*)func, func_list); - sm->cmd = xstrdup(cmd); - sm->area = area; - sm->win = win; + sm->button = button; + sm->func = name_to_func((char*)func, func_list); + sm->cmd = xstrdup(cmd); + sm->area = area; + sm->infobar = infobar; SLIST_INSERT_HEAD(&smhead, sm, next); @@ -91,7 +91,7 @@ statustext_rectangle(InfoBar *ib, char *str) draw_rectangle(ib->bar->dr, r.g.x - sw, r.g.y, r.g.width, r.g.height, r.color); if(n == 7) - statustext_mouse(mouse, r.g, ib->bar->win); + statustext_mouse(mouse, r.g, ib); for(++i, --j; str[i] != as || str[i - 1] != ']'; ++i); } @@ -182,7 +182,7 @@ statustext_text(InfoBar *ib, char *str) area.x = s.x - sw; area.y = s.y - area.height; - statustext_mouse(mouse, area, ib->bar->win); + statustext_mouse(mouse, area, ib); } for(++i, --j; str[i] != as || str[i - 1] != ']'; ++i); @@ -267,13 +267,14 @@ statustext_handle(int sc, char *str) return; /* Free previous linked list of mouse bind */ - while(!SLIST_EMPTY(&smhead)) - { - sm = SLIST_FIRST(&smhead); - SLIST_REMOVE_HEAD(&smhead, next); - free((void*)sm->cmd); - free(sm); - } + if(!sc) + while(!SLIST_EMPTY(&smhead)) + { + sm = SLIST_FIRST(&smhead); + SLIST_REMOVE_HEAD(&smhead, next); + free((void*)sm->cmd); + free(sm); + } if(sc == conf.systray.screen) sw = systray_get_width(); diff --git a/src/structs.h b/src/structs.h index b428d6b..eaa5314 100644 --- a/src/structs.h +++ b/src/structs.h @@ -563,7 +563,7 @@ typedef struct typedef struct StatusMouse { Geo area; - Window win; + InfoBar *infobar; int button; void (*func)(uicb_t); uicb_t cmd; diff --git a/src/wmfs.h b/src/wmfs.h index 1e96068..c32d3a9 100644 --- a/src/wmfs.h +++ b/src/wmfs.h @@ -363,7 +363,7 @@ void uicb_screen_prev(uicb_t); void uicb_screen_prev_sel(uicb_t); /* status.c */ -void statustext_mouse(char *str, Geo area, Drawable dr); +void statustext_mouse(char *str, Geo area, InfoBar *infobar); void statustext_handle(int sc, char *str); /* systray.c */