DEV Community

Cover image for Compose for Desktop: Window party tricks
ColtonIdle
ColtonIdle

Posted on • Edited on

Compose for Desktop: Window party tricks

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)
)
Enter fullscreen mode Exit fullscreen mode

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))
Enter fullscreen mode Exit fullscreen mode

(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)
            }
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

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)
Enter fullscreen mode Exit fullscreen mode

More info:
https://github.com/JetBrains/compose-multiplatform/issues/4231#issuecomment-1952205605
and
https://kotlinlang.slack.com/archives/C01D6HTPATV/p1739152698052949

5. Customize UI stuff on Java/macOS: https://developer.apple.com/library/archive/technotes/tn2007/tn2196.html

Source: https://kotlinlang.slack.com/archives/C01D6HTPATV/p1741607313291729

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay