Skip to contentSkip to conversation

sdl2 text console fixes and cleanups.

PATCH In review Gerd Hoffmann 3 participants 9 messages Mar 21, 2018 – Apr 9, 2018

lore
Share & tools
lore
#0 lore raw

cover sdl2 text console fixes and cleanups.

Gerd Hoffmann (5):
ui: add ctrl modifier support to kbd_put_qcode_console()
sdl2: track kbd modifier state unconditionally
sdl2: enable ctrl modifier keys for text consoles
sdl2: drop QEMU_KEY_BACKSPACE special case
sdl2: drop dead code

 include/ui/console.h |  2 +-
 ui/console.c         | 15 +++++++++++++--
 ui/gtk.c             |  4 ++--
 ui/sdl2-input.c      | 46 ++++++++++++++++++++--------------------------
 4 files changed, 36 insertions(+), 31 deletions(-)
Signature · 1 line
2.9.3
#1 lore raw

PATCH 1/5 ui: add ctrl modifier support to kbd_put_qcode_console()

---
 include/ui/console.h |  2 +-
 ui/console.c         | 15 +++++++++++++--
 ui/gtk.c             |  4 ++--
 ui/sdl2-input.c      |  2 +-
 4 files changed, 17 insertions(+), 6 deletions(-)
include/ui/console.h +1 -1
index 6d2c052068..37a8d68d29 100644
@@ -99,7 +99,7 @@ void hmp_mouse_set(Monitor *mon, const QDict *qdict);
 #define QEMU_KEY_CTRL_PAGEDOWN   0xe407
 
 void kbd_put_keysym_console(QemuConsole *s, int keysym);
-bool kbd_put_qcode_console(QemuConsole *s, int qcode);
+bool kbd_put_qcode_console(QemuConsole *s, int qcode, bool ctrl);
 void kbd_put_string_console(QemuConsole *s, const char *str, int len);
 void kbd_put_keysym(int keysym);
 
ui/console.c +13 -2
index 530a491987..3fb2f4e09f 100644
@@ -1191,11 +1191,22 @@ static const int qcode_to_keysym[Q_KEY_CODE__MAX] = {
     [Q_KEY_CODE_BACKSPACE] = QEMU_KEY_BACKSPACE,
 };
 
-bool kbd_put_qcode_console(QemuConsole *s, int qcode)
+static const int ctrl_qcode_to_keysym[Q_KEY_CODE__MAX] = {
+    [Q_KEY_CODE_UP]     = QEMU_KEY_CTRL_UP,
+    [Q_KEY_CODE_DOWN]   = QEMU_KEY_CTRL_DOWN,
+    [Q_KEY_CODE_RIGHT]  = QEMU_KEY_CTRL_RIGHT,
+    [Q_KEY_CODE_LEFT]   = QEMU_KEY_CTRL_LEFT,
+    [Q_KEY_CODE_HOME]   = QEMU_KEY_CTRL_HOME,
+    [Q_KEY_CODE_END]    = QEMU_KEY_CTRL_END,
+    [Q_KEY_CODE_PGUP]   = QEMU_KEY_CTRL_PAGEUP,
+    [Q_KEY_CODE_PGDN]   = QEMU_KEY_CTRL_PAGEDOWN,
+};
+
+bool kbd_put_qcode_console(QemuConsole *s, int qcode, bool ctrl)
 {
     int keysym;
 
-    keysym = qcode_to_keysym[qcode];
+    keysym = ctrl ? ctrl_qcode_to_keysym[qcode] : qcode_to_keysym[qcode];
     if (keysym == 0) {
         return false;
     }
ui/gtk.c +2 -2
index ef5bc42094..e98ac4d2fc 100644
@@ -1197,12 +1197,12 @@ static gboolean gd_text_key_down(GtkWidget *widget,
     QemuConsole *con = vc->gfx.dcl.con;
 
     if (key->keyval == GDK_KEY_Delete) {
-        kbd_put_qcode_console(con, Q_KEY_CODE_DELETE);
+        kbd_put_qcode_console(con, Q_KEY_CODE_DELETE, false);
     } else if (key->length) {
         kbd_put_string_console(con, key->string, key->length);
     } else {
         int qcode = gd_map_keycode(key->hardware_keycode);
-        kbd_put_qcode_console(con, qcode);
+        kbd_put_qcode_console(con, qcode, false);
     }
     return TRUE;
 }
ui/sdl2-input.c +1 -1
index 605d781971..35d35c14c4 100644
@@ -70,7 +70,7 @@ void sdl2_process_key(struct sdl2_console *scon,
                 kbd_put_keysym_console(con, QEMU_KEY_BACKSPACE);
                 break;
             default:
-                kbd_put_qcode_console(con, qcode);
+                kbd_put_qcode_console(con, qcode, false);
                 break;
             }
         }
