Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing caps lock input on macOS #1601

Merged
merged 2 commits into from
Jul 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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