mirror of
https://github.com/mpv-player/mpv.git
synced 2024-09-20 12:02:23 +02:00
w32_common: refactor mouse button handling
Previously, the shared behaviour for each mouse-button message lived at the bottom of the WndProc. Move it into handle_mouse_down/up functions (similar to the handle_key_down/up functions.) This makes the WndProc slightly less complicated. There should be no change in behaviour.
This commit is contained in:
parent
1c0bd59bc2
commit
0e4531440d
@ -399,6 +399,35 @@ static bool handle_char(struct vo_w32_state *w32, wchar_t wc)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool handle_mouse_down(struct vo_w32_state *w32, int btn, int x, int y)
|
||||||
|
{
|
||||||
|
btn |= mod_state(w32);
|
||||||
|
mp_input_put_key(w32->input_ctx, btn | MP_KEY_STATE_DOWN);
|
||||||
|
|
||||||
|
if (btn == MP_MOUSE_BTN0 && !w32->current_fs &&
|
||||||
|
!mp_input_test_dragging(w32->input_ctx, x, y))
|
||||||
|
{
|
||||||
|
// Window dragging hack
|
||||||
|
ReleaseCapture();
|
||||||
|
SendMessage(w32->window, WM_NCLBUTTONDOWN, HTCAPTION, 0);
|
||||||
|
mp_input_put_key(w32->input_ctx, MP_MOUSE_BTN0 | MP_KEY_STATE_UP);
|
||||||
|
|
||||||
|
// Indicate the message was handled, so DefWindowProc won't be called
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
SetCapture(w32->window);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void handle_mouse_up(struct vo_w32_state *w32, int btn)
|
||||||
|
{
|
||||||
|
btn |= mod_state(w32);
|
||||||
|
mp_input_put_key(w32->input_ctx, btn | MP_KEY_STATE_UP);
|
||||||
|
|
||||||
|
ReleaseCapture();
|
||||||
|
}
|
||||||
|
|
||||||
static void signal_events(struct vo_w32_state *w32, int events)
|
static void signal_events(struct vo_w32_state *w32, int events)
|
||||||
{
|
{
|
||||||
atomic_fetch_or(&w32->event_flags, events);
|
atomic_fetch_or(&w32->event_flags, events);
|
||||||
@ -840,7 +869,6 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam,
|
|||||||
if (!w32->window)
|
if (!w32->window)
|
||||||
w32->window = hWnd; // can happen during CreateWindow*!
|
w32->window = hWnd; // can happen during CreateWindow*!
|
||||||
assert(w32->window == hWnd);
|
assert(w32->window == hWnd);
|
||||||
int mouse_button = 0;
|
|
||||||
|
|
||||||
switch (message) {
|
switch (message) {
|
||||||
case WM_USER:
|
case WM_USER:
|
||||||
@ -1028,35 +1056,42 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WM_LBUTTONDOWN:
|
case WM_LBUTTONDOWN:
|
||||||
mouse_button = MP_MOUSE_BTN0 | MP_KEY_STATE_DOWN;
|
if (handle_mouse_down(w32, MP_MOUSE_BTN0, GET_X_LPARAM(lParam),
|
||||||
|
GET_Y_LPARAM(lParam)))
|
||||||
|
return 0;
|
||||||
break;
|
break;
|
||||||
case WM_LBUTTONUP:
|
case WM_LBUTTONUP:
|
||||||
mouse_button = MP_MOUSE_BTN0 | MP_KEY_STATE_UP;
|
handle_mouse_up(w32, MP_MOUSE_BTN0);
|
||||||
break;
|
break;
|
||||||
case WM_MBUTTONDOWN:
|
case WM_MBUTTONDOWN:
|
||||||
mouse_button = MP_MOUSE_BTN1 | MP_KEY_STATE_DOWN;
|
handle_mouse_down(w32, MP_MOUSE_BTN1, GET_X_LPARAM(lParam),
|
||||||
|
GET_Y_LPARAM(lParam));
|
||||||
break;
|
break;
|
||||||
case WM_MBUTTONUP:
|
case WM_MBUTTONUP:
|
||||||
mouse_button = MP_MOUSE_BTN1 | MP_KEY_STATE_UP;
|
handle_mouse_up(w32, MP_MOUSE_BTN1);
|
||||||
break;
|
break;
|
||||||
case WM_RBUTTONDOWN:
|
case WM_RBUTTONDOWN:
|
||||||
mouse_button = MP_MOUSE_BTN2 | MP_KEY_STATE_DOWN;
|
handle_mouse_down(w32, MP_MOUSE_BTN2, GET_X_LPARAM(lParam),
|
||||||
|
GET_Y_LPARAM(lParam));
|
||||||
break;
|
break;
|
||||||
case WM_RBUTTONUP:
|
case WM_RBUTTONUP:
|
||||||
mouse_button = MP_MOUSE_BTN2 | MP_KEY_STATE_UP;
|
handle_mouse_up(w32, MP_MOUSE_BTN2);
|
||||||
break;
|
break;
|
||||||
case WM_MOUSEWHEEL: {
|
case WM_MOUSEWHEEL: {
|
||||||
int x = GET_WHEEL_DELTA_WPARAM(wParam);
|
int x = GET_WHEEL_DELTA_WPARAM(wParam);
|
||||||
mouse_button = x > 0 ? MP_MOUSE_BTN3 : MP_MOUSE_BTN4;
|
mp_input_put_key(w32->input_ctx,
|
||||||
|
(x > 0 ? MP_MOUSE_BTN3 : MP_MOUSE_BTN4) |
|
||||||
|
mod_state(w32));
|
||||||
|
ReleaseCapture();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WM_XBUTTONDOWN:
|
case WM_XBUTTONDOWN:
|
||||||
mouse_button = HIWORD(wParam) == 1 ? MP_MOUSE_BTN5 : MP_MOUSE_BTN6;
|
handle_mouse_down(w32,
|
||||||
mouse_button |= MP_KEY_STATE_DOWN;
|
HIWORD(wParam) == 1 ? MP_MOUSE_BTN5 : MP_MOUSE_BTN6,
|
||||||
|
GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
|
||||||
break;
|
break;
|
||||||
case WM_XBUTTONUP:
|
case WM_XBUTTONUP:
|
||||||
mouse_button = HIWORD(wParam) == 1 ? MP_MOUSE_BTN5 : MP_MOUSE_BTN6;
|
handle_mouse_up(w32, HIWORD(wParam) == 1 ? MP_MOUSE_BTN5 : MP_MOUSE_BTN6);
|
||||||
mouse_button |= MP_KEY_STATE_UP;
|
|
||||||
break;
|
break;
|
||||||
case WM_DISPLAYCHANGE:
|
case WM_DISPLAYCHANGE:
|
||||||
force_update_display_info(w32);
|
force_update_display_info(w32);
|
||||||
@ -1069,33 +1104,6 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mouse_button) {
|
|
||||||
mouse_button |= mod_state(w32);
|
|
||||||
mp_input_put_key(w32->input_ctx, mouse_button);
|
|
||||||
|
|
||||||
if (mp_input_mouse_enabled(w32->input_ctx)) {
|
|
||||||
int x = GET_X_LPARAM(lParam);
|
|
||||||
int y = GET_Y_LPARAM(lParam);
|
|
||||||
|
|
||||||
if (mouse_button == (MP_MOUSE_BTN0 | MP_KEY_STATE_DOWN) &&
|
|
||||||
!w32->current_fs &&
|
|
||||||
!mp_input_test_dragging(w32->input_ctx, x, y))
|
|
||||||
{
|
|
||||||
// Window dragging hack
|
|
||||||
ReleaseCapture();
|
|
||||||
SendMessage(hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0);
|
|
||||||
mp_input_put_key(w32->input_ctx, MP_MOUSE_BTN0 |
|
|
||||||
MP_KEY_STATE_UP);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mouse_button & MP_KEY_STATE_DOWN)
|
|
||||||
SetCapture(w32->window);
|
|
||||||
else
|
|
||||||
ReleaseCapture();
|
|
||||||
}
|
|
||||||
|
|
||||||
return DefWindowProcW(hWnd, message, wParam, lParam);
|
return DefWindowProcW(hWnd, message, wParam, lParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user