diff mbox series

[v1] ui: fix mixup between qnum and qcode in SDL1 key handling

Message ID 20180201180033.14255-1-berrange@redhat.com
State New
Headers show
Series [v1] ui: fix mixup between qnum and qcode in SDL1 key handling | expand

Commit Message

Daniel P. Berrangé Feb. 1, 2018, 6 p.m. UTC
The previous commit:

  commit 2ec78706d188df7d3dab43d07b19b05ef7800a44
  Author: Daniel P. Berrange <berrange@redhat.com>
  Date:   Wed Jan 17 16:47:15 2018 +0000

    ui: convert GTK and SDL1 frontends to keycodemapdb

changed the x_keymap.c keymap so that its target was qcodes instead of
qnums. It updated the GTK frontend to take account of this change, but
forgot to update the SDL1 frontend. Thus the SDL frontend was getting
qcodes but dispatching them as if they were qnums. IOW, keyboard input
was completely hosed with SDL1. Since the keyboard layout tables are
still all based on qnums, it is easier to just keep SDL1 using qnums as
it will be deleted in a few releases time.

Reported-by: BALATON Zoltan <balaton@eik.bme.hu>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 ui/sdl.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

Comments

BALATON Zoltan Feb. 1, 2018, 6:25 p.m. UTC | #1
On Thu, 1 Feb 2018, Daniel P. Berrangé wrote:
> The previous commit:
>
>  commit 2ec78706d188df7d3dab43d07b19b05ef7800a44
>  Author: Daniel P. Berrange <berrange@redhat.com>
>  Date:   Wed Jan 17 16:47:15 2018 +0000
>
>    ui: convert GTK and SDL1 frontends to keycodemapdb
>
> changed the x_keymap.c keymap so that its target was qcodes instead of
> qnums. It updated the GTK frontend to take account of this change, but
> forgot to update the SDL1 frontend. Thus the SDL frontend was getting
> qcodes but dispatching them as if they were qnums. IOW, keyboard input
> was completely hosed with SDL1. Since the keyboard layout tables are
> still all based on qnums, it is easier to just keep SDL1 using qnums as
> it will be deleted in a few releases time.
>
> Reported-by: BALATON Zoltan <balaton@eik.bme.hu>
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>

Tested-by: BALATON Zoltan <balaton@eik.bme.hu>

Thanks, this seems to fix the issue I have seen with SDL1.

> ---
> ui/sdl.c | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/ui/sdl.c b/ui/sdl.c
> index c8f102bb9f..a6bff301eb 100644
> --- a/ui/sdl.c
> +++ b/ui/sdl.c
> @@ -242,6 +242,7 @@ static const guint16 *sdl_get_keymap(size_t *maplen)
>
> static uint8_t sdl_keyevent_to_keycode(const SDL_KeyboardEvent *ev)
> {
> +    int qcode;
>     if (!keycode_map) {
>         return 0;
>     }
> @@ -249,7 +250,13 @@ static uint8_t sdl_keyevent_to_keycode(const SDL_KeyboardEvent *ev)
>         return 0;
>     }
>
> -    return keycode_map[ev->keysym.scancode];
> +    qcode = keycode_map[ev->keysym.scancode];
> +
> +    if (qcode > qemu_input_map_qcode_to_qnum_len) {
> +        return 0;
> +    }
> +
> +    return qemu_input_map_qcode_to_qnum[qcode];
> }
>
> static void reset_keys(void)
>
diff mbox series

Patch

diff --git a/ui/sdl.c b/ui/sdl.c
index c8f102bb9f..a6bff301eb 100644
--- a/ui/sdl.c
+++ b/ui/sdl.c
@@ -242,6 +242,7 @@  static const guint16 *sdl_get_keymap(size_t *maplen)
 
 static uint8_t sdl_keyevent_to_keycode(const SDL_KeyboardEvent *ev)
 {
+    int qcode;
     if (!keycode_map) {
         return 0;
     }
@@ -249,7 +250,13 @@  static uint8_t sdl_keyevent_to_keycode(const SDL_KeyboardEvent *ev)
         return 0;
     }
 
-    return keycode_map[ev->keysym.scancode];
+    qcode = keycode_map[ev->keysym.scancode];
+
+    if (qcode > qemu_input_map_qcode_to_qnum_len) {
+        return 0;
+    }
+
+    return qemu_input_map_qcode_to_qnum[qcode];
 }
 
 static void reset_keys(void)