All of lore.kernel.org
 help / color / mirror / Atom feed
From: Will Cohen <wwcohen@gmail.com>
To: "Philippe Mathieu-Daudé" <philippe.mathieu.daude@gmail.com>
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
	"Thomas Huth" <thuth@redhat.com>,
	qemu-block@nongnu.org, "Markus Armbruster" <armbru@redhat.com>,
	"Christian Schoenebeck" <qemu_oss@crudebyte.com>,
	"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
	"Cameron Esfahani" <dirty@apple.com>,
	"qemu Developers" <qemu-devel@nongnu.org>,
	"Roman Bolshakov" <r.bolshakov@yadro.com>,
	"Gerd Hoffmann" <kraxel@redhat.com>,
	"Akihiko Odaki" <akihiko.odaki@gmail.com>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Gustavo Noronha Silva" <gustavo@noronha.dev.br>
Subject: Re: [PATCH v7 21/22] ui/cocoa: add option to swap Option and Command
Date: Mon, 7 Mar 2022 12:00:13 -0500	[thread overview]
Message-ID: <CAB26zV0GoW4gSVV2Vc1UAO-T0AhJf1P-WPVizWv1xa=BVcSt8Q@mail.gmail.com> (raw)
In-Reply-To: <20220306231753.50277-22-philippe.mathieu.daude@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 6839 bytes --]

On Sun, Mar 6, 2022 at 6:19 PM Philippe Mathieu-Daudé <
philippe.mathieu.daude@gmail.com> wrote:

> From: Gustavo Noronha Silva <gustavo@noronha.dev.br>
>
> 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.
>
> Acked-by: Markus Armbruster <armbru@redhat.com>
> Signed-off-by: Gustavo Noronha Silva <gustavo@noronha.dev.br>
> Message-Id: <20210713213200.2547-3-gustavo@noronha.dev.br>
> Signed-off-by: Akihiko Odaki <akihiko.odaki@gmail.com>
> Message-Id: <20220306121119.45631-3-akihiko.odaki@gmail.com>
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
>  qapi/ui.json    |  7 ++++++-
>  qemu-options.hx |  2 +-
>  ui/cocoa.m      | 49 +++++++++++++++++++++++++++++++++++++++----------
>  3 files changed, 46 insertions(+), 12 deletions(-)
>
> diff --git a/qapi/ui.json b/qapi/ui.json
> index 1d60d5fc78..664da9e462 100644
> --- a/qapi/ui.json
> +++ b/qapi/ui.json
> @@ -1275,12 +1275,17 @@
>  #             a global grab on key events. (default: off)
>  #             See
> https://support.apple.com/en-in/guide/mac-help/mh32356/mac
>  #
> +# @swap-opt-cmd: 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: 7.0
>  ##
>  { 'struct': 'DisplayCocoa',
>    'data': {
>        '*left-command-key': 'bool',
> -      '*full-grab': 'bool'
> +      '*full-grab': 'bool',
> +      '*swap-opt-cmd': 'bool'
>    } }
>
>  ##
> diff --git a/qemu-options.hx b/qemu-options.hx
> index 2e6d54db4f..f443b0f33a 100644
> --- a/qemu-options.hx
> +++ b/qemu-options.hx
> @@ -1917,7 +1917,7 @@ 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][,swap-opt-cmd=on|off]\n"
>  #endif
>  #if defined(CONFIG_OPENGL)
>      "-display egl-headless[,rendernode=<file>]\n"
> diff --git a/ui/cocoa.m b/ui/cocoa.m
> index ca1cab1ae6..c0a948201d 100644
> --- a/ui/cocoa.m
> +++ b/ui/cocoa.m
> @@ -96,6 +96,7 @@ static DisplayChangeListener dcl = {
>  static int last_buttons;
>  static int cursor_hide = 1;
>  static int left_command_key_enabled = 1;
> +static bool swap_opt_cmd;
>
>  static int gArgc;
>  static char **gArgv;
> @@ -854,12 +855,22 @@ static CGEventRef handleTapEvent(CGEventTapProxy
> proxy, CGEventType type, CGEven
>          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 (swap_opt_cmd) {
> +            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 (swap_opt_cmd) {
> +            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]) {
> @@ -891,29 +902,44 @@ static CGEventRef handleTapEvent(CGEventTapProxy
> proxy, CGEventType type, CGEven
>
>                  case kVK_Option:
>                      if (!!(modifiers & NSEventModifierFlagOption)) {
> -                        [self toggleKey:Q_KEY_CODE_ALT];
> +                        if (swap_opt_cmd) {
> +                            [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 (swap_opt_cmd) {
> +                            [self toggleKey:Q_KEY_CODE_META_R];
> +                        } else {
> +                            [self toggleKey:Q_KEY_CODE_ALT_R];
> +                        }
>                      }
>                      break;
>
>                  /* Don't pass command key changes to guest unless mouse
> is grabbed */
>                  case kVK_Command:
>                      if (isMouseGrabbed &&
> -                        !!(modifiers & NSEventModifierFlagCommand) &&
> -                        left_command_key_enabled) {
> -                        [self toggleKey:Q_KEY_CODE_META_L];
> +                        !!(modifiers & NSEventModifierFlagCommand)) {
> +                        if (swap_opt_cmd) {
> +                            [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 (swap_opt_cmd) {
> +                            [self toggleKey:Q_KEY_CODE_ALT_R];
> +                        } else {
> +                            [self toggleKey:Q_KEY_CODE_META_R];
> +                        }
>                      }
>                      break;
>              }
> @@ -2134,6 +2160,9 @@ static void cocoa_display_init(DisplayState *ds,
> DisplayOptions *opts)
>      if (opts->has_show_cursor && opts->show_cursor) {
>          cursor_hide = 0;
>      }
> +    if (opts->u.cocoa.has_swap_opt_cmd) {
> +        swap_opt_cmd = opts->u.cocoa.swap_opt_cmd;
> +    }
>
>      if (opts->u.cocoa.has_left_command_key &&
> !opts->u.cocoa.left_command_key) {
>          left_command_key_enabled = 0;
> --
> 2.34.1
>
> Reviewed-by: Will Cohen <wwcohen@gmail.com>

[-- Attachment #2: Type: text/html, Size: 9125 bytes --]

  reply	other threads:[~2022-03-07 17:09 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-06 23:17 [PATCH v7 00/22] host: Support macOS 12 Philippe Mathieu-Daudé
2022-03-06 23:17 ` [PATCH v7 01/22] configure: Allow passing extra Objective C compiler flags Philippe Mathieu-Daudé
2022-03-06 23:17 ` [PATCH v7 02/22] tests/fp/berkeley-testfloat-3: Ignore ignored #pragma directives Philippe Mathieu-Daudé
2022-03-09 11:17   ` Alex Bennée
2022-03-06 23:17 ` [PATCH v7 03/22] hvf: Use standard CR0 and CR4 register definitions Philippe Mathieu-Daudé
2022-03-06 23:17 ` [PATCH v7 04/22] hvf: Make hvf_get_segments() / hvf_put_segments() local Philippe Mathieu-Daudé
2022-03-06 23:17 ` [PATCH v7 05/22] hvf: Remove deprecated hv_vcpu_flush() calls Philippe Mathieu-Daudé
2022-03-06 23:17 ` [PATCH v7 06/22] hvf: Fix OOB write in RDTSCP instruction decode Philippe Mathieu-Daudé
2022-03-09 10:20   ` Philippe Mathieu-Daudé
2022-03-15 12:58     ` Peter Maydell
2022-03-15 13:00       ` Philippe Mathieu-Daudé
2022-03-06 23:17 ` [PATCH v7 07/22] block/file-posix: Remove a deprecation warning on macOS 12 Philippe Mathieu-Daudé
2022-03-06 23:17 ` [PATCH v7 08/22] audio/coreaudio: " Philippe Mathieu-Daudé
2022-03-06 23:17 ` [PATCH v7 09/22] audio/dbus: Fix building with modules on macOS Philippe Mathieu-Daudé
2022-03-06 23:17 ` [PATCH v7 10/22] audio: Log context for audio bug Philippe Mathieu-Daudé
2022-03-06 23:17 ` [PATCH v7 11/22] coreaudio: Always return 0 in handle_voice_change Philippe Mathieu-Daudé
2022-03-06 23:17 ` [PATCH v7 12/22] audio: Rename coreaudio extension to use Objective-C compiler Philippe Mathieu-Daudé
2022-03-06 23:17 ` [PATCH v7 13/22] osdep: Avoid using Clang-specific __builtin_available() Philippe Mathieu-Daudé
2022-03-07  4:11   ` Akihiko Odaki
2022-03-06 23:17 ` [PATCH v7 14/22] meson: Resolve the entitlement.sh script once for good Philippe Mathieu-Daudé
2022-03-07  4:13   ` Akihiko Odaki
2022-03-06 23:17 ` [PATCH v7 15/22] meson: Log QEMU_CXXFLAGS content in summary Philippe Mathieu-Daudé
2022-03-07  4:13   ` Akihiko Odaki
2022-03-06 23:17 ` [PATCH v7 16/22] configure: Pass filtered QEMU_OBJCFLAGS to meson Philippe Mathieu-Daudé
2022-03-07  4:15   ` Akihiko Odaki
2022-03-06 23:17 ` [PATCH v7 17/22] ui/cocoa: Constify qkeycode translation arrays Philippe Mathieu-Daudé
2022-03-07  4:16   ` Akihiko Odaki
2022-03-06 23:17 ` [PATCH v7 18/22] ui/cocoa: add option to disable left-command forwarding to guest Philippe Mathieu-Daudé
2022-03-06 23:17 ` [PATCH v7 19/22] ui/cocoa: release mouse when user switches away from QEMU window Philippe Mathieu-Daudé
2022-03-06 23:17 ` [PATCH v7 20/22] ui/cocoa: capture all keys and combos when mouse is grabbed Philippe Mathieu-Daudé
2022-03-07 17:01   ` Will Cohen
2022-03-06 23:17 ` [PATCH v7 21/22] ui/cocoa: add option to swap Option and Command Philippe Mathieu-Daudé
2022-03-07 17:00   ` Will Cohen [this message]
2022-03-06 23:17 ` [PATCH v7 22/22] gitlab-ci: Support macOS 12 via cirrus-run Philippe Mathieu-Daudé
2022-03-09 10:24   ` Philippe Mathieu-Daudé
2022-03-09 11:58     ` Thomas Huth
2022-03-09 12:33       ` Daniel P. Berrangé
2022-03-09 12:50         ` Philippe Mathieu-Daudé
2022-03-09 12:52           ` Thomas Huth
2022-03-09 12:55             ` Daniel P. Berrangé
2022-03-09 13:02           ` Daniel P. Berrangé
2022-03-09 13:09             ` Peter Maydell
2022-03-09 13:40               ` Philippe Mathieu-Daudé
2022-03-09 10:28   ` Daniel P. Berrangé
2022-03-15 12:48 ` [PATCH v7 00/22] host: Support macOS 12 Philippe Mathieu-Daudé
2022-05-03  9:40 ` Claudio Fontana
2022-05-09 12:31   ` Philippe Mathieu-Daudé via
2022-05-09 13:08     ` Claudio Fontana

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAB26zV0GoW4gSVV2Vc1UAO-T0AhJf1P-WPVizWv1xa=BVcSt8Q@mail.gmail.com' \
    --to=wwcohen@gmail.com \
    --cc=akihiko.odaki@gmail.com \
    --cc=alex.bennee@linaro.org \
    --cc=armbru@redhat.com \
    --cc=dirty@apple.com \
    --cc=f4bug@amsat.org \
    --cc=gustavo@noronha.dev.br \
    --cc=kraxel@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=philippe.mathieu.daude@gmail.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu_oss@crudebyte.com \
    --cc=r.bolshakov@yadro.com \
    --cc=thuth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.