-
Notifications
You must be signed in to change notification settings - Fork 3.5k
hide mouse after idle time based on mouse-hide-after config
#9937
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
kaplanelad
wants to merge
5
commits into
ghostty-org:main
Choose a base branch
from
kaplanelad:feature/mouse-hide-after
base: main
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 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
de79e79
hide mouse after idle time based on `mouse-hide-after` config
kaplanelad 380e2ab
Merge branch 'ghostty-org:main' into feature/mouse-hide-after
kaplanelad 345a20a
move mouse-hide-after implementation to apprt
kaplanelad e890856
review changes
kaplanelad 39c0826
remove last_mouse_move_time
kaplanelad 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -587,6 +587,14 @@ pub const Surface = extern struct { | |
| // Progress bar | ||
| progress_bar_timer: ?c_uint = null, | ||
|
|
||
| /// Timer source id for `mouse-hide-after` idle hiding. When non-null, | ||
| /// a one-shot GLib timeout is scheduled to hide the mouse after the | ||
| /// configured idle duration. | ||
| mouse_hide_after_timer: ?c_uint = null, | ||
|
|
||
| /// The last time we observed mouse movement, used for `mouse-hide-after`. | ||
| last_mouse_move_time: ?std.time.Instant = null, | ||
|
|
||
| // True while the bell is ringing. This will be set to false (after | ||
| // true) under various scenarios, but can also manually be set to | ||
| // false by a parent widget. | ||
|
|
@@ -911,6 +919,24 @@ pub const Surface = extern struct { | |
| return @intFromBool(glib.SOURCE_REMOVE); | ||
| } | ||
|
|
||
| /// Timer callback for `mouse-hide-after`. Hides the mouse after a period | ||
| /// of no mouse movement. | ||
| fn mouseHideAfterTimer(ud: ?*anyopaque) callconv(.c) c_int { | ||
| const self: *Self = @ptrCast(@alignCast(ud orelse | ||
| return @intFromBool(glib.SOURCE_REMOVE))); | ||
| const priv = self.private(); | ||
|
|
||
| // Clear our timer handle first to avoid reusing it. | ||
| priv.mouse_hide_after_timer = null; | ||
|
|
||
| // Hide the mouse cursor directly. | ||
| if (!priv.mouse_hidden) { | ||
| self.setMouseHidden(true); | ||
| } | ||
|
|
||
| return @intFromBool(glib.SOURCE_REMOVE); | ||
| } | ||
|
|
||
| /// Request that this terminal come to the front and become focused. | ||
| /// It is up to the embedding widget to react to this. | ||
| pub fn present(self: *Self) void { | ||
|
|
@@ -1716,6 +1742,13 @@ pub const Surface = extern struct { | |
| priv.progress_bar_timer = null; | ||
| } | ||
|
|
||
| if (priv.mouse_hide_after_timer) |timer| { | ||
| if (glib.Source.remove(timer) == 0) { | ||
| log.warn("unable to remove mouse hide-after timer", .{}); | ||
| } | ||
| priv.mouse_hide_after_timer = null; | ||
| } | ||
|
|
||
| if (priv.idle_rechild) |v| { | ||
| if (glib.Source.remove(v) == 0) { | ||
| log.warn("unable to remove idle source", .{}); | ||
|
|
@@ -2641,6 +2674,12 @@ pub const Surface = extern struct { | |
| @abs(priv.cursor_pos.y - pos.y) < 1; | ||
| if (is_cursor_still) return; | ||
|
|
||
| // If the mouse is currently hidden (for example due to `mouse-hide-after`), | ||
| // show it again on real mouse movement. | ||
| if (priv.mouse_hidden) { | ||
| self.setMouseHidden(false); | ||
| } | ||
|
|
||
| // If we don't have focus, and we want it, grab it. | ||
| if (priv.config) |config| { | ||
| const gl_area_widget = priv.gl_area.as(gtk.Widget); | ||
|
|
@@ -2654,6 +2693,27 @@ pub const Surface = extern struct { | |
| // Our pos changed, update | ||
| priv.cursor_pos = pos; | ||
|
|
||
| // Track mouse movement time for `mouse-hide-after`. | ||
| priv.last_mouse_move_time = std.time.Instant.now() catch null; | ||
|
Member
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. Is this ever used? I don't think it is, right? |
||
|
|
||
| // Reset `mouse-hide-after` idle timer if configured. | ||
| if (priv.mouse_hide_after_timer) |timer| { | ||
| if (glib.Source.remove(timer) == 0) { | ||
| log.warn("unable to remove mouse hide-after timer", .{}); | ||
| } | ||
| priv.mouse_hide_after_timer = null; | ||
| } | ||
| if (priv.config) |config| { | ||
| const ms = config.get().@"mouse-hide-after".asMilliseconds(); | ||
| if (ms > 0) { | ||
| priv.mouse_hide_after_timer = glib.timeoutAdd( | ||
| ms, | ||
| mouseHideAfterTimer, | ||
| self, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| // Notify the callback | ||
| if (priv.core_surface) |surface| { | ||
| const gtk_mods = event.getModifierState(); | ||
|
|
||
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
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.
Using
Durationis better, likeundoTimeoutdown below