Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simulate tilt multitouch event by pressing Shift #4529

Closed
wants to merge 1 commit into from

Conversation

tillrathmann
Copy link
Contributor

I missed simulating tilt multitouch events (two fingers moving up or down) for map apps.
Here is an implementation for that.

@rom1v
Copy link
Collaborator

rom1v commented Dec 13, 2023

Thank you. I like the idea.

However, Alt + mouse move is captured by my window manager (to move the window), so I can't use it.

Since there are 2 axis, we can use for example:

  • Ctrl to mirror the mouse horizontally (to slide vertically) (or the reverse)
  • Shift to mirror the mouse vertically (to slide horizontally) (or the reverse)
  • Ctrl+Shift to mirror in both directions (what already exists in the current version)

One drawback is that it causes a change in the shortcut for an existing action, but the result seems more logical to me.

What do you think?

@tillrathmann
Copy link
Contributor Author

Ah, good point.
Two more alternatives:

  • We could keep the current behavior for Ctrl and use Shift for mirroring horizontally (to slide vertically / tilt gesture). Mirroring only vertically could be dropped, as sliding horizontally with two fingers is no common gesture I think.
  • The same, but additionally provide Alt for this uncommon vertical only mirroring. If this is rarely used it is probably no big deal that it is not reachable if prevented by the window manager. But if someone really needs to use such a gesture it can be circumvented by temporarily switching to a different window manager or disabling the Alt + mouse move capturing.

So, what to do? Your proposal or one of these alternatives?

@rom1v
Copy link
Collaborator

rom1v commented Dec 14, 2023

We could keep the current behavior for Ctrl and use Shift for mirroring horizontally (to slide vertically / tilt gesture). Mirroring only vertically could be dropped, as sliding horizontally with two fingers is no common gesture I think.

I like this one 👍 Indeed I think that horizontal sliding with 2 fingers is not common.

If Ctrl+Shift are pressed, either:

  • do nothing (disable virtual finger)
  • only consider the first pressed when the click was pressed ("Ctrl then Shift" is the same Ctrl, "Shift then Ctrl" is the same Shift)

(choose the one with the simplest implementation)

EDIT: in fact, for simplicity and consistency with the current behavior, just consider the Ctrl or Shift key when the click is pressed, and keep its behavior until the click is released (even if the modifier is released/changed meanwhile).

(Ctrl+Shift could be reserved for the less common horizontal sliding for later if necessary, but not for now, let's keep it simple)

@tillrathmann tillrathmann changed the title Simulate tilt multitouch event by pressing Alt Simulate tilt multitouch event by pressing Shift Dec 14, 2023
@tillrathmann
Copy link
Contributor Author

Alright, let's do that!

@rom1v
Copy link
Collaborator

rom1v commented Dec 15, 2023

👌

I just reformulated a bit because technically it's an axial symmetry:

diff --git a/app/src/input_manager.c b/app/src/input_manager.c
index 13f5a4908..76cfbd928 100644
--- a/app/src/input_manager.c
+++ b/app/src/input_manager.c
@@ -745,9 +745,10 @@ 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 Shift can be used instead of Ctrl. The "virtual
-    // finger" has the x coordinate inverted through the center of the screen
-    // while the y coordinate is unchanged.
+    // To simulate a 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.
     const SDL_Keymod keymod = SDL_GetModState();
     const bool ctrl_pressed = keymod & KMOD_CTRL;
     const bool shift_pressed = keymod & KMOD_SHIFT;

(Please do not hesitate to suggest a reformulation if my English is incorrect.)

I also updated some more documentation:

diff --git a/app/scrcpy.1 b/app/scrcpy.1
index 8ca4a7730..beaa99ab4 100644
--- a/app/scrcpy.1
+++ b/app/scrcpy.1
@@ -642,7 +642,11 @@ Enable/disable FPS counter (print frames/second in logs)
 
 .TP
 .B Ctrl+click-and-move
-Pinch-to-zoom from the center of the screen
+Pinch-to-zoom and rotate from the center of the screen
+
+.TP
+.B Shift+click-and-move
+Tilt (slide vertically with two fingers)
 
 .TP
 .B Drag & drop APK file
diff --git a/app/src/cli.c b/app/src/cli.c
index fd4525f55..c580c9597 100644
--- a/app/src/cli.c
+++ b/app/src/cli.c
@@ -947,7 +947,11 @@ static const struct sc_shortcut shortcuts[] = {
     },
     {
         .shortcuts = { "Ctrl+click-and-move" },
-        .text = "Pinch-to-zoom from the center of the screen",
+        .text = "Pinch-to-zoom and rotate from the center of the screen",
+    },
+    {
+        .shortcuts = { "Shift+click-and-move" },
+        .text = "Tilt (slide vertically with two fingers)",
     },
     {
         .shortcuts = { "Drag & drop APK file" },
diff --git a/doc/shortcuts.md b/doc/shortcuts.md
index c0fc28421..21bccbd95 100644
--- a/doc/shortcuts.md
+++ b/doc/shortcuts.md
@@ -49,7 +49,8 @@ _<kbd>[Super]</kbd> is typically the <kbd>Windows</kbd> or <kbd>Cmd</kbd> key._
  | Synchronize clipboards and paste⁵           | <kbd>MOD</kbd>+<kbd>v</kbd>
  | Inject computer clipboard text              | <kbd>MOD</kbd>+<kbd>Shift</kbd>+<kbd>v</kbd>
  | Enable/disable FPS counter (on stdout)      | <kbd>MOD</kbd>+<kbd>i</kbd>
- | Pinch-to-zoom                               | <kbd>Ctrl</kbd>+_click-and-move_
+ | Pinch-to-zoom/rotate                        | <kbd>Ctrl</kbd>+_click-and-move_
+ | Tilt (slide vertically with 2 fingers)      | <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)
 

The resulting commit is here: d2ed451 (not merged yet)

rom1v pushed a commit that referenced this pull request Dec 15, 2023
PR #4529 <#4529>

Signed-off-by: Romain Vimont <rom@rom1v.com>
@tillrathmann
Copy link
Contributor Author

Looks fine! 👍

@rom1v
Copy link
Collaborator

rom1v commented Dec 16, 2023

Merged into dev 🚀

@rom1v rom1v closed this Dec 16, 2023
armm29393 added a commit to armm29393/scrcpy-root that referenced this pull request May 24, 2024
scrcpy v2.4

Changes since v2.3.1:
 - Add UHID keyboard and mouse support (Genymobile#4473)
 - Simulate tilt multitouch by pressing Shift (Genymobile#4529)
 - Add rotation support for non-default display (Genymobile#4698)
 - Improve audio player (Genymobile#4572)
 - Adapt to display API changes in Android 15 (Genymobile#4646, Genymobile#4656, Genymobile#4657)
 - Adapt audio workarounds to Android 14 (Genymobile#4492)
 - Fix clipboard for IQOO devices on Android 14 (Genymobile#4492, Genymobile#4589, Genymobile#4703)
 - Fix integer overflow for audio packet duration (Genymobile#4536)
 - Rework cleanup (Genymobile#4649)
 - Upgrade FFmpeg to 6.1.1 in Windows releases (Genymobile#4713)
 - Upgrade libusb to 1.0.27 in Windows releases (Genymobile#4713)
 - Various technical fixes
rom1v added a commit that referenced this pull request Sep 25, 2024
Use Ctrl+Shift for horizontal tilt.

Refs #4529 comment <#4529 (comment)>
Fixes #5317 <#5317>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants