Skip to content

Commit

Permalink
fix(mac): renaming and refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
sgschantz committed Dec 18, 2024
1 parent e778537 commit b9b1786
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ - (void)windowWillClose:(NSNotification *)notification {
[self.oskView clearOskModifiers];
}

- (void) showWindow:(id) sender {
[super showWindow:sender];

os_log_info([KMLogs oskLog], "OSKWindowController showWindow");
}

- (void)helpAction:(id)sender {
NSString *kvkPath = [self AppDelegate].kvk.filePath;
if (!kvkPath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ - (void)setKvk:(KVKFile *)kvk {
_oskLayout = nil;
_oskDefaultNKeys = nil;

[self displayKeyLabelsForLayer];
[self updateKeyLabelsForState];
}

- (void)initOSKKeys {
Expand Down Expand Up @@ -174,7 +174,7 @@ - (void)initOSKKeys {
py += keyHeight;
}

[self displayKeyLabelsForLayer];
[self updateKeyLabelsForState];
}

- (NSArray *)oskLayout {
Expand Down Expand Up @@ -435,8 +435,8 @@ - (void)clearOskModifiers {
_oskShiftState = NO;
_oskOptionState = NO;
_oskControlState = NO;
[self displayModifierKeysState];
[self displayKeyLabelsForLayer];
[self updateModifierKeysForState];
[self updateKeyLabelsForState];
}

- (void)resetOSK {
Expand Down Expand Up @@ -536,22 +536,13 @@ - (void)setKeyPressedOff:(KeyView *)keyView {
}

/**
* Display the key labels that correspond to the current state of the modifier keys.
* The layer shown depends on both the physical modifier state and the osk modifier state.
* get the modifier flags that represent the combined state of the physical and osk modifiers
*/
- (void)displayKeyLabelsForLayer {
os_log_debug([KMELogs oskLog], "OSKView displayKeyLabelsForLayer, phsyical modifiers [shift: %d, option: %d, control: %d]\nosk modifiers [shift: %d, option: %d, control: %d]", self.physicalShiftState, self.physicalOptionState, self.physicalControlState, self.oskShiftState, self.oskOptionState, self.oskControlState);

- (WORD) getCombinedModifierFlags {
BOOL shift = self.physicalShiftState | self.oskShiftState;
BOOL option = self.physicalOptionState | self.oskOptionState;
BOOL control = self.physicalControlState | self.oskControlState;

[self resetKeyLabels];
NSMutableArray *mKeys = [[self keyTags] mutableCopy];
NSArray *nkeys = [self.kvk keys];
if (nkeys == nil)
nkeys = self.oskDefaultNKeys;


WORD flags = 0;
if (shift) {
flags |= KVKS_SHIFT;
Expand All @@ -567,6 +558,24 @@ - (void)displayKeyLabelsForLayer {
flags |= KVKS_RCTRL;
}

return flags;
}

/**
* Display the key labels that correspond to the current state of the modifier keys.
* The layer shown depends on both the physical modifier state and the osk modifier state.
*/
- (void)updateKeyLabelsForState {
os_log_debug([KMELogs oskLog], "OSKView updateKeyLabelsForState, phsyical modifiers [shift: %d, option: %d, control: %d]\nosk modifiers [shift: %d, option: %d, control: %d]", self.physicalShiftState, self.physicalOptionState, self.physicalControlState, self.oskShiftState, self.oskOptionState, self.oskControlState);

[self resetKeyLabels];
NSMutableArray *mKeys = [[self keyTags] mutableCopy];
NSArray *nkeys = [self.kvk keys];
if (nkeys == nil)
nkeys = self.oskDefaultNKeys;

WORD flags = [self getCombinedModifierFlags];

NSString *ansiFont = [self ansiFont];
NSString *unicodeFont = [self unicodeFont];
unsigned short keyCode;
Expand Down Expand Up @@ -645,8 +654,8 @@ - (void)setPhysicalShiftState:(BOOL)state {
_oskShiftState = NO;

os_log_debug([KMELogs oskLog], "hardware shift key released");
[self displayKeyLabelsForLayer];
[self displayShiftKeysState];
[self updateKeyLabelsForState];
[self updateShiftKeysForState];
}
}

Expand All @@ -655,13 +664,13 @@ - (void)setOskShiftState:(BOOL)state {
_oskShiftState = state;
if (state) {
os_log_debug([KMELogs oskLog], "OSK shift key selected");
[self displayKeyLabelsForLayer];
[self displayShiftKeysState];
[self updateKeyLabelsForState];
[self updateShiftKeysForState];
}
else if (!self.physicalShiftState) {
os_log_debug([KMELogs oskLog], "OSK shift key de-selected");
[self displayKeyLabelsForLayer];
[self displayShiftKeysState];
[self updateKeyLabelsForState];
[self updateShiftKeysForState];
}
}
}
Expand All @@ -675,21 +684,21 @@ - (void)setPhysicalOptionState:(BOOL)state {
* The state of the physical key overrides the modifier key clicked in the OSK.
*/
_oskOptionState = NO;
[self displayKeyLabelsForLayer];
[self displayOptionKeysState];
[self updateKeyLabelsForState];
[self updateOptionKeysForState];
}
}

- (void)setOskOptionState:(BOOL)state {
if (_oskOptionState != state && !self.physicalOptionState) {
_oskOptionState = state;
if (state) {
[self displayKeyLabelsForLayer];
[self displayOptionKeysState];
[self updateKeyLabelsForState];
[self updateOptionKeysForState];
}
else if (!self.physicalOptionState) {
[self displayKeyLabelsForLayer];
[self displayOptionKeysState];
[self updateKeyLabelsForState];
[self updateOptionKeysForState];
}
}
}
Expand All @@ -703,48 +712,48 @@ - (void)setPhysicalControlState:(BOOL)state {
* The state of the physical key overrides the modifier key clicked in the OSK.
*/
_oskControlState = NO;
[self displayKeyLabelsForLayer];
[self displayControlKeysState];
[self updateKeyLabelsForState];
[self updateControlKeysForState];
}
}

- (void)setOskControlState:(BOOL)state {
if (_oskControlState != state && !self.physicalControlState) {
_oskControlState = state;
if (state) {
[self displayKeyLabelsForLayer];
[self displayControlKeysState];
[self updateKeyLabelsForState];
[self updateControlKeysForState];
}
else if (!self.physicalControlState) {
[self displayKeyLabelsForLayer];
[self displayControlKeysState];
[self updateKeyLabelsForState];
[self updateControlKeysForState];
}
}
}

- (void)displayModifierKeysState {
[self displayShiftKeysState];
[self displayOptionKeysState];
[self displayControlKeysState];
- (void)updateModifierKeysForState {
[self updateShiftKeysForState];
[self updateOptionKeysForState];
[self updateControlKeysForState];
}

- (void)displayShiftKeysState {
- (void)updateShiftKeysForState {
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)displayOptionKeysState {
- (void)updateOptionKeysForState{
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)displayControlKeysState {
- (void)updateControlKeysForState {
BOOL pressed = self.oskControlState || self.physicalControlState;
KeyView *leftControlKey = (KeyView *)[self viewWithTag:MVK_LEFT_CTRL|0x1000];
KeyView *rightControlKey = (KeyView *)[self viewWithTag:MVK_RIGHT_CTRL|0x1000];
Expand Down

0 comments on commit b9b1786

Please sign in to comment.