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

Samsung Browser doesn't do anything on touch inputs (left click) #2169

Closed
axsb opened this issue Mar 5, 2021 · 14 comments
Closed

Samsung Browser doesn't do anything on touch inputs (left click) #2169

axsb opened this issue Mar 5, 2021 · 14 comments

Comments

@axsb
Copy link

axsb commented Mar 5, 2021

Environment

  • OS: opensuse leap 15.2
  • scrcpy version: 1.17
  • installation method: manual build
  • device model: Samsung S20 SM-G980
  • Android version: 11

Describe the bug
Samsung Browser (Samsung Internet 13.2.2.4) doesn't do anything on touch inputs (left click) on the website rendered area. Scroll wheel works however, the UI elements are responsive to left clicks as well. No problems on chrome browser.
It worked in the past. I can't remember if a new version of scrcpy or samsung internet introduced this bug.

logcat output while trying to do inputs with left mouse click:
03-05 10:31:57.323 3329 3354 I chromium: [INFO:web_view_impl.cc(2030)] SBRTOUCHLOG Blink HandleInputEvent event received = MouseMove

@rom1v
Copy link
Collaborator

rom1v commented Mar 5, 2021

It worked in the past. I can't remember if a new version of scrcpy or samsung internet introduced this bug.

Could you please test older scrcpy version? (or even git bisect, if you know how to)
This will help to find the cause.

@axsb
Copy link
Author

axsb commented Mar 5, 2021

didn't know about git bisect, but it was fun learning it.
that's the result

17d53be

17d53be3ef9d376e48a7f9e90cf6c87cf8fbf8f5 is the first bad commit
commit 17d53be3ef9d376e48a7f9e90cf6c87cf8fbf8f5
Author: Romain Vimont <[email protected]>
Date:   Fri Oct 25 11:06:30 2019 +0200

    Fix mouse events conversion
    
    The conversion from SDL mouse state to Android mouse state used wrong
    constants as mask.
    
    Fixes <https://github.com/Genymobile/scrcpy/issues/635>

 app/src/event_converter.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

I did a revert of this commit on the latest tag, and it solves the issue (for me at least)

@rom1v
Copy link
Collaborator

rom1v commented Mar 5, 2021

Oh, thank you very much for the bisect 👍

diff --git a/app/src/event_converter.c b/app/src/event_converter.c
index ab48898d..7bc56ed4 100644
--- a/app/src/event_converter.c
+++ b/app/src/event_converter.c
@@ -1,6 +1,7 @@
 #include "event_converter.h"
 
 #include "config.h"
+#include "util/log.h"
 
 #define MAP(FROM, TO) case FROM: *to = TO; return true
 #define FAIL default: return false
@@ -174,6 +175,7 @@ convert_mouse_buttons(uint32_t state) {
     if (state & SDL_BUTTON_X2MASK) {
         buttons |= AMOTION_EVENT_BUTTON_FORWARD;
     }
+    LOGI("buttons = %x\n", buttons);
     return buttons;
 }
 
