Set displayId to NONE in Options on new display

If a new display is set, force options.getDisplayId() to return
Device.DISPLAY_ID_NONE, to avoid any confusion between a local displayId
and options.getDisplayId().
This commit is contained in:
Romain Vimont 2024-11-14 20:20:10 +01:00
parent 5e10c37f02
commit 794595e3f0
3 changed files with 16 additions and 12 deletions

View File

@ -25,13 +25,13 @@ public final class CleanUp {
private Thread thread;
private CleanUp(int displayId, Options options) {
thread = new Thread(() -> runCleanUp(displayId, options), "cleanup");
private CleanUp(Options options) {
thread = new Thread(() -> runCleanUp(options), "cleanup");
thread.start();
}
public static CleanUp start(int displayId, Options options) {
return new CleanUp(displayId, options);
public static CleanUp start(Options options) {
return new CleanUp(options);
}
public void interrupt() {
@ -42,7 +42,7 @@ public final class CleanUp {
thread.join();
}
private void runCleanUp(int displayId, Options options) {
private void runCleanUp(Options options) {
boolean disableShowTouches = false;
if (options.getShowTouches()) {
try {
@ -93,6 +93,7 @@ public final class CleanUp {
}
boolean powerOffScreen = options.getPowerOffScreenOnClose();
int displayId = options.getDisplayId();
try {
run(displayId, restoreStayOn, disableShowTouches, powerOffScreen, restoreScreenOffTimeout);

View File

@ -479,6 +479,11 @@ public class Options {
}
}
if (options.newDisplay != null) {
assert options.displayId == 0 : "Must not set both displayId and newDisplay";
options.displayId = Device.DISPLAY_ID_NONE;
}
return options;
}

View File

@ -103,11 +103,8 @@ public final class Server {
CleanUp cleanUp = null;
NewDisplay newDisplay = options.getNewDisplay();
int displayId = newDisplay == null ? options.getDisplayId() : Device.DISPLAY_ID_NONE;
if (options.getCleanup()) {
cleanUp = CleanUp.start(displayId, options);
cleanUp = CleanUp.start(options);
}
int scid = options.getScid();
@ -131,7 +128,7 @@ public final class Server {
if (control) {
ControlChannel controlChannel = connection.getControlChannel();
controller = new Controller(displayId, controlChannel, cleanUp, options.getClipboardAutosync(), options.getPowerOn());
controller = new Controller(options.getDisplayId(), controlChannel, cleanUp, options.getClipboardAutosync(), options.getPowerOn());
asyncProcessors.add(controller);
}
@ -161,11 +158,12 @@ public final class Server {
options.getSendFrameMeta());
SurfaceCapture surfaceCapture;
if (options.getVideoSource() == VideoSource.DISPLAY) {
NewDisplay newDisplay = options.getNewDisplay();
if (newDisplay != null) {
surfaceCapture = new NewDisplayCapture(controller, newDisplay, options.getMaxSize());
} else {
assert displayId != Device.DISPLAY_ID_NONE;
surfaceCapture = new ScreenCapture(controller, displayId, options.getMaxSize(), options.getCrop(),
assert options.getDisplayId() != Device.DISPLAY_ID_NONE;
surfaceCapture = new ScreenCapture(controller, options.getDisplayId(), options.getMaxSize(), options.getCrop(),
options.getLockVideoOrientation());
}
} else {