auto-hide cursor on idle and start (window) #732

Closed
github-bot wants to merge 2 commits from gh-pr/732/head into gh-pr/732/base
Owner

@⁠anatoliikuc on GitHub · 2026-09-20 14:18 UTC · original
anatoliikuc:fix/cursor-auto-hide-282 → main · +80 −6 · 3 files · 2 commits · closed without merging

Hides the mouse cursor over the game window when the game starts, and brings it back the moment you move the mouse. If it sits still for a couple seconds it hides itself again. Should help with games that draw their own cursor (e.g. Blue Prince), where the OS cursor just gets in the way.

Fixes #282

**@⁠anatoliikuc** on GitHub · 2026-09-20 14:18 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/732) `anatoliikuc:fix/cursor-auto-hide-282` → `main` · +80 −6 · 3 files · 2 commits · closed without merging Hides the mouse cursor over the game window when the game starts, and brings it back the moment you move the mouse. If it sits still for a couple seconds it hides itself again. Should help with games that draw their own cursor (e.g. Blue Prince), where the OS cursor just gets in the way. Fixes #282
The game timer pauses when the game pauses, but HostInputWaitEvent's
timeout keeps firing and mouse motion still gets dispatched while
paused, so the cursor could get stuck instead of reacting normally.
Time it off SDL_GetTicks64() instead.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:31:01 +00:00
github-bot closed this pull request 2026-11-26 09:31:01 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-09-20 14:24 UTC · original · edited 2026-09-20 14:28 UTC

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: a7cfa2d4-ee0e-462b-9cfe-c6e2314d2f5c

📥 Commits

Reviewing files that changed from the base of the PR and between 8867e0061c and b6ecd8dc56.

📒 Files selected for processing (1)
  • src/graphics/presentation/window/window.cpp
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/graphics/presentation/window/window.cpp

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.


📝 Walkthrough

Walkthrough

HostInputWaitEvent now accepts an optional timeout. Negative values remain indefinite. Nonnegative values use timed waiting and return false when no event arrives. Cursor restoration and auto-hide checks now use SDL monotonic time instead of the pausable game timer.

Priority: ⬇️ Low

Change: Feature · Severity of issue fixed: Low

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description check ✅ Passed The description accurately covers cursor hiding at startup, cursor restoration on mouse movement, idle auto-hide behavior, and the related issue.
Title check ✅ Passed The title clearly identifies the main change: automatic cursor hiding at startup and after inactivity in the window.
Linked Issues check ✅ Passed The pull request meets the coding objectives in #282. window.cpp hides the cursor at window startup, shows it on mouse movement, and hides it after mouse inactivity. SDL_GetTicks64() keeps the idl…
Out of Scope Changes check ✅ Passed The changes remain within #282. The HostInputWaitEvent timeout changes support periodic cursor-idle checks. The monotonic timing change supports correct auto-hide behavior during pauses. No unrelate…

Comment @coderabbitai help to get the list of available commands.

