Skip to contentSkip to conversation

cocoa: keyboard quality of life

PATCH Superseded Akihiko Odaki 3 participants 8 messages Mar 6, 2022 – Mar 7, 2022

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover cocoa: keyboard quality of life

The patch series was originally posted by Gustavo Noronha Silva, and rebased to commit 2acf5e1d0e0f15be1b0ad85cf05b3a6e6307680c by Akihiko Odaki.

This series adds two new options to the cocoa display:

- full-grab causes it to use a global tap to steal system combos away from Mac OS X, so they can be handled by the VM

- swap-option-command does what it says on the tin; while that is something you can do at the Mac OS X level or even supported by some keyboards, it is much more convenient to have qemu put Meta/Super and Alt where they belong if you are running a non-Mac VM

Both are off by default. For full-grab in particular, it is off also because unfortunately it needs accessibility permissions for input grabbing, so it requires more deliberate action by the user anyway.

Gustavo Noronha Silva (2):
ui/cocoa: capture all keys and combos when mouse is grabbed ui/cocoa: add option to swap Option and Command

 qapi/ui.json    |  22 +++++++++
 qemu-options.hx |   4 ++
 ui/cocoa.m      | 129 ++++++++++++++++++++++++++++++++++++++++++++----
 3 files changed, 146 insertions(+), 9 deletions(-)
Signature · 1 line
2.32.0 (Apple Git-132)
#1 lore raw

PATCH 1/2 ui/cocoa: capture all keys and combos when mouse is grabbed

From: Gustavo Noronha Silva <[email protected]>

Applications such as Gnome may use Alt-Tab and Super-Tab for different purposes, some use Ctrl-arrows so we want to allow qemu to handle everything when it captures the mouse/keyboard.

However, Mac OS handles some combos like Command-Tab and Ctrl-arrows at an earlier part of the event handling chain, not letting qemu see it.

We add a global Event Tap that allows qemu to see all events when the mouse is grabbed. Note that this requires additional permissions.

See:

https://developer.apple.com/documentation/coregraphics/1454426-cgeventtapcreate?language=objc#discussion
https://support.apple.com/en-in/guide/mac-help/mh32356/mac

Message-Id: <[email protected]>

---
 qapi/ui.json    | 16 ++++++++++++
 qemu-options.hx |  3 +++
 ui/cocoa.m      | 65 ++++++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 83 insertions(+), 1 deletion(-)
qapi/ui.json +16 -0
index 4a13f883a30..1e9893419fe 100644
@@ -1260,6 +1260,21 @@
 { 'struct'  : 'DisplayCurses',
   'data'    : { '*charset'       : 'str' } }
 
+##
+# @DisplayCocoa:
+#
+# Cocoa display options.
+#
+# @full-grab: Capture all key presses, including system combos. This
+#             requires accessibility permissions, since it performs
+#             a global grab on key events. (default: off)
+#             See https://support.apple.com/en-in/guide/mac-help/mh32356/mac
+#
+# Since: 6.1
+##
+{ 'struct'  : 'DisplayCocoa',
+  'data'    : { '*full-grab'     : 'bool' } }
+
 ##
 # @DisplayType:
 #
