diff --git a/awesome.c b/awesome.c index 730ac438..09b383cb 100644 --- a/awesome.c +++ b/awesome.c @@ -55,6 +55,7 @@ void cleanup_screen(awesome_config *awesomeconf) { int i; + Button *b, *bn; XftFontClose(awesomeconf->display, awesomeconf->font); XUngrabKey(awesomeconf->display, AnyKey, AnyModifier, RootWindow(awesomeconf->display, awesomeconf->phys_screen)); @@ -67,10 +68,29 @@ cleanup_screen(awesome_config *awesomeconf) p_delete(&awesomeconf->tags[i].name); for(i = 0; i < awesomeconf->nkeys; i++) p_delete(&awesomeconf->keys[i].arg); - for(i = 0; i< awesomeconf->buttons.ntitle; i++) - p_delete(&awesomeconf->buttons.title[i].arg); - for(i = 0; i< awesomeconf->buttons.nlayout; i++) - p_delete(&awesomeconf->buttons.layout[i].arg); + for(b = awesomeconf->buttons.tag; b; b = bn) + { + bn = b->next; + p_delete(&b); + } + for(b = awesomeconf->buttons.title; b; b = bn) + { + bn = b->next; + p_delete(&b->arg); + p_delete(&b); + } + for(b = awesomeconf->buttons.layout; b; b = bn) + { + bn = b->next; + p_delete(&b->arg); + p_delete(&b); + } + for(b = awesomeconf->buttons.root; b; b = bn) + { + bn = b->next; + p_delete(&b->arg); + p_delete(&b); + } for(i = 0; i < awesomeconf->nlayouts; i++) p_delete(&awesomeconf->layouts[i].symbol); for(i = 0; i < awesomeconf->nrules; i++) @@ -82,9 +102,6 @@ cleanup_screen(awesome_config *awesomeconf) p_delete(&awesomeconf->layouts); p_delete(&awesomeconf->rules); p_delete(&awesomeconf->keys); - p_delete(&awesomeconf->buttons.tag); - p_delete(&awesomeconf->buttons.title); - p_delete(&awesomeconf->buttons.layout); p_delete(&awesomeconf->configpath); } diff --git a/client.c b/client.c index fa817ad7..8307c895 100644 --- a/client.c +++ b/client.c @@ -189,7 +189,7 @@ focus(Client *c, Bool selscreen, awesome_config *awesomeconf) window_grabbuttons(awesomeconf->tags[i].client_sel->display, awesomeconf->tags[i].client_sel->phys_screen, awesomeconf->tags[i].client_sel->win, - False, True, awesomeconf->buttons.root, awesomeconf->buttons.nroot, + False, True, awesomeconf->buttons.root, awesomeconf->modkey, awesomeconf->numlockmask); XSetWindowBorder(awesomeconf->tags[i].client_sel->display, awesomeconf->tags[i].client_sel->win, @@ -201,7 +201,7 @@ focus(Client *c, Bool selscreen, awesome_config *awesomeconf) { XSetWindowBorder(awesomeconf->display, c->win, awesomeconf->colors_selected[ColBorder].pixel); window_grabbuttons(c->display, c->phys_screen, c->win, - True, True, awesomeconf->buttons.root, awesomeconf->buttons.nroot, + True, True, awesomeconf->buttons.root, awesomeconf->modkey, awesomeconf->numlockmask); } if(!selscreen) @@ -326,7 +326,7 @@ client_manage(Window w, XWindowAttributes *wa, awesome_config *awesomeconf) /* grab buttons */ window_grabbuttons(c->display, c->phys_screen, c->win, - False, True, awesomeconf->buttons.root, awesomeconf->buttons.nroot, + False, True, awesomeconf->buttons.root, awesomeconf->modkey, awesomeconf->numlockmask); /* update window title */ diff --git a/config.c b/config.c index 6889fbb5..e4f4169e 100644 --- a/config.c +++ b/config.c @@ -172,28 +172,41 @@ mouse_button_lookup(const char *button) return 0; } -static void -parse_mouse_bindings(cfg_t * cfg, const char *secname, Button **buttons, int *n, Bool handle_arg) +static Button * +parse_mouse_bindings(cfg_t * cfg, const char *secname, Bool handle_arg) { - int i; - unsigned int j; + unsigned int i, j; cfg_t *cfgsectmp; + Button *b = NULL, *head = NULL; /* Mouse: layout click bindings */ - *n = cfg_size(cfg, secname); - *buttons = p_new(Button, *n); - for(i = 0; i < *n; i++) + for(i = 0; i < cfg_size(cfg, secname); i++) { + /* init first elem */ + if(i == 0) + head = b = p_new(Button, 1); + cfgsectmp = cfg_getnsec(cfg, secname, i); for(j = 0; j < cfg_size(cfgsectmp, "modkey"); j++) - (*buttons)[i].mod |= key_mask_lookup(cfg_getnstr(cfgsectmp, "modkey", j)); - (*buttons)[i].button = mouse_button_lookup(cfg_getstr(cfgsectmp, "button")); - (*buttons)[i].func = name_func_lookup(cfg_getstr(cfgsectmp, "command"), UicbList); + b->mod |= key_mask_lookup(cfg_getnstr(cfgsectmp, "modkey", j)); + b->button = mouse_button_lookup(cfg_getstr(cfgsectmp, "button")); + b->func = name_func_lookup(cfg_getstr(cfgsectmp, "command"), UicbList); if(handle_arg) - (*buttons)[i].arg = a_strdup(cfg_getstr(cfgsectmp, "arg")); + b->arg = a_strdup(cfg_getstr(cfgsectmp, "arg")); else - (*buttons)[i].arg = NULL; + b->arg = NULL; + + /* switch to next elem or finalize the list */ + if(i < cfg_size(cfg, secname) - 1) + { + b->next = p_new(Button, 1); + b = b->next; + } + else + b->next = NULL; } + + return head; } /** Parse configuration file and initialize some stuff @@ -472,16 +485,16 @@ parse_config(const char *confpatharg, awesome_config *awesomeconf) awesomeconf->modkey = Mod4Mask; /* Mouse: tags click bindings */ - parse_mouse_bindings(cfg_mouse, "tag", &awesomeconf->buttons.tag, &awesomeconf->buttons.ntag, False); + awesomeconf->buttons.tag = parse_mouse_bindings(cfg_mouse, "tag", False); /* Mouse: layout click bindings */ - parse_mouse_bindings(cfg_mouse, "layout", &awesomeconf->buttons.layout, &awesomeconf->buttons.nlayout, True); + awesomeconf->buttons.layout = parse_mouse_bindings(cfg_mouse, "layout", True); /* Mouse: title click bindings */ - parse_mouse_bindings(cfg_mouse, "title", &awesomeconf->buttons.title, &awesomeconf->buttons.ntitle, True); + awesomeconf->buttons.title = parse_mouse_bindings(cfg_mouse, "title", True); /* Mouse: root window click bindings */ - parse_mouse_bindings(cfg_mouse, "root", &awesomeconf->buttons.root, &awesomeconf->buttons.nroot, True); + awesomeconf->buttons.root = parse_mouse_bindings(cfg_mouse, "root", True); /* Keys */ awesomeconf->numlockmask = get_numlockmask(awesomeconf->display); diff --git a/config.h b/config.h index e5ee26e0..fc1a7722 100644 --- a/config.h +++ b/config.h @@ -68,6 +68,7 @@ struct Button unsigned int button; void (*func) (awesome_config *, char *); char *arg; + Button *next; }; /** Status bar */ @@ -174,13 +175,9 @@ struct awesome_config struct { Button *tag; - int ntag; Button *title; - int ntitle; Button *layout; - int nlayout; Button *root; - int nroot; } buttons; /** Number of keys binding in *keys */ int nkeys; diff --git a/event.c b/event.c index 4d7ed5d6..4ae0a9fb 100644 --- a/event.c +++ b/event.c @@ -141,19 +141,17 @@ resizemouse(Client * c, awesome_config *awesomeconf) static void handle_mouse_button_press(awesome_config *awesomeconf, unsigned int button, unsigned int state, unsigned int numlockmask, - Button *buttons, int nbuttons, char *arg) + Button *buttons, char *arg) { - int i; + Button *b; - for(i = 0; i < nbuttons; i++) - if(button == buttons[i].button - && (state == buttons[i].mod || state == (buttons[i].mod | numlockmask)) - && buttons[i].func) + for(b = buttons; b; b = b->next) + if(button == b->button && (state == b->mod || state == (b->mod | numlockmask)) && b->func) { if(arg) - buttons[i].func(awesomeconf, arg); + b->func(awesomeconf, arg); else - buttons[i].func(awesomeconf, buttons[i].arg); + b->func(awesomeconf, b->arg); return; } } @@ -182,7 +180,7 @@ handle_event_buttonpress(XEvent * e, awesome_config *awesomeconf) snprintf(arg, sizeof(arg), "%d", i + 1); handle_mouse_button_press(&awesomeconf[screen], ev->button, ev->state, awesomeconf->numlockmask, - awesomeconf->buttons.tag, awesomeconf->buttons.ntag, arg); + awesomeconf[screen].buttons.tag, arg); return; } } @@ -194,11 +192,11 @@ handle_event_buttonpress(XEvent * e, awesome_config *awesomeconf) || (awesomeconf[screen].statusbar.position == BarLeft && ev->y > awesomeconf[screen].statusbar.width - x)) handle_mouse_button_press(&awesomeconf[screen], ev->button, ev->state, awesomeconf->numlockmask, - awesomeconf->buttons.layout, awesomeconf->buttons.nlayout, NULL); + awesomeconf[screen].buttons.layout, NULL); else handle_mouse_button_press(&awesomeconf[screen], ev->button, ev->state, awesomeconf->numlockmask, - awesomeconf->buttons.title, awesomeconf->buttons.ntitle, NULL); + awesomeconf[screen].buttons.title, NULL); return; } @@ -212,7 +210,7 @@ handle_event_buttonpress(XEvent * e, awesome_config *awesomeconf) { restack(&awesomeconf[c->screen]); window_grabbuttons(c->display, c->phys_screen, c->win, - True, True, awesomeconf->buttons.root, awesomeconf->buttons.nroot, + True, True, awesomeconf->buttons.root, awesomeconf->modkey, awesomeconf->numlockmask); } } @@ -258,7 +256,7 @@ handle_event_buttonpress(XEvent * e, awesome_config *awesomeconf) screen = get_screen_bycoord(e->xany.display, x, y); handle_mouse_button_press(&awesomeconf[screen], ev->button, ev->state, awesomeconf->numlockmask, - awesomeconf->buttons.root, awesomeconf->buttons.nroot, NULL); + awesomeconf[screen].buttons.root, NULL); return; } } @@ -369,7 +367,7 @@ handle_event_enternotify(XEvent * e, awesome_config *awesomeconf) || get_current_layout(awesomeconf[c->screen].tags, awesomeconf[c->screen].ntags)->arrange == layout_floating) window_grabbuttons(c->display, c->phys_screen, c->win, - True, False, awesomeconf->buttons.root, awesomeconf->buttons.nroot, + True, False, awesomeconf->buttons.root, awesomeconf->modkey, awesomeconf->numlockmask); } else diff --git a/window.c b/window.c index 7d227968..4436b615 100644 --- a/window.c +++ b/window.c @@ -93,10 +93,9 @@ window_configure(Display *disp, Window win, int x, int y, int w, int h, int bord */ void window_grabbuttons(Display *disp, int screen, Window win, Bool focused, Bool raised, - Button *buttons_root, int nbuttons_root, - KeySym modkey, unsigned int numlockmask) + Button *buttons_root, KeySym modkey, unsigned int numlockmask) { - int i; + Button *b; XUngrabButton(disp, AnyButton, AnyModifier, win); @@ -158,18 +157,18 @@ window_grabbuttons(Display *disp, int screen, Window win, Bool focused, Bool rai XGrabButton(disp, AnyButton, AnyModifier, win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None); - for(i = 0; i < nbuttons_root; i++) + for(b = buttons_root; b; b = b->next) { - XGrabButton(disp, buttons_root[i].button, buttons_root[i].mod, + XGrabButton(disp, b->button, b->mod, RootWindow(disp, screen), False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None); - XGrabButton(disp, buttons_root[i].button, buttons_root[i].mod | LockMask, + XGrabButton(disp, b->button, b->mod | LockMask, RootWindow(disp, screen), False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None); - XGrabButton(disp, buttons_root[i].button, buttons_root[i].mod | numlockmask, + XGrabButton(disp, b->button, b->mod | numlockmask, RootWindow(disp, screen), False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None); - XGrabButton(disp, buttons_root[i].button, buttons_root[i].mod | numlockmask | LockMask, + XGrabButton(disp, b->button, b->mod | numlockmask | LockMask, RootWindow(disp, screen), False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None); } diff --git a/window.h b/window.h index ae653cac..6b93b18b 100644 --- a/window.h +++ b/window.h @@ -31,7 +31,7 @@ int window_setstate(Display *, Window, long); long window_getstate(Display *, Window); Status window_configure(Display *, Window, int, int, int, int, int); -void window_grabbuttons(Display *, int, Window, Bool, Bool, Button *, int, KeySym, unsigned int); +void window_grabbuttons(Display *, int, Window, Bool, Bool, Button *, KeySym, unsigned int); void window_setshape(Display *, int, Window); void window_settrans(Display *, Window, double);