ui/cocoa.m: Add ability for user to specify mouse ungrab key
PATCH v8 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
---
v8 changes:
- Added a queue that keeps track of keys and their order for sending to the guest.
- Removed send_key_if_delayed()
- Before if the user had 1-2-3 as the ungrab keys, and this happend:
down: 1
down: 2
down: 3
down: 4
What the guest would see is 'down 4' only.
Now this is what happens:
If user entered:
down: 1
down: 2
down: 3
down: 4
Guest would see:
down: 1
down: 2
down: 3
down: 4
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 | 36 ++++++++ qemu-options.hx | 1 + ui/cocoa.m | 93 ++++++++++++++++++--- ui/console.c | 227 +++++++++++++++++++++++++++++++++++++++++++++++++++ vl.c | 17 ++++ 5 files changed, 362 insertions(+), 12 deletions(-)
include/ui/console.h +36 -0
@@ -508,4 +508,40 @@ 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); + +/* Code to handle sending keys to the guest */ + +/* The queue is implemented as a linked list */ +struct Node { +int value; +void *next; +}; + +typedef struct Node Node ; + +void add_key_to_queue (int keycode); +void clear_key_queue (void ); +void send_queued_keys (DisplayChangeListener *dcl); +#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 +81 -12
166 lines not on this page · raw message
ui/console.c +227 -0
246 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)