From f15c0af34ed3898abc49434351bf8f27aa4aad75 Mon Sep 17 00:00:00 2001 From: alien2003 Date: Sun, 15 Nov 2026 15:35:23 +0100 Subject: [PATCH] fix(ctl): screenshots on phones with two screens take the main display (#2628) screencap without -d prints a warning before the PNG when it finds more than one display, so droiddeckctl screenshot failed on foldables and dual-screen phones. Without --display, screenshot and record now use the physical display behind logical display 0 when there is more than one. Co-authored-by: alien2003 <11610652+alien2003@users.noreply.github.com> --- tools/droiddeckctl | 4 +++- tools/tests/test_droiddeckctl.py | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/tools/droiddeckctl b/tools/droiddeckctl index ea82343888..acdfce5fdb 100755 --- a/tools/droiddeckctl +++ b/tools/droiddeckctl @@ -287,7 +287,9 @@ def displays(adb: str, serial: str) -> list[dict]: def physical_display(adb: str, serial: str, logical: int | None) -> str | None: if logical is None: - return None + found = displays(adb, serial) + main = next((d["physicalId"] for d in found if d["display"] == 0), None) + return main if len(found) > 1 else None for d in displays(adb, serial): if d["display"] == logical: if not d["physicalId"]: diff --git a/tools/tests/test_droiddeckctl.py b/tools/tests/test_droiddeckctl.py index 1f7e32cdff..3d26a409fb 100644 --- a/tools/tests/test_droiddeckctl.py +++ b/tools/tests/test_droiddeckctl.py @@ -332,6 +332,21 @@ class DroiddeckctlTest(FakeAdbTest): shot = [c for c in self.calls() if c["args"][:2] == ["exec-out", "screencap"]][0] self.assertEqual(["exec-out", "screencap", "-p", "-d", "222"], shot["args"]) + def test_screenshot_with_two_screens_takes_the_main_display(self): + self.configure({}, dumpsys_display=DUMPSYS_DISPLAY) + code, out = self.run_ctl("screenshot", str(self.dir / "shot.png")) + self.assertEqual(0, code) + shot = [c for c in self.calls() if c["args"][:2] == ["exec-out", "screencap"]][0] + self.assertEqual(["exec-out", "screencap", "-p", "-d", "111"], shot["args"]) + + def test_screenshot_with_one_screen_names_no_display(self): + one = DUMPSYS_DISPLAY.split(" Display 4:")[0] + self.configure({}, dumpsys_display=one) + code, out = self.run_ctl("screenshot", str(self.dir / "shot.png")) + self.assertEqual(0, code) + shot = [c for c in self.calls() if c["args"][:2] == ["exec-out", "screencap"]][0] + self.assertEqual(["exec-out", "screencap", "-p"], shot["args"]) + def test_displays(self): self.configure({}, dumpsys_display=DUMPSYS_DISPLAY) code, out = self.run_ctl("displays")