@@ -1338,6 +1353,7 @@
   'discriminator' : 'type',
   'data'    : {
       'gtk': { 'type': 'DisplayGTK', 'if': 'CONFIG_GTK' },
+      'cocoa': { 'type': 'DisplayCocoa', 'if': 'CONFIG_COCOA' },
       'curses': { 'type': 'DisplayCurses', 'if': 'CONFIG_CURSES' },
       'egl-headless': { 'type': 'DisplayEGLHeadless',
                         'if': { 'all': ['CONFIG_OPENGL', 'CONFIG_GBM'] } },
qemu-options.hx +3 -0
index 094a6c1d7c2..4df9ccc3446 100644
@@ -1916,6 +1916,9 @@ DEF("display", HAS_ARG, QEMU_OPTION_display,
 #if defined(CONFIG_CURSES)
     "-display curses[,charset=<encoding>]\n"
 #endif
+#if defined(CONFIG_COCOA)
+    "-display cocoa[,full_grab=on|off]\n"
+#endif
 #if defined(CONFIG_OPENGL)
     "-display egl-headless[,rendernode=<file>]\n"
 #endif
ui/cocoa.m +64 -1

110 lines not on this page · raw message

Signature · 1 line
2.32.0 (Apple Git-132)
#2 lore raw

Re: [PATCH 1/2] ui/cocoa: capture all keys and combos when mouse is grabbed

Quoted 94 lines · Akihiko Odaki

From: Gustavo Noronha Silva <[email protected]>

Applications such as Gnome may use Alt-Tab and Super-Tab for different purposes, some use Ctrl-arrows so we want to allow qemu to handle everything when it captures the mouse/keyboard.

However, Mac OS handles some combos like Command-Tab and Ctrl-arrows at an earlier part of the event handling chain, not letting qemu see it.

We add a global Event Tap that allows qemu to see all events when the mouse is grabbed. Note that this requires additional permissions.

See:

https://developer.apple.com/documentation/coregraphics/1454426-cgeventtapcreate?language=objc#discussion
https://support.apple.com/en-in/guide/mac-help/mh32356/mac

Message-Id: <[email protected]>

---

qapi/ui.json    | 16 ++++++++++++
qemu-options.hx |  3 +++
ui/cocoa.m      | 65 ++++++++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 83 insertions(+), 1 deletion(-)
qapi/ui.json +16 -0
index 4a13f883a30..1e9893419fe 100644
@@ -1260,6 +1260,21 @@
 { 'struct'  : 'DisplayCurses',
  'data'    : { '*charset'       : 'str' } }
 
+##
+# @DisplayCocoa:
+#
+# Cocoa display options.
+#
+# @full-grab: Capture all key presses, including system combos. This
+#             requires accessibility permissions, since it performs
+#             a global grab on key events. (default: off)
+#             See https://support.apple.com/en-in/guide/mac-help/mh32356/mac
+#
+# Since: 6.1
+##
+{ 'struct'  : 'DisplayCocoa',
+  'data'    : { '*full-grab'     : 'bool' } }
+
 ##
 # @DisplayType:
 #
@@ -1338,6 +1353,7 @@
  'discriminator' : 'type',
  'data'    : {
      'gtk': { 'type': 'DisplayGTK', 'if': 'CONFIG_GTK' },
+      'cocoa': { 'type': 'DisplayCocoa', 'if': 'CONFIG_COCOA' },
      'curses': { 'type': 'DisplayCurses', 'if': 'CONFIG_CURSES' },
      'egl-headless': { 'type': 'DisplayEGLHeadless',
                        'if': { 'all': ['CONFIG_OPENGL', 'CONFIG_GBM'] } },
qemu-options.hx +3 -0
index 094a6c1d7c2..4df9ccc3446 100644
@@ -1916,6 +1916,9 @@ DEF("display", HAS_ARG, QEMU_OPTION_display,
 #if defined(CONFIG_CURSES)
    "-display curses[,charset=<encoding>]\n"
 #endif
+#if defined(CONFIG_COCOA)
+    "-display cocoa[,full_grab=on|off]\n"
+#endif
 #if defined(CONFIG_OPENGL)
    "-display egl-headless[,rendernode=<file>]\n"
 #endif
ui/cocoa.m +2 -7
index 8ab9ab5e84d..c41bc615d33 100644
@@ -308,11 +308,13 @@ @interface QemuCocoaView : NSView
    BOOL isMouseGrabbed;
    BOOL isFullscreen;
    BOOL isAbsoluteEnabled;
+    CFMachPortRef eventsTap;
 }
- (void) switchSurface:(pixman_image_t *)image;
- (void) grabMouse;
- (void) ungrabMouse;
- (void) toggleFullScreen:(id)sender;
+- (void) setFullGrab:(id)sender;
- (void) handleMonitorInput:(NSEvent *)event;
- (bool) handleEvent:(NSEvent *)event;
- (bool) handleEventLocked:(NSEvent *)event;

ui/cocoa.m - (void) raiseAllKeys; · line 342

Quoted 6 lines
ui/cocoa.m +3 -0
@@ -335,6 +337,19 @@ - (void) raiseAllKeys;
 
 QemuCocoaView *cocoaView;
 
+static CGEventRef handleTapEvent(CGEventTapProxy proxy, CGEventType type, CGEventRef cgEvent, void *userInfo)
+{
+    QemuCocoaView *cocoaView = (QemuCocoaView*) userInfo;

Extra space between cast and userinfo? Do you need explicit cast at all? In C at least void * does not need explicit cast, not sure about Objective-C but if it's not needed you could just remove the cast.

Regards,
BALATON Zoltan

Quoted 96 lines
ui/cocoa.m +10 -0
+    NSEvent* event = [NSEvent eventWithCGEvent:cgEvent];
+    if ([cocoaView isMouseGrabbed] && [cocoaView handleEvent:event]) {
+        COCOA_DEBUG("Global events tap: qemu handled the event, capturing!\n");
+        return NULL;
+    }
+    COCOA_DEBUG("Global events tap: qemu did not handle the event, letting it through...\n");
+
+    return cgEvent;
+}
+

@implementation QemuCocoaView
- (id)initWithFrame:(NSRect)frameRect
{

ui/cocoa.m +49 -3
@@ -360,6 +375,11 @@ - (void) dealloc
    }
 
    qkbd_state_free(kbd);
+
+    if (eventsTap) {
+        CFRelease(eventsTap);
+    }
+
    [super dealloc];
 }
 
@@ -654,6 +674,36 @@ - (void) toggleFullScreen:(id)sender
    }
 }
 
