refactor(scrcpy): small optimizations

This commit is contained in:
Simon Chan 2023-01-20 20:43:43 +08:00
parent 6b23154694
commit b5f58227fd
No known key found for this signature in database
GPG key ID: A8B69F750B9BCEDD
11 changed files with 359 additions and 71 deletions

View file

@ -5,16 +5,21 @@ import {
import { ScrcpyControlMessageType } from "./type.js";
/**
* On Android, touching the screen with a finger will disable mouse cursor.
* However, Scrcpy doesn't do that, and can inject two pointers at the same time.
* This can cause finger events to be "ignored" because mouse is still the primary pointer.
* On both Android and Windows, while both mouse and touch are supported input devices,
* only one of them can be active at a time. Touch the screen with a finger will deactivate mouse,
* and move the mouse will deactivate touch.
*
* This helper class injects an extra `ACTION_UP` event,
* On Android, this is achieved by dispatching a `MotionEvent.ACTION_UP` event for the previous input type.
* But on Chrome, there is no such event, causing both mouse and touch to be active at the same time.
* This can cause the new input to appear as "ignored".
*
* This helper class synthesis `ACTION_UP` events when a different pointer type appears,
* so Scrcpy server can remove the previously hovering pointer.
*/
export class ScrcpyHoverHelper {
// AFAIK, only mouse and pen can have hover state
// and you can't have two mouses or pens.
// So remember the last hovering pointer is enough.
private lastHoverMessage: ScrcpyInjectTouchControlMessage | undefined;
public process(