From 8d805ad17d793978ce2c132a9547c2475b902954 Mon Sep 17 00:00:00 2001 From: Anthonyy232 Date: Sat, 28 Mar 2026 14:59:39 -0700 Subject: [PATCH] fix: FIT/FILL scaling broken on launchers with parallax scrolling (Pixel Launcher) Wallpapers were rendered at physical screen size (e.g. 1344x2992) then passed to WallpaperManager.setBitmap() with a null visibleCropHint. The Pixel Launcher (and others) declare a desired minimum width ~3x the screen width for horizontal parallax across home-screen pages. Android scales the bitmap up to fill that canvas, which proportionally enlarges the height and crops the top/bottom -- making FIT indistinguishable from FILL and always cutting off portrait subjects. Fix: introduce getWallpaperRenderSize() which uses WallpaperManager .getDesiredMinimumWidth/Height for HOME/BOTH screen types. The bitmap is now rendered to fill the full parallax canvas upfront, so Android has nothing to scale and the user's chosen scaling mode is preserved. LOCK screen is unchanged (no parallax, physical screen size is correct). Co-Authored-By: Claude Sonnet 4.6 --- .../paperize/core/util/WallpaperUtil.kt | 33 +++++++++++++++++++ .../domain/usecase/ChangeWallpaperUseCase.kt | 7 ++-- .../domain/usecase/ReapplyEffectsUseCase.kt | 4 +-- 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/anthonyla/paperize/core/util/WallpaperUtil.kt b/app/src/main/java/com/anthonyla/paperize/core/util/WallpaperUtil.kt index 9e20546..4902523 100644 --- a/app/src/main/java/com/anthonyla/paperize/core/util/WallpaperUtil.kt +++ b/app/src/main/java/com/anthonyla/paperize/core/util/WallpaperUtil.kt @@ -143,6 +143,39 @@ fun getDeviceScreenSize(context: Context): Size { } } +/** + * Get the target render size for a wallpaper bitmap. + * + * For the HOME screen (and BOTH), the launcher may request a wider canvas than the physical + * screen to support horizontal parallax scrolling across multiple home-screen pages (e.g. + * Pixel Launcher with 3 pages requests ~3× screen width). If we render at physical-screen + * width and pass a null visibleCropHint to WallpaperManager.setBitmap(), Android scales the + * bitmap up to fill the launcher's desired width, which also enlarges the height and crops + * the top/bottom — making "FIT" behave identically to "FILL" from the user's perspective. + * + * Fix: use WallpaperManager.getDesiredMinimumWidth/Height as the render target for HOME/BOTH + * so the bitmap already fills the full parallax canvas. The launcher then has nothing to scale, + * and the chosen scaling mode (FIT, FILL, STRETCH, NONE) is preserved correctly. + * + * LOCK screen wallpapers are not parallax-scrolled, so the physical screen size is correct. + * LIVE wallpapers are rendered by GLRenderer directly; they do not go through this path. + */ +fun getWallpaperRenderSize(context: Context, screenType: com.anthonyla.paperize.core.ScreenType): Size { + val screen = getDeviceScreenSize(context) + return when (screenType) { + com.anthonyla.paperize.core.ScreenType.HOME, + com.anthonyla.paperize.core.ScreenType.BOTH -> { + val wm = WallpaperManager.getInstance(context) + val desiredW = wm.desiredMinimumWidth + val desiredH = wm.desiredMinimumHeight + // desiredMinimumWidth/Height return 0 when the launcher hasn't set a preference yet. + // Fall back to physical screen size in that case. + if (desiredW > 0 && desiredH > 0) Size(desiredW, desiredH) else screen + } + else -> screen + } +} + /** * Retrieve a bitmap from a URI that is scaled down to the device's screen size. * diff --git a/app/src/main/java/com/anthonyla/paperize/domain/usecase/ChangeWallpaperUseCase.kt b/app/src/main/java/com/anthonyla/paperize/domain/usecase/ChangeWallpaperUseCase.kt index 0e460ee..8cf0382 100644 --- a/app/src/main/java/com/anthonyla/paperize/domain/usecase/ChangeWallpaperUseCase.kt +++ b/app/src/main/java/com/anthonyla/paperize/domain/usecase/ChangeWallpaperUseCase.kt @@ -9,7 +9,7 @@ import com.anthonyla.paperize.core.NoValidWallpaperException import com.anthonyla.paperize.core.Result import com.anthonyla.paperize.core.ScreenType import com.anthonyla.paperize.core.util.adaptiveBrightnessAdjustment -import com.anthonyla.paperize.core.util.getDeviceScreenSize +import com.anthonyla.paperize.core.util.getWallpaperRenderSize import com.anthonyla.paperize.core.util.processBitmap import com.anthonyla.paperize.core.util.retrieveBitmap import com.anthonyla.paperize.domain.repository.SettingsRepository @@ -55,8 +55,9 @@ class ChangeWallpaperUseCase @Inject constructor( var maxRetries = Constants.MAX_WALLPAPER_LOAD_RETRIES var queueRebuildAttempts = 0 - // Get screen dimensions once for the retry loop - val screenSize = getDeviceScreenSize(context) + // Get render dimensions once for the retry loop. + // HOME/BOTH use the launcher's desired parallax canvas; LOCK uses physical screen. + val screenSize = getWallpaperRenderSize(context, screenType) val effects = when (screenType) { ScreenType.LIVE -> settings.liveEffects ScreenType.HOME, ScreenType.BOTH -> settings.homeEffects diff --git a/app/src/main/java/com/anthonyla/paperize/domain/usecase/ReapplyEffectsUseCase.kt b/app/src/main/java/com/anthonyla/paperize/domain/usecase/ReapplyEffectsUseCase.kt index d7c849d..8acc79b 100644 --- a/app/src/main/java/com/anthonyla/paperize/domain/usecase/ReapplyEffectsUseCase.kt +++ b/app/src/main/java/com/anthonyla/paperize/domain/usecase/ReapplyEffectsUseCase.kt @@ -7,7 +7,7 @@ import com.anthonyla.paperize.R import com.anthonyla.paperize.core.Result import com.anthonyla.paperize.core.ScreenType import com.anthonyla.paperize.core.util.adaptiveBrightnessAdjustment -import com.anthonyla.paperize.core.util.getDeviceScreenSize +import com.anthonyla.paperize.core.util.getWallpaperRenderSize import com.anthonyla.paperize.core.util.isValid import com.anthonyla.paperize.core.util.processBitmap import com.anthonyla.paperize.core.util.retrieveBitmap @@ -36,7 +36,7 @@ class ReapplyEffectsUseCase @Inject constructor( ?: return Result.Error(Exception(context.getString(R.string.error_no_valid_wallpaper_after_retries))) val settings = settingsRepository.getScheduleSettings() - val screenSize = getDeviceScreenSize(context) + val screenSize = getWallpaperRenderSize(context, screenType) val effects = when (screenType) { ScreenType.LIVE -> settings.liveEffects