[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 3/3] ui/sdl2: ignore GUI keys in SDL_TEXTINPUT handler
From: |
Volker Rümelin |
Subject: |
[PATCH 3/3] ui/sdl2: ignore GUI keys in SDL_TEXTINPUT handler |
Date: |
Mon, 9 Sep 2024 08:15:52 +0200 |
Ignore GUI keys for SDL_TEXTINPUT events, just like GUI keys are
ignored for SDL_KEYDOWN events. This prevents unintended text input
in a text console when hiding the text console with the GUI keys.
The SDL_TEXTINPUT event always comes after the SDL_KEYDOWN event.
See libsdl-org/SDL issue #1659.
Tested-by: Howard Spoelstra <hsp.cat7@gmail.com>
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
---
include/ui/sdl2.h | 1 +
ui/sdl2.c | 17 +++++++++--------
2 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/include/ui/sdl2.h b/include/ui/sdl2.h
index 6907115809..dbe6e3d973 100644
--- a/include/ui/sdl2.h
+++ b/include/ui/sdl2.h
@@ -42,6 +42,7 @@ struct sdl2_console {
int updates;
int idle_counter;
int ignore_hotkeys;
+ bool gui_keysym;
SDL_GLContext winctx;
QKbdState *kbd;
#ifdef CONFIG_OPENGL
diff --git a/ui/sdl2.c b/ui/sdl2.c
index 9d9a9362cb..cb1acd4499 100644
--- a/ui/sdl2.c
+++ b/ui/sdl2.c
@@ -396,12 +396,13 @@ static void handle_keydown(SDL_Event *ev)
int win;
struct sdl2_console *scon = get_scon_from_window(ev->key.windowID);
int gui_key_modifier_pressed = get_mod_state();
- int gui_keysym = 0;
if (!scon) {
return;
}
+ scon->gui_keysym = false;
+
if (!scon->ignore_hotkeys && gui_key_modifier_pressed && !ev->key.repeat) {
switch (ev->key.keysym.scancode) {
case SDL_SCANCODE_2:
@@ -427,15 +428,15 @@ static void handle_keydown(SDL_Event *ev)
}
}
sdl2_release_modifiers(scon);
- gui_keysym = 1;
+ scon->gui_keysym = true;
}
break;
case SDL_SCANCODE_F:
toggle_full_screen(scon);
- gui_keysym = 1;
+ scon->gui_keysym = true;
break;
case SDL_SCANCODE_G:
- gui_keysym = 1;
+ scon->gui_keysym = true;
if (!gui_grab) {
sdl_grab_start(scon);
} else if (!gui_fullscreen) {
@@ -448,7 +449,7 @@ static void handle_keydown(SDL_Event *ev)
/* re-create scon->texture */
sdl2_2d_switch(&scon->dcl, scon->surface);
}
- gui_keysym = 1;
+ scon->gui_keysym = true;
break;
#if 0
case SDL_SCANCODE_KP_PLUS:
@@ -467,14 +468,14 @@ static void handle_keydown(SDL_Event *ev)
__func__, width, height);
sdl_scale(scon, width, height);
sdl2_redraw(scon);
- gui_keysym = 1;
+ scon->gui_keysym = true;
}
#endif
default:
break;
}
}
- if (!gui_keysym) {
+ if (!scon->gui_keysym) {
sdl2_process_key(scon, &ev->key);
}
}
@@ -500,7 +501,7 @@ static void handle_textinput(SDL_Event *ev)
return;
}
- if (QEMU_IS_TEXT_CONSOLE(con)) {
+ if (!scon->gui_keysym && QEMU_IS_TEXT_CONSOLE(con)) {
qemu_text_console_put_string(QEMU_TEXT_CONSOLE(con), ev->text.text,
strlen(ev->text.text));
}
}
--
2.35.3
- SDL2 keyboard fixes on Windows, Volker Rümelin, 2024/09/09
- [PATCH 3/3] ui/sdl2: ignore GUI keys in SDL_TEXTINPUT handler,
Volker Rümelin <=
- [PATCH 1/3] ui/sdl2: reenable the SDL2 Windows keyboard hook procedure, Volker Rümelin, 2024/09/09
- Re: [PATCH 1/3] ui/sdl2: reenable the SDL2 Windows keyboard hook procedure, Marc-André Lureau, 2024/09/09
- Re: [PATCH 1/3] ui/sdl2: reenable the SDL2 Windows keyboard hook procedure, Stefan Weil, 2024/09/09
- Re: [PATCH 1/3] ui/sdl2: reenable the SDL2 Windows keyboard hook procedure, Volker Rümelin, 2024/09/09
- Re: [PATCH 1/3] ui/sdl2: reenable the SDL2 Windows keyboard hook procedure, Philippe Mathieu-Daudé, 2024/09/11
- Re: [PATCH 1/3] ui/sdl2: reenable the SDL2 Windows keyboard hook procedure, Philippe Mathieu-Daudé, 2024/09/11
- Re: [PATCH 1/3] ui/sdl2: reenable the SDL2 Windows keyboard hook procedure, Bernhard Beschow, 2024/09/11
[PATCH 2/3] ui/sdl2: release all modifiers, Volker Rümelin, 2024/09/09
Re: SDL2 keyboard fixes on Windows, Bernhard Beschow, 2024/09/11