diff mbox series

[v2,1/2] ui/cocoa.m: move ungrab to ctrl-alt-g

Message ID 20171005145557.5746-2-programmingkidx@gmail.com
State New
Headers show
Series ui/cocoa.m: enable guest to see control-alt key combinations | expand

Commit Message

Programmingkid Oct. 5, 2017, 2:55 p.m. UTC
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>
---
 ui/cocoa.m | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

Comments

Peter Maydell Nov. 2, 2017, 9:10 a.m. UTC | #1
On 5 October 2017 at 15:55, 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.
>
> signed-off-by: John Arbuckle <programmingkidx@gmail.com>
> ---

> +
> +                    // release the mouse grab
> +                    case Q_KEY_CODE_G:
> +                        [self ungrabMouse];
> +                        break;
>                  }

Testing this I have found that it makes the grab key be
"ctrl+alt+ the key labelled 'g'", even if in the
OSX host keyboard mapping that key doesn't produce the
letter 'g'. This is in contrast to for instance the menu
accelerators which honour the host keyboard layout, and
it's also not what the GTK UI does. So I think we need
to fix that.

thanks
-- PMM
Programmingkid Nov. 2, 2017, 3:20 p.m. UTC | #2
> On Nov 2, 2017, at 5:10 AM, Peter Maydell <peter.maydell@linaro.org> wrote:
> 
> On 5 October 2017 at 15:55, 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.
>> 
>> signed-off-by: John Arbuckle <programmingkidx@gmail.com>
>> ---
> 
>> +
>> +                    // release the mouse grab
>> +                    case Q_KEY_CODE_G:
>> +                        [self ungrabMouse];
>> +                        break;
>>                 }
> 
> Testing this I have found that it makes the grab key be
> "ctrl+alt+ the key labelled 'g'", even if in the
> OSX host keyboard mapping that key doesn't produce the
> letter 'g'. This is in contrast to for instance the menu
> accelerators which honour the host keyboard layout, and
> it's also not what the GTK UI does. So I think we need
> to fix that.

I just realized that the cocoa interface does not consider the keyboard layout. Switching from QWERTY to DVORK I still see the same keys outputting the same characters in OpenBIOS. This is a separate patch but sometime to take note.
BALATON Zoltan Nov. 2, 2017, 4:06 p.m. UTC | #3
On Thu, 2 Nov 2017, Programmingkid wrote:
>> On Nov 2, 2017, at 5:10 AM, Peter Maydell <peter.maydell@linaro.org> wrote:
>>
>> On 5 October 2017 at 15:55, 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.
>>>
>>> signed-off-by: John Arbuckle <programmingkidx@gmail.com>
>>> ---
>>
>>> +
>>> +                    // release the mouse grab
>>> +                    case Q_KEY_CODE_G:
>>> +                        [self ungrabMouse];
>>> +                        break;
>>>                 }
>>
>> Testing this I have found that it makes the grab key be
>> "ctrl+alt+ the key labelled 'g'", even if in the
>> OSX host keyboard mapping that key doesn't produce the
>> letter 'g'. This is in contrast to for instance the menu
>> accelerators which honour the host keyboard layout, and
>> it's also not what the GTK UI does. So I think we need
>> to fix that.
>
> I just realized that the cocoa interface does not consider the keyboard 
> layout. Switching from QWERTY to DVORK I still see the same keys 
> outputting the same characters in OpenBIOS. This is a separate patch but 
> sometime to take note.

Is it the cocoa interface or OpenBIOS? In case you are using an emulated 
USB keyboard, the very simple driver in OpenBIOS only has a US layout so 
this may be the reason (see openbios/drivers/usbhid.c). I'm not sure about 
ADB keyboards but you may want to try a few combinations to identify where 
the problem is before looking for it in QEMU's cocoa interface.

Regards,
BALATON Zoltan
Peter Maydell Nov. 2, 2017, 4:09 p.m. UTC | #4
On 2 November 2017 at 15:20, Programmingkid <programmingkidx@gmail.com> wrote:
>> On Nov 2, 2017, at 5:10 AM, Peter Maydell <peter.maydell@linaro.org> wrote:
>> Testing this I have found that it makes the grab key be
>> "ctrl+alt+ the key labelled 'g'", even if in the
>> OSX host keyboard mapping that key doesn't produce the
>> letter 'g'. This is in contrast to for instance the menu
>> accelerators which honour the host keyboard layout, and
>> it's also not what the GTK UI does. So I think we need
>> to fix that.
>
> I just realized that the cocoa interface does not consider the keyboard layout. Switching from QWERTY to DVORK I still see the same keys outputting the same characters in OpenBIOS. This is a separate patch but sometime to take note.

There's a difference between "what do we send to the guest"
(where we're obliged to send raw keycodes, but the user can
configure their guest with an appropriate keymap if they like)
and "what do we do as part of the QEMU UI" (where there is
no ability for the user to set a keymap and we should honour
the host UI keymap settings).

If you look at the behaviour of other VM implementations
like Parallels I think you'll find it's the same.

I think the way we need to implement this is that instead
of doing "switch (keycode)" and looking for Q_KEY_CODE_1...
we should do something like

if (ctrl and alt pressed) {
    NSString *keychar = [theEvent charactersIgnoringModifiers];
    if ([keychar length] == 1) {
        switch ([keychar characterAtIndex:0]) {
        case '1' .. '9':
            console_select(...);
            return;
        case 'g':
            /* handle ungrab */
            return;
    }
}

as suggested by:
https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/EventOverview/HandlingKeyEvents/HandlingKeyEvents.html

thanks
-- PMM
Programmingkid Nov. 2, 2017, 9:42 p.m. UTC | #5
> On Nov 2, 2017, at 12:06 PM, BALATON Zoltan <balaton@eik.bme.hu> wrote:
> 
> On Thu, 2 Nov 2017, Programmingkid wrote:
>>> On Nov 2, 2017, at 5:10 AM, Peter Maydell <peter.maydell@linaro.org> wrote:
>>> 
>>> On 5 October 2017 at 15:55, 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.
>>>> 
>>>> signed-off-by: John Arbuckle <programmingkidx@gmail.com>
>>>> ---
>>> 
>>>> +
>>>> +                    // release the mouse grab
>>>> +                    case Q_KEY_CODE_G:
>>>> +                        [self ungrabMouse];
>>>> +                        break;
>>>>                }
>>> 
>>> Testing this I have found that it makes the grab key be
>>> "ctrl+alt+ the key labelled 'g'", even if in the
>>> OSX host keyboard mapping that key doesn't produce the
>>> letter 'g'. This is in contrast to for instance the menu
>>> accelerators which honour the host keyboard layout, and
>>> it's also not what the GTK UI does. So I think we need
>>> to fix that.
>> 
>> I just realized that the cocoa interface does not consider the keyboard layout. Switching from QWERTY to DVORK I still see the same keys outputting the same characters in OpenBIOS. This is a separate patch but sometime to take note.
> 
> Is it the cocoa interface or OpenBIOS?

It was with the cocoa interface.

> In case you are using an emulated USB keyboard, the very simple driver in OpenBIOS only has a US layout so this may be the reason (see openbios/drivers/usbhid.c). I'm not sure about ADB keyboards but you may want to try a few combinations to identify where the problem is before looking for it in QEMU's cocoa interface.

It looks like there is no problem with sending keys to the guest. The cocoa interface behaves as it should.
diff mbox series

Patch

diff --git a/ui/cocoa.m b/ui/cocoa.m
index 93e56d0518..d3e7907103 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,7 +621,7 @@  - (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) {
 
@@ -633,6 +629,11 @@  - (void) handleEvent:(NSEvent *)event
                     case Q_KEY_CODE_1 ... Q_KEY_CODE_9: // '1' to '9' keys
                         console_select(keycode - 11);
                         break;
+
+                    // release the mouse grab
+                    case Q_KEY_CODE_G:
+                        [self ungrabMouse];
+                        break;
                 }
 
             // handle keys for graphic console
@@ -806,9 +807,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) {