Skip to content

Commit

Permalink
keymap: pass full keyboard state to keysym2scancode
Browse files Browse the repository at this point in the history
Pass the keyboard state tracker handle down to keysym2scancode(),
so the code can fully inspect the keyboard state as needed.  No
functional change.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Message-id: 20190122092814.14919-8-kraxel@redhat.com
  • Loading branch information
kraxel committed Feb 5, 2019
1 parent c2f2ba4 commit 4ed26e1
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion ui/curses.c
Expand Up @@ -273,7 +273,7 @@ static void curses_refresh(DisplayChangeListener *dcl)
}

keycode = keysym2scancode(kbd_layout, keysym & KEYSYM_MASK,
false, false, false);
NULL);
if (keycode == 0)
continue;

Expand Down
8 changes: 4 additions & 4 deletions ui/keymaps.c
Expand Up @@ -188,7 +188,7 @@ kbd_layout_t *init_keyboard_layout(const name2keysym_t *table,


int keysym2scancode(kbd_layout_t *k, int keysym,
bool shift, bool altgr, bool ctrl)
QKbdState *kbd)
{
static const uint32_t mask =
SCANCODE_SHIFT | SCANCODE_ALTGR | SCANCODE_CTRL;
Expand Down Expand Up @@ -220,13 +220,13 @@ int keysym2scancode(kbd_layout_t *k, int keysym,
* If so, prefer that one.
*/
mods = 0;
if (shift) {
if (kbd && qkbd_state_modifier_get(kbd, QKBD_MOD_SHIFT)) {
mods |= SCANCODE_SHIFT;
}
if (altgr) {
if (kbd && qkbd_state_modifier_get(kbd, QKBD_MOD_ALTGR)) {
mods |= SCANCODE_ALTGR;
}
if (ctrl) {
if (kbd && qkbd_state_modifier_get(kbd, QKBD_MOD_CTRL)) {
mods |= SCANCODE_CTRL;
}

Expand Down
3 changes: 2 additions & 1 deletion ui/keymaps.h
Expand Up @@ -26,6 +26,7 @@
#define QEMU_KEYMAPS_H

#include "qemu-common.h"
#include "ui/kbd-state.h"

typedef struct {
const char* name;
Expand Down Expand Up @@ -55,7 +56,7 @@ typedef struct kbd_layout_t kbd_layout_t;
kbd_layout_t *init_keyboard_layout(const name2keysym_t *table,
const char *language, Error **errp);
int keysym2scancode(kbd_layout_t *k, int keysym,
bool shift, bool altgr, bool ctrl);
QKbdState *kbd);
int keycode_is_keypad(kbd_layout_t *k, int keycode);
int keysym_is_numlock(kbd_layout_t *k, int keysym);

Expand Down
5 changes: 1 addition & 4 deletions ui/vnc.c
Expand Up @@ -1973,9 +1973,6 @@ static const char *code2name(int keycode)

static void key_event(VncState *vs, int down, uint32_t sym)
{
bool shift = qkbd_state_modifier_get(vs->vd->kbd, QKBD_MOD_SHIFT);
bool altgr = qkbd_state_modifier_get(vs->vd->kbd, QKBD_MOD_ALTGR);
bool ctrl = qkbd_state_modifier_get(vs->vd->kbd, QKBD_MOD_CTRL);
int keycode;
int lsym = sym;

Expand All @@ -1984,7 +1981,7 @@ static void key_event(VncState *vs, int down, uint32_t sym)
}

keycode = keysym2scancode(vs->vd->kbd_layout, lsym & 0xFFFF,
shift, altgr, ctrl) & SCANCODE_KEYMASK;
vs->vd->kbd) & SCANCODE_KEYMASK;
trace_vnc_key_event_map(down, sym, keycode, code2name(keycode));
do_key_event(vs, down, keycode, sym);
}
Expand Down

0 comments on commit 4ed26e1

Please sign in to comment.