**@⁠coderabbitai[bot]** on GitHub · 2026-09-20 14:24 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/732#issuecomment-5750394417) · edited 2026-09-20 14:28 UTC <!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- review_stack_entry_start --> <a href="https://app.coderabbit.ai/change-stack/KytyPS5/KytyPS5/pull/732#gh-light-mode-only"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg" alt="Review Change Stack" width="202" height="32"></a><a href="https://app.coderabbit.ai/change-stack/KytyPS5/KytyPS5/pull/732#gh-dark-mode-only"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg" alt="Review Change Stack" width="202" height="32"></a> <!-- review_stack_entry_end --> <!-- recent_review_start --> No actionable comments were generated in the recent review. 🎉 <details> <summary>ℹ️ Recent review info</summary> <details> <summary>⚙️ Run configuration</summary> **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml **Review profile**: CHILL **Plan**: Advanced **Run ID**: `a7cfa2d4-ee0e-462b-9cfe-c6e2314d2f5c` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 8867e0061c7c26871b4bbee383ea41b46651c0d8 and b6ecd8dc56955fc88a77219a535f727f1a4d7bd3. </details> <details> <summary>📒 Files selected for processing (1)</summary> * `src/graphics/presentation/window/window.cpp` </details> <details> <summary>🚧 Files skipped from review as they are similar to previous changes (1)</summary> * src/graphics/presentation/window/window.cpp </details> **Included review availability:** Your plan provides up to 10 included reviews per hour; 8 remain after this review. </details> --- <!-- recent_review_end --> <!-- walkthrough_start --> <details> <summary>📝 Walkthrough</summary> ## Walkthrough `HostInputWaitEvent` now accepts an optional timeout. Negative values remain indefinite. Nonnegative values use timed waiting and return `false` when no event arrives. Cursor restoration and auto-hide checks now use SDL monotonic time instead of the pausable game timer. </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ⬇️ Low <!-- change_assessment_commit:"b6ecd8dc56955fc88a77219a535f727f1a4d7bd3" --> **Change:** Feature · **Severity of issue fixed:** Low <!-- change_assessment_end --> <!-- pre_merge_checks_walkthrough_start --> <details> <summary>🚥 Pre-merge checks | ✅ 4 | ❌ 1</summary> ### ❌ Failed checks (1 warning) | Check name | Status | Explanation | Resolution | | :----------------: | :--------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | :--------------------------------------------------------------------------------- | | Docstring Coverage | ⚠️ Warning | Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 3 files. | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary>✅ Passed checks (4 passed)</summary> | Check name | Status | Explanation | | :------------------------: | :------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Description check | ✅ Passed | The description accurately covers cursor hiding at startup, cursor restoration on mouse movement, idle auto-hide behavior, and the related issue. | | Title check | ✅ Passed | The title clearly identifies the main change: automatic cursor hiding at startup and after inactivity in the window. | | Linked Issues check | ✅ Passed | The pull request meets the coding objectives in `#282`. `window.cpp` hides the cursor at window startup, shows it on mouse movement, and hides it after mouse inactivity. `SDL_GetTicks64()` keeps the idl… | | Out of Scope Changes check | ✅ Passed | The changes remain within `#282`. The `HostInputWaitEvent` timeout changes support periodic cursor-idle checks. The monotonic timing change supports correct auto-hide behavior during pauses. No unrelate… | </details> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- tips_start --> --- <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-09-20 14:24 UTC · original · reviewed

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 039fc920-f5b9-4906-8dbd-f0e6d34fd5b7

📥 Commits

Reviewing files that changed from the base of the PR and between e930657bf6 and 8867e0061c.

📒 Files selected for processing (3)
  • src/graphics/presentation/window/hostInput.cpp
  • src/graphics/presentation/window/hostInput.h
  • src/graphics/presentation/window/window.cpp

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-09-20 14:24 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/732#pullrequestreview-5260812077) · **reviewed** **Actionable comments posted: 1** --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml **Review profile**: CHILL **Plan**: Advanced **Run ID**: `039fc920-f5b9-4906-8dbd-f0e6d34fd5b7` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between e930657bf65b323e25363dbb697eff036877504f and 8867e0061c7c26871b4bbee383ea41b46651c0d8. </details> <details> <summary>📒 Files selected for processing (3)</summary> * `src/graphics/presentation/window/hostInput.cpp` * `src/graphics/presentation/window/hostInput.h` * `src/graphics/presentation/window/window.cpp` </details> **Included review availability:** Your plan provides up to 10 included reviews per hour; 9 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-09-20 14:24 UTC · original · edited 2026-09-20 14:28 UTC
On src/graphics/presentation/window/window.cpp line 334 (outdated):

@@ -289,6 +330,10 @@ static void GameEventMouse([[maybe_unused]] const EventMouse& mb) {
 	}
 #endif
 
