From 62ba56b82c32bc9754b733fa8ea48378f417c058 Mon Sep 17 00:00:00 2001 From: koekeishiya Date: Sat, 2 May 2020 23:43:26 +0200 Subject: #127 notify when secure keyboard input is enabled/disabled --- src/skhd.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src') diff --git a/src/skhd.c b/src/skhd.c index c86724c..191a2af 100644 --- a/src/skhd.c +++ b/src/skhd.c @@ -11,6 +11,8 @@ #include #include #include +#include +#include #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, -- cgit v1.2.3