qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: byxk <patricktsen@gmail.com>
To: qemu-devel@nongnu.org
Cc: kraxel@redhat.com, byxk <patricktsen@gmail.com>
Subject: [Qemu-devel] [PATCH 1/1] input-linux: provide hotkeys for evdev toggle
Date: Sun,  7 Jan 2018 14:14:55 -0800	[thread overview]
Message-ID: <20180107221455.25504-2-patricktsen@gmail.com> (raw)
In-Reply-To: <20180107221455.25504-1-patricktsen@gmail.com>

---
 ui/input-linux.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 75 insertions(+), 2 deletions(-)

diff --git a/ui/input-linux.c b/ui/input-linux.c
index 9720333b2c..a553d2b4cc 100644
--- a/ui/input-linux.c
+++ b/ui/input-linux.c
@@ -5,6 +5,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/cutils.h"
 #include "qapi/error.h"
 #include "qemu-common.h"
 #include "qemu/config-file.h"
@@ -62,6 +63,8 @@ struct InputLinux {
     int         abs_y_max;
     struct input_event event;
     int         read_offset;
+    long        rhotkey;
+    long        lhotkey;
 
     QTAILQ_ENTRY(InputLinux) next;
 };
@@ -134,8 +137,8 @@ static void input_linux_handle_keyboard(InputLinux *il,
         }
 
         /* hotkey -> record switch request ... */
-        if (il->keydown[KEY_LEFTCTRL] &&
-            il->keydown[KEY_RIGHTCTRL]) {
+        if (il->keydown[il->rhotkey] &&
+            il->keydown[il->lhotkey]) {
             il->grab_request = true;
         }
 
@@ -274,6 +277,14 @@ static void input_linux_complete(UserCreatable *uc, Error **errp)
         return;
     }
 
+    if (!il->rhotkey) {
+        il->rhotkey = KEY_RIGHTCTRL;
+    }
+
+    if (!il->lhotkey) {
+        il->lhotkey = KEY_LEFTCTRL;
+    }
+
     il->fd = open(il->evdev, O_RDWR);
     if (il->fd < 0)  {
         error_setg_file_open(errp, errno, il->evdev);
@@ -395,6 +406,62 @@ static void input_linux_set_grab_all(Object *obj, bool value,
     il->grab_all = value;
 }
 
+static void input_linux_set_rhotkey(Object *obj, const char *value,
+                                   Error **errp)
+{
+    InputLinux *il = INPUT_LINUX(obj);
+    InputLinux *item;
+    long rhotkey;
+    int res = qemu_strtol(value, NULL, 0, &rhotkey);
+    if (res != 0) {
+        rhotkey = KEY_RIGHTCTRL;
+    }
+    il->rhotkey = rhotkey;
+
+    QTAILQ_FOREACH(item, &inputs, next) {
+        if (item == il || item->rhotkey) {
+            continue;
+        }
+        item->rhotkey = rhotkey;
+    }
+}
+
+static char *input_linux_get_rhotkey(Object *obj, Error **errp)
+{
+    InputLinux *il = INPUT_LINUX(obj);
+    char buf[sizeof(int) * 4];
+    sprintf(buf, "%ld", il->rhotkey);
+    return g_strdup(buf);
+}
+
+static void input_linux_set_lhotkey(Object *obj, const char *value,
+                                   Error **errp)
+{
+    InputLinux *il = INPUT_LINUX(obj);
+    InputLinux *item;
+    long lhotkey = KEY_LEFTCTRL;
+    int res = qemu_strtol(value, NULL, 0, &lhotkey);
+    if (res != 0) {
+        lhotkey = KEY_LEFTCTRL;
+    }
+    il->lhotkey = lhotkey;
+
+    QTAILQ_FOREACH(item, &inputs, next) {
+        if (item == il || item->lhotkey) {
+            continue;
+        }
+        item->lhotkey = lhotkey;
+    }
+}
+
+static char *input_linux_get_lhotkey(Object *obj, Error **errp)
+{
+    InputLinux *il = INPUT_LINUX(obj);
+    char buf[sizeof(int) * 4];
+    sprintf(buf, "%ld", il->lhotkey);
+    return g_strdup(buf);
+}
+
 static bool input_linux_get_repeat(Object *obj, Error **errp)
 {
     InputLinux *il = INPUT_LINUX(obj);
@@ -421,6 +488,12 @@ 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_str(obj, "rhotkey",
+                            input_linux_get_rhotkey,
+                            input_linux_set_rhotkey, NULL);
+    object_property_add_str(obj, "lhotkey",
+                            input_linux_get_lhotkey,
+                            input_linux_set_lhotkey, NULL);
 }
 
 static void input_linux_class_init(ObjectClass *oc, void *data)
-- 
2.15.1

  reply	other threads:[~2018-01-07 22:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-07 22:14 [Qemu-devel] [PATCH v2 0/1] input-linux: provide hotkeys for evdev toggle byxk
2018-01-07 22:14 ` byxk [this message]
2018-01-10 16:30 ` Daniel P. Berrange
2018-01-10 17:06   ` Patrick Tseng
2018-01-11  9:38   ` Gerd Hoffmann
  -- strict thread matches above, loose matches on Subject: below --
2018-01-07 11:13 [Qemu-devel] [PATCH " byxk
2018-01-07 11:13 ` [Qemu-devel] [PATCH 1/1] " byxk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180107221455.25504-2-patricktsen@gmail.com \
    --to=patricktsen@gmail.com \
    --cc=kraxel@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).