[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH] input-linux: toggle for lock keys
From: |
Ryan El Kochta |
Subject: |
[Qemu-devel] [PATCH] input-linux: toggle for lock keys |
Date: |
Thu, 23 Aug 2018 01:23:20 +0000 |
This patch introduces three new options on the input-linux commandline:
(a) ignore_caps_lock=[on|off]
(b) ignore_num_lock=[on|off]
(c) ignore_scroll_lock=[on|off]
If enabled, the key will be disabled and not forwarded to the guest.
There are two main reasons for this:
(a) Without keyboard LEDs, it can be difficult to tell whether it is
enabled or not
(b) Preparation for another patch which will allow changing the keys
used to toggle the input device's grab. If you set the key to
KEY_SCROLLLOCK for example, it can be frustrating disabling scroll lock
in the guest, as it will require pressing the key more than twice.
I'm new to this, so if I've made a mistake, let me know ;-)
Signed-off-by: Ryan El Kochta <address@hidden>
---
ui/input-linux.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 78 insertions(+), 2 deletions(-)
diff --git a/ui/input-linux.c b/ui/input-linux.c
index 9720333b2c..059d0c02a7 100644
--- a/ui/input-linux.c
+++ b/ui/input-linux.c
@@ -63,6 +63,10 @@ struct InputLinux {
struct input_event event;
int read_offset;
+ bool ignore_caps_lock;
+ bool ignore_num_lock;
+ bool ignore_scroll_lock;
+
QTAILQ_ENTRY(InputLinux) next;
};
@@ -98,6 +102,21 @@ static void input_linux_toggle_grab(InputLinux *il)
}
}
+static bool input_linux_ignore_event(InputLinux *il,
+ struct input_event *event)
+{
+ if (il->ignore_caps_lock && event->code == KEY_CAPSLOCK) {
+ return true;
+ }
+ if (il->ignore_num_lock && event->code == KEY_NUMLOCK) {
+ return true;
+ }
+ if (il->ignore_scroll_lock && event->code == KEY_SCROLLLOCK) {
+ return true;
+ }
+ return false;
+}
+
static void input_linux_handle_keyboard(InputLinux *il,
struct input_event *event)
{
@@ -127,8 +146,11 @@ static void input_linux_handle_keyboard(InputLinux *il,
il->keycount--;
}
- /* send event to guest when grab is active */
- if (il->grab_active) {
+ /*
+ * send event to guest when grab is active,
+ * ignoring caps/num/scroll lock when ignore bit set
+ */
+ if (il->grab_active && !input_linux_ignore_event(il, event)) {
int qcode = qemu_input_linux_to_qcode(event->code);
qemu_input_event_send_key_qcode(NULL, qcode, event->value);
}
@@ -410,6 +432,51 @@ static void input_linux_set_repeat(Object *obj, bool value,
il->repeat = value;
}
+static bool input_linux_get_ignore_caps_lock(Object *obj, Error **errp)
+{
+ InputLinux *il = INPUT_LINUX(obj);
+
+ return il->ignore_caps_lock;
+}
+
+static void input_linux_set_ignore_caps_lock(Object *obj, bool value,
+ Error **errp)
+{
+ InputLinux *il = INPUT_LINUX(obj);
+
+ il->ignore_caps_lock = value;
+}
+
+static bool input_linux_get_ignore_num_lock(Object *obj, Error **errp)
+{
+ InputLinux *il = INPUT_LINUX(obj);
+
+ return il->ignore_num_lock;
+}
+
+static void input_linux_set_ignore_num_lock(Object *obj, bool value,
+ Error **errp)
+{
+ InputLinux *il = INPUT_LINUX(obj);
+
+ il->ignore_num_lock = value;
+}
+
+static bool input_linux_get_ignore_scroll_lock(Object *obj, Error **errp)
+{
+ InputLinux *il = INPUT_LINUX(obj);
+
+ return il->ignore_scroll_lock;
+}
+
+static void input_linux_set_ignore_scroll_lock(Object *obj, bool value,
+ Error **errp)
+{
+ InputLinux *il = INPUT_LINUX(obj);
+
+ il->ignore_scroll_lock = value;
+}
+
static void input_linux_instance_init(Object *obj)
{
object_property_add_str(obj, "evdev",
@@ -421,6 +488,15 @@ 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_bool(obj, "ignore_caps_lock",
+ input_linux_get_ignore_caps_lock,
+ input_linux_set_ignore_caps_lock, NULL);
+ object_property_add_bool(obj, "ignore_num_lock",
+ input_linux_get_ignore_num_lock,
+ input_linux_set_ignore_num_lock, NULL);
+ object_property_add_bool(obj, "ignore_scroll_lock",
+ input_linux_get_ignore_scroll_lock,
+ input_linux_set_ignore_scroll_lock, NULL);
}
static void input_linux_class_init(ObjectClass *oc, void *data)
--
2.18.0
- [Qemu-devel] [PATCH] input-linux: toggle for lock keys,
Ryan El Kochta <=