From ddb36e343652264db4599bf186498c30657e79a4 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Mon, 1 Jun 2020 16:46:46 +0200 Subject: [PATCH] Forward copy-cut shortcuts For convenience, forward RCtrl+c (or Cmd+c) and and RCtrl+x (or Cmd+x) as LCtrl+c and LCtrl+x to the device. This allows to use the "natural" keys for copy-paste (especially on macOS). --- app/src/input_manager.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/app/src/input_manager.c b/app/src/input_manager.c index ed840604..3e932a59 100644 --- a/app/src/input_manager.c +++ b/app/src/input_manager.c @@ -242,6 +242,25 @@ convert_input_key(const SDL_KeyboardEvent *from, struct control_msg *to, return true; } +static void +inject_as_ctrl(struct input_manager *im, const SDL_KeyboardEvent *event) { + struct control_msg msg; + + if (!convert_input_key(event, &msg, false)) { + return; + } + + // Disable RCtrl and Meta + msg.inject_keycode.metastate &= + ~(AMETA_CTRL_RIGHT_ON | AMETA_META_LEFT_ON | AMETA_META_RIGHT_ON); + // Enable LCtrl + msg.inject_keycode.metastate |= AMETA_CTRL_LEFT_ON; + + if (!controller_push_msg(im->controller, &msg)) { + LOGW("Could not request 'inject keycode'"); + } +} + void input_manager_process_key(struct input_manager *im, const SDL_KeyboardEvent *event, @@ -382,6 +401,15 @@ input_manager_process_key(struct input_manager *im, rotate_device(controller); } return; + case SDLK_c: + case SDLK_x: + if (control && !shift) { + // For convenience, forward shortcut_key+c and + // shortcut_key+x as Ctrl+c and Ctrl+x (typically "copy" and + // "cut", but not always) to the device + inject_as_ctrl(im, event); + } + return; } return;