From 95a5e9ad45ffff0c1380a94345fd6173d71b75ec Mon Sep 17 00:00:00 2001 From: Colin Cornaby Date: Sat, 6 Jul 2024 20:40:33 -0700 Subject: [PATCH] Adding caps lock state cache MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Attempting to correct caps lock state if it’s changed in the background --- .../Mac-Cocoa/PLSKeyboardEventMonitor.mm | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Sources/Plasma/Apps/plClient/Mac-Cocoa/PLSKeyboardEventMonitor.mm b/Sources/Plasma/Apps/plClient/Mac-Cocoa/PLSKeyboardEventMonitor.mm index 8d4f8ab13e..73656cab0d 100644 --- a/Sources/Plasma/Apps/plClient/Mac-Cocoa/PLSKeyboardEventMonitor.mm +++ b/Sources/Plasma/Apps/plClient/Mac-Cocoa/PLSKeyboardEventMonitor.mm @@ -66,6 +66,7 @@ @interface PLSKeyboardEventMonitor () @property(weak) NSView* view; @property plInputManager* inputManager; @property(retain) id localMonitor; +@property BOOL capsLockKeyDown; @end @@ -152,10 +153,12 @@ - (BOOL)processKeyEvent:(NSEvent*)event if (keycode == kVK_Control) { down = (event.modifierFlags & NSEventModifierFlagControl) != 0; } - if (keycode == kVK_CapsLock) { - down = (event.modifierFlags & NSEventModifierFlagCapsLock) != 0; + BOOL capsLockMaskPresent = (event.modifierFlags & NSEventModifierFlagCapsLock) != 0; + if (capsLockMaskPresent != self.capsLockKeyDown) { + self.capsLockKeyDown = capsLockMaskPresent; + self.inputManager->HandleKeyEvent((plKeyDef)kVK_CapsLock, self.capsLockKeyDown, false); } - + /* This gets weird. Recent Apple hardware is starting to have its system key shortcuts assigned to the fn key @@ -174,8 +177,11 @@ - (BOOL)processKeyEvent:(NSEvent*)event } @synchronized(self.view.layer) { - self.inputManager->HandleKeyEvent( - (plKeyDef)keycode, down, event.type == NSEventTypeFlagsChanged ? false : event.ARepeat); + // Caps lock modifer has special handling that was earlier + if (keycode != kVK_CapsLock) { + self.inputManager->HandleKeyEvent( + (plKeyDef)keycode, down, event.type == NSEventTypeFlagsChanged ? false : event.ARepeat); + } if (!(modifierFlags & NSEventModifierFlagFunction) && down) { if (event.type != NSEventTypeFlagsChanged && event.characters.length > 0) { // Only works for BMP code points (up to U+FFFF), but that's unlikely to matter at