+	if (mb.motion) {
+		CursorShow(mb.timestamp_seconds);

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

sed -n '175,240p' src/graphics/presentation/window/window.cpp
sed -n '315,345p' src/graphics/presentation/window/window.cpp
sed -n '840,870p' src/graphics/presentation/window/window.cpp
rg -n 'class Timer|GetTimeS|Pause|Resume|timer\.' src/common src/graphics/presentation/window/window.cpp

Repository: KytyPS5/KytyPS5

Length of output: 5996


🏁 Script executed:

set -e
printf '%s\n' '--- timer implementation ---'
cat -n src/common/timer.cpp | sed -n '1,90p'
printf '%s\n' '--- timer declaration ---'
cat -n src/common/timer.h | sed -n '1,80p'
printf '%s\n' '--- window input/event bindings ---'
rg -n -C 5 'HostInputWaitEvent|timestamp_seconds|ProcessEvent|struct Mouse|MouseButton|SDL_WaitEvent|WaitEventTimeout|SDL_PollEvent' src/graphics src/common

Repository: KytyPS5/KytyPS5

Length of output: 35704


🏁 Script executed:

set -e
printf '%s\n' '--- HostInputWaitEvent ---'
cat -n src/graphics/presentation/window/hostInput.cpp | sed -n '411,455p'
printf '%s\n' '--- ProcessEvent mouse motion and timestamp ---'
cat -n src/graphics/presentation/window/window.cpp | sed -n '543,555p;600,675p'
printf '%s\n' '--- Run loop ---'
cat -n src/graphics/presentation/window/window.cpp | sed -n '838,861p'

Repository: KytyPS5/KytyPS5

Length of output: 5758


🏁 Script executed:

set -e
rg -n -C 12 'ProcessSystemOverlayInput' src/graphics

Repository: KytyPS5/KytyPS5

Length of output: 5888


🏁 Script executed:

set -e
cat -n src/graphics/presentation/systemOverlay.cpp | sed -n '469,545p'

Repository: KytyPS5/KytyPS5

Length of output: 3498


Use a non-pausing clock for cursor idle time.

Run() pauses timer while the game is paused, but HostInputWaitEvent() still performs timed waits and dispatches mouse motion. ProcessEvent() passes the paused timer.GetTimeS() value to CursorShow() and UpdateCursorAutoHide(). The cursor can therefore remain visible during the pause after mouse movement. Use a monotonic clock for both operations.

Proposed fix
+double CursorTimeS() {
+	return static_cast<double>(SDL_GetTicks64()) / 1000.0;
+}
+
 if (mb.motion) {
-	CursorShow(mb.timestamp_seconds);
+	CursorShow(CursorTimeS());
 }

-	UpdateCursorAutoHide(timer.GetTimeS());
+	UpdateCursorAutoHide(CursorTimeS());
 ...
-	UpdateCursorAutoHide(timer.GetTimeS());
+	UpdateCursorAutoHide(CursorTimeS());

✅ Addressed in commit b6ecd8d

**@⁠coderabbitai[bot]** on GitHub · 2026-09-20 14:24 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/732#discussion_r4057167388) · edited 2026-09-20 14:28 UTC On `src/graphics/presentation/window/window.cpp` line 334 (outdated): ```diff @@ -289,6 +330,10 @@ static void GameEventMouse([[maybe_unused]] const EventMouse& mb) { } #endif + if (mb.motion) { + CursorShow(mb.timestamp_seconds); ``` _🎯 Functional Correctness_ | _🟡 Minor_ | _⚡ Quick win_ <details> <summary>🔎 Supported by static analysis</summary> 🏁 Script executed: ```bash sed -n '175,240p' src/graphics/presentation/window/window.cpp sed -n '315,345p' src/graphics/presentation/window/window.cpp sed -n '840,870p' src/graphics/presentation/window/window.cpp rg -n 'class Timer|GetTimeS|Pause|Resume|timer\.' src/common src/graphics/presentation/window/window.cpp ``` Repository: KytyPS5/KytyPS5 Length of output: 5996 --- 🏁 Script executed: ```bash set -e printf '%s\n' '--- timer implementation ---' cat -n src/common/timer.cpp | sed -n '1,90p' printf '%s\n' '--- timer declaration ---' cat -n src/common/timer.h | sed -n '1,80p' printf '%s\n' '--- window input/event bindings ---' rg -n -C 5 'HostInputWaitEvent|timestamp_seconds|ProcessEvent|struct Mouse|MouseButton|SDL_WaitEvent|WaitEventTimeout|SDL_PollEvent' src/graphics src/common ``` Repository: KytyPS5/KytyPS5 Length of output: 35704 --- 🏁 Script executed: ```bash set -e printf '%s\n' '--- HostInputWaitEvent ---' cat -n src/graphics/presentation/window/hostInput.cpp | sed -n '411,455p' printf '%s\n' '--- ProcessEvent mouse motion and timestamp ---' cat -n src/graphics/presentation/window/window.cpp | sed -n '543,555p;600,675p' printf '%s\n' '--- Run loop ---' cat -n src/graphics/presentation/window/window.cpp | sed -n '838,861p' ``` Repository: KytyPS5/KytyPS5 Length of output: 5758 --- 🏁 Script executed: ```bash set -e rg -n -C 12 'ProcessSystemOverlayInput' src/graphics ``` Repository: KytyPS5/KytyPS5 Length of output: 5888 --- 🏁 Script executed: ```bash set -e cat -n src/graphics/presentation/systemOverlay.cpp | sed -n '469,545p' ``` Repository: KytyPS5/KytyPS5 Length of output: 3498 --- </details> **Use a non-pausing clock for cursor idle time.** `Run()` pauses `timer` while the game is paused, but `HostInputWaitEvent()` still performs timed waits and dispatches mouse motion. `ProcessEvent()` passes the paused `timer.GetTimeS()` value to `CursorShow()` and `UpdateCursorAutoHide()`. The cursor can therefore remain visible during the pause after mouse movement. Use a monotonic clock for both operations. <details> <summary>Proposed fix</summary> ```diff +double CursorTimeS() { + return static_cast<double>(SDL_GetTicks64()) / 1000.0; +} + if (mb.motion) { - CursorShow(mb.timestamp_seconds); + CursorShow(CursorTimeS()); } - UpdateCursorAutoHide(timer.GetTimeS()); + UpdateCursorAutoHide(CursorTimeS()); ... - UpdateCursorAutoHide(timer.GetTimeS()); + UpdateCursorAutoHide(CursorTimeS()); ``` </details> <!-- fingerprinting:phantom:medusa:tapir --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:ecfd0955ba54d553da0f21cf --> <!-- This is an auto-generated comment by CodeRabbit --> ✅ Addressed in commit b6ecd8d
@ -812,3 +866,4 @@
ProcessEvent(timer.GetTimeS());
UpdateCursorAutoHide(CursorTimeS());
}
}
Author
Owner

