input-linux: customizable grab toggle keys

-----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2.0.22 (GNU/Linux)
 
 iQIcBAABAgAGBQJcSZTxAAoJEEy22O7T6HE4TmkP/1Ym0YTe0RTT7WV+oZtp1ZOB
 B02c3EU7aAT+y0aupD5WWIQV/Jgbx40RaACIyi8MxKfUD5is/8jS2WXgffPPAIxA
 e6jpnO+7PHkmny42jYWdiOD1Eb5OnSeQL8ax06CdFnZhxRvibrBCV7RdB01yMg1G
 wIzIjgvvFwjgzbCMq3L8n+uCRwmQqgMQ7xUhDFxv3omLK01pTGf95fYhoGTJ7Cc5
 gUWlugifM10Vs+62kuDkYbebCm0F8ALHtrTqC/schZfOOLrVIhtyqBdLrl8n9U/J
 ziyshrmtVfpfB/ezGwse66L2Fi/0K/o6GKesXjNEkfxb8RHNaw17SukOylR0nXHs
 oaviIH7JUh+MWcK/zuOVFzkRX3WUBsHLODMQRSixK2Kh6EtOqncO2x+ulaHKJtGb
 B1jyZpZgJEdXiUTgheZwn7csZDHc/Wh6a/LIe6sv7UUJEHbK+oklmPc6Dkrr4GUp
 UgODYDrTSZKwy8hk1BLLerRC3jzz1oIDRDAUi+z4Ct2ofGBUW91gjcJjtcVE2Kvq
 Jexqoo7pgaMJZ4GZllNWqHRDG95sBG2suycfesJgrABiHL/JWwD+ecfpvbuCtcX9
 vtdLUdyzc6REIQ2s9wh+lyml6LOCK40j4gwi0oSQ++pvw+eNud2lb/0ZgBF8xno5
 jrtkODqmnSWS8lgYgg8N
 =znqD
 -----END PGP SIGNATURE-----

Merge remote-tracking branch 'remotes/kraxel/tags/ui-20190124-pull-request' into staging

input-linux: customizable grab toggle keys

# gpg: Signature made Thu 24 Jan 2019 10:35:29 GMT
# gpg:                using RSA key 4CB6D8EED3E87138
# gpg: Good signature from "Gerd Hoffmann (work) <kraxel@redhat.com>"
# gpg:                 aka "Gerd Hoffmann <gerd@kraxel.org>"
# gpg:                 aka "Gerd Hoffmann (private) <kraxel@gmail.com>"
# Primary key fingerprint: A032 8CFF B93A 17A7 9901  FE7D 4CB6 D8EE D3E8 7138

* remotes/kraxel/tags/ui-20190124-pull-request:
  input-linux: customizable grab toggle keys

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
Peter Maydell 2019-01-24 15:38:47 +00:00
commit 341b7186e7
2 changed files with 73 additions and 3 deletions

View File

@ -1016,6 +1016,16 @@
'*head' : 'int',
'events' : [ 'InputEvent' ] } }
##
# @GrabToggleKeys:
#
# Keys to toggle input-linux between host and guest.
#
# Since: 4.0
#
##
{ 'enum': 'GrabToggleKeys',
'data': [ 'ctrl-ctrl', 'alt-alt', 'meta-meta', 'scrolllock', 'ctrl-scrolllock' ] }
##
# @DisplayGTK:

View File

@ -12,6 +12,8 @@
#include "sysemu/sysemu.h"
#include "ui/input.h"
#include "qom/object_interfaces.h"
#include "sysemu/iothread.h"
#include "block/aio.h"
#include <sys/ioctl.h>
#include "standard-headers/linux/input.h"
@ -63,6 +65,8 @@ struct InputLinux {
struct input_event event;
int read_offset;
enum GrabToggleKeys grab_toggle;
QTAILQ_ENTRY(InputLinux) next;
};
@ -98,6 +102,44 @@ static void input_linux_toggle_grab(InputLinux *il)
}
}
static bool input_linux_check_toggle(InputLinux *il)
{
switch (il->grab_toggle) {
case GRAB_TOGGLE_KEYS_CTRL_CTRL:
return il->keydown[KEY_LEFTCTRL] &&
il->keydown[KEY_RIGHTCTRL];
case GRAB_TOGGLE_KEYS_ALT_ALT:
return il->keydown[KEY_LEFTALT] &&
il->keydown[KEY_RIGHTALT];
case GRAB_TOGGLE_KEYS_META_META:
return il->keydown[KEY_LEFTMETA] &&
il->keydown[KEY_RIGHTMETA];
case GRAB_TOGGLE_KEYS_SCROLLLOCK:
return il->keydown[KEY_SCROLLLOCK];
case GRAB_TOGGLE_KEYS_CTRL_SCROLLLOCK:
return (il->keydown[KEY_LEFTCTRL] ||
il->keydown[KEY_RIGHTCTRL]) &&
il->keydown[KEY_SCROLLLOCK];
case GRAB_TOGGLE_KEYS__MAX:
/* avoid gcc error */
break;
}
return false;
}
static bool input_linux_should_skip(InputLinux *il,
struct input_event *event)
{
return (il->grab_toggle == GRAB_TOGGLE_KEYS_SCROLLLOCK ||
il->grab_toggle == GRAB_TOGGLE_KEYS_CTRL_SCROLLLOCK) &&
event->code == KEY_SCROLLLOCK;
}
static void input_linux_handle_keyboard(InputLinux *il,
struct input_event *event)
{
@ -128,14 +170,13 @@ static void input_linux_handle_keyboard(InputLinux *il,
}
/* send event to guest when grab is active */
if (il->grab_active) {
if (il->grab_active && !input_linux_should_skip(il, event)) {
int qcode = qemu_input_linux_to_qcode(event->code);
qemu_input_event_send_key_qcode(NULL, qcode, event->value);
}
/* hotkey -> record switch request ... */
if (il->keydown[KEY_LEFTCTRL] &&
il->keydown[KEY_RIGHTCTRL]) {
if (input_linux_check_toggle(il)) {
il->grab_request = true;
}
@ -410,6 +451,21 @@ static void input_linux_set_repeat(Object *obj, bool value,
il->repeat = value;
}
static int input_linux_get_grab_toggle(Object *obj, Error **errp)
{
InputLinux *il = INPUT_LINUX(obj);
return il->grab_toggle;
}
static void input_linux_set_grab_toggle(Object *obj, int value,
Error **errp)
{
InputLinux *il = INPUT_LINUX(obj);
il->grab_toggle = value;
}
static void input_linux_instance_init(Object *obj)
{
object_property_add_str(obj, "evdev",
@ -421,6 +477,10 @@ static void input_linux_instance_init(Object *obj)
object_property_add_bool(obj, "repeat",
input_linux_get_repeat,
input_linux_set_repeat, NULL);
object_property_add_enum(obj, "grab-toggle", "GrabToggleKeys",
&GrabToggleKeys_lookup,
input_linux_get_grab_toggle,
input_linux_set_grab_toggle, NULL);
}
static void input_linux_class_init(ObjectClass *oc, void *data)