Skip to content

Commit

Permalink
feat(mac): get key_list from core
Browse files Browse the repository at this point in the history
  • Loading branch information
sgschantz committed Sep 20, 2024
1 parent a14a988 commit 0dc7bac
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
29A658C82AF394560038DCFE /* armenian_mnemonic.kmx in Resources */ = {isa = PBXBuildFile; fileRef = 29A658C72AF394560038DCFE /* armenian_mnemonic.kmx */; };
29B4A0D82BFAE8A400682049 /* KMELogs.h in Headers */ = {isa = PBXBuildFile; fileRef = 29B4A0D62BFAE8A400682049 /* KMELogs.h */; };
29B4A0D92BFAE8A400682049 /* KMELogs.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B4A0D72BFAE8A400682049 /* KMELogs.m */; };
29BD27482C9D813D00AE7D1B /* CoreKey.h in Headers */ = {isa = PBXBuildFile; fileRef = 29BE6F022C9D700B00635B1A /* CoreKey.h */; settings = {ATTRIBUTES = (Public, ); }; };
29BE6F042C9D700B00635B1A /* CoreKey.m in Sources */ = {isa = PBXBuildFile; fileRef = 29BE6F032C9D700B00635B1A /* CoreKey.m */; };
378568D122FCCF0A00B481B5 /* sil_ipa.kmx in Resources */ = {isa = PBXBuildFile; fileRef = 378568D022FCCF0A00B481B5 /* sil_ipa.kmx */; };
378568D322FCD93300B481B5 /* indexoffset1892.kmx in Resources */ = {isa = PBXBuildFile; fileRef = 378568D222FCD93300B481B5 /* indexoffset1892.kmx */; };
980053351B37C9B50088DDDD /* NFont.h in Headers */ = {isa = PBXBuildFile; fileRef = 980053311B37C9B50088DDDD /* NFont.h */; settings = {ATTRIBUTES = (Public, ); }; };
Expand Down Expand Up @@ -101,6 +103,8 @@
29A658C72AF394560038DCFE /* armenian_mnemonic.kmx */ = {isa = PBXFileReference; lastKnownFileType = file; path = armenian_mnemonic.kmx; sourceTree = "<group>"; };
29B4A0D62BFAE8A400682049 /* KMELogs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KMELogs.h; sourceTree = "<group>"; };
29B4A0D72BFAE8A400682049 /* KMELogs.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KMELogs.m; sourceTree = "<group>"; };
29BE6F022C9D700B00635B1A /* CoreKey.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CoreKey.h; sourceTree = "<group>"; };
29BE6F032C9D700B00635B1A /* CoreKey.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CoreKey.m; sourceTree = "<group>"; };
378568D022FCCF0A00B481B5 /* sil_ipa.kmx */ = {isa = PBXFileReference; lastKnownFileType = file; path = sil_ipa.kmx; sourceTree = "<group>"; };
378568D222FCD93300B481B5 /* indexoffset1892.kmx */ = {isa = PBXFileReference; lastKnownFileType = file; path = indexoffset1892.kmx; sourceTree = "<group>"; };
980053311B37C9B50088DDDD /* NFont.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NFont.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -178,6 +182,8 @@
children = (
2993C32B29B1D92E00FB5E95 /* CoreHelper.h */,
2993C32529B1D92E00FB5E95 /* CoreHelper.m */,
29BE6F022C9D700B00635B1A /* CoreKey.h */,
29BE6F032C9D700B00635B1A /* CoreKey.m */,
2993C32829B1D92E00FB5E95 /* CoreWrapper.h */,
2993C32429B1D92E00FB5E95 /* CoreWrapper.m */,
2993C32A29B1D92E00FB5E95 /* CoreAction.h */,
Expand Down Expand Up @@ -346,6 +352,7 @@
9818807B1BC1EE9700A1FBA5 /* TimerTarget.h in Headers */,
E28C71E520EBBA2D002D959D /* KMkeyViewProtocol.h in Headers */,
984C2B191A79CB020023F89D /* WindowsVKCodes.h in Headers */,
29BD27482C9D813D00AE7D1B /* CoreKey.h in Headers */,
984C2B0C1A79CA4F0023F89D /* KMCompGroup.h in Headers */,
984C2B101A79CA4F0023F89D /* KMCompStore.h in Headers */,
984C2B0E1A79CA4F0023F89D /* KMCompKey.h in Headers */,
Expand Down Expand Up @@ -517,6 +524,7 @@
29A1971F2AF091E600512A37 /* CoreKeyOutput.m in Sources */,
981880741BC1EA5800A1FBA5 /* KeyView.m in Sources */,
981880761BC1EA5800A1FBA5 /* OSKKey.m in Sources */,
29BE6F042C9D700B00635B1A /* CoreKey.m in Sources */,
2993C32F29B1D92E00FB5E95 /* CoreHelper.m in Sources */,
984C2B0D1A79CA4F0023F89D /* KMCompGroup.m in Sources */,
984C2B111A79CA4F0023F89D /* KMCompStore.m in Sources */,
Expand Down
17 changes: 17 additions & 0 deletions mac/KeymanEngine4Mac/KeymanEngine4Mac/CoreWrapper/CoreKey.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Keyman is copyright (C) SIL International. MIT License.
*
* Created by Shawn Schantz on 2024-09-20.
*/

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface CoreKey : NSObject
@property (nonatomic, readonly) NSUInteger keyCode;
@property (nonatomic, readonly) NSUInteger keyModifiers;
-(instancetype)init:(NSUInteger)code modifiers:(NSUInteger)modifiers;
@end

