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

fix(mac): OSK layers displayed consistently for hardware and OSK modifiers #12829

Merged
merged 4 commits into from
Dec 17, 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
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
@interface OSKWindowController ()
@property (nonatomic, strong) NSButton *helpButton;
@property (nonatomic, strong) NSTimer *modFlagsTimer;
@property (nonatomic, assign) BOOL xShiftState;
@property (nonatomic, assign) BOOL xAltState;
@property (nonatomic, assign) BOOL xCtrlState;
@property (nonatomic, assign) BOOL previousShiftState;
@property (nonatomic, assign) BOOL previousOptionState;
@property (nonatomic, assign) BOOL previousControlState;
@end

@implementation OSKWindowController
Expand Down Expand Up @@ -58,7 +58,7 @@ - (void)windowDidLoad {
[super windowDidLoad];
[self.oskView setKvk:[self.AppDelegate kvk]];
[self startTimerWithTimeInterval:0.1];
// Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
// [self startTimerToTrackPhysicalModifierState:0.1];
}

- (void)windowDidResize:(NSNotification *)notification {
Expand Down Expand Up @@ -116,52 +116,73 @@ - (void)stopTimer {
}
}

/**
* Called repeatedly by timer to track the state of the physical modifier keys.
* Changes in state are reported to the OSKView, so it can make corresponding updates to the OSK's appearance
* and apply the state as necessary when keys on the OSK are clicked.
*/
- (void)timerAction:(NSTimer *)timer {
UInt32 modifiers = GetCurrentKeyModifiers();

[self trackPhysicalShiftKeyState: modifiers];
[self trackPhysicalOptionKeyState: modifiers];
[self trackPhysicalControlKeyState: modifiers];
}

- (void)trackPhysicalShiftKeyState:(UInt32) modifiers {
if ((modifiers & shiftKey) == shiftKey) {
[self.oskView setShiftState:YES];
self.xShiftState = YES;
[self.oskView setPhysicalShiftState:YES];
self.previousShiftState = YES;
}
else {
[self.oskView setShiftState:NO];
if (self.xShiftState)
[self.oskView setPhysicalShiftState:NO];
if (self.previousShiftState) {
[self.oskView setOskShiftState:NO];
self.xShiftState = NO;
}
self.previousShiftState = NO;
}

}

- (void)trackPhysicalOptionKeyState:(UInt32) modifiers {
if ((modifiers & optionKey) == optionKey) {
[self.oskView setAltState:YES];
self.xAltState = YES;
[self.oskView setPhysicalOptionState:YES];
self.previousOptionState = YES;
}
else {
[self.oskView setAltState:NO];
if (self.xAltState)
[self.oskView setOskAltState:NO];
self.xAltState = NO;
[self.oskView setPhysicalOptionState:NO];
if (self.previousOptionState) {
[self.oskView setOskOptionState:NO];
}
self.previousOptionState = NO;
}

}

- (void)trackPhysicalControlKeyState:(UInt32) modifiers {
if ((modifiers & controlKey) == controlKey) {
[self.oskView setCtrlState:YES];
self.xCtrlState = YES;
[self.oskView setPhysicalControlState:YES];
self.previousControlState = YES;
}
else {
[self.oskView setCtrlState:NO];
if (self.xCtrlState)
[self.oskView setOskCtrlState:NO];
self.xCtrlState = NO;
[self.oskView setPhysicalControlState:NO];
if (self.previousControlState) {
[self.oskView setOskControlState:NO];
}
self.previousControlState = NO;
}
}

- (BOOL)hasHelpDocumentation {
NSString *kvkPath = [self AppDelegate].kvk.filePath;
if (!kvkPath)
if (!kvkPath) {
return NO;
}

NSString *packagePath = [kvkPath stringByDeletingLastPathComponent];
if (packagePath != nil) {
NSString *welcomeFile = [packagePath stringByAppendingPathComponent:@"welcome.htm"];
if ([[NSFileManager defaultManager] fileExistsAtPath:welcomeFile])
if ([[NSFileManager defaultManager] fileExistsAtPath:welcomeFile]) {
return YES;
}
}

return NO;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
+ (BOOL)isOskKeyDownEvent:(CGEventRef)event;
+ (NSEventModifierFlags)extractModifierFlagsFromOskEvent:(CGEventRef)event;
- (void)handleKeyEvent:(NSEvent *)event;
- (void)setShiftState:(BOOL)shiftState;
- (void)setPhysicalShiftState:(BOOL)shiftState;
- (void)setOskShiftState:(BOOL)oskShiftState;
- (void)setAltState:(BOOL)altState;
- (void)setOskAltState:(BOOL)oskAltState;
- (void)setCtrlState:(BOOL)ctrlState;
- (void)setOskCtrlState:(BOOL)oskCtrlState;
- (void)setPhysicalOptionState:(BOOL)altState;
- (void)setOskOptionState:(BOOL)oskAltState;
- (void)setPhysicalControlState:(BOOL)ctrlState;
- (void)setOskControlState:(BOOL)oskCtrlState;
- (void)resetOSK;
- (void)resizeOSKLayout;
- (int64_t)createOskEventUserData;
Expand Down
Loading
Loading