diff --git a/src/config.c b/src/config.c index a738a4e..a2a87b4 100644 --- a/src/config.c +++ b/src/config.c @@ -65,7 +65,8 @@ conf_init_func_list(void) {"screen_prev", uicb_screen_prev }, {"reload", uicb_reload }, {"launcher", uicb_launcher }, - {"set_layout", uicb_set_layout } + {"set_layout", uicb_set_layout }, + {"menu", uicb_menu } }; func_list = emalloc(LEN(tmp_list), sizeof(func_name_list_t)); @@ -145,8 +146,8 @@ void conf_root_section(cfg_t *cfg_r) { conf.root.background_command = strdup(alias_to_str(cfg_getstr(cfg_r, "background_command"))); - conf.root.nmouse = cfg_size(cfg_r, "mouse"); - conf.root.mouse = emalloc(conf.root.nmouse, sizeof(MouseBinding)); + conf.root.nmouse = cfg_size(cfg_r, "mouse"); + conf.root.mouse = emalloc(conf.root.nmouse, sizeof(MouseBinding)); mouse_section(conf.root.mouse, cfg_r, conf.root.nmouse); return; @@ -209,7 +210,7 @@ conf_layout_section(cfg_t *cfg_l) } if(conf.layout_system) - menu_init(&menulayout, conf.nlayout, + menu_init(&menulayout, "menulayout", conf.nlayout, /* Colors */ conf.colors.layout_bg, conf.colors.layout_fg, @@ -252,6 +253,9 @@ conf_tag_section(cfg_t *cfg_t) /* If there is no tag in the conf or more than * MAXTAG (32) print an error and create only one. */ + Tag default_tag = { "WMFS", + 0.50, 1, False, + layout_name_to_struct(conf.layout, "tile_right", conf.nlayout, layout_list) }; conf.tag_round = cfg_getbool(cfg_t, "tag_round"); conf.colors.tagselfg = strdup(alias_to_str(cfg_getstr(cfg_t, "sel_fg"))); @@ -294,14 +298,7 @@ conf_tag_section(cfg_t *cfg_t) " (%d) in the screen %d\n", conf.ntag[i], i); conf.ntag[i] = 1; - tags[i][1].name = strdup("WMFS"); - tags[i][1].mwfact = 0.50; - tags[i][1].nmaster = 1; - tags[i][1].resizehint = False; - tags[i][1].layout = layout_name_to_struct(conf.layout, - "tile_right", - conf.nlayout, - layout_list); + tags[i][1] = default_tag; } seltag = emalloc(screen_count(), sizeof(int)); @@ -311,6 +308,56 @@ conf_tag_section(cfg_t *cfg_t) return; } +void +conf_menu_section(cfg_t *cfg_m) +{ + cfg_t *cfgtmp2; + int i, j; + + conf.nmenu = cfg_size(cfg_m, "set_menu"); + + if(!conf.nmenu) + return; + + conf.menu = emalloc(conf.nmenu, sizeof(Menu)); + + for(i = 0; i < conf.nmenu; ++i) + { + cfgtmp = cfg_getnsec(cfg_m, "set_menu", i); + + conf.menu[i].name = strdup(cfg_getstr(cfgtmp, "name")); + + if(!(conf.menu[i].place_at_mouse = cfg_getbool(cfgtmp, "place_at_mouse"))) + { + conf.menu[i].x = cfg_getint(cfgtmp, "x"); + conf.menu[i].y = cfg_getint(cfgtmp, "y"); + } + + conf.menu[i].colors.focus.bg = getcolor(strdup(cfg_getstr(cfgtmp, "bg_focus"))); + conf.menu[i].colors.focus.fg = strdup(cfg_getstr(cfgtmp, "fg_focus")); + conf.menu[i].colors.normal.bg = getcolor(strdup(cfg_getstr(cfgtmp, "bg_normal"))); + conf.menu[i].colors.normal.fg = strdup(cfg_getstr(cfgtmp, "fg_normal")); + + conf.menu[i].nitem = cfg_size(cfgtmp, "item"); + + if(conf.menu[i].nitem) + { + conf.menu[i].item = emalloc(conf.menu[i].nitem, sizeof(MenuItem)); + for(j = 0; j < cfg_size(cfgtmp, "item"); ++j) + { + cfgtmp2 = cfg_getnsec(cfgtmp, "item", j); + + conf.menu[i].item[j].name = strdup(cfg_getstr(cfgtmp2, "name")); + conf.menu[i].item[j].func = name_to_func(strdup(cfg_getstr(cfgtmp2, "func")), func_list); + conf.menu[i].item[j].cmd = (!strdup(alias_to_str((cfg_getstr(cfgtmp2, "cmd")))) + ? NULL : strdup(alias_to_str(cfg_getstr(cfgtmp2, "cmd")))); + } + } + } + + return; +} + void conf_keybind_section(cfg_t *cfg_k) { @@ -372,6 +419,7 @@ init_conf(void) conf_client_section(cfg_getsec(cfg, "client")); conf_layout_section(cfg_getsec(cfg, "layouts")); conf_tag_section(cfg_getsec(cfg, "tags")); + conf_menu_section(cfg_getsec(cfg, "menu")); conf_keybind_section(cfg_getsec(cfg, "keys")); cfg_free(cfg); diff --git a/src/config_struct.h b/src/config_struct.h index 062c66f..7fe45c8 100644 --- a/src/config_struct.h +++ b/src/config_struct.h @@ -95,6 +95,8 @@ cfg_opt_t client_opts[]= CFG_END() }; +/* TAGS {{{ */ + cfg_opt_t layout_opts[] = { CFG_STR("type", "", CFGF_NONE), @@ -112,6 +114,10 @@ cfg_opt_t layouts_opts[] = CFG_END() }; +/* }}} */ + +/* TAGS {{{ */ + cfg_opt_t tag_opts[] = { CFG_INT("screen", -1, CFGF_NONE), @@ -135,6 +141,42 @@ cfg_opt_t tags_opts[] = CFG_END() }; +/* }}} */ + +/* MENU {{{ */ + +cfg_opt_t menu_items_opts[] = +{ + CFG_STR("name", "iten_wname", CFGF_NONE), + CFG_STR("func", "", CFGF_NONE), + CFG_STR("cmd", "", CFGF_NONE), + CFG_END() +}; + +cfg_opt_t menus_opts[] = +{ + CFG_STR("name", "menu_wname", CFGF_NONE), + CFG_BOOL("place_at_mouse", cfg_true, CFGF_NONE), + CFG_INT("x", 0, CFGF_NONE), + CFG_INT("y", 0, CFGF_NONE), + CFG_STR("fg_normal", "#ffffff", CFGF_NONE), + CFG_STR("bg_normal", "#000000", CFGF_NONE), + CFG_STR("fg_focus", "#ffffff", CFGF_NONE), + CFG_STR("bg_focus", "#000000", CFGF_NONE), + CFG_SEC("item", menu_items_opts, CFGF_MULTI), + CFG_END() +}; + +cfg_opt_t menu_opts[] = +{ + CFG_SEC("set_menu", menus_opts, CFGF_MULTI), + CFG_END() +}; + +/* }}} */ + +/* KEYBIND {{{ */ + cfg_opt_t key_opts[] = { CFG_STR_LIST("mod", "{Control}", CFGF_NONE), @@ -150,6 +192,10 @@ cfg_opt_t keys_opts[] = CFG_END() }; +/* }}} */ + +/* ALIAS {{{ */ + cfg_opt_t _alias_opts[] = { CFG_STR("content", "", CFGF_NONE), @@ -162,6 +208,8 @@ cfg_opt_t alias_opts[] = CFG_END() }; +/* }}} */ + cfg_opt_t opts[] = { CFG_SEC("misc", misc_opts, CFGF_NONE), @@ -171,6 +219,7 @@ cfg_opt_t opts[] = CFG_SEC("bar", bar_opts, CFGF_NONE), CFG_SEC("layouts", layouts_opts, CFGF_NONE), CFG_SEC("tags", tags_opts, CFGF_NONE), + CFG_SEC("menu", menu_opts, CFGF_NONE), CFG_SEC("keys", keys_opts, CFGF_NONE), CFG_END() }; diff --git a/src/menu.c b/src/menu.c index d500cc7..ef6b59d 100644 --- a/src/menu.c +++ b/src/menu.c @@ -33,12 +33,13 @@ #include "wmfs.h" void -menu_init(Menu *menu, int nitem, uint bg_f, char *fg_f, uint bg_n, char *fg_n) +menu_init(Menu *menu, char *name, int nitem, uint bg_f, char *fg_f, uint bg_n, char *fg_n) { /* Item */ menu->nitem = nitem; menu->item = emalloc(sizeof(MenuItem), nitem); + menu->name = name; /* Colors */ menu->colors.focus.bg = bg_f; @@ -215,8 +216,6 @@ menu_draw_item_name(Menu *menu, int item, BarWindow *winitem[]) return; } - - int menu_get_longer_string(MenuItem *mt, int nitem) { @@ -228,3 +227,27 @@ menu_get_longer_string(MenuItem *mt, int nitem) return l + PAD; } + +void +uicb_menu(uicb_t cmd) +{ + int i, d, u, x, y; + Window w; + + for(i = 0; i < conf.nmenu; ++i) + if(!strcmp(cmd, conf.menu[i].name)) + { + if(conf.menu[i].place_at_mouse) + XQueryPointer(dpy, ROOT, &w, &w, &x, &y, &d, &d, (uint *)&u); + else + { + screen_get_sel(); + x = sgeo[selscreen].x + conf.menu[i].x; + y = sgeo[selscreen].y + conf.menu[i].y; + } + + menu_draw(conf.menu[i], x, y); + } + + return; +} diff --git a/src/structs.h b/src/structs.h index 334c9d9..7c5efae 100644 --- a/src/structs.h +++ b/src/structs.h @@ -211,6 +211,14 @@ typedef struct /* Menu Struct */ typedef struct { + /* Name of the menu for call + * it in the conf (function = "menu" + * menu = ""). + */ + char *name; + /* Placement */ + Bool place_at_mouse; + int x, y; /* Color */ struct { @@ -288,12 +296,14 @@ typedef struct } border; Alias alias[256]; Layout layout[NUM_OF_LAYOUT]; + Menu *menu; int *ntag; Bool tag_round; Bool layout_system; /* Switch: False, Menu: True. */ int nkeybind; int nbutton; int nlayout; + int nmenu; } Conf; /* Config.c struct */ diff --git a/src/wmfs.h b/src/wmfs.h index b6e86d2..d91d46f 100644 --- a/src/wmfs.h +++ b/src/wmfs.h @@ -176,6 +176,7 @@ void conf_root_section(cfg_t *cfg_r); void conf_client_section(cfg_t *cfg_c); void conf_layout_section(cfg_t *cfg_l); void conf_tag_section(cfg_t *cfg_t); +void conf_menu_section(cfg_t *cfg_m); void conf_keybind_section(cfg_t *cfg_k); void init_conf(void); @@ -194,14 +195,14 @@ void propertynotify(XPropertyEvent *ev); void getevent(XEvent ev); /* menu.c */ -void menu_init(Menu *menu, int nitem, uint bg_f, char *fg_f, uint bg_n, char *fg_n); +void menu_init(Menu *menu, char *name, int nitem, uint bg_f, char *fg_f, uint bg_n, char *fg_n); void menu_new_item(MenuItem *mi, char *name, void *func, char *cmd); void menu_draw(Menu menu, int x, int y); Bool menu_manage_event(XEvent *ev, Menu *menu, BarWindow *winitem[]); void menu_focus_item(Menu *menu, int item, BarWindow *winitem[]); void menu_draw_item_name(Menu *menu, int item, BarWindow *winitem[]); int menu_get_longer_string(MenuItem *mt, int nitem); - +void uicb_menu(uicb_t cmd); /* mouse.c */ void mouse_move(Client *c); void mouse_resize(Client *c);