add support for keybinds that work in any mode

This commit is contained in:
speedie 2023-03-06 19:13:38 +01:00
parent 7e98a40c02
commit 0b0cfa5d36
4 changed files with 16 additions and 19 deletions

View file

@ -19,6 +19,7 @@
*/
/* Modes
* -1: Any mode
* 0: Normal mode
* 1: Insert mode
*
@ -42,11 +43,7 @@ static Key keys[] = {
{ 1, 0, XK_Down, move, {.i = 2 } },
{ 1, 0, XK_Left, move, {.i = 3 } },
{ 1, 0, XK_Right, move, {.i = 4 } },
{ 1, CONTROL, XK_v, paste, {.i = 1 } }, /* primary buffer */
{ 1, CONTROL|SHIFT, XK_v, paste, {.i = 2 } },
{ 1, 0, XK_BackSpace, backspace, {0} },
{ 1, 0, XK_Return, selectitem, {.i = +1 } },
{ 1, 0, XK_Tab, complete, {0} },
/* normal mode
*
@ -67,8 +64,6 @@ static Key keys[] = {
{ 0, 0, XK_j, move, {.i = 2 } },
{ 0, 0, XK_h, move, {.i = 3 } },
{ 0, 0, XK_l, move, {.i = 4 } },
{ 0, CONTROL, XK_v, paste, {.i = 1 } }, /* primary buffer */
{ 0, CONTROL|SHIFT, XK_v, paste, {.i = 2 } },
{ 0, CONTROL, XK_k, restoresel, {0} },
{ 0, CONTROL, XK_r, viewhist, {0} },
{ 0, CONTROL, XK_u, clear, {0} },
@ -79,10 +74,16 @@ static Key keys[] = {
{ 0, SHIFT, XK_g, moveend, {0} },
{ 0, 0, XK_Next, movenext, {0} },
{ 0, 0, XK_Prior, moveprev, {0} },
{ 0, 0, XK_Return, selectitem, {.i = +1 } },
{ 0, 0, XK_Tab, complete, {0} },
{ 0, MODIFIER1, XK_b, moveword, {.i = -1 } },
{ 0, MODIFIER1, XK_f, moveword, {.i = +1 } },
{ 0, MODIFIER1, XK_p, navhistory, {.i = -1 } },
{ 0, MODIFIER1, XK_n, navhistory, {.i = +1 } },
/* any mode
*
* mode modifier key function argument */
{ -1, 0, XK_Return, selectitem, {.i = +1 } },
{ -1, 0, XK_Tab, complete, {0} },
{ -1, CONTROL, XK_v, paste, {.i = 1 } }, /* primary buffer */
{ -1, CONTROL|SHIFT, XK_v, paste, {.i = 2 } },
};

View file

@ -27,6 +27,8 @@ readargs(int argc, char *argv[])
if (!strcmp(argv[i], "-v")) { /* prints version information */
puts("spmenu-"VERSION);
exit(0);
} else if (!strcmp(argv[i], "-h")) { /* help */
usage();
} else if (!strcmp(argv[i], "-it")) { /* image: top */
imageposition = 0;
} else if (!strcmp(argv[i], "-ib")) { /* image: bottom */
@ -120,7 +122,7 @@ readargs(int argc, char *argv[])
} else if (!strcmp(argv[i], "-si")) { /* don't hide image */
hideimage = 0;
} else if (i + 1 == argc)
usage();
fprintf(stderr, "spmenu: Invalid argument: '%s'\n", argv[i]);
/* these options take one argument */
else if (!strcmp(argv[i], "-g")) { /* number of columns in grid */
@ -267,7 +269,7 @@ readargs(int argc, char *argv[])
else if (!strcmp(argv[i], "-n")) /* preselected item */
preselected = atoi(argv[++i]);
else
usage();
fprintf(stderr, "spmenu: Invalid argument: '%s'\n", argv[i]);
}
void

View file

@ -1,11 +1,5 @@
static char modetext[16] = "Insert"; /* default mode text */
/* available modes */
typedef enum mode {
Normal,
Insert,
} image_mode;
/* mode settings */
static int curMode = 1; /* 0 is command mode */
static int allowkeys = 1; /* whether or not to interpret a keypress as an insertion */

View file

@ -1090,7 +1090,7 @@ keypress(XEvent *e)
for (i = 0; i < LENGTH(keys); i++) {
if (keysym == keys[i].keysym && CLEANMASK(keys[i].mod) == CLEANMASK(ev->state) && keys[i].func)
if (keys[i].mode && curMode) {
if (keys[i].mode && curMode || keys[i].mode == -1) {
keys[i].func(&(keys[i].arg));
return;
} else if (!keys[i].mode && !curMode) {