Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,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": {
Expand Down
53 changes: 35 additions & 18 deletions src/backend.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include <cocos2d.h>
#include <Geode/modify/CCTouchDispatcher.hpp>
#ifndef GEODE_IS_IOS
#include <Geode/modify/CCMouseDispatcher.hpp>
#include <Geode/modify/CCKeyboardDispatcher.hpp>
#endif
#include <Geode/modify/CCIMEDispatcher.hpp>
#include "Geode/cocos/text_input_node/CCIMEDelegate.h"
#include "Geode/platform/cplatform.h"
Expand Down Expand Up @@ -494,30 +496,29 @@ 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);
$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<char>(key);
if (data.key >= KEY_A && data.key <= KEY_Z) {
c = static_cast<char>(data.key);
if (!io.KeyShift) {
c = static_cast<char>(tolower(c));
}
} else if (key >= KEY_Zero && key <= KEY_Nine) {
c = static_cast<char>('0' + (key - KEY_Zero));
} else if (key == KEY_Space) {
} else if (data.key >= KEY_Zero && data.key <= KEY_Nine) {
c = static_cast<char>('0' + (data.key - KEY_Zero));
} else if (data.key == KEY_Space) {
c = ' ';
}

Expand All @@ -526,20 +527,37 @@ 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();

#if defined(GEODE_IS_MACOS)
#ifdef GEODE_IS_IOS
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 (!io.WantCaptureMouse || shouldPassEventsToGDButTransformed()) {
return ListenerResult::Propagate;
}

return ListenerResult::Stop;
}).leak();
#endif
}

#if defined(GEODE_IS_MACOS)
class $modify(CCKeyboardDispatcher) {
static void onModify(auto& self) {
Result<> res = self.setHookPriorityBeforePre("CCKeyboardDispatcher::updateModifierKeys", "geode.custom-keybinds");
if (!res) {
Expand All @@ -555,6 +573,5 @@ class $modify(CCKeyboardDispatcher) {
io.AddKeyEvent(ImGuiKey_ModSuper, cmd);
CCKeyboardDispatcher::updateModifierKeys(shft, ctrl, alt, cmd);
}
#endif
};
#endif
20 changes: 6 additions & 14 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "platform/platform.hpp"
#include <Geode/modify/CCKeyboardDispatcher.hpp>
#include <Geode/modify/AchievementNotifier.hpp>
#include <Geode/modify/CCDirector.hpp>
#include <Geode/modify/CCEGLView.hpp>
Expand All @@ -20,24 +19,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 <Geode/loader/GameEvent.hpp>
$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 <Geode/modify/CCScene.hpp>
Expand Down
Loading