compose-multiplatform icon indicating copy to clipboard operation
compose-multiplatform copied to clipboard

Cannot find the api to implement the requirement,please help.

Open s949492225 opened this issue 1 year ago • 3 comments

May I ask how to achieve the effect in the following picture? Display the icon in the title bar, click the icon to display a window below the icon, and do not display the application in the dock of mac.

It is said that jetbrain toolbox is written in compose desktop, and the interaction used is also in the form mentioned above. preferably a simple demo, thank you

image

s949492225 avatar Mar 22 '23 05:03 s949492225

I guess you want to use the tray (see Menu, tray, notifications) with a Dialog? Sample implementation would be:

fun main() = application {
    var count by remember { mutableStateOf(0) }
    var isOpen by remember { mutableStateOf(false) }

    val trayState = rememberTrayState()

    Tray(
        state = trayState,
        icon = TrayIcon,
        onAction = { isOpen = true },
    )

    if (isOpen) {
        Dialog(
            onCloseRequest = { isOpen = false },
        ) {
            this.window.size
            Box(
                modifier = Modifier.size(256.dp),
                contentAlignment = Alignment.Center
            ) {
                Text(text = "Value: $count")
            }
        }
    }
}

object TrayIcon : Painter() {
    override val intrinsicSize = Size(256f, 256f)

    override fun DrawScope.onDraw() {
        drawOval(Color(0xFFFFA500))
    }
}

malliaridis avatar Apr 04 '23 11:04 malliaridis

Is there any way to get the tray's position and width on the screen?

s949492225 avatar Apr 06 '23 03:04 s949492225

As far as I know there is no way to do that, not with the current version of Compose, and I don't think it will be easy to support or work around this limitation. But correct me if I'm wrong.

malliaridis avatar Apr 06 '23 04:04 malliaridis

That Dialog trick did not work for me, the icon is still visible in the dock, any solution?

Giuliopime avatar Jul 07 '23 21:07 Giuliopime