aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkoekeishiya <aasvi93@hotmail.com>2020-05-02 23:43:26 +0200
committerkoekeishiya <aasvi93@hotmail.com>2020-05-02 23:43:39 +0200
commit62ba56b82c32bc9754b733fa8ea48378f417c058 (patch)
tree026247f8ff7a6ea2cd3041e501c3ac71ab28e80f
parent1fbce35a78563f915f3699724623295020f66167 (diff)
downloadskhd-62ba56b82c32bc9754b733fa8ea48378f417c058.tar.gz
skhd-62ba56b82c32bc9754b733fa8ea48378f417c058.zip
#127 notify when secure keyboard input is enabled/disabled
-rw-r--r--src/skhd.c25
1 files changed, 25 insertions, 0 deletions
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 <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,