Skip to content

Conversation

@NullPointerDepressiveDisorder
Copy link
Owner

This pull request addresses critical race conditions in the mouse drag event handling logic and improves UI state mutation safety. The most important changes focus on ensuring correct state transitions for mouse events and proper thread usage for UI updates.

Race condition fixes in mouse event handling:

  • Synchronously set isMiddleMouseDown = true in startDrag() before dispatching the async event to prevent a race condition where endDrag() could be called before the async block runs, which previously could leave the middle mouse button stuck down.
  • Synchronously set isMiddleMouseDown = false in both endDrag() and cancelDrag() before dispatching the async event, ensuring that rapid start/end or cancel/start cycles do not cause inconsistent state or missed mouse up events. This also ensures that updateDrag() stops processing immediately when the drag ends or is cancelled. [1] [2]

UI thread safety improvement:

  • Ensured that mutation of button.alphaValue after an animation completion happens on the main actor using Swift concurrency, preventing potential UI glitches or crashes due to thread misuse.

Minor codebase maintenance:

  • Added a newline at the end of the Notification.Name extension for style consistency.

- Set isMiddleMouseDown synchronously in startDrag, endDrag, and cancelDrag methods to prevent race conditions during rapid drag cycles.
- Ensure proper state management by synchronously updating isMiddleMouseDown before dispatching asynchronous tasks.
- Update MenuBarController to ensure UI mutations occur on the main actor, improving thread safety for UI updates.
Copilot AI review requested due to automatic review settings January 22, 2026 02:11
@NullPointerDepressiveDisorder NullPointerDepressiveDisorder linked an issue Jan 22, 2026 that may be closed by this pull request
@sentry
Copy link
Contributor

sentry bot commented Jan 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens middle mouse drag handling by eliminating race conditions around the drag state flag and ensures UI updates to the menu bar icon are performed safely on the main actor.

Changes:

  • Update MouseEventGenerator to set isMiddleMouseDown synchronously in startDrag, endDrag, and cancelDrag while keeping event posting on the serial eventQueue, closing race windows that could leave the middle button logically “stuck” or allow updateDrag to continue after a drag ends.
  • Wrap the completion of the status item icon fade animation in a Task { @MainActor in ... } to guarantee button.alphaValue is mutated on the main actor.
  • Add a trailing newline to the Notification.Name extension for style consistency.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
MiddleDrag/Core/MouseEventGenerator.swift Adjusts drag state transitions to set isMiddleMouseDown under a lock before/when ending drags, ensuring consistent state and immediate stopping of drag updates while preserving correct sequencing of CGEvents on eventQueue.
MiddleDrag/UI/MenuBarController.swift Ensures the status item button’s alpha reset after the animation is performed on the main actor via Swift concurrency, and adds a trailing newline to the notification name extension.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Updated the MouseEventGenerator to set the isMiddleMouseDown flag and send the mouse-down event synchronously, preventing potential race conditions during drag operations.
- Improved comments to clarify the critical nature of synchronous execution for both flag setting and event dispatching.
@NullPointerDepressiveDisorder NullPointerDepressiveDisorder merged commit 9ed3de4 into main Jan 22, 2026
6 checks passed
@NullPointerDepressiveDisorder NullPointerDepressiveDisorder deleted the 73-still-getting-the-odd-stickiness branch January 22, 2026 02:24
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.

Still getting the odd stickiness.

2 participants