Signature · 1 line
2.9.3
#2 lore raw

PATCH 2/5 sdl2: track kbd modifier state unconditionally

In reply to Gerd Hoffmann

For both grapical and text consoles.

---
 ui/sdl2-input.c | 39 +++++++++++++++++++++------------------
 1 file changed, 21 insertions(+), 18 deletions(-)
ui/sdl2-input.c +21 -18
index 35d35c14c4..8d0d9ba17c 100644
@@ -60,23 +60,7 @@ void sdl2_process_key(struct sdl2_console *scon,
 
     qcode = qemu_input_map_usb_to_qcode[ev->keysym.scancode];
 
-    if (!qemu_console_is_graphic(con)) {
-        if (ev->type == SDL_KEYDOWN) {
-            switch (ev->keysym.scancode) {
-            case SDL_SCANCODE_RETURN:
-                kbd_put_keysym_console(con, '\n');
-                break;
-            case SDL_SCANCODE_BACKSPACE:
-                kbd_put_keysym_console(con, QEMU_KEY_BACKSPACE);
-                break;
-            default:
-                kbd_put_qcode_console(con, qcode, false);
-                break;
-            }
-        }
-        return;
-    }
-
+    /* modifier state tracking */
     switch (ev->keysym.scancode) {
 #if 0
     case SDL_SCANCODE_NUMLOCKCLEAR:
@@ -99,8 +83,27 @@ void sdl2_process_key(struct sdl2_console *scon,
         } else {
             modifiers_state[ev->keysym.scancode] = 1;
         }
-        /* fall though */
+        break;
     default:
+        /* nothing */
+        break;
+    }
+
+    if (!qemu_console_is_graphic(con)) {
+        if (ev->type == SDL_KEYDOWN) {
+            switch (ev->keysym.scancode) {
+            case SDL_SCANCODE_RETURN:
+                kbd_put_keysym_console(con, '\n');
+                break;
+            case SDL_SCANCODE_BACKSPACE:
+                kbd_put_keysym_console(con, QEMU_KEY_BACKSPACE);
+                break;
+            default:
+                kbd_put_qcode_console(con, qcode, false);
+                break;
+            }
+        }
+    } else {
         qemu_input_event_send_key_qcode(con, qcode,
                                         ev->type == SDL_KEYDOWN);
     }
Signature · 1 line
2.9.3
#3 lore raw

PATCH 3/5 sdl2: enable ctrl modifier keys for text consoles

In reply to Gerd Hoffmann

Unbreaks ctrl-pageup/pagedown scrollback.

---
 ui/sdl2-input.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
ui/sdl2-input.c +3 -1
index 8d0d9ba17c..62c2b58ef0 100644
@@ -90,6 +90,8 @@ void sdl2_process_key(struct sdl2_console *scon,
     }
 
     if (!qemu_console_is_graphic(con)) {
+        bool ctrl = (modifiers_state[SDL_SCANCODE_LCTRL] ||
+                     modifiers_state[SDL_SCANCODE_RCTRL]);
         if (ev->type == SDL_KEYDOWN) {
             switch (ev->keysym.scancode) {
             case SDL_SCANCODE_RETURN:
@@ -99,7 +101,7 @@ void sdl2_process_key(struct sdl2_console *scon,
                 kbd_put_keysym_console(con, QEMU_KEY_BACKSPACE);
                 break;
             default:
-                kbd_put_qcode_console(con, qcode, false);
+                kbd_put_qcode_console(con, qcode, ctrl);
                 break;
             }
         }
Signature · 1 line
2.9.3
#4 lore raw

PATCH 4/5 sdl2: drop QEMU_KEY_BACKSPACE special case

In reply to Gerd Hoffmann

Not needed, kbd_put_qcode_console() will handle that for us.

---
 ui/sdl2-input.c | 3 ---
 1 file changed, 3 deletions(-)
ui/sdl2-input.c +0 -3
index 62c2b58ef0..d46411c474 100644
@@ -97,9 +97,6 @@ void sdl2_process_key(struct sdl2_console *scon,
             case SDL_SCANCODE_RETURN:
                 kbd_put_keysym_console(con, '\n');
                 break;
-            case SDL_SCANCODE_BACKSPACE:
-                kbd_put_keysym_console(con, QEMU_KEY_BACKSPACE);
-                break;
             default:
                 kbd_put_qcode_console(con, qcode, ctrl);
                 break;
Signature · 1 line
2.9.3
#5 lore raw

PATCH 5/5 sdl2: drop dead code

In reply to Gerd Hoffmann

Leftover from sdl1 -> sdl2 port.

---
 ui/sdl2-input.c | 8 --------
 1 file changed, 8 deletions(-)
ui/sdl2-input.c +0 -8
index d46411c474..1378b63dd9 100644
@@ -62,14 +62,6 @@ void sdl2_process_key(struct sdl2_console *scon,
 
     /* modifier state tracking */
     switch (ev->keysym.scancode) {
-#if 0
-    case SDL_SCANCODE_NUMLOCKCLEAR:
-    case SDL_SCANCODE_CAPSLOCK:
-        /* SDL does not send the key up event, so we generate it */
-        qemu_input_event_send_key_qcode(con, qcode, true);
-        qemu_input_event_send_key_qcode(con, qcode, false);
-        return;
-#endif
     case SDL_SCANCODE_LCTRL:
     case SDL_SCANCODE_LSHIFT:
     case SDL_SCANCODE_LALT:
Signature · 1 line
2.9.3
#6 lore raw
In reply to Gerd Hoffmann
Quoted 7 lines · Gerd Hoffmann

Gerd Hoffmann (5):
ui: add ctrl modifier support to kbd_put_qcode_console()
sdl2: track kbd modifier state unconditionally
sdl2: enable ctrl modifier keys for text consoles
sdl2: drop QEMU_KEY_BACKSPACE special case
sdl2: drop dead code

Quoted 5 lines
include/ui/console.h |  2 +-
ui/console.c         | 15 +++++++++++++--
ui/gtk.c             |  4 ++--
ui/sdl2-input.c      | 46 ++++++++++++++++++++--------------------------
4 files changed, 36 insertions(+), 31 deletions(-)

Will this be included in 2.12? I haven't seen it reaching master yet.

Regards,
BALATON Zoltan

#7 lore raw
Quoted 8 lines · BALATON Zoltan
Quoted 7 lines · Gerd Hoffmann

Gerd Hoffmann (5):
ui: add ctrl modifier support to kbd_put_qcode_console()
sdl2: track kbd modifier state unconditionally
sdl2: enable ctrl modifier keys for text consoles
sdl2: drop QEMU_KEY_BACKSPACE special case
sdl2: drop dead code

Quoted 7 lines
Quoted 5 lines
include/ui/console.h |  2 +-
ui/console.c         | 15 +++++++++++++--
ui/gtk.c             |  4 ++--
ui/sdl2-input.c      | 46 ++++++++++++++++++++--------------------------
4 files changed, 36 insertions(+), 31 deletions(-)

Will this be included in 2.12? I haven't seen it reaching master yet.

Oops. Thanks for the reminder. Pull request sent.

cheers,
Gerd

#8 lore raw
Quoted 15 lines · Gerd Hoffmann
Quoted 14 lines · BALATON Zoltan
Quoted 12 lines · Gerd Hoffmann

Gerd Hoffmann (5):
ui: add ctrl modifier support to kbd_put_qcode_console()
sdl2: track kbd modifier state unconditionally
sdl2: enable ctrl modifier keys for text consoles
sdl2: drop QEMU_KEY_BACKSPACE special case
sdl2: drop dead code

include/ui/console.h |  2 +-
ui/console.c         | 15 +++++++++++++--
ui/gtk.c             |  4 ++--
ui/sdl2-input.c      | 46 ++++++++++++++++++++--------------------------
4 files changed, 36 insertions(+), 31 deletions(-)
Quoted 3 lines
Quoted 1 line

Will this be included in 2.12? I haven't seen it reaching master yet.

Oops. Thanks for the reminder. Pull request sent.

FWIW I think we're also missing the patch for the GTK errors: https://lists.gnu.org/archive/html/qemu-devel/2018-03/msg04315.html.

ATB,

Mark.