Skip to content

Commit

Permalink
Adding caps lock state cache
Browse files Browse the repository at this point in the history
Attempting to correct caps lock state if it’s changed in the background
  • Loading branch information
colincornaby committed Jul 7, 2024
1 parent 2f3dc89 commit 95a5e9a
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions Sources/Plasma/Apps/plClient/Mac-Cocoa/PLSKeyboardEventMonitor.mm
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ @interface PLSKeyboardEventMonitor ()
@property(weak) NSView* view;
@property plInputManager* inputManager;
@property(retain) id localMonitor;
@property BOOL capsLockKeyDown;

@end

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 95a5e9a

Please sign in to comment.