From 99370f0ccd4934ceef63a61c445fd919c6c41c28 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Sun, 11 Nov 2007 15:55:13 +0100 Subject: [PATCH] mouse buttons are now configurable for click on title bar --- awesome.c | 3 +++ config.c | 23 +++++++++++++++++++++-- config.h | 2 ++ event.c | 17 +++++++++++++---- 4 files changed, 39 insertions(+), 6 deletions(-) diff --git a/awesome.c b/awesome.c index d88f4ff85..29edba004 100644 --- a/awesome.c +++ b/awesome.c @@ -68,6 +68,8 @@ 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->nlayouts; i++) p_delete(&awesomeconf->layouts[i].symbol); for(i = 0; i < awesomeconf->nrules; i++) @@ -80,6 +82,7 @@ cleanup_screen(awesome_config *awesomeconf) p_delete(&awesomeconf->rules); p_delete(&awesomeconf->keys); p_delete(&awesomeconf->buttons.tag); + p_delete(&awesomeconf->buttons.title); p_delete(&awesomeconf->configpath); } diff --git a/config.c b/config.c index 6a85a2d2a..0d01fa458 100644 --- a/config.c +++ b/config.c @@ -268,10 +268,18 @@ parse_config(const char *confpatharg, awesome_config *awesomeconf) CFG_STR((char *) "button", (char *) "None", CFGF_NONE), CFG_STR((char *) "command", (char *) "", CFGF_NONE), }; + static cfg_opt_t mouse_title_opts[] = + { + CFG_STR_LIST((char *) "modkey", (char *) "{}", CFGF_NONE), + CFG_STR((char *) "button", (char *) "None", CFGF_NONE), + CFG_STR((char *) "command", (char *) "", CFGF_NONE), + CFG_STR((char *) "arg", NULL, CFGF_NONE), + }; static cfg_opt_t mouse_opts[] = { CFG_STR((char *) "modkey", (char *) "Mod4", CFGF_NONE), CFG_SEC((char *) "tag", mouse_tag_opts, CFGF_MULTI), + CFG_SEC((char *) "title", mouse_title_opts, CFGF_MULTI), CFG_END() }; static cfg_opt_t opts[] = @@ -367,7 +375,6 @@ parse_config(const char *confpatharg, awesome_config *awesomeconf) awesomeconf->statusbar.position = awesomeconf->statusbar.dposition; /* Layouts */ - awesomeconf->nlayouts = cfg_size(cfg_layouts, "layout"); awesomeconf->layouts = p_new(Layout, awesomeconf->nlayouts); for(i = 0; i < awesomeconf->nlayouts; i++) @@ -387,7 +394,6 @@ parse_config(const char *confpatharg, awesome_config *awesomeconf) eprint("awesome: fatal: no default layout available\n"); /* Rules */ - awesomeconf->nrules = cfg_size(cfg_rules, "rule"); awesomeconf->rules = p_new(Rule, awesomeconf->nrules); for(i = 0; i < awesomeconf->nrules; i++) @@ -448,6 +454,19 @@ parse_config(const char *confpatharg, awesome_config *awesomeconf) awesomeconf->buttons.tag[i].arg = NULL; /* for now */ } + /* Mouse: title click bindings */ + awesomeconf->buttons.ntitle = cfg_size(cfg_mouse, "title"); + awesomeconf->buttons.title = p_new(Button, awesomeconf->buttons.ntitle); + for(i = 0; i < awesomeconf->buttons.ntitle; i++) + { + cfgsectmp = cfg_getnsec(cfg_mouse, "title", i); + for(j = 0; j < cfg_size(cfgsectmp, "modkey"); j++) + awesomeconf->buttons.title[i].mod |= key_mask_lookup(cfg_getnstr(cfgsectmp, "modkey", j)); + awesomeconf->buttons.title[i].button = mouse_button_lookup(cfg_getstr(cfgsectmp, "button")); + awesomeconf->buttons.title[i].func = name_func_lookup(cfg_getstr(cfgsectmp, "command"), UicbList); + awesomeconf->buttons.title[i].arg = a_strdup(cfg_getstr(cfgsectmp, "arg")); + } + /* Keys */ awesomeconf->numlockmask = get_numlockmask(awesomeconf->display); awesomeconf->nkeys = cfg_size(cfg_keys, "key"); diff --git a/config.h b/config.h index 0ffbdc4ac..8fa569fa4 100644 --- a/config.h +++ b/config.h @@ -177,6 +177,8 @@ struct awesome_config { Button *tag; int ntag; + Button *title; + int ntitle; } buttons; /** Number of keys binding in *keys */ int nkeys; diff --git a/event.c b/event.c index 5d01d81bd..89149d0d0 100644 --- a/event.c +++ b/event.c @@ -175,10 +175,19 @@ handle_event_buttonpress(XEvent * e, awesome_config *awesomeconf) uicb_setlayout(&awesomeconf[screen], "+1"); else if(ev->x < x && (ev->button == Button3 || ev->button == Button5)) uicb_setlayout(&awesomeconf[screen], "-1"); - else if(ev->button == Button4) - uicb_focusnext(&awesomeconf[screen], NULL); - else if(ev->button == Button5) - uicb_focusprev(&awesomeconf[screen], NULL); + else + { + for(j = 0; j < awesomeconf[screen].buttons.ntitle; j++) + if(ev->button == awesomeconf[screen].buttons.title[j].button + && (ev->state == awesomeconf[screen].buttons.title[j].mod + || ev->state == (awesomeconf[screen].buttons.title[j].mod | awesomeconf[screen].numlockmask)) + && awesomeconf[screen].buttons.title[j].func) + { + awesomeconf[screen].buttons.title[j].func(&awesomeconf[screen], + awesomeconf[screen].buttons.title[j].arg); + return; + } + } return; }