diff --git a/compose/ui/ui/src/macosMain/kotlin/androidx/compose/ui/input/pointer/PointerIcon.macos.kt b/compose/ui/ui/src/macosMain/kotlin/androidx/compose/ui/input/pointer/PointerIcon.macos.kt new file mode 100644 index 0000000000000..13500d2503419 --- /dev/null +++ b/compose/ui/ui/src/macosMain/kotlin/androidx/compose/ui/input/pointer/PointerIcon.macos.kt @@ -0,0 +1,26 @@ +/* + * Copyright 2021 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package androidx.compose.ui.input.pointer + +import platform.AppKit.NSCursor + +internal data class MacosCursor(val cursor: NSCursor): PointerIcon + +internal actual val pointerIconDefault: PointerIcon = MacosCursor(NSCursor.arrowCursor) +internal actual val pointerIconCrosshair: PointerIcon = MacosCursor(NSCursor.crosshairCursor) +internal actual val pointerIconText: PointerIcon = MacosCursor(NSCursor.IBeamCursor) +internal actual val pointerIconHand: PointerIcon = MacosCursor(NSCursor.pointingHandCursor) diff --git a/compose/ui/ui/src/macosMain/kotlin/androidx/compose/ui/window/ComposeWindow.macos.kt b/compose/ui/ui/src/macosMain/kotlin/androidx/compose/ui/window/ComposeWindow.macos.kt index ba9c9c4cc776a..9a62255937632 100644 --- a/compose/ui/ui/src/macosMain/kotlin/androidx/compose/ui/window/ComposeWindow.macos.kt +++ b/compose/ui/ui/src/macosMain/kotlin/androidx/compose/ui/window/ComposeWindow.macos.kt @@ -22,8 +22,10 @@ import androidx.compose.ui.geometry.Offset import androidx.compose.ui.graphics.asComposeCanvas import androidx.compose.ui.input.key.KeyEvent import androidx.compose.ui.input.key.toComposeEvent +import androidx.compose.ui.input.pointer.MacosCursor import androidx.compose.ui.input.pointer.PointerButton import androidx.compose.ui.input.pointer.PointerEventType +import androidx.compose.ui.input.pointer.PointerIcon import androidx.compose.ui.platform.MacosTextInputService import androidx.compose.ui.platform.PlatformContext import androidx.compose.ui.platform.WindowInfoImpl @@ -44,6 +46,7 @@ import org.jetbrains.skia.Canvas import org.jetbrains.skiko.SkiaLayer import org.jetbrains.skiko.SkikoRenderDelegate import platform.AppKit.NSBackingStoreBuffered +import platform.AppKit.NSCursor import platform.AppKit.NSEvent import platform.AppKit.NSTrackingActiveAlways import platform.AppKit.NSTrackingActiveInKeyWindow @@ -93,6 +96,10 @@ private class ComposeWindow( object : PlatformContext by PlatformContext.Empty { override val windowInfo get() = _windowInfo override val textInputService get() = macosTextInputService + override fun setPointerIcon(pointerIcon: PointerIcon) { + val cursor = (pointerIcon as? MacosCursor)?.cursor ?: NSCursor.arrowCursor + cursor.set() + } } private val skiaLayer = SkiaLayer() private val scene = CanvasLayersComposeScene( diff --git a/compose/ui/ui/src/darwinMain/kotlin/androidx/compose/ui/input/pointer/PointerIcon.darwin.kt b/compose/ui/ui/src/uikitMain/kotlin/androidx/compose/ui/input/pointer/PointerIcon.uikit.kt similarity index 60% rename from compose/ui/ui/src/darwinMain/kotlin/androidx/compose/ui/input/pointer/PointerIcon.darwin.kt rename to compose/ui/ui/src/uikitMain/kotlin/androidx/compose/ui/input/pointer/PointerIcon.uikit.kt index 418f3ebff25cb..153651ff4504b 100644 --- a/compose/ui/ui/src/darwinMain/kotlin/androidx/compose/ui/input/pointer/PointerIcon.darwin.kt +++ b/compose/ui/ui/src/uikitMain/kotlin/androidx/compose/ui/input/pointer/PointerIcon.uikit.kt @@ -17,11 +17,9 @@ package androidx.compose.ui.input.pointer // uikit doesn't seem to have NSCursor. -// TODO: consider having it for macos though. -object DummyPointerIcon : PointerIcon -private data class DarwinCursor(val id: String): PointerIcon +private data class UIKitCursor(val id: String): PointerIcon -internal actual val pointerIconDefault: PointerIcon = DarwinCursor("default") -internal actual val pointerIconCrosshair: PointerIcon = DarwinCursor("crosshair") -internal actual val pointerIconText: PointerIcon = DarwinCursor("text") -internal actual val pointerIconHand: PointerIcon = DarwinCursor("hand") +internal actual val pointerIconDefault: PointerIcon = UIKitCursor("default") +internal actual val pointerIconCrosshair: PointerIcon = UIKitCursor("crosshair") +internal actual val pointerIconText: PointerIcon = UIKitCursor("text") +internal actual val pointerIconHand: PointerIcon = UIKitCursor("hand")