Skip to content

Windows: don't release mouse capture on WM_CAPTURECHANGED - #378

Open
cjbhaines wants to merge 1 commit into
RustAudio:masterfrom
cjbhaines:fix/windows-capture-transfer
Open

cjbhaines wants to merge 1 commit into
RustAudio:masterfrom
cjbhaines:fix/windows-capture-transfer

Conversation

@cjbhaines

Copy link
Copy Markdown

This is a small follow-up to #347 (the fix for #302).

When a window loses the mouse capture to another window, on_capture_changed calls ReleaseCapture. The thing is, Windows only sends WM_CAPTURECHANGED to the old window after it has already given the capture to the new one, so that release takes the capture away from the new window instead. I ran into it starting an OLE drag (DoDragDrop) from a button press in a baseview window: OLE takes the capture for the drag, on_capture_changed releases it, OLE never sees the mouse-up, and the drop never completes (dropping a file onto Explorer just did nothing).

The fix just drops the ReleaseCapture call. Everything else #347 added stays: the button counter still gets reset, so the stuck capture from #302 is still covered, and CursorLeft is still sent when no button was down. And if the capture was released rather than moved to another window, there's nothing left to release anyway.

Tests: I added a Windows test in src/platform/win/mouse.rs that does the same thing with two windows instead of OLE. It creates two hidden windows, sends WM_LBUTTONDOWN to the first so it takes the capture, calls SetCapture on the second, and checks that the second window still has the capture. It fails on master at the last assert (GetCapture() comes back null) and passes with the fix. It doesn't touch any of the files in #377, so the two don't depend on each other.

WM_CAPTURECHANGED reaches the window losing the capture after Windows
has already given it to the new window, so the ReleaseCapture call in
on_capture_changed took the capture away from that new window. Keep the
button counter reset and the CursorLeft handling, and drop the release.
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.

1 participant