qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Jindrich Makovicka <makovick@gmail.com>
To: QEMU Developers <qemu-devel@nongnu.org>,
	Gerd Hoffmann <kraxel@redhat.com>,
	Cole Robinson <crobinso@redhat.com>
Cc: Jindrich Makovicka <makovick@gmail.com>
Subject: [Qemu-devel] [PATCH 8/8] sdl2: Ignore UI hotkeys after a focus change when GUI modifier is held
Date: Sun, 12 Nov 2017 20:30:32 +0100	[thread overview]
Message-ID: <20171112193032.9724-9-makovick@gmail.com> (raw)
In-Reply-To: <20171112193032.9724-1-makovick@gmail.com>

When SDL2 windows change focus while a key is held, the window that
receives the focus also receives a new KeyDown event, without an
autorepeat flag. This means that if a WM places the qemu console
over the main window after Ctrl-Alt-2, the console closes immediately
after opening. Then, the main window receives the KeyDown event again
and the whole process repeats.

This patch makes the SDL2 UI ignore the KeyDown events on a window that
just received the focus, if the GUI modifier was held. The ignore flag
is reset on a first KeyUp event. This effectively works around the issue
above.

Signed-off-by: Jindrich Makovicka <makovick@gmail.com>
---
 include/ui/sdl2.h |  1 +
 ui/sdl2.c         | 25 ++++++++++++++++---------
 2 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/include/ui/sdl2.h b/include/ui/sdl2.h
index b29cf803c9..51084e6320 100644
--- a/include/ui/sdl2.h
+++ b/include/ui/sdl2.h
@@ -24,6 +24,7 @@ struct sdl2_console {
     int opengl;
     int updates;
     int idle_counter;
+    int ignore_hotkeys;
     SDL_GLContext winctx;
 #ifdef CONFIG_OPENGL
     QemuGLShader *gls;
diff --git a/ui/sdl2.c b/ui/sdl2.c
index 6feb637739..2d48686b83 100644
--- a/ui/sdl2.c
+++ b/ui/sdl2.c
@@ -310,22 +310,26 @@ static void toggle_full_screen(struct sdl2_console *scon)
     sdl2_redraw(scon);
 }
 
