diff --git a/mac/KeymanEngine4Mac/KeymanEngine4Mac.xcodeproj/project.pbxproj b/mac/KeymanEngine4Mac/KeymanEngine4Mac.xcodeproj/project.pbxproj index 658891c0c6f..4d4c1adc446 100644 --- a/mac/KeymanEngine4Mac/KeymanEngine4Mac.xcodeproj/project.pbxproj +++ b/mac/KeymanEngine4Mac/KeymanEngine4Mac.xcodeproj/project.pbxproj @@ -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, ); }; }; @@ -101,6 +103,8 @@ 29A658C72AF394560038DCFE /* armenian_mnemonic.kmx */ = {isa = PBXFileReference; lastKnownFileType = file; path = armenian_mnemonic.kmx; sourceTree = ""; }; 29B4A0D62BFAE8A400682049 /* KMELogs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KMELogs.h; sourceTree = ""; }; 29B4A0D72BFAE8A400682049 /* KMELogs.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KMELogs.m; sourceTree = ""; }; + 29BE6F022C9D700B00635B1A /* CoreKey.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CoreKey.h; sourceTree = ""; }; + 29BE6F032C9D700B00635B1A /* CoreKey.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CoreKey.m; sourceTree = ""; }; 378568D022FCCF0A00B481B5 /* sil_ipa.kmx */ = {isa = PBXFileReference; lastKnownFileType = file; path = sil_ipa.kmx; sourceTree = ""; }; 378568D222FCD93300B481B5 /* indexoffset1892.kmx */ = {isa = PBXFileReference; lastKnownFileType = file; path = indexoffset1892.kmx; sourceTree = ""; }; 980053311B37C9B50088DDDD /* NFont.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NFont.h; sourceTree = ""; }; @@ -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 */, @@ -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 */, @@ -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 */, diff --git a/mac/KeymanEngine4Mac/KeymanEngine4Mac/CoreWrapper/CoreKey.h b/mac/KeymanEngine4Mac/KeymanEngine4Mac/CoreWrapper/CoreKey.h new file mode 100644 index 00000000000..2ec5c7f5a52 --- /dev/null +++ b/mac/KeymanEngine4Mac/KeymanEngine4Mac/CoreWrapper/CoreKey.h @@ -0,0 +1,17 @@ +/* + * Keyman is copyright (C) SIL International. MIT License. + * + * Created by Shawn Schantz on 2024-09-20. + */ + +#import + +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 diff --git a/mac/KeymanEngine4Mac/KeymanEngine4Mac/CoreWrapper/CoreKey.m b/mac/KeymanEngine4Mac/KeymanEngine4Mac/CoreWrapper/CoreKey.m new file mode 100644 index 00000000000..06d65094054 --- /dev/null +++ b/mac/KeymanEngine4Mac/KeymanEngine4Mac/CoreWrapper/CoreKey.m @@ -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 diff --git a/mac/KeymanEngine4Mac/KeymanEngine4Mac/CoreWrapper/CoreWrapper.h b/mac/KeymanEngine4Mac/KeymanEngine4Mac/CoreWrapper/CoreWrapper.h index 1109b1130fd..2d4bddb106e 100644 --- a/mac/KeymanEngine4Mac/KeymanEngine4Mac/CoreWrapper/CoreWrapper.h +++ b/mac/KeymanEngine4Mac/KeymanEngine4Mac/CoreWrapper/CoreWrapper.h @@ -1,9 +1,6 @@ -/** +/* * Keyman is copyright (C) SIL International. MIT License. * - * CoreWrapper.h - * Keyman - * * Created by Shawn Schantz on 2022-12-12. */ @@ -12,6 +9,7 @@ #import "CoreHelper.h" #import "CoreAction.h" #import "CoreKeyOutput.h" +#import "CoreKey.h" NS_ASSUME_NONNULL_BEGIN @@ -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 diff --git a/mac/KeymanEngine4Mac/KeymanEngine4Mac/CoreWrapper/CoreWrapper.m b/mac/KeymanEngine4Mac/KeymanEngine4Mac/CoreWrapper/CoreWrapper.m index 44c82e5b7b8..e47bd6165da 100644 --- a/mac/KeymanEngine4Mac/KeymanEngine4Mac/CoreWrapper/CoreWrapper.m +++ b/mac/KeymanEngine4Mac/KeymanEngine4Mac/CoreWrapper/CoreWrapper.m @@ -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 @@ -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); diff --git a/mac/KeymanEngine4Mac/KeymanEngine4Mac/KME/KMEngine.m b/mac/KeymanEngine4Mac/KeymanEngine4Mac/KME/KMEngine.m index dd2b3247ede..9524878e25e 100644 --- a/mac/KeymanEngine4Mac/KeymanEngine4Mac/KME/KMEngine.m +++ b/mac/KeymanEngine4Mac/KeymanEngine4Mac/KME/KMEngine.m @@ -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 { diff --git a/mac/KeymanEngine4Mac/KeymanEngine4Mac/KeymanEngine4Mac.h b/mac/KeymanEngine4Mac/KeymanEngine4Mac/KeymanEngine4Mac.h index eef0225413b..a08307be825 100644 --- a/mac/KeymanEngine4Mac/KeymanEngine4Mac/KeymanEngine4Mac.h +++ b/mac/KeymanEngine4Mac/KeymanEngine4Mac/KeymanEngine4Mac.h @@ -29,6 +29,7 @@ FOUNDATION_EXPORT const unsigned char KeymanEngine4MacVersionString[]; #import #import #import +#import #import "KMkeyViewProtocol.h" #import "OSKView.h" #import "TimerTarget.h"