Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit faa4bda6 authored by Daichi Hirono's avatar Daichi Hirono
Browse files

Add keyboard shortcut to close focused task

This CL introduces a keyboard shortcut (Action+Ctrl+W) to close the
currently focused task, in addtion to the existing long press ESC. This
provides users with a quick way to dismiss applications using the
keyboard.

The feature is controlled by the `close_task_keyboard_shortcut` flag.

Bug: 416437920
Test: adb shell am start -n com.google.android.calculator/com.android.calculator2.Calculator && sleep 2 && adb shell input keycombination KEYCODE_META_LEFT KEYCODE_CTRL_LEFT KEYCODE_W
Flag: com.android.window.flags.close_task_keyboard_shortcut
Change-Id: Ief8dbc45f592bdd4f2b9b2c212c6deb824d736ae
parent 9cebcbfa
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -58,6 +58,8 @@ public enum DesktopExperienceFlags {
    BASE_DENSITY_FOR_EXTERNAL_DISPLAYS(
            com.android.server.display.feature.flags.Flags::baseDensityForExternalDisplays, true,
            com.android.server.display.feature.flags.Flags.FLAG_BASE_DENSITY_FOR_EXTERNAL_DISPLAYS),
    CLOSE_TASK_KEYBOARD_SHORTCUT(Flags::closeTaskKeyboardShortcut, false,
            Flags.FLAG_CLOSE_TASK_KEYBOARD_SHORTCUT),
    CONNECTED_DISPLAYS_CURSOR(com.android.input.flags.Flags::connectedDisplaysCursor, true,
            com.android.input.flags.Flags.FLAG_CONNECTED_DISPLAYS_CURSOR),
    DISPLAY_TOPOLOGY(com.android.server.display.feature.flags.Flags::displayTopology, true,
+9 −0
Original line number Diff line number Diff line
@@ -315,6 +315,15 @@ final class InputGestureManager {
                            /* allowCaptureByFocusedWindow = */false
                    ));
        }
        if (DesktopExperienceFlags.CLOSE_TASK_KEYBOARD_SHORTCUT.isTrue()) {
            systemShortcuts.add(
                    createKeyGesture(
                            KeyEvent.KEYCODE_W,
                            KeyEvent.META_META_ON | KeyEvent.META_CTRL_ON,
                            KeyGestureEvent.KEY_GESTURE_TYPE_QUIT_FOCUSED_TASK,
                            /* allowCaptureByFocusedWindow = */false
                    ));
        }
        if (enableQuickSettingsPanelShortcut()) {
            systemShortcuts.add(
                    createKeyGesture(
+4 −3
Original line number Diff line number Diff line
@@ -99,6 +99,7 @@ import org.mockito.kotlin.times
    com.android.hardware.input.Flags.FLAG_KEYBOARD_A11Y_SHORTCUT_CONTROL,
    com.android.hardware.input.Flags.FLAG_ENABLE_TALKBACK_AND_MAGNIFIER_KEY_GESTURES,
    com.android.hardware.input.Flags.FLAG_ENABLE_VOICE_ACCESS_KEY_GESTURES,
    com.android.window.flags.Flags.FLAG_CLOSE_TASK_KEYBOARD_SHORTCUT,
    com.android.window.flags.Flags.FLAG_ENABLE_MOVE_TO_NEXT_DISPLAY_SHORTCUT,
    com.android.window.flags.Flags.FLAG_ENABLE_TASK_RESIZING_KEYBOARD_SHORTCUTS,
    com.android.window.flags.Flags.FLAG_KEYBOARD_SHORTCUTS_TO_SWITCH_DESKS,
@@ -1283,7 +1284,7 @@ class KeyGestureControllerTests {
        )
        sendKeys(
            intArrayOf(KeyEvent.KEYCODE_ESCAPE),
            timeDelayMs = 2 * LONG_PRESS_DELAY_FOR_ESCAPE_MILLIS
            timeDelayMs = 2 * LONG_PRESS_DELAY_FOR_ESCAPE_MILLIS,
        )
        keyGestureController.unregisterKeyGestureHandler(handler, TEST_PID)
        assertEquals(1, callback)
@@ -1301,7 +1302,7 @@ class KeyGestureControllerTests {
        )
        sendKeys(
            intArrayOf(KeyEvent.KEYCODE_ESCAPE),
            timeDelayMs = 2 * LONG_PRESS_DELAY_FOR_ESCAPE_MILLIS
            timeDelayMs = 2 * LONG_PRESS_DELAY_FOR_ESCAPE_MILLIS,
        )
        keyGestureController.unregisterKeyGestureHandler(handler, TEST_PID)
        assertEquals(0, callback)
@@ -1320,7 +1321,7 @@ class KeyGestureControllerTests {
        )
        sendKeys(
            intArrayOf(KeyEvent.KEYCODE_ESCAPE),
            timeDelayMs = LONG_PRESS_DELAY_FOR_ESCAPE_MILLIS / 2
            timeDelayMs = LONG_PRESS_DELAY_FOR_ESCAPE_MILLIS / 2,
        )
        keyGestureController.unregisterKeyGestureHandler(handler, TEST_PID)
        assertEquals(0, callback)
+12 −0
Original line number Diff line number Diff line
@@ -165,6 +165,18 @@ object KeyGestureTestData {
                KeyEvent.META_META_ON or KeyEvent.META_CTRL_ON,
                intArrayOf(KeyGestureEvent.ACTION_GESTURE_COMPLETE),
            ),
            KeyGestureData(
                "META + CTRL + W -> Quit focused task",
                intArrayOf(
                    KeyEvent.KEYCODE_META_LEFT,
                    KeyEvent.KEYCODE_CTRL_LEFT,
                    KeyEvent.KEYCODE_W,
                ),
                KeyGestureEvent.KEY_GESTURE_TYPE_QUIT_FOCUSED_TASK,
                intArrayOf(KeyEvent.KEYCODE_W),
                KeyEvent.META_META_ON or KeyEvent.META_CTRL_ON,
                intArrayOf(KeyGestureEvent.ACTION_GESTURE_COMPLETE),
            ),
            KeyGestureData(
                "META + [ -> Resizes a task to fit the left half of the screen",
                intArrayOf(KeyEvent.KEYCODE_META_LEFT, KeyEvent.KEYCODE_LEFT_BRACKET),