Skip to content

Commit d24257b

Browse files
committed
Add undecorated and resizable parameters to TrayApp for enhanced window customization
- Introduced `undecorated` and `resizable` parameters to `TrayApp` and related methods, allowing control over window decorations and resizing options. - Updated platform-specific implementations to apply the new parameters consistently across systems. - Documented the parameters in the README with examples to illustrate their usage.
1 parent 7a13d97 commit d24257b

2 files changed

Lines changed: 64 additions & 10 deletions

File tree

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,30 @@ application {
714714
// content
715715
}
716716
}
717+
```
718+
719+
#### Window Decoration and Resizing
720+
You can control whether the tray popup window has native decorations (title bar, borders) and whether it is resizable.
721+
722+
- undecorated: Boolean = true (default). When true, the window has no OS decorations. Set to false to show the standard window frame.
723+
- resizable: Boolean = false (default). When true, users can resize the popup window.
724+
725+
Example:
726+
```kotlin
727+
@OptIn(ExperimentalTrayAppApi::class)
728+
application {
729+
val trayAppState = rememberTrayAppState(initialWindowSize = DpSize(360.dp, 480.dp))
730+
TrayApp(
731+
state = trayAppState,
732+
icon = Icons.Default.Dashboard,
733+
tooltip = "My Tray App",
734+
transparent = false,
735+
undecorated = false, // show standard window frame
736+
resizable = true // allow resizing
737+
) {
738+
// content
739+
}
740+
}
717741
```
718742

719743
## 🧩 New: Tray Window Dismiss Modes

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

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ fun ApplicationScope.TrayApp(
8282
transparent: Boolean = true,
8383
windowsTitle: String = "",
8484
windowIcon: Painter? = null,
85+
undecorated: Boolean = true,
86+
resizable: Boolean = false,
8587
onPreviewKeyEvent: (KeyEvent) -> Boolean = { false },
8688
onKeyEvent: (KeyEvent) -> Boolean = { false },
8789
menu: (TrayMenuBuilder.() -> Unit)? = null,
@@ -109,6 +111,8 @@ fun ApplicationScope.TrayApp(
109111
transparent = transparent,
110112
windowsTitle = windowsTitle,
111113
windowIcon = windowIcon,
114+
undecorated = undecorated,
115+
resizable = resizable,
112116
onPreviewKeyEvent = onPreviewKeyEvent,
113117
onKeyEvent = onKeyEvent,
114118
menu = menu,
@@ -149,6 +153,8 @@ fun ApplicationScope.TrayApp(
149153
transparent: Boolean = true,
150154
windowsTitle: String = "",
151155
windowIcon: Painter? = null,
156+
undecorated: Boolean = true,
157+
resizable: Boolean = false,
152158
onPreviewKeyEvent: (KeyEvent) -> Boolean = { false },
153159
onKeyEvent: (KeyEvent) -> Boolean = { false },
154160
menu: (TrayMenuBuilder.() -> Unit)? = null,
@@ -169,6 +175,8 @@ fun ApplicationScope.TrayApp(
169175
transparent = transparent,
170176
windowsTitle = windowsTitle,
171177
windowIcon = windowIcon,
178+
undecorated = undecorated,
179+
resizable = resizable,
172180
onPreviewKeyEvent = onPreviewKeyEvent,
173181
onKeyEvent = onKeyEvent,
174182
menu = menu,
@@ -214,6 +222,8 @@ fun ApplicationScope.TrayApp(
214222
transparent: Boolean = true,
215223
windowsTitle: String = "",
216224
windowIcon: Painter? = null,
225+
undecorated: Boolean = true,
226+
resizable: Boolean = false,
217227
onPreviewKeyEvent: (KeyEvent) -> Boolean = { false },
218228
onKeyEvent: (KeyEvent) -> Boolean = { false },
219229
menu: (TrayMenuBuilder.() -> Unit)? = null,
@@ -232,6 +242,8 @@ fun ApplicationScope.TrayApp(
232242
transparent = transparent,
233243
windowsTitle = windowsTitle,
234244
windowIcon = windowIcon,
245+
undecorated = undecorated,
246+
resizable = resizable,
235247
onPreviewKeyEvent = onPreviewKeyEvent,
236248
onKeyEvent = onKeyEvent,
237249
menu = menu,
@@ -242,8 +254,6 @@ fun ApplicationScope.TrayApp(
242254
icon = macLinuxIcon,
243255
tint = tint,
244256
iconRenderProperties = iconRenderProperties,
245-
onPreviewKeyEvent = onPreviewKeyEvent,
246-
onKeyEvent = onKeyEvent,
247257
tooltip = tooltip,
248258
state = state,
249259
windowSize = windowSize,
@@ -253,6 +263,10 @@ fun ApplicationScope.TrayApp(
253263
transparent = transparent,
254264
windowsTitle = windowsTitle,
255265
windowIcon = windowIcon,
266+
undecorated = undecorated,
267+
resizable = resizable,
268+
onPreviewKeyEvent = onPreviewKeyEvent,
269+
onKeyEvent = onKeyEvent,
256270
menu = menu,
257271
content = content,
258272
)
@@ -274,6 +288,8 @@ fun ApplicationScope.TrayApp(
274288
transparent: Boolean = true,
275289
windowsTitle: String = "",
276290
windowIcon: Painter? = null,
291+
undecorated: Boolean = true,
292+
resizable: Boolean = false,
277293
onPreviewKeyEvent: (KeyEvent) -> Boolean = { false },
278294
onKeyEvent: (KeyEvent) -> Boolean = { false },
279295
menu: (TrayMenuBuilder.() -> Unit)? = null,
@@ -291,6 +307,8 @@ fun ApplicationScope.TrayApp(
291307
transparent = transparent,
292308
windowsTitle = windowsTitle,
293309
windowIcon = windowIcon,
310+
undecorated = undecorated,
311+
resizable = resizable,
294312
menu = menu,
295313
content = content,
296314
)
@@ -313,6 +331,8 @@ fun ApplicationScope.TrayApp(
313331
transparent: Boolean = true,
314332
windowsTitle: String = "",
315333
windowIcon: Painter? = null,
334+
undecorated: Boolean = true,
335+
resizable: Boolean = false,
316336
onPreviewKeyEvent: (KeyEvent) -> Boolean = { false },
317337
onKeyEvent: (KeyEvent) -> Boolean = { false },
318338
menu: (TrayMenuBuilder.() -> Unit)? = null,
@@ -331,6 +351,8 @@ fun ApplicationScope.TrayApp(
331351
transparent = transparent,
332352
windowsTitle = windowsTitle,
333353
windowIcon = windowIcon,
354+
undecorated = undecorated,
355+
resizable = resizable,
334356
onPreviewKeyEvent = onPreviewKeyEvent,
335357
onKeyEvent = onKeyEvent,
336358
menu = menu,
@@ -341,8 +363,6 @@ fun ApplicationScope.TrayApp(
341363
icon = macLinuxIcon,
342364
tint = tint,
343365
iconRenderProperties = iconRenderProperties,
344-
onPreviewKeyEvent = onPreviewKeyEvent,
345-
onKeyEvent = onKeyEvent,
346366
tooltip = tooltip,
347367
state = state,
348368
windowSize = windowSize,
@@ -352,6 +372,10 @@ fun ApplicationScope.TrayApp(
352372
transparent = transparent,
353373
windowsTitle = windowsTitle,
354374
windowIcon = windowIcon,
375+
undecorated = undecorated,
376+
resizable = resizable,
377+
onPreviewKeyEvent = onPreviewKeyEvent,
378+
onKeyEvent = onKeyEvent,
355379
menu = menu,
356380
content = content,
357381
)
@@ -374,6 +398,8 @@ fun ApplicationScope.TrayApp(
374398
transparent: Boolean = true,
375399
windowsTitle: String = "",
376400
windowIcon: Painter? = null,
401+
undecorated: Boolean = true,
402+
resizable: Boolean = false,
377403
onPreviewKeyEvent: (KeyEvent) -> Boolean = { false },
378404
onKeyEvent: (KeyEvent) -> Boolean = { false },
379405
menu: (TrayMenuBuilder.() -> Unit)? = null,
@@ -382,11 +408,11 @@ fun ApplicationScope.TrayApp(
382408
when (getOperatingSystem()) {
383409
OperatingSystem.LINUX -> TrayAppImplLinux(
384410
iconContent, iconRenderProperties, tooltip, state, windowSize,
385-
visibleOnStart, fadeDurationMs, animationSpec, transparent, windowsTitle, windowIcon, onPreviewKeyEvent, onKeyEvent, menu, content
411+
visibleOnStart, fadeDurationMs, animationSpec, transparent, windowsTitle, windowIcon, undecorated, resizable, onPreviewKeyEvent, onKeyEvent, menu, content
386412
)
387413
else -> TrayAppImplOriginal(
388414
iconContent, iconRenderProperties, tooltip, state, windowSize,
389-
visibleOnStart, fadeDurationMs, animationSpec, transparent, windowsTitle, windowIcon, onPreviewKeyEvent, onKeyEvent, menu, content
415+
visibleOnStart, fadeDurationMs, animationSpec, transparent, windowsTitle, windowIcon, undecorated, resizable, onPreviewKeyEvent, onKeyEvent, menu, content
390416
)
391417
}
392418
}
@@ -406,6 +432,8 @@ private fun ApplicationScope.TrayAppImplOriginal(
406432
transparent: Boolean,
407433
windowsTitle: String,
408434
windowIcon: Painter?,
435+
undecorated: Boolean,
436+
resizable: Boolean,
409437
onPreviewKeyEvent: (KeyEvent) -> Boolean,
410438
onKeyEvent: (KeyEvent) -> Boolean,
411439
menu: (TrayMenuBuilder.() -> Unit)?,
@@ -544,8 +572,8 @@ private fun ApplicationScope.TrayAppImplOriginal(
544572
onCloseRequest = { requestHideExplicit() },
545573
title = windowsTitle,
546574
icon = windowIcon,
547-
undecorated = true,
548-
resizable = false,
575+
undecorated = undecorated,
576+
resizable = resizable,
549577
focusable = true,
550578
alwaysOnTop = true,
551579
transparent = transparent,
@@ -627,6 +655,8 @@ private fun ApplicationScope.TrayAppImplLinux(
627655
transparent: Boolean,
628656
windowsTitle: String,
629657
windowIcon: Painter?,
658+
undecorated: Boolean,
659+
resizable: Boolean,
630660
onPreviewKeyEvent: (KeyEvent) -> Boolean,
631661
onKeyEvent: (KeyEvent) -> Boolean,
632662
menu: (TrayMenuBuilder.() -> Unit)?,
@@ -740,8 +770,8 @@ private fun ApplicationScope.TrayAppImplLinux(
740770
onCloseRequest = { requestHideExplicit() },
741771
title = windowsTitle,
742772
icon = windowIcon,
743-
undecorated = true,
744-
resizable = false,
773+
undecorated = undecorated,
774+
resizable = resizable,
745775
focusable = shouldShowWindow, // avoid focus-steal while hidden
746776
alwaysOnTop = true,
747777
transparent = transparent,

0 commit comments

Comments
 (0)