diff options
| author | Akshay Nair <phenax5@gmail.com> | 2020-06-17 11:04:48 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2020-06-17 11:04:48 +0530 |
| commit | a54d2bcc102d8c30ff0e07f024458f2c61b3a7e3 (patch) | |
| tree | 5a76e8a544a7afb0cc679871047cf3cc2b53cdfc | |
| parent | d2e74bf6b19f5669ff22b0c7cb6600e78de2cf03 (diff) | |
| download | shotkey-a54d2bcc102d8c30ff0e07f024458f2c61b3a7e3.tar.gz shotkey-a54d2bcc102d8c30ff0e07f024458f2c61b3a7e3.zip | |
Adds persistent key modes
Diffstat (limited to '')
| -rw-r--r-- | config.h | 8 | ||||
| -rw-r--r-- | daemonic.c | 31 |
2 files changed, 25 insertions, 14 deletions
@@ -18,15 +18,15 @@ static Key modes[MODE_SIZE][10] = { { 0, XK_m, cmd("notify-send inside_music") }, }, [Bright] = { - { 0, XK_m, cmd("notify-send inside_bright") }, - { 0, XK_n, cmd("notify-send inside_bright_1") }, + { 0, XK_m, cmd("notify-send inside_bright") }, + { 0, XK_n, cmd("notify-send inside_bright_1") }, }, }; // Define normal mode key bindings here static Key keys[] = { { MOD|ShiftMask, XK_y, cmd("notify-send hello") }, - { MOD|ShiftMask, XK_z, mode(Music) }, - { MOD|ShiftMask, XK_x, mode(Bright) }, + { MOD|ShiftMask, XK_z, mode(Music, False) }, + { MOD|ShiftMask, XK_x, mode(Bright, True) }, }; @@ -7,6 +7,7 @@ typedef struct Command { char* command; unsigned int mode; + int persist; } Command; typedef struct Key { @@ -15,8 +16,8 @@ typedef struct Key { Command command; } Key; -#define cmd(c) (Command) { c, -1 } -#define mode(m) (Command) { NULL, m } +#define cmd(c) (Command) { c, -1, False } +#define mode(m, p) (Command) { NULL, m, p } #include "config.h" @@ -24,6 +25,7 @@ typedef struct Key { #define CLEANMASK(mask) (mask & ~LockMask & (ShiftMask|ControlMask|Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask)) int current_mode = -1; +int is_mode_persistent = 0; void bind_key(Display *dpy, Window win, unsigned int mod, KeySym key) { int keycode = XKeysymToKeycode(dpy, key); @@ -63,6 +65,7 @@ void run(Display* dpy, Window win, Command command) { spawn(cmd); } else if(command.mode != -1) { current_mode = command.mode; + is_mode_persistent = command.persist; if (modes[current_mode] && current_mode < MODE_SIZE) { for (i = 0; i < LENGTH(modes[current_mode]); i++) { @@ -89,6 +92,9 @@ void keypress(Display *dpy, Window win, XKeyEvent *ev) { } } } else { + // Escape key + is_mode_persistent = is_mode_persistent && ev->keycode != 9; + if (modes[current_mode] && current_mode < MODE_SIZE) { // Check if key is in mode and execute for (i = 0; i < LENGTH(modes[current_mode]); i++) { @@ -99,17 +105,22 @@ void keypress(Display *dpy, Window win, XKeyEvent *ev) { } } - // Unbind mode related keys - for (i = 0; i < LENGTH(modes[current_mode]); i++) { - mode_key = modes[current_mode][i]; - unbind_key(dpy, win, mode_key.mod, mode_key.key); - } + if (!is_mode_persistent) { + // Unbind mode related keys + for (i = 0; i < LENGTH(modes[current_mode]); i++) { + mode_key = modes[current_mode][i]; + unbind_key(dpy, win, mode_key.mod, mode_key.key); + } - // Unbind escape key - unbind_key(dpy, win, 0, XK_Escape); + // Unbind escape key + unbind_key(dpy, win, 0, XK_Escape); + } } - current_mode = -1; + if (!is_mode_persistent) { + current_mode = -1; + is_mode_persistent = False; + } } } |
