Skip to content

Commit 98f7936

Browse files
1.10.3 (Reset button bugfix + Command/Control/Arrow bugfix) (#89)
* Fix reset button appearing for default keybinds * Long-awaited fixes * Changelogger * Add editor zooming hack * Small oversight --------- Co-authored-by: Jasmine <[email protected]>
1 parent e7adc4b commit 98f7936

File tree

8 files changed

+51
-54
lines changed

8 files changed

+51
-54
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
44
set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64")
55
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
66

7-
project(CustomKeybinds VERSION 1.10.1)
7+
project(CustomKeybinds VERSION 1.10.3)
88

99
file(GLOB SOURCES
1010
src/*.hpp

changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
# Changelog
2+
## v1.10.3
3+
- Fixed reset button appearing for default keybinds
4+
- Fixed command/control and arrow key keybinds not working on MacOS
5+
- Thanks hiimjasmine00!
6+
27
## v1.10.2
38
- MacOS support
49
- Thanks hiimjasmine00!

include/Keybinds.hpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,6 @@ namespace keybinds {
6161
Shift = 0b0010,
6262
Alt = 0b0100,
6363
Command = 0b1000,
64-
#ifdef GEODE_IS_MACOS
65-
PlatformControl = Command,
66-
#else
67-
PlatformControl = Control,
68-
#endif
6964
};
7065
CUSTOM_KEYBINDS_DLL Modifier operator|(Modifier const& a, Modifier const& b);
7166
CUSTOM_KEYBINDS_DLL Modifier operator|=(Modifier& a, Modifier const& b);

mod.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"android": "2.2074",
66
"mac": "2.2074"
77
},
8-
"version": "v1.10.2",
8+
"version": "v1.10.3",
99
"id": "geode.custom-keybinds",
1010
"name": "Custom Keybinds",
1111
"developer": "Geode Team",

src/EditorUI.cpp

Lines changed: 32 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,6 @@
99
using namespace geode::prelude;
1010
using namespace keybinds;
1111

12-
// TODO: move this to header in 1.2.0
13-
14-
class EvilBypass : public CCKeyboardDispatcher {
15-
public:
16-
bool setControlPressed(bool pressed) {
17-
auto old = m_bControlPressed;
18-
m_bControlPressed = pressed;
19-
return old;
20-
}
21-
bool setCommandPressed(bool pressed) {
22-
auto old = m_bCommandPressed;
23-
m_bCommandPressed = pressed;
24-
return old;
25-
}
26-
bool setShiftPressed(bool pressed) {
27-
auto old = m_bShiftPressed;
28-
m_bShiftPressed = pressed;
29-
return old;
30-
}
31-
bool setAltPressed(bool pressed) {
32-
auto old = m_bAltPressed;
33-
m_bAltPressed = pressed;
34-
return old;
35-
}
36-
};
37-
3812
struct $modify(EditorPauseLayer) {
3913
static void onModify(auto& self) {
4014
(void)self.setHookPriority("EditorPauseLayer::keyDown", 1000);
@@ -129,28 +103,28 @@ struct $modify(EditorUI) {
129103
this->passThroughKeyDown(KEY_Delete);
130104
});
131105
this->defineKeybind("robtop.geometry-dash/undo", [this] {
132-
this->passThroughKeyDown(KEY_Z, Modifier::PlatformControl);
106+
this->passThroughKeyDown(KEY_Z, Modifier::Control);
133107
});
134108
this->defineKeybind("robtop.geometry-dash/redo", [this] {
135-
this->passThroughKeyDown(KEY_Z, Modifier::PlatformControl | Modifier::Shift);
109+
this->passThroughKeyDown(KEY_Z, Modifier::Control | Modifier::Shift);
136110
});
137111
this->defineKeybind("robtop.geometry-dash/deselect-all", [this] {
138112
this->passThroughKeyDown(KEY_D, Modifier::Alt);
139113
});
140114
this->defineKeybind("robtop.geometry-dash/copy", [this] {
141-
this->passThroughKeyDown(KEY_C, Modifier::PlatformControl);
115+
this->passThroughKeyDown(KEY_C, Modifier::Control);
142116
});
143117
this->defineKeybind("robtop.geometry-dash/paste", [this] {
144-
this->passThroughKeyDown(KEY_V, Modifier::PlatformControl);
118+
this->passThroughKeyDown(KEY_V, Modifier::Control);
145119
});
146120
this->defineKeybind("robtop.geometry-dash/copy-paste", [this] {
147-
this->passThroughKeyDown(KEY_D, Modifier::PlatformControl);
121+
this->passThroughKeyDown(KEY_D, Modifier::Control);
148122
});
149123
this->defineKeybind("robtop.geometry-dash/toggle-rotate", [this] {
150124
this->passThroughKeyDown(KEY_R);
151125
});
152126
this->defineKeybind("robtop.geometry-dash/toggle-transform", [this] {
153-
this->passThroughKeyDown(KEY_T, Modifier::PlatformControl);
127+
this->passThroughKeyDown(KEY_T, Modifier::Control);
154128
});
155129
this->defineKeybind("robtop.geometry-dash/toggle-free-move", [this] {
156130
this->passThroughKeyDown(KEY_F);
@@ -166,7 +140,7 @@ struct $modify(EditorUI) {
166140
});
167141
this->defineKeybind("robtop.geometry-dash/playback-music", [this] {
168142
// RobTop broke this in 2.2, which makes it trigger the playtest keybind
169-
// this->passThroughKeyDown(KEY_Enter, Modifier::PlatformControl);
143+
// this->passThroughKeyDown(KEY_Enter, Modifier::Control);
170144
EditorUI::onPlayback(nullptr);
171145
});
172146
this->defineKeybind("robtop.geometry-dash/prev-build-tab", [this] {
@@ -249,7 +223,7 @@ struct $modify(EditorUI) {
249223
auto x = std::to_string(i);
250224
auto key = static_cast<enumKeyCodes>(KEY_Zero + i);
251225
this->defineKeybind("robtop.geometry-dash/save-editor-position-" + x, [this, key] {
252-
this->passThroughKeyDown(key, Modifier::PlatformControl);
226+
this->passThroughKeyDown(key, Modifier::Control);
253227
});
254228
this->defineKeybind("robtop.geometry-dash/load-editor-position-" + x, [this, key] {
255229
this->passThroughKeyDown(key, Modifier::Alt);
@@ -298,16 +272,20 @@ struct $modify(EditorUI) {
298272

299273
void passThroughKeyDown(enumKeyCodes key, Modifier modifiers = Modifier::None) {
300274
s_allowPassThrough = true;
301-
auto d = static_cast<EvilBypass*>(CCKeyboardDispatcher::get());
302-
auto alt = d->setAltPressed(modifiers & Modifier::Alt);
303-
auto shift = d->setShiftPressed(modifiers & Modifier::Shift);
304-
auto ctrl = d->setControlPressed(modifiers & Modifier::Control);
305-
auto cmd = d->setCommandPressed(modifiers & Modifier::Command);
275+
auto d = CCKeyboardDispatcher::get();
276+
auto alt = d->m_bAltPressed;
277+
auto shift = d->m_bShiftPressed;
278+
auto ctrl = d->m_bControlPressed;
279+
auto cmd = d->m_bCommandPressed;
280+
d->m_bAltPressed = modifiers & Modifier::Alt;
281+
d->m_bShiftPressed = modifiers & Modifier::Shift;
282+
d->m_bControlPressed = modifiers & Modifier::Control;
283+
d->m_bCommandPressed = modifiers & Modifier::Command;
306284
this->keyDown(key);
307-
d->setAltPressed(alt);
308-
d->setShiftPressed(shift);
309-
d->setControlPressed(ctrl);
310-
d->setCommandPressed(cmd);
285+
d->m_bAltPressed = alt;
286+
d->m_bShiftPressed = shift;
287+
d->m_bControlPressed = ctrl;
288+
d->m_bCommandPressed = cmd;
311289
}
312290

313291
void keyDown(enumKeyCodes key) {
@@ -325,6 +303,15 @@ struct $modify(EditorUI) {
325303
EditorUI::keyUp(key);
326304
}
327305
}
306+
#ifdef GEODE_IS_MACOS // Editor zooming hack
307+
void scrollWheel(float y, float x) {
308+
auto d = CCKeyboardDispatcher::get();
309+
auto ctrl = d->m_bControlPressed;
310+
d->m_bControlPressed = ctrl || d->m_bCommandPressed;
311+
EditorUI::scrollWheel(y, x);
312+
d->m_bControlPressed = ctrl;
313+
}
314+
#endif
328315
};
329316

330317
$execute {
@@ -496,14 +483,14 @@ struct $modify(EditorUI) {
496483
"robtop.geometry-dash/next-layer",
497484
"Next Layer",
498485
"Go to Next Editor Layer",
499-
{ Keybind::create(KEY_Right, Modifier::None) },
486+
{ Keybind::create(KEY_Right, Modifier::None), GEODE_MACOS(Keybind::create(KEY_ArrowRight, Modifier::None)) },
500487
Category::EDITOR_UI, true
501488
});
502489
BindManager::get()->registerBindable({
503490
"robtop.geometry-dash/prev-layer",
504491
"Previous Layer",
505492
"Go to Previous Editor Layer",
506-
{ Keybind::create(KEY_Left, Modifier::None) },
493+
{ Keybind::create(KEY_Left, Modifier::None), GEODE_MACOS(Keybind::create(KEY_ArrowLeft, Modifier::None)) },
507494
Category::EDITOR_UI, true
508495
});
509496
BindManager::get()->registerBindable({

src/Keybind.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Modifier Keybind::getModifiers() const {
3737
}
3838

3939
size_t Keybind::getHash() const {
40-
return m_key | (static_cast<int>(m_modifiers) << 29);
40+
return static_cast<size_t>(m_key) | (static_cast<size_t>(m_modifiers) << 29);
4141
}
4242

4343
bool Keybind::isEqual(Bind* other) const {

src/Keybinds.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,10 @@ std::vector<Ref<Bind>> BindManager::getBindsFor(ActionID const& action) const {
536536
binds.push_back(bind.bind);
537537
}
538538
}
539+
// since they aren't always sorted correctly...
540+
std::sort(binds.begin(), binds.end(), [](auto const& a, auto const& b) {
541+
return a->getHash() < b->getHash();
542+
});
539543
return binds;
540544
}
541545

src/UILayer.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,11 @@ struct $modify(UILayer) {
309309
"robtop.geometry-dash/jump-p2",
310310
"Jump P2",
311311
"Player 2 Jump",
312-
{ Keybind::create(KEY_Up), ControllerBind::create(CONTROLLER_LB) },
312+
{
313+
Keybind::create(KEY_Up),
314+
GEODE_MACOS(Keybind::create(KEY_ArrowUp, Modifier::None),)
315+
ControllerBind::create(CONTROLLER_LB)
316+
},
313317
Category::PLAY,
314318
false
315319
});
@@ -343,6 +347,7 @@ struct $modify(UILayer) {
343347
"Player 2 move left",
344348
{
345349
Keybind::create(KEY_Left),
350+
GEODE_MACOS(Keybind::create(KEY_ArrowLeft, Modifier::None),)
346351
ControllerBind::create(CONTROLLER_RTHUMBSTICK_LEFT)
347352
},
348353
Category::PLAY,
@@ -354,6 +359,7 @@ struct $modify(UILayer) {
354359
"Player 2 move right",
355360
{
356361
Keybind::create(KEY_Right),
362+
GEODE_MACOS(Keybind::create(KEY_ArrowRight, Modifier::None),)
357363
ControllerBind::create(CONTROLLER_RTHUMBSTICK_RIGHT)
358364
},
359365
Category::PLAY,

0 commit comments

Comments
 (0)