From 288e705c43a9a9a610b1be8dda88b77fccedef84 Mon Sep 17 00:00:00 2001 From: Ajinkya Chalke Date: Wed, 23 Apr 2025 08:50:42 +0000 Subject: [PATCH] Dismiss KQS when focused display changes - When focused display changes, the KQS view doesn't receive any KeyEvents thus the view remains open even if user clicks or hits Esc while on a different display. - Use FocusState to dismiss KQS if the displayId changes. Bug: 382762871 Flag: com.android.launcher3.enable_alt_tab_kqs_on_connected_displays Test: m Change-Id: Ic34a2bc7863575449e5b5c88377da8b1a8d48c20 --- .../launcher3/taskbar/KeyboardQuickSwitchView.java | 9 +++++++++ .../taskbar/KeyboardQuickSwitchViewController.java | 10 +++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchView.java b/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchView.java index 693fe9cc8f..0026396b17 100644 --- a/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchView.java +++ b/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchView.java @@ -18,6 +18,7 @@ package com.android.launcher3.taskbar; import static androidx.constraintlayout.widget.ConstraintLayout.LayoutParams.PARENT_ID; import static com.android.launcher3.taskbar.TaskbarDesktopExperienceFlags.enableAltTabKqsFlatenning; +import static com.android.launcher3.taskbar.TaskbarDesktopExperienceFlags.enableAltTabKqsOnConnectedDisplays; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; @@ -54,6 +55,7 @@ import com.android.launcher3.Utilities; import com.android.launcher3.anim.AnimatedFloat; import com.android.launcher3.testing.TestLogging; import com.android.launcher3.testing.shared.TestProtocol; +import com.android.quickstep.SystemUiProxy; import com.android.quickstep.util.DesktopTask; import com.android.quickstep.util.GroupTask; import com.android.quickstep.util.SingleTask; @@ -450,6 +452,9 @@ public class KeyboardQuickSwitchView extends ConstraintLayout { // Unregister the back invoked callback after the view is closed and before the // mViewCallbacks is reset. unregisterOnBackInvokedCallback(); + if (enableAltTabKqsOnConnectedDisplays.isTrue()) { + SystemUiProxy.INSTANCE.get(getContext()).getFocusState().removeListener(mViewCallbacks); + } mViewCallbacks = null; } @@ -616,6 +621,10 @@ public class KeyboardQuickSwitchView extends ConstraintLayout { displayedContent.setVisibility(VISIBLE); setVisibility(VISIBLE); requestFocus(); + if (enableAltTabKqsOnConnectedDisplays.isTrue()) { + SystemUiProxy.INSTANCE.get(getContext()).getFocusState().addListener( + mViewCallbacks); + } } @Override diff --git a/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchViewController.java b/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchViewController.java index fdd0887a5a..7616ebd8d0 100644 --- a/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchViewController.java +++ b/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchViewController.java @@ -43,6 +43,7 @@ import com.android.launcher3.desktop.DesktopAppLaunchTransition; import com.android.launcher3.taskbar.overlay.TaskbarOverlayContext; import com.android.launcher3.taskbar.overlay.TaskbarOverlayDragLayer; import com.android.launcher3.views.BaseDragLayer; +import com.android.quickstep.FocusState; import com.android.quickstep.SystemUiProxy; import com.android.quickstep.util.DesktopTask; import com.android.quickstep.util.GroupTask; @@ -382,7 +383,7 @@ public class KeyboardQuickSwitchViewController { return dl.isEventOverView(mKeyboardQuickSwitchView, ev); } - class ViewCallbacks { + class ViewCallbacks implements FocusState.FocusChangeListener { public final OnBackInvokedCallback onBackInvokedCallback = () -> closeQuickSwitchView(true); boolean onKeyUp(int keyCode, KeyEvent event, boolean isRTL, boolean allowTraversal) { @@ -453,5 +454,12 @@ public class KeyboardQuickSwitchViewController { closeQuickSwitchView(false); mDetachingFromWindow = false; } + + @Override + public void onFocusedDisplayChanged(int displayId) { + if (mControllers.taskbarActivityContext.getDisplayId() != displayId) { + closeQuickSwitchView(/* animate= */ true); + } + } } }