Skip to contentSkip to conversation

SDL2 various fixes

PATCH In review Jindrich Makovicka 2 participants 7 messages Nov 17, 2017 – Jan 12, 2018

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 SDL2 various fixes

Hi,

here is a respin of the three remaining patches, with checkpatch errors corrected.

Also added the Fixes: line for "sdl2 uses surface relative coordinates", and an explaining comment to "sdl2: Ignore UI hotkeys".

Regards, Jindrich

#1 lore raw

PATCH 1/3 sdl2: Do not hide the cursor on auxilliary windows

---
 ui/sdl2.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
ui/sdl2.c +17 -0
index 53dd447fd2..290b57b1b3 100644
@@ -463,6 +463,10 @@ static void handle_mousemotion(SDL_Event *ev)
     int max_x, max_y;
     struct sdl2_console *scon = get_scon_from_window(ev->key.windowID);
 
+    if (!qemu_console_is_graphic(scon->dcl.con)) {
+        return;
+    }
+
     if (qemu_input_is_absolute() || absolute_enabled) {
         int scr_w, scr_h;
         SDL_GetWindowSize(scon->real_window, &scr_w, &scr_h);
@@ -490,6 +494,10 @@ static void handle_mousebutton(SDL_Event *ev)
     SDL_MouseButtonEvent *bev;
     struct sdl2_console *scon = get_scon_from_window(ev->key.windowID);
 
+    if (!qemu_console_is_graphic(scon->dcl.con)) {
+        return;
+    }
+
     bev = &ev->button;
     if (!gui_grab && !qemu_input_is_absolute()) {
         if (ev->type == SDL_MOUSEBUTTONUP && bev->button == SDL_BUTTON_LEFT) {
@@ -512,6 +520,10 @@ static void handle_mousewheel(SDL_Event *ev)
     SDL_MouseWheelEvent *wev = &ev->wheel;
     InputButton btn;
 
+    if (!qemu_console_is_graphic(scon->dcl.con)) {
+        return;
+    }
+
     if (wev->y > 0) {
         btn = INPUT_BUTTON_WHEEL_UP;
     } else if (wev->y < 0) {
@@ -652,6 +664,11 @@ static void sdl_mouse_warp(DisplayChangeListener *dcl,
                            int x, int y, int on)
 {
     struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl);
+
+    if (!qemu_console_is_graphic(scon->dcl.con)) {
+        return;
+    }
+
     if (on) {
         if (!guest_cursor) {
             sdl_show_cursor();
Signature · 1 line
2.15.0
#2 lore raw

PATCH 2/3 sdl2 uses surface relative coordinates

In reply to Jindrich Makovicka

This patch fixes mouse positioning with -device usb-tablet and fullscreen or resized window.

Fixes 46522a82236ea0cf9011b89896d2d8f8ddaf2443
---
 ui/sdl2.c | 30 ++++--------------------------
 1 file changed, 4 insertions(+), 26 deletions(-)
ui/sdl2.c +4 -26
index 290b57b1b3..4810f1fc43 100644
@@ -274,32 +274,10 @@ static void sdl_send_mouse_event(struct sdl2_console *scon, int dx, int dy,
     }
 
     if (qemu_input_is_absolute()) {
-        int scr_w, scr_h;
-        int max_w = 0, max_h = 0;
-        int off_x = 0, off_y = 0;
-        int cur_off_x = 0, cur_off_y = 0;
-        int i;
-
-        for (i = 0; i < sdl2_num_outputs; i++) {
-            struct sdl2_console *thiscon = &sdl2_console[i];
-            if (thiscon->real_window && thiscon->surface) {
-                SDL_GetWindowSize(thiscon->real_window, &scr_w, &scr_h);
-                cur_off_x = thiscon->x;
-                cur_off_y = thiscon->y;
-                if (scr_w + cur_off_x > max_w) {
-                    max_w = scr_w + cur_off_x;
-                }
-                if (scr_h + cur_off_y > max_h) {
-                    max_h = scr_h + cur_off_y;
-                }
-                if (i == scon->idx) {
-                    off_x = cur_off_x;
-                    off_y = cur_off_y;
-                }
-            }
-        }
-        qemu_input_queue_abs(scon->dcl.con, INPUT_AXIS_X, off_x + x, 0, max_w);
-        qemu_input_queue_abs(scon->dcl.con, INPUT_AXIS_Y, off_y + y, 0, max_h);
+        qemu_input_queue_abs(scon->dcl.con, INPUT_AXIS_X,
+                             x, 0, surface_width(scon->surface));
+        qemu_input_queue_abs(scon->dcl.con, INPUT_AXIS_Y,
+                             y, 0, surface_height(scon->surface));
     } else {
         if (guest_cursor) {
             x -= guest_x;
Signature · 1 line
2.15.0
#3 lore raw

PATCH 3/3 sdl2: Ignore UI hotkeys after a focus change when GUI modifier is held

In reply to Jindrich Makovicka

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.

---
 include/ui/sdl2.h |  1 +
 ui/sdl2.c         | 32 ++++++++++++++++++++++++--------
 2 files changed, 25 insertions(+), 8 deletions(-)
include/ui/sdl2.h +1 -0
index b29cf803c9..51084e6320 100644
@@ -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;
ui/sdl2.c +24 -8
index 4810f1fc43..414b1c71d9 100644
@@ -310,22 +310,28 @@ 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);
+    SDL_Keymod mod = SDL_GetModState();
 
     if (alt_grab) {
-        mod_state = (SDL_GetModState() & (gui_grab_code | KMOD_LSHIFT)) ==
+        return (mod & (gui_grab_code | KMOD_LSHIFT)) ==
             (gui_grab_code | KMOD_LSHIFT);
     } else if (ctrl_grab) {
-        mod_state = (SDL_GetModState() & KMOD_RCTRL) == KMOD_RCTRL;
+        return (mod & KMOD_RCTRL) == KMOD_RCTRL;
     } else {
-        mod_state = (SDL_GetModState() & gui_grab_code) == gui_grab_code;
+        return (mod & gui_grab_code) == gui_grab_code;
     }
-    gui_key_modifier_pressed = mod_state;
+}
 
-    if (gui_key_modifier_pressed) {
+static void handle_keydown(SDL_Event *ev)
+{
+    int win;
+    struct sdl2_console *scon = get_scon_from_window(ev->key.windowID);
+
+    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 +405,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 {
@@ -543,6 +551,14 @@ static void handle_windowevent(SDL_Event *ev)
         if (!gui_grab && (qemu_input_is_absolute() || absolute_enabled)) {
             absolute_mouse_grab(scon);
         }
+        /* If a new console window opened using a hotkey receives the
+         * focus, SDL sends another KEYDOWN event to the new window,
+         * closing the console window immediately after.
+         *
+         * Work around this by ignoring further hotkey events until a
+         * key is released.
+         */
+        scon->ignore_hotkeys = get_mod_state();
         break;
     case SDL_WINDOWEVENT_FOCUS_LOST:
         if (gui_grab && !gui_fullscreen) {
Signature · 1 line
2.15.0
#4 lore raw
In reply to Jindrich Makovicka
Quoted 10 lines · On Fri, 17 Nov 2017 12:22:55 +0100 Jindrich Makovicka <[email protected]>…

Hi,

here is a respin of the three remaining patches, with checkpatch errors corrected.

Also added the Fixes: line for "sdl2 uses surface relative coordinates", and an explaining comment to "sdl2: Ignore UI hotkeys".

Regards, Jindrich

Hi,

these changes somehow got lost. Any chance to have them merged into the next minor?

Regards,

Signature · 1 line
Jindrich Makovicka
#5 lore raw
Quoted 11 lines · Jindřich Makovička
Quoted 8 lines · On Fri, 17 Nov 2017 12:22:55 +0100 Jindrich Makovicka <[email protected]>…

Hi,

here is a respin of the three remaining patches, with checkpatch errors corrected.

Also added the Fixes: line for "sdl2 uses surface relative coordinates", and an explaining comment to "sdl2: Ignore UI hotkeys".

Quoted 7 lines
Quoted 2 lines

Regards, Jindrich

Hi,

these changes somehow got lost. Any chance to have them merged into the next minor?

First master, then possibly backport into -stable.

Just back from a few weeks of sick leave due to broken finger.

Will have to go through my email backlog, then I'll go handle pending patches. Will probably take some days though ...

cheers,
Gerd

#6 lore raw
In reply to Jindrich Makovicka
Quoted 7 lines · Jindrich Makovicka

Hi,

here is a respin of the three remaining patches, with checkpatch errors corrected.

Also added the Fixes: line for "sdl2 uses surface relative coordinates", and an explaining comment to "sdl2: Ignore UI hotkeys".

Series queued up now.

thanks,
Gerd