Fix freeform window can't resize

The WindowState touch region would be cropped by task bounds, but in
free form window mode, we could has some extra space outside the window
content in order to resize window, we should include the resize border
in the touch region.

- Touch region should include the resize border and prevent it to be
  cropped by task bounds if window is freeform.
- Apply show or hide transaction for InputSurface immediately.

Bug: 152248369
Test: Enable freeform and resize.
Change-Id: I738da8f8c5cc08483c71edfc29eb7110c6111154
This commit is contained in:
arthurhung
2020-04-21 14:38:54 +08:00
parent 8c624b8001
commit da4c2d609b
4 changed files with 34 additions and 34 deletions

View File

@@ -27,7 +27,6 @@ import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_FOCUS_LIGHT;
import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT;
import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TASK_POSITIONING;
import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
import android.graphics.Rect;
@@ -38,7 +37,6 @@ import android.os.Process;
import android.os.Trace;
import android.os.UserHandle;
import android.util.ArrayMap;
import android.util.Log;
import android.util.Slog;
import android.view.InputApplicationHandle;
import android.view.InputChannel;
@@ -138,18 +136,6 @@ final class InputMonitor {
// If there's a drag in flight, provide a pseudo-window to catch drag input
final boolean inDrag = mService.mDragDropController.dragDropActiveLocked();
final boolean inPositioning =
mService.mTaskPositioningController.isPositioningLocked();
if (inPositioning) {
if (DEBUG_TASK_POSITIONING) {
Log.d(TAG_WM, "Inserting window handle for repositioning");
}
mService.mTaskPositioningController.showInputSurface(mInputTransaction,
mDisplayId);
} else {
mService.mTaskPositioningController.hideInputSurface(mInputTransaction,
mDisplayId);
}
// Add all windows on the default display.
mUpdateInputForAllWindowsConsumer.updateInputWindows(inDrag);

View File

@@ -53,7 +53,6 @@ import android.view.InputDevice;
import android.view.InputEvent;
import android.view.InputWindowHandle;
import android.view.MotionEvent;
import android.view.SurfaceControl;
import android.view.WindowManager;
import com.android.internal.annotations.VisibleForTesting;
@@ -268,9 +267,7 @@ class TaskPositioner implements IBinder.DeathRecipient {
mDisplayContent.getDisplayRotation().pause();
// Notify InputMonitor to take mDragWindowHandle.
final SurfaceControl.Transaction t = mService.mTransactionFactory.get();
mDisplayContent.getInputMonitor().updateInputWindowsImmediately(t);
t.syncInputWindows().apply();
mService.mTaskPositioningController.showInputSurface(win.getDisplayId());
final DisplayMetrics displayMetrics = displayContent.getDisplayMetrics();
mMinVisibleWidth = dipToPixel(MINIMUM_VISIBLE_WIDTH_IN_DP, displayMetrics);
@@ -301,6 +298,7 @@ class TaskPositioner implements IBinder.DeathRecipient {
return;
}
mService.mTaskPositioningController.hideInputSurface(mDisplayContent.getDisplayId());
mService.mInputManager.unregisterInputChannel(mServerChannel);
mInputEventReceiver.dispose();

View File

@@ -55,6 +55,8 @@ class TaskPositioningController {
return mTaskPositioner != null;
}
final SurfaceControl.Transaction mTransaction;
InputWindowHandle getDragWindowHandleLocked() {
return mTaskPositioner != null ? mTaskPositioner.mDragWindowHandle : null;
}
@@ -65,16 +67,18 @@ class TaskPositioningController {
mInputManager = inputManager;
mActivityManager = activityManager;
mHandler = new Handler(looper);
mTransaction = service.mTransactionFactory.get();
}
void hideInputSurface(SurfaceControl.Transaction t, int displayId) {
void hideInputSurface(int displayId) {
if (mPositioningDisplay != null && mPositioningDisplay.getDisplayId() == displayId
&& mInputSurface != null) {
t.hide(mInputSurface);
mTransaction.hide(mInputSurface);
mTransaction.syncInputWindows().apply();
}
}
void showInputSurface(SurfaceControl.Transaction t, int displayId) {
void showInputSurface(int displayId) {
if (mPositioningDisplay == null || mPositioningDisplay.getDisplayId() != displayId) {
return;
}
@@ -92,16 +96,17 @@ class TaskPositioningController {
return;
}
t.show(mInputSurface);
t.setInputWindowInfo(mInputSurface, h);
t.setLayer(mInputSurface, Integer.MAX_VALUE);
mTransaction.show(mInputSurface);
mTransaction.setInputWindowInfo(mInputSurface, h);
mTransaction.setLayer(mInputSurface, Integer.MAX_VALUE);
final Display display = dc.getDisplay();
final Point p = new Point();
display.getRealSize(p);
mTmpClipRect.set(0, 0, p.x, p.y);
t.setWindowCrop(mInputSurface, mTmpClipRect);
mTransaction.setWindowCrop(mInputSurface, mTmpClipRect);
mTransaction.syncInputWindows().apply();
}
boolean startMovingTask(IWindow window, float startX, float startY) {

View File

@@ -2489,6 +2489,23 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
return flags;
}
/**
* Expands the given rectangle by the region of window resize handle for freeform window.
* @param inOutRect The rectangle to update.
*/
private void adjustRegionInFreefromWindowMode(Rect inOutRect) {
if (!inFreeformWindowingMode()) {
return;
}
// For freeform windows, we need the touch region to include the whole
// surface for the shadows.
final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
final int delta = WindowManagerService.dipToPixel(
RESIZE_HANDLE_WIDTH_IN_DP, displayMetrics);
inOutRect.inset(-delta, -delta);
}
/**
* Updates the region for a window in an Activity that was a touch modal. This will limit
* the outer touch to the activity stack region.
@@ -2512,14 +2529,7 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
getRootTask().getDimBounds(mTmpRect);
}
}
if (inFreeformWindowingMode()) {
// For freeform windows, we need the touch region to include the whole
// surface for the shadows.
final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
final int delta = WindowManagerService.dipToPixel(
RESIZE_HANDLE_WIDTH_IN_DP, displayMetrics);
mTmpRect.inset(-delta, -delta);
}
adjustRegionInFreefromWindowMode(mTmpRect);
outRegion.set(mTmpRect);
cropRegionToStackBoundsIfNeeded(outRegion);
}
@@ -3334,7 +3344,7 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
}
final ActivityStack stack = task.getStack();
if (stack == null) {
if (stack == null || inFreeformWindowingMode()) {
return;
}
@@ -3353,6 +3363,7 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
}
stack.getDimBounds(mTmpRect);
adjustRegionInFreefromWindowMode(mTmpRect);
region.op(mTmpRect, Region.Op.INTERSECT);
}