aboutsummaryrefslogtreecommitdiff
path: root/daemonic.c
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2020-06-17 11:04:48 +0530
committerAkshay Nair <phenax5@gmail.com>2020-06-17 11:04:48 +0530
commita54d2bcc102d8c30ff0e07f024458f2c61b3a7e3 (patch)
tree5a76e8a544a7afb0cc679871047cf3cc2b53cdfc /daemonic.c
parentd2e74bf6b19f5669ff22b0c7cb6600e78de2cf03 (diff)
downloadshotkey-a54d2bcc102d8c30ff0e07f024458f2c61b3a7e3.tar.gz
shotkey-a54d2bcc102d8c30ff0e07f024458f2c61b3a7e3.zip
Adds persistent key modes
Diffstat (limited to '')
-rw-r--r--daemonic.c31
1 files changed, 21 insertions, 10 deletions
diff --git a/daemonic.c b/daemonic.c
index bb22d47..881034f 100644
--- a/daemonic.c
+++ b/daemonic.c
@@ -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;
+ }
}
}