From 7b166488b17ae35da1cbcb86e645a68a174e93a2 Mon Sep 17 00:00:00 2001 From: phillbush Date: Wed, 16 Sep 2020 22:06:12 -0300 Subject: [PATCH] now user can set custom key bindings in config.h --- config.h | 25 +++++++++++++++++++++++++ xmenu.c | 12 ++++++------ 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/config.h b/config.h index aec217e..ae7e59a 100644 --- a/config.h +++ b/config.h @@ -32,3 +32,28 @@ static struct Config config = { /* area around the icon, the triangle and the separator */ .horzpadding = 8, }; + +/* + * KEYBINDINGS + * + * Look at your /usr/include/X11/keysymdef.h (or the equivalent file + * in your system) for a list of key symbol constants, and change the + * macros below accordingly. Note there IS NO equal sign (=) between + * the macros and their values. All key symbol constants begin with + * the prefix XK_ + * + * For example, to use vim-like key bindings, set KEYSYMLEFT to XK_h, + * KEYSYMDOWN to XK_j, KEYSYMUP to XK_k, etc. + * + * Note that the regular keys like ArrowUp, ArrowDown, Tab, Home, etc + * will ALWAYS work, so you do not need to set them. + * + * If you do not want to set a key binding, keep it with the value of + * XK_VoidSymbol + */ +#define KSYMFIRST XK_VoidSymbol /* select first item */ +#define KSYMLAST XK_VoidSymbol /* select last item */ +#define KSYMUP XK_VoidSymbol /* select previous item */ +#define KSYMDOWN XK_VoidSymbol /* select next item */ +#define KSYMLEFT XK_VoidSymbol /* close current menu */ +#define KSYMRIGHT XK_VoidSymbol /* enter selected item */ diff --git a/xmenu.c b/xmenu.c index 2a8de09..0cc56ac 100644 --- a/xmenu.c +++ b/xmenu.c @@ -1272,19 +1272,19 @@ selectitem: /* cycle through menu */ item = NULL; - if (ksym == XK_Home) { + if (ksym == XK_Home || ksym == KSYMFIRST) { item = itemcycle(currmenu, ITEMFIRST); - } else if (ksym == XK_End) { + } else if (ksym == XK_End || ksym == KSYMLAST) { item = itemcycle(currmenu, ITEMLAST); - } else if (ksym == XK_ISO_Left_Tab || ksym == XK_Up) { + } else if (ksym == XK_ISO_Left_Tab || ksym == XK_Up || ksym == KSYMUP) { item = itemcycle(currmenu, ITEMPREV); - } else if (ksym == XK_Tab || ksym == XK_Down) { + } else if (ksym == XK_Tab || ksym == XK_Down || ksym == KSYMDOWN) { item = itemcycle(currmenu, ITEMNEXT); - } else if ((ksym == XK_Return || ksym == XK_Right) && + } else if ((ksym == XK_Return || ksym == XK_Right || ksym == KSYMRIGHT) && currmenu->selected != NULL) { item = currmenu->selected; goto selectitem; - } else if ((ksym == XK_Escape || ksym == XK_Left) && + } else if ((ksym == XK_Escape || ksym == XK_Left || ksym == KSYMLEFT) && currmenu->parent != NULL) { item = currmenu->parent->selected; currmenu = currmenu->parent;