Skip to content

Commit

Permalink
fix(mac): support alt layers in OSK
Browse files Browse the repository at this point in the history
Fixes: #5721
  • Loading branch information
sgschantz committed Oct 18, 2024
1 parent d40ca93 commit dc6f518
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 8 deletions.
3 changes: 3 additions & 0 deletions mac/KeymanEngine4Mac/KeymanEngine4Mac/KME/KVKFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
@property (strong, nonatomic, readonly) NFont *unicodeFont;
@property (strong, nonatomic, readonly) NSArray *keys;
@property (strong, nonatomic, readonly) NSString *filePath;
@property (readonly) BOOL containsAltKeys;
@property (readonly) BOOL containsLeftAltKeys;
@property (readonly) BOOL containsRightAltKeys;

- (id)initWithFilePath:(NSString *)path;

Expand Down
25 changes: 22 additions & 3 deletions mac/KeymanEngine4Mac/KeymanEngine4Mac/KME/KVKFile.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,31 @@ - (id)initWithFilePath:(NSString *)path {
size = sizeof(keyCount);
dataBuffer = [file readDataOfLength:size];
[dataBuffer getBytes:&keyCount length:size];


_containsAltKeys = NO;
_containsLeftAltKeys = NO;
_containsRightAltKeys = NO;

NSMutableArray *mKeys = [[NSMutableArray alloc] initWithCapacity:keyCount];
for (int i = 0; i < keyCount; i++) {
[mKeys addObject:[KVKFile NKeyFromFile:file]];
NKey *key = [KVKFile NKeyFromFile:file];
if(key.shift & KVKS_ALT) {
_containsAltKeys = YES;
}
if(key.shift & KVKS_LALT) {
_containsLeftAltKeys = YES;
}
if(key.shift & KVKS_RALT) {
_containsRightAltKeys = YES;
}
[mKeys addObject:key];
}

os_log_debug([KMELogs testLog], "KVKFile initWithFilePath, containsAltKeys:%d containsLeftAltKeys:%d containsRightAltKeys:%d", _containsAltKeys, _containsLeftAltKeys, _containsRightAltKeys);

_keys = [NSArray arrayWithArray:mKeys];


[file closeFile];
}

Expand Down Expand Up @@ -146,7 +163,9 @@ + (NKey *)NKeyFromFile:(NSFileHandle *)file {
nkey.bitmap = [[NSImage alloc] initWithCGImage:imageRef size:NSMakeSize(CGImageGetWidth(imageRep.CGImage), CGImageGetHeight(imageRep.CGImage))];
CGImageRelease(imageRef);
}


os_log_debug([KMELogs testLog], "KVKFile NKeyFromFile: %{public}@", nkey);

return nkey;
}

Expand Down
2 changes: 1 addition & 1 deletion mac/KeymanEngine4Mac/KeymanEngine4Mac/KME/NKey.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ - (id)init {
}

- (NSString *)description {
NSString *format = @"<%@:%p flags:%d shift:%d virtualkey:%d text:%@ utf8:%@ bmp:%@>";
NSString *format = @"<%@:%p flags:0x%hhX shift:0x%X virtualkey:0x%X text:%@ utf8:%@ bmp:%@>";
NSString *str = [NSString stringWithFormat:format, self.className, self, self.flags, self.shift, self.vkey, self.text, [self.text dataUsingEncoding:NSUTF8StringEncoding], self.bitmap];
return str;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,12 +532,19 @@ - (void)setKeyLabels:(BOOL)shift alt:(BOOL)alt ctrl:(BOOL)ctrl {
nkeys = self.oskDefaultNKeys;

WORD flags = 0;
if (shift)
if (shift) {
flags |= KVKS_SHIFT;
if (alt)
flags |= KVKS_RALT;
if (ctrl)
}
if (alt) {
if (self.kvk.containsRightAltKeys) {
flags |= KVKS_RALT;
} else if (self.kvk.containsAltKeys) {
flags |= KVKS_ALT;
}
}
if (ctrl) {
flags |= KVKS_RCTRL;
}

NSString *ansiFont = [self ansiFont];
NSString *unicodeFont = [self unicodeFont];
Expand Down

0 comments on commit dc6f518

Please sign in to comment.