diff --git a/server/src/main/java/com/genymobile/scrcpy/video/DisplaySizeMonitor.java b/server/src/main/java/com/genymobile/scrcpy/video/DisplaySizeMonitor.java index 3d7cccfeab..b2561973a8 100644 --- a/server/src/main/java/com/genymobile/scrcpy/video/DisplaySizeMonitor.java +++ b/server/src/main/java/com/genymobile/scrcpy/video/DisplaySizeMonitor.java @@ -38,6 +38,18 @@ public interface Listener { private Listener listener; + // Some devices report slightly different sizes depending on UI state. Ignore + // such minor fluctuations to avoid spurious capture resets. + private static final int SIZE_EPSILON = 4; + + private static boolean approximatelyEquals(Size s1, Size s2) { + if (s1 == null || s2 == null) { + return false; + } + return Math.abs(s1.getWidth() - s2.getWidth()) <= SIZE_EPSILON + && Math.abs(s1.getHeight() - s2.getHeight()) <= SIZE_EPSILON; + } + public void start(int displayId, Listener listener) { // Once started, the listener and the displayId must never change assert listener != null; @@ -124,7 +136,7 @@ private void checkDisplaySizeChanged() { Size sessionDisplaySize = getSessionDisplaySize(); // synchronized // .equals() also works if sessionDisplaySize == null - if (!size.equals(sessionDisplaySize)) { + if (!approximatelyEquals(size, sessionDisplaySize)) { // Reset only if the size is different if (Ln.isEnabled(Ln.Level.VERBOSE)) { Ln.v("DisplaySizeMonitor: requestReset(): " + sessionDisplaySize + " -> " + size);