Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 64 additions & 23 deletions composeApp/src/commonMain/kotlin/com/maxrave/simpmusic/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
Expand Down Expand Up @@ -73,6 +73,7 @@ import com.maxrave.simpmusic.expect.openUrl
import com.maxrave.simpmusic.expect.ui.layerBackdrop
import com.maxrave.simpmusic.expect.ui.rememberBackdrop
import com.maxrave.simpmusic.extension.copy
import com.maxrave.simpmusic.extension.getScreenSizeInfo
import com.maxrave.simpmusic.ui.component.AppBottomNavigationBar
import com.maxrave.simpmusic.ui.component.AppNavigationRail
import com.maxrave.simpmusic.ui.component.DesktopSidebar
Expand All @@ -82,6 +83,7 @@ import com.maxrave.simpmusic.ui.component.LocalNowPlayingOpen
import com.maxrave.simpmusic.ui.component.LocalUserStarted
import com.maxrave.simpmusic.ui.icon.ArrowForwardIos
import com.maxrave.simpmusic.ui.icon.SimpIcons
import com.maxrave.simpmusic.ui.screen.DesktopCapsuleMaxWidth
import com.maxrave.simpmusic.ui.navigation.destination.home.AnalyticsDestination
import com.maxrave.simpmusic.ui.navigation.destination.home.HomeDestination
import com.maxrave.simpmusic.ui.navigation.destination.home.NotificationDestination
Expand Down Expand Up @@ -143,6 +145,18 @@ import simpmusic.composeapp.generated.resources.update_message
import simpmusic.composeapp.generated.resources.yes
import kotlin.time.ExperimentalTime

/** Below this width the Desktop sidebar folds so Home / Library keep a usable column. */
private const val DESKTOP_SIDEBAR_AUTO_COLLAPSE_WIDTH_DP = 1100

/**
* Below this width the side Now Playing panel yields to the fullscreen player overlay — a 13"
* MacBook in split view cannot host sidebar + content + 35% player at once.
*/
private const val DESKTOP_SIDE_NOW_PLAYING_MIN_WIDTH_DP = 960

/** Floor left for the content panel beside an open Desktop Now Playing card. */
private val DESKTOP_MIN_CONTENT_BESIDE_NP = 360.dp

