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
10 changes: 6 additions & 4 deletions loader/include/Geode/utils/Keyboard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,10 @@ namespace geode {
cocos2d::enumKeyCodes key;
Action action;
KeyboardModifier modifiers = KeyboardModifier::None;
void* physicalDevice = nullptr;

KeyboardInputData(cocos2d::enumKeyCodes key, Action action, Native native, double timestamp, KeyboardModifier mods) noexcept
: native(native), timestamp(timestamp), key(key), action(action), modifiers(mods) {}
KeyboardInputData(cocos2d::enumKeyCodes key, Action action, Native native, double timestamp, KeyboardModifier mods, void* device) noexcept
: native(native), timestamp(timestamp), key(key), action(action), modifiers(mods), physicalDevice(device) {}
};

struct KeyboardInputEvent final : GlobalEvent<KeyboardInputEvent, bool(KeyboardInputData&), cocos2d::enumKeyCodes> {
Expand All @@ -106,6 +107,7 @@ namespace geode {
Action action;
double timestamp;
KeyboardModifier modifiers = KeyboardModifier::None;
void* physicalDevice = nullptr;

// having this here is incredibly silly but oh well
inline static cocos2d::enumKeyCodes buttonToKeyCode(Button button) {
Expand All @@ -121,8 +123,8 @@ namespace geode {
}
}

MouseInputData(Button button, Action action, double timestamp, KeyboardModifier mods) noexcept
: timestamp(timestamp), button(button), action(action), modifiers(mods) {}
MouseInputData(Button button, Action action, double timestamp, KeyboardModifier mods, void* device) noexcept
: timestamp(timestamp), button(button), action(action), modifiers(mods), physicalDevice(device) {}
};

struct MouseInputEvent final : Event<MouseInputEvent, bool(MouseInputData&)> {
Expand Down
6 changes: 4 additions & 2 deletions loader/src/platform/android/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ namespace {
timestamp,
(isShiftPressed ? KeyboardModifier::Shift : KeyboardModifier::None) |
(isCtrlPressed ? KeyboardModifier::Control : KeyboardModifier::None) |
(isAltPressed ? KeyboardModifier::Alt : KeyboardModifier::None)
(isAltPressed ? KeyboardModifier::Alt : KeyboardModifier::None),
nullptr
);

if (KeyboardInputEvent(translated_code).send(data) != ListenerResult::Propagate) {
Expand Down Expand Up @@ -204,7 +205,8 @@ namespace {
timestamp,
(isShiftPressed ? KeyboardModifier::Shift : KeyboardModifier::None) |
(isCtrlPressed ? KeyboardModifier::Control : KeyboardModifier::None) |
(isAltPressed ? KeyboardModifier::Alt : KeyboardModifier::None)
(isAltPressed ? KeyboardModifier::Alt : KeyboardModifier::None),
nullptr
);

if (KeyboardInputEvent(translated_code).send(data) != ListenerResult::Propagate) {
Expand Down
9 changes: 6 additions & 3 deletions loader/src/platform/ios/input.mm
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ KeyboardInputData data(
keyCode, isRepeat ? KeyboardInputData::Action::Repeat : KeyboardInputData::Action::Press,
{ nativeCode },
timestamp,
modifiers
modifiers,
nullptr
);

if (KeyboardInputEvent(keyCode).send(data) != ListenerResult::Propagate) return;
Expand Down Expand Up @@ -255,7 +256,8 @@ KeyboardInputData data(
keyCode, KeyboardInputData::Action::Release,
{ nativeCode },
timestamp,
modifiers
modifiers,
nullptr
);

if (KeyboardInputEvent(keyCode).send(data) != ListenerResult::Propagate) return;
Expand Down Expand Up @@ -355,7 +357,8 @@ KeyboardInputData data(
[btn isPressed] ? KeyboardInputData::Action::Press : KeyboardInputData::Action::Release,
{0}, // Controller buttons don't have native codes.
(double) [gamepad lastEventTimestamp],
KeyboardModifier::None
KeyboardModifier::None,
nullptr
);
if (KeyboardInputEvent(key).send(data) != ListenerResult::Propagate) return;
if (data.key != KEY_Unknown && (!imeDispatcher->hasDelegate() || data.key == KEY_Escape || data.key == KEY_Enter)) {
Expand Down
6 changes: 4 additions & 2 deletions loader/src/platform/mac/input.mm
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ KeyboardInputData data(
keyCode, isRepeat ? KeyboardInputData::Action::Repeat : KeyboardInputData::Action::Press,
{ nativeCode },
timestamp,
modifiers
modifiers,
nullptr
);

if (KeyboardInputEvent(keyCode).send(data) != ListenerResult::Propagate) return;
Expand Down Expand Up @@ -327,7 +328,8 @@ KeyboardInputData data(
keyCode, KeyboardInputData::Action::Release,
{ nativeCode },
timestamp,
modifiers
modifiers,
nullptr
);

if (KeyboardInputEvent(keyCode).send(data) != ListenerResult::Propagate) return;
Expand Down
28 changes: 19 additions & 9 deletions loader/src/platform/windows/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using namespace geode::prelude;

struct RawInputEvent {
void* physicalDevice = nullptr;
double timestamp = 0.0;
KeyboardModifier mods;

Expand All @@ -36,7 +37,7 @@ struct RawInputEvent {
} type;

static RawInputEvent makeKeyboard(
bool isDown, uint16_t vk, uint16_t scan, uint16_t flags, bool isRepeat, KeyboardModifier mods
bool isDown, uint16_t vk, uint16_t scan, uint16_t flags, bool isRepeat, KeyboardModifier mods, void* device
) {
RawInputEvent evt;
evt.type = isDown ? Type::KeyDown : Type::KeyUp;
Expand All @@ -48,15 +49,17 @@ struct RawInputEvent {
evt.keyboard.isE0 = (flags & RI_KEY_E0) != 0;
evt.keyboard.isE1 = (flags & RI_KEY_E1) != 0;
evt.keyboard.isRepeat = isRepeat;
evt.physicalDevice = device;
return evt;
}

static RawInputEvent makeMouse(uint16_t btnFlags, KeyboardModifier mods) {
static RawInputEvent makeMouse(uint16_t btnFlags, KeyboardModifier mods, void* device) {
RawInputEvent evt;
evt.type = Type::MouseButton;
evt.timestamp = getInputTimestamp();
evt.mods = mods;
evt.mouse.flags = btnFlags;
evt.physicalDevice = device;
return evt;
}
};
Expand Down Expand Up @@ -407,7 +410,8 @@ LRESULT CALLBACK GeodeRawInputWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
kb.MakeCode,
kb.Flags,
isRepeat,
KeyStateTracker::get().getMods()
KeyStateTracker::get().getMods(),
raw->header.hDevice
));
} else if (raw->header.dwType == RIM_TYPEMOUSE) {
auto const& mouse = raw->data.mouse;
Expand All @@ -417,7 +421,8 @@ LRESULT CALLBACK GeodeRawInputWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM

RawInputQueue::get().push(RawInputEvent::makeMouse(
mouse.usButtonFlags,
KeyStateTracker::get().getMods()
KeyStateTracker::get().getMods(),
raw->header.hDevice
));
}

Expand Down Expand Up @@ -484,7 +489,8 @@ struct GeodeRawInput : Modify<GeodeRawInput, CCEGLView> {
isDown ? (evt.keyboard.isRepeat ? Repeat : Press) : Release,
{evt.keyboard.vkey, evt.keyboard.scanCode},
evt.timestamp,
mods
mods,
evt.physicalDevice
);

auto result = KeyboardInputEvent(keyCode).send(data);
Expand Down Expand Up @@ -558,7 +564,8 @@ struct GeodeRawInput : Modify<GeodeRawInput, CCEGLView> {
b.btn,
isDown ? Press : Release,
evt.timestamp,
evt.mods
evt.mods,
evt.physicalDevice
);

auto result = MouseInputEvent().send(data);
Expand Down Expand Up @@ -731,7 +738,8 @@ struct GeodeControllerInput : Modify<GeodeControllerInput, CCApplication> {
isDown ? KeyboardInputData::Action::Press : KeyboardInputData::Action::Release,
{},
timestamp,
KeyboardModifier::None
KeyboardModifier::None,
controller
);

if (KeyboardInputEvent(data.key).send(data) == ListenerResult::Stop) {
Expand Down Expand Up @@ -771,7 +779,8 @@ struct GeodeControllerInput : Modify<GeodeControllerInput, CCApplication> {
isADown ? KeyboardInputData::Action::Press : KeyboardInputData::Action::Release,
{},
timestamp,
KeyboardModifier::None
KeyboardModifier::None,
controller
);

if (KeyboardInputEvent(data.key).send(data) == ListenerResult::Propagate) {
Expand Down Expand Up @@ -818,7 +827,8 @@ struct GeodeControllerInput : Modify<GeodeControllerInput, CCApplication> {
isBackDown ? KeyboardInputData::Action::Press : KeyboardInputData::Action::Release,
{},
timestamp,
KeyboardModifier::None
KeyboardModifier::None,
controller
);

if (KeyboardInputEvent(data.key).send(data) == ListenerResult::Propagate) {
Expand Down
Loading