diff --git a/server/src/main/java/com/genymobile/scrcpy/Controller.java b/server/src/main/java/com/genymobile/scrcpy/Controller.java
index 84780239..c70eebaf 100644
--- a/server/src/main/java/com/genymobile/scrcpy/Controller.java
+++ b/server/src/main/java/com/genymobile/scrcpy/Controller.java
@@ -172,6 +172,7 @@ public class Controller {
     }
 
     private boolean injectTouch(int action, long pointerId, Position position, float pressure, int buttons) {
+        Ln.i("buttons = " + Integer.toHexString(buttons));
         long now = SystemClock.uptimeMillis();
 
         Point point = device.getPhysicalPoint(position);

Could you please add some logs? (on current master)

Then, when you click, it should print these logs in the console.

@axsb
Copy link
Author

axsb commented Mar 5, 2021

INFO: scrcpy 1.17 https://github.com/Genymobile/scrcpy
DEBUG: Using SCRCPY_SERVER_PATH: x/server/scrcpy-server
x/server/scrcpy-server: 1 file pushed. 8.8 MB/s (35030 bytes in 0.004s)
DEBUG: Screensaver enabled
[server] INFO: Device: samsung SM-G980F (Android 11)
DEBUG: Starting stream thread
DEBUG: Starting controller thread
DEBUG: Starting receiver thread
[server] DEBUG: Using encoder: 'OMX.Exynos.AVC.Encoder'
INFO: Renderer: opengl
INFO: OpenGL version: 4.6.0 NVIDIA 460.32.03
INFO: Trilinear filtering enabled
INFO: Initial texture: 1080x2400
INFO: buttons = 1
[server] INFO: buttons = 1
INFO: buttons = 1
INFO: buttons = 1
[server] INFO: buttons = 1
[server] INFO: buttons = 1
INFO: buttons = 1
[server] INFO: buttons = 1
INFO: buttons = 1
[server] INFO: buttons = 1
INFO: buttons = 1
[server] INFO: buttons = 1
INFO: buttons = 1
INFO: buttons = 1
[server] INFO: buttons = 1
[server] INFO: buttons = 1
INFO: buttons = 1
[server] INFO: buttons = 1

...

logcat output for touch events in samsung browser
3-05 14:45:12.913 8388 8405 I scrcpy : buttons = 1
03-05 14:45:12.923 8388 8405 I scrcpy : buttons = 1
03-05 14:45:12.925 3329 3354 I chromium: [INFO:web_view_impl.cc(2030)] SBRTOUCHLOG Blink HandleInputEvent event received = MouseMove
03-05 14:45:12.925 8388 8405 I scrcpy : buttons = 1
03-05 14:45:12.943 3329 3354 I chromium: [INFO:web_view_impl.cc(2030)] SBRTOUCHLOG Blink HandleInputEvent event received = MouseMove
03-05 14:45:12.964 8388 8405 I scrcpy : buttons = 1
03-05 14:45:12.975 8388 8405 I scrcpy : buttons = 1
03-05 14:45:12.976 8388 8405 I scrcpy : buttons = 1
03-05 14:45:12.985 8388 8405 I scrcpy : buttons = 1
03-05 14:45:12.991 3329 3354 I chromium: [INFO:web_view_impl.cc(2030)] SBRTOUCHLOG Blink HandleInputEvent event received = MouseMove
03-05 14:45:12.995 8388 8405 I scrcpy : buttons = 1
03-05 14:45:13.005 8388 8405 I scrcpy : buttons = 1
03-05 14:45:13.009 3329 3354 I chromium: [INFO:web_view_impl.cc(2030)] SBRTOUCHLOG Blink HandleInputEvent event received = MouseMove

for comparison, that's a logcat from chrome browser
03-05 14:46:57.929 8388 8405 I scrcpy : buttons = 1
03-05 14:46:57.930 31297 32021 D InputDispatcher: Inject motion (8388): action=0x0, time=283590479000000, f=0x0, d=0
03-05 14:46:57.930 8388 8405 I scrcpy : buttons = 1
03-05 14:46:57.931 31297 31482 I InputDispatcher: Delivering touch to (31656): action: 0x4, f=0x0, d=0, '17c101d', t=1
03-05 14:46:57.931 31297 31482 I InputDispatcher: Delivering touch to (28143): action: 0x0, f=0x2, d=0, 'e2823bf', t=1
03-05 14:46:57.931 28143 28143 I ViewRootImpl@f36a589[Main]: ViewPostIme pointer 0
03-05 14:46:57.939 8388 8405 I scrcpy : buttons = 1
03-05 14:46:57.949 8388 8405 I scrcpy : buttons = 1
03-05 14:46:57.951 31144 9884 I HYPER-HAL: [ResourceManager.cpp]removeResource(): [CPUMinFreq] RemoveResource Request ID : 490800148
03-05 14:46:57.951 31144 9884 I HYPER-HAL: [RequestManager.cpp]releaseLocked(): Released ID : 490800148
03-05 14:46:57.959 8388 8405 I scrcpy : buttons = 1
03-05 14:46:57.970 8388 8405 I scrcpy : buttons = 1
03-05 14:46:57.971 8388 8405 I scrcpy : buttons = 1
03-05 14:46:57.975 9427 9451 I id.app.contact: Waiting for a blocking GC ProfileSaver
03-05 14:46:57.978 785 1715 D NativeSemDvfsManager: acquire:: timeout = 1000 mIsAcquired = 1 mTagName : SurfaceFlinger
03-05 14:46:57.978 785 1715 E NativeCustomFrequencyManager: [NativeCFMS] BpCustomFrequencyManager::acquire()
03-05 14:46:57.979 31144 31180 I HYPER-HAL: [RequestManager.cpp]acquire(): Acquired ID : 1596792 [785 / 1001] HINT : list : [GPUMinFreq / 377000] [TIMEOUT / 1000]
03-05 14:46:57.980 8388 8405 I scrcpy : buttons = 1
03-05 14:46:57.990 8388 8405 I scrcpy : buttons = 1
03-05 14:46:58.003 8388 8405 I scrcpy : buttons = 1
03-05 14:46:58.004 8388 8405 I scrcpy : buttons = 1
03-05 14:46:58.010 938 9966 I EPIC : PROPERTY : persist.vendor.sys.camera.preview, Value : 0
03-05 14:46:58.014 8388 8405 I scrcpy : buttons = 1
03-05 14:46:58.024 8388 8405 I scrcpy : buttons = 1
03-05 14:46:58.030 938 9887 I EPIC : PROPERTY : persist.vendor.sys.camera.preview, Value : 0

and finally with the revert of 17d53be (samsung browser)
03-05 14:58:21.664 13907 13923 I scrcpy : buttons = 11
03-05 14:58:21.665 31297 31318 D InputDispatcher: Inject motion (13907): action=0x0, time=284274214000000, f=0x0, d=0
03-05 14:58:21.666 31297 31482 I InputDispatcher: Delivering touch to (31656): action: 0x4, f=0x0, d=0, '17c101d', t=1
03-05 14:58:21.666 14382 14382 I ViewRootImpl@bfc4dc2[SBrowserMainActivity]: ViewPostIme pointer 0
03-05 14:58:21.667 31297 31482 I InputDispatcher: Delivering touch to (14382): action: 0x0, f=0x2, d=0, '8fd012e', t=1
03-05 14:58:21.668 31297 31482 D PowerManagerService: UserActivityStateListenerState: 1
03-05 14:58:21.668 14382 14382 W chromium: [WARNING:render_widget_host_view_android.cc(873)] SBRTOUCHLOG OnTouchEvent, Action::DOWN
03-05 14:58:21.668 14382 14382 I chromium: [INFO:render_widget_host_input_event_router.cc(836)] SBRTOUCHLOG Set Touch sequence target view: 0xdb0b1490
03-05 14:58:21.668 14382 14382 W chromium: [WARNING:input_router_impl.cc(571)] SBRTOUCHLOG FilterAndSendWebInputEvent, kTouchStart
03-05 14:58:21.669 3329 3362 I chromium: [INFO:input_handler_proxy.cc(1109)] SBRTOUCHLOG : TouchStart
03-05 14:58:21.669 3329 3354 I chromium: [INFO:web_view_impl.cc(2030)] SBRTOUCHLOG Blink HandleInputEvent event received = PointerDown
03-05 14:58:21.671 3329 3354 I chromium: [INFO:web_view_impl.cc(2030)] SBRTOUCHLOG Blink HandleInputEvent event received = GestureTapDown
03-05 14:58:21.684 13907 13923 I scrcpy : buttons = 11
03-05 14:58:21.694 13907 13923 I scrcpy : buttons = 11
03-05 14:58:21.695 13907 13923 I scrcpy : buttons = 11
03-05 14:58:21.704 13907 13923 I scrcpy : buttons = 11
03-05 14:58:21.714 13907 13923 I scrcpy : buttons = 11
03-05 14:58:21.724 13907 13923 I scrcpy : buttons = 11
03-05 14:58:21.735 13907 13923 I scrcpy : buttons = 11
03-05 14:58:21.737 13907 13923 I scrcpy : buttons = 11
03-05 14:58:21.739 3329 3362 I chromium: [INFO:layer_tree_host_impl.cc(3950)] SBRTOUCHLOG LayerTreeHostImpl::ScrollBegin defer_commit = 0
03-05 14:58:21.740 3329 3362 I chromium: [INFO:input_handler_proxy.cc(933)] SBRTOUCHLOG HandleGestureScrollBegin result = 0
03-05 14:58:21.740 3329 3354 I chromium: [INFO:web_view_impl.cc(2030)] SBRTOUCHLOG Blink HandleInputEvent event received = Gestur

@rom1v
Copy link
Collaborator

rom1v commented Mar 5, 2021

scrcpy : buttons = 11

(0x11) so clicks are working only if you indicate that AMOTION_EVENT_BUTTON_FORWARD (0x10) is down (in addition to AMOTION_EVENT_BUTTON_PRIMARY (0x01)).

This looks like a bug in the browser.

Could you also apply this change: #2125 (comment)

@axsb
Copy link
Author

axsb commented Mar 5, 2021

ok, I did the change. It doesn't help with the issue.

whit 17d53be
03-05 15:15:32.269 16682 16700 I scrcpy : buttons = 1
03-05 15:15:32.270 31297 1448 D InputDispatcher: Inject motion (16682): action=0x0, time=285304819000000, f=0x0, d=0
03-05 15:15:32.271 31297 31482 I InputDispatcher: Delivering touch to (31656): action: 0x4, f=0x0, d=0, '17c101d', t=1
03-05 15:15:32.272 31297 31482 I InputDispatcher: Delivering touch to (14382): action: 0x0, f=0x2, d=0, '8fd012e', t=1
03-05 15:15:32.271 14382 14382 I ViewRootImpl@bfc4dc2[SBrowserMainActivity]: ViewPostIme pointer 0
03-05 15:15:32.272 31297 31482 D PowerManagerService: UserActivityStateListenerState: 1
03-05 15:15:32.320 16682 16700 I scrcpy : buttons = 1
03-05 15:15:32.330 16682 16700 I scrcpy : buttons = 1
03-05 15:15:32.340 16682 16700 I scrcpy : buttons = 1
03-05 15:15:32.350 3329 3354 I chromium: [INFO:web_view_impl.cc(2030)] SBRTOUCHLOG Blink HandleInputEvent event received = MouseMove
03-05 15:15:32.350 16682 16700 I scrcpy : buttons = 1
03-05 15:15:32.361 16682 16700 I scrcpy : buttons = 1
03-05 15:15:32.362 31114 21417 E power : ISystemSuspend::getService() failed.
03-05 15:15:32.362 32089 16008 I RILClient: processUnsolicited(): resp_id (11090), len(420)
03-05 15:15:32.363 31297 31368 D BatteryExternalStatsWorker: ModemActivityEnergyInfo was updated
03-05 15:15:32.367 16682 16700 I scrcpy : buttons = 1
03-05 15:15:32.367 31297 31368 D BatteryExternalStatsWorker: updateKernelWakelocksLocked was updated
03-05 15:15:32.367 3329 3354 I chromium: [INFO:web_view_impl.cc(2030)] SBRTOUCHLOG Blink HandleInputEvent event received = MouseMove
03-05 15:15:32.367 31297 31368 D BatteryExternalStatsWorker: updateKernelMemoryBandwidthLocked was updated
03-05 15:15:32.368 31632 31813 I System.out: Broadcasting: Intent { act=com.samsung.intent.action.BIG_DATA_INFO (has extras) }
03-05 15:15:32.369 31297 31368 D BatteryExternalStatsWorker: done updateExternalStatsLocked
03-05 15:15:32.370 16682 16700 I scrcpy : buttons = 1
03-05 15:15:32.370 31632 31632 D SemBigDataInfoController: Intent : com.samsung.intent.action.BIG_DATA_INFO
03-05 15:15:32.370 31632 31632 D SemBigDataInfoController: BIG_DATA insertLog slot : 0 feature : 26
03-05 15:15:32.370 31632 31632 D SemBigDataInfoController: feature : CMAI, extra : {"JVER":"SSB2","SLP_TM":"5002","IDL_TM":"2687","NR_TX0_TM":"0","NR_TX1_TM":"0","NR_TX2_TM":"0","NR_TX3_TM":"0","NR_TX4_TM":"0","NR_RX_TM":"0","NR_TX_BYTE":"0","NR_RX_BYTE":"0","LC_TX0_TM":"0","LC_TX1_TM":"0","LC_TX2_TM":"0","LC_TX3_TM":"79","LC_TX4_TM":"239","LC_RX_TM":"4659","LC_TX_BYTE":"193","LC_RX_BYTE":"187"}
03-05 15:15:32.371 31297 1962 D BatteryStatsImpl: SemModemActivityInfo{ SleepTimeMs=5002 IdleTimeMs=2687 mNr=MobileActivity{ txTimeMs[]=[0, 0, 0, 0, 0] rxTimeMs=0 txBytes=0 rxBytes=0 } mLc=MobileActivity{ txTimeMs[]=[0, 0, 0, 79, 239] rxTimeMs=4659 txBytes=193 rxBytes=187 } }
03-05 15:15:32.372 31632 31632 D SemBigDataInfoController: Intent : com.samsung.intent.action.BIG_DATA_INFO
03-05 15:15:32.381 16682 16700 I scrcpy : buttons = 1
03-05 15:15:32.381 31632 3395 I System.out: Broadcast completed: result=0
03-05 15:15:32.384 3329 3354 I chromium: [INFO:web_view_impl.cc(2030)] SBRTOUCHLOG Blink HandleInputEvent event received = MouseMove
03-05 15:15:32.385 31297 31368 D BatteryExternalStatsWorker: updateMobileRadioState was updated
03-05 15:15:32.391 16682 16700 I scrcpy : buttons = 1
03-05 15:15:32.392 16682 16700 I scrcpy : buttons = 1
03-05 15:15:32.401 3329 3354 I chromium: [INFO:web_view_impl.cc(2030)] SBRTOUCHLOG Blink HandleInputEvent event received = MouseMove
03-05 15:15:32.401 16682 16700 I scrcpy : buttons = 1
03-05 15:15:32.411 16682 16700 I scrcpy : buttons = 1
03-05 15:15:32.417 3329 3354 I chromium: [INFO:web_view_impl.cc(2030)] SBRTOUCHLOG Blink HandleInputEvent event received = MouseMove

without 17d53be
03-05 15:18:12.537 17048 17064 I scrcpy : buttons = 11
03-05 15:18:12.538 31297 32221 D InputDispatcher: Inject motion (17048): action=0x0, time=285465087000000, f=0x0, d=0
03-05 15:18:12.538 31297 31482 I InputDispatcher: Delivering touch to (31656): action: 0x4, f=0x0, d=0, '17c101d', t=1
03-05 15:18:12.539 31297 31482 I InputDispatcher: Delivering touch to (14382): action: 0x0, f=0x2, d=0, '8fd012e', t=1
03-05 15:18:12.539 14382 14382 I ViewRootImpl@bfc4dc2[SBrowserMainActivity]: ViewPostIme pointer 0
03-05 15:18:12.539 31297 31482 D PowerManagerService: UserActivityStateListenerState: 1
03-05 15:18:12.541 14382 14382 W chromium: [WARNING:render_widget_host_view_android.cc(873)] SBRTOUCHLOG OnTouchEvent, Action::DOWN
03-05 15:18:12.541 14382 14382 I chromium: [INFO:render_widget_host_input_event_router.cc(836)] SBRTOUCHLOG Set Touch sequence target view: 0xdb0b1490
03-05 15:18:12.541 14382 14382 W chromium: [WARNING:input_router_impl.cc(571)] SBRTOUCHLOG FilterAndSendWebInputEvent, kTouchStart
03-05 15:18:12.542 14382 14382 I ViewRootImpl: updatePointerIcon pointerType = 1000, calling pid = 14382
03-05 15:18:12.542 3329 3362 I chromium: [INFO:input_handler_proxy.cc(1109)] SBRTOUCHLOG : TouchStart
03-05 15:18:12.542 31297 1456 D PointerController: updatePointerIcon, 1008 -> 1000
03-05 15:18:12.543 3329 3354 I chromium: [INFO:web_view_impl.cc(2030)] SBRTOUCHLOG Blink HandleInputEvent event received = PointerDown
03-05 15:18:12.549 3329 3354 I chromium: [INFO:web_view_impl.cc(2030)] SBRTOUCHLOG Blink HandleInputEvent event received = GestureTapDown
03-05 15:18:12.562 31297 31515 D SamsungAlarmManager: setInexact (T:2/F:8/AC:false) 20210305T151827 now=979378315 - CU:1000/CP:31297/L:7bc499d:WificondScannerImpl Scan Timeout
03-05 15:18:12.562 31297 31515 I SamsungAlarmManager: setLocked to kernel - T:2 / 20210305T151827, set=979393315, now=979378315
03-05 15:18:12.562 31297 31515 I SamsungAlarmManager: setLocked to kernel - T:3 / 20210305T151817, set=979383457, now=979378315
03-05 15:18:12.586 17048 17064 I scrcpy : buttons = 11
03-05 15:18:12.588 17048 17064 I scrcpy : buttons = 11
03-05 15:18:12.606 17048 17064 I scrcpy : buttons = 11
03-05 15:18:12.607 17048 17064 I scrcpy : buttons = 11
03-05 15:18:12.617 17048 17064 I scrcpy : buttons = 11
03-05 15:18:12.617 17048 17064 I scrcpy : buttons = 11
03-05 15:18:12.627 17048 17064 I scrcpy : buttons = 11
03-05 15:18:12.637 17048 17064 I scrcpy : buttons = 11
03-05 15:18:12.642 3329 3354 I chromium: [INFO:web_view_impl.cc(2030)] SBRTOUCHLOG Blink HandleInputEvent event received = GestureShowPress
03-05 15:18:12.647 17048 17064 I scrcpy : buttons = 11
03-05 15:18:12.648 17048 17064 I scrcpy : buttons = 11
03-05 15:18:12.652 3329 3362 I chromium: [INFO:layer_tree_host_impl.cc(3950)] SBRTOUCHLOG LayerTreeHostImpl::ScrollBegin defer_commit = 0
03-05 15:18:12.652 3329 3354 I chromium: [INFO:web_view_impl.cc(2030)] SBRTOUCHLOG Blink HandleInputEvent event received = GestureTapCancel
03-05 15:18:12.652 3329 3362 I chromium: [INFO:input_handler_proxy.cc(933)] SBRTOUCHLOG HandleGestureScrollBegin result = 0
03-05 15:18:12.652 3329 3354 I chromium: [INFO:web_view_impl.cc(2030)] SBRTOUCHLOG Blink HandleInputEvent event received = PointerCausedUaAction
03-05 15:18:12.657 17048 17064 I scrcpy : buttons = 11
03-05 15:18:12.665 3329 3362 I chromium: [INFO:layer_tree_host_impl.cc(4701)] SBRTOUCHLOG LayerTreeHostImpl::ScrollBy delta_y = -12.6156
03-05 15:18:12.668 17048 17064 I scrcpy : buttons = 11
03-05 15:18:12.678 17048 17064 I scrcpy : buttons = 11
03-05 15:18:12.680 17048 17064 I scrcpy : buttons = 11
03-05 15:18:12.689 17048 17064 I scrcpy : buttons = 11
03-05 15:18:12.689 711 711 D gralloc : [mali_gralloc_allocate] begin
03-05 15:18:12.689 711 711 D gralloc : buffer_descriptor: wh(1080 2256) usage_pc(0x40000000000b00 0x40000000000b00) hal_format(0x1) layer_count(1) sizes(0 0 0) strde(0) byte_stride(0) alloc_wh(0 0) internal_format(0x0) alloc_format(0x0) fd_count(1) plane_count(0)
03-05 15:18:12.695 711 711 D gralloc : [mali_gralloc_allocate] allocation successful
03-05 15:18:12.697 785 1715 D NativeSemDvfsManager: acquire:: timeout = 1000 mIsAcquired = 1 mTagName : SurfaceFlinger
03-05 15:18:12.697 785 1715 E NativeCustomFrequencyManager: [NativeCFMS] BpCustomFrequencyManager::acquire()
03-05 15:18:12.697 31144 31180 I HYPER-HAL: [RequestManager.cpp]acquire(): Acquired ID : 1596792 [785 / 1001] HINT : list : [GPUMinFreq / 377000] [TIMEOUT / 1000]

@ANDImur
Copy link

ANDImur commented Mar 10, 2021

I have the same problem. On an old phone (Redmi 6), the solution is to install version 12.1.4.3. Everything works on it. But the market version is now 13.2.2.4 and there is a problem with it.

@dmissmann
Copy link

I'm facing the same issue with the Samsung Browser. I was trying to compare the MotionEvent objects of adb input tap with the ones created by scrcpy on a left mouse click.
For adb input tab we have something like

    action=ACTION_DOWN, 
    actionButton=0, 
    id[0]=0,
    x[0]=100.0,
    y[0]=300.0,
    toolType[0]=TOOL_TYPE_UNKNOWN,
    buttonState=0,
    metaState=0,
    flags=0x0,
    edgeFlags=0x0,
    pointerCount=1,
    historySize=0,
    eventTime=7609337,
    downTime=7609337,
    deviceId=3,
    source=0x1002
}

