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=
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
Signed-off-by: John Arbuckle
---
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(-)
diff --git a/include/ui/console.h b/include/ui/console.h
index 12fef80923..5664b4c087 100644
--- a/include/ui/console.h
+++ b/include/ui/console.h
@@ -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
diff --git a/qemu-options.hx b/qemu-options.hx
index 5050a49a5e..4a613e4e9c 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -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=[,]\n"
+"-display cocoa[hotkey-grab=]\n"
"-display curses\n"
"-display none"
"select display type\n"
diff --git a/ui/cocoa.m b/ui/cocoa.m
index 51db47cd71..a4b1f9b9f4 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -106,6 +106,8 @@
bool stretch_video;
NSTextField *pauseLabel;
NSArray * supportedImageFileTypes;
+Set *key_set, *ungrab_set;
+int ungrab_sequence_length;
// Mac to QKeyCode conversion
const int mac_to_qkeycode_map[] = {
@@ -261,6 +263,15 @@ static void handleAnyDeviceErrors(Error * err)
}
}
+/* 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);
+}
+}
+
/*
--
QemuCocoaView
@@ -489,8 +500,6 @@ - (void) switchSurface:(DisplaySurface *)surface
[[fullScreenWindow contentView] setFrame:[[NSScreen mainScreen]
frame]];
[normalWindow setFrame:NSMakeRect([normalWindow frame].origin.x,
[normalWindow frame].origin.y - h + oldh, w, h + [normalWindow
frame].size.height - oldh) display:NO animate:NO];
} else {
-if (qemu_name)
-[normalWindow setTitle:[NSString stringWithFormat:@"QEMU %s",
qemu_name]];
[normalWindow setFrame:NSMakeRect([normalWindow