feat(workspace): Add "Set as default page" option (#6395)

Allow users to designate any workspace page as the default home page
via long-press popup menu. Pressing HOME navigates to the chosen page
instead of always page 0. Resets to page 0 if the default page is deleted.
This commit is contained in:
Paul
2026-02-22 03:37:13 -06:00
committed by GitHub
parent d912e4399a
commit 0f0a75726d
6 changed files with 79 additions and 4 deletions

View File

@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="#000000">
<path
android:fillColor="@android:color/white"
android:pathData="M360,520L440,520L440,410L520,410L520,520L600,520L600,330L480,250L360,330L360,520ZM480,774Q602,662 661,570.5Q720,479 720,408Q720,299 650.5,229.5Q581,160 480,160Q379,160 309.5,229.5Q240,299 240,408Q240,479 299,570.5Q358,662 480,774ZM452,848Q438,843 427,833Q362,773 312,716Q262,659 228.5,605.5Q195,552 177.5,502.5Q160,453 160,408Q160,258 256.5,169Q353,80 480,80Q607,80 703.5,169Q800,258 800,408Q800,453 782.5,502.5Q765,552 731.5,605.5Q698,659 648,716Q598,773 533,833Q522,843 508,848Q494,853 480,853Q466,853 452,848ZM480,400Q480,400 480,400Q480,400 480,400Q480,400 480,400Q480,400 480,400Q480,400 480,400Q480,400 480,400Q480,400 480,400Q480,400 480,400Z"/>
</vector>

View File

@@ -656,6 +656,9 @@
<string name="home_screen_locked">Home screen is locked</string>
<string name="home_screen_lock_description">Prevent changes to the home screen layout</string>
<string name="set_default_home_page">Set as default page</string>
<string name="default_home_page_set">Default home page updated</string>
<string name="popup_menu">Pop-up menu</string>
<string name="popup_menu_items">Pop-up menu items</string>
<string name="edit_menu_items">Edit pop-up menu items</string>

View File

@@ -59,6 +59,7 @@ import com.android.launcher3.LauncherAppState
import com.android.launcher3.LauncherPrefs
import com.android.launcher3.LauncherPrefs.Companion.ENABLE_TWOLINE_ALLAPPS_TOGGLE
import com.android.launcher3.R
import com.android.launcher3.Workspace
import com.android.launcher3.dagger.ApplicationContext
import com.android.launcher3.dagger.LauncherAppComponent
import com.android.launcher3.dagger.LauncherAppSingleton
@@ -345,6 +346,11 @@ class PreferenceManager2 @Inject constructor(
defaultValue = context.resources.getBoolean(R.bool.config_default_lock_home_screen),
)
val defaultHomePage = preference(
key = intPreferencesKey(name = "default_home_page"),
defaultValue = Workspace.DEFAULT_PAGE,
)
val legacyPopupOptionsMigrated = preference(
key = booleanPreferencesKey(name = "legacy_popup_options_migrated"),
defaultValue = false,

View File

@@ -1,6 +1,7 @@
package app.lawnchair.ui.popup
import android.view.View
import android.widget.Toast
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import app.lawnchair.preferences2.PreferenceManager2.Companion.getInstance
@@ -23,6 +24,7 @@ object LauncherOptionsPopup {
LauncherOptionPopupItem("all_apps", true),
LauncherOptionPopupItem("home_settings", true),
LauncherOptionPopupItem("sys_settings", false),
LauncherOptionPopupItem("default_page", true),
)
fun restoreMissingPopupOptions(
@@ -39,7 +41,7 @@ object LauncherOptionsPopup {
}
prefs2.launcherPopupOrder.setBlocking(
(missingItems + currentOptions).toOptionOrderString(),
(currentOptions + missingItems).toOptionOrderString(),
)
}
@@ -123,6 +125,13 @@ object LauncherOptionsPopup {
LauncherEvent.LAUNCHER_SETTINGS_BUTTON_TAP_OR_LONGPRESS,
onStartHomeSettings,
),
"default_page" to OptionItem(
launcher,
R.string.set_default_home_page,
R.drawable.ic_home_pin,
LauncherEvent.IGNORE,
::setAsDefaultHomePage,
),
)
val options = ArrayList<OptionItem>()
@@ -137,12 +146,21 @@ object LauncherOptionsPopup {
true
}
}
.filter { it.identifier != "default_page" || !launcher.workspace.isCurrentPageDefault }
.mapNotNull { optionsList[it.identifier] }
.forEach { options.add(it) }
return options
}
private fun setAsDefaultHomePage(v: View): Boolean {
val launcher = Launcher.getLauncher(v.context)
val currentPage = launcher.workspace.getNextPage()
launcher.workspace.setDefaultPage(currentPage)
Toast.makeText(launcher, R.string.default_home_page_set, Toast.LENGTH_SHORT).show()
return true
}
fun getMetadataForOption(identifier: String): LauncherOptionMetadata {
return when (identifier) {
"carousel" -> LauncherOptionMetadata(
@@ -186,6 +204,11 @@ object LauncherOptionsPopup {
icon = R.drawable.ic_home_screen,
)
"default_page" -> LauncherOptionMetadata(
label = R.string.set_default_home_page,
icon = R.drawable.ic_home_pin,
)
else -> throw IllegalArgumentException("invalid popup option")
}
}

View File

@@ -1596,7 +1596,7 @@ public class Launcher extends StatefulActivity<LauncherState>
}
if (shouldMoveToDefaultScreen && !mWorkspace.isHandlingTouch()) {
if (mWorkspace.getNextPage() != Workspace.DEFAULT_PAGE) {
if (mWorkspace.getNextPage() != mWorkspace.getDefaultPage()) {
mWorkspace.post(mWorkspace::moveToDefaultScreen);
} else {
handleHomeTap();

View File

@@ -598,7 +598,7 @@ public class Workspace<T extends View & PageIndicator> extends PagedView<T>
* Initializes various states for this workspace.
*/
protected void initWorkspace() {
mCurrentPage = DEFAULT_PAGE;
mCurrentPage = getDefaultPage();
setClipToPadding(false);
setupLayoutTransition();
@@ -1152,6 +1152,12 @@ public class Workspace<T extends View & PageIndicator> extends PagedView<T>
// Now that we have removed some pages, ensure state description is up to date.
updateAccessibilityViewPageDescription();
// Reset default home page if it's now out of range after page removal
int storedDefault = PreferenceExtensionsKt.firstBlocking(mPreferenceManager2.getDefaultHomePage());
if (storedDefault >= getChildCount()) {
setDefaultPage(DEFAULT_PAGE);
}
}
/**
@@ -3536,7 +3542,7 @@ public class Workspace<T extends View & PageIndicator> extends PagedView<T>
* Calls {@link #snapToPage(int)} on the {@link #DEFAULT_PAGE}, then requests focus on it.
*/
public void moveToDefaultScreen() {
int page = DEFAULT_PAGE;
int page = getDefaultPage();
if (!workspaceInModalState() && getNextPage() != page) {
snapToPage(page);
}
@@ -3546,6 +3552,33 @@ public class Workspace<T extends View & PageIndicator> extends PagedView<T>
}
}
/**
* Returns the validated default home page index from user preferences.
* Falls back to {@link #DEFAULT_PAGE} if the stored page is out of range.
*/
public int getDefaultPage() {
int storedPage = PreferenceExtensionsKt.firstBlocking(mPreferenceManager2.getDefaultHomePage());
int pageCount = getChildCount();
if (storedPage >= 0 && storedPage < pageCount) {
return storedPage;
}
return DEFAULT_PAGE;
}
/**
* Sets the given page index as the default home page.
*/
public void setDefaultPage(int pageIndex) {
PreferenceExtensionsKt.setBlocking(mPreferenceManager2.getDefaultHomePage(), pageIndex);
}
/**
* Returns true if the current page is the default home page.
*/
public boolean isCurrentPageDefault() {
return getNextPage() == getDefaultPage();
}
/**
* Set the given view's pivot point to match the workspace's, so that it scales together. Since
* both this view and workspace can move, transform the point manually instead of using