aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorkoekeishiya <aasvi93@hotmail.com>2018-05-10 16:49:33 +0200
committerkoekeishiya <aasvi93@hotmail.com>2018-05-10 16:49:33 +0200
commitc5f03f1f96c7f707c078c3b6e4355808033127a0 (patch)
treeabc6de2e2b035fd164d97fa76bd9a73823ff8340 /src
parent73abf77e71c75aaea8ee181da26b7994ba69de6f (diff)
downloadskhd-c5f03f1f96c7f707c078c3b6e4355808033127a0.tar.gz
skhd-c5f03f1f96c7f707c078c3b6e4355808033127a0.zip
#15 update sample and code cleanup
Diffstat (limited to 'src')
-rw-r--r--src/hotkey.c37
-rw-r--r--src/skhd.c2
2 files changed, 23 insertions, 16 deletions
diff --git a/src/hotkey.c b/src/hotkey.c
index a6d03b9..40894f1 100644
--- a/src/hotkey.c
+++ b/src/hotkey.c
@@ -83,7 +83,7 @@ unsigned long hash_mode(char *key)
return hash;
}
-internal bool
+internal void
fork_and_exec(char *command)
{
local_persist char arg[] = "-c";
@@ -99,26 +99,32 @@ fork_and_exec(char *command)
int status_code = execvp(exec[0], exec);
exit(status_code);
}
+}
- return true;
+internal inline bool
+passthrough(struct hotkey *hotkey)
+{
+ return !has_flags(hotkey, Hotkey_Flag_Passthrough);
}
-bool find_and_exec_hotkey(struct hotkey *eventkey, struct table *mode_map, struct mode **current_mode)
+internal inline struct hotkey *
+find_hotkey(struct mode *mode, struct hotkey *hotkey)
{
- struct hotkey *hotkey;
- if ((hotkey = table_find(&(*current_mode)->hotkey_map, eventkey))) {
- bool capture = (*current_mode)->capture || !has_flags(hotkey, Hotkey_Flag_Passthrough);
- char *command = hotkey->command;
+ return table_find(&mode->hotkey_map, hotkey);
+}
- if (has_flags(hotkey, Hotkey_Flag_Activate)) {
- *current_mode = table_find(mode_map, hotkey->command);
- command = (*current_mode)->command;
- if (!command) return capture;
+bool find_and_exec_hotkey(struct hotkey *k, struct table *t, struct mode **m)
+{
+ bool c = (*m)->capture;
+ for (struct hotkey *h = find_hotkey(*m, k); h; c |= passthrough(h), h = 0) {
+ char *cmd = h->command;
+ if (has_flags(h, Hotkey_Flag_Activate)) {
+ *m = table_find(t, cmd);
+ cmd = (*m)->command;
}
-
- if (fork_and_exec(command)) return capture;
+ if (cmd) fork_and_exec(cmd);
}
- return false;
+ return c;
}
void free_mode_map(struct table *mode_map)
@@ -137,7 +143,7 @@ void free_mode_map(struct table *mode_map)
for (int i = 0; i < buf_len(freed_pointers); ++i) {
if (freed_pointers[i] == hotkey) {
- continue;
+ goto next;
}
}
@@ -145,6 +151,7 @@ void free_mode_map(struct table *mode_map)
buf_free(hotkey->mode_list);
free(hotkey->command);
free(hotkey);
+next:;
}
if (hk_count) free(hotkeys);
diff --git a/src/skhd.c b/src/skhd.c
index ee8772c..5056507 100644
--- a/src/skhd.c
+++ b/src/skhd.c
@@ -29,7 +29,7 @@
extern bool CGSIsSecureEventInputSet();
#define secure_keyboard_entry_enabled CGSIsSecureEventInputSet
-#if 0
+#if 1
#define BEGIN_TIMED_BLOCK() \
clock_t timed_block_begin = clock()
#define END_TIMED_BLOCK() \