diff --git a/config.c b/config.c index 7265c67..3956fb6 100644 --- a/config.c +++ b/config.c @@ -6,11 +6,6 @@ #define FILE_NAME ".wmfsrc" -typedef struct { - char *name; - KeySym keysym; -} key_name_list_t; - func_name_list_t func_list[] = { {"spawn", spawn}, {"killclient", killclient}, @@ -38,6 +33,14 @@ key_name_list_t key_list[] = { {NULL, NoSymbol} }; +mouse_button_list_t mouse_button_list[] = { + {"Button1", Button1}, + {"Button2", Button2}, + {"Button3", Button3}, + {"Button4", Button4}, + {"Button5", Button5} +}; + void* name_to_func(char *name) { int i; @@ -54,11 +57,21 @@ char_to_modkey(char *name) { int i; if(name) for(i=0; key_list[i].name; ++i) - if(!strcmp(name,key_list[i].name)) + if(!strcmp(name, key_list[i].name)) return key_list[i].keysym; return NoSymbol; } +unsigned int +char_to_button(char *name) { + int i; + if(name) + for(i=0; mouse_button_list[i].name; ++i) + if(!strcmp(name, mouse_button_list[i].name)) + return mouse_button_list[i].button; + return 0; +} + void init_conf(void) { @@ -103,7 +116,7 @@ init_conf(void) { CFG_STR_LIST("mod","{Control}", CFGF_NONE), CFG_STR("key", "None", CFGF_NONE), CFG_STR("func", "", CFGF_NONE), - CFG_STR("cmd", NULL, CFGF_NONE), + CFG_STR("cmd", "", CFGF_NONE), CFG_END() }; @@ -113,11 +126,18 @@ init_conf(void) { CFG_END() }; + static cfg_opt_t mouse_button_opts[] = { + + CFG_STR("button", "Button1", CFGF_NONE), + CFG_STR("func", "", CFGF_NONE), + CFG_STR("cmd", "", CFGF_NONE), + CFG_END() + }; + static cfg_opt_t button_opts[] = { CFG_STR("text", "", CFGF_NONE), - CFG_STR("func", "", CFGF_NONE), - CFG_STR("cmd", "", CFGF_NONE), + CFG_SEC("mouse", mouse_button_opts, CFGF_MULTI), CFG_INT("fg_color", 0x000000, CFGF_NONE), CFG_INT("bg_color", 0xFFFFFF, CFGF_NONE), CFG_END() @@ -147,7 +167,7 @@ init_conf(void) { cfg_t *cfg_tag; cfg_t *cfg_keys; cfg_t *cfg_buttons; - cfg_t *cfgtmp, *cfgtmp2; + cfg_t *cfgtmp, *cfgtmp2, *cfgtmp3; char final_path[100]; int ret, i, j, l; @@ -190,9 +210,9 @@ init_conf(void) { conf.colors.tagselbg = cfg_getint(cfg_colors, "tag_sel_bg"); /* layout */ - conf.layouts.free = strdup(cfg_getstr(cfg_layout,"free")); - conf.layouts.tile = strdup(cfg_getstr(cfg_layout,"tile")); - conf.layouts.max = strdup(cfg_getstr(cfg_layout,"max")); + conf.layouts.free = strdup(cfg_getstr(cfg_layout, "free")); + conf.layouts.tile = strdup(cfg_getstr(cfg_layout, "tile")); + conf.layouts.max = strdup(cfg_getstr(cfg_layout, "max")); /* tag */ conf.ntag = cfg_size(cfg_tag, "tag"); @@ -210,19 +230,27 @@ init_conf(void) { keys[j].keysym = XStringToKeysym(cfg_getstr(cfgtmp, "key")); keys[j].func = name_to_func(cfg_getstr(cfgtmp, "func")); if(!keys[j].func) { - printf("WMFS Configuration: Unknow Function %s",cfg_getstr(cfgtmp,"func")); + printf("WMFS Configuration: Unknow Function %s",cfg_getstr(cfgtmp, "func")); return; } - keys[j].cmd = strdup(strdup(cfg_getstr(cfgtmp, "cmd"))); + if(!strdup(strdup(cfg_getstr(cfgtmp, "cmd")))) + keys[j].cmd = NULL; + else + keys[j].cmd = strdup(strdup(cfg_getstr(cfgtmp, "cmd"))); } /* button */ conf.nbutton = cfg_size(cfg_buttons, "button"); for(i = 0; i < conf.nbutton; ++i) { cfgtmp2 = cfg_getnsec(cfg_buttons, "button", i); + for(j = 0; j < cfg_size(cfgtmp2, "mouse"); ++j) { + cfgtmp3 = cfg_getnsec(cfgtmp2, "mouse", j); + conf.barbutton[i].func[j] = name_to_func(cfg_getstr(cfgtmp3, "func")); + conf.barbutton[i].cmd[j] = strdup(cfg_getstr(cfgtmp3, "cmd")); + conf.barbutton[i].mouse[j] = char_to_button(cfg_getstr(cfgtmp3, "button")); + } + conf.barbutton[i].nmousesec = cfg_size(cfgtmp2, "mouse"); conf.barbutton[i].text = strdup(cfg_getstr(cfgtmp2, "text")); - conf.barbutton[i].func = name_to_func(cfg_getstr(cfgtmp2, "func")); - conf.barbutton[i].cmd = strdup(cfg_getstr(cfgtmp2, "cmd")); conf.barbutton[i].fg_color = cfg_getint(cfgtmp2, "fg_color"); conf.barbutton[i].bg_color = cfg_getint(cfgtmp2, "bg_color"); } diff --git a/local.h b/local.h index 213b2b4..3d213ee 100644 --- a/local.h +++ b/local.h @@ -7,11 +7,8 @@ #include #include #include -#include -#include #include #include -#include #include #include #include @@ -72,12 +69,13 @@ typedef struct { typedef struct { char *text; Window win; - void (*func)(char *cmd); - char *cmd; + void (*func[5])(char *cmd); + char *cmd[5]; int fg_color; int bg_color; unsigned int x; - unsigned int button; + unsigned int mouse[5]; + int nmousesec; } BarButton; typedef struct { diff --git a/wmfs.c b/wmfs.c index 90aeeda..0754359 100644 --- a/wmfs.c +++ b/wmfs.c @@ -41,7 +41,7 @@ attach(Client *c) { void buttonpress(XEvent *event) { Client *c; - int i; + int i, j; char s[6]; XButtonPressedEvent *ev = &event->xbutton; @@ -110,10 +110,12 @@ buttonpress(XEvent *event) { /* Bar Button */ for(i=0; iwindow == conf.barbutton[i].win - && ev->button == Button1) { - if(conf.barbutton[i].func) - conf.barbutton[i].func(conf.barbutton[i].cmd); + for(j=0; jwindow == conf.barbutton[i].win + && ev->button == conf.barbutton[i].mouse[j]) { + if(conf.barbutton[i].func[j]) + conf.barbutton[i].func[j](conf.barbutton[i].cmd[j]); + } } } } @@ -535,7 +537,11 @@ ishide(Client *c) { void keymovex(char *cmd) { - if(sel && cmd && !ishide(sel) && !sel->max) { + if(sel + && cmd + && !ishide(sel) + && !sel->max) + { if((layout[seltag] == Tile && !sel->hint) || layout[seltag] == Max) return; int tmp; @@ -547,7 +553,11 @@ keymovex(char *cmd) { void keymovey(char *cmd) { - if(sel && cmd && !ishide(sel) && !sel->max) { + if(sel + && cmd + && !ishide(sel) + && !sel->max) + { if((layout[seltag] == Tile && !sel->hint) || layout[seltag] == Max) return; int tmp; @@ -578,7 +588,11 @@ keypress(XEvent *e) { void keyresize(char *cmd) { - if(sel && !ishide(sel) && !sel->max && layout[seltag] != Tile && layout[seltag] != Max) { + if(sel && !ishide(sel) + && !sel->max + && layout[seltag] != Tile + && layout[seltag] != Max) + { int temph = 0, tempw = 0, modh = 0, modw = 0, tmp = 0; switch(cmd[1]) { @@ -667,7 +681,7 @@ manage(Window w, XWindowAttributes *wa) { if((rettrans = XGetTransientForHint(dpy, w, &trans) == Success)) for(t = clients; t && t->win != trans; t = t->next); - c->tbar = XCreateSimpleWindow(dpy,root, + c->tbar = XCreateSimpleWindow(dpy, root, c->x, c->y - conf.ttbarheight, c->w, @@ -677,7 +691,7 @@ manage(Window w, XWindowAttributes *wa) { conf.colors.bar); XSelectInput(dpy, c->tbar, ExposureMask | EnterWindowMask); - c->button = XCreateSimpleWindow(dpy,root, + c->button = XCreateSimpleWindow(dpy, root, c->x + c->w - 10, BUTY(c->y), 5, diff --git a/wmfsrc b/wmfsrc index ade0846..3ffb800 100644 --- a/wmfsrc +++ b/wmfsrc @@ -22,9 +22,9 @@ colors layout { - free = "[Free]" - tile = "[Tile]" - max = "[Max]" + free = "[Free]" + tile = "[Tile]" + max = "[Max]" } tag @@ -34,7 +34,13 @@ tag buttons { - button { text = "Terminal" func = "spawn" cmd = "urxvt" fg_color = 0xFFFFFF bg_color = 0x3E3E3E } + button + { + text = "Terminal" + mouse { button = "Button1" func = "spawn" cmd = "urxvt" } + mouse { button = "Button3" func = "spawn" cmd = "xterm" } + fg_color = 0xFFFFFF bg_color = 0x3E3E3E + } } keys @@ -42,8 +48,8 @@ keys # general keybind key { mod = {"Control"} key = "Return" func = "spawn" cmd = "urxvt" } - key { mod = {"Alt"} key = "q" func = "killclient" cmd = NULL } - key { mod = {"Control"} key = "m" func = "togglemax" cmd = NULL } + key { mod = {"Alt"} key = "q" func = "killclient" } + key { mod = {"Control"} key = "m" func = "togglemax" } key { mod = {"Alt"} key = "Tab" func = "wswitch" cmd = "+" } key { mod = {"Alt","Shift"} key = "Tab" func = "wswitch" cmd = "-" } key { mod = {"Control"} key = "Right" func = "tagswitch" cmd = "+1" }