1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.systemui.keyboard.shortcut.data.source 18 19 import android.content.Context 20 import android.content.res.Resources 21 import android.view.KeyEvent.KEYCODE_D 22 import android.view.KeyEvent.KEYCODE_DPAD_DOWN 23 import android.view.KeyEvent.KEYCODE_DPAD_LEFT 24 import android.view.KeyEvent.KEYCODE_DPAD_RIGHT 25 import android.view.KeyEvent.KEYCODE_DPAD_UP 26 import android.view.KeyEvent.KEYCODE_EQUALS 27 import android.view.KeyEvent.KEYCODE_LEFT_BRACKET 28 import android.view.KeyEvent.KEYCODE_MINUS 29 import android.view.KeyEvent.KEYCODE_RIGHT_BRACKET 30 import android.view.KeyEvent.META_CTRL_ON 31 import android.view.KeyEvent.META_META_ON 32 import android.view.KeyboardShortcutGroup 33 import android.window.DesktopModeFlags 34 import com.android.systemui.dagger.qualifiers.Application 35 import com.android.systemui.dagger.qualifiers.Main 36 import com.android.systemui.keyboard.shortcut.data.model.shortcutInfo 37 import com.android.systemui.res.R 38 import com.android.window.flags.Flags.enableMoveToNextDisplayShortcut 39 import com.android.wm.shell.shared.desktopmode.DesktopModeStatus 40 import javax.inject.Inject 41 42 class MultitaskingShortcutsSource 43 @Inject 44 constructor(@Main private val resources: Resources, @Application private val context: Context) : 45 KeyboardShortcutGroupsSource { 46 shortcutGroupsnull47 override suspend fun shortcutGroups(deviceId: Int) = 48 listOf( 49 KeyboardShortcutGroup( 50 resources.getString(R.string.shortcutHelper_category_split_screen), 51 splitScreenShortcuts(), 52 ) 53 ) 54 55 private fun splitScreenShortcuts() = buildList { 56 // Enter Split screen with current app to RHS: 57 // - Meta + Ctrl + Right arrow 58 add( 59 shortcutInfo(resources.getString(R.string.system_multitasking_rhs)) { 60 command(META_META_ON or META_CTRL_ON, KEYCODE_DPAD_RIGHT) 61 } 62 ) 63 // Enter Split screen with current app to LHS: 64 // - Meta + Ctrl + Left arrow 65 add( 66 shortcutInfo(resources.getString(R.string.system_multitasking_lhs)) { 67 command(META_META_ON or META_CTRL_ON, KEYCODE_DPAD_LEFT) 68 } 69 ) 70 // Switch from Split screen to full screen: 71 // - Meta + Ctrl + Up arrow 72 add( 73 shortcutInfo(resources.getString(R.string.system_multitasking_full_screen)) { 74 command(META_META_ON or META_CTRL_ON, KEYCODE_DPAD_UP) 75 } 76 ) 77 if (DesktopModeStatus.canEnterDesktopMode(context)) { 78 // Switch to desktop view 79 // - Meta + Ctrl + Down arrow 80 add( 81 shortcutInfo(resources.getString(R.string.system_multitasking_desktop_view)) { 82 command(META_META_ON or META_CTRL_ON, KEYCODE_DPAD_DOWN) 83 } 84 ) 85 } 86 if (enableMoveToNextDisplayShortcut()) { 87 // Move a window to the next display: 88 // - Meta + Ctrl + D 89 add( 90 shortcutInfo( 91 resources.getString(R.string.system_multitasking_move_to_next_display) 92 ) { 93 command(META_META_ON or META_CTRL_ON, KEYCODE_D) 94 } 95 ) 96 } 97 if ( 98 DesktopModeStatus.canEnterDesktopMode(context) && 99 DesktopModeFlags.ENABLE_TASK_RESIZING_KEYBOARD_SHORTCUTS.isTrue 100 ) { 101 // Snap a freeform window to the left 102 // - Meta + Left bracket 103 add( 104 shortcutInfo(resources.getString(R.string.system_desktop_mode_snap_left_window)) { 105 command(META_META_ON, KEYCODE_LEFT_BRACKET) 106 } 107 ) 108 // Snap a freeform window to the right 109 // - Meta + Right bracket 110 add( 111 shortcutInfo(resources.getString(R.string.system_desktop_mode_snap_right_window)) { 112 command(META_META_ON, KEYCODE_RIGHT_BRACKET) 113 } 114 ) 115 // Toggle maximize a freeform window 116 // - Meta + Equals 117 add( 118 shortcutInfo( 119 resources.getString(R.string.system_desktop_mode_toggle_maximize_window) 120 ) { 121 command(META_META_ON, KEYCODE_EQUALS) 122 } 123 ) 124 // Minimize a freeform window 125 // - Meta + Minus 126 add( 127 shortcutInfo(resources.getString(R.string.system_desktop_mode_minimize_window)) { 128 command(META_META_ON, KEYCODE_MINUS) 129 } 130 ) 131 } 132 } 133 } 134