From 7a9ea5c66fedbb5b3b1d02f51695aa4ab259dfe3 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Wed, 25 Sep 2024 21:38:09 +0200 Subject: [PATCH] Add shortcut for horizontal tilt Use Ctrl+Shift for horizontal tilt. Refs #4529 comment Fixes #5317 --- app/scrcpy.1 | 6 +++++- app/src/cli.c | 6 +++++- app/src/input_manager.c | 20 ++++++++++++++++---- doc/control.md | 8 ++++++-- doc/shortcuts.md | 3 ++- 5 files changed, 34 insertions(+), 9 deletions(-) diff --git a/app/scrcpy.1 b/app/scrcpy.1 index a256c40e..3fd3eb29 100644 --- a/app/scrcpy.1 +++ b/app/scrcpy.1 @@ -727,7 +727,11 @@ Pinch-to-zoom and rotate from the center of the screen .TP .B Shift+click-and-move -Tilt (slide vertically with two fingers) +Tilt vertically (slide with 2 fingers) + +.TP +.B Ctrl+Shift+click-and-move +Tilt horizontally (slide with 2 fingers) .TP .B Drag & drop APK file diff --git a/app/src/cli.c b/app/src/cli.c index 3c1f9a1b..4fc3c534 100644 --- a/app/src/cli.c +++ b/app/src/cli.c @@ -1072,7 +1072,11 @@ static const struct sc_shortcut shortcuts[] = { }, { .shortcuts = { "Shift+click-and-move" }, - .text = "Tilt (slide vertically with two fingers)", + .text = "Tilt vertically (slide with 2 fingers)", + }, + { + .shortcuts = { "Ctrl+Shift+click-and-move" }, + .text = "Tilt horizontally (slide with 2 fingers)", }, { .shortcuts = { "Drag & drop APK file" }, diff --git a/app/src/input_manager.c b/app/src/input_manager.c index b1d7e9b9..444a5f16 100644 --- a/app/src/input_manager.c +++ b/app/src/input_manager.c @@ -836,7 +836,7 @@ sc_input_manager_process_mouse_button(struct sc_input_manager *im, } bool change_vfinger = event->button == SDL_BUTTON_LEFT && - ((down && !im->vfinger_down && (ctrl_pressed ^ shift_pressed)) || + ((down && !im->vfinger_down && (ctrl_pressed || shift_pressed)) || (!down && im->vfinger_down)); bool use_finger = im->vfinger_down || change_vfinger; @@ -868,16 +868,28 @@ sc_input_manager_process_mouse_button(struct sc_input_manager *im, // In other words, the center of the rotation/scaling is the center of the // screen. // - // To simulate a tilt gesture (a vertical slide with two fingers), Shift - // can be used instead of Ctrl. The "virtual finger" has a position + // To simulate a vertical tilt gesture (a vertical slide with two fingers), + // Shift can be used instead of Ctrl. The "virtual finger" has a position // inverted with respect to the vertical axis of symmetry in the middle of // the screen. + // + // To simulate a horizontal tilt gesture (a horizontal slide with two + // fingers), Ctrl+Shift can be used. The "virtual finger" has a position + // inverted with respect to the horizontal axis of symmetry in the middle + // of the screen. It is expected to be less frequently used, that's why the + // one-mod shortcuts are assigned to rotation and vertical tilt. if (change_vfinger) { struct sc_point mouse = sc_screen_convert_window_to_frame_coords(im->screen, event->x, event->y); if (down) { - im->vfinger_invert_x = ctrl_pressed || shift_pressed; + // Ctrl Shift invert_x invert_y + // ---- ----- ==> -------- -------- + // 0 0 0 0 - + // 0 1 1 0 vertical tilt + // 1 0 1 1 rotate + // 1 1 0 1 horizontal tilt + im->vfinger_invert_x = ctrl_pressed ^ shift_pressed; im->vfinger_invert_y = ctrl_pressed; } struct sc_point vfinger = inverse_point(mouse, im->screen->frame_size, diff --git a/doc/control.md b/doc/control.md index 34eb7a6a..26805346 100644 --- a/doc/control.md +++ b/doc/control.md @@ -94,14 +94,18 @@ the content (if supported by the app) relative to the center of the screen. https://github.com/Genymobile/scrcpy/assets/543275/26c4a920-9805-43f1-8d4c-608752d04767 -To simulate a tilt gesture: Shift+_click-and-move-up-or-down_. +To simulate a vertical tilt gesture: Shift+_click-and-move-up-or-down_. https://github.com/Genymobile/scrcpy/assets/543275/1e252341-4a90-4b29-9d11-9153b324669f +Similarly, to simulate a horizontal tilt gesture: +Ctrl+Shift+_click-and-move-left-or-right_. + Technically, _scrcpy_ generates additional touch events from a "virtual finger" at a location inverted through the center of the screen. When pressing Ctrl the _x_ and _y_ coordinates are inverted. Using Shift -only inverts _x_. +only inverts _x_, whereas using Ctrl+Shift only inverts +_y_. This only works for the default mouse mode (`--mouse=sdk`). diff --git a/doc/shortcuts.md b/doc/shortcuts.md index 841ceaa6..4ea37257 100644 --- a/doc/shortcuts.md +++ b/doc/shortcuts.md @@ -53,7 +53,8 @@ _[Super] is typically the Windows or Cmd key._ | Open keyboard settings (HID keyboard only) | MOD+k | Enable/disable FPS counter (on stdout) | MOD+i | Pinch-to-zoom/rotate | Ctrl+_click-and-move_ - | Tilt (slide vertically with 2 fingers) | Shift+_click-and-move_ + | Tilt vertically (slide with 2 fingers) | Shift+_click-and-move_ + | Tilt horizontally (slide with 2 fingers) | Ctrl+Shift+_click-and-move_ | Drag & drop APK file | Install APK from computer | Drag & drop non-APK file | [Push file to device](control.md#push-file-to-device)