diff --git a/mod.json b/mod.json index 27b6ef6..31309d3 100644 --- a/mod.json +++ b/mod.json @@ -25,6 +25,17 @@ "name": "Use GD window", "description": "Determines if the DevTools should use a custom GD window or not. Required to disable for some exotic configurations (MacOS Wine).", "default": true + }, + "open-bind": { + "type": "keybind", + "name": "DevTools Keybind", + "descriptions": "The keybind to open DevTools", + "default": { + "win": "F11", + "mac": ["F10", "F11"], + "android": "F11", + "ios": "F11" + } } }, "resources": { diff --git a/src/backend.cpp b/src/backend.cpp index 394efa5..bd6c7b7 100644 --- a/src/backend.cpp +++ b/src/backend.cpp @@ -329,25 +329,6 @@ void DevTools::renderDrawData(ImDrawData* draw_data) { glDisable(GL_SCISSOR_TEST); } -static float SCROLL_SENSITIVITY = 10; - -#ifndef GEODE_IS_IOS -class $modify(CCMouseDispatcher) { - bool dispatchScrollMSG(float y, float x) { - if(!DevTools::get()->isSetup()) return true; - - auto& io = ImGui::GetIO(); - io.AddMouseWheelEvent(x / SCROLL_SENSITIVITY, -y / SCROLL_SENSITIVITY); - - if (!io.WantCaptureMouse || shouldPassEventsToGDButTransformed()) { - return CCMouseDispatcher::dispatchScrollMSG(y, x); - } - - return true; - } -}; -#endif - class $modify(CCTouchDispatcher) { static void onModify(auto& self) { /* @@ -486,30 +467,31 @@ ImGuiKey cocosToImGuiKey(cocos2d::enumKeyCodes key) { } } -#ifndef GEODE_IS_IOS -class $modify(CCKeyboardDispatcher) { - bool dispatchKeyboardMSG(enumKeyCodes key, bool down, bool repeat, double a4) { - if(!DevTools::get()->isSetup()) return CCKeyboardDispatcher::dispatchKeyboardMSG(key, down, repeat, a4); +static float SCROLL_SENSITIVITY = 10; + +$on_mod(Loaded) { + KeyboardInputEvent().listen([](KeyboardInputData& data){ + if(!DevTools::get()->isSetup()) return ListenerResult::Propagate; auto& io = ImGui::GetIO(); - const auto imKey = cocosToImGuiKey(key); + const auto imKey = cocosToImGuiKey(data.key); if (imKey != ImGuiKey_None) { - io.AddKeyEvent(imKey, down); + io.AddKeyEvent(imKey, data.action != KeyboardInputData::Action::Release); } // CCIMEDispatcher stuff only gets called on mobile if the virtual keyboard would be up. // Similarly, CCKeyboardDispatcher doesn't get called if the virtual keyboard would be up. #ifdef GEODE_IS_MOBILE - if (down) { + if (data.action != KeyboardInputData::Action::Release) { char c = 0; - if (key >= KEY_A && key <= KEY_Z) { - c = static_cast(key); + if (data.key >= KEY_A && data.key <= KEY_Z) { + c = static_cast(data.key); if (!io.KeyShift) { c = static_cast(tolower(c)); } - } else if (key >= KEY_Zero && key <= KEY_Nine) { - c = static_cast('0' + (key - KEY_Zero)); - } else if (key == KEY_Space) { + } else if (data.key >= KEY_Zero && data.key <= KEY_Nine) { + c = static_cast('0' + (data.key - KEY_Zero)); + } else if (data.key == KEY_Space) { c = ' '; } @@ -518,20 +500,35 @@ class $modify(CCKeyboardDispatcher) { io.AddInputCharactersUTF8(str.c_str()); } } - if (key == KEY_Backspace) { + if (data.key == KEY_Backspace) { io.AddKeyEvent(ImGuiKey_Backspace, true); io.AddKeyEvent(ImGuiKey_Backspace, false); } #endif if (io.WantCaptureKeyboard) { - return false; + return ListenerResult::Stop; } else { - return CCKeyboardDispatcher::dispatchKeyboardMSG(key, down, repeat, a4); + return ListenerResult::Propagate; } - } + }).leak(); + + ScrollWheelEvent().listen([](float x, float y) { + if(!DevTools::get()->isSetup()) return true; + + auto& io = ImGui::GetIO(); + io.AddMouseWheelEvent(x / SCROLL_SENSITIVITY, -y / SCROLL_SENSITIVITY); - #if defined(GEODE_IS_MACOS) + if (!io.WantCaptureMouse || shouldPassEventsToGDButTransformed()) { + return ListenerResult::Propagate; + } + + return ListenerResult::Stop; + }).leak(); +} + +#if defined(GEODE_IS_MACOS) +class $modify(CCKeyboardDispatcher) { static void onModify(auto& self) { Result<> res = self.setHookPriorityBeforePre("CCKeyboardDispatcher::updateModifierKeys", "geode.custom-keybinds"); if (!res) { @@ -547,6 +544,5 @@ class $modify(CCKeyboardDispatcher) { io.AddKeyEvent(ImGuiKey_ModSuper, cmd); CCKeyboardDispatcher::updateModifierKeys(shft, ctrl, alt, cmd); } - #endif }; -#endif \ No newline at end of file +#endif diff --git a/src/main.cpp b/src/main.cpp index a210de8..ea1d67d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -20,24 +20,17 @@ class $modify(CCNode) { } }; -// todo: use shortcuts api once Geode has those -#ifndef GEODE_IS_IOS -class $modify(CCKeyboardDispatcher) { - bool dispatchKeyboardMSG(enumKeyCodes key, bool down, bool arr, double timestamp) { - if (down && (key == KEY_F11 GEODE_MACOS(|| key == KEY_F10))) { - DevTools::get()->toggle(); - return true; - } - return CCKeyboardDispatcher::dispatchKeyboardMSG(key, down, arr, timestamp); - } -}; -#endif - #include $execute { GameEvent(GameEventType::Loaded).listen([] { if (DevTools::get()->isButtonEnabled()) DevTools::get()->setupDragButton(); }).leak(); + + listenForKeybindSettingPresses("open-bind", [](Keybind const& keybind, bool down, bool repeat, double timestamp) { + if (down && !repeat) { + DevTools::get()->toggle(); + } + }); } #include