+- (void) setFullGrab:(id)sender
+{
+    COCOA_DEBUG("QemuCocoaView: setFullGrab\n");
+
+    CGEventMask mask = CGEventMaskBit(kCGEventKeyDown) | CGEventMaskBit(kCGEventKeyUp) | CGEventMaskBit(kCGEventFlagsChanged);
+    eventsTap = CGEventTapCreate(kCGHIDEventTap, kCGHeadInsertEventTap, kCGEventTapOptionDefault,
+                                 mask, handleTapEvent, self);
+    if (!eventsTap) {
+        warn_report("Could not create event tap, system key combos will not be captured.\n");
+        return;
+    } else {
+        COCOA_DEBUG("Global events tap created! Will capture system key combos.\n");
+    }
+
+    CFRunLoopRef runLoop = CFRunLoopGetCurrent();
+    if (!runLoop) {
+        warn_report("Could not obtain current CF RunLoop, system key combos will not be captured.\n");
+        return;
+    }
+
+    CFRunLoopSourceRef tapEventsSrc = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, eventsTap, 0);
+    if (!tapEventsSrc ) {
+        warn_report("Could not obtain current CF RunLoop, system key combos will not be captured.\n");
+        return;
+    }
+
+    CFRunLoopAddSource(runLoop, tapEventsSrc, kCFRunLoopDefaultMode);
+    CFRelease(tapEventsSrc);
+}
+
- (void) toggleKey: (int)keycode {
    qkbd_state_key_event(kbd, keycode, !qkbd_state_key_get(kbd, keycode));
 }
@@ -1281,6 +1331,13 @@ - (void)toggleFullScreen:(id)sender
    [cocoaView toggleFullScreen:sender];
 }
 
+- (void) setFullGrab:(id)sender
+{
+    COCOA_DEBUG("QemuCocoaAppController: setFullGrab\n");
+
+    [cocoaView setFullGrab:sender];
+}
+
 /* Tries to find then open the specified filename */
- (void) openDocumentation: (NSString *) filename
 {
@@ -2057,11 +2114,17 @@ static void cocoa_display_init(DisplayState *ds, DisplayOptions *opts)
    qemu_sem_wait(&app_started_sem);
    COCOA_DEBUG("cocoa_display_init: app start completed\n");
 
+    QemuCocoaAppController* controller = (QemuCocoaAppController*)[[NSApplication sharedApplication] delegate];
    /* if fullscreen mode is to be used */
    if (opts->has_full_screen && opts->full_screen) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [NSApp activateIgnoringOtherApps: YES];
-            [(QemuCocoaAppController *)[[NSApplication sharedApplication] delegate] toggleFullScreen: nil];
+            [controller toggleFullScreen: nil];
+        });
+    }
+    if (opts->u.cocoa.has_full_grab && opts->u.cocoa.full_grab) {
+        dispatch_async(dispatch_get_main_queue(), ^{
+            [controller setFullGrab: nil];
        });
    }
    if (opts->has_show_cursor && opts->show_cursor) {
#3 lore raw

PATCH 2/2 ui/cocoa: add option to swap Option and Command

In reply to Akihiko Odaki

From: Gustavo Noronha Silva <[email protected]>

On Mac OS X the Option key maps to Alt and Command to Super/Meta. This change swaps them around so that Alt is the key closer to the space bar and Meta/Super is between Control and Alt, like on non-Mac keyboards.

It is a cocoa display option, disabled by default.

Message-Id: <[email protected]>

---
 qapi/ui.json    |  8 ++++++-
 qemu-options.hx |  3 ++-
 ui/cocoa.m      | 64 ++++++++++++++++++++++++++++++++++++++++++-------
 3 files changed, 65 insertions(+), 10 deletions(-)
qapi/ui.json +7 -1
index 1e9893419fe..b082e1a7dee 100644
@@ -1270,10 +1270,16 @@
 #             a global grab on key events. (default: off)
 #             See https://support.apple.com/en-in/guide/mac-help/mh32356/mac
 #
+# @swap-option-command: Swap the Option and Command keys so that their key
+#                       codes match their position on non-Mac keyboards and
+#                       you can use Meta/Super and Alt where you expect them.
+#                       (default: off)
+#
 # Since: 6.1
 ##
 { 'struct'  : 'DisplayCocoa',
-  'data'    : { '*full-grab'     : 'bool' } }
+  'data'    : { '*full-grab'           : 'bool',
+                '*swap-option-command' : 'bool' } }
 
 ##
 # @DisplayType:
