From cb4bbd7af8d07fc53938ae81f2604498b502f1dd Mon Sep 17 00:00:00 2001 From: Vladislav Kaznacheev Date: Thu, 12 May 2016 12:56:31 -0700 Subject: [PATCH] Partial fix for jumping freeform windows Currently every focus change causes a freeform window to jump for a few frames. The size of the jump is equal to the difference in inset size (which is derived directly from the window elevation). This problem goes away for most real use cases if the insets are not allowed to decrease. Bug: 28318973 Bug: 22668382 Change-Id: I77ca440a7d9c89cc4d45e6667bf37da94a5c8a9a --- core/java/android/view/WindowManager.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/core/java/android/view/WindowManager.java b/core/java/android/view/WindowManager.java index 9b74fc05809db..fe2423093c881 100644 --- a/core/java/android/view/WindowManager.java +++ b/core/java/android/view/WindowManager.java @@ -1803,7 +1803,21 @@ public interface WindowManager extends ViewManager { */ public final void setSurfaceInsets(View view, boolean manual, boolean preservePrevious) { final int surfaceInset = (int) Math.ceil(view.getZ() * 2); - surfaceInsets.set(surfaceInset, surfaceInset, surfaceInset, surfaceInset); + // Partial workaround for b/28318973. Every inset change causes a freeform window + // to jump a little for a few frames. If we never allow surface insets to decrease, + // they will stabilize quickly (often from the very beginning, as most windows start + // as focused). + // TODO(b/22668382) to fix this properly. + if (surfaceInset == 0) { + // OK to have 0 (this is the case for non-freeform windows). + surfaceInsets.set(0, 0, 0, 0); + } else { + surfaceInsets.set( + Math.max(surfaceInset, surfaceInsets.left), + Math.max(surfaceInset, surfaceInsets.top), + Math.max(surfaceInset, surfaceInsets.right), + Math.max(surfaceInset, surfaceInsets.bottom)); + } hasManualSurfaceInsets = manual; preservePreviousSurfaceInsets = preservePrevious; }