aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2020-06-17 00:00:51 +0530
committerAkshay Nair <phenax5@gmail.com>2020-06-17 00:00:51 +0530
commitede2f9fcacede3201fb3db8b0d38717ddad7c1b7 (patch)
tree65e2b942fb7fd0c97709dcddb1591fed3f5fc5ae
parentd6639cf420aa7a23466cf6005f1e4b069ba839b0 (diff)
downloadshotkey-ede2f9fcacede3201fb3db8b0d38717ddad7c1b7.tar.gz
shotkey-ede2f9fcacede3201fb3db8b0d38717ddad7c1b7.zip
Adds escape key to quit mode
-rw-r--r--daemonic.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/daemonic.c b/daemonic.c
index 580794f..d2c90cb 100644
--- a/daemonic.c
+++ b/daemonic.c
@@ -59,12 +59,9 @@ void run(Display* dpy, Window win, Command command) {
unsigned int i;
if (command.command) {
- printf("Running cmd %s\n", command.command);
char* cmd[] = {shell, "-c", command.command, NULL};
spawn(cmd);
} else if(command.mode != -1) {
- printf("Enabling mode %d\n", command.mode);
-
current_mode = command.mode;
if (modes[current_mode] && current_mode < MODE_SIZE) {
@@ -73,8 +70,9 @@ void run(Display* dpy, Window win, Command command) {
bind_key(dpy, win, keys[i].mod, keys[i].key);
}
}
- // TODO: Bind keys associated with mode
- // TODO: Bind Escape
+
+ // Bind an escape key to quit mode
+ bind_key(dpy, win, 0, XK_Escape);
}
}
@@ -83,9 +81,8 @@ void keypress(Display *dpy, Window win, XKeyEvent *ev) {
Key mode_key;
KeySym keysym = XKeycodeToKeysym(dpy, (KeyCode) ev->keycode, 0);
- printf("kpress\n");
-
if (current_mode == -1) {
+ // Bind all the normal mode keys
for (i = 0; i < LENGTH(keys); i++) {
if (keysym == keys[i].key && CLEANMASK(keys[i].mod) == CLEANMASK(ev->state)) {
run(dpy, win, keys[i].command);
@@ -105,8 +102,11 @@ 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, keys[i].mod, keys[i].key);
+ unbind_key(dpy, win, mode_key.mod, mode_key.key);
}
+
+ // Unbind escape key
+ unbind_key(dpy, win, 0, XK_Escape);
}
current_mode = -1;
@@ -135,6 +135,7 @@ int main() {
switch (ev.type) {
case KeyPress: {
keypress(dpy, root, &ev.xkey);
+ break;
}
}
}