-
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.
+125
−0
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
Some comments aren't visible on the classic Files Changed page.
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
56 changes: 56 additions & 0 deletions
56
...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,56 @@ | ||
| // 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 | ||
|
|
||
| /** | ||
| * Standalone implementation of [PlatformCursorController] for macOS. | ||
| * | ||
| * This implementation uses JNA to call the native Objective-C method `[NSCursor setHiddenUntilMouseMoves:]`. The | ||
| * implementation is based on the platform code in `com.intellij.util.ui.MacUIUtil.hideCursor()`, but uses JNA's | ||
| * `objc_msgSend` directly instead of the IJ Foundation framework, since IJ APIs are not available in standalone mode. | ||
| * the Foundation framework, since Foundation is not available in standalone mode. | ||
| * | ||
| * @see com.intellij.util.ui.MacUIUtil.hideCursor | ||
| */ | ||
| internal object StandalonePlatformCursorController : PlatformCursorController { | ||
| private val objcLibrary: ObjCLibrary? by lazy { | ||
| try { | ||
| Native.load("objc", ObjCLibrary::class.java) | ||
| } catch (_: Exception) { | ||
wellingtoncosta marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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 (_: Throwable) { | ||
| // 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?) | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
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
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 | ||
|
|
||
| /** | ||
| * Controller for platform-specific cursor behavior. | ||
| * | ||
| * This interface provides methods to control cursor visibility and behavior in a platform-specific way. Implementations | ||
| * should handle platform differences internally. | ||
| */ | ||
| public interface PlatformCursorController { | ||
wellingtoncosta marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /** Hides the mouse cursor while the user is typing. This is a MacOS-only behavior. */ | ||
| public fun hideCursorWhileTyping() | ||
| } | ||
|
|
||
| public val LocalPlatformCursorController: ProvidableCompositionLocal<PlatformCursorController> = | ||
| staticCompositionLocalOf { | ||
| error("No LocalPlatformCursorController provided. Have you forgotten the theme?") | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.