Skip to content
Open
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 @@ -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": {
Expand Down
72 changes: 34 additions & 38 deletions src/backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
/*
Expand Down Expand Up @@ -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<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 @@ -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) {
Expand All @@ -547,6 +544,5 @@ class $modify(CCKeyboardDispatcher) {
io.AddKeyEvent(ImGuiKey_ModSuper, cmd);
CCKeyboardDispatcher::updateModifierKeys(shft, ctrl, alt, cmd);
}
#endif
};
#endif
#endif
19 changes: 6 additions & 13 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <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