From 0d0405b95a6867257af71957e0482669e7e2938a Mon Sep 17 00:00:00 2001 From: SpaghettDev <37266659+SpaghettDev@users.noreply.github.com> Date: Sun, 1 Dec 2024 00:18:33 -0500 Subject: [PATCH 01/20] add some logs --- src/macos.mm | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/macos.mm b/src/macos.mm index ce8f6b6..519dd45 100644 --- a/src/macos.mm +++ b/src/macos.mm @@ -1,4 +1,5 @@ -#ifdef GEODE_IS_MACOS +// #ifdef GEODE_IS_MACOS +#if 1 #define CommentType CommentTypeDummy #import @@ -6,6 +7,8 @@ #import #undef CommentType +#include + #include #import #import @@ -41,9 +44,19 @@ inline bool keyDown(PlatformKey key, NSEvent* event) static KeyEventType keyDownExecOIMP; void keyDownExec(EAGLView* self, SEL sel, NSEvent* event) { + geode::log::debug("received event"); + if (!g_selectedInput) keyDownExecOIMP(self, sel, event); + geode::log::debug("received event 2 with keyCode {}", [event keyCode]); + geode::log::debug( + "isControl: {} isShift: {}", + BI::platform::keyDown(BI::PlatformKey::LEFT_CONTROL, event), + BI::platform::keyDown(BI::PlatformKey::LEFT_SHIFT, event) + ); + geode::log::debug("isRepeat: {}", [event isARepeat]); + // on click, can be held if ( !BI::platform::keyDown(BI::PlatformKey::LEFT_CONTROL, event) && @@ -119,6 +132,8 @@ void keyDownExec(EAGLView* self, SEL sel, NSEvent* event) { s = [event charactersIgnoringModifiers]; code = [s length] > 0 ? [s characterAtIndex:0] : 0; } + + geode::log::debug("key found: '{}' ({})", static_cast(code), code); } switch (code) From 31b7161193b7852e52718a128f4782f7315d656e Mon Sep 17 00:00:00 2001 From: SpaghettDev <37266659+SpaghettDev@users.noreply.github.com> Date: Sun, 1 Dec 2024 00:27:07 -0500 Subject: [PATCH 02/20] oops --- src/macos.mm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/macos.mm b/src/macos.mm index 519dd45..2f1c2b9 100644 --- a/src/macos.mm +++ b/src/macos.mm @@ -1,5 +1,5 @@ -// #ifdef GEODE_IS_MACOS -#if 1 +#ifdef GEODE_IS_MACOS +// #if 1 #define CommentType CommentTypeDummy #import From 37d0515f9e187350faa03f1a51e8e50caa526056 Mon Sep 17 00:00:00 2001 From: SpaghettDev <37266659+SpaghettDev@users.noreply.github.com> Date: Sun, 1 Dec 2024 01:16:24 -0500 Subject: [PATCH 03/20] change to `geode::ObjcHook`s --- src/macos.mm | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/macos.mm b/src/macos.mm index 2f1c2b9..81f2899 100644 --- a/src/macos.mm +++ b/src/macos.mm @@ -1,5 +1,5 @@ -#ifdef GEODE_IS_MACOS -// #if 1 +// #ifdef GEODE_IS_MACOS +#if 1 #define CommentType CommentTypeDummy #import @@ -34,20 +34,21 @@ inline bool keyDown(PlatformKey key, NSEvent* event) } } -#define HOOK_OBJC_METHOD(klass, type, cleanFuncName, funcName) \ - auto cleanFuncName ## Method = class_getInstanceMethod(klass, @selector(funcName)); \ - cleanFuncName ## OIMP = method_getImplementation(cleanFuncName ## Method); \ - method_setImplementation(cleanFuncName ## Method, (type)&funcName); +void empty() {} -using KeyEventType = void(*)(EAGLView*, SEL, NSEvent*); +template +void createObjcHook(std::string_view className, std::string_view funcName, Func function) +{ + if (auto res = geode::ObjcHook::create(className, funcName, function, &empty); res.isOk()) + static_cast(geode::Mod::get()->claimHook(res.unwrap())); +} -static KeyEventType keyDownExecOIMP; void keyDownExec(EAGLView* self, SEL sel, NSEvent* event) { geode::log::debug("received event"); if (!g_selectedInput) - keyDownExecOIMP(self, sel, event); + [self performSelector:sel withObject:event]; geode::log::debug("received event 2 with keyCode {}", [event keyCode]); geode::log::debug( @@ -187,15 +188,14 @@ void keyDownExec(EAGLView* self, SEL sel, NSEvent* event) { !BI::platform::keyDown(BI::PlatformKey::LEFT_CONTROL, event) && [event keyCode] == kVK_Return ) { - keyDownExec(self, sel, event); + [self performSelector:sel withObject:event]; } } } -static KeyEventType keyUpExecOIMP; void keyUpExec(EAGLView* self, SEL sel, NSEvent* event) { if (!g_selectedInput) - keyUpExec(self, sel, event); + [self performSelector:sel withObject:event]; } @@ -233,10 +233,8 @@ void touches(cocos2d::CCSet* touches, cocos2d::CCEvent* event, unsigned int type $on_mod(Loaded) { - auto eaglView = objc_getClass("EAGLView"); - - HOOK_OBJC_METHOD(eaglView, KeyEventType, keyDownExec, keyDownExec:); - HOOK_OBJC_METHOD(eaglView, KeyEventType, keyUpExec, keyUpExec:); + createObjcHook("EAGLView", "keyDownExec:", keyDownExec); + createObjcHook("EAGLView", "keyUpExec:", keyDownExec); } #endif \ No newline at end of file From edee63f7ef4eb79eb22c33de562ec8041dffbbd3 Mon Sep 17 00:00:00 2001 From: SpaghettDev <37266659+SpaghettDev@users.noreply.github.com> Date: Sun, 1 Dec 2024 01:17:25 -0500 Subject: [PATCH 04/20] oops --- src/macos.mm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/macos.mm b/src/macos.mm index 81f2899..4c867f9 100644 --- a/src/macos.mm +++ b/src/macos.mm @@ -1,5 +1,5 @@ -// #ifdef GEODE_IS_MACOS -#if 1 +#ifdef GEODE_IS_MACOS +// #if 1 #define CommentType CommentTypeDummy #import From 9ad4f4ec632091e1881818614e71b51aa87bf3a7 Mon Sep 17 00:00:00 2001 From: SpaghettDev <37266659+SpaghettDev@users.noreply.github.com> Date: Sun, 1 Dec 2024 01:30:05 -0500 Subject: [PATCH 05/20] error --- src/macos.mm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/macos.mm b/src/macos.mm index 4c867f9..25d3914 100644 --- a/src/macos.mm +++ b/src/macos.mm @@ -41,6 +41,8 @@ void createObjcHook(std::string_view className, std::string_view funcName, Func { if (auto res = geode::ObjcHook::create(className, funcName, function, &empty); res.isOk()) static_cast(geode::Mod::get()->claimHook(res.unwrap())); + else + geode::log::error("Failed to create Objective C Hook '{} {}'", className, funcName); } From 6d25c9f8f6d93bbe776f2737d32f11a9d8e8f185 Mon Sep 17 00:00:00 2001 From: SpaghettDev <37266659+SpaghettDev@users.noreply.github.com> Date: Sun, 1 Dec 2024 01:36:38 -0500 Subject: [PATCH 06/20] more messages --- src/macos.mm | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/macos.mm b/src/macos.mm index 25d3914..f4e35db 100644 --- a/src/macos.mm +++ b/src/macos.mm @@ -40,7 +40,10 @@ void empty() {} void createObjcHook(std::string_view className, std::string_view funcName, Func function) { if (auto res = geode::ObjcHook::create(className, funcName, function, &empty); res.isOk()) + { static_cast(geode::Mod::get()->claimHook(res.unwrap())); + geode::log::debug("Objective C Hook created successfully '{} {}'", className, funcName); + } else geode::log::error("Failed to create Objective C Hook '{} {}'", className, funcName); } @@ -211,6 +214,8 @@ void touches(cocos2d::CCSet* touches, cocos2d::CCEvent* event, unsigned int type if (!g_selectedInput) return cocos2d::CCTouchDispatcher::touches(touches, event, type); + geode::log::debug("button clicked"); + auto* touch = static_cast(touches->anyObject()); const auto touchPos = touch->getLocation(); From 8f4bb531e99767a948ba5e585bbdc3eb4915145d Mon Sep 17 00:00:00 2001 From: SpaghettDev <37266659+SpaghettDev@users.noreply.github.com> Date: Sun, 1 Dec 2024 01:47:01 -0500 Subject: [PATCH 07/20] remove ifdef for target platform --- src/macos.mm | 5 +---- src/windows.cpp | 4 ---- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/src/macos.mm b/src/macos.mm index f4e35db..c064e70 100644 --- a/src/macos.mm +++ b/src/macos.mm @@ -1,5 +1,4 @@ -#ifdef GEODE_IS_MACOS -// #if 1 +#include #define CommentType CommentTypeDummy #import @@ -243,5 +242,3 @@ void touches(cocos2d::CCSet* touches, cocos2d::CCEvent* event, unsigned int type createObjcHook("EAGLView", "keyDownExec:", keyDownExec); createObjcHook("EAGLView", "keyUpExec:", keyDownExec); } - -#endif \ No newline at end of file diff --git a/src/windows.cpp b/src/windows.cpp index 5caf668..1338179 100644 --- a/src/windows.cpp +++ b/src/windows.cpp @@ -1,5 +1,3 @@ -#ifdef GEODE_IS_WINDOWS - #include #include @@ -178,5 +176,3 @@ struct BetterCCEGLView : Modify g_selectedInput->useUpdateBlinkPos(false); } }; - -#endif From 60822108921881ae078ea9ec0d4c78cb65eaa434 Mon Sep 17 00:00:00 2001 From: SpaghettDev <37266659+SpaghettDev@users.noreply.github.com> Date: Sun, 1 Dec 2024 01:55:03 -0500 Subject: [PATCH 08/20] maybe fix includes --- src/macos.mm | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/macos.mm b/src/macos.mm index c064e70..a00f095 100644 --- a/src/macos.mm +++ b/src/macos.mm @@ -1,16 +1,19 @@ #include +#include +#include + #define CommentType CommentTypeDummy #import #import -#import #undef CommentType -#include +#include +#import +#include #include #import -#import #include "BetterTextInputNode.hpp" From 6fcf00fba25de51ad6bc8145d76846b52b6e5175 Mon Sep 17 00:00:00 2001 From: SpaghettDev <37266659+SpaghettDev@users.noreply.github.com> Date: Sun, 1 Dec 2024 01:56:43 -0500 Subject: [PATCH 09/20] forgot cocos2d namespace --- src/macos.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/macos.mm b/src/macos.mm index a00f095..5fbebb3 100644 --- a/src/macos.mm +++ b/src/macos.mm @@ -223,7 +223,7 @@ void touches(cocos2d::CCSet* touches, cocos2d::CCEvent* event, unsigned int type if (type == TouchMessageType::Began) { - CCSize winSize = cocos2d::CCDirector::sharedDirector()->getWinSize(); + cocos2d::CCSize winSize = cocos2d::CCDirector::sharedDirector()->getWinSize(); // the touch event's origin is bottom left cocos2d::CCTouch touch{}; From 30fe2cae229a29e5ef5a2462d5cf86972ee59e33 Mon Sep 17 00:00:00 2001 From: SpaghettDev <37266659+SpaghettDev@users.noreply.github.com> Date: Sun, 1 Dec 2024 01:58:53 -0500 Subject: [PATCH 10/20] use std::string instead of std::string_view --- src/macos.mm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/macos.mm b/src/macos.mm index 5fbebb3..e723d31 100644 --- a/src/macos.mm +++ b/src/macos.mm @@ -1,4 +1,4 @@ -#include +#include #include #include @@ -39,7 +39,7 @@ inline bool keyDown(PlatformKey key, NSEvent* event) void empty() {} template -void createObjcHook(std::string_view className, std::string_view funcName, Func function) +void createObjcHook(const std::string& className, const std::string& funcName, Func function) { if (auto res = geode::ObjcHook::create(className, funcName, function, &empty); res.isOk()) { From 6e3dcb01ba8549590d661604c9a294a77aa5736c Mon Sep 17 00:00:00 2001 From: SpaghettDev <37266659+SpaghettDev@users.noreply.github.com> Date: Sun, 1 Dec 2024 02:08:54 -0500 Subject: [PATCH 11/20] revert ObjcHook change --- src/macos.mm | 31 ++++++++++++++----------------- src/windows.cpp | 2 +- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/macos.mm b/src/macos.mm index e723d31..5217c37 100644 --- a/src/macos.mm +++ b/src/macos.mm @@ -36,26 +36,20 @@ inline bool keyDown(PlatformKey key, NSEvent* event) } } -void empty() {} +#define HOOK_OBJC_METHOD(klass, type, cleanFuncName, funcName) \ + auto cleanFuncName ## Method = class_getInstanceMethod(klass, @selector(funcName)); \ + cleanFuncName ## OIMP = method_getImplementation(cleanFuncName ## Method); \ + method_setImplementation(cleanFuncName ## Method, (type)&funcName); -template -void createObjcHook(const std::string& className, const std::string& funcName, Func function) -{ - if (auto res = geode::ObjcHook::create(className, funcName, function, &empty); res.isOk()) - { - static_cast(geode::Mod::get()->claimHook(res.unwrap())); - geode::log::debug("Objective C Hook created successfully '{} {}'", className, funcName); - } - else - geode::log::error("Failed to create Objective C Hook '{} {}'", className, funcName); -} +using KeyEventType = void(*)(EAGLView*, SEL, NSEVent*); +static KeyEventType keyDownExecOIMP; void keyDownExec(EAGLView* self, SEL sel, NSEvent* event) { geode::log::debug("received event"); if (!g_selectedInput) - [self performSelector:sel withObject:event]; + return keyDownExecOIMP(self, sel, event); geode::log::debug("received event 2 with keyCode {}", [event keyCode]); geode::log::debug( @@ -195,14 +189,15 @@ void keyDownExec(EAGLView* self, SEL sel, NSEvent* event) { !BI::platform::keyDown(BI::PlatformKey::LEFT_CONTROL, event) && [event keyCode] == kVK_Return ) { - [self performSelector:sel withObject:event]; + return keyDownExecOIMP(self, sel, event); } } } +static KeyEventType keyUpExecOIMP; void keyUpExec(EAGLView* self, SEL sel, NSEvent* event) { if (!g_selectedInput) - [self performSelector:sel withObject:event]; + return keyUpExecOIMP(self, sel, event); } @@ -242,6 +237,8 @@ void touches(cocos2d::CCSet* touches, cocos2d::CCEvent* event, unsigned int type $on_mod(Loaded) { - createObjcHook("EAGLView", "keyDownExec:", keyDownExec); - createObjcHook("EAGLView", "keyUpExec:", keyDownExec); + auto eaglView = objc_getClass("EAGLView"); + + HOOK_OBJC_METHOD(eaglView, KeyEventType, keyDownExec, keyDownExec:); + HOOK_OBJC_METHOD(eaglView, KeyEventType, keyUpExec, keyUpExec:); } diff --git a/src/windows.cpp b/src/windows.cpp index 1338179..3e74834 100644 --- a/src/windows.cpp +++ b/src/windows.cpp @@ -143,7 +143,7 @@ struct BetterCCEGLView : Modify !BI::platform::keyDown(BI::PlatformKey::LEFT_CONTROL) && key == GLFW_KEY_ENTER ) { - CCEGLView::onGLFWKeyCallback(window, key, scancode, action, mods); + return CCEGLView::onGLFWKeyCallback(window, key, scancode, action, mods); } } } From e050bb72c6cc8d2e281d3be6b50d24968236a5a5 Mon Sep 17 00:00:00 2001 From: SpaghettDev <37266659+SpaghettDev@users.noreply.github.com> Date: Sun, 1 Dec 2024 02:11:38 -0500 Subject: [PATCH 12/20] cast original implementation --- src/macos.mm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/macos.mm b/src/macos.mm index 5217c37..1a38ce9 100644 --- a/src/macos.mm +++ b/src/macos.mm @@ -38,10 +38,10 @@ inline bool keyDown(PlatformKey key, NSEvent* event) #define HOOK_OBJC_METHOD(klass, type, cleanFuncName, funcName) \ auto cleanFuncName ## Method = class_getInstanceMethod(klass, @selector(funcName)); \ - cleanFuncName ## OIMP = method_getImplementation(cleanFuncName ## Method); \ + cleanFuncName ## OIMP = reinterpret_cast(method_getImplementation(cleanFuncName ## Method)); \ method_setImplementation(cleanFuncName ## Method, (type)&funcName); -using KeyEventType = void(*)(EAGLView*, SEL, NSEVent*); +using KeyEventType = void(*)(EAGLView*, SEL, NSEvent*); static KeyEventType keyDownExecOIMP; From 13e65ec3f31e17b065a4dbfd9c96db79853b1670 Mon Sep 17 00:00:00 2001 From: SpaghettDev <37266659+SpaghettDev@users.noreply.github.com> Date: Sun, 1 Dec 2024 02:15:53 -0500 Subject: [PATCH 13/20] wrong macro argument used --- src/macos.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/macos.mm b/src/macos.mm index 1a38ce9..400a6f5 100644 --- a/src/macos.mm +++ b/src/macos.mm @@ -39,7 +39,7 @@ inline bool keyDown(PlatformKey key, NSEvent* event) #define HOOK_OBJC_METHOD(klass, type, cleanFuncName, funcName) \ auto cleanFuncName ## Method = class_getInstanceMethod(klass, @selector(funcName)); \ cleanFuncName ## OIMP = reinterpret_cast(method_getImplementation(cleanFuncName ## Method)); \ - method_setImplementation(cleanFuncName ## Method, (type)&funcName); + method_setImplementation(cleanFuncName ## Method, (type)&cleanFuncName); using KeyEventType = void(*)(EAGLView*, SEL, NSEvent*); From ad8868a9a4621b778533561982f23c1447199ca4 Mon Sep 17 00:00:00 2001 From: SpaghettDev <37266659+SpaghettDev@users.noreply.github.com> Date: Sun, 1 Dec 2024 02:17:47 -0500 Subject: [PATCH 14/20] cast hook --- src/macos.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/macos.mm b/src/macos.mm index 400a6f5..4761dba 100644 --- a/src/macos.mm +++ b/src/macos.mm @@ -39,7 +39,7 @@ inline bool keyDown(PlatformKey key, NSEvent* event) #define HOOK_OBJC_METHOD(klass, type, cleanFuncName, funcName) \ auto cleanFuncName ## Method = class_getInstanceMethod(klass, @selector(funcName)); \ cleanFuncName ## OIMP = reinterpret_cast(method_getImplementation(cleanFuncName ## Method)); \ - method_setImplementation(cleanFuncName ## Method, (type)&cleanFuncName); + method_setImplementation(cleanFuncName ## Method, reinterpret_cast(&cleanFuncName)); using KeyEventType = void(*)(EAGLView*, SEL, NSEvent*); From ba0d385b441ab8753b570c466dcbc9ab5ceacdb8 Mon Sep 17 00:00:00 2001 From: SpaghettDev <37266659+SpaghettDev@users.noreply.github.com> Date: Sun, 1 Dec 2024 02:42:50 -0500 Subject: [PATCH 15/20] fix how events are handeled --- src/macos.mm | 84 +++++++++++++--------------------------------------- 1 file changed, 20 insertions(+), 64 deletions(-) diff --git a/src/macos.mm b/src/macos.mm index 4761dba..a9286a1 100644 --- a/src/macos.mm +++ b/src/macos.mm @@ -46,18 +46,16 @@ inline bool keyDown(PlatformKey key, NSEvent* event) static KeyEventType keyDownExecOIMP; void keyDownExec(EAGLView* self, SEL sel, NSEvent* event) { - geode::log::debug("received event"); - if (!g_selectedInput) return keyDownExecOIMP(self, sel, event); - geode::log::debug("received event 2 with keyCode {}", [event keyCode]); + geode::log::debug("key down ({})", [event keyCode]); geode::log::debug( - "isControl: {} isShift: {}", + "isControl: {} isShift: {} isRepeat: {}", BI::platform::keyDown(BI::PlatformKey::LEFT_CONTROL, event), - BI::platform::keyDown(BI::PlatformKey::LEFT_SHIFT, event) + BI::platform::keyDown(BI::PlatformKey::LEFT_SHIFT, event), + [event isARepeat] ); - geode::log::debug("isRepeat: {}", [event isARepeat]); // on click, can be held if ( @@ -67,13 +65,11 @@ void keyDownExec(EAGLView* self, SEL sel, NSEvent* event) { switch ([event keyCode]) { case kVK_Escape: - g_selectedInput->deselectInput(); - break; + return g_selectedInput->deselectInput(); case kVK_Delete: case kVK_ForwardDelete: - g_selectedInput->onDelete(false, [event keyCode] == kVK_ForwardDelete); - break; + return g_selectedInput->onDelete(false, [event keyCode] == kVK_ForwardDelete); default: break; @@ -83,18 +79,16 @@ void keyDownExec(EAGLView* self, SEL sel, NSEvent* event) { switch ([event keyCode]) { case kVK_RightArrow: - g_selectedInput->onRightArrowKey( + return g_selectedInput->onRightArrowKey( BI::platform::keyDown(BI::PlatformKey::LEFT_CONTROL, event), BI::platform::keyDown(BI::PlatformKey::LEFT_SHIFT, event) ); - break; case kVK_LeftArrow: - g_selectedInput->onLeftArrowKey( + return g_selectedInput->onLeftArrowKey( BI::platform::keyDown(BI::PlatformKey::LEFT_CONTROL, event), BI::platform::keyDown(BI::PlatformKey::LEFT_SHIFT, event) ); - break; default: break; @@ -109,52 +103,19 @@ void keyDownExec(EAGLView* self, SEL sel, NSEvent* event) { { case kVK_Delete: case kVK_ForwardDelete: - g_selectedInput->onDelete(true, [event keyCode] == kVK_ForwardDelete); - break; - - default: - break; - } - - /* - int code = [[event characters] length] > 0 - ? [[event characters] characterAtIndex:0] - : [[event charactersIgnoringModifiers] length] > 0 - ? [[event charactersIgnoringModifiers] characterAtIndex:0] - : 0; - */ - - int code = 0; - { - NSString* s = [event characters]; - code = [s length] > 0 ? [s characterAtIndex:0] : 0; - - if (code == 0) - { - s = [event charactersIgnoringModifiers]; - code = [s length] > 0 ? [s characterAtIndex:0] : 0; - } - - geode::log::debug("key found: '{}' ({})", static_cast(code), code); - } + return g_selectedInput->onDelete(true, [event keyCode] == kVK_ForwardDelete); - switch (code) - { case 'a': case 'A': - g_selectedInput->highlightFromToPos(0, -1); - break; + return g_selectedInput->highlightFromToPos(0, -1); case 'c': case 'C': - g_selectedInput->onCopy(); - break; + return g_selectedInput->onCopy(); case 'v': case 'V': - g_selectedInput->onPaste(); - break; + return g_selectedInput->onPaste(); case 'x': case 'X': - g_selectedInput->onCut(); - break; + return g_selectedInput->onCut(); default: break; @@ -168,36 +129,31 @@ void keyDownExec(EAGLView* self, SEL sel, NSEvent* event) { switch ([event keyCode]) { case kVK_Home: - g_selectedInput->onHomeKey( + return g_selectedInput->onHomeKey( BI::platform::keyDown(BI::PlatformKey::LEFT_SHIFT, event) ); - break; case kVK_End: - g_selectedInput->onEndKey( + return g_selectedInput->onEndKey( BI::platform::keyDown(BI::PlatformKey::LEFT_SHIFT, event) ); - break; default: break; } } - - if ( - !BI::platform::keyDown(BI::PlatformKey::LEFT_SHIFT, event) && - !BI::platform::keyDown(BI::PlatformKey::LEFT_CONTROL, event) && - [event keyCode] == kVK_Return - ) { - return keyDownExecOIMP(self, sel, event); - } } + + // key is probably a regular character, allow CCIMEDispatcher to pick up the event + keyDownExecOIMP(self, sel, event); } static KeyEventType keyUpExecOIMP; void keyUpExec(EAGLView* self, SEL sel, NSEvent* event) { if (!g_selectedInput) return keyUpExecOIMP(self, sel, event); + + geode::log::debug("key released ({})", [event keyCode]); } From 0b468f902b77705529958ec5c0bec2912179dd12 Mon Sep 17 00:00:00 2001 From: SpaghettDev <37266659+SpaghettDev@users.noreply.github.com> Date: Sun, 1 Dec 2024 03:22:29 -0500 Subject: [PATCH 16/20] fix Command + A crashing --- src/macos.mm | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/macos.mm b/src/macos.mm index a9286a1..6601ef8 100644 --- a/src/macos.mm +++ b/src/macos.mm @@ -96,15 +96,11 @@ void keyDownExec(EAGLView* self, SEL sel, NSEvent* event) { if ( ![event isARepeat] && - !BI::platform::keyDown(BI::PlatformKey::LEFT_CONTROL, event) && - BI::platform::keyDown(BI::PlatformKey::LEFT_SHIFT, event) + BI::platform::keyDown(BI::PlatformKey::LEFT_CONTROL, event) && + !BI::platform::keyDown(BI::PlatformKey::LEFT_SHIFT, event) ) { switch ([event keyCode]) { - case kVK_Delete: - case kVK_ForwardDelete: - return g_selectedInput->onDelete(true, [event keyCode] == kVK_ForwardDelete); - case 'a': case 'A': return g_selectedInput->highlightFromToPos(0, -1); @@ -117,6 +113,10 @@ void keyDownExec(EAGLView* self, SEL sel, NSEvent* event) { case 'x': case 'X': return g_selectedInput->onCut(); + case kVK_Delete: + case kVK_ForwardDelete: + return g_selectedInput->onDelete(true, [event keyCode] == kVK_ForwardDelete); + default: break; } @@ -152,12 +152,10 @@ void keyDownExec(EAGLView* self, SEL sel, NSEvent* event) { void keyUpExec(EAGLView* self, SEL sel, NSEvent* event) { if (!g_selectedInput) return keyUpExecOIMP(self, sel, event); - - geode::log::debug("key released ({})", [event keyCode]); } -// TODO: move to hooking mouseDownExec +// TODO: move to hooking mouseDownExec/mouseUpExec // handles mouse clicks struct BetterTouchDispatcher : geode::Modify { @@ -167,8 +165,6 @@ void touches(cocos2d::CCSet* touches, cocos2d::CCEvent* event, unsigned int type if (!g_selectedInput) return cocos2d::CCTouchDispatcher::touches(touches, event, type); - geode::log::debug("button clicked"); - auto* touch = static_cast(touches->anyObject()); const auto touchPos = touch->getLocation(); From 9aa11d616ef0d0c5f04942dd1e26604c8a0eaf39 Mon Sep 17 00:00:00 2001 From: SpaghettDev <37266659+SpaghettDev@users.noreply.github.com> Date: Sun, 1 Dec 2024 03:28:29 -0500 Subject: [PATCH 17/20] ok i might be stupid --- src/macos.mm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/macos.mm b/src/macos.mm index 6601ef8..c54ee7b 100644 --- a/src/macos.mm +++ b/src/macos.mm @@ -101,16 +101,16 @@ void keyDownExec(EAGLView* self, SEL sel, NSEvent* event) { ) { switch ([event keyCode]) { - case 'a': case 'A': + case kVK_ANSI_A: return g_selectedInput->highlightFromToPos(0, -1); - case 'c': case 'C': + case kVK_ANSI_C: return g_selectedInput->onCopy(); - case 'v': case 'V': + case kVK_ANSI_V: return g_selectedInput->onPaste(); - case 'x': case 'X': + case kVK_ANSI_X: return g_selectedInput->onCut(); case kVK_Delete: From c484bcc6526a81595ec2a65de3f3c06c058ae19e Mon Sep 17 00:00:00 2001 From: SpaghettDev <37266659+SpaghettDev@users.noreply.github.com> Date: Sun, 1 Dec 2024 03:35:59 -0500 Subject: [PATCH 18/20] make command + A, C, V, X cross-keyboard compatible --- src/macos.mm | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/macos.mm b/src/macos.mm index c54ee7b..c6e09e7 100644 --- a/src/macos.mm +++ b/src/macos.mm @@ -99,24 +99,37 @@ void keyDownExec(EAGLView* self, SEL sel, NSEvent* event) { BI::platform::keyDown(BI::PlatformKey::LEFT_CONTROL, event) && !BI::platform::keyDown(BI::PlatformKey::LEFT_SHIFT, event) ) { + // https://github.com/WebKit/WebKit/blob/5c8281f146cfbf4b6189b435b80c527f138b829f/Source/WebCore/platform/mac/PlatformEventFactoryMac.mm#L559 + int code = [[event characters] length] > 0 + ? [[event characters] characterAtIndex:0] + : [[event charactersIgnoringModifiers] length] > 0 + ? [[event charactersIgnoringModifiers] characterAtIndex:0] + : 0; + switch ([event keyCode]) { - case kVK_ANSI_A: + case kVK_Delete: + case kVK_ForwardDelete: + g_selectedInput->onDelete(true, [event keyCode] == kVK_ForwardDelete); + break; + default: + break; + } + + switch (code) + { + case 'a': case 'A': return g_selectedInput->highlightFromToPos(0, -1); - case kVK_ANSI_C: + case 'c': case 'C': return g_selectedInput->onCopy(); - case kVK_ANSI_V: + case 'v': case 'V': return g_selectedInput->onPaste(); - case kVK_ANSI_X: + case 'x': case 'X': return g_selectedInput->onCut(); - case kVK_Delete: - case kVK_ForwardDelete: - return g_selectedInput->onDelete(true, [event keyCode] == kVK_ForwardDelete); - default: break; } @@ -187,6 +200,7 @@ void touches(cocos2d::CCSet* touches, cocos2d::CCEvent* event, unsigned int type }; +// https://github.com/qimiko/click-on-steps/blob/d8a87e93b5407e5f2113a9715363a5255724c901/src/macos.mm#L101 $on_mod(Loaded) { auto eaglView = objc_getClass("EAGLView"); From 2b9d18e6d36d1c93349c899426a48d34bb92fa5b Mon Sep 17 00:00:00 2001 From: SpaghettDev <37266659+SpaghettDev@users.noreply.github.com> Date: Sun, 1 Dec 2024 03:45:59 -0500 Subject: [PATCH 19/20] remove logs --- src/macos.mm | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/macos.mm b/src/macos.mm index c6e09e7..cf92833 100644 --- a/src/macos.mm +++ b/src/macos.mm @@ -49,14 +49,6 @@ void keyDownExec(EAGLView* self, SEL sel, NSEvent* event) { if (!g_selectedInput) return keyDownExecOIMP(self, sel, event); - geode::log::debug("key down ({})", [event keyCode]); - geode::log::debug( - "isControl: {} isShift: {} isRepeat: {}", - BI::platform::keyDown(BI::PlatformKey::LEFT_CONTROL, event), - BI::platform::keyDown(BI::PlatformKey::LEFT_SHIFT, event), - [event isARepeat] - ); - // on click, can be held if ( !BI::platform::keyDown(BI::PlatformKey::LEFT_CONTROL, event) && @@ -112,6 +104,7 @@ void keyDownExec(EAGLView* self, SEL sel, NSEvent* event) { case kVK_ForwardDelete: g_selectedInput->onDelete(true, [event keyCode] == kVK_ForwardDelete); break; + default: break; } From 30c153307f87dd3ff8cd17dd9d578f7258ceeaab Mon Sep 17 00:00:00 2001 From: SpaghettDev <37266659+SpaghettDev@users.noreply.github.com> Date: Sun, 1 Dec 2024 03:47:34 -0500 Subject: [PATCH 20/20] remove unused logs --- src/macos.mm | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/macos.mm b/src/macos.mm index cf92833..5ef36e7 100644 --- a/src/macos.mm +++ b/src/macos.mm @@ -1,8 +1,3 @@ -#include - -#include -#include - #define CommentType CommentTypeDummy #import #import