Hello, I am facing a problem integrating my custom...
# compose-desktop
v
Hello, I am facing a problem integrating my custom cursors in compose app on desktop My implementation is:
Copy code
public actual val PointerIcon.Companion.ZoomIn: PointerIcon
    get() = customZoomInCursor

public actual val PointerIcon.Companion.ZoomOut: PointerIcon
    get() = customZoomOutCursor

private val customZoomInCursor: PointerIcon by lazy {
    val toolkit = Toolkit.getDefaultToolkit()
    val customCursor = toolkit.createCustomCursor(DesignRes.images.cursor_zoom_in.image, Point(8, 8), "ZoomIn")
    PointerIcon(customCursor)
}

private val customZoomOutCursor: PointerIcon by lazy {
    val toolkit = Toolkit.getDefaultToolkit()
    val customCursor = toolkit.createCustomCursor(DesignRes.images.cursor_zoom_out.image, Point(8, 8), "ZoomOut")
    PointerIcon(customCursor)
}
I try to switch between them when my image scale changes
Copy code
.pointerHoverIcon(if (scale >= 2f) PointerIcon.ZoomOut else PointerIcon.ZoomIn)
However, cursors do not change. Upon investigating, I found out that internal
AwtCursor
does not implement hashCode and simply uses
cursor.type
value. Which is always -1 for both since it is a custom type indicator
Copy code
public static final int CUSTOM_CURSOR = -1;
I've also found there is
PointerIconService
, but its internal and I can't plug my own. Has anybody had same issue? How do I use multiple custom cursors?
AwtCursor equals looks like this
Copy code
override fun equals(other: Any?): Boolean {
    if (this === other) return true
    if (javaClass != other?.javaClass) return false

    other as AwtCursor

    // AwtCursor doesn't implement equals
    if (cursor.type != other.cursor.type) return false

    return true
}
I think comparing
cursor.type
+
cursor.name
would do the trick
👍 1
tried 1.9.3 and 1.10.0-beta02 and it behaves the same
a
Please submit a bug report on YouTrack
👍 1
a
I faced the same bug, I have a workaround but it can introduce some flicker: https://kotlinlang.slack.com/archives/C01D6HTPATV/p1741387168081589
👍 1
v
Oh, thank for suggestion, will give it a try