qemu-options.hx +2 -1
index 4df9ccc3446..8431445e9c0 100644
@@ -1917,7 +1917,8 @@ DEF("display", HAS_ARG, QEMU_OPTION_display,
     "-display curses[,charset=<encoding>]\n"
 #endif
 #if defined(CONFIG_COCOA)
-    "-display cocoa[,full_grab=on|off]\n"
+    "-display cocoa[,full-grab=on|off]\n"
+    "              [,swap-option-command=on|off]\n"
 #endif
 #if defined(CONFIG_OPENGL)
     "-display egl-headless[,rendernode=<file>]\n"
ui/cocoa.m +56 -8

131 lines not on this page · raw message

Signature · 1 line
2.32.0 (Apple Git-132)
#4 lore raw

Re: [PATCH 2/2] ui/cocoa: add option to swap Option and Command

Quoted 27 lines · Akihiko Odaki

From: Gustavo Noronha Silva <[email protected]>

On Mac OS X the Option key maps to Alt and Command to Super/Meta. This change swaps them around so that Alt is the key closer to the space bar and Meta/Super is between Control and Alt, like on non-Mac keyboards.

It is a cocoa display option, disabled by default.

Message-Id: <[email protected]>

---

qapi/ui.json    |  8 ++++++-
qemu-options.hx |  3 ++-
ui/cocoa.m      | 64 ++++++++++++++++++++++++++++++++++++++++++-------
3 files changed, 65 insertions(+), 10 deletions(-)
qapi/ui.json +1 -0
index 1e9893419fe..b082e1a7dee 100644
@@ -1270,10 +1270,16 @@
 #             a global grab on key events. (default: off)
 #             See https://support.apple.com/en-in/guide/mac-help/mh32356/mac
 #
+# @swap-option-command: Swap the Option and Command keys so that their key

qapi/ui.json line 1282

Quoted 10 lines
qapi/ui.json +6 -1
+#                       codes match their position on non-Mac keyboards and
+#                       you can use Meta/Super and Alt where you expect them.
+#                       (default: off)
+#
 # Since: 6.1
 ##
 { 'struct'  : 'DisplayCocoa',
-  'data'    : { '*full-grab'     : 'bool' } }
+  'data'    : { '*full-grab'           : 'bool',
+                '*swap-option-command' : 'bool' } }

This option name is too long to type. Could we abbreviate it somehow? Like swap-opt-cmd or swap-alt-meta?

Regards,
BALATON Zoltan

Quoted 161 lines
qapi/ui.json +0 -0
 ##
 # @DisplayType:
