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

add dispatch_to_vd option to server #5214

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions server/src/main/java/com/genymobile/scrcpy/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public class Options {
private boolean listDisplays;
private boolean listCameras;
private boolean listCameraSizes;
// when screen virtual display, input event should be dispatched to virtual display
private boolean dispatchToVD = 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 @@ -209,6 +211,10 @@ public boolean getList() {
return listEncoders || listDisplays || listCameras || listCameraSizes;
}

public boolean getDispatchToVD() {
return dispatchToVD;
}

public boolean getListEncoders() {
return listEncoders;
}
Expand Down Expand Up @@ -388,6 +394,9 @@ public static Options parse(String... args) {
case "list_camera_sizes":
options.listCameraSizes = Boolean.parseBoolean(value);
break;
case "dispatch_to_vd":
options.dispatchToVD = Boolean.parseBoolean(value);
break;
case "camera_id":
if (!value.isEmpty()) {
options.cameraId = value;
Expand Down
23 changes: 21 additions & 2 deletions server/src/main/java/com/genymobile/scrcpy/device/Device.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public interface ClipboardListener {
* Logical display identifier
*/
private final int displayId;
private int inputDisplayId;

/**
* The surface flinger layer stack associated with this logical display
Expand All @@ -72,8 +73,15 @@ public interface ClipboardListener {

private final boolean supportsInputEvents;

/**
* Whether to dispatch input events to the virtual display
*/
private final boolean dispatchToVD;

public Device(Options options) throws ConfigurationException {
displayId = options.getDisplayId();
inputDisplayId = displayId;
dispatchToVD = options.getDispatchToVD();
DisplayInfo displayInfo = ServiceManager.getDisplayManager().getDisplayInfo(displayId);
if (displayInfo == null) {
Ln.e("Display " + displayId + " not found\n" + LogUtils.buildDisplayListMessage());
Expand Down Expand Up @@ -172,6 +180,14 @@ public int getDisplayId() {
return displayId;
}

public int getInputDisplayId() {
return inputDisplayId;
}

public void setInputDisplayId(int id) {
inputDisplayId = id;
}

public synchronized void setMaxSize(int newMaxSize) {
maxSize = newMaxSize;
screenInfo = ScreenInfo.computeScreenInfo(screenInfo.getReverseVideoRotation(), deviceSize, crop, newMaxSize, lockVideoOrientation);
Expand Down Expand Up @@ -222,11 +238,14 @@ public boolean supportsInputEvents() {
return supportsInputEvents;
}

public boolean isDispatchToVD() {
return dispatchToVD;
}

public static boolean injectEvent(InputEvent inputEvent, int displayId, int injectMode) {
if (!supportsInputEvents(displayId)) {
throw new AssertionError("Could not inject input event if !supportsInputEvents()");
}

if (displayId != 0 && !InputManager.setDisplayId(inputEvent, displayId)) {
return false;
}
Expand All @@ -235,7 +254,7 @@ public static boolean injectEvent(InputEvent inputEvent, int displayId, int inje
}

public boolean injectEvent(InputEvent event, int injectMode) {
return injectEvent(event, displayId, injectMode);
return injectEvent(event, inputDisplayId, injectMode);
}

public static boolean injectKeyEvent(int action, int keyCode, int repeat, int metaState, int displayId, int injectMode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public void start(Surface surface) {
virtualDisplay = ServiceManager.getDisplayManager()
.createVirtualDisplay("scrcpy", videoRect.width(), videoRect.height(), device.getDisplayId(), surface);
Ln.d("Display: using DisplayManager API");
if (device.isDispatchToVD()) {
device.setInputDisplayId(virtualDisplay.getDisplay().getDisplayId());
}
} catch (Exception displayManagerException) {
try {
display = createDisplay();
Expand Down