Skip to content

fix: address mouse capture review feedback#1962

Merged
maximilien-noal merged 2 commits intofeature/mouse_capturefrom
copilot/sub-pr-1805
Mar 12, 2026
Merged

fix: address mouse capture review feedback#1962
maximilien-noal merged 2 commits intofeature/mouse_capturefrom
copilot/sub-pr-1805

Conversation

Copy link
Contributor

Copilot AI commented Mar 12, 2026

Addresses all review comments from the mouse capture PR review.

Description of Changes

NativeMouseCapture.cs

  • Renamed x11Display/isCaptured_x11Display/_isCaptured (underscore-prefix convention)
  • Fixed macOS DllImport: "libSystem.dylib""CoreGraphics" (symbols live in CoreGraphics framework, not libSystem)
  • DisableCapture(): _isCaptured now only set to false after the platform call succeeds — prevents state/OS mismatch on failure, and ensures Cleanup() still releases if an earlier disable failed
  • XGrabPointer confineTo: IntPtr.ZerowindowHandle — without this, X11 grab doesn't actually confine the cursor

MainWindow.axaml.cs

  • Replaced LayoutUpdated (fires every layout pass → repeated native calls) with SizeChanged/PositionChanged for re-applying capture only on actual bounds changes
  • Renamed AttemptCaptureIfPointerInViewAttemptCapture — no pointer-in-view check was ever performed; name was misleading
  • Added Deactivated/Activated handlers: capture is released on focus loss (Alt+Tab) and restored on re-activation, preventing the cursor from being trapped outside the window

Rationale behind Changes

The original implementation had several correctness and behavioral issues: internal state could desync from OS state on failed platform calls, X11 capture didn't actually confine the cursor, LayoutUpdated caused excessive native syscalls, and Alt+Tab would leave the cursor permanently trapped.

Suggested Testing Steps

  • Toggle capture with middle-click; Alt+Tab away and back — cursor should be released and recaptured automatically
  • Resize/move the window while captured — clip rect should update correctly
  • On Linux: verify cursor is actually confined to the window boundary
  • On macOS: verify no DllNotFoundException at runtime

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: maximilien-noal <1087524+maximilien-noal@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 12, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • av-build-tel-api-v1.avaloniaui.net
    • Triggering command: /usr/share/dotnet/dotnet dotnet exec --runtimeconfig /home/REDACTED/.nuget/packages/avalonia.buildservices/11.3.2/tools/netstandard2.0/runtimeconfig.json /home/REDACTED/.nuget/packages/avalonia.buildservices/11.3.2/tools/netstandard2.0/Avalonia.BuildServices.Collector.dll (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] Add mouse capture feature to game window fix: address mouse capture review feedback Mar 12, 2026
@maximilien-noal maximilien-noal marked this pull request as ready for review March 12, 2026 06:53
@maximilien-noal maximilien-noal merged commit 4899ee9 into feature/mouse_capture Mar 12, 2026
@maximilien-noal maximilien-noal deleted the copilot/sub-pr-1805 branch March 12, 2026 06:53
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.

2 participants