Skip to content

Commit

Permalink
Synchronize clipboard on Ctrl+v
Browse files Browse the repository at this point in the history
Pressing Ctrl+v on the device will typically paste the clipboard
content.

Before sending the key event, synchronize the computer clipboard to the
device clipboard to allow seamless copy-paste.
  • Loading branch information
rom1v committed Aug 1, 2020
1 parent d4ca85d commit 7683be8
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions app/src/input_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,13 +326,15 @@ input_manager_process_key(struct input_manager *im,

struct controller *controller = im->controller;

SDL_Keycode keycode = event->keysym.sym;
bool down = event->type == SDL_KEYDOWN;
bool ctrl = event->keysym.mod & KMOD_CTRL;
bool shift = event->keysym.mod & KMOD_SHIFT;
bool repeat = event->repeat;

// The shortcut modifier is pressed
if (smod) {
SDL_Keycode keycode = event->keysym.sym;
bool down = event->type == SDL_KEYDOWN;
int action = down ? ACTION_DOWN : ACTION_UP;
bool repeat = event->repeat;
bool shift = event->keysym.mod & (KMOD_LSHIFT | KMOD_RSHIFT);
switch (keycode) {
case SDLK_h:
if (control && !shift && !repeat) {
Expand Down Expand Up @@ -457,6 +459,12 @@ input_manager_process_key(struct input_manager *im,
im->repeat = 0;
}

if (ctrl && !shift && keycode == SDLK_v && down && !repeat) {
// Synchronize the computer clipboard to the device clipboard before
// sending Ctrl+v, to allow seamless copy-paste.
set_device_clipboard(controller, false);
}

struct control_msg msg;
if (convert_input_key(event, &msg, im->prefer_text, im->repeat)) {
if (!controller_push_msg(controller, &msg)) {
Expand Down

0 comments on commit 7683be8

Please sign in to comment.