aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorkoekeishiya <aasvi93@hotmail.com>2018-05-10 15:42:48 +0200
committerkoekeishiya <aasvi93@hotmail.com>2018-05-10 15:42:48 +0200
commitff8f00afc858d2f9979966a36e90278e6aaae517 (patch)
treed23875ac4799d10a28e0a13b3db01afa3002d0ca /src
parent847c2c873c06a3866981834d29eccef1041f5410 (diff)
downloadskhd-ff8f00afc858d2f9979966a36e90278e6aaae517.tar.gz
skhd-ff8f00afc858d2f9979966a36e90278e6aaae517.zip
#15 cleanup code
Diffstat (limited to 'src')
-rw-r--r--src/hotkey.c10
-rw-r--r--src/skhd.c9
2 files changed, 7 insertions, 12 deletions
diff --git a/src/hotkey.c b/src/hotkey.c
index 2de3a10..a6d03b9 100644
--- a/src/hotkey.c
+++ b/src/hotkey.c
@@ -1,5 +1,4 @@
#include "hotkey.h"
-#include <stdlib.h>
#define internal static
#define local_persist static
@@ -124,23 +123,24 @@ bool find_and_exec_hotkey(struct hotkey *eventkey, struct table *mode_map, struc
void free_mode_map(struct table *mode_map)
{
+ struct hotkey **freed_pointers = NULL;
+
int mode_count;
void **modes = table_reset(mode_map, &mode_count);
- if (!mode_count) return;
-
- struct hotkey **freed_pointers = NULL;
for (int mode_index = 0; mode_index < mode_count; ++mode_index) {
struct mode *mode = (struct mode *) modes[mode_index];
+
int hk_count;
void **hotkeys = table_reset(&mode->hotkey_map, &hk_count);
-
for (int hk_index = 0; hk_index < hk_count; ++hk_index) {
struct hotkey *hotkey = (struct hotkey *) hotkeys[hk_index];
+
for (int i = 0; i < buf_len(freed_pointers); ++i) {
if (freed_pointers[i] == hotkey) {
continue;
}
}
+
buf_push(freed_pointers, hotkey);
buf_free(hotkey->mode_list);
free(hotkey->command);
diff --git a/src/skhd.c b/src/skhd.c
index 7250ba5..5056507 100644
--- a/src/skhd.c
+++ b/src/skhd.c
@@ -6,13 +6,11 @@
#include <signal.h>
#include <string.h>
#include <unistd.h>
-
#include <Carbon/Carbon.h>
#define HASHTABLE_IMPLEMENTATION
#include "hashtable.h"
#include "sbuffer.h"
-
#include "hotload.h"
#include "event_tap.h"
#include "locale.h"
@@ -46,8 +44,8 @@ extern bool CGSIsSecureEventInputSet();
internal unsigned major_version = 0;
internal unsigned minor_version = 0;
internal unsigned patch_version = 14;
-internal struct table mode_map;
internal struct mode *current_mode;
+internal struct table mode_map;
internal char *config_file;
internal void
@@ -198,11 +196,8 @@ int main(int argc, char **argv)
set_config_path();
}
- table_init(&mode_map, 13,
- (table_hash_func) hash_mode,
- (table_compare_func) same_mode);
-
printf("skhd: using config '%s'\n", config_file);
+ table_init(&mode_map, 13, (table_hash_func) hash_mode, (table_compare_func) same_mode);
parse_config_helper(config_file);
signal(SIGCHLD, SIG_IGN);