@⁠davidrohusch on GitHub · 2026-09-20 16:51 UTC · original

The whole mouse visibility function sounds more like an event to process.

Making the main loop more complex when it can be avoided is something I would preferably not do.

I subjectively think it would be more fit to extend ProcessEvent()

Any mouse motion could just invoke a SDL_AddTimer(CURSOR_IDLE_HIDE_SECONDS * 1000, CursorHide() ) + CursorShow()

**@⁠davidrohusch** on GitHub · 2026-09-20 16:51 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/732#discussion_r4057474166) The whole mouse visibility function sounds more like an event to process. Making the main loop more complex when it can be avoided is something I would preferably not do. I subjectively think it would be more fit to extend `ProcessEvent()` Any mouse motion could just invoke a `SDL_AddTimer(CURSOR_IDLE_HIDE_SECONDS * 1000, CursorHide() ) ` + CursorShow()
@ -812,3 +866,4 @@
ProcessEvent(timer.GetTimeS());
UpdateCursorAutoHide(CursorTimeS());
}
}
Author
Owner

@⁠davidrohusch on GitHub · 2026-09-20 16:59 UTC · original

Oh okay, nevermind. AddTimer is not desirable as it would spawn another thread, SDL prefers the graphic calls to be done within main thread. This would not work.

**@⁠davidrohusch** on GitHub · 2026-09-20 16:59 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/732#discussion_r4057493050) Oh okay, nevermind. AddTimer is not desirable as it would spawn another thread, SDL prefers the graphic calls to be done within main thread. This would not work.
Author
Owner

@⁠Nmzik on GitHub · 2026-10-03 14:22 UTC · original

@⁠anatoliikuc credited. Merged

**@⁠Nmzik** on GitHub · 2026-10-03 14:22 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/732#issuecomment-5970042807) @⁠anatoliikuc credited. Merged

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.