From 4bd8a487e9126124f007866cd87d4c1a2af10d87 Mon Sep 17 00:00:00 2001 From: Martin Duquesnoy Date: Sun, 26 Oct 2008 18:52:59 +0100 Subject: [PATCH] config: Add root section (with multi mouse section and background_command) --- src/config.c | 29 +++++++++++++++++++++++++++-- src/event.c | 10 ++++------ src/structs.h | 6 ++++++ src/wmfs.c | 2 ++ wmfsrc | 9 +++++++++ 5 files changed, 48 insertions(+), 8 deletions(-) diff --git a/src/config.c b/src/config.c index 71262ce..009a4bf 100644 --- a/src/config.c +++ b/src/config.c @@ -191,6 +191,13 @@ init_conf(void) CFG_END() }; + static cfg_opt_t root_opts[] = + { + CFG_STR("background_command", "", CFGF_NONE), + CFG_SEC("mouse", mouse_button_opts, CFGF_MULTI), + CFG_END() + }; + static cfg_opt_t titlebar_opts[] = { CFG_STR("position", "top", CFGF_NONE), @@ -199,7 +206,8 @@ init_conf(void) CFG_STR("fg_focus", "#FFFFFF", CFGF_NONE), CFG_STR("fg_normal", "#FFFFFF", CFGF_NONE), CFG_STR("text_align", "left", CFGF_NONE), - CFG_SEC("mouse", mouse_button_opts, CFGF_MULTI) + CFG_SEC("mouse", mouse_button_opts, CFGF_MULTI), + CFG_END() }; static cfg_opt_t client_opts[]= @@ -208,7 +216,8 @@ init_conf(void) CFG_STR("border_normal", "#354B5C", CFGF_NONE), CFG_STR("border_focus", "#6286A1", CFGF_NONE), CFG_STR("modifier", "Alt", CFGF_NONE), - CFG_SEC("mouse", mouse_button_opts, CFGF_MULTI) + CFG_SEC("mouse", mouse_button_opts, CFGF_MULTI), + CFG_END() }; static cfg_opt_t layout_opts[] = @@ -277,6 +286,7 @@ init_conf(void) { CFG_SEC("misc", misc_opts, CFGF_NONE), CFG_SEC("variables", variables_opts, CFGF_NONE), + CFG_SEC("root", root_opts, CFGF_NONE), CFG_SEC("titlebar", titlebar_opts, CFGF_NONE), CFG_SEC("client", client_opts, CFGF_NONE), CFG_SEC("bar", bar_opts, CFGF_NONE), @@ -290,6 +300,7 @@ init_conf(void) cfg_t *cfg_misc; cfg_t *cfg_bar; cfg_t *cfg_variables; + cfg_t *cfg_root; cfg_t *cfg_titlebar; cfg_t *cfg_client; cfg_t *cfg_layouts; @@ -319,6 +330,7 @@ init_conf(void) cfg_misc = cfg_getsec(cfg, "misc"); cfg_variables = cfg_getsec(cfg, "variables"); + cfg_root = cfg_getsec(cfg, "root"); cfg_titlebar = cfg_getsec(cfg, "titlebar"); cfg_client = cfg_getsec(cfg, "client"); cfg_bar = cfg_getsec(cfg, "bar"); @@ -349,6 +361,19 @@ init_conf(void) conf.colors.text = strdup(var_to_str(cfg_getstr(cfg_bar, "fg"))); conf.bartop = (strcmp(strdup(cfg_getstr(cfg_bar, "position")), "top") == 0) ? True : False; + /* root */ + conf.root.background_command = strdup(var_to_str(cfg_getstr(cfg_root, "background_command"))); + conf.root.nmouse = cfg_size(cfg_root, "mouse"); + conf.root.mouse = emalloc(conf.root.nmouse, sizeof(MouseBinding)); + + for(i = 0; i < conf.root.nmouse; ++i) + { + cfgtmp = cfg_getnsec(cfg_root, "mouse", i); + conf.root.mouse[i].button = char_to_button(cfg_getstr(cfgtmp, "button")); + conf.root.mouse[i].func = name_to_func(cfg_getstr(cfgtmp, "func"), func_list); + conf.root.mouse[i].cmd = strdup(var_to_str(cfg_getstr(cfgtmp, "cmd"))); + } + /* titlebar */ strcpy(buf, var_to_str(cfg_getstr(cfg_titlebar, "position"))); if(strcmp(buf, "bottom") == 0) diff --git a/src/event.c b/src/event.c index c357462..eb90284 100644 --- a/src/event.c +++ b/src/event.c @@ -57,12 +57,10 @@ buttonpress(XEvent ev) /* Root */ if(ev.xbutton.window == root) - { - if(ev.xbutton.button == Button4) - uicb_tag("+1"); - if(ev.xbutton.button == Button5) - uicb_tag("-1"); - } + for(i = 0; i < conf.root.nmouse; ++i) + if(ev.xbutton.button == conf.root.mouse[i].button) + if(conf.root.mouse[i].func) + conf.root.mouse[i].func(conf.root.mouse[i].cmd); /* Bar */ { diff --git a/src/structs.h b/src/structs.h index 43100b4..6c10b84 100644 --- a/src/structs.h +++ b/src/structs.h @@ -163,6 +163,12 @@ typedef struct uint layout_bg; } colors; struct + { + char *background_command; + MouseBinding *mouse; + int nmouse; + } root; + struct { int borderheight; uint bordernormal; diff --git a/src/wmfs.c b/src/wmfs.c index 50faae5..8e72b0d 100644 --- a/src/wmfs.c +++ b/src/wmfs.c @@ -167,6 +167,8 @@ init(void) EnterWindowMask | LeaveWindowMask | StructureNotifyMask ; at.cursor = cursor[CurNormal]; XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &at); + if(conf.root.background_command) + uicb_spawn(conf.root.background_command); /* INIT BAR / BUTTON */ bary = (conf.bartop) ? 0 : mh - barheight; diff --git a/wmfsrc b/wmfsrc index 3289d26..41416b3 100644 --- a/wmfsrc +++ b/wmfsrc @@ -47,6 +47,15 @@ tags tag { name = "nine" } } +root +{ + background_command = "xsetroot -solid black" + + mouse { button = "4" func = "tag_next" } + mouse { button = "5" func = "tag_prev" } + mouse { button = "3" func = "spawn" cmd = term } +} + client { border_height = 1