Skip to content

Commit

Permalink
This is just to document an attempt to fix Genymobile#3568
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
paweljasinski committed Nov 10, 2022
1 parent 72ba913 commit 14d7351
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 5 deletions.
1 change: 1 addition & 0 deletions app/src/scrcpy.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ scrcpy(struct scrcpy_options *options) {
.tcpip_dst = options->tcpip_dst,
.cleanup = options->cleanup,
.power_on = options->power_on,
.forward_all_clicks = options->forward_all_clicks,
};

static const struct sc_server_callbacks cbs = {
Expand Down
4 changes: 4 additions & 0 deletions app/src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ execute_server(struct sc_server *server,
// By default, power_on is true
ADD_PARAM("power_on=false");
}
if (params->forward_all_clicks) {
// By default, forward all clicks is false
ADD_PARAM("forward_all_clicks=true");
}

#undef ADD_PARAM

Expand Down
1 change: 1 addition & 0 deletions app/src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ struct sc_server_params {
bool select_tcpip;
bool cleanup;
bool power_on;
bool forward_all_clicks;
};

struct sc_server {
Expand Down
8 changes: 4 additions & 4 deletions server/src/main/java/com/genymobile/scrcpy/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class Controller {
private final DeviceMessageSender sender;
private final boolean clipboardAutosync;
private final boolean powerOn;
private final boolean forwardAllClicks;

private final KeyCharacterMap charMap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);

Expand All @@ -33,11 +34,12 @@ public class Controller {

private boolean keepPowerModeOff;

public Controller(Device device, DesktopConnection connection, boolean clipboardAutosync, boolean powerOn) {
public Controller(Device device, DesktopConnection connection, boolean clipboardAutosync, boolean powerOn, boolean forwardAllClicks) {
this.device = device;
this.connection = connection;
this.clipboardAutosync = clipboardAutosync;
this.powerOn = powerOn;
this.forwardAllClicks = forwardAllClicks;
initPointers();
sender = new DeviceMessageSender(connection);
}
Expand Down Expand Up @@ -210,13 +212,11 @@ private boolean injectTouch(int action, long pointerId, Position position, float
}

// 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;
int source = forwardAllClicks ? InputDevice.SOURCE_MOUSE : InputDevice.SOURCE_TOUCHSCREEN;
if (source != InputDevice.SOURCE_MOUSE) {
// Buttons must not be set for touch events
buttons = 0;
}

MotionEvent event = MotionEvent
.obtain(lastTouchDown, now, action, pointerCount, pointerProperties, pointerCoords, 0, buttons, 1f, 1f, DEFAULT_DEVICE_ID, 0, source,
0);
Expand Down
10 changes: 10 additions & 0 deletions server/src/main/java/com/genymobile/scrcpy/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class Options {
private boolean downsizeOnError = true;
private boolean cleanup = true;
private boolean powerOn = true;
private boolean forwardAllClicks = false;

// Options not used by the scrcpy client, but useful to use scrcpy-server directly
private boolean sendDeviceMeta = true; // send device name and size
Expand Down Expand Up @@ -196,4 +197,13 @@ public boolean getSendDummyByte() {
public void setSendDummyByte(boolean sendDummyByte) {
this.sendDummyByte = sendDummyByte;
}

public boolean getForwardAllClicks() {
return forwardAllClicks;
}

public void setForwardAllClicks(boolean forwardAllClicks) {
this.forwardAllClicks = forwardAllClicks;
}

}
7 changes: 6 additions & 1 deletion server/src/main/java/com/genymobile/scrcpy/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private static void scrcpy(Options options) throws IOException {
Thread controllerThread = null;
Thread deviceMessageSenderThread = null;
if (control) {
final Controller controller = new Controller(device, connection, options.getClipboardAutosync(), options.getPowerOn());
final Controller controller = new Controller(device, connection, options.getClipboardAutosync(), options.getPowerOn(), options.getForwardAllClicks());

// asynchronous
controllerThread = startController(controller);
Expand Down Expand Up @@ -272,6 +272,11 @@ private static Options createOptions(String... args) {
options.setSendDummyByte(false);
}
break;
case "forward_all_clicks":
boolean forwardAllClicks = Boolean.parseBoolean(value);
options.setForwardAllClicks(forwardAllClicks);
break;

default:
Ln.w("Unknown server option: " + key);
break;
Expand Down

0 comments on commit 14d7351

Please sign in to comment.