[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 10/10] input-linux: initialize key state
From: |
Gerd Hoffmann |
Subject: |
[Qemu-devel] [PULL 10/10] input-linux: initialize key state |
Date: |
Thu, 13 Oct 2016 11:32:58 +0200 |
Query input device keys, initialize state accordingly, so the correct
state is reflected in case any key is pressed at initialization time.
There is a high chance for this to actually happen for the 'enter' key
in case you start qemu with a terminal command (directly or virsh).
When finding any pressed keys the input grab is delayed until all keys
are lifted, to avoid confusing guest and host with appearently stuck
keys.
Reported-by: Muted Bytes <address@hidden>
Signed-off-by: Gerd Hoffmann <address@hidden>
Message-id: address@hidden
---
ui/input-linux.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/ui/input-linux.c b/ui/input-linux.c
index 0e230ce..f345317 100644
--- a/ui/input-linux.c
+++ b/ui/input-linux.c
@@ -347,7 +347,8 @@ static void input_linux_event(void *opaque)
static void input_linux_complete(UserCreatable *uc, Error **errp)
{
InputLinux *il = INPUT_LINUX(uc);
- uint8_t evtmap, relmap, absmap, keymap[KEY_CNT / 8];
+ uint8_t evtmap, relmap, absmap;
+ uint8_t keymap[KEY_CNT / 8], keystate[KEY_CNT / 8];
unsigned int i;
int rc, ver;
@@ -394,6 +395,7 @@ static void input_linux_complete(UserCreatable *uc, Error
**errp)
if (evtmap & (1 << EV_KEY)) {
memset(keymap, 0, sizeof(keymap));
rc = ioctl(il->fd, EVIOCGBIT(EV_KEY, sizeof(keymap)), keymap);
+ rc = ioctl(il->fd, EVIOCGKEY(sizeof(keystate)), keystate);
for (i = 0; i < KEY_CNT; i++) {
if (keymap[i / 8] & (1 << (i % 8))) {
if (linux_is_button(i)) {
@@ -401,12 +403,21 @@ static void input_linux_complete(UserCreatable *uc, Error
**errp)
} else {
il->num_keys++;
}
+ if (keystate[i / 8] & (1 << (i % 8))) {
+ il->keydown[i] = true;
+ il->keycount++;
+ }
}
}
}
qemu_set_fd_handler(il->fd, input_linux_event, NULL, il);
- input_linux_toggle_grab(il);
+ if (il->keycount) {
+ /* delay grab until all keys are released */
+ il->grab_request = true;
+ } else {
+ input_linux_toggle_grab(il);
+ }
QTAILQ_INSERT_TAIL(&inputs, il, next);
il->initialized = true;
return;
--
1.8.3.1
- [Qemu-devel] [PULL 00/10] ui: vnc cleanups, input-linux kbd fix., Gerd Hoffmann, 2016/10/13
- [Qemu-devel] [PULL 01/10] ui: remove misleading comment from vnc_init_state, Gerd Hoffmann, 2016/10/13
- [Qemu-devel] [PULL 07/10] ui: remove bogus call to reset_keys() in vnc_init_state, Gerd Hoffmann, 2016/10/13
- [Qemu-devel] [PULL 10/10] input-linux: initialize key state,
Gerd Hoffmann <=
- [Qemu-devel] [PULL 03/10] ui: remove 'ws_tls' field from VncState, Gerd Hoffmann, 2016/10/13
- [Qemu-devel] [PULL 04/10] ui: rename misleading 'VncDisplay' variables, Gerd Hoffmann, 2016/10/13
- [Qemu-devel] [PULL 06/10] ui: remove bogus call to graphic_hw_update() in vnc_listen_io, Gerd Hoffmann, 2016/10/13
- [Qemu-devel] [PULL 05/10] ui: refactor method for setting up VncDisplay auth types, Gerd Hoffmann, 2016/10/13
- [Qemu-devel] [PULL 08/10] ui: move some initialization out of vnc_init_state, Gerd Hoffmann, 2016/10/13
- [Qemu-devel] [PULL 02/10] ui: remove 'enabled' and 'ws_enabled' fields from VncState, Gerd Hoffmann, 2016/10/13
- [Qemu-devel] [PULL 09/10] ui: rename vnc_init_state to vnc_start_protocol, Gerd Hoffmann, 2016/10/13
- Re: [Qemu-devel] [PULL 00/10] ui: vnc cleanups, input-linux kbd fix., Peter Maydell, 2016/10/13