@OptIn(ExperimentalMaterial3Api::class, ExperimentalTime::class, ExperimentalFoundationApi::class)
@Composable
fun App(
Expand Down Expand Up @@ -508,6 +522,19 @@ fun App(
}
val isTablet = windowSize.isWidthAtLeastBreakpoint(WIDTH_DP_MEDIUM_LOWER_BOUND)
val isTabletLandscape = isTablet && currentOrientation() == Orientation.LANDSCAPE
// Desktop shell on a MacBook (split view, zoomed, or a half-screen window) needs its own
// breakpoints: the Material tablet ones alone still leave an expanded 280dp sidebar and a
// 35% Now Playing panel fighting over the leftover strip.
val desktopWindowWidthDp = if (isDesktopShell) getScreenSizeInfo().wDP else Int.MAX_VALUE
val forceSidebarCollapsed = isDesktopShell && desktopWindowWidthDp < DESKTOP_SIDEBAR_AUTO_COLLAPSE_WIDTH_DP
// Whether this window *can* host the side Now Playing card (width + orientation). Fullscreen
// gates the card separately so a landscape fullscreen session does not fall through to the
// overlay the way a too-narrow Desktop window should.
val canHostSideNowPlaying =
isTablet &&
isTabletLandscape &&
(!isDesktopShell || desktopWindowWidthDp >= DESKTOP_SIDE_NOW_PLAYING_MIN_WIDTH_DP)
val useSideNowPlaying = canHostSideNowPlaying && !isInFullscreen

AppTheme(
themeMode = themeMode,
Expand Down Expand Up @@ -645,20 +672,20 @@ fun App(
bottom = 4.dp,
)
} else {
// Floating capsule, Apple Music style: a fixed size so it never
// stretches to the window width, and no haze at all — the capsule
// paints its own liquid glass. Layering haze underneath blurs the
// same pixels twice and reads as a dark smear, not glass.
// padding BEFORE height: the other way round the bottom margin
// eats into the 72dp and the capsule ends up 52dp tall.
// 60dp is the floor for this layout: the content row is centred
// on the capsule's axis and the 16dp progress box hangs off the
// bottom, so the height has to cover the taller of the artwork
// (32dp) and the two text lines (~33dp), plus that 16dp, plus a
// gap. Going lower means shrinking the artwork again.
// Floating capsule, Apple Music style. Cap at the full three-cluster
// width and fill what the content strip has left, so a resized
// MacBook window shrinks the pill instead of letting it spill past
// the sidebar / Now Playing edge. No haze — the capsule paints its
// own liquid glass; layering haze underneath blurs the same pixels
// twice and reads as a dark smear. padding BEFORE height: the other
// way round the bottom margin eats into the 60dp. That height is the
// floor: artwork 32dp / two text lines ~33dp, plus the 16dp progress
// box hung off the bottom.
Modifier
.wrapContentWidth()
.padding(horizontal = 20.dp)
.padding(bottom = 20.dp)
.widthIn(max = DesktopCapsuleMaxWidth)
.fillMaxWidth()
.height(60.dp)
},
backdrop = backdrop,
Expand Down Expand Up @@ -710,6 +737,7 @@ fun App(
containerColor = desktopPanel,
showAnalyticsTab = showAnalyticsTab,
showMixForYouTab = showMixForYouTab,
forceCollapsed = forceSidebarCollapsed,
// No end padding: the content panel's own 8dp is the gap between the two.
modifier = Modifier.padding(start = 8.dp, top = 8.dp, bottom = 8.dp),
) { klass ->
Expand Down Expand Up @@ -789,7 +817,7 @@ fun App(
tabletMiniPlayer(Modifier.padding(innerPadding).align(Alignment.BottomCenter))
}
}
if (isTablet && isTabletLandscape && !isInFullscreen) {
if (useSideNowPlaying) {
AnimatedVisibility(
isShowNowPlaylistScreen,
enter = expandHorizontally() + fadeIn(),
Expand All @@ -798,17 +826,30 @@ fun App(
Row(
Modifier
.fillMaxHeight()
// The width Now Playing has always had: `fillMaxWidth(0.35f)` of what the
// 80dp NavigationRail left in this Row. The rail and the sidebar now sit
// inside the weighted Box, so that share is taken by hand from the Row's
// own width; otherwise it would follow the sidebar. On Desktop it is 8dp
// less, the spacer it no longer has, so the card keeps its exact size.
// Preferred width is still `fillMaxWidth(0.35f)` of what the
// 80dp NavigationRail left in this Row. On a narrow Desktop
// window that share is clamped so the content panel keeps at
// least [DESKTOP_MIN_CONTENT_BESIDE_NP], otherwise the Home
// cards and the capsule crush into a strip.
.layout { measurable, constraints ->
val width =
val full = constraints.maxWidth
val preferred =
(
((constraints.maxWidth - 80.dp.roundToPx()) * 0.35f).roundToInt() -
((full - 80.dp.roundToPx()) * 0.35f).roundToInt() -
if (isDesktopShell) 8.dp.roundToPx() else 0
).coerceIn(0, constraints.maxWidth)
)
val width =
if (isDesktopShell) {
val sidebarDp = if (forceSidebarCollapsed) 72 else 280
val reservedLeft =
(sidebarDp + 8).dp.roundToPx() +
DESKTOP_MIN_CONTENT_BESIDE_NP.roundToPx() +
16.dp.roundToPx()
val maxNp = (full - reservedLeft).coerceAtLeast(280.dp.roundToPx())
preferred.coerceIn(280.dp.roundToPx(), maxNp)
} else {
preferred
}.coerceIn(0, full)
val placeable = measurable.measure(constraints.copy(minWidth = width, maxWidth = width))
layout(placeable.width, placeable.height) { placeable.placeRelative(0, 0) }
},
Expand Down Expand Up @@ -860,7 +901,7 @@ fun App(
}
}

if (isShowNowPlaylistScreen && !isTabletLandscape) {
if (isShowNowPlaylistScreen && !canHostSideNowPlaying) {
ForceDarkContent {
NowPlayingScreen(
navController = navController,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ fun DesktopSidebar(
showAnalyticsTab: Boolean,
showMixForYouTab: Boolean,
modifier: Modifier = Modifier,
/**
* When the window is too narrow for a 280dp library column (MacBook split view / resized),
* fold visually without rewriting the stored preference — widening the window restores it.
* The user can still expand while forced; that override clears once the window is wide again.
*/
forceCollapsed: Boolean = false,
viewModel: LibrarySidebarViewModel = koinViewModel(),
reloadDestinationIfNeeded: (KClass<*>) -> Unit = { _ -> },
) {
Expand Down Expand Up @@ -197,7 +203,12 @@ fun DesktopSidebar(
// The library sources are one-shot reads, not observed queries, so the list is read again whenever
// the user moves between screens, which is where a like, follow or new playlist happens.
LaunchedEffect(currentBackStackEntry?.id) { viewModel.refresh() }
val collapsed by viewModel.collapsed.collectAsStateWithLifecycle()
val collapsedPref by viewModel.collapsed.collectAsStateWithLifecycle()
var expandWhileForced by rememberSaveable { mutableStateOf(false) }
LaunchedEffect(forceCollapsed) {
if (!forceCollapsed) expandWhileForced = false
}
val collapsed = (collapsedPref || forceCollapsed) && !(forceCollapsed && expandWhileForced)
val overview by viewModel.overview.collectAsStateWithLifecycle()
val libraryItems by viewModel.items.collectAsStateWithLifecycle()
val playingQueueId by viewModel.playingQueueId.collectAsStateWithLifecycle()
Expand Down Expand Up @@ -349,7 +360,11 @@ fun DesktopSidebar(
onToggle = {
searching = false
query = ""
viewModel.setCollapsed(!collapsed)
if (forceCollapsed) {
expandWhileForced = !expandWhileForced
} else {
viewModel.setCollapsed(!collapsedPref)
}
},
onStartSearch = { searching = true },
onQueryChange = { query = it },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.collectIsHoveredAsState
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
Expand All @@ -45,6 +46,7 @@ import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.foundation.layout.wrapContentWidth
Expand Down Expand Up @@ -154,6 +156,13 @@ import kotlin.math.roundToLong

private const val TAG = "MiniPlayer"

/**
* Widest the Desktop floating capsule grows to: transport 200 + dividers + track 300 + action
* cluster. Callers cap with [widthIn] so a narrower MacBook window / split view shrinks it instead
* of letting it spill past the content panel.
*/
internal val DesktopCapsuleMaxWidth = 822.dp

@OptIn(ExperimentalFoundationApi::class, ExperimentalMaterial3Api::class)
@Composable
fun MiniPlayer(
Expand Down Expand Up @@ -644,13 +653,14 @@ fun MiniPlayer(
)
}
// Apple Music-style floating capsule: transport on the left, the track and its slim
// progress slider in the middle, the action cluster on the right. Size and placement come
// from the caller (App.kt), so the capsule keeps a fixed width and floats over content.
// Without glass it is an opaque theme surface, the Android flat card's colour; a haze blur
// instead gives a dark smear rather than a floating pill.
// progress slider in the middle, the action cluster on the right. The caller (App.kt) caps
// width at [DesktopCapsuleMaxWidth] and fills what is left of the content strip, so a
// resized MacBook window shrinks the capsule instead of letting it overflow. Without glass
// it is an opaque theme surface; a haze blur instead gives a dark smear rather than a
// floating pill.
val capsuleShape = RoundedCornerShape(50)
val density = LocalDensity.current
Box(
BoxWithConstraints(
modifier
.then(
if (useGlassSurface) {
Expand All @@ -664,8 +674,15 @@ fun MiniPlayer(
},
contentAlignment = Alignment.Center,
) {
// Drop secondary chrome before the track title: PiP first, then queue. Controls and
// mute/close stay — a capsule that cannot pause is useless.
val showPipButton = maxWidth >= 700.dp
val showQueueButton = maxWidth >= 560.dp
val controlsWidth = if (maxWidth < 520.dp) 160.dp else 200.dp
val dividerPad = if (maxWidth < 600.dp) 8.dp else 14.dp
Row(
Modifier
.fillMaxWidth()
.fillMaxHeight()
// No vertical padding: the progress line is bottom-aligned inside its own 16dp
// touch box, so the line already floats 8dp above whatever the bottom edge is.
Expand All @@ -678,7 +695,7 @@ fun MiniPlayer(
// button, so it consumes whatever width it is handed. The old layout kept it in check
// with Column(width = 600.dp); inside a capsule it must be boxed to a fixed width or
// it spreads across the whole bar and pushes the other two clusters out of view.
Box(Modifier.width(200.dp)) {
Box(Modifier.width(controlsWidth)) {
PlayerControlLayout(
controllerState,
isSmallSize = true,
Expand All @@ -693,7 +710,7 @@ fun MiniPlayer(
}
}
VerticalDivider(
modifier = Modifier.height(28.dp).padding(horizontal = 14.dp),
modifier = Modifier.height(28.dp).padding(horizontal = dividerPad),
color = textColor.copy(alpha = 0.2f),
)
// The whole track cluster is the hover target, not the progress line itself:
Expand All @@ -717,7 +734,8 @@ fun MiniPlayer(
Box(
modifier =
Modifier
.width(300.dp)
.weight(1f)
.widthIn(min = 100.dp)
.fillMaxHeight()
.hoverable(trackInteraction),
) {
Expand Down Expand Up @@ -965,7 +983,7 @@ fun MiniPlayer(
)
}
VerticalDivider(
modifier = Modifier.height(28.dp).padding(horizontal = 14.dp),
modifier = Modifier.height(28.dp).padding(horizontal = dividerPad),
color = textColor.copy(alpha = 0.2f),
)
Row(verticalAlignment = Alignment.CenterVertically) {
Expand All @@ -978,19 +996,21 @@ fun MiniPlayer(
sharedViewModel.onUIEvent(UIEvent.ToggleLike)
}
}
IconButton(
onClick = {
showQueueBottomSheet = true
},
) {
Icon(
imageVector = SimpIcons.QueueMusic,
tint = textColor,
contentDescription = "",
)
if (showQueueButton) {
IconButton(
onClick = {
showQueueBottomSheet = true
},
) {
Icon(
imageVector = SimpIcons.QueueMusic,
tint = textColor,
contentDescription = "",
)
}
}
// Desktop mini player button (JVM only)
if (getPlatform() == Platform.Desktop) {
if (getPlatform() == Platform.Desktop && showPipButton) {
IconButton(onClick = { toggleMiniPlayer() }) {
Icon(
imageVector = SimpIcons.PictureInPictureAlt,
Expand Down
Loading