Skip to content

Commit

Permalink
Merge pull request #1601 from colincornaby/mac-caps-lock
Browse files Browse the repository at this point in the history
Fixing caps lock input on macOS
  • Loading branch information
colincornaby authored Jul 7, 2024
2 parents 04c72ac + 95a5e9a commit 01d0704
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 12 additions & 3 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,7 +153,12 @@ - (BOOL)processKeyEvent:(NSEvent*)event
if (keycode == kVK_Control) {
down = (event.modifierFlags & NSEventModifierFlagControl) != 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 @@ -171,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
2 changes: 2 additions & 0 deletions Sources/Plasma/PubUtilLib/plInputCore/plInputDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 01d0704

Please sign in to comment.