SDL mouse input fixes

This commit is contained in:
Henrik Rydgård 2024-11-06 12:04:24 +01:00
parent 55aa1ff66e
commit c68c5353b0
2 changed files with 23 additions and 9 deletions

View File

@ -948,6 +948,7 @@ static void ProcessSDLEvent(SDL_Window *window, const SDL_Event &event, InputSta
input.x = mx;
input.y = my;
input.flags = TOUCH_DOWN | TOUCH_MOUSE;
input.buttons = 1;
input.id = 0;
NativeTouch(input);
KeyInput key(DEVICE_ID_MOUSE, NKCODE_EXT_MOUSEBUTTON_1, KEY_DOWN);
@ -956,12 +957,11 @@ static void ProcessSDLEvent(SDL_Window *window, const SDL_Event &event, InputSta
break;
case SDL_BUTTON_RIGHT:
{
// Right button only emits mouse move events. This is weird,
// but consistent with Windows. Needs cleanup.
TouchInput input{};
input.x = mx;
input.y = my;
input.flags = TOUCH_MOVE | TOUCH_MOUSE;
input.flags = TOUCH_DOWN | TOUCH_MOUSE;
input.buttons = 2;
input.id = 0;
NativeTouch(input);
KeyInput key(DEVICE_ID_MOUSE, NKCODE_EXT_MOUSEBUTTON_2, KEY_DOWN);
@ -1037,6 +1037,7 @@ static void ProcessSDLEvent(SDL_Window *window, const SDL_Event &event, InputSta
input.x = mx;
input.y = my;
input.flags = TOUCH_UP | TOUCH_MOUSE;
input.buttons = 1;
NativeTouch(input);
KeyInput key(DEVICE_ID_MOUSE, NKCODE_EXT_MOUSEBUTTON_1, KEY_UP);
NativeKey(key);
@ -1049,7 +1050,8 @@ static void ProcessSDLEvent(SDL_Window *window, const SDL_Event &event, InputSta
TouchInput input{};
input.x = mx;
input.y = my;
input.flags = TOUCH_MOVE | TOUCH_MOUSE;
input.flags = TOUCH_UP | TOUCH_MOUSE;
input.buttons = 2;
NativeTouch(input);
KeyInput key(DEVICE_ID_MOUSE, NKCODE_EXT_MOUSEBUTTON_2, KEY_UP);
NativeKey(key);

View File

@ -3,7 +3,7 @@
#include "Common/Data/Encoding/Utf8.h"
#include "Common/System/Display.h"
#include "Common/TimeUtil.h"
#include "Common/Log.h"
#include "imgui_impl_platform.h"
@ -12,10 +12,9 @@ void ImGui_ImplPlatform_KeyEvent(const KeyInput &key) {
if (key.flags & KEY_DOWN) {
ImGuiKey keyCode = KeyCodeToImGui(key.keyCode);
if (keyCode == ImGuiKey_None) {
WARN_LOG(Log::System, "Unmapped ImGui keycode conversion from %d", key.keyCode);
if (keyCode != ImGuiKey_None) {
io.AddKeyEvent(keyCode, true);
}
io.AddKeyEvent(keyCode, true);
}
if (key.flags & KEY_UP) {
ImGuiKey keyCode = KeyCodeToImGui(key.keyCode);
@ -192,6 +191,19 @@ ImGuiKey KeyCodeToImGui(InputKeyCode keyCode) {
// Lock keys
case NKCODE_NUM_LOCK: return ImGuiKey_NumLock;
case NKCODE_SCROLL_LOCK: return ImGuiKey_ScrollLock;
default: return ImGuiKey_None;
case NKCODE_EXT_MOUSEBUTTON_1:
case NKCODE_EXT_MOUSEBUTTON_2:
case NKCODE_EXT_MOUSEBUTTON_3:
case NKCODE_EXT_MOUSEBUTTON_4:
case NKCODE_EXT_MOUSEBUTTON_5:
case NKCODE_EXT_MOUSEWHEEL_DOWN:
case NKCODE_EXT_MOUSEWHEEL_UP:
// Keys ignored for imgui
return ImGuiKey_None;
default:
WARN_LOG(Log::System, "Unmapped ImGui keycode conversion from %d", keyCode);
return ImGuiKey_None;
}
}