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

Commit 4aaebc22 authored by Youkichi Hosoi's avatar Youkichi Hosoi
Browse files

Define new key gesture to toggle fullscreen state of focused task

The new key gesture KEY_GESTURE_TYPE_TOGGLE_FULLSCREEN toggles the
focused task's fullscreen state. See ag/35049859 for the actual logic to
toggle the focused task's fullscreen state in DesktopTasksController.

The key gesture will be mapped from the fullscreen key (under a flag) by
ag/35049860.

Bug: 396483171
Test: atest WmTests:KeyGestureEventTests
Test: atest WMShellUnitTests:DesktopModeKeyGestureHandlerTest
Flag: com.android.window.flags.toggle_fullscreen_state_via_fullscreen_key

Change-Id: I759ee7c95a42d701c55d7cd8ddfc25976d44cd94
parent e3830462
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -134,6 +134,7 @@ public final class KeyGestureEvent {
    public static final int KEY_GESTURE_TYPE_TOGGLE_QUICK_SETTINGS_PANEL = 79;
    public static final int KEY_GESTURE_TYPE_QUIT_FOCUSED_TASK = 80;
    public static final int KEY_GESTURE_TYPE_QUIT_FOCUSED_DESKTOP_TASK = 81;
    public static final int KEY_GESTURE_TYPE_TOGGLE_FULLSCREEN = 82;

    public static final int FLAG_CANCELLED = 1 << 0;
    public static final int FLAG_LONG_PRESS = 1 << 1;
@@ -230,6 +231,7 @@ public final class KeyGestureEvent {
            KEY_GESTURE_TYPE_TOGGLE_QUICK_SETTINGS_PANEL,
            KEY_GESTURE_TYPE_QUIT_FOCUSED_TASK,
            KEY_GESTURE_TYPE_QUIT_FOCUSED_DESKTOP_TASK,
            KEY_GESTURE_TYPE_TOGGLE_FULLSCREEN,
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface KeyGestureType {
@@ -832,6 +834,8 @@ public final class KeyGestureEvent {
                return "KEY_GESTURE_TYPE_QUIT_FOCUSED_TASK";
            case KEY_GESTURE_TYPE_QUIT_FOCUSED_DESKTOP_TASK:
                return "KEY_GESTURE_TYPE_QUIT_FOCUSED_DESKTOP_TASK";
            case KEY_GESTURE_TYPE_TOGGLE_FULLSCREEN:
                return "KEY_GESTURE_TYPE_TOGGLE_FULLSCREEN";
            default:
                return Integer.toHexString(value);
        }
+14 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import com.android.wm.shell.desktopmode.DesktopModeEventLogger.Companion.Minimiz
import com.android.wm.shell.desktopmode.common.ToggleTaskSizeInteraction
import com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_DESKTOP_MODE
import com.android.wm.shell.shared.annotations.ShellMainThread
import com.android.wm.shell.shared.desktopmode.DesktopModeTransitionSource
import com.android.wm.shell.shared.desktopmode.DesktopState
import com.android.wm.shell.transition.FocusTransitionObserver
import com.android.wm.shell.windowdecor.DesktopModeWindowDecorViewModel
@@ -66,6 +67,7 @@ class DesktopModeKeyGestureHandler(
                    KeyGestureEvent.KEY_GESTURE_TYPE_SWITCH_TO_PREVIOUS_DESK,
                    KeyGestureEvent.KEY_GESTURE_TYPE_SWITCH_TO_NEXT_DESK,
                    KeyGestureEvent.KEY_GESTURE_TYPE_QUIT_FOCUSED_DESKTOP_TASK,
                    KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_FULLSCREEN,
                )
            inputManager.registerKeyGestureEventHandler(supportedGestures, this)
        }
@@ -182,6 +184,18 @@ class DesktopModeKeyGestureHandler(
                    desktopModeWindowDecorViewModel.get().closeTask(focusedTask)
                }
            }
            KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_FULLSCREEN -> {
                logV("Key gesture TOGGLE_FULLSCREEN is handled")
                mainExecutor.execute {
                    desktopTasksController
                        .get()
                        .toggleFocusedTaskFullscreenState(
                            displayId = focusTransitionObserver.globallyFocusedDisplayId,
                            userId = desktopUserRepositories.current.userId,
                            transitionSource = DesktopModeTransitionSource.KEYBOARD_SHORTCUT,
                        )
                }
            }
        }
    }

+21 −0
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ import com.android.wm.shell.desktopmode.DesktopTestHelpers.createFreeformTask
import com.android.wm.shell.desktopmode.DesktopTestHelpers.createFullscreenTask
import com.android.wm.shell.desktopmode.common.ToggleTaskSizeInteraction
import com.android.wm.shell.desktopmode.data.DesktopRepository
import com.android.wm.shell.shared.desktopmode.DesktopModeTransitionSource
import com.android.wm.shell.shared.desktopmode.FakeDesktopConfig
import com.android.wm.shell.shared.desktopmode.FakeDesktopState
import com.android.wm.shell.sysui.ShellController
@@ -417,6 +418,26 @@ class DesktopModeKeyGestureHandlerTest : ShellTestCase() {
            .activateNextDesk(displayId, DEFAULT_USER_ID, EnterReason.KEYBOARD_SHORTCUT_ENTER)
    }

    @Test
    fun keyGestureToggleFullscreen_toggleFocusedTaskFullscreenState() {
        val displayId = 2
        whenever(focusTransitionObserver.globallyFocusedDisplayId).thenReturn(displayId)
        val event =
            KeyGestureEvent.Builder()
                .setKeyGestureType(KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_FULLSCREEN)
                .build()

        keyGestureEventHandler.handleKeyGestureEvent(event, null)
        testExecutor.flushAll()

        verify(desktopTasksController)
            .toggleFocusedTaskFullscreenState(
                displayId = displayId,
                userId = repository.userId,
                transitionSource = DesktopModeTransitionSource.KEYBOARD_SHORTCUT,
            )
    }

    private fun setUpDesktopTask(
        displayId: Int = DEFAULT_DISPLAY,
        bounds: Rect? = null,