Skip to content

Commit

Permalink
Add shortcut for horizontal tilt
Browse files Browse the repository at this point in the history
Use Ctrl+Shift for horizontal tilt.

Refs #4529 comment <#4529 (comment)>
Fixes #5317 <#5317>
  • Loading branch information
rom1v committed Sep 25, 2024
1 parent d92b7a6 commit 7a9ea5c
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 9 deletions.
6 changes: 5 additions & 1 deletion app/scrcpy.1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion app/src/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down
20 changes: 16 additions & 4 deletions app/src/input_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand Down
8 changes: 6 additions & 2 deletions doc/control.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: <kbd>Shift</kbd>+_click-and-move-up-or-down_.
To simulate a vertical tilt gesture: <kbd>Shift</kbd>+_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:
<kbd>Ctrl</kbd>+<kbd>Shift</kbd>+_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
<kbd>Ctrl</kbd> the _x_ and _y_ coordinates are inverted. Using <kbd>Shift</kbd>
only inverts _x_.
only inverts _x_, whereas using <kbd>Ctrl</kbd>+<kbd>Shift</kbd> only inverts
_y_.

This only works for the default mouse mode (`--mouse=sdk`).

Expand Down
3 changes: 2 additions & 1 deletion doc/shortcuts.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ _<kbd>[Super]</kbd> is typically the <kbd>Windows</kbd> or <kbd>Cmd</kbd> key._
| Open keyboard settings (HID keyboard only) | <kbd>MOD</kbd>+<kbd>k</kbd>
| Enable/disable FPS counter (on stdout) | <kbd>MOD</kbd>+<kbd>i</kbd>
| Pinch-to-zoom/rotate | <kbd>Ctrl</kbd>+_click-and-move_
| Tilt (slide vertically with 2 fingers) | <kbd>Shift</kbd>+_click-and-move_
| Tilt vertically (slide with 2 fingers) | <kbd>Shift</kbd>+_click-and-move_
| Tilt horizontally (slide with 2 fingers) | <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+_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)

Expand Down

0 comments on commit 7a9ea5c

Please sign in to comment.