Enhance mouse event handling for middle mouse button #76
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
isMiddleMouseDown = trueinstartDrag()before dispatching the async event to prevent a race condition whereendDrag()could be called before the async block runs, which previously could leave the middle mouse button stuck down.isMiddleMouseDown = falsein bothendDrag()andcancelDrag()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 thatupdateDrag()stops processing immediately when the drag ends or is cancelled. [1] [2]UI thread safety improvement:
button.alphaValueafter an animation completion happens on the main actor using Swift concurrency, preventing potential UI glitches or crashes due to thread misuse.Minor codebase maintenance:
Notification.Nameextension for style consistency.