Skip to content

Commit

Permalink
fix(mac): also reset the corresponding keys when closing OSK
Browse files Browse the repository at this point in the history
  • Loading branch information
sgschantz committed Dec 17, 2024
1 parent 803a218 commit e778537
Showing 1 changed file with 26 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ - (void)clearOskModifiers {
_oskShiftState = NO;
_oskOptionState = NO;
_oskControlState = NO;
[self displayModifierKeysState];
[self displayKeyLabelsForLayer];
}

Expand Down Expand Up @@ -643,16 +644,9 @@ - (void)setPhysicalShiftState:(BOOL)state {
*/
_oskShiftState = NO;

if (state) {
os_log_debug([KMELogs oskLog], "hardware shift key pressed");
[self displayKeyLabelsForLayer];
[self displaysShiftKeysAsPressed:YES];
}
else {
os_log_debug([KMELogs oskLog], "hardware shift key released");
[self displayKeyLabelsForLayer];
[self displaysShiftKeysAsPressed:NO];
}
os_log_debug([KMELogs oskLog], "hardware shift key released");
[self displayKeyLabelsForLayer];
[self displayShiftKeysState];
}
}

Expand All @@ -662,12 +656,12 @@ - (void)setOskShiftState:(BOOL)state {
if (state) {
os_log_debug([KMELogs oskLog], "OSK shift key selected");
[self displayKeyLabelsForLayer];
[self displaysShiftKeysAsPressed:YES];
[self displayShiftKeysState];
}
else if (!self.physicalShiftState) {
os_log_debug([KMELogs oskLog], "OSK shift key de-selected");
[self displayKeyLabelsForLayer];
[self displaysShiftKeysAsPressed:NO];
[self displayShiftKeysState];
}
}
}
Expand All @@ -681,15 +675,8 @@ - (void)setPhysicalOptionState:(BOOL)state {
* The state of the physical key overrides the modifier key clicked in the OSK.
*/
_oskOptionState = NO;

if (state) {
[self displayKeyLabelsForLayer];
[self displaysOptionKeysAsPressed:YES];
}
else {
[self displayKeyLabelsForLayer];
[self displaysOptionKeysAsPressed:NO];
}
[self displayKeyLabelsForLayer];
[self displayOptionKeysState];
}
}

Expand All @@ -698,11 +685,11 @@ - (void)setOskOptionState:(BOOL)state {
_oskOptionState = state;
if (state) {
[self displayKeyLabelsForLayer];
[self displaysOptionKeysAsPressed:YES];
[self displayOptionKeysState];
}
else if (!self.physicalOptionState) {
[self displayKeyLabelsForLayer];
[self displaysOptionKeysAsPressed:NO];
[self displayOptionKeysState];
}
}
}
Expand All @@ -716,15 +703,8 @@ - (void)setPhysicalControlState:(BOOL)state {
* The state of the physical key overrides the modifier key clicked in the OSK.
*/
_oskControlState = NO;

if (state) {
[self displayKeyLabelsForLayer];
[self displaysControlKeysAsPressed:YES];
}
else {
[self displayKeyLabelsForLayer];
[self displaysControlKeysAsPressed:NO];
}
[self displayKeyLabelsForLayer];
[self displayControlKeysState];
}
}

Expand All @@ -733,30 +713,39 @@ - (void)setOskControlState:(BOOL)state {
_oskControlState = state;
if (state) {
[self displayKeyLabelsForLayer];
[self displaysControlKeysAsPressed:YES];
[self displayControlKeysState];
}
else if (!self.physicalControlState) {
[self displayKeyLabelsForLayer];
[self displaysControlKeysAsPressed:NO];
[self displayControlKeysState];
}
}
}

- (void)displaysShiftKeysAsPressed:(BOOL)pressed {
- (void)displayModifierKeysState {
[self displayShiftKeysState];
[self displayOptionKeysState];
[self displayControlKeysState];
}

- (void)displayShiftKeysState {
BOOL pressed = self.oskShiftState || self.physicalShiftState;
KeyView *leftShiftKey = (KeyView *)[self viewWithTag:MVK_LEFT_SHIFT|0x1000];
KeyView *rightShiftKey = (KeyView *)[self viewWithTag:MVK_RIGHT_SHIFT|0x1000];
[leftShiftKey setKeyPressed:pressed];
[rightShiftKey setKeyPressed:pressed];
}

- (void)displaysOptionKeysAsPressed:(BOOL)pressed {
- (void)displayOptionKeysState {
BOOL pressed = self.oskOptionState || self.physicalOptionState;
KeyView *leftOptionKey = (KeyView *)[self viewWithTag:MVK_LEFT_ALT|0x1000];
KeyView *rightOptionKey = (KeyView *)[self viewWithTag:MVK_RIGHT_ALT|0x1000];
[leftOptionKey setKeyPressed:pressed];
[rightOptionKey setKeyPressed:pressed];
}

- (void)displaysControlKeysAsPressed:(BOOL)pressed {
- (void)displayControlKeysState {
BOOL pressed = self.oskControlState || self.physicalControlState;
KeyView *leftControlKey = (KeyView *)[self viewWithTag:MVK_LEFT_CTRL|0x1000];
KeyView *rightControlKey = (KeyView *)[self viewWithTag:MVK_RIGHT_CTRL|0x1000];
[leftControlKey setKeyPressed:pressed];
Expand Down

0 comments on commit e778537

Please sign in to comment.