conf/menu: Add menu support in the configuration file: menu { set_menu { ... } } (See the default configuration) And call it with a keybind or mousebind : func = "menu" cmd = "<menu name>".
This commit is contained in:
parent
33234f2266
commit
2d26778835
68
src/config.c
68
src/config.c
@ -65,7 +65,8 @@ conf_init_func_list(void)
|
|||||||
{"screen_prev", uicb_screen_prev },
|
{"screen_prev", uicb_screen_prev },
|
||||||
{"reload", uicb_reload },
|
{"reload", uicb_reload },
|
||||||
{"launcher", uicb_launcher },
|
{"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));
|
func_list = emalloc(LEN(tmp_list), sizeof(func_name_list_t));
|
||||||
@ -209,7 +210,7 @@ conf_layout_section(cfg_t *cfg_l)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(conf.layout_system)
|
if(conf.layout_system)
|
||||||
menu_init(&menulayout, conf.nlayout,
|
menu_init(&menulayout, "menulayout", conf.nlayout,
|
||||||
/* Colors */
|
/* Colors */
|
||||||
conf.colors.layout_bg,
|
conf.colors.layout_bg,
|
||||||
conf.colors.layout_fg,
|
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
|
/* If there is no tag in the conf or more than
|
||||||
* MAXTAG (32) print an error and create only one.
|
* 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.tag_round = cfg_getbool(cfg_t, "tag_round");
|
||||||
conf.colors.tagselfg = strdup(alias_to_str(cfg_getstr(cfg_t, "sel_fg")));
|
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);
|
" (%d) in the screen %d\n", conf.ntag[i], i);
|
||||||
|
|
||||||
conf.ntag[i] = 1;
|
conf.ntag[i] = 1;
|
||||||
tags[i][1].name = strdup("WMFS");
|
tags[i][1] = default_tag;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
seltag = emalloc(screen_count(), sizeof(int));
|
seltag = emalloc(screen_count(), sizeof(int));
|
||||||
@ -311,6 +308,56 @@ conf_tag_section(cfg_t *cfg_t)
|
|||||||
return;
|
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
|
void
|
||||||
conf_keybind_section(cfg_t *cfg_k)
|
conf_keybind_section(cfg_t *cfg_k)
|
||||||
{
|
{
|
||||||
@ -372,6 +419,7 @@ init_conf(void)
|
|||||||
conf_client_section(cfg_getsec(cfg, "client"));
|
conf_client_section(cfg_getsec(cfg, "client"));
|
||||||
conf_layout_section(cfg_getsec(cfg, "layouts"));
|
conf_layout_section(cfg_getsec(cfg, "layouts"));
|
||||||
conf_tag_section(cfg_getsec(cfg, "tags"));
|
conf_tag_section(cfg_getsec(cfg, "tags"));
|
||||||
|
conf_menu_section(cfg_getsec(cfg, "menu"));
|
||||||
conf_keybind_section(cfg_getsec(cfg, "keys"));
|
conf_keybind_section(cfg_getsec(cfg, "keys"));
|
||||||
|
|
||||||
cfg_free(cfg);
|
cfg_free(cfg);
|
||||||
|
|||||||
@ -95,6 +95,8 @@ cfg_opt_t client_opts[]=
|
|||||||
CFG_END()
|
CFG_END()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* TAGS {{{ */
|
||||||
|
|
||||||
cfg_opt_t layout_opts[] =
|
cfg_opt_t layout_opts[] =
|
||||||
{
|
{
|
||||||
CFG_STR("type", "", CFGF_NONE),
|
CFG_STR("type", "", CFGF_NONE),
|
||||||
@ -112,6 +114,10 @@ cfg_opt_t layouts_opts[] =
|
|||||||
CFG_END()
|
CFG_END()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* }}} */
|
||||||
|
|
||||||
|
/* TAGS {{{ */
|
||||||
|
|
||||||
cfg_opt_t tag_opts[] =
|
cfg_opt_t tag_opts[] =
|
||||||
{
|
{
|
||||||
CFG_INT("screen", -1, CFGF_NONE),
|
CFG_INT("screen", -1, CFGF_NONE),
|
||||||
@ -135,6 +141,42 @@ cfg_opt_t tags_opts[] =
|
|||||||
CFG_END()
|
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_opt_t key_opts[] =
|
||||||
{
|
{
|
||||||
CFG_STR_LIST("mod", "{Control}", CFGF_NONE),
|
CFG_STR_LIST("mod", "{Control}", CFGF_NONE),
|
||||||
@ -150,6 +192,10 @@ cfg_opt_t keys_opts[] =
|
|||||||
CFG_END()
|
CFG_END()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* }}} */
|
||||||
|
|
||||||
|
/* ALIAS {{{ */
|
||||||
|
|
||||||
cfg_opt_t _alias_opts[] =
|
cfg_opt_t _alias_opts[] =
|
||||||
{
|
{
|
||||||
CFG_STR("content", "", CFGF_NONE),
|
CFG_STR("content", "", CFGF_NONE),
|
||||||
@ -162,6 +208,8 @@ cfg_opt_t alias_opts[] =
|
|||||||
CFG_END()
|
CFG_END()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* }}} */
|
||||||
|
|
||||||
cfg_opt_t opts[] =
|
cfg_opt_t opts[] =
|
||||||
{
|
{
|
||||||
CFG_SEC("misc", misc_opts, CFGF_NONE),
|
CFG_SEC("misc", misc_opts, CFGF_NONE),
|
||||||
@ -171,6 +219,7 @@ cfg_opt_t opts[] =
|
|||||||
CFG_SEC("bar", bar_opts, CFGF_NONE),
|
CFG_SEC("bar", bar_opts, CFGF_NONE),
|
||||||
CFG_SEC("layouts", layouts_opts, CFGF_NONE),
|
CFG_SEC("layouts", layouts_opts, CFGF_NONE),
|
||||||
CFG_SEC("tags", tags_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_SEC("keys", keys_opts, CFGF_NONE),
|
||||||
CFG_END()
|
CFG_END()
|
||||||
};
|
};
|
||||||
|
|||||||
29
src/menu.c
29
src/menu.c
@ -33,12 +33,13 @@
|
|||||||
#include "wmfs.h"
|
#include "wmfs.h"
|
||||||
|
|
||||||
void
|
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 */
|
/* Item */
|
||||||
menu->nitem = nitem;
|
menu->nitem = nitem;
|
||||||
menu->item = emalloc(sizeof(MenuItem), nitem);
|
menu->item = emalloc(sizeof(MenuItem), nitem);
|
||||||
|
menu->name = name;
|
||||||
|
|
||||||
/* Colors */
|
/* Colors */
|
||||||
menu->colors.focus.bg = bg_f;
|
menu->colors.focus.bg = bg_f;
|
||||||
@ -215,8 +216,6 @@ menu_draw_item_name(Menu *menu, int item, BarWindow *winitem[])
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
menu_get_longer_string(MenuItem *mt, int nitem)
|
menu_get_longer_string(MenuItem *mt, int nitem)
|
||||||
{
|
{
|
||||||
@ -228,3 +227,27 @@ menu_get_longer_string(MenuItem *mt, int nitem)
|
|||||||
|
|
||||||
return l + PAD;
|
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;
|
||||||
|
}
|
||||||
|
|||||||
@ -211,6 +211,14 @@ typedef struct
|
|||||||
/* Menu Struct */
|
/* Menu Struct */
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
|
/* Name of the menu for call
|
||||||
|
* it in the conf (function = "menu"
|
||||||
|
* menu = "<name>").
|
||||||
|
*/
|
||||||
|
char *name;
|
||||||
|
/* Placement */
|
||||||
|
Bool place_at_mouse;
|
||||||
|
int x, y;
|
||||||
/* Color */
|
/* Color */
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
@ -288,12 +296,14 @@ typedef struct
|
|||||||
} border;
|
} border;
|
||||||
Alias alias[256];
|
Alias alias[256];
|
||||||
Layout layout[NUM_OF_LAYOUT];
|
Layout layout[NUM_OF_LAYOUT];
|
||||||
|
Menu *menu;
|
||||||
int *ntag;
|
int *ntag;
|
||||||
Bool tag_round;
|
Bool tag_round;
|
||||||
Bool layout_system; /* Switch: False, Menu: True. */
|
Bool layout_system; /* Switch: False, Menu: True. */
|
||||||
int nkeybind;
|
int nkeybind;
|
||||||
int nbutton;
|
int nbutton;
|
||||||
int nlayout;
|
int nlayout;
|
||||||
|
int nmenu;
|
||||||
} Conf;
|
} Conf;
|
||||||
|
|
||||||
/* Config.c struct */
|
/* Config.c struct */
|
||||||
|
|||||||
@ -176,6 +176,7 @@ void conf_root_section(cfg_t *cfg_r);
|
|||||||
void conf_client_section(cfg_t *cfg_c);
|
void conf_client_section(cfg_t *cfg_c);
|
||||||
void conf_layout_section(cfg_t *cfg_l);
|
void conf_layout_section(cfg_t *cfg_l);
|
||||||
void conf_tag_section(cfg_t *cfg_t);
|
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 conf_keybind_section(cfg_t *cfg_k);
|
||||||
void init_conf(void);
|
void init_conf(void);
|
||||||
|
|
||||||
@ -194,14 +195,14 @@ void propertynotify(XPropertyEvent *ev);
|
|||||||
void getevent(XEvent ev);
|
void getevent(XEvent ev);
|
||||||
|
|
||||||
/* menu.c */
|
/* 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_new_item(MenuItem *mi, char *name, void *func, char *cmd);
|
||||||
void menu_draw(Menu menu, int x, int y);
|
void menu_draw(Menu menu, int x, int y);
|
||||||
Bool menu_manage_event(XEvent *ev, Menu *menu, BarWindow *winitem[]);
|
Bool menu_manage_event(XEvent *ev, Menu *menu, BarWindow *winitem[]);
|
||||||
void menu_focus_item(Menu *menu, int item, BarWindow *winitem[]);
|
void menu_focus_item(Menu *menu, int item, BarWindow *winitem[]);
|
||||||
void menu_draw_item_name(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);
|
int menu_get_longer_string(MenuItem *mt, int nitem);
|
||||||
|
void uicb_menu(uicb_t cmd);
|
||||||
/* mouse.c */
|
/* mouse.c */
|
||||||
void mouse_move(Client *c);
|
void mouse_move(Client *c);
|
||||||
void mouse_resize(Client *c);
|
void mouse_resize(Client *c);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user