-static void handle_keydown(SDL_Event *ev)
+static int get_mod_state(void)
 {
-    int mod_state, win;
-    struct sdl2_console *scon = get_scon_from_window(ev->key.windowID);
-
     if (alt_grab) {
-        mod_state = (SDL_GetModState() & (gui_grab_code | KMOD_LSHIFT)) ==
+        return (SDL_GetModState() & (gui_grab_code | KMOD_LSHIFT)) ==
             (gui_grab_code | KMOD_LSHIFT);
     } else if (ctrl_grab) {
-        mod_state = (SDL_GetModState() & KMOD_RCTRL) == KMOD_RCTRL;
+        return (SDL_GetModState() & KMOD_RCTRL) == KMOD_RCTRL;
     } else {
-        mod_state = (SDL_GetModState() & gui_grab_code) == gui_grab_code;
+        return (SDL_GetModState() & gui_grab_code) == gui_grab_code;
     }
-    gui_key_modifier_pressed = mod_state;
+}
+
+static void handle_keydown(SDL_Event *ev)
+{
+    int win;
+    struct sdl2_console *scon = get_scon_from_window(ev->key.windowID);
 
-    if (gui_key_modifier_pressed) {
+    gui_key_modifier_pressed = get_mod_state();
+
+    if (!scon->ignore_hotkeys && gui_key_modifier_pressed && !ev->key.repeat) {
         switch (ev->key.keysym.scancode) {
         case SDL_SCANCODE_2:
         case SDL_SCANCODE_3:
@@ -399,6 +403,8 @@ static void handle_keyup(SDL_Event *ev)
     int mod_state;
     struct sdl2_console *scon = get_scon_from_window(ev->key.windowID);
 
+    scon->ignore_hotkeys = false;
+
     if (!alt_grab) {
         mod_state = (ev->key.keysym.mod & gui_grab_code);
     } else {
@@ -545,6 +551,7 @@ static void handle_windowevent(SDL_Event *ev)
         if (!gui_grab && (qemu_input_is_absolute() || absolute_enabled)) {
             absolute_mouse_grab(scon);
         }
+        scon->ignore_hotkeys = get_mod_state();
         break;
     case SDL_WINDOWEVENT_FOCUS_LOST:
         if (gui_grab && !gui_fullscreen) {
-- 
2.15.0

  parent reply	other threads:[~2017-11-12 19:30 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-23 21:07 [Qemu-devel] SDL2 various fixes Jindrich Makovicka
2017-10-23 21:07 ` [Qemu-devel] [PATCH 1/7] sdl2: Fix broken display updating after the window is hidden Jindrich Makovicka
2017-11-01 10:37   ` Gerd Hoffmann
2017-10-23 21:07 ` [Qemu-devel] [PATCH 2/7] sdl2: Do not quit the emulator when an auxilliary window is closed Jindrich Makovicka
2017-11-01 10:39   ` Gerd Hoffmann
2017-10-23 21:07 ` [Qemu-devel] [PATCH 3/7] sdl2: Do not hide the cursor on auxilliary windows Jindrich Makovicka
2017-10-24  2:38   ` Philippe Mathieu-Daudé
2017-10-24 17:39     ` Jindřich Makovička
2017-10-23 21:08 ` [Qemu-devel] [PATCH 4/7] sdl2: Only accept the hotkeys on the main window Jindrich Makovicka
2017-11-01 10:40   ` Gerd Hoffmann
2017-11-02 17:12     ` Jindřich Makovička
2017-11-03  9:26       ` Gerd Hoffmann
2017-11-03  9:37         ` Peter Maydell
2017-11-03 10:35           ` Gerd Hoffmann
2017-11-03 10:41             ` Peter Maydell
2017-11-03 10:45               ` Daniel P. Berrange
2017-11-03 11:01               ` Gerd Hoffmann
2017-11-03 11:10                 ` Peter Maydell
2017-11-03 12:07                   ` Gerd Hoffmann
2017-11-03 12:10                     ` Peter Maydell
2017-11-03 12:34                       ` Gerd Hoffmann
2017-11-05 14:10       ` Cole Robinson
2017-11-08 10:10         ` Gerd Hoffmann
2017-11-08 19:15           ` Jindřich Makovička
2017-10-23 21:08 ` [Qemu-devel] [PATCH 5/7] sdl2 uses surface relative coordinates Jindrich Makovicka
2017-11-01 10:43   ` Gerd Hoffmann
2017-11-02 17:07     ` Jindřich Makovička
2017-11-03  9:53       ` Gerd Hoffmann
2017-10-23 21:08 ` [Qemu-devel] [PATCH 6/7] sdl2: Fix dead keyboard after fullsceen Jindrich Makovicka
2017-10-23 21:08 ` [Qemu-devel] [PATCH 7/7] sdl2: Do not leave grab when fullscreen Jindrich Makovicka
2017-10-24  2:40 ` [Qemu-devel] SDL2 various fixes Philippe Mathieu-Daudé
2017-11-12 10:42 ` [Qemu-devel] [PATCH] " Jindrich Makovicka
2017-11-12 10:42   ` [Qemu-devel] [PATCH 1/8] sdl2: Fix broken display updating after the window is hidden Jindrich Makovicka
2017-11-12 10:42   ` [Qemu-devel] [PATCH 2/8] sdl2: Do not quit the emulator when an auxilliary window is closed Jindrich Makovicka
2017-11-12 10:42   ` [Qemu-devel] [PATCH 3/8] sdl2: Use the same pointer show/hide logic for absolute and relative mode Jindrich Makovicka
2017-11-12 10:42   ` [Qemu-devel] [PATCH 4/8] sdl2: Do not hide the cursor on auxilliary windows Jindrich Makovicka
2017-11-12 10:42   ` [Qemu-devel] [PATCH 5/8] sdl2 uses surface relative coordinates Jindrich Makovicka
2017-11-12 10:42   ` [Qemu-devel] [PATCH 6/8] sdl2: Fix dead keyboard after fullsceen Jindrich Makovicka
2017-11-12 10:42   ` [Qemu-devel] [PATCH 7/8] sdl2: Do not leave grab when fullscreen Jindrich Makovicka
2017-11-12 10:42   ` [Qemu-devel] [PATCH 8/8] sdl2: Ignore UI hotkeys after a focus change when GUI modifier is held Jindrich Makovicka
2017-11-12 17:17   ` [Qemu-devel] [PATCH] SDL2 various fixes Philippe Mathieu-Daudé
2017-11-12 19:30     ` [Qemu-devel] [PATCH v3] " Jindrich Makovicka
2017-11-12 19:30       ` [Qemu-devel] [PATCH 1/8] sdl2: Fix broken display updating after the window is hidden Jindrich Makovicka
2017-11-13 12:39         ` Gerd Hoffmann
2017-11-13 12:59           ` Gerd Hoffmann
2017-11-13 13:17             ` Jindřich Makovička
2017-11-13 13:38               ` Gerd Hoffmann
2017-11-13 16:35           ` Max Reitz
2017-11-14  9:53             ` Gerd Hoffmann
2017-11-14 14:48             ` Max Reitz
2017-11-14 15:12               ` Gerd Hoffmann
2017-11-12 19:30       ` [Qemu-devel] [PATCH 2/8] sdl2: Do not quit the emulator when an auxilliary window is closed Jindrich Makovicka
2017-11-12 19:30       ` [Qemu-devel] [PATCH 3/8] sdl2: Use the same pointer show/hide logic for absolute and relative mode Jindrich Makovicka
2017-11-12 19:30       ` [Qemu-devel] [PATCH 4/8] sdl2: Do not hide the cursor on auxilliary windows Jindrich Makovicka
2017-11-13 13:21         ` Gerd Hoffmann
2017-11-12 19:30       ` [Qemu-devel] [PATCH 5/8] sdl2 uses surface relative coordinates Jindrich Makovicka
2017-11-13 13:22         ` Gerd Hoffmann
2017-11-12 19:30       ` [Qemu-devel] [PATCH 6/8] sdl2: Fix dead keyboard after fullsceen Jindrich Makovicka
2017-11-12 19:30       ` [Qemu-devel] [PATCH 7/8] sdl2: Do not leave grab when fullscreen Jindrich Makovicka
2017-11-12 19:30       ` Jindrich Makovicka [this message]
2017-11-13 13:29         ` [Qemu-devel] [PATCH 8/8] sdl2: Ignore UI hotkeys after a focus change when GUI modifier is held Gerd Hoffmann
2017-11-13 13:34       ` [Qemu-devel] [PATCH v3] SDL2 various fixes Gerd Hoffmann
2017-11-13 15:46       ` Eric Blake

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171112193032.9724-9-makovick@gmail.com \
    --to=makovick@gmail.com \
    --cc=crobinso@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).