-
Notifications
You must be signed in to change notification settings - Fork 5.7k
[JEWEL-992] Hide mouse cursor while typing in BTF on macOS #3372
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
wellingtoncosta
wants to merge
1
commit into
JetBrains:master
Choose a base branch
from
wellingtoncosta:wp/hide-cursor-while-typing-macos
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
...e-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/BridgePlatformCursorController.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...rc/main/kotlin/org/jetbrains/jewel/intui/standalone/StandalonePlatformCursorController.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 { | ||
| 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?) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
platform/jewel/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/HideCursorOnTyping.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...form/jewel/ui/src/main/kotlin/org/jetbrains/jewel/ui/platform/PlatformCursorController.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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