diff options
author | koekeishiya <aasvi93@hotmail.com> | 2020-05-02 23:43:26 +0200 |
---|---|---|
committer | koekeishiya <aasvi93@hotmail.com> | 2020-05-02 23:43:39 +0200 |
commit | 62ba56b82c32bc9754b733fa8ea48378f417c058 (patch) | |
tree | 026247f8ff7a6ea2cd3041e501c3ac71ab28e80f /src/skhd.c | |
parent | 1fbce35a78563f915f3699724623295020f66167 (diff) | |
download | skhd-62ba56b82c32bc9754b733fa8ea48378f417c058.tar.gz skhd-62ba56b82c32bc9754b733fa8ea48378f417c058.zip |
#127 notify when secure keyboard input is enabled/disabled
Diffstat (limited to 'src/skhd.c')
-rw-r--r-- | src/skhd.c | 25 |
1 files changed, 25 insertions, 0 deletions
@@ -11,6 +11,8 @@ #include <sys/uio.h> #include <unistd.h> #include <Carbon/Carbon.h> +#include <CoreFoundation/CoreFoundation.h> +#include <objc/objc-runtime.h> #include "timing.h" #include "log.h" @@ -34,11 +36,18 @@ #include "parse.c" #include "hotkey.c" #include "synthesize.c" +#include "notify.c" +extern void NSApplicationLoad(void); +extern int CGSMainConnectionID(void); extern CFDictionaryRef CGSCopyCurrentSessionDictionary(void); extern bool CGSIsSecureEventInputSet(void); #define secure_keyboard_entry_enabled CGSIsSecureEventInputSet +#define GLOBAL_CONNECTION_CALLBACK(name) void name(uint32_t type, void *data, size_t data_length, void *context) +typedef GLOBAL_CONNECTION_CALLBACK(global_connection_callback); +extern CGError CGSRegisterNotifyProc(void *handler, uint32_t type, void *context); + #define internal static #define global static @@ -57,9 +66,19 @@ global struct table mode_map; global struct table blacklst; global bool thwart_hotloader; global char config_file[4096]; +global int connection; internal HOTLOADER_CALLBACK(config_handler); +static GLOBAL_CONNECTION_CALLBACK(connection_handler) +{ + if (type == 752) { + notify("skhd", "Secure Keyboard Entry was enabled!"); + } else if (type == 753) { + notify("skhd", "Secure Keyboard Entry was disabled.."); + } +} + internal void parse_config_helper(char *absolutepath) { @@ -429,6 +448,12 @@ int main(int argc, char **argv) get_config_file("skhdrc", config_file, sizeof(config_file)); } + NSApplicationLoad(); + notify_init(); + connection = CGSMainConnectionID(); + CGSRegisterNotifyProc((void*)connection_handler, 752, NULL); + CGSRegisterNotifyProc((void*)connection_handler, 753, NULL); + CFNotificationCenterAddObserver(CFNotificationCenterGetDistributedCenter(), NULL, &keymap_handler, |