Skip to content

Commit 3d5294c

Browse files
committed
Set main display power for virtual display
Change the display power of the main display when mirroring a virtual display, to make it possible to turn off the screen. Fixes #5522 <#5522> Refs #5530 <#5530>
1 parent 1d2f16d commit 3d5294c

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

server/src/main/java/com/genymobile/scrcpy/CleanUp.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -207,13 +207,15 @@ public static void main(String... args) {
207207
}
208208
}
209209

210-
if (displayId != Device.DISPLAY_ID_NONE && Device.isScreenOn(displayId)) {
210+
// Change the power of the main display when mirroring a virtual display
211+
int targetDisplayId = displayId != Device.DISPLAY_ID_NONE ? displayId : 0;
212+
if (Device.isScreenOn(targetDisplayId)) {
211213
if (powerOffScreen) {
212214
Ln.i("Power off screen");
213-
Device.powerOffScreen(displayId);
215+
Device.powerOffScreen(targetDisplayId);
214216
} else if (restoreDisplayPower) {
215217
Ln.i("Restoring display power");
216-
Device.setDisplayPower(displayId, true);
218+
Device.setDisplayPower(targetDisplayId, true);
217219
}
218220
}
219221

server/src/main/java/com/genymobile/scrcpy/control/Controller.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ private boolean handleEvent() throws IOException {
281281
setClipboard(msg.getText(), msg.getPaste(), msg.getSequence());
282282
break;
283283
case ControlMessage.TYPE_SET_DISPLAY_POWER:
284-
if (supportsInputEvents && displayId != Device.DISPLAY_ID_NONE) {
284+
if (supportsInputEvents) {
285285
setDisplayPower(msg.getOn());
286286
}
287287
break;
@@ -691,9 +691,12 @@ private DisplayData waitDisplayData(long timeoutMillis) throws InterruptedExcept
691691
}
692692

693693
private void setDisplayPower(boolean on) {
694-
boolean setDisplayPowerOk = Device.setDisplayPower(displayId, on);
694+
// Change the power of the main display when mirroring a virtual display
695+
int targetDisplayId = displayId != Device.DISPLAY_ID_NONE ? displayId : 0;
696+
boolean setDisplayPowerOk = Device.setDisplayPower(targetDisplayId, on);
695697
if (setDisplayPowerOk) {
696-
keepDisplayPowerOff = !on;
698+
// Do not keep display power off for virtual displays: MOD+p must wake up the physical device
699+
keepDisplayPowerOff = displayId != Device.DISPLAY_ID_NONE && !on;
697700
Ln.i("Device display turned " + (on ? "on" : "off"));
698701
if (cleanUp != null) {
699702
boolean mustRestoreOnExit = !on;

0 commit comments

Comments
 (0)