Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2000-2026 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.jewel.bridge

import com.intellij.util.ui.MacUIUtil
import org.jetbrains.jewel.ui.platform.PlatformCursorController
import org.jetbrains.skiko.OS
import org.jetbrains.skiko.hostOs

internal object BridgePlatformCursorController : PlatformCursorController {
override fun hideCursorWhileTyping() {
if (hostOs == OS.MacOS) {
MacUIUtil.hideCursor()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.compose.ui.platform.LocalUriHandler
import org.jetbrains.annotations.ApiStatus
import org.jetbrains.jewel.bridge.BridgeMessageResourceResolver
import org.jetbrains.jewel.bridge.BridgePainterHintsProvider
import org.jetbrains.jewel.bridge.BridgePlatformCursorController
import org.jetbrains.jewel.bridge.BridgeTypography
import org.jetbrains.jewel.bridge.BridgeUriHandler
import org.jetbrains.jewel.bridge.SwingBridgeReader
Expand All @@ -26,6 +27,7 @@ import org.jetbrains.jewel.ui.LocalMenuItemShortcutProvider
import org.jetbrains.jewel.ui.LocalTypography
import org.jetbrains.jewel.ui.icon.LocalNewUiChecker
import org.jetbrains.jewel.ui.painter.LocalPainterHintsProvider
import org.jetbrains.jewel.ui.platform.LocalPlatformCursorController
import org.jetbrains.jewel.ui.theme.BaseJewelTheme
import org.jetbrains.jewel.ui.util.LocalMessageResourceResolverProvider

Expand All @@ -52,6 +54,7 @@ public fun SwingBridgeTheme(content: @Composable () -> Unit) {
LocalTypography provides BridgeTypography,
LocalUriHandler provides BridgeUriHandler,
LocalMessageResourceResolverProvider provides BridgeMessageResourceResolver(),
LocalPlatformCursorController provides BridgePlatformCursorController,
) {
content()
}
Expand Down
1 change: 1 addition & 0 deletions platform/jewel/int-ui/int-ui-standalone/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ jvm_library(
"//libraries/compose-runtime-desktop",
"//platform/jewel/foundation",
"//libraries/jbr",
"@lib//:jna",
],
plugins = ["@lib//:compose-plugin"]
)
Expand Down
1 change: 1 addition & 0 deletions platform/jewel/int-ui/int-ui-standalone/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ plugins {
dependencies {
api(projects.ui)
implementation(libs.jbr.api)
implementation(libs.jna.core)
}

intelliJThemeGenerator {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@
<orderEntry type="module" module-name="intellij.libraries.compose.runtime.desktop" />
<orderEntry type="module" module-name="intellij.platform.jewel.foundation" />
<orderEntry type="module" module-name="intellij.libraries.jbr" />
<orderEntry type="library" name="jna" level="project" />
</component>
</module>
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.jewel.intui.standalone

import com.sun.jna.Library
import com.sun.jna.Native
import com.sun.jna.Pointer
import org.jetbrains.jewel.ui.platform.PlatformCursorController
import org.jetbrains.skiko.OS
import org.jetbrains.skiko.hostOs

internal object StandalonePlatformCursorController : PlatformCursorController {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is copied from platform code, it'd be good to write it in the KDoc

private val objcLibrary: ObjCLibrary? by lazy {
try {
Native.load("objc", ObjCLibrary::class.java)
} catch (_: Exception) {
null
}
}

override fun hideCursorWhileTyping() {
if (hostOs == OS.MacOS) {
try {
val lib = objcLibrary ?: return

val nsCursorClass = lib.objc_getClass("NSCursor")
if (nsCursorClass == null || Pointer.nativeValue(nsCursorClass) == 0L) return

val selector = lib.sel_registerName("setHiddenUntilMouseMoves:")
if (selector == null || Pointer.nativeValue(selector) == 0L) return

lib.objc_msgSend(nsCursorClass, selector, true)
} catch (_: Exception) {
// Silently fail if native calls fail or if JNA is not available
}
}
}

@Suppress("ktlint:standard:function-naming")
private interface ObjCLibrary : Library {
fun objc_getClass(className: String?): Pointer?

fun sel_registerName(selectorName: String?): Pointer?

fun objc_msgSend(receiver: Pointer?, selector: Pointer?, vararg args: Any?)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import org.jetbrains.jewel.intui.core.theme.IntUiLightTheme
import org.jetbrains.jewel.intui.standalone.IntUiMessageResourceResolver
import org.jetbrains.jewel.intui.standalone.IntUiTypography
import org.jetbrains.jewel.intui.standalone.StandalonePainterHintsProvider
import org.jetbrains.jewel.intui.standalone.StandalonePlatformCursorController
import org.jetbrains.jewel.intui.standalone.icon.StandaloneNewUiChecker
import org.jetbrains.jewel.intui.standalone.menuShortcut.StandaloneMenuItemShortcutHintProvider
import org.jetbrains.jewel.intui.standalone.menuShortcut.StandaloneShortcutProvider
Expand Down Expand Up @@ -68,6 +69,7 @@ import org.jetbrains.jewel.ui.component.styling.TooltipAutoHideBehavior
import org.jetbrains.jewel.ui.component.styling.TooltipStyle
import org.jetbrains.jewel.ui.icon.LocalNewUiChecker
import org.jetbrains.jewel.ui.painter.LocalPainterHintsProvider
import org.jetbrains.jewel.ui.platform.LocalPlatformCursorController
import org.jetbrains.jewel.ui.theme.BaseJewelTheme
import org.jetbrains.jewel.ui.util.LocalMessageResourceResolverProvider

Expand Down Expand Up @@ -727,6 +729,7 @@ public fun IntUiTheme(
LocalMenuItemShortcutHintProvider provides StandaloneMenuItemShortcutHintProvider,
LocalTypography provides IntUiTypography,
LocalMessageResourceResolverProvider provides IntUiMessageResourceResolver,
LocalPlatformCursorController provides StandalonePlatformCursorController,
) {
content()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2000-2026 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.jewel.ui.component

import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.key.Key
import androidx.compose.ui.input.key.KeyEventType
import androidx.compose.ui.input.key.key
import androidx.compose.ui.input.key.onPreviewKeyEvent
import androidx.compose.ui.input.key.type
import androidx.compose.ui.input.key.utf16CodePoint
import org.jetbrains.jewel.ui.platform.LocalPlatformCursorController
import org.jetbrains.jewel.ui.platform.PlatformCursorController

@Composable
public fun Modifier.hideCursorOnTyping(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make it internal? I don't think people will need to use this directly.

cursorController: PlatformCursorController = LocalPlatformCursorController.current
): Modifier = onPreviewKeyEvent { event ->
if (event.type == KeyEventType.KeyDown && event.key != Key.Escape && event.utf16CodePoint != 0) {
cursorController.hideCursorWhileTyping()
}
false // returning false so the text field can handle the key event properly
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ internal fun InputField(
modifier =
modifier
.hoverable(hoverInteractionSource)
.thenIf(enabled && !readOnly) { hideCursorOnTyping() }
.then(backgroundModifier)
.thenIf(!undecorated && hasNoOutline) {
focusOutline(state = inputFieldState, outlineShape = shape, alignment = Stroke.Alignment.Center)
Expand Down Expand Up @@ -216,6 +217,7 @@ internal fun InputField(
modifier =
modifier
.hoverable(hoverInteractionSource)
.thenIf(enabled && !readOnly) { hideCursorOnTyping() }
.then(backgroundModifier)
.thenIf(!undecorated && hasNoOutline) {
focusOutline(state = inputFieldState, outlineShape = shape, alignment = Stroke.Alignment.Center)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.jewel.ui.platform

import androidx.compose.runtime.ProvidableCompositionLocal
import androidx.compose.runtime.staticCompositionLocalOf

public interface PlatformCursorController {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add KDoc to all public API symbols

/** Hides the mouse cursor while the user is typing. This is a MacOS-only behavior. */
public fun hideCursorWhileTyping()
}

public object NoOpPlatformCursorController : PlatformCursorController {
override fun hideCursorWhileTyping() {
// No-op
}
}

public val LocalPlatformCursorController: ProvidableCompositionLocal<PlatformCursorController> =
staticCompositionLocalOf {
NoOpPlatformCursorController
}
Loading