Skip to content

Commit

Permalink
Merge pull request #12565 from keymanapp/fix/mac/5721-OSK-alt-layers-…
Browse files Browse the repository at this point in the history
…missing

fix(mac): support missing alt layers in OSK
  • Loading branch information
sgschantz authored Oct 25, 2024
2 parents 60d6753 + 8acff15 commit a4b9b9f
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 125 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ struct COMP_KEY {
#define KVKK_BITMAP 0x01
#define KVKK_UNICODE 0x02

// KVK shift flags
// KVK modifier flags
#define KVKS_NORMAL 0x00
#define KVKS_SHIFT 0x01
#define KVKS_CTRL 0x02
Expand Down
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
49 changes: 34 additions & 15 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.modifierFlags & KVKS_ALT) {
_containsAltKeys = YES;
}
if(key.modifierFlags & KVKS_LALT) {
_containsLeftAltKeys = YES;
}
if(key.modifierFlags & KVKS_RALT) {
_containsRightAltKeys = YES;
}
[mKeys addObject:key];
}

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

_keys = [NSArray arrayWithArray:mKeys];


[file closeFile];
}

Expand Down Expand Up @@ -114,23 +131,23 @@ + (NFont *)NFontFromFile:(NSFileHandle *)file {
+ (NKey *)NKeyFromFile:(NSFileHandle *)file {
NKey *nkey = [[NKey alloc] init];

Byte flags;
size_t size = sizeof(flags);
Byte typeFlags;
size_t size = sizeof(typeFlags);
NSData *dataBuffer = [file readDataOfLength:size];
[dataBuffer getBytes:&flags length:size];
nkey.flags = flags;
[dataBuffer getBytes:&typeFlags length:size];
nkey.typeFlags = typeFlags;

WORD shift;
size = sizeof(shift);
WORD modifierFlags;
size = sizeof(modifierFlags);
dataBuffer = [file readDataOfLength:size];
[dataBuffer getBytes:&shift length:size];
nkey.shift = shift;
[dataBuffer getBytes:&modifierFlags length:size];
nkey.modifierFlags = modifierFlags;

WORD vkey;
size = sizeof(vkey);
WORD keyCode;
size = sizeof(keyCode);
dataBuffer = [file readDataOfLength:size];
[dataBuffer getBytes:&vkey length:size];
nkey.vkey = vkey;
[dataBuffer getBytes:&keyCode length:size];
nkey.keyCode = keyCode;

nkey.text = [KVKFile NStringFromFile:file];

Expand All @@ -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 oskLog], "KVKFile NKeyFromFile: %{public}@", nkey);

return nkey;
}

Expand Down
6 changes: 3 additions & 3 deletions mac/KeymanEngine4Mac/KeymanEngine4Mac/KME/NKey.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

@interface NKey : NSObject

@property (assign, nonatomic) Byte flags;
@property (assign, nonatomic) WORD shift;
@property (assign, nonatomic) WORD vkey;
@property (assign, nonatomic) Byte typeFlags;
@property (assign, nonatomic) WORD modifierFlags;
@property (assign, nonatomic) WORD keyCode;
@property (strong, nonatomic) NSString *text;
@property (strong, nonatomic) NSImage *bitmap;

Expand Down
4 changes: 2 additions & 2 deletions mac/KeymanEngine4Mac/KeymanEngine4Mac/KME/NKey.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ - (id)init {
}

- (NSString *)description {
NSString *format = @"<%@:%p flags:%d shift:%d virtualkey:%d 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];
NSString *format = @"<%@:%p flags:0x%hhX shift:0x%X virtualkey:0x%X text:%@ utf8:%@ bmp:%@>";
NSString *str = [NSString stringWithFormat:format, self.className, self, self.typeFlags, self.modifierFlags, self.keyCode, self.text, [self.text dataUsingEncoding:NSUTF8StringEncoding], self.bitmap];
return str;
}

Expand Down
Loading

0 comments on commit a4b9b9f

Please sign in to comment.