input-linux: provide hotkeys for evdev toggle
v2 cover input-linux: provide hotkeys for evdev toggle
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(-)
Signature · 1 line
2.15.1
PATCH v2 1/1 input-linux: provide hotkeys for evdev toggle
--- ui/input-linux.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 75 insertions(+), 2 deletions(-)
ui/input-linux.c +75 -2
@@ -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)
Signature · 1 line
2.15.1
Quoted 5 lines · 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 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
Signature · 3 lines
|: 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 :|
Hi Daniel, thanks for responding.
Quoted 1 line
This should really be part of the commit message for the patch itself, so
it
Quoted 1 line
gets recorded in git history.
Next patch version I'll separate this out to another commit.
Quoted 2 lines
I wonder if it is reasonable for
ui/input-linux.cto 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.
Quoted 3 lines
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)
Quoted 32 lines · Daniel P. Berrange
Quoted 5 lines · 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 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.cto 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 :|
Hi,
Quoted 2 lines
I wonder if it is reasonable for
ui/input-linux.cto 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