Repository navigation
A field's caret blinks only while Hush's window is active, minimised included - #304
Merged
Merged
Conversation
gpui-base stops a field's blink on the first frame an inactive window draws, but a minimised window draws none, so the blink went on there (twice a second, nothing drawn), and a field given the keys while the window was inactive blinked behind. The window's activation now sets gpui-base's blink policy: blinking while active, steady otherwise.
The test gives the composer the keys again while the window is behind, which blinks unless deactivation set the steady setting. The drawables test's name no longer says a caret blinks behind another app, and the setting's comment says who stops the blink and that it is the app's.
Owner
Author
Review (pr-review-toolkit: code, tests, comments) and what was doneThere were no Critical findings. Fixes are in a794660; origin/main is merged in (526f8f1). Important
Suggestions taken
Declined
Noted, not changed
Gate on 526f8f1 (origin/main merged in): |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
A text field's caret now blinks only while Hush's window is active. When the window isn't active, gpui-base's blink is set to steady, so no timer runs and nothing redraws for it. When the window becomes active again, the blink comes back.
What changed
app::blink_while_activesets gpui-base's own caret policy,CursorBlink, through gpui-component'sTheme::update:CursorBlink::default()(500 ms) while the window is active,CursorBlink::steady()otherwise. It runs once when the window opens (a window can open inactive) and on every change in the window's activation (Hush::observe). gpui-base'sBlinkCursorwatches the theme, so a focused field's blink stops right away, without waiting for a frame. On activation, gpui-base's own activation observer andon_focusstart it again, now with the blinking setting. gpui-base isn't forked or patched.The doc comment on
drawables::let_go_soonand the name of one of its tests no longer say a caret blinks behind another app. Now it never does. On main it did only in the second case below, a field given the keys while the window was inactive.Not what the issue expected
The issue's reading (from #296) was that the caret keeps redrawing twice a second whenever Hush is behind another app. That's not what happens on main, by test and by measurement. On the first frame an inactive window draws, GPUI sends a focus event with an empty focus path (
Window::draw,current_window_active). gpui-base'son_blurthen stops the blink. macOS draws that frame when another app comes to the front, and also when Hush is hidden (⌘H). The blink kept going only where no such frame came:running::hide), so a field that had the keys kept this up for as long as Hush sat in the tray.focusstarts the blink directly, and no focus event stops it. This happens with a chat opened from the tray or a notification where the system won't bring the window up (running::show: on Windows and Wayland it may only ask for attention). It also happens with a window that opens behind.Both cases now stay quiet. The effect is small (see the numbers below), because the common case was already quiet.
How the caret looks while the window is inactive is unchanged: it isn't drawn. The issue asks for the caret "shown steady, as native fields do". gpui-base draws the caret only in an active window (
show_cursorcheckswindow.is_window_active()), and native fields do the same: AppKit draws no insertion point outside the key window, and Windows and GTK hide the caret when their window loses focus. Showing it would mean forking gpui-base, so it's left as it was. This needs the owner's call if a visible caret behind other apps is really wanted.Measured
I measured with a release binary (
cargo build --release -p hush-desktop --features snapshot) andHUSH_DATA_DIRset to a throwaway folder. Thesnapshotfeature is only there for the demo data. I used a scratch harness that isn't committed:hush --liveopensDemo::Chaton screen with the composer focused. It counts frames (Hush::rendercalls), the composer's notifies, and the process's CPU time (getrusage) over each phase, after one second to settle. The harness moves between phases itself: in front, behind another app (NSApp.deactivate), hidden (cx.hide()), minimised (minimize_window). The window was the default 1000×720 at 2×, on macOS. There were two short runs per build.When the window goes inactive, both builds draw exactly one frame (in the settling second), so the change adds no frame. One "after" run counted a single frame in a 10 s behind phase (0.1 frames/s). The second run didn't, and its settling second showed the same one frame as main, so I put it down to noise.
Tests
compose::window_tests::the_caret_blinks_only_while_the_window_is_in_front: the composer gets the keys while the window is behind, then the window is activated, deactivated and activated again. After the deactivate step it gives the composer the keys again while the window is behind. It counts the composer's notifies over 3 s in each state: 0 behind, at least 5 in front. It failed before the change at the first step ("given the keys behind, it doesn't blink": 6 notifies). The "given the keys behind again" step guards the steady setting on deactivation: with the setting applied only on activation, that step fails (6 notifies). The deactivate step on its own passed on main as well: GPUI's test windows always draw a frame, so a minimised window can't be reproduced in a test (the test platform can't minimise either). The minimised case is covered by the measurement above.make checkpasses on 526f8f1 (origin/main merged in):cargo fmt --check, bothclippy -D warningsruns, andcargo test --features hush-desktop/snapshot(404 + 553 passed, 4 ignored).--snapshot). The only differences are the demo's clock times, because the runs were a minute apart. I looked atchat-lightfrom both builds: same layout and styling. Snapshot windows are inactive, so neither build ever drew a caret there.Closes #297