Just a random collection of window tricks I've accumulated while trying to build a desktop app.
1. Size the window to your content
Sometimes you just want your window to match the size of your content. I've found this to be true for settings windows for example. Simply use:
val state = rememberWindowState(
size = DpSize(Dp.Unspecified, Dp.Unspecified)
)
Make sure your root layouts don't have fillMaxSize() or else this won't work. You can optionally also make the Window non-resizable via resizable = false
on the Window.
If you need the window size to adjust to your content size, checkout https://gist.github.com/ColtonIdle/df23e3dc8e72569a28a4c64197bed14c
More info: https://kotlinlang.slack.com/archives/C01D6HTPATV/p1740892851067859
2. Start with the window centered
Use:
Window(
state = rememberWindowState(position = WindowPosition(Alignment.Center))
(Barely) More info: https://kotlinlang.slack.com/archives/C01D6HTPATV/p1739326963488559
3. Remove title bar
Use:
fun main() = application {
Window(
onCloseRequest = ::exitApplication,
title = ""
) {
Box(Modifier.fillMaxSize().background(Color.Red))
LaunchedEffect(window.rootPane) {
with(window.rootPane) {
putClientProperty("apple.awt.transparentTitleBar", true)
putClientProperty("apple.awt.fullWindowContent", true)
}
}
}
}
More info:
https://kotlinlang.slack.com/archives/C01D6HTPATV/p1739449034315049
4. Bring window to front and into focus
If you need to bring it to the foreground and focussed
Desktop.getDesktop().requestForeground(true)
More info:
https://github.com/JetBrains/compose-multiplatform/issues/4231#issuecomment-1952205605
and
https://kotlinlang.slack.com/archives/C01D6HTPATV/p1739152698052949
Top comments (0)