and for scrcpy it's:

MotionEvent { 
    action=ACTION_DOWN,
    actionButton=0,
    id[0]=0,
    x[0]=150.0,
    y[0]=278.0,
    toolType[0]=TOOL_TYPE_FINGER,
    buttonState=BUTTON_PRIMARY,
    metaState=0,
    flags=0x0,
    edgeFlags=0x0,
    pointerCount=1,
    historySize=0,
    eventTime=7675534,
    downTime=7675534,
    deviceId=-1,
    source=0x1002 
}

Changing buttonState from BUTTON_PRIMARY to 0 did actually make it work. I'm not sure what is actually the expected value here. We're obviously using a mouse with scrcpy but I guess we want to emit touch events. And from the Android documentation for BUTTON_PRIMARY it's also not clear if 0 or 1 is the correct value for a touch event since it states "This button constant is not set in response to simple touches with a finger or stylus tip"

@rom1v
Copy link
Collaborator

rom1v commented Mar 11, 2021

it's also not clear if 0 or 1 is the correct value for a touch event since it states "This button constant is not set in response to simple touches with a finger or stylus tip"

Hmmm, I understand that BUTTON_PRIMARY must not be set for touch events:

diff --git a/server/src/main/java/com/genymobile/scrcpy/Controller.java b/server/src/main/java/com/genymobile/scrcpy/Controller.java
index d8059b43..21ff6932 100644
--- a/server/src/main/java/com/genymobile/scrcpy/Controller.java
+++ b/server/src/main/java/com/genymobile/scrcpy/Controller.java
@@ -208,6 +208,9 @@ 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 = 0;
+        }
 
         MotionEvent event = MotionEvent
                 .obtain(lastTouchDown, now, action, pointerCount, pointerProperties, pointerCoords, 0, buttons, 1f, 1f, DEVICE_ID_VIRTUAL, 0, source,

However, more generally, I guess using SOURCE_MOUSE for all mouse events instead would be better.

But I remember doing that in the past, and it changes the actual behavior, at least on text selection. The mouse behavior seems acceptable, but I remember that there were cases were it was not (even when using a mouse on the computer), I don't remember which cases.

(And it complicates the behavior when both mouse and touch events are generated from the computer, but that's secondary.)

Refs adc547f 6220456

@rom1v
Copy link
Collaborator

rom1v commented Mar 12, 2021

but I remember that there were cases were it was not (even when using a mouse on the computer), I don't remember which cases.

As a mouse, some clicks on close prositions (sic) are sometimes not generated on some devices.

f70359f

But that problem was maybe related to #2125 (comment).

@rom1v
Copy link
Collaborator

rom1v commented Mar 12, 2021

In fact, using SOURCE_MOUSE instead of SOURCE_FINGER even for left-clicks is bad for text selection. It may seem better at first, because it's easier to select, but deselection and click to move the cursor is broken.

rom1v added a commit that referenced this issue Mar 15, 2021
BUTTON_PRIMARY must not be set for touch events:

> This button constant is not set in response to simple touches with a
> finger or stylus tip. The user must actually push a button.

<https://developer.android.com/reference/android/view/MotionEvent#BUTTON_PRIMARY>

Fixes #2169 <#2169>
@rom1v
Copy link
Collaborator

rom1v commented Mar 15, 2021

Could you please confirm that it works correctly on branch issue2169?

@dmissmann
Copy link

Yes, that works with the Samsung Browser

@rom1v
Copy link
Collaborator

rom1v commented Mar 16, 2021

👍 Let's merge it (into dev), then.

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

No branches or pull requests

4 participants