From nobody Fri Dec 19 19:06:33 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1519233029517938.7064998724122; Wed, 21 Feb 2018 09:10:29 -0800 (PST) Received: from localhost ([::1]:33832 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eoXuR-0001lv-Jg for importer@patchew.org; Wed, 21 Feb 2018 12:10:23 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39779) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eoXsY-0000Tf-GD for qemu-devel@nongnu.org; Wed, 21 Feb 2018 12:08:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eoXsW-0005dX-IE for qemu-devel@nongnu.org; Wed, 21 Feb 2018 12:08:26 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:32926 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eoXsW-0005cZ-Bh for qemu-devel@nongnu.org; Wed, 21 Feb 2018 12:08:24 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 04B174022905; Wed, 21 Feb 2018 17:08:24 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-147.ams2.redhat.com [10.36.116.147]) by smtp.corp.redhat.com (Postfix) with ESMTP id 951D3B07B9; Wed, 21 Feb 2018 17:08:21 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id E97801751E; Wed, 21 Feb 2018 18:08:20 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Wed, 21 Feb 2018 18:08:19 +0100 Message-Id: <20180221170820.15365-5-kraxel@redhat.com> In-Reply-To: <20180221170820.15365-1-kraxel@redhat.com> References: <20180221170820.15365-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 21 Feb 2018 17:08:24 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 21 Feb 2018 17:08:24 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kraxel@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [RFC PATCH 4/5] kbd-state: register sdl2 hotkeys X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: programmingkidx@gmail.com, Gerd Hoffmann , peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Register SDL2 hotkeys in keyboard state tracker, use it to check for hotkeys. Drop even more modifier code. This also changes behavior a bit. The Ctrl-Alt- hotkey combinations accept both ctrl keys now. Likewise the Ctrl-Alt-Shift- mode you can enable with -alt-grab accepts both ctrl and shift keys. The -ctrl-grab mode (use right ctrl key) is not supported. Signed-off-by: Gerd Hoffmann --- ui/sdl2-input.c | 1 - ui/sdl2.c | 98 ++++++++++++++++++++++++++++++++++-------------------= ---- 2 files changed, 59 insertions(+), 40 deletions(-) diff --git a/ui/sdl2-input.c b/ui/sdl2-input.c index d970655616..82ec375ea2 100644 --- a/ui/sdl2-input.c +++ b/ui/sdl2-input.c @@ -61,7 +61,6 @@ void sdl2_process_key(struct sdl2_console *scon, break; } } - return; } =20 kbd_state_key_event(scon->kbd, qcode, ev->type =3D=3D SDL_KEYDOWN); diff --git a/ui/sdl2.c b/ui/sdl2.c index 50f5fca0f6..0f48f5a546 100644 --- a/ui/sdl2.c +++ b/ui/sdl2.c @@ -39,8 +39,6 @@ static int gui_grab; /* if true, all keyboard/mouse event= s are grabbed */ =20 static int gui_saved_grab; static int gui_fullscreen; -static int gui_key_modifier_pressed; -static int gui_grab_code =3D KMOD_LALT | KMOD_LCTRL; static SDL_Cursor *sdl_cursor_normal; static SDL_Cursor *sdl_cursor_hidden; static int absolute_enabled; @@ -312,43 +310,35 @@ static void toggle_full_screen(struct sdl2_console *s= con) sdl2_redraw(scon); } =20 -static int get_mod_state(void) -{ - SDL_Keymod mod =3D SDL_GetModState(); - - if (alt_grab) { - return (mod & (gui_grab_code | KMOD_LSHIFT)) =3D=3D - (gui_grab_code | KMOD_LSHIFT); - } else if (ctrl_grab) { - return (mod & KMOD_RCTRL) =3D=3D KMOD_RCTRL; - } else { - return (mod & gui_grab_code) =3D=3D gui_grab_code; - } -} - static void handle_keydown(SDL_Event *ev) { int win; struct sdl2_console *scon =3D get_scon_from_window(ev->key.windowID); - int gui_keysym =3D 0; + KbdHotkey hotkey; + QKeyCode qcode; =20 - gui_key_modifier_pressed =3D get_mod_state(); + if (ev->key.keysym.scancode >=3D qemu_input_map_usb_to_qcode_len) { + return; + } + qcode =3D qemu_input_map_usb_to_qcode[ev->key.keysym.scancode]; =20 - if (!scon->ignore_hotkeys && gui_key_modifier_pressed && !ev->key.repe= at) { - switch (ev->key.keysym.scancode) { - case SDL_SCANCODE_2: - case SDL_SCANCODE_3: - case SDL_SCANCODE_4: - case SDL_SCANCODE_5: - case SDL_SCANCODE_6: - case SDL_SCANCODE_7: - case SDL_SCANCODE_8: - case SDL_SCANCODE_9: + if (!scon->ignore_hotkeys && !ev->key.repeat) { + hotkey =3D kbd_state_hotkey_get(scon->kbd, qcode); + switch (hotkey) { + case KBD_HOTKEY_CONSOLE_2: + case KBD_HOTKEY_CONSOLE_3: + case KBD_HOTKEY_CONSOLE_4: + case KBD_HOTKEY_CONSOLE_5: + case KBD_HOTKEY_CONSOLE_6: + case KBD_HOTKEY_CONSOLE_7: + case KBD_HOTKEY_CONSOLE_8: + case KBD_HOTKEY_CONSOLE_9: if (gui_grab) { sdl_grab_end(scon); } + sdl2_reset_keys(scon); =20 - win =3D ev->key.keysym.scancode - SDL_SCANCODE_1; + win =3D hotkey - KBD_HOTKEY_CONSOLE_1; if (win < sdl2_num_outputs) { sdl2_console[win].hidden =3D !sdl2_console[win].hidden; if (sdl2_console[win].real_window) { @@ -358,29 +348,25 @@ static void handle_keydown(SDL_Event *ev) SDL_ShowWindow(sdl2_console[win].real_window); } } - gui_keysym =3D 1; } break; - case SDL_SCANCODE_F: + case KBD_HOTKEY_FULLSCREEN: toggle_full_screen(scon); - gui_keysym =3D 1; break; - case SDL_SCANCODE_G: - gui_keysym =3D 1; + case KBD_HOTKEY_GRAB: if (!gui_grab) { sdl_grab_start(scon); } else if (!gui_fullscreen) { sdl_grab_end(scon); } break; - case SDL_SCANCODE_U: + case KBD_HOTKEY_REDRAW: sdl2_window_destroy(scon); sdl2_window_create(scon); if (!scon->opengl) { /* re-create scon->texture */ sdl2_2d_switch(&scon->dcl, scon->surface); } - gui_keysym =3D 1; break; #if 0 case SDL_SCANCODE_KP_PLUS: @@ -402,11 +388,14 @@ static void handle_keydown(SDL_Event *ev) gui_keysym =3D 1; } #endif + case KBD_HOTKEY_NONE: + sdl2_process_key(scon, &ev->key); + break; default: + /* keep gcc happy */ break; } - } - if (!gui_keysym) { + } else { sdl2_process_key(scon, &ev->key); } } @@ -546,7 +535,7 @@ static void handle_windowevent(SDL_Event *ev) * Work around this by ignoring further hotkey events until a * key is released. */ - scon->ignore_hotkeys =3D get_mod_state(); + scon->ignore_hotkeys =3D SDL_GetModState(); break; case SDL_WINDOWEVENT_FOCUS_LOST: if (gui_grab && !gui_fullscreen) { @@ -756,6 +745,36 @@ void sdl_display_early_init(DisplayOptions *o) } } =20 +static void sdl2_hotkey_init(KbdState *kbd) +{ + /* + * Register traditional SDL hotkeys for now. + * + * Making this configurable is left as an + * excercise for another day ... + */ + KbdModifier m1 =3D KBD_MOD_CTRL; + KbdModifier m2 =3D KBD_MOD_ALT; + KbdModifier m3 =3D KBD_MOD_NONE; + int i; + + if (alt_grab) { + m3 =3D KBD_MOD_SHIFT; + } + + kbd_state_hotkey_register(kbd, KBD_HOTKEY_FULLSCREEN, + Q_KEY_CODE_F, m1, m2, m3); + kbd_state_hotkey_register(kbd, KBD_HOTKEY_GRAB, + Q_KEY_CODE_G, m1, m2, m3); + kbd_state_hotkey_register(kbd, KBD_HOTKEY_REDRAW, + Q_KEY_CODE_U, m1, m2, m3); + for (i =3D 0; i <=3D 7; i++) { + /* keys 2 ... 9 */ + kbd_state_hotkey_register(kbd, KBD_HOTKEY_CONSOLE_2 + i, + Q_KEY_CODE_2 + i, m1, m2, m3); + } +} + void sdl_display_init(DisplayState *ds, DisplayOptions *o) { int flags; @@ -817,6 +836,7 @@ void sdl_display_init(DisplayState *ds, DisplayOptions = *o) #endif sdl2_console[i].dcl.con =3D con; sdl2_console[i].kbd =3D kbd_state_init(con); + sdl2_hotkey_init(sdl2_console[i].kbd); register_displaychangelistener(&sdl2_console[i].dcl); =20 #if defined(SDL_VIDEO_DRIVER_WINDOWS) || defined(SDL_VIDEO_DRIVER_X11) --=20 2.9.3