Skip to content

Commit c34300e

Browse files
committed
Add windowIcon parameter to TrayApp for custom popup window icons
- Introduced `windowIcon` parameter to `TrayApp` and related methods to allow specifying a custom icon for the popup window. - Updated `DialogWindow` to include the provided icon, enhancing visual customization options. - Documented the new parameter in the README with examples.
1 parent 88eab48 commit c34300e

2 files changed

Lines changed: 41 additions & 2 deletions

File tree

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,28 @@ application {
692692
// content
693693
}
694694
}
695+
```
696+
697+
#### Window Icon
698+
Set a custom window icon for the popup using `windowIcon`. This maps directly to the `icon` parameter of Compose's `DialogWindow`.
699+
700+
- Type: `Painter?`
701+
- Default: `null` (no custom icon)
702+
- Example:
703+
```kotlin
704+
@OptIn(ExperimentalTrayAppApi::class)
705+
application {
706+
val trayState = rememberTrayAppState()
707+
TrayApp(
708+
state = trayState,
709+
icon = Icons.Default.Dashboard,
710+
tooltip = "My Tray App",
711+
windowsTitle = "My Tray Popup",
712+
windowIcon = painterResource(Res.drawable.icon)
713+
) {
714+
// content
715+
}
716+
}
695717
```
696718

697719
## 🧩 New: Tray Window Dismiss Modes

src/commonMain/kotlin/com/kdroid/composetray/tray/api/TrayApp.kt

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ fun ApplicationScope.TrayApp(
7575
animationSpec: AnimationSpec<Float> = tween(durationMillis = fadeDurationMs, easing = EaseInOut),
7676
transparent: Boolean = true,
7777
windowsTitle: String = "",
78+
windowIcon: Painter? = null,
7879
menu: (TrayMenuBuilder.() -> Unit)? = null,
7980
content: @Composable () -> Unit,
8081
) {
@@ -99,6 +100,7 @@ fun ApplicationScope.TrayApp(
99100
animationSpec = animationSpec,
100101
transparent = transparent,
101102
windowsTitle = windowsTitle,
103+
windowIcon = windowIcon,
102104
menu = menu,
103105
content = content,
104106
)
@@ -117,6 +119,7 @@ fun ApplicationScope.TrayApp(
117119
animationSpec: AnimationSpec<Float> = tween(durationMillis = fadeDurationMs, easing = EaseInOut),
118120
transparent: Boolean = true,
119121
windowsTitle: String = "",
122+
windowIcon: Painter? = null,
120123
menu: (TrayMenuBuilder.() -> Unit)? = null,
121124
content: @Composable () -> Unit,
122125
) {
@@ -134,6 +137,7 @@ fun ApplicationScope.TrayApp(
134137
animationSpec = animationSpec,
135138
transparent = transparent,
136139
windowsTitle = windowsTitle,
140+
windowIcon = windowIcon,
137141
menu = menu,
138142
content = content,
139143
)
@@ -154,6 +158,7 @@ fun ApplicationScope.TrayApp(
154158
animationSpec: AnimationSpec<Float> = tween(durationMillis = fadeDurationMs, easing = EaseInOut),
155159
transparent: Boolean = true,
156160
windowsTitle: String = "",
161+
windowIcon: Painter? = null,
157162
menu: (TrayMenuBuilder.() -> Unit)? = null,
158163
content: @Composable () -> Unit,
159164
) {
@@ -169,6 +174,7 @@ fun ApplicationScope.TrayApp(
169174
animationSpec = animationSpec,
170175
transparent = transparent,
171176
windowsTitle = windowsTitle,
177+
windowIcon = windowIcon,
172178
menu = menu,
173179
content = content,
174180
)
@@ -185,6 +191,7 @@ fun ApplicationScope.TrayApp(
185191
animationSpec = animationSpec,
186192
transparent = transparent,
187193
windowsTitle = windowsTitle,
194+
windowIcon = windowIcon,
188195
menu = menu,
189196
content = content,
190197
)
@@ -204,6 +211,7 @@ fun ApplicationScope.TrayApp(
204211
animationSpec: AnimationSpec<Float> = tween(durationMillis = fadeDurationMs, easing = EaseInOut),
205212
transparent: Boolean = true,
206213
windowsTitle: String = "",
214+
windowIcon: Painter? = null,
207215
menu: (TrayMenuBuilder.() -> Unit)? = null,
208216
content: @Composable () -> Unit,
209217
) {
@@ -218,6 +226,7 @@ fun ApplicationScope.TrayApp(
218226
animationSpec = animationSpec,
219227
transparent = transparent,
220228
windowsTitle = windowsTitle,
229+
windowIcon = windowIcon,
221230
menu = menu,
222231
content = content,
223232
)
@@ -238,6 +247,7 @@ fun ApplicationScope.TrayApp(
238247
animationSpec: AnimationSpec<Float> = tween(durationMillis = fadeDurationMs, easing = EaseInOut),
239248
transparent: Boolean = true,
240249
windowsTitle: String = "",
250+
windowIcon: Painter? = null,
241251
menu: (TrayMenuBuilder.() -> Unit)? = null,
242252
content: @Composable () -> Unit,
243253
) {
@@ -253,6 +263,7 @@ fun ApplicationScope.TrayApp(
253263
animationSpec = animationSpec,
254264
transparent = transparent,
255265
windowsTitle = windowsTitle,
266+
windowIcon = windowIcon,
256267
menu = menu,
257268
content = content,
258269
)
@@ -269,6 +280,7 @@ fun ApplicationScope.TrayApp(
269280
animationSpec = animationSpec,
270281
transparent = transparent,
271282
windowsTitle = windowsTitle,
283+
windowIcon = windowIcon,
272284
menu = menu,
273285
content = content,
274286
)
@@ -290,17 +302,18 @@ fun ApplicationScope.TrayApp(
290302
animationSpec: AnimationSpec<Float> = tween(durationMillis = fadeDurationMs, easing = EaseInOut),
291303
transparent: Boolean = true,
292304
windowsTitle: String = "",
305+
windowIcon: Painter? = null,
293306
menu: (TrayMenuBuilder.() -> Unit)? = null,
294307
content: @Composable () -> Unit,
295308
) {
296309
when (getOperatingSystem()) {
297310
OperatingSystem.LINUX -> TrayAppImplLinux(
298311
iconContent, iconRenderProperties, tooltip, state, windowSize,
299-
visibleOnStart, fadeDurationMs, animationSpec, transparent, windowsTitle, menu, content
312+
visibleOnStart, fadeDurationMs, animationSpec, transparent, windowsTitle, windowIcon, menu, content
300313
)
301314
else -> TrayAppImplOriginal(
302315
iconContent, iconRenderProperties, tooltip, state, windowSize,
303-
visibleOnStart, fadeDurationMs, animationSpec, transparent, windowsTitle, menu, content
316+
visibleOnStart, fadeDurationMs, animationSpec, transparent, windowsTitle, windowIcon, menu, content
304317
)
305318
}
306319
}
@@ -319,6 +332,7 @@ private fun ApplicationScope.TrayAppImplOriginal(
319332
animationSpec: AnimationSpec<Float>,
320333
transparent: Boolean,
321334
windowsTitle: String,
335+
windowIcon: Painter?,
322336
menu: (TrayMenuBuilder.() -> Unit)?,
323337
content: @Composable () -> Unit,
324338
) {
@@ -454,6 +468,7 @@ private fun ApplicationScope.TrayAppImplOriginal(
454468
DialogWindow(
455469
onCloseRequest = { requestHideExplicit() },
456470
title = windowsTitle,
471+
icon = windowIcon,
457472
undecorated = true,
458473
resizable = false,
459474
focusable = true,
@@ -534,6 +549,7 @@ private fun ApplicationScope.TrayAppImplLinux(
534549
animationSpec: AnimationSpec<Float>,
535550
transparent: Boolean,
536551
windowsTitle: String,
552+
windowIcon: Painter?,
537553
menu: (TrayMenuBuilder.() -> Unit)?,
538554
content: @Composable () -> Unit,
539555
) {
@@ -644,6 +660,7 @@ private fun ApplicationScope.TrayAppImplLinux(
644660
DialogWindow(
645661
onCloseRequest = { requestHideExplicit() },
646662
title = windowsTitle,
663+
icon = windowIcon,
647664
undecorated = true,
648665
resizable = false,
649666
focusable = shouldShowWindow, // avoid focus-steal while hidden

0 commit comments

Comments
 (0)