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
25 changes: 16 additions & 9 deletions src/window_callbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ void WindowCallbacks::onTouchEnd(int id, double x, double y) {
}
}
void WindowCallbacks::onKeyboard(KeyCode key, KeyAction action) {
if(hasInputMode(InputMode::Mouse)) {
if(sendEvents) {
// return onKeyboard((KeyCode) 4, KeyAction::PRESS);
// key = (KeyCode) 0x21;
#ifdef __APPLE__
Expand Down Expand Up @@ -188,20 +188,26 @@ void WindowCallbacks::onKeyboard(KeyCode key, KeyAction action) {
}
}
void WindowCallbacks::onKeyboardText(std::string const& c) {
if(c == "\n" && !jniSupport.getTextInputHandler().isMultiline())
jniSupport.onReturnKeyPressed();
else
jniSupport.getTextInputHandler().onTextInput(c);
if(sendEvents) {
if(c == "\n" && !jniSupport.getTextInputHandler().isMultiline()) {
jniSupport.onReturnKeyPressed();
} else {
jniSupport.getTextInputHandler().onTextInput(c);
}
}
}
void WindowCallbacks::onPaste(std::string const& str) {
jniSupport.getTextInputHandler().onTextInput(str);
if(sendEvents) {
jniSupport.getTextInputHandler().onTextInput(str);
}
}
void WindowCallbacks::onGamepadState(int gamepad, bool connected) {
Log::trace("WindowCallbacks", "Gamepad %s #%i", connected ? "connected" : "disconnected", gamepad);
if(connected)
if(connected) {
gamepads.insert({gamepad, GamepadData()});
else
} else {
gamepads.erase(gamepad);
}

if(sendEvents) {
// This crashs the game 1.16.210+ during init, but works after loading
Expand All @@ -212,8 +218,9 @@ void WindowCallbacks::onGamepadState(int gamepad, bool connected) {
}

void WindowCallbacks::queueGamepadAxisInputIfNeeded(int gamepad) {
if(!needsQueueGamepadInput)
if(!needsQueueGamepadInput) {
return;
}
inputQueue.addEvent(FakeMotionEvent(AINPUT_SOURCE_GAMEPAD, gamepad, AMOTION_EVENT_ACTION_MOVE, 0, 0.f, 0.f,
[this, gamepad](int axis) {
auto gpi = gamepads.find(gamepad);
Expand Down
3 changes: 2 additions & 1 deletion src/window_callbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ class WindowCallbacks {
bool needsQueueGamepadInput = true;
bool fullscreen = options.fullscreen;
bool sendEvents = false;
// Prefer Touch, Gamepad over Mouse due to Input Emulation
enum class InputMode {
Touch,
Mouse,
Gamepad,
Mouse,
Unknown,
};
InputMode inputMode = InputMode::Unknown;
Expand Down