Skip to content

Editor updates mouse position while game widget is unfocused#10319

Open
aidencurtis wants to merge 2 commits intoFacepunch:masterfrom
aidencurtis:editor-input-focus
Open

Editor updates mouse position while game widget is unfocused#10319
aidencurtis wants to merge 2 commits intoFacepunch:masterfrom
aidencurtis:editor-input-focus

Conversation

@aidencurtis
Copy link
Copy Markdown
Contributor

@aidencurtis aidencurtis commented Mar 31, 2026

Pull Request

Thanks for contributing to s&box ❤️
Please fill out the sections below to help us review your change efficiently.


Summary

Bottom line: Fixes undesired behaviour when game widget is unfocused in editor.

  • Adds mouse position tracking while unfocused so clicking back into the game widget does not cause a click event on a position your mouse is not hovering.

Motivation & Context

Fixes: #10261

As someone developing a point and click game who wants to iterate between IDE / Terminal and s&box, this is a very annoying issue. Every single re-focus click is moving my character somewhere my mouse is not hovering (usually at the border of the screen). This will greatly improve my developer experience while working on games for the engine.

Implementation Details

While in editor and in play mode, the game widget can be unfocused (editor is unfocused, or interacting with editor panels). In this state, SDL stops reporting mouse positions, so the engine loses track of the cursor while it's hovering over the game widget.

To fix this, GameMode now enables MouseTracking and subscribes to the MouseMove event. When a move is received while the widget is unfocused, it calls InputRouter::OnMousePositionChange with the widget-local cursor position and a computed delta, keeping the mouse state in sync using the same path as native input.

InputRouter::OnMousePositionChange itself is also cleaned up. Position is now set before the relative-mode and capturechecks, and delta accumulation is skipped during mouse capture. GetRelativeMouseMode() is respected, zeroing the delta, which is consistent with pre-existing behaviour.

I've tested this in-editor, in-game, with mouse enabled, disabled, unfocused, in split view, scene view, within prefabs, etc. and can't seem to find any regressions.

Screenshots / Videos (if applicable)

Before After
https://github.com/user-attachments/assets/6ed03098-5bcf-4b71-9e2c-affd38b06a4a https://github.com/user-attachments/assets/88f1ee4e-89e3-48a0-a8cd-1d78b27a76f5
https://github.com/user-attachments/assets/60dcdede-9aa7-48e6-b63c-e9abbd349997 https://github.com/user-attachments/assets/f6749237-0305-4840-8811-5b3b4c703605

Checklist

  • Code follows existing style and conventions
  • No unnecessary formatting or unrelated changes
  • Public APIs are documented (if applicable)
  • Unit tests added where applicable and all passing
  • I’m okay with this PR being rejected or requested to change 🙂

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

In editor, clicking back into unfocused game window results in click at incorrect mouse position

1 participant