qemu-options.hx +2 -1
index 4df9ccc3446..8431445e9c0 100644
@@ -1917,7 +1917,8 @@ DEF("display", HAS_ARG, QEMU_OPTION_display,
    "-display curses[,charset=<encoding>]\n"
 #endif
 #if defined(CONFIG_COCOA)
-    "-display cocoa[,full_grab=on|off]\n"
+    "-display cocoa[,full-grab=on|off]\n"
+    "              [,swap-option-command=on|off]\n"
 #endif
 #if defined(CONFIG_OPENGL)
    "-display egl-headless[,rendernode=<file>]\n"
ui/cocoa.m +56 -20
index c41bc615d33..b152d3a1563 100644
@@ -73,6 +73,7 @@
 typedef struct {
    int width;
    int height;
+    bool swap_option_command;
 } QEMUScreen;
 
 static void cocoa_update(DisplayChangeListener *dcl,
@@ -329,6 +330,7 @@ - (void) setAbsoluteEnabled:(BOOL)tIsAbsoluteEnabled;
 */
- (BOOL) isMouseGrabbed;
- (BOOL) isAbsoluteEnabled;
+- (BOOL) isSwapOptionCommandEnabled;
- (float) cdx;
- (float) cdy;
- (QEMUScreen) gscreen;
@@ -704,6 +706,13 @@ - (void) setFullGrab:(id)sender
    CFRelease(tapEventsSrc);
 }
 
+- (void) setSwapOptionCommand:(id)sender
+{
+    COCOA_DEBUG("QemuCocoaView: setSwapOptionCommand\n");
+
+    screen.swap_option_command = true;
+}
+
- (void) toggleKey: (int)keycode {
    qkbd_state_key_event(kbd, keycode, !qkbd_state_key_get(kbd, keycode));
 }
@@ -853,12 +862,22 @@ - (bool) handleEventLocked:(NSEvent *)event
        qkbd_state_key_event(kbd, Q_KEY_CODE_CTRL_R, false);
    }
    if (!(modifiers & NSEventModifierFlagOption)) {
-        qkbd_state_key_event(kbd, Q_KEY_CODE_ALT, false);
-        qkbd_state_key_event(kbd, Q_KEY_CODE_ALT_R, false);
+        if ([self isSwapOptionCommandEnabled]) {
+            qkbd_state_key_event(kbd, Q_KEY_CODE_META_L, false);
+            qkbd_state_key_event(kbd, Q_KEY_CODE_META_R, false);
+        } else {
+            qkbd_state_key_event(kbd, Q_KEY_CODE_ALT, false);
+            qkbd_state_key_event(kbd, Q_KEY_CODE_ALT_R, false);
+        }
    }
    if (!(modifiers & NSEventModifierFlagCommand)) {
-        qkbd_state_key_event(kbd, Q_KEY_CODE_META_L, false);
-        qkbd_state_key_event(kbd, Q_KEY_CODE_META_R, false);
+        if ([self isSwapOptionCommandEnabled]) {
+            qkbd_state_key_event(kbd, Q_KEY_CODE_ALT, false);
+            qkbd_state_key_event(kbd, Q_KEY_CODE_ALT_R, false);
+        } else {
+            qkbd_state_key_event(kbd, Q_KEY_CODE_META_L, false);
+            qkbd_state_key_event(kbd, Q_KEY_CODE_META_R, false);
+        }
    }
 
    switch ([event type]) {
@@ -890,13 +909,21 @@ - (bool) handleEventLocked:(NSEvent *)event
 
                case kVK_Option:
                    if (!!(modifiers & NSEventModifierFlagOption)) {
-                        [self toggleKey:Q_KEY_CODE_ALT];
+                        if ([self isSwapOptionCommandEnabled]) {
+                            [self toggleKey:Q_KEY_CODE_META_L];
+                        } else {
+                            [self toggleKey:Q_KEY_CODE_ALT];
+                        }
                    }
                    break;
 
                case kVK_RightOption:
                    if (!!(modifiers & NSEventModifierFlagOption)) {
-                        [self toggleKey:Q_KEY_CODE_ALT_R];
+                        if ([self isSwapOptionCommandEnabled]) {
+                            [self toggleKey:Q_KEY_CODE_META_R];
+                        } else {
+                            [self toggleKey:Q_KEY_CODE_ALT_R];
+                        }
                    }
                    break;
 
@@ -904,14 +931,22 @@ - (bool) handleEventLocked:(NSEvent *)event
                case kVK_Command:
                    if (isMouseGrabbed &&
                        !!(modifiers & NSEventModifierFlagCommand)) {
-                        [self toggleKey:Q_KEY_CODE_META_L];
+                        if ([self isSwapOptionCommandEnabled]) {
+                            [self toggleKey:Q_KEY_CODE_ALT];
+                        } else {
+                            [self toggleKey:Q_KEY_CODE_META_L];
+                        }
                    }
                    break;
 
                case kVK_RightCommand:
                    if (isMouseGrabbed &&
                        !!(modifiers & NSEventModifierFlagCommand)) {
-                        [self toggleKey:Q_KEY_CODE_META_R];
+                        if ([self isSwapOptionCommandEnabled]) {
+                            [self toggleKey:Q_KEY_CODE_ALT_R];
+                        } else {
+                            [self toggleKey:Q_KEY_CODE_META_R];
+                        }
                    }
                    break;
            }
