1
0
mirror of https://github.com/mpv-player/mpv synced 2025-03-25 04:38:01 +00:00

w32_common: implement VOCTRL_BEGIN_DRAGGING

This allows begin-vo-dragging command to initialize a vo dragging request
for win32. Also set dragging to release all keys like for other platforms.
The hard-coded left mouse button down trigger is scheduled to be removed
in a later commit.
This commit is contained in:
nanahi 2024-02-26 18:49:03 -05:00 committed by sfan5
parent 6eedf9b1e9
commit 14c5da6f50

View File

@ -472,29 +472,35 @@ static bool handle_char(struct vo_w32_state *w32, WPARAM wc, bool decode)
return true;
}
static void begin_dragging(struct vo_w32_state *w32)
{
if (mp_input_test_dragging(w32->input_ctx, w32->mouse_x, w32->mouse_y))
return;
// Window dragging hack
ReleaseCapture();
// The dragging model loop is entered at SendMessage() here.
// Unfortunately, the w32->current_fs value is stale because the
// input is handled in a different thread, and we cannot wait for
// an up-to-date value before entering the model loop if dragging
// needs to be kept resonsive.
// Workaround this by intercepting the loop in the WM_MOVING message,
// where the up-to-date value is available.
SystemParametersInfoW(SPI_GETWINARRANGING, 0, &w32->win_arranging, 0);
w32->dragging = true;
SendMessage(w32->window, WM_NCLBUTTONDOWN, HTCAPTION, 0);
w32->dragging = false;
SystemParametersInfoW(SPI_SETWINARRANGING, w32->win_arranging, 0, 0);
mp_input_put_key(w32->input_ctx, MP_INPUT_RELEASE_ALL);
}
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_MBTN_LEFT && !mp_input_test_dragging(w32->input_ctx, x, y)) {
// Window dragging hack
ReleaseCapture();
// The dragging model loop is entered at SendMessage() here.
// Unfortunately, the w32->current_fs value is stale because the
// input is handled in a different thread, and we cannot wait for
// an up-to-date value before entering the model loop if dragging
// needs to be kept resonsive.
// Workaround this by intercepting the loop in the WM_MOVING message,
// where the up-to-date value is available.
SystemParametersInfoW(SPI_GETWINARRANGING, 0, &w32->win_arranging, 0);
w32->dragging = true;
SendMessage(w32->window, WM_NCLBUTTONDOWN, HTCAPTION, 0);
w32->dragging = false;
SystemParametersInfoW(SPI_SETWINARRANGING, w32->win_arranging, 0, 0);
mp_input_put_key(w32->input_ctx, MP_MBTN_LEFT | MP_KEY_STATE_UP);
if (btn == MP_MBTN_LEFT) {
begin_dragging(w32);
// Indicate the message was handled, so DefWindowProc won't be called
return true;
}
@ -2164,6 +2170,9 @@ static int gui_thread_control(struct vo_w32_state *w32, int request, void *arg)
case VOCTRL_GET_FOCUSED:
*(bool *)arg = w32->focused;
return VO_TRUE;
case VOCTRL_BEGIN_DRAGGING:
begin_dragging(w32);
return VO_TRUE;
}
return VO_NOTIMPL;
}