ui/cocoa.m: Add ability for user to specify mouse ungrab key
PATCH v6 1/1 ui/cocoa.m: Add ability for user to specify mouse ungrab key
Currently the ungrab keys for the Cocoa and GTK interface are Control-Alt-g. This combination may not be very fun for the user to have to enter, so we now enable the user to specify their own key(s) as the ungrab key(s). The list of keys that can be used is found in the file qapi/ui.json under QKeyCode. The max number of keys that can be used is three.
Syntax: -display cocoa,hotkey-grab=<key-key-key>
Example usage: -display cocoa,hotkey-grab=home
-display cocoa,hotkey-grab=shift-ctrl -display cocoa,hotkey-grab=ctrl-x -display cocoa,hotkey-grab=pgup-pgdn -display cocoa,hotkey-grab=kp_5-kp_6 -display cocoa,hotkey-grab=kp_4-kp_5-kp_6 -display cocoa,hotkey-grab=ctrl-alt
---
v6 changes:
- changed ungrab command-line option to -display cocoa,hotkey-grab
- Removed NSMutableSet code
- Implemented C version of Set datatype
v5 changes:
- Removed ungrab detection code from keydown event in handleEvent.
- Removed console_ungrab_sequence_length().
- Removed ability to always use the default ctrl-alt-g ungrab key sequence.
- Added ability to actually send keys to the guest that might overlap ungrab keys. Example for -ungrab ctrl-alt:
down(ctrl)
down(alt)
up(ctrl)
up(alt)
..ungrab activates..
down(ctrl)
down(alt)
down(f1)
up(ctrl)
up(alt)
up(f1)
..no ungrab activates..
v4 changes:
- Removed initialization code for key_value_array.
- Added void keyword to console_ungrab_key_sequence(), and console_ungrab_key_string() functions.
v3 changes:
- Added the ability for any "sendkey supported" key to be used.
- Added ability for one to three key sequences to be used.
v2 changes:
- Removed the "int i" code from the for loops.
include/ui/console.h | 22 +++++++ qemu-options.hx | 1 + ui/cocoa.m | 80 ++++++++++++++++++++---- ui/console.c | 169 +++++++++++++++++++++++++++++++++++++++++++++++++++ vl.c | 17 ++++++ 5 files changed, 277 insertions(+), 12 deletions(-)
include/ui/console.h +22 -0
@@ -533,4 +533,26 @@ static inline void early_gtk_display_init(int opengl)/* egl-headless.c */ void egl_headless_init (void ); +/* console.c */ +/* max number of keys that can be used as the ungrab keys */ +#define MAX_UNGRAB_KEYS 3 +void set_ungrab_seq (const char *new_seq); +int *console_ungrab_key_sequence (void ); +const char *console_ungrab_key_string (void ); +void use_default_ungrab_keys (void ); +void init_ungrab_keys (void ); + +/* Set datatype related code */ +typedef struct Set_struct { +int size;/* The size of the array */ +int *array;/* The array used to store the set's values */ +}Set ; + +Set *new_set (int max_size); +void add_number (Set *the_set,int the_number); +void remove_number (Set *the_set,int the_number); +bool contains_number (Set *the_set,int the_number); +void clear_set (Set *the_set); +bool are_sets_equal (Set *set1,Set *set2); +#endif
qemu-options.hx +1 -0
@@ -1243,6 +1243,7 @@ DEF("display", HAS_ARG, QEMU_OPTION_display, " [,window_close=on|off][,gl=on|off]\n" "-display gtk[,grab_on_hover=on|off][,gl=on|off]|\n" "-display vnc=<display>[,<optargs>]\n" + "-display cocoa[hotkey-grab=<key(s)>]\n" "-display curses\n" "-display none" " select display type\n"
ui/cocoa.m +68 -12
153 lines not on this page · raw message
ui/console.c +169 -0
188 lines not on this page · raw message
vl.c +17 -0
@@ -2219,6 +2219,23 @@ static DisplayType select_display(const char *p)#endif }else if (strstart (p,"none" , &opts)) { display =DT_NONE ; + }else if (strstart (p,"cocoa" , &opts)) { +#ifdef CONFIG_COCOA + display =DT_COCOA ; +if (strstart (opts,",hotkey-grab=" , &opts)) { +if (strcmp (opts,"" ) ==0 ) { +error_report ("Please add the key(s) argument" ); +exit (1 ); + } +set_ungrab_seq (opts); + }else { +error_report ("invalid Cocoa option" ); +exit (1 ); + } +#else +error_report ("Cocoa support is disabled" ); +exit (1 ); +#endif }else {error_report ("unknown display type" );exit (1 );
Signature · 1 line
2.14.3 (Apple Git-98)
Quoted 8 lines · John Arbuckle
Currently the ungrab keys for the Cocoa and GTK interface are Control-Alt-g. This combination may not be very fun for the user to have to enter, so we now enable the user to specify their own key(s) as the ungrab key(s). The list of keys that can be used is found in the file
qapi/ui.jsonunder QKeyCode. The max number of keys that can be used is three.Syntax: -display cocoa,hotkey-grab=<key-key-key>
Quoted 7 lines
Example usage: -display cocoa,hotkey-grab=home
-display cocoa,hotkey-grab=shift-ctrl -display cocoa,hotkey-grab=ctrl-x -display cocoa,hotkey-grab=pgup-pgdn -display cocoa,hotkey-grab=kp_5-kp_6 -display cocoa,hotkey-grab=kp_4-kp_5-kp_6 -display cocoa,hotkey-grab=ctrl-alt
Finally found the time for a closer look and some testing.
Problem is the hotkeys are all forwarded to the guest. So when using -- for example -- the pgup-pgdn hotkey and you press the combination the guest will see it.
I see basically two options to deal with that:
(a) Make the code more clever. On pgup keydown event the code has to figure this might be part of a hotkey sequence, hold back the event to see what comes next.
- If the next event is pgup keyup -> ok, normal pgup keypress, forward both keydown and keyup to the guest.
- If the next event is pgdn keydown -> hotkey found. So do hotkey action, don't forward keydown (and following keyup) events to the guest.
(b) Restrict allowed hotkeys to modifier key(s) plus one non-modifier key. Forwarding modifier keydown+keyup to the guest has typically effects inside the guest, so we only have to hold back that single non-modifier key. That is alot easier to implement.
cheers,
Gerd
Quoted 28 lines · Gerd Hoffmann
Quoted 8 lines · John Arbuckle
Currently the ungrab keys for the Cocoa and GTK interface are Control-Alt-g. This combination may not be very fun for the user to have to enter, so we now enable the user to specify their own key(s) as the ungrab key(s). The list of keys that can be used is found in the file
qapi/ui.jsonunder QKeyCode. The max number of keys that can be used is three.Syntax: -display cocoa,hotkey-grab=<key-key-key>
Quoted 7 lines
Example usage: -display cocoa,hotkey-grab=home
-display cocoa,hotkey-grab=shift-ctrl -display cocoa,hotkey-grab=ctrl-x -display cocoa,hotkey-grab=pgup-pgdn -display cocoa,hotkey-grab=kp_5-kp_6 -display cocoa,hotkey-grab=kp_4-kp_5-kp_6 -display cocoa,hotkey-grab=ctrl-altFinally found the time for a closer look and some testing.
Problem is the hotkeys are all forwarded to the guest. So when using -- for example -- the pgup-pgdn hotkey and you press the combination the guest will see it.
I see basically two options to deal with that:
Quoted 8 lines
(a) Make the code more clever. On pgup keydown event the code has to figure this might be part of a hotkey sequence, hold back the event to see what comes next.
- If the next event is pgup keyup -> ok, normal pgup keypress, forward both keydown and keyup to the guest.
- If the next event is pgdn keydown -> hotkey found. So do hotkey action, don't forward keydown (and following keyup) events to the guest.
Ok. I think this should be doable.
Quoted 6 lines
(b) Restrict allowed hotkeys to modifier key(s) plus one non-modifier key. Forwarding modifier keydown+keyup to the guest has typically effects inside the guest, so we only have to hold back that single non-modifier key. That is alot easier to implement.
Sorry but I was using this patch to make my ungrab key F15. This key is not used by anything and makes things so simple for me. Requiring a modifier key in the sequence seems unnecessary.
Thank you.
Hi,
Quoted 9 lines
Quoted 5 lines
(b) Restrict allowed hotkeys to modifier key(s) plus one non-modifier key. Forwarding modifier keydown+keyup to the guest has typically effects inside the guest, so we only have to hold back that single non-modifier key. That is alot easier to implement.
Sorry but I was using this patch to make my ungrab key F15. This key is not used by anything and makes things so simple for me. Requiring a modifier key in the sequence seems unnecessary.
Just a plain F15 without any modifier should be find too.
Allowing *two* (or more) non-modifier keys (i.e. F14+F15) is where it becomes tricky ...
cheers,
Gerd
Quoted 11 lines · Gerd Hoffmann
Hi,
Quoted 6 lines
Quoted 5 lines
(b) Restrict allowed hotkeys to modifier key(s) plus one non-modifier key. Forwarding modifier keydown+keyup to the guest has typically effects inside the guest, so we only have to hold back that single non-modifier key. That is alot easier to implement.
Quoted 8 lines
Quoted 3 lines
Sorry but I was using this patch to make my ungrab key F15. This key is not used by anything and makes things so simple for me. Requiring a modifier key in the sequence seems unnecessary.
Just a plain F15 without any modifier should be find too.
Allowing *two* (or more) non-modifier keys (i.e. F14+F15) is where it becomes tricky ...
I'm not sure I follow. The code does handle two or three non-modifier keys just fine.
A quick test shows this does work:
./ppc-softmmu/qemu-system-ppc -display cocoa,hotkey-grab=kp_4-kp_5-kp_6