Skip to content

fix: stop sending movement input when the window is unfocused - #5335

Merged
soloturn merged 2 commits into
developfrom
soloturn-unfocused-input
Aug 9, 2026
Merged

fix: stop sending movement input when the window is unfocused#5335
soloturn merged 2 commits into
developfrom
soloturn-unfocused-input

Conversation

@soloturn

Copy link
Copy Markdown
Contributor

Summary

  • LocalPlayerSystem.processInput() sent a CharacterMoveInputEvent every frame unconditionally, even with zero keys held and no window focus - a per-frame heartbeat, not edge-triggered on actual input.
  • Under a normal frame rate the resulting client/server clock skew is small enough to pass ServerCharacterPredictionSystem's overflow check. When macOS throttles a backgrounded window's render loop to a much lower rate (e.g. after Cmd+Tab), the network-queue delivery granularity no longer scales with it, so a small residual skew leaks past the check every single frame - spamming the "dropping input" warning continuously for as long as the window stays unfocused.
  • Fixed by gating processInput() on DisplayDevice.hasFocus(), the same check InputSystem.isCapturingMouse() already uses for raw device polling - no movement input gets generated at all while unfocused.

Test plan

  • gradle :engine:compileJava succeeds
  • Cmd+Tab away from the game window and confirm no more "dropping input" spam in the log

🤖 Generated with Claude Code

@github-actions github-actions Bot added the Type: Bug Issues reporting and PRs fixing problems label Jul 26, 2026
@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Improved input handling so keyboard and mouse actions are ignored when the game window isn’t focused.
    • Prevented stale movement, look, and jump input from being processed or triggering unintended gameplay interactions while the display is inactive.

Walkthrough

LocalPlayerSystem now receives DisplayDevice through dependency injection. When the display is unfocused, processInput clears input state and skips event emission.

Changes

Local player input

Layer / File(s) Summary
Display focus input guard
engine/src/main/java/org/terasology/engine/logic/players/LocalPlayerSystem.java
Injects DisplayDevice. When the display lacks focus, processInput clears movement, look deltas, and jump state before returning.

Estimated code review effort: 1 (Trivial) | ~3 minutes

Poem

A rabbit checks the display light,
Then clears stale hops from sight.
No jump or turn can travel through,
Until the window gains its view.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: preventing movement input while the window is unfocused.
Description check ✅ Passed The description directly explains the unfocused-window input bug, the fix, and the test status.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch soloturn-unfocused-input

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@engine/src/main/java/org/terasology/engine/logic/players/LocalPlayerSystem.java`:
- Around line 145-148: Update processInput() so that when display.hasFocus() is
false, relativeMovement, lookPitchDelta, lookYawDelta, and jump are reset or
invalidated before returning; ensure these input values cannot persist and be
reused when focus is restored without new input.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a07093b4-31ee-40b1-bea0-c9ec5ccb74e2

📥 Commits

Reviewing files that changed from the base of the PR and between 0018a0a and 4cb010e.

📒 Files selected for processing (1)
  • engine/src/main/java/org/terasology/engine/logic/players/LocalPlayerSystem.java

@soloturn
soloturn force-pushed the soloturn-unfocused-input branch 3 times, most recently from df2f7b7 to 4a7d17c Compare July 28, 2026 19:58
@Cervator

Cervator commented Aug 2, 2026

Copy link
Copy Markdown
Member

I tested this, admittedly on Windows, and while movement stops when I press ESC it does not stop if I Alt+Tab away from the window, nor if I use the Windows key to otherwise lose focus. That's single player and not on a Mac, however, and I did not go hunting for the logging.

Not sure how much of that was already an issue before this PR, but I wonder if we should cover it as well / test fully on different OSes?

@soloturn

soloturn commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

looked again at it. with josariassurvival, when switching away with tab, it gives endless:

20:45:28.288 [main] WARN  o.t.e.l.c.ServerCharacterPredictionSystem - Received too much input from EntityRef{id = 1330, netId = 2061, prefab = 'engine:player'}, dropping input. Delta difference: 22.0
20:45:28.416 [main] WARN  o.t.e.l.c.ServerCharacterPredictionSystem - Received too much input from EntityRef{id = 1330, netId = 2061, prefab = 'engine:player'}, dropping input. Delta difference: 28.0
20:45:28.537 [main] WARN  o.t.e.l.c.ServerCharacterPredictionSystem - Received too much input from EntityRef{id = 1330, netId = 2061, prefab = 'engine:player'}, dropping input. Delta difference: 20.0
20:45:28.658 [main] WARN  o.t.e.l.c.ServerCharacterPredictionSystem - Received too much input from EntityRef{id = 1330, netId = 2061, prefab = 'engine:player'}, dropping input. Delta difference: 22.0
20:45:28.777 [main] WARN  o.t.e.l.c.ServerCharacterPredictionSystem - Received too much input from EntityRef{id = 1330, netId = 2061, prefab = 'engine:player'}, dropping input. Delta difference: 18.0
20:45:28.897 [main] WARN  o.t.e.l.c.ServerCharacterPredictionSystem - Received too much input from EntityRef{id = 1330, netId = 2061, prefab = 'engine:player'}, dropping input. Delta difference: 19.0

with core gameplay not. applying this pr stops the output for JSS.

soloturn added a commit that referenced this pull request Aug 9, 2026
Addresses BenjaminAmos/CodeRabbit review on #5335.
soloturn and others added 2 commits August 9, 2026 13:54
processInput sent a CharacterMoveInputEvent every frame regardless of
focus, even with zero keys held. Under a normal frame rate the
resulting client/server clock skew is small enough to pass the
server's overflow check. When macOS throttles a backgrounded window's
render loop, the skew grows past the check every frame, spamming
ServerCharacterPredictionSystem's dropped-input warning the whole time
the window is unfocused.

Gate processInput on DisplayDevice.hasFocus, the same check
InputSystem.isCapturingMouse already uses for raw device polling.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Addresses BenjaminAmos/CodeRabbit review on #5335.
@soloturn
soloturn force-pushed the soloturn-unfocused-input branch from f188544 to 60b3c32 Compare August 9, 2026 11:54
@soloturn
soloturn merged commit 186a39a into develop Aug 9, 2026
12 checks passed
@soloturn

soloturn commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

tested on linux, unfocussed error with terasologylauncher downloaded game.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Bug Issues reporting and PRs fixing problems

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants