Skip to contentSkip to conversation

ui/cocoa.m: enable guest to see control-alt key combinations

PATCH Superseded John Arbuckle 4 participants 12 messages Oct 5, 2017 – Nov 2, 2017

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover ui/cocoa.m: enable guest to see control-alt key combinations

Currently if the user needs to send a control-alt key combination, he or she was either out of luck or had to rely on the monitor's sendkey command to do so. With this patch the user can now directly send control-alt key combinations. This is great for Windows guest that may need the control-alt-delete key combination.

John Arbuckle (2):
move ungrab to ctrl-alt-g
send ctrl-alt key combinations to guest if not used by QEMU

 ui/cocoa.m | 34 ++++++++++++++++------------------
 1 file changed, 16 insertions(+), 18 deletions(-)

--
v2 changes:
- changed logic to use existing if case

2.13.5 (Apple Git-94)

#1 lore raw

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

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.

---
 ui/cocoa.m | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
ui/cocoa.m +8 -7
index 93e56d0518..d3e7907103 100644
@@ -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) {
Signature · 1 line
2.13.5 (Apple Git-94)
#2 lore raw

Re: [Qemu-devel] [PATCH v2 1/2] ui/cocoa.m: move ungrab to ctrl-alt-g

ui/cocoa.m - (void) handleEvent:(NSEvent *)event · line 637

Quoted 11 lines · 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.

---

ui/cocoa.m +5 -0
+
+                    // 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

#3 lore raw

Re: [Qemu-devel] [PATCH v2 1/2] ui/cocoa.m: move ungrab to ctrl-alt-g

Quoted 16 lines · Peter Maydell

ui/cocoa.m - (void) handleEvent:(NSEvent *)event · line 637

Quoted 11 lines · 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.

---

ui/cocoa.m +5 -0
+
+                    // release the mouse grab
+                    case Q_KEY_CODE_G:
+                        [self ungrabMouse];
+                        break;
                }
Quoted 7 lines

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.

#4 lore raw

Re: [Qemu-devel] [PATCH v2 1/2] ui/cocoa.m: move ungrab to ctrl-alt-g

Quoted 23 lines · Programmingkid
Quoted 15 lines · Peter Maydell

ui/cocoa.m - (void) handleEvent:(NSEvent *)event · line 637

Quoted 11 lines · 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.

---

ui/cocoa.m +5 -0
+
+                    // release the mouse grab
+                    case Q_KEY_CODE_G:
+                        [self ungrabMouse];
+                        break;
                }
Quoted 7 lines

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.

Quoted 1 line

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

#5 lore raw

Re: [Qemu-devel] [PATCH v2 1/2] ui/cocoa.m: move ungrab to ctrl-alt-g

Quoted 27 lines · BALATON Zoltan
Quoted 23 lines · Programmingkid
Quoted 22 lines · Peter Maydell

ui/cocoa.m - (void) handleEvent:(NSEvent *)event · line 637

Quoted 11 lines · 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.

---

ui/cocoa.m +5 -0
+
+                    // 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.

Quoted 3 lines
Quoted 1 line

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.

Quoted 1 line

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.

#6 lore raw

Re: [Qemu-devel] [PATCH v2 1/2] ui/cocoa.m: move ungrab to ctrl-alt-g

In reply to Programmingkid
Quoted 10 lines · Programmingkid
Quoted 8 lines · Peter Maydell

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

#7 lore raw

PATCH v2 2/2 ui/cocoa.m: send ctrl-alt key combinations to guest if not used by QEMU

In reply to John Arbuckle

Send control-alt key combinations to the guest if not used by the user interface.

---
v2 changes:
- changed logic to use existing if case

 ui/cocoa.m | 31 ++++++++++++++-----------------
 1 file changed, 14 insertions(+), 17 deletions(-)
ui/cocoa.m +14 -17
index d3e7907103..828d507d57 100644
@@ -619,25 +619,22 @@ - (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)) {
-                switch (keycode) {
-
-                    // enable graphic console
-                    case Q_KEY_CODE_1 ... Q_KEY_CODE_9: // '1' to '9' keys
-                        console_select(keycode - 11);
-                        break;
+            // console selection
+            if (([event modifierFlags] & NSEventModifierFlagControl) &&
+                ([event modifierFlags] & NSEventModifierFlagOption) &&
+                (keycode >= Q_KEY_CODE_1 && keycode <= Q_KEY_CODE_9)) {
+                console_select(keycode - 11);
+            }
 
-                    // release the mouse grab
-                    case Q_KEY_CODE_G:
-                        [self ungrabMouse];
-                        break;
-                }
+            // mouse ungrab
+            else if (([event modifierFlags] & NSEventModifierFlagControl) &&
+                     ([event modifierFlags] & NSEventModifierFlagOption) &&
+                     (keycode == Q_KEY_CODE_G)) {
+                [self ungrabMouse];
+            }
 
-            // 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
Signature · 1 line
2.13.5 (Apple Git-94)
#8 lore raw

Re: [Qemu-devel] [PATCH v2 2/2] ui/cocoa.m: send ctrl-alt key combinations to guest if not used by QEMU

Quoted 6 lines · John Arbuckle

Send control-alt key combinations to the guest if not used by the user interface.

---
v2 changes:
- changed logic to use existing if case

This patch is missing your signed-off-by line, can you provide it, please?

thanks
-- PMM

#9 lore raw

Re: [Qemu-devel] [PATCH v2 2/2] ui/cocoa.m: send ctrl-alt key combinations to guest if not used by QEMU

Quoted 10 lines · Peter Maydell
Quoted 6 lines · John Arbuckle

Send control-alt key combinations to the guest if not used by the user interface.

---
v2 changes:
- changed logic to use existing if case

This patch is missing your signed-off-by line, can you provide it, please?

...actually, don't worry -- I wrote an equivalent of this patch that does the same thing but doesn't need to get rid of the switch() statement.

thanks
-- PMM

#10 lore raw

Re: [Qemu-devel] [PATCH v2 2/2] ui/cocoa.m: send ctrl-alt key combinations to guest if not used by QEMU

Quoted 15 lines · Peter Maydell
Quoted 10 lines · Peter Maydell
Quoted 6 lines · John Arbuckle

Send control-alt key combinations to the guest if not used by the user interface.

---
v2 changes:
- changed logic to use existing if case

This patch is missing your signed-off-by line, can you provide it, please?

Quoted 6 lines

...actually, don't worry -- I wrote an equivalent of this patch that does the same thing but doesn't need to get rid of the switch() statement.

thanks
-- PMM

Please cc me when you send it to the mailing list. Thanks.

#11 lore raw
In reply to John Arbuckle
This series seems to have some coding style problems. See output below for more information:

Hi,

This series seems to have some coding style problems. See output below for more information:

Type: series
Message-id: [email protected]
Subject: [Qemu-devel] [PATCH v2 0/2] ui/cocoa.m: enable guest to see control-alt key combinations

=== TEST SCRIPT BEGIN ===
#!/bin/bash

BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0

git config --local diff.renamelimit 0
git config --local diff.renames True

commits="$(git log --format=%H --reverse $BASE..)" for c in $commits; do

    echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
    if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
        failed=1
        echo
    fi
    n=$((n+1))

done

exit $failed
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
t [tag update] patchew/[email protected] -> patchew/[email protected]
t [tag update] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'
16fa5de081 ui/cocoa.m: send ctrl-alt key combinations to guest if not used by QEMU d71057fc7d ui/cocoa.m: move ungrab to ctrl-alt-g

=== OUTPUT BEGIN ===
Checking PATCH 1/2: ui/cocoa.m: move ungrab to ctrl-alt-g...
ERROR: The correct form is "Signed-off-by"
#8:

total: 1 errors, 0 warnings, 40 lines checked

Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

Checking PATCH 2/2: ui/cocoa.m: send ctrl-alt key combinations to guest if not used by QEMU... === OUTPUT END ===

Test command exited with code: 1

---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]