* [Qemu-devel] [PATCH v3 1/2] ui/cocoa.m: move ungrab to ctrl-alt-g
@ 2017-11-02 21:39 John Arbuckle
2017-11-02 21:39 ` [Qemu-devel] [PATCH v3 2/2] ui/cocoa.m: send ctrl-alt key combinations to guest if not used by QEMU John Arbuckle
2017-11-07 10:10 ` [Qemu-devel] [PATCH v3 1/2] ui/cocoa.m: move ungrab to ctrl-alt-g Peter Maydell
0 siblings, 2 replies; 4+ messages in thread
From: John Arbuckle @ 2017-11-02 21:39 UTC (permalink / raw)
To: peter.maydell, qemu-devel; +Cc: John Arbuckle
Currently the cocoa user interface relys on the user pushing control-alt to ungrab the mouse. This is patch changes the key combination to control-alt-g to be in line with the GTK user interface.
Signed-off-by: John Arbuckle <programmingkidx@gmail.com>
---
v3 changes
- Code is now keyboard layout aware.
ui/cocoa.m | 31 ++++++++++++++++++-------------
1 file changed, 18 insertions(+), 13 deletions(-)
diff --git a/ui/cocoa.m b/ui/cocoa.m
index 2794f60b27..e06aa9c65f 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -609,10 +609,6 @@ - (void) handleEvent:(NSEvent *)event
}
}
- // release Mouse grab when pressing ctrl+alt
- if (([event modifierFlags] & NSEventModifierFlagControl) && ([event modifierFlags] & NSEventModifierFlagOption)) {
- [self ungrabMouse];
- }
break;
case NSEventTypeKeyDown:
keycode = cocoa_keycode_to_qemu([event keyCode]);
@@ -625,14 +621,23 @@ - (void) handleEvent:(NSEvent *)event
// default
- // handle control + alt Key Combos (ctrl+alt is reserved for QEMU)
+ // handle control + alt Key Combos (ctrl+alt+[1..9,g] is reserved for QEMU)
if (([event modifierFlags] & NSEventModifierFlagControl) && ([event modifierFlags] & NSEventModifierFlagOption)) {
- switch (keycode) {
-
- // enable graphic console
- case Q_KEY_CODE_1 ... Q_KEY_CODE_9: // '1' to '9' keys
- console_select(keycode - Q_KEY_CODE_1);
- break;
+ NSString *keychar = [event charactersIgnoringModifiers];
+ if ([keychar length] == 1) {
+ char key = [keychar characterAtIndex:0];
+ switch (key) {
+
+ // enable graphic console
+ case '1' ... '9':
+ console_select(key - '0' - 1); /* ascii math */
+ return;
+
+ // release the mouse grab
+ case 'g':
+ [self ungrabMouse];
+ return;
+ }
}
// handle keys for graphic console
@@ -806,9 +811,9 @@ - (void) grabMouse
if (!isFullscreen) {
if (qemu_name)
- [normalWindow setTitle:[NSString stringWithFormat:@"QEMU %s - (Press ctrl + alt to release Mouse)", qemu_name]];
+ [normalWindow setTitle:[NSString stringWithFormat:@"QEMU %s - (Press ctrl + alt + g to release Mouse)", qemu_name]];
else
- [normalWindow setTitle:@"QEMU - (Press ctrl + alt to release Mouse)"];
+ [normalWindow setTitle:@"QEMU - (Press ctrl + alt + g to release Mouse)"];
}
[self hideCursor];
if (!isAbsoluteEnabled) {
--
2.13.5 (Apple Git-94)
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [Qemu-devel] [PATCH v3 2/2] ui/cocoa.m: send ctrl-alt key combinations to guest if not used by QEMU
2017-11-02 21:39 [Qemu-devel] [PATCH v3 1/2] ui/cocoa.m: move ungrab to ctrl-alt-g John Arbuckle
@ 2017-11-02 21:39 ` John Arbuckle
2017-11-07 10:13 ` Peter Maydell
2017-11-07 10:10 ` [Qemu-devel] [PATCH v3 1/2] ui/cocoa.m: move ungrab to ctrl-alt-g Peter Maydell
1 sibling, 1 reply; 4+ messages in thread
From: John Arbuckle @ 2017-11-02 21:39 UTC (permalink / raw)
To: peter.maydell, qemu-devel; +Cc: John Arbuckle
Send control-alt key combinations to the guest if not used by the user interface.
Signed-off-by: John Arbuckle <programmingkidx@gmail.com>
---
v3 changes:
- Code is now keyboard layout aware
v2 changes:
- changed logic to use existing if case
ui/cocoa.m | 41 ++++++++++++++++++++---------------------
1 file changed, 20 insertions(+), 21 deletions(-)
diff --git a/ui/cocoa.m b/ui/cocoa.m
index e06aa9c65f..030479f4cd 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -619,29 +619,28 @@ - (void) handleEvent:(NSEvent *)event
return;
}
- // default
-
- // handle control + alt Key Combos (ctrl+alt+[1..9,g] is reserved for QEMU)
- if (([event modifierFlags] & NSEventModifierFlagControl) && ([event modifierFlags] & NSEventModifierFlagOption)) {
+ // console selection
+ if (([event modifierFlags] & NSEventModifierFlagControl) &&
+ ([event modifierFlags] & NSEventModifierFlagOption) &&
+ ([[event charactersIgnoringModifiers] length] == 1) &&
+ (isdigit([[event charactersIgnoringModifiers] characterAtIndex: 0]))) {
NSString *keychar = [event charactersIgnoringModifiers];
- if ([keychar length] == 1) {
- char key = [keychar characterAtIndex:0];
- switch (key) {
-
- // enable graphic console
- case '1' ... '9':
- console_select(key - '0' - 1); /* ascii math */
- return;
-
- // release the mouse grab
- case 'g':
- [self ungrabMouse];
- return;
- }
- }
+ char key = [keychar characterAtIndex:0];
+ console_select(key - '0' - 1); /* ascii math */
+ return;
+ }
+
+ // mouse ungrab
+ else if (([event modifierFlags] & NSEventModifierFlagControl) &&
+ ([event modifierFlags] & NSEventModifierFlagOption) &&
+ ([[event charactersIgnoringModifiers] length] == 1) &&
+ ([[event charactersIgnoringModifiers] characterAtIndex: 0] == 'g')) {
+ [self ungrabMouse];
+ return;
+ }
- // handle keys for graphic console
- } else if (qemu_console_is_graphic(NULL)) {
+ // send to guest
+ else if (qemu_console_is_graphic(NULL)) {
qemu_input_event_send_key_qcode(dcl->con, keycode, true);
// handlekeys for Monitor
--
2.13.5 (Apple Git-94)
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH v3 1/2] ui/cocoa.m: move ungrab to ctrl-alt-g
2017-11-02 21:39 [Qemu-devel] [PATCH v3 1/2] ui/cocoa.m: move ungrab to ctrl-alt-g John Arbuckle
2017-11-02 21:39 ` [Qemu-devel] [PATCH v3 2/2] ui/cocoa.m: send ctrl-alt key combinations to guest if not used by QEMU John Arbuckle
@ 2017-11-07 10:10 ` Peter Maydell
1 sibling, 0 replies; 4+ messages in thread
From: Peter Maydell @ 2017-11-07 10:10 UTC (permalink / raw)
To: John Arbuckle; +Cc: QEMU Developers
On 2 November 2017 at 21:39, John Arbuckle <programmingkidx@gmail.com> wrote:
> Currently the cocoa user interface relys on the user pushing control-alt to ungrab the mouse. This is patch changes the key combination to control-alt-g to be in line with the GTK user interface.
Hi; I've applied this to cocoa.next.
This commit message needed line-wrapping.
It also looks like you forgot the cover letter
for this patchset.
thanks
-- PMM
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH v3 2/2] ui/cocoa.m: send ctrl-alt key combinations to guest if not used by QEMU
2017-11-02 21:39 ` [Qemu-devel] [PATCH v3 2/2] ui/cocoa.m: send ctrl-alt key combinations to guest if not used by QEMU John Arbuckle
@ 2017-11-07 10:13 ` Peter Maydell
0 siblings, 0 replies; 4+ messages in thread
From: Peter Maydell @ 2017-11-07 10:13 UTC (permalink / raw)
To: John Arbuckle; +Cc: QEMU Developers
On 2 November 2017 at 21:39, John Arbuckle <programmingkidx@gmail.com> wrote:
> Send control-alt key combinations to the guest if not used by the user interface.
>
> Signed-off-by: John Arbuckle <programmingkidx@gmail.com>
> ---
> v3 changes:
> - Code is now keyboard layout aware
>
> v2 changes:
> - changed logic to use existing if case
>
> ui/cocoa.m | 41 ++++++++++++++++++++---------------------
> 1 file changed, 20 insertions(+), 21 deletions(-)
>
> diff --git a/ui/cocoa.m b/ui/cocoa.m
> index e06aa9c65f..030479f4cd 100644
> --- a/ui/cocoa.m
> +++ b/ui/cocoa.m
> @@ -619,29 +619,28 @@ - (void) handleEvent:(NSEvent *)event
> return;
> }
>
> - // default
> -
> - // handle control + alt Key Combos (ctrl+alt+[1..9,g] is reserved for QEMU)
> - if (([event modifierFlags] & NSEventModifierFlagControl) && ([event modifierFlags] & NSEventModifierFlagOption)) {
> + // console selection
> + if (([event modifierFlags] & NSEventModifierFlagControl) &&
> + ([event modifierFlags] & NSEventModifierFlagOption) &&
> + ([[event charactersIgnoringModifiers] length] == 1) &&
> + (isdigit([[event charactersIgnoringModifiers] characterAtIndex: 0]))) {
> NSString *keychar = [event charactersIgnoringModifiers];
> - if ([keychar length] == 1) {
> - char key = [keychar characterAtIndex:0];
> - switch (key) {
> -
> - // enable graphic console
> - case '1' ... '9':
> - console_select(key - '0' - 1); /* ascii math */
> - return;
> -
> - // release the mouse grab
> - case 'g':
> - [self ungrabMouse];
> - return;
> - }
> - }
> + char key = [keychar characterAtIndex:0];
> + console_select(key - '0' - 1); /* ascii math */
> + return;
> + }
> +
> + // mouse ungrab
> + else if (([event modifierFlags] & NSEventModifierFlagControl) &&
> + ([event modifierFlags] & NSEventModifierFlagOption) &&
> + ([[event charactersIgnoringModifiers] length] == 1) &&
> + ([[event charactersIgnoringModifiers] characterAtIndex: 0] == 'g')) {
> + [self ungrabMouse];
> + return;
> + }
>
> - // handle keys for graphic console
> - } else if (qemu_console_is_graphic(NULL)) {
> + // send to guest
> + else if (qemu_console_is_graphic(NULL)) {
> qemu_input_event_send_key_qcode(dcl->con, keycode, true);
>
> // handlekeys for Monitor
> --
> 2.13.5 (Apple Git-94)
This is an awful lot of entirely unnecessary code change.
Any time you find yourself repeating a big long
conditional like
> + if (([event modifierFlags] & NSEventModifierFlagControl) &&
> + ([event modifierFlags] & NSEventModifierFlagOption) &&
> + ([[event charactersIgnoringModifiers] length] == 1) &&
you should take a step back and say "how can I
avoid repeating this?".
In this case, all you need to do is delete the "else"
from the start of
} else if (qemu_console_is_graphic(NULL)) {
All the specially-handled ctrl-alt combos finish with
"return", so all the rest will then just fall through
as required.
I've put a patch which does that into cocoa.next.
thanks
-- PMM
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-11-07 10:13 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-02 21:39 [Qemu-devel] [PATCH v3 1/2] ui/cocoa.m: move ungrab to ctrl-alt-g John Arbuckle
2017-11-02 21:39 ` [Qemu-devel] [PATCH v3 2/2] ui/cocoa.m: send ctrl-alt key combinations to guest if not used by QEMU John Arbuckle
2017-11-07 10:13 ` Peter Maydell
2017-11-07 10:10 ` [Qemu-devel] [PATCH v3 1/2] ui/cocoa.m: move ungrab to ctrl-alt-g Peter Maydell
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.