ui/cocoa.m: Add ability for user to specify mouse ungrab key
PATCH v7 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
---
v7 changes:
- Prevent ungrab keys from being seen by guest.
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 | 98 +++++++++++++++++++++++++---- ui/console.c | 169 +++++++++++++++++++++++++++++++++++++++++++++++++++ vl.c | 17 ++++++ 5 files changed, 295 insertions(+), 12 deletions(-)
include/ui/console.h +22 -0
@@ -508,4 +508,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 +86 -12
177 lines not on this page · raw message
ui/console.c +169 -0
188 lines not on this page · raw message
vl.c +17 -0
@@ -2220,6 +2220,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)
Hi,
Quoted 9 lines
(quoted diff) +8
-0+/* Sends any keys that were delayed because they were part of the ungrab set */ +static void send_key_if_delayed(Set *the_set, int keycode) +{ + if (contains_number(the_set, keycode)) { + qemu_input_event_send_key_qcode(dcl->con, keycode, true); + qemu_input_event_send_key_qcode(dcl->con, keycode, false); + } +}
Review
Quoted 10 lines
(quoted diff) +7
-0case NSEventTypeKeyUp: keycode = cocoa_keycode_to_qemu([event keyCode]); + if (are_sets_equal(ungrab_set, key_set)) { + [self ungrabMouse]; + clear_set(key_set); + return; + } + send_key_if_delayed(key_set, keycode); + remove_number(key_set, keycode);
This doesn't maintain the event ordering.
cheers,
Gerd
Quoted 25 lines · Gerd Hoffmann
Hi,
Quoted 9 lines
(quoted diff) +8
-0+/* Sends any keys that were delayed because they were part of the ungrab set */ +static void send_key_if_delayed(Set *the_set, int keycode) +{ + if (contains_number(the_set, keycode)) { + qemu_input_event_send_key_qcode(dcl->con, keycode, true); + qemu_input_event_send_key_qcode(dcl->con, keycode, false); + } +}Review
Quoted 10 lines
(quoted diff) +7
-0case NSEventTypeKeyUp: keycode = cocoa_keycode_to_qemu([event keyCode]); + if (are_sets_equal(ungrab_set, key_set)) { + [self ungrabMouse]; + clear_set(key_set); + return; + } + send_key_if_delayed(key_set, keycode); + remove_number(key_set, keycode);
Quoted 1 line
This doesn't maintain the event ordering.
I need more clearifiction.
If the ungrab keys are 1-2-3, and the user does this:
down: 2
down: 3
down: 4
The only input that is sent to the guest is the 4. The 2 and 3 are forgotten about. You want the 2 and the 3 sent to the guest in the order they were pushed?
Is there another condition that needs work.
Quoted 15 lines
Quoted 11 lines
ui/cocoa.m - (void) handleEvent:(NSEvent *)event · line 746
Quoted 10 lines
case NSEventTypeKeyUp: keycode = cocoa_keycode_to_qemu([event keyCode]);ui/cocoa.m +7
-0+ if (are_sets_equal(ungrab_set, key_set)) { + [self ungrabMouse]; + clear_set(key_set); + return; + } + send_key_if_delayed(key_set, keycode); + remove_number(key_set, keycode);Quoted 1 line
This doesn't maintain the event ordering.
I need more clearifiction.
Quoted 8 lines
If the ungrab keys are 1-2-3, and the user does this:
down: 2
down: 3
down: 4The only input that is sent to the guest is the 4. The 2 and 3 are forgotten about. You want the 2 and the 3 sent to the guest in the order they were pushed?
Yes.
Quoted 1 line
Is there another condition that needs work.
Well, basically if the key combination pressed isn't a hotkey all key events should be sent as-is to the guest. No events dropped, no events reordered.
You can't use a set for this, because you don't know the event order then. With ungrab key 1-2-3 and this event sequence ...
down: 1
down: 2
up: 2
up: 1
... your send_key_if_delayed() logic sends this to the guest:
down: 2
up: 2
down: 1
up: 1
cheers,
Gerd