From 2f3dc89b4ee147d31c6944296be0d22ed2041c51 Mon Sep 17 00:00:00 2001 From: Colin Cornaby Date: Sat, 6 Jul 2024 20:15:28 -0700 Subject: [PATCH 1/2] Fixing caps lock input on macOS Querying for the current state of caps lock after coming back to foreground is not implemented --- .../Plasma/Apps/plClient/Mac-Cocoa/PLSKeyboardEventMonitor.mm | 3 +++ Sources/Plasma/PubUtilLib/plInputCore/plInputDevice.cpp | 2 ++ 2 files changed, 5 insertions(+) diff --git a/Sources/Plasma/Apps/plClient/Mac-Cocoa/PLSKeyboardEventMonitor.mm b/Sources/Plasma/Apps/plClient/Mac-Cocoa/PLSKeyboardEventMonitor.mm index e981055552..8d4f8ab13e 100644 --- a/Sources/Plasma/Apps/plClient/Mac-Cocoa/PLSKeyboardEventMonitor.mm +++ b/Sources/Plasma/Apps/plClient/Mac-Cocoa/PLSKeyboardEventMonitor.mm @@ -152,6 +152,9 @@ - (BOOL)processKeyEvent:(NSEvent*)event if (keycode == kVK_Control) { down = (event.modifierFlags & NSEventModifierFlagControl) != 0; } + if (keycode == kVK_CapsLock) { + down = (event.modifierFlags & NSEventModifierFlagCapsLock) != 0; + } /* This gets weird. diff --git a/Sources/Plasma/PubUtilLib/plInputCore/plInputDevice.cpp b/Sources/Plasma/PubUtilLib/plInputCore/plInputDevice.cpp index 4dcfada1c8..614c20fe40 100644 --- a/Sources/Plasma/PubUtilLib/plInputCore/plInputDevice.cpp +++ b/Sources/Plasma/PubUtilLib/plInputCore/plInputDevice.cpp @@ -186,6 +186,8 @@ void plKeyboardDevice::HandleKeyEvent(plKeyDef key, bool bKeyDown, bool bKeyRepe { #ifdef HS_BUILD_FOR_WIN32 fCapsLockLock = (GetKeyState(KEY_CAPSLOCK) & 1) == 1; +#else + fCapsLockLock = bKeyDown; #endif plAvatarInputInterface::GetInstance()->ForceAlwaysRun(fCapsLockLock); } From 95a5e9ad45ffff0c1380a94345fd6173d71b75ec Mon Sep 17 00:00:00 2001 From: Colin Cornaby Date: Sat, 6 Jul 2024 20:40:33 -0700 Subject: [PATCH 2/2] 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