Skip to content

Commit

Permalink
Shift hold fix (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alphalaneous authored May 14, 2024
1 parent 276ffb5 commit 642b7e3
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <Geode/modify/CCKeyboardDispatcher.hpp>
#include <Geode/modify/MoreOptionsLayer.hpp>
#include <Geode/modify/CCEGLView.hpp>
#include <Geode/binding/AppDelegate.hpp>
#include <Geode/binding/PlatformToolbox.hpp>
#include <Geode/binding/ButtonSprite.hpp>
Expand All @@ -18,6 +19,31 @@
using namespace geode::prelude;
using namespace keybinds;

class $modify(CCEGLView){

/**
* GD does not pass shift into dispatchKeyboardMSG, causing the modifier to break when holding.
* We need to manually pass in shift from onGLFWKeyCallback to resolve this bug.
*/
void onGLFWKeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods) {
enumKeyCodes keycode = enumKeyCodes::KEY_Unknown;

switch (key) {
case GLFW_KEY_LEFT_SHIFT:
keycode = enumKeyCodes::KEY_LeftShift;
break;
case GLFW_KEY_RIGHT_SHIFT:
keycode = enumKeyCodes::KEY_RightShift;
break;
}

if (keycode != enumKeyCodes::KEY_Unknown) {
CCKeyboardDispatcher::get()->dispatchKeyboardMSG(keycode, action >= 1, action == 2);
}
CCEGLView::onGLFWKeyCallback(window, key, scancode, action, mods);
}
};

class $modify(CCKeyboardDispatcher) {
static inline std::unordered_set<enumKeyCodes> s_held {};

Expand Down Expand Up @@ -67,8 +93,12 @@ class $modify(CCKeyboardDispatcher) {
// dispatch release events for Modifier + Key combos
else {
// If no actual key was being held, just modifiers
if (s_held.empty() && !down) {
return CCKeyboardDispatcher::dispatchKeyboardMSG(key, down, p2);
if (!down) {
// Stop repeats here, resolves repeat issue when keys and modifiers are pressed in reverse
BindManager::get()->stopAllRepeats();
if (s_held.empty()) {
return CCKeyboardDispatcher::dispatchKeyboardMSG(key, down, p2);
}
}
std::unordered_set<Modifier> modifiersToToggle = this->getModifiersToToggle(key, down);
bool ok = true;
Expand Down

0 comments on commit 642b7e3

Please sign in to comment.