@@ -1146,6 +1181,7 @@ - (void) setAbsoluteEnabled:(BOOL)tIsAbsoluteEnabled {
 }
- (BOOL) isMouseGrabbed {return isMouseGrabbed;}
- (BOOL) isAbsoluteEnabled {return isAbsoluteEnabled;}
+- (BOOL) isSwapOptionCommandEnabled {return screen.swap_option_command;}
- (float) cdx {return cdx;}
- (float) cdy {return cdy;}
- (QEMUScreen) gscreen {return screen;}
@@ -1338,6 +1374,13 @@ - (void) setFullGrab:(id)sender
    [cocoaView setFullGrab:sender];
 }
 
+- (void) setSwapOptionCommand:(id)sender
+{
+    COCOA_DEBUG("QemuCocoaAppController: setSwapOptionCommand\n");
+
+    [cocoaView setSwapOptionCommand:sender];
+}
+
 /* Tries to find then open the specified filename */
- (void) openDocumentation: (NSString *) filename
 {
@@ -2127,6 +2170,11 @@ static void cocoa_display_init(DisplayState *ds, DisplayOptions *opts)
            [controller setFullGrab: nil];
        });
    }
+    if (opts->u.cocoa.has_swap_option_command && opts->u.cocoa.swap_option_command) {
+        dispatch_async(dispatch_get_main_queue(), ^{
+            [controller setSwapOptionCommand: nil];
+        });
+    }
    if (opts->has_show_cursor && opts->show_cursor) {
        cursor_hide = 0;
    }
#5 lore raw

Re: [PATCH 2/2] ui/cocoa: add option to swap Option and Command

Quoted 32 lines · BALATON Zoltan
Quoted 31 lines · Akihiko Odaki

From: Gustavo Noronha Silva <[email protected]>

On Mac OS X the Option key maps to Alt and Command to Super/Meta. This change swaps them around so that Alt is the key closer to the space bar and Meta/Super is between Control and Alt, like on non-Mac keyboards.

It is a cocoa display option, disabled by default.

Message-Id: <[email protected]>

---

qapi/ui.json    |  8 ++++++-
qemu-options.hx |  3 ++-
ui/cocoa.m      | 64 ++++++++++++++++++++++++++++++++++++++++++-------
3 files changed, 65 insertions(+), 10 deletions(-)
qapi/ui.json +5 -0
index 1e9893419fe..b082e1a7dee 100644
@@ -1270,10 +1270,16 @@
 #             a global grab on key events. (default: off)
 #             See https://support.apple.com/en-in/guide/mac-help/mh32356/mac
 #
+# @swap-option-command: Swap the Option and Command keys so that their key
+#                       codes match their position on non-Mac keyboards and
+#                       you can use Meta/Super and Alt where you expect them.
+#                       (default: off)
+#
Quoted 8 lines

qapi/ui.json line 1282

Quoted 6 lines
qapi/ui.json +2 -1
 # Since: 6.1
 ##
 { 'struct'  : 'DisplayCocoa',
-  'data'    : { '*full-grab'     : 'bool' } }
+  'data'    : { '*full-grab'           : 'bool',
+                '*swap-option-command' : 'bool' } }

This option name is too long to type. Could we abbreviate it somehow?

We've largely avoided abbreviations in the QAPI schema, for better or worse.

Quoted 1 line

Like swap-opt-cmd or swap-alt-meta?

We should stick to how the keys are generally called on this platform. I can't say (I'm not using it).

#6 lore raw

Re: [PATCH 2/2] ui/cocoa: add option to swap Option and Command

Quoted 43 lines · Markus Armbruster
Quoted 32 lines · BALATON Zoltan
Quoted 31 lines · Akihiko Odaki

From: Gustavo Noronha Silva <[email protected]>

On Mac OS X the Option key maps to Alt and Command to Super/Meta. This change swaps them around so that Alt is the key closer to the space bar and Meta/Super is between Control and Alt, like on non-Mac keyboards.

It is a cocoa display option, disabled by default.

Message-Id: <[email protected]>

