compose-multiplatform
compose-multiplatform copied to clipboard
Blurry icon in application switcher
When setting the window icon using the Windows API, the icon looks blurry / pixelated in the XFCE application switcher (when pressing ALT+TAB). I think it has to do with how the icon is rasterized and set in Window.desktop.kt:
// In fact, this size doesn't affect anything on Windows/Linux, and isn't used by macOs (macOs
// doesn't have separate Window icons). We specify it to support Painter's with
// Unspecified intrinsicSize
private val iconSize = Size(32f, 32f)
internal fun Window.setIcon(painter: Painter?) {
setIconImage(painter?.toAwtImage(density, layoutDirection, iconSize))
}
Java Swing/AWT has support for setting multiple versions of the window icon by setIconImages() from which the OS / Window Manager should be able to choose the right one depending on the resolution.
Since you've added the windows label: I'm actually experiencing this on a XFCE desktop, so I don't know if the same problems occurs on Windows too, but it's definitely not something Windows-specific.
Yep, I observe the same on Fedora/Linux with Wayland and Gnome.
Here is my workaround:
Window(
// ...
) {
// TODO this is a workaround for https://github.com/JetBrains/compose-jb/issues/1838
val icon = painterResource("/assets/icon.svg")
val density = LocalDensity.current
SideEffect {
window.iconImage = icon.toAwtImage(density, LayoutDirection.Ltr, Size(128f, 128f))
}
// ...
}
I think the problem is in this file, currently line 174: https://github.com/JetBrains/compose-multiplatform-core/blob/jb-main/compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/util/Windows.desktop.kt
// In fact, this size doesn't affect anything on Windows/Linux, and isn't used by macOS (macOS
// doesn't have separate Window icons). We specify it to support Painter's with
// Unspecified intrinsicSize
private val iconSize = Size(32f, 32f)
internal fun Window.setIcon(painter: Painter?) {
setIconImage(painter?.toAwtImage(density, layoutDirectionFor(this), iconSize))
}
looks like that assumption is not right, the size does seem to affect things on Windows and Linux.