Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Low-power/822eace3f37c893bc6aad3af647b4c7d to your computer and use it in GitHub Desktop.
Save Low-power/822eace3f37c893bc6aad3af647b4c7d to your computer and use it in GitHub Desktop.
Revent changes in QEMU SDL user interface hotkey for exiting mouse grab
diff -ru qemu-2.12.1.orig/ui/sdl.c qemu-2.12.1/ui/sdl.c
--- qemu-2.12.1.orig/ui/sdl.c 2018-08-03 05:48:53.000000000 +0800
+++ qemu-2.12.1/ui/sdl.c 2019-01-17 18:48:26.806839746 +0800
@@ -335,11 +335,11 @@
status = " [Stopped]";
else if (gui_grab) {
if (alt_grab)
- status = " - Press Ctrl-Alt-Shift-G to exit mouse grab";
+ status = " - Press Ctrl-Alt-Shift to exit mouse grab";
else if (ctrl_grab)
- status = " - Press Right-Ctrl-G to exit mouse grab";
+ status = " - Press Right-Ctrl to exit mouse grab";
else
- status = " - Press Ctrl-Alt-G to exit mouse grab";
+ status = " - Press Ctrl-Alt to exit mouse grab";
}
if (qemu_name) {
@@ -543,16 +543,6 @@
toggle_full_screen();
gui_keysym = 1;
break;
- case 0x22: /* 'g' key */
- if (!gui_grab) {
- if (qemu_console_is_graphic(NULL)) {
- sdl_grab_start();
- }
- } else if (!gui_fullscreen) {
- sdl_grab_end();
- }
- gui_keysym = 1;
- break;
case 0x16: /* 'u' key on US keyboard */
if (scaling_active) {
scaling_active = 0;
@@ -688,6 +678,19 @@
}
if (!mod_state && gui_key_modifier_pressed) {
gui_key_modifier_pressed = 0;
+ if (gui_keysym == 0) {
+ if (!gui_grab) {
+ if (qemu_console_is_graphic(NULL)) {
+ sdl_grab_start();
+ }
+ } else if (!gui_fullscreen) {
+ sdl_grab_end();
+ }
+ /* SDL does not send back all the modifiers key, so we must
+ * correct it. */
+ reset_keys();
+ return;
+ }
gui_keysym = 0;
}
if (qemu_console_is_graphic(NULL) && !gui_keysym) {
diff -ru qemu-2.12.1.orig/ui/sdl2.c qemu-2.12.1/ui/sdl2.c
--- qemu-2.12.1.orig/ui/sdl2.c 2018-08-03 05:48:53.000000000 +0800
+++ qemu-2.12.1/ui/sdl2.c 2019-01-17 18:52:57.513255812 +0800
@@ -48,6 +48,7 @@
static int guest_x, guest_y;
static SDL_Cursor *guest_sprite;
static Notifier mouse_mode_notifier;
+static int gui_previous_key_modifier_pressed;
#define SDL2_REFRESH_INTERVAL_BUSY 10
#define SDL2_MAX_IDLE_COUNT (2 * GUI_REFRESH_INTERVAL_DEFAULT \
@@ -140,11 +141,11 @@
status = " [Stopped]";
} else if (gui_grab) {
if (alt_grab) {
- status = " - Press Ctrl-Alt-Shift-G to exit grab";
+ status = " - Press Ctrl-Alt-Shift to exit grab";
} else if (ctrl_grab) {
- status = " - Press Right-Ctrl-G to exit grab";
+ status = " - Press Right-Ctrl to exit grab";
} else {
- status = " - Press Ctrl-Alt-G to exit grab";
+ status = " - Press Ctrl-Alt to exit grab";
}
}
@@ -331,6 +332,7 @@
int win;
struct sdl2_console *scon = get_scon_from_window(ev->key.windowID);
int gui_key_modifier_pressed = get_mod_state();
+ gui_previous_key_modifier_pressed = gui_key_modifier_pressed;
if (!scon->ignore_hotkeys && gui_key_modifier_pressed && !ev->key.repeat) {
switch (ev->key.keysym.scancode) {
@@ -363,14 +365,6 @@
toggle_full_screen(scon);
gui_keysym = 1;
break;
- case SDL_SCANCODE_G:
- gui_keysym = 1;
- if (!gui_grab) {
- sdl_grab_start(scon);
- } else if (!gui_fullscreen) {
- sdl_grab_end(scon);
- }
- break;
case SDL_SCANCODE_U:
sdl2_window_destroy(scon);
sdl2_window_create(scon);
@@ -417,6 +411,21 @@
scon->ignore_hotkeys = false;
if (!gui_key_modifier_pressed) {
+ if (gui_previous_key_modifier_pressed) {
+ gui_previous_key_modifier_pressed = 0;
+ if (gui_keysym == 0) {
+ if (!gui_grab) {
+ sdl_grab_start(scon);
+ } else if (!gui_fullscreen) {
+ sdl_grab_end(scon);
+ }
+ /* SDL does not send back all the modifiers key, so we must
+ * correct it. */
+ sdl2_reset_keys(scon);
+ return;
+ }
+ sdl2_reset_keys(scon);
+ }
gui_keysym = 0;
}
if (!gui_keysym) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment