-
-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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
mouse right click ACTION_UP is lost #3568
Comments
Thank you for your detailed bug report.
Then the problem is here: scrcpy/server/src/main/java/com/genymobile/scrcpy/Controller.java Lines 212 to 214 in 48bb6f2
The input source must be a touchscreen unless a non-primary button is pressed (see f70359f, unfortunately, poor commit messages with a typo and no details). But your report adds an additional constraint: an action_up must be sent with the same source as the matching action_down (which makes sense). However, the fix is not trivial. For example consider the following sequence of events:
I will think about it. If you have any suggestion, don't hesitate :) |
This looks like workaround for devices which have problem with a mouse in general.
I have checked events for a real finger touch with 2 fingers and compared to 2 button mouse (coincidentally exactly what your example is). I believe simulating touches with a mouse is compatible only for a single button/finger. It is broken when more keys/fingers are involved. For multi finger, events contain multiple touch points. For the mouse, events always contain single touch with multiple keys. How about a verbatim mouse mode, where events injected by scrcpy are as close as possible to what can be observed with physical mouse? How about I hack something together and do a PR for review? |
Maybe, but I would like not to break them again. It might also impact only some apps (I don't remember).
(I would like to keep a common behavior between multi-touch and single click.)
Here are the possible alternatives I considered since yesterday.
I think my current preference is 4. What do you think? |
Option 4 makes sense. I was trying to be conservative and avoid changes in the way things work today. However, I would like to go one step further and also add the ACTION_BUTTON_PRESS, ACTION_BUTTON_RELEASE and ACTION_HOOVER_MOVE. Lines 61 to 64 in 72ba913
Any particular reason? |
I don't know when it is necessary (when
It represents maybe 99% of event generation (it floods the device), and hover alone typically does nothing. Also, I don't necessarily want to inject events on the device just because my mouse is over the scrcpy window on the computer. |
This is the capture with a physical mouse for: left-down, right-down, left-up, right-up
The first and last hoover is to show there was no motion before and after. You are absolutely right, there is no reason to implement them. and the genericMotionEvents: As far as I can tell, aFreeRDP is not using the genericMotionEvents at the moment neither handle properly touchEvents sequence as above. |
Thank you for the details. So IIUC, there is currently no practical reason to implement
Would you like to implement option 4 and submit a PR? Thank you |
yes, but ... I will create a separate issue for it when it comes
yes |
How important is simulated zoom (ctrl-click) when in forward-all-clicks mode? |
When in forward-all-clicks mode: - mouse events source set to mouse - motion event toolType set to mouse - disabled pinch-to-zoom When not in forward-all-clicks: - left click mouse event simulates first finger - pinch-to-zoom uses second finger
Good question, ideally it should still work, but I understand this is a problem with solution (4) 😞 |
I implemented it trying to mimic hardware mouse, so the events have source set to SOURCE_MOUSE and tool type set to TOOL_TYPE_MOUSE. In this configuration I have not found a way to simulate pinch. Tried 2 virtual fingers. But I have to cancel mouse events. |
The ACTION_UP is delivered for middle and right button, but since the combination of TOOL_TYPE_FINGER and SOURCE_MOUSE is not something you can generate with a hardware the correct interpretation of the events in the actual app depends on how relaxed is the app event handling.
So, if I mix TOOL_TYPE_FINGER and source SOURCE_MOUSE which was the original hack, the results are application dependent. This combination is not a valid combination observed on the device, so it is a best effort. I have another idea, what if we modify pinch-to-zoom emulator logic. |
Right click and middle click require the source device to be a mouse, not a touchscreen). Therefore, the source device was changed only when a button other than the primary button was pressed (see adc547f). However, this led to inconsistencies between the ACTION_DOWN when a secondary button is pressed (with a mouse as source device) and the matching ACTION_UP when the secondary button is released (with a touchscreen as source device, because then there is no button pressed). To avoid the problem in all cases, force a mouse as source device when --forward-all-clicks is set. As a consequence, pinch-to-zoom using a virtual finger is disabled in this case. Concretely, in --forward-all-clicks mode: - device source is set to InputDevice.SOURCE_MOUSE; - motion event toolType is set to MotionEvent.TOOL_TYPE_MOUSE; - pinch-to-zoom simulation is disabled. Otherwise: - left-click mouse event simulates a first virtual finger; - pinch-to-zoom simulation uses a second virtual finger. For all (virtual or not) finger events: - device source is set to InputDevice.SOURCE_TOUCHSCREEN; - motion event toolType is set to MotionEvent.TOOL_TYPE_FINGER. Fixes #3568 <#3568> Signed-off-by: Romain Vimont <rom@rom1v.com> TODO: - test that nothing is broken on a computer with a touchscreen, both with and without --forward-all-clicks
Hi, Thank you for your work. I reviewed your 2 proposals: (2) is the most straightforward, but (1) LGTM. I made minor changes, in particular I moved the I opened a PR: #3579 Please review and test 😉
How does the "mouse event get canceled"? If this implies to inject an |
testing right now
I am guilty of doing experiments with physical mouse and not documenting. Let's fix it. The experiment:
And here are the events captured by the app, the finger motion events and generic motion events removed.
The interesting part, when finger touches, the old mouse click event get ACTION_CANCEL even when the mouse has its button down.
Based on the above logic, it will not have mouse click effect. I will try it when I have a moment. |
In fact, the virtual finger may also be a mouse. Here is a diff to test against current diff --git a/server/src/main/java/com/genymobile/scrcpy/Controller.java b/server/src/main/java/com/genymobile/scrcpy/Controller.java
index 95b64711..b9f193c1 100644
--- a/server/src/main/java/com/genymobile/scrcpy/Controller.java
+++ b/server/src/main/java/com/genymobile/scrcpy/Controller.java
@@ -45,7 +45,7 @@ public class Controller {
private void initPointers() {
for (int i = 0; i < PointersState.MAX_POINTERS; ++i) {
MotionEvent.PointerProperties props = new MotionEvent.PointerProperties();
- props.toolType = MotionEvent.TOOL_TYPE_FINGER;
+ props.toolType = MotionEvent.TOOL_TYPE_MOUSE;
MotionEvent.PointerCoords coords = new MotionEvent.PointerCoords();
coords.orientation = 0;
@@ -210,12 +210,7 @@ public class Controller {
}
// Right-click and middle-click only work if the source is a mouse
- boolean nonPrimaryButtonPressed = (buttons & ~MotionEvent.BUTTON_PRIMARY) != 0;
- int source = nonPrimaryButtonPressed ? InputDevice.SOURCE_MOUSE : InputDevice.SOURCE_TOUCHSCREEN;
- if (source != InputDevice.SOURCE_MOUSE) {
- // Buttons must not be set for touch events
- buttons = 0;
- }
+ int source = InputDevice.SOURCE_MOUSE;
MotionEvent event = MotionEvent
.obtain(lastTouchDown, now, action, pointerCount, pointerProperties, pointerCoords, 0, buttons, 1f, 1f, DEFAULT_DEVICE_ID, 0, source, |
Right click and middle click require the source device to be a mouse, not a touchscreen). Therefore, the source device was changed only when a button other than the primary button was pressed (see adc547f). However, this led to inconsistencies between the ACTION_DOWN when a secondary button is pressed (with a mouse as source device) and the matching ACTION_UP when the secondary button is released (with a touchscreen as source device, because then there is no button pressed). To avoid the problem in all cases, force a mouse as source device when --forward-all-clicks is set. Concretely, in --forward-all-clicks mode: - device source is set to InputDevice.SOURCE_MOUSE; - motion event toolType is set to MotionEvent.TOOL_TYPE_MOUSE; For all (virtual or not) finger events: - device source is set to InputDevice.SOURCE_TOUCHSCREEN; - motion event toolType is set to MotionEvent.TOOL_TYPE_FINGER. Fixes #3568 <#3568> Signed-off-by: Romain Vimont <rom@rom1v.com> TODO: - test that nothing is broken on a computer with a touchscreen, both with and without --forward-all-clicks
I recall inconsistent behavior. Not all applications worked. |
With which commit? With 2 "virtual" mice? |
yes, but I didn't use your code, it was one of the experiments I did on my own. |
OK. When you have some time, could you please review and test this new version? (#3579) |
Right click and middle click require the source device to be a mouse, not a touchscreen. Therefore, the source device was changed only when a button other than the primary button was pressed (see adc547f). However, this led to inconsistencies between the ACTION_DOWN when a secondary button is pressed (with a mouse as source device) and the matching ACTION_UP when the secondary button is released (with a touchscreen as source device, because then there is no button pressed). To avoid the problem in all cases, force a mouse as source device when --forward-all-clicks is set. Concretely, for mouse events in --forward-all-clicks mode: - device source is set to InputDevice.SOURCE_MOUSE; - motion event toolType is set to MotionEvent.TOOL_TYPE_MOUSE; Otherwise (when --forward-all-clicks is unset, or on real touch events), finger events are injected: - device source is set to InputDevice.SOURCE_TOUCHSCREEN; - motion event toolType is set to MotionEvent.TOOL_TYPE_FINGER. Fixes #3568 <#3568> Signed-off-by: Romain Vimont <rom@rom1v.com>
Existing issues:
#2711, similar to my experience with right-click
#3070, related, if this is implemented right, the hoover events can be delivered
Environment
google pixel 6 pro, grapheneOS (android13)
asus nexus7, android 6
samsung SM-T510, android 11
Primary work on pixel, other devices used to make sure problem is not os/device specific
Describe the bug
When using scrcpy with aFreeRDP, the right and middle mouse button don't work as expected.
I don't use the hid (AOA). In case of pixel, mouse pointer appears on the primary display. In case of samsung tab, it shows up on the extra display. I have not found a way to control it.
Investigation
Initially I assumed that the problem is in the aFreeRDP and started by dumping all motion events delivered to dispatchTouchEvent and dispatchGenericMotionEvent.
The first impression: ACTION_UP is missing for right and middle click. The event is not delivered. But perhaps it is the app itself.
So, I took a physical mouse and captured events. Than captured events when delivered from scrcpy.
Right click events from physical mouse as seen by the application, the attributes which are always the same are in const section.
Right click events when delivered from scrcpy, the attributes which are always the same are in const section.
In addition log contains scrcpy events just before injection point (Controller.java, injectTouch)
The highlights are:
When I hard-code source to 0x2002 in injectTouch, the ACTION_UP is delivered to the application.
But this is just to prove why android is swallowing the event.
The text was updated successfully, but these errors were encountered: