From ded62153622a48f28c74be2d66bd0379e08e2759 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Mon, 1 Jun 2020 16:14:51 +0200 Subject: [PATCH] Accept Cmd for shortcuts on macOS For convenience (and to keep the existing behavior), also accept shortcuts using Cmd instead of RCtrl. --- README.md | 3 +++ app/src/input_manager.c | 17 +++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c88a1946..518d2084 100644 --- a/README.md +++ b/README.md @@ -560,6 +560,9 @@ Also see [issue #14]. `RCtrl` is the right `Ctrl` key (the left `Ctrl` key is forwarded to the device). +On macOS, `Cmd` also works (for shortcuts which are not already captured by the +system). + | Action | Shortcut | ------------------------------------------- |:----------------------------- | Switch fullscreen mode | `RCtrl`+`f` diff --git a/app/src/input_manager.c b/app/src/input_manager.c index 7aac33e8..81695b5f 100644 --- a/app/src/input_manager.c +++ b/app/src/input_manager.c @@ -254,9 +254,18 @@ input_manager_process_key(struct input_manager *im, bool meta = event->keysym.mod & (KMOD_LGUI | KMOD_RGUI); bool shift = event->keysym.mod & (KMOD_LSHIFT | KMOD_RSHIFT); - if (alt || meta) { - // No shortcuts involve Alt or Meta, and they are not forwarded to the - // device + bool shortcut_key = rctrl; +#ifdef __APPLE__ + shortcut_key |= meta; +#else + if (meta) { + // No shortcut involve Meta, and it is not forwarded to the device + return; + } +#endif + + if (alt) { + // No shortcuts involve Alt, and it is not forwarded to the device return; } @@ -266,7 +275,7 @@ input_manager_process_key(struct input_manager *im, bool down = event->type == SDL_KEYDOWN; // Capture all RCtrl events - if (rctrl) { + if (shortcut_key) { int action = down ? ACTION_DOWN : ACTION_UP; bool repeat = event->repeat; switch (keycode) {