diff --git a/src/allegro/src/win/wmouse.c b/src/allegro/src/win/wmouse.c index bf46fc83e..4584aaf55 100644 --- a/src/allegro/src/win/wmouse.c +++ b/src/allegro/src/win/wmouse.c @@ -251,6 +251,8 @@ static int mouse_winapi_select_system_cursor(int cursor) void _al_win_mouse_handle_button(HWND hwnd, int button, BOOL down, int x, int y, BOOL abs) { + int last_mouse_b; + _enter_critical(); if (down) @@ -258,8 +260,21 @@ void _al_win_mouse_handle_button(HWND hwnd, int button, BOOL down, int x, int y, else _mouse_b &= ~(1 << (button-1)); + last_mouse_b = _mouse_b; + _exit_critical(); + /* If there is a mouse button pressed we capture the mouse, in any + other cases we release it. */ + if (last_mouse_b) { + if (GetCapture() != hwnd) + SetCapture(hwnd); + } + else { + if (GetCapture() == hwnd) + ReleaseCapture(); + } + _handle_mouse_input(); } diff --git a/src/gui/system.cpp b/src/gui/system.cpp index caf7e7cf2..cea334ab0 100644 --- a/src/gui/system.cpp +++ b/src/gui/system.cpp @@ -366,11 +366,7 @@ void jmouse_set_position(int x, int y) void jmouse_capture() { -#if defined(ALLEGRO_WINDOWS) - - SetCapture(win_get_window()); - -#elif defined(ALLEGRO_UNIX) +#if defined(ALLEGRO_UNIX) XGrabPointer(_xwin.display, _xwin.window, False, PointerMotionMask | ButtonPressMask | ButtonReleaseMask, @@ -382,11 +378,7 @@ void jmouse_capture() void jmouse_release() { -#if defined(ALLEGRO_WINDOWS) - - ::ReleaseCapture(); - -#elif defined(ALLEGRO_UNIX) +#if defined(ALLEGRO_UNIX) XUngrabPointer(_xwin.display, CurrentTime);