NS_ASSUME_NONNULL_END
23 changes: 23 additions & 0 deletions mac/KeymanEngine4Mac/KeymanEngine4Mac/CoreWrapper/CoreKey.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Keyman is copyright (C) SIL International. MIT License.
*
* Created by Shawn Schantz on 2024-09-20.
*
* A value object to represent a keycode and modifier pair.
* This corresponds to the km_core_keyboard_key struct returned by Core.
*/

#import "CoreKey.h"

@implementation CoreKey
-(instancetype)init:(NSUInteger)code modifiers:(NSUInteger)modifiers {
self = [super init];
if (self) {
_keyCode = code;
_keyModifiers = modifiers;
}
return self;
}


@end
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
/**
/*
* Keyman is copyright (C) SIL International. MIT License.
*
* CoreWrapper.h
* Keyman
*
* Created by Shawn Schantz on 2022-12-12.
*/

Expand All @@ -12,6 +9,7 @@
#import "CoreHelper.h"
#import "CoreAction.h"
#import "CoreKeyOutput.h"
#import "CoreKey.h"

NS_ASSUME_NONNULL_BEGIN

Expand All @@ -23,6 +21,7 @@ NS_ASSUME_NONNULL_BEGIN
-(instancetype)initWithHelper:(CoreHelper*)helper kmxFilePath:(nullable NSString*)path;
-(BOOL)setOptionsForCore: (NSString *) key value:(NSString *) value;
-(void)changeKeyboardWithKmxFilePath:(NSString*)path;
-(NSArray*)getKeyList;
-(CoreKeyOutput*)processEvent:(nonnull NSEvent *)event;
-(CoreKeyOutput*)processMacVirtualKey:(unsigned short)macKeyCode
withModifiers:(NSEventModifierFlags)modifierState
Expand Down
26 changes: 22 additions & 4 deletions mac/KeymanEngine4Mac/KeymanEngine4Mac/CoreWrapper/CoreWrapper.m
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
/**
/*
* Keyman is copyright (C) SIL International. MIT License.
*
* CoreWrapper.m
* Keyman
*
* Created by Shawn Schantz on 2022-12-12.
*
* A class to wrap an instance of a Keyman Core keyboard (a km_core_keyboard
Expand Down Expand Up @@ -67,6 +64,27 @@ -(void)changeKeyboardWithKmxFilePath:(NSString*) path {
}
}

-(NSArray*)getKeyList {
NSMutableArray *keyArray = [[NSMutableArray alloc] initWithCapacity:0];
km_core_keyboard_key *keyList;

os_log_debug([KMELogs coreLog], "getKeyList called.");
km_core_status result = km_core_keyboard_get_key_list(self.coreKeyboard, &keyList);

for(km_core_keyboard_key* keyPtr = keyList; (keyPtr->key) != 0; keyPtr++) {
uint16_t key = keyPtr->key;
uint32_t modifier_flag = keyPtr->modifier_flag;
os_log_debug([KMELogs coreLog], "key %d modifiers %d ", key, modifier_flag);

if(key != 0) {
CoreKey* coreKey = [[CoreKey alloc] init: key modifiers: modifier_flag];
[keyArray addObject:coreKey];
}
}

return keyArray;
}

-(void) dealloc{
if (self.coreState) {
km_core_state_dispose(self.coreState);
Expand Down
6 changes: 6 additions & 0 deletions mac/KeymanEngine4Mac/KeymanEngine4Mac/KME/KMEngine.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ -(void)loadCoreWrapperFromKmxFile:(NSString *)kmxFilePath {
@catch (NSException *exception) {
os_log_error([KMELogs coreLog], "loadCoreWrapperFromKmxFile, failed to create keyboard for path '%{public}@' with exception: %{public}@", kmxFilePath, exception.description);
}

/**
* Get the list of Keys supported by the keyboard
*/
NSArray* keyList = [_coreWrapper getKeyList];
os_log_debug([KMELogs coreLog], "loadCoreWrapperFromKmxFile, keyList: %{public}@", keyList);
}

-(void)setKmx:(KMXFile*) kmxFile {
Expand Down
1 change: 1 addition & 0 deletions mac/KeymanEngine4Mac/KeymanEngine4Mac/KeymanEngine4Mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ FOUNDATION_EXPORT const unsigned char KeymanEngine4MacVersionString[];
#import <KeymanEngine4Mac/CoreHelper.h>
#import <KeymanEngine4Mac/CoreAction.h>
#import <KeymanEngine4Mac/CoreKeyOutput.h>
#import <KeymanEngine4Mac/CoreKey.h>
#import "KMkeyViewProtocol.h"
#import "OSKView.h"
#import "TimerTarget.h"
Expand Down

0 comments on commit 0dc7bac

Please sign in to comment.