From cc026528ea21382f943ffa5c573c363decdb7bf2 Mon Sep 17 00:00:00 2001 From: altalk23 <45172705+altalk23@users.noreply.github.com> Date: Tue, 26 Aug 2025 18:49:58 +0300 Subject: [PATCH] implement horizontal scrolling with trackpad to windows (and bring back macos) --- mod.json | 8 ++++ src/features/FixMouseControls.cpp | 68 +++++++++++++++++++++++-------- 2 files changed, 58 insertions(+), 18 deletions(-) diff --git a/mod.json b/mod.json index 0afd25a..875218f 100644 --- a/mod.json +++ b/mod.json @@ -115,6 +115,14 @@ "platforms": ["desktop"], "enable-if": "enable-fixed-mouse-controls" }, + "mouse-scroll-sensitivity": { + "type": "float", + "default": 32.0, + "name": "Mouse Scroll Sensitivity", + "description": "Controls the sensitivity of the mouse scroll input.", + "platforms": ["win"], + "enable-if": "enable-fixed-mouse-controls" + }, "pinch-to-zoom": { "type": "bool", "default": true, diff --git a/src/features/FixMouseControls.cpp b/src/features/FixMouseControls.cpp index 2989678..f9673b4 100644 --- a/src/features/FixMouseControls.cpp +++ b/src/features/FixMouseControls.cpp @@ -1,5 +1,6 @@ #include +#include #include #include #include @@ -13,6 +14,38 @@ using namespace geode::prelude; #ifdef GEODE_IS_DESKTOP +#ifdef GEODE_IS_WINDOWS + +class $modify(MouseScrollWindowsFix, CCEGLView){ + static void onModify(auto& self) { + // The static version inlines the actual callback, so i uninline it by hooking it + (void)Mod::get()->hook((void*)(base::getCocos() + 0x76390), &MouseScrollWindowsFix::onGLFWMouseScrollCallbackStatic, "onGLFWMouseScrollCallbackStatic"); + + (void)self.setHookPriority("cocos2d::CCEGLView::onGLFWMouseScrollCallback", Priority::Replace); + } + + static MouseScrollWindowsFix* get() { + return static_cast(CCEGLView::get()); + } + + // + $override + void onGLFWMouseScrollCallback(GLFWwindow* window, double xpos, double ypos) { + if (!Mod::get()->getSettingValue("enable-fixed-mouse-controls")) { + return CCEGLView::onGLFWMouseScrollCallback(window, xpos, ypos); + } + + auto sensitivity = Mod::get()->getSettingValue("mouse-scroll-sensitivity"); + CCDirector::get()->getMouseDispatcher()->dispatchScrollMSG(-ypos * sensitivity, xpos * sensitivity); + } + + static void onGLFWMouseScrollCallbackStatic(GLFWwindow* window, double xpos, double ypos) { + MouseScrollWindowsFix::get()->CCEGLView::onGLFWMouseScrollCallback(window, xpos, ypos); + } +}; + +#endif + class $modify(EditorUI) { $override virtual void scrollWheel(float y, float x) { @@ -60,27 +93,26 @@ class $modify(EditorUI) { } // otherwise move screen else { - constexpr float mult = 2.f; - - // move horizontally on shift - if (CCKeyboardDispatcher::get()->getShiftKeyPressed()) { - objLayer->setPositionX( - objLayer->getPositionX() - y * mult - ); + // move normally if x doesnt exist + if (std::fabs(x) < std::numeric_limits::epsilon()) { + // move horizontally on shift + if (CCKeyboardDispatcher::get()->getShiftKeyPressed()) { + objLayer->setPositionX( + objLayer->getPositionX() - y + ); + } + // otherwise move as is in vanilla + else { + objLayer->setPositionY( + objLayer->getPositionY() + y + ); + } } - // otherwise move as is in vanilla + // use both axes, ignore shift else { - // add support for the horizontal trackpad scrolling on mac - // causes the editor to move sideways when scrolling on windows - #ifdef GEODE_IS_MACOS - objLayer->setPositionX( - objLayer->getPositionX() + y * mult - ); - #else - objLayer->setPositionY( - objLayer->getPositionY() + y * mult + objLayer->setPosition( + objLayer->getPosition() + ccp(x, y) ); - #endif } // call original but make it not do anything other than update