How can I set a window icon for linux? Is it suppo...
# compose-desktop
a
How can I set a window icon for linux? Is it supported? Setting
Window(....., icon=painterResource(Res.drawable.icon), .....)
works in Windows but not in Linux.
It is not even showing the app icon as window icon. But just shows a system icon(default icon?)
k
Unfortunately, that will not be displayed there. There are two icons to be displayed, one is displayed on the top bar and when it is displayed on the window bar. If you want to display an icon on the window bar then you need to set that from the gradle Inside the desktop target.
🙏 1
Checkout one of my projects and checkout the gradle file. I already have integrated that. https://github.com/KhubaibKhan4/Youtube-Clone-KMP
🙏 1
t
If you only want a static icon which does not change you could just define it in your gradle file this works for me in linux.
a
I am already using
Copy code
linux {
    iconFile.set(project.file("Icon.png"))
}
which sets the icon for launcher, i.e, on the application list, but after I launch the app, icon of the window on top bar(in Ubuntu) is not being set to what I want. Is there something else I can do in gradle file or in the main code which will set the window Icon?
k
Provide the actual file location like composeResources/drawable/icon.ico. remember don't provide PNG instead provide ico
t
For linux you need a png file not ico. I think ico is for window only
k
Nope, you need to provide ico for all the platforms (as I know).
t
Ok i checked my project and it looks like for the running app the icon provided in the code is used:
Copy code
Window(icon = painterResource("icon-linux.png"))
So make sure it is in the src/main/resources folder. I am using XUbuntu and it is shown as window icon and also in my taskbar.
k
Yeah, that might be working but officiall documentation recommends to use .ico
t
Where did you found that. I was just searching for the official documentation.
k
Checkout tutorial docs on the compose multiplatform Repository.
t
I now that in the past there was a section for icons but did not found this anymore
k
👍 1
p
I am having the same issue, it works for Mac and Windows but not for Linux. On the linux bar you can still see the default icon
Copy code
windows {
    iconFile.set(project.file("src/main/resources/icons/windows/icon.ico"))
}
linux {
    iconFile.set(project.file("src/main/resources/icons/linux/icon.png"))
}
macOS {
    dockName = "Test"
    bundleID = "test.ui"
    iconFile.set(project.file("src/main/resources/icons/macos/icon.icns"))
}
Copy code
Window(
    onCloseRequest = ::exitApplication,
    state = windowState,
    title = "Test UI - ",
    icon = BitmapPainter(imageFromByteArray(object {}.javaClass.getResourceAsStream("/icons/linux/icon.png")!!.readAllBytes()))
)
fun imageFromByteArray(bytes: ByteArray): ImageBitmap {
    return org.jetbrains.skia.Image.makeFromEncoded(bytes).toComposeImageBitmap()
}
First code snippet is gradle, second compose main function. How did you guys handle the icons?
a
@Paulo Balbino The issue remains unsolved for me
p