---

qapi/ui.json    |  8 ++++++-
qemu-options.hx |  3 ++-
ui/cocoa.m      | 64 ++++++++++++++++++++++++++++++++++++++++++-------
3 files changed, 65 insertions(+), 10 deletions(-)
qapi/ui.json +5 -0
index 1e9893419fe..b082e1a7dee 100644
@@ -1270,10 +1270,16 @@
 #             a global grab on key events. (default: off)
 #             See https://support.apple.com/en-in/guide/mac-help/mh32356/mac
 #
+# @swap-option-command: Swap the Option and Command keys so that their key
+#                       codes match their position on non-Mac keyboards and
+#                       you can use Meta/Super and Alt where you expect them.
+#                       (default: off)
+#
Quoted 8 lines

qapi/ui.json line 1282

Quoted 6 lines
qapi/ui.json +2 -1
 # Since: 6.1
 ##
 { 'struct'  : 'DisplayCocoa',
-  'data'    : { '*full-grab'     : 'bool' } }
+  'data'    : { '*full-grab'           : 'bool',
+                '*swap-option-command' : 'bool' } }

This option name is too long to type. Could we abbreviate it somehow?

Quoted 8 lines

We've largely avoided abbreviations in the QAPI schema, for better or worse.

Quoted 1 line

Like swap-opt-cmd or swap-alt-meta?

We should stick to how the keys are generally called on this platform. I can't say (I'm not using it).

The patch series is now in:
https://patchew.org/QEMU/[email protected]/

It uses swap-opt-cmd for the name. Please reply to the series if it is problematic.

Regards,
Akihiko Odaki

#7 lore raw

Re: [PATCH 2/2] ui/cocoa: add option to swap Option and Command

Quoted 47 lines · Akihiko Odaki
Quoted 46 lines · Markus Armbruster
Quoted 43 lines · BALATON Zoltan
Quoted 37 lines · Akihiko Odaki

From: Gustavo Noronha Silva <[email protected]>

On Mac OS X the Option key maps to Alt and Command to Super/Meta. This change swaps them around so that Alt is the key closer to the space bar and Meta/Super is between Control and Alt, like on non-Mac keyboards.

It is a cocoa display option, disabled by default.

Message-Id: <[email protected]>

---

qapi/ui.json    |  8 ++++++-
qemu-options.hx |  3 ++-
ui/cocoa.m      | 64 ++++++++++++++++++++++++++++++++++++++++++-------
3 files changed, 65 insertions(+), 10 deletions(-)
qapi/ui.json +1 -0
index 1e9893419fe..b082e1a7dee 100644
@@ -1270,10 +1270,16 @@
 #             a global grab on key events. (default: off)
 #             See https://support.apple.com/en-in/guide/mac-help/mh32356/mac
 #
+# @swap-option-command: Swap the Option and Command keys so that their 

key
+# codes match their position on non-Mac keyboards
and
+# you can use Meta/Super and Alt where you expect
them.

qapi/ui.json +2 -0
+#                       (default: off)
+#

# Since: 6.1
##
{ 'struct' : 'DisplayCocoa',

qapi/ui.json line 1282

Quoted 3 lines
qapi/ui.json +2 -1
-  'data'    : { '*full-grab'     : 'bool' } }
+  'data'    : { '*full-grab'           : 'bool',
+                '*swap-option-command' : 'bool' } }

This option name is too long to type. Could we abbreviate it somehow?

Quoted 2 lines
Quoted 2 lines

We've largely avoided abbreviations in the QAPI schema, for better or worse.

There are already some abreviated options in this file and since users will need to use it to switch this on it's better to have something that can be typed without too much hassle and result in a command that still fits in a window...

Quoted 10 lines
Quoted 5 lines
Quoted 1 line

Like swap-opt-cmd or swap-alt-meta?

We should stick to how the keys are generally called on this platform. I can't say (I'm not using it).

The patch series is now in:
https://patchew.org/QEMU/[email protected]/

It uses swap-opt-cmd for the name. Please reply to the series if it is problematic.

The more common name for these keys on macOS is option and command although the opt key sometimes also has alt written on it and the code seems to use meta instead of command but I think swap-opt-cmd is simple and clear so unless it's mandatory to have very long options that's not practical for users I'd go with swap-opt-cmd (which is what's in the last patch from Philippe so it should be OK).

Regards,
BALATON Zoltan