* [Qemu-devel] [PATCH v2 0/1] input-linux: provide hotkeys for evdev toggle @ 2018-01-07 22:14 byxk 2018-01-07 22:14 ` [Qemu-devel] [PATCH 1/1] " byxk 2018-01-10 16:30 ` [Qemu-devel] [PATCH v2 0/1] " Daniel P. Berrange 0 siblings, 2 replies; 6+ messages in thread From: byxk @ 2018-01-07 22:14 UTC (permalink / raw) To: qemu-devel; +Cc: kraxel, byxk Added some functionality to change the key combo for evdev toggle. example: -object input-linux,rhotkey=29,lhotkey=56,evdev=[etc...] Set the defaults to LCTRL and RCTRL if not provided. This is my first patch to anything so feedback/help appreciated! byxk (1): input-linux: provide hotkeys for evdev toggle ui/input-linux.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 75 insertions(+), 2 deletions(-) -- 2.15.1 ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Qemu-devel] [PATCH 1/1] input-linux: provide hotkeys for evdev toggle 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 2018-01-10 16:30 ` [Qemu-devel] [PATCH v2 0/1] " Daniel P. Berrange 1 sibling, 0 replies; 6+ messages in thread From: byxk @ 2018-01-07 22:14 UTC (permalink / raw) To: qemu-devel; +Cc: kraxel, byxk --- 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 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH v2 0/1] input-linux: provide hotkeys for evdev toggle 2018-01-07 22:14 [Qemu-devel] [PATCH v2 0/1] input-linux: provide hotkeys for evdev toggle byxk 2018-01-07 22:14 ` [Qemu-devel] [PATCH 1/1] " byxk @ 2018-01-10 16:30 ` Daniel P. Berrange 2018-01-10 17:06 ` Patrick Tseng 2018-01-11 9:38 ` Gerd Hoffmann 1 sibling, 2 replies; 6+ messages in thread From: Daniel P. Berrange @ 2018-01-10 16:30 UTC (permalink / raw) To: byxk; +Cc: qemu-devel, kraxel On Sun, Jan 07, 2018 at 02:14:54PM -0800, byxk wrote: > Added some functionality to change the key combo for evdev toggle. > example: > -object input-linux,rhotkey=29,lhotkey=56,evdev=[etc...] > > Set the defaults to LCTRL and RCTRL if not provided. This should really be part of the commit message for the patch itself, so it gets recorded in git history. There is some overlap here with the grab sequence work John has just posted for cocoa frontend https://lists.gnu.org/archive/html/qemu-devel/2017-12/msg05115.html I wonder if it is reasonable for ui/input-linux.c to honour the same global '-ungrab' configuration option ? If not, we should at least use the same syntax for describing the ungrab sequence. ie a list of key code names, rather than a hardcoded pair of numeric values. Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :| ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH v2 0/1] input-linux: provide hotkeys for evdev toggle 2018-01-10 16:30 ` [Qemu-devel] [PATCH v2 0/1] " Daniel P. Berrange @ 2018-01-10 17:06 ` Patrick Tseng 2018-01-11 9:38 ` Gerd Hoffmann 1 sibling, 0 replies; 6+ messages in thread From: Patrick Tseng @ 2018-01-10 17:06 UTC (permalink / raw) To: Daniel P. Berrange; +Cc: qemu-devel, kraxel Hi Daniel, thanks for responding. > This should really be part of the commit message for the patch itself, so it > gets recorded in git history. Next patch version I'll separate this out to another commit. > I wonder if it is reasonable for ui/input-linux.c to honour the same > global '-ungrab' configuration option ? I had it as a global config option at first, but realized all config options related to input-linux appears to be contained in it's own object-based args, especially since evdev is still quite niche/isolated in its own way. But I rather not make the decisions for input-linux, I'll leave that up to the maintainer. > If not, we should at least > use the same syntax for describing the ungrab sequence. ie a list of > key code names, rather than a hardcoded pair of numeric values. This make sense, I agree it should at least be consistent. - Patrick (byxk) On Wed, Jan 10, 2018 at 8:30 AM, Daniel P. Berrange <berrange@redhat.com> wrote: > On Sun, Jan 07, 2018 at 02:14:54PM -0800, byxk wrote: > > Added some functionality to change the key combo for evdev toggle. > > example: > > -object input-linux,rhotkey=29,lhotkey=56,evdev=[etc...] > > > > Set the defaults to LCTRL and RCTRL if not provided. > > This should really be part of the commit message for the patch itself, so > it > gets recorded in git history. > > There is some overlap here with the grab sequence work John has just posted > for cocoa frontend > > https://lists.gnu.org/archive/html/qemu-devel/2017-12/msg05115.html > > I wonder if it is reasonable for ui/input-linux.c to honour the same > global '-ungrab' configuration option ? If not, we should at least > use the same syntax for describing the ungrab sequence. ie a list of > key code names, rather than a hardcoded pair of numeric values. > > > Regards, > Daniel > -- > |: https://berrange.com -o- https://www.flickr.com/photos/ > dberrange :| > |: https://libvirt.org -o- > https://fstop138.berrange.com :| > |: https://entangle-photo.org -o- https://www.instagram.com/ > dberrange :| > ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH v2 0/1] input-linux: provide hotkeys for evdev toggle 2018-01-10 16:30 ` [Qemu-devel] [PATCH v2 0/1] " Daniel P. Berrange 2018-01-10 17:06 ` Patrick Tseng @ 2018-01-11 9:38 ` Gerd Hoffmann 1 sibling, 0 replies; 6+ messages in thread From: Gerd Hoffmann @ 2018-01-11 9:38 UTC (permalink / raw) To: Daniel P. Berrange; +Cc: byxk, qemu-devel Hi, > I wonder if it is reasonable for ui/input-linux.c to honour the same > global '-ungrab' configuration option ? No. Problem here is that input-linux is basically sniffing keyboard input when the host owns the keyboard, so it can't prevent the hotkey being seen by the host. Therefore I picked something which (a) has no side effects (modifier keys only) and (b) is highly unlikely to be used in normal operation. cheers, Gerd ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Qemu-devel] [PATCH 0/1] input-linux: provide hotkeys for evdev toggle @ 2018-01-07 11:13 byxk 2018-01-07 11:13 ` [Qemu-devel] [PATCH 1/1] " byxk 0 siblings, 1 reply; 6+ messages in thread From: byxk @ 2018-01-07 11:13 UTC (permalink / raw) To: qemu-devel; +Cc: kraxel, byxk Hi QEMU, This patch allows one to pass either one or both of --evdev-lhotkey {keycode} and --evdev-rhotkey {keycode} to change the default key combo to toggle evdev grab. I had trouble figuring out where to set defaults (LCTRL + RCTRL), so ended up setting it directly. This is my first patch ever to anything so any help/feedback is appreciated. Thanks, byxk byxk (1): input-linux: provide hotkeys for evdev toggle include/ui/input.h | 3 +++ qemu-options.hx | 13 +++++++++++++ ui/input-linux.c | 4 ++-- vl.c | 8 ++++++++ 4 files changed, 26 insertions(+), 2 deletions(-) -- 2.15.1 ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Qemu-devel] [PATCH 1/1] input-linux: provide hotkeys for evdev toggle 2018-01-07 11:13 [Qemu-devel] [PATCH " byxk @ 2018-01-07 11:13 ` byxk 0 siblings, 0 replies; 6+ messages in thread From: byxk @ 2018-01-07 11:13 UTC (permalink / raw) To: qemu-devel; +Cc: kraxel, byxk --- include/ui/input.h | 3 +++ qemu-options.hx | 13 +++++++++++++ ui/input-linux.c | 4 ++-- vl.c | 8 ++++++++ 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/include/ui/input.h b/include/ui/input.h index 5cc76d6e41..94b1468159 100644 --- a/include/ui/input.h +++ b/include/ui/input.h @@ -80,4 +80,7 @@ extern const guint16 qemu_input_map_qnum_to_qcode[]; extern const guint qemu_input_map_qcode_to_linux_len; extern const guint16 qemu_input_map_qcode_to_linux[]; +extern int qemu_evdev_rhotkey; +extern int qemu_evdev_lhotkey; + #endif /* INPUT_H */ diff --git a/qemu-options.hx b/qemu-options.hx index 94647e21e3..56cafd7592 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -4264,6 +4264,19 @@ contents of @code{iv.b64} to the second secret ETEXI +DEF("evdev-lhotkey", HAS_ARG, QEMU_OPTION_evdev_lhotkey, "--evdev-lhotkey left hotkey for evdev input toggle, default=LEFTCTRL(29)\n", QEMU_ARCH_ALL) +STEXI +@item --evdev-lhotkey @var{evdevLHotkey} +@findex --evdev-lhotkey +Left keycode to use in toggling evdev +ETEXI + +DEF("evdev-rhotkey", HAS_ARG, QEMU_OPTION_evdev_rhotkey, "--evdev-rhotkey right hotkey for evdev input toggle, default=RIGHTCTRL(97)\n", QEMU_ARCH_ALL) +STEXI +@item --evdev-rhotkey @var{evdevRHotkey} +@findex --evdev-rhotkey +Right keycode to use in toggling evdev +ETEXI HXCOMM This is the last statement. Insert new options before this line! STEXI diff --git a/ui/input-linux.c b/ui/input-linux.c index 9720333b2c..8af1450dce 100644 --- a/ui/input-linux.c +++ b/ui/input-linux.c @@ -134,8 +134,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[qemu_evdev_lhotkey] && + il->keydown[qemu_evdev_rhotkey]) { il->grab_request = true; } diff --git a/vl.c b/vl.c index d3a5c5d021..7bdf6030cf 100644 --- a/vl.c +++ b/vl.c @@ -184,6 +184,8 @@ bool boot_strict; uint8_t *boot_splash_filedata; size_t boot_splash_filedata_size; uint8_t qemu_extra_params_fw[2]; +int qemu_evdev_lhotkey = 29; /* LEFTCONTROL */ +int qemu_evdev_rhotkey = 97; /* RIGHTCONTROL */ int icount_align_option; @@ -3378,6 +3380,12 @@ int main(int argc, char **argv, char **envp) qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg, &error_abort); break; + case QEMU_OPTION_evdev_rhotkey: + qemu_evdev_rhotkey = strtol(optarg, NULL, 0); + break; + case QEMU_OPTION_evdev_lhotkey: + qemu_evdev_lhotkey = strtol(optarg, NULL, 0); + break; case QEMU_OPTION_append: qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg, &error_abort); -- 2.15.1 ^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2018-01-11 9:38 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2018-01-07 22:14 [Qemu-devel] [PATCH v2 0/1] input-linux: provide hotkeys for evdev toggle byxk 2018-01-07 22:14 ` [Qemu-devel] [PATCH 1/1] " byxk 2018-01-10 16:30 ` [Qemu-devel] [PATCH v2 0/1] " 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
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).