* [Qemu-devel] [PATCH] input-linux: customizable grab toggle keys v5
@ 2019-01-22 20:56 Ryan El Kochta
2019-01-23 8:15 ` Gerd Hoffmann
0 siblings, 1 reply; 2+ messages in thread
From: Ryan El Kochta @ 2019-01-22 20:56 UTC (permalink / raw)
To: qemu-devel, kraxel; +Cc: Ryan El Kochta
Here is an updated version of my previous patch. Ctrl-Alt has been
removed, as per your recommendation, and Ctrl-Scrolllock has been
changed so as to trigger when either ctrl key is pressed, for a
consistent naming scheme. I do agree that this is the best way forward.
Ctrl-Backtick is also gone.
I've tested these on a Windows and Linux guest and they all appear to
work fine.
Quick aside; I'm sorry if this e-mail isn't a reply to the old thread. I
haven't quite figured that one out yet :-)
Signed-off-by: Ryan El Kochta <relkochta@gmail.com>
---
qapi/ui.json | 10 ++++++++
ui/input-linux.c | 66 +++++++++++++++++++++++++++++++++++++++++++++---
2 files changed, 73 insertions(+), 3 deletions(-)
diff --git a/qapi/ui.json b/qapi/ui.json
index 5ad1324..7d9c4bd 100644
--- a/qapi/ui.json
+++ b/qapi/ui.json
@@ -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:
diff --git a/ui/input-linux.c b/ui/input-linux.c
index 9720333..ba550dd 100644
--- a/ui/input-linux.c
+++ b/ui/input-linux.c
@@ -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)
--
2.20.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [PATCH] input-linux: customizable grab toggle keys v5
2019-01-22 20:56 [Qemu-devel] [PATCH] input-linux: customizable grab toggle keys v5 Ryan El Kochta
@ 2019-01-23 8:15 ` Gerd Hoffmann
0 siblings, 0 replies; 2+ messages in thread
From: Gerd Hoffmann @ 2019-01-23 8:15 UTC (permalink / raw)
To: Ryan El Kochta; +Cc: qemu-devel
On Tue, Jan 22, 2019 at 03:56:27PM -0500, Ryan El Kochta wrote:
> Here is an updated version of my previous patch. Ctrl-Alt has been
> removed, as per your recommendation, and Ctrl-Scrolllock has been
> changed so as to trigger when either ctrl key is pressed, for a
> consistent naming scheme. I do agree that this is the best way forward.
>
> Ctrl-Backtick is also gone.
>
> I've tested these on a Windows and Linux guest and they all appear to
> work fine.
Almost there. Code is fine now, but the commit message describes the v4
-> v5 changes instead of describing the patch. The v4 message was much
better.
Can you grab the v4 commit message and adapt the text to the v5 code
changes?
A better place to list the changes is the patch series cover letter
(yes, you can send a cover letter with a single patch too).
Some people use "git notes" + "git format-patch --notes" for changelog
annotations. That'll work too.
> Quick aside; I'm sorry if this e-mail isn't a reply to the old thread. I
> haven't quite figured that one out yet :-)
Starting a new thread is perfectly fine and in fact the preferred way to
send a new patch revision.
cheers,
Gerd
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-01-23 8:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-01-22 20:56 [Qemu-devel] [PATCH] input-linux: customizable grab toggle keys v5 Ryan El Kochta
2019-01-23 8:15 ` Gerd Hoffmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).