History

win32: support multitouch

Use the multitouch API. To disable system's defualt mouse emulation, set --native-touch=yes.

nanahi committed 2 years ago

Commit e20ca151 parent 807a6d81 file · +54 −7Browse files

Unified · Split

video/out/w32_common.c+54−7
@@ -568,19 +568,29 @@ static void begin_dragging(struct vo_w32_state *w32) · 567 unmodified lines
568568 mp_input_put_key(w32->input_ctx, MP_INPUT_RELEASE_ALL);
569569 }
570570
571−static bool handle_mouse_down(struct vo_w32_state *w32, int btn, int x, int y)
571+// If native touch is enabled and the mouse event is emulated, ignore it.
572+// See: <https://learn.microsoft.com/en-us/windows/win32/tablet/
573+// system-events-and-mouse-messages#distinguishing-pen-input-from-mouse-and-touch>
574+static bool should_ignore_mouse_event(const struct vo_w32_state *w32)
572575 {
576+ return w32->opts->native_touch && ((GetMessageExtraInfo() & 0xFFFFFF00) == 0xFF515700);
577+}
578+
579+static void handle_mouse_down(struct vo_w32_state *w32, int btn, int x, int y)
580+{
581+ if (should_ignore_mouse_event(w32))
582+ return;
573583 btn |= mod_state(w32);
574584 mp_input_put_key(w32->input_ctx, btn | MP_KEY_STATE_DOWN);
575585 SetCapture(w32->window);
576− return false;
577586 }
578587
579588 static void handle_mouse_up(struct vo_w32_state *w32, int btn)
580589 {
590+ if (should_ignore_mouse_event(w32))
591+ return;
581592 btn |= mod_state(w32);
582593 mp_input_put_key(w32->input_ctx, btn | MP_KEY_STATE_UP);
583−
584594 ReleaseCapture();
585595 }
586596
@@ -1315,6 +1325,19 @@ static void update_cursor_passthrough(const struct vo_w32_state *w32) · 728 unmodified lines
13151325 }
13161326 }
13171327
1328+static void update_native_touch(const struct vo_w32_state *w32)
1329+{
1330+ if (w32->parent)
1331+ return;
1332+
1333+ if (w32->opts->native_touch) {
1334+ RegisterTouchWindow(w32->window, 0);
1335+ } else {
1336+ UnregisterTouchWindow(w32->window);
1337+ mp_input_put_key(w32->input_ctx, MP_TOUCH_RELEASE_ALL);
1338+ }
1339+}
1340+
13181341 static void set_ime_conversion_mode(const struct vo_w32_state *w32, DWORD mode)
13191342 {
13201343 if (w32->parent)
@@ -1615,14 +1638,14 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, · 294 unmodified lines
16151638 if (x != w32->mouse_x || y != w32->mouse_y) {
16161639 w32->mouse_x = x;
16171640 w32->mouse_y = y;
1618− mp_input_set_mouse_pos(w32->input_ctx, x, y);
1641+ if (!should_ignore_mouse_event(w32))
1642+ mp_input_set_mouse_pos(w32->input_ctx, x, y);
16191643 }
16201644 break;
16211645 }
16221646 case WM_LBUTTONDOWN:
1623− if (handle_mouse_down(w32, MP_MBTN_LEFT, GET_X_LPARAM(lParam),
1624− GET_Y_LPARAM(lParam)))
1625− return 0;
1647+ handle_mouse_down(w32, MP_MBTN_LEFT, GET_X_LPARAM(lParam),
1648+ GET_Y_LPARAM(lParam));
16261649 break;
16271650 case WM_LBUTTONUP:
16281651 handle_mouse_up(w32, MP_MBTN_LEFT);
@@ -1713,6 +1736,26 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, · 84 unmodified lines
17131736 case WM_SHOWMENU:
17141737 mp_win32_menu_show(w32->menu_ctx, w32->window);
17151738 break;
1739+ case WM_TOUCH: {
1740+ UINT count = LOWORD(wParam);
1741+ TOUCHINPUT *inputs = talloc_array_ptrtype(NULL, inputs, count);
1742+ if (GetTouchInputInfo((HTOUCHINPUT)lParam, count, inputs, sizeof(TOUCHINPUT))) {
1743+ for (UINT i = 0; i < count; i++) {
1744+ TOUCHINPUT *ti = &inputs[i];
1745+ POINT pt = {TOUCH_COORD_TO_PIXEL(ti->x), TOUCH_COORD_TO_PIXEL(ti->y)};
1746+ ScreenToClient(w32->window, &pt);
1747+ if (ti->dwFlags & TOUCHEVENTF_DOWN)
1748+ mp_input_add_touch_point(w32->input_ctx, ti->dwID, pt.x, pt.y);
1749+ if (ti->dwFlags & TOUCHEVENTF_MOVE)
1750+ mp_input_update_touch_point(w32->input_ctx, ti->dwID, pt.x, pt.y);
1751+ if (ti->dwFlags & TOUCHEVENTF_UP)
1752+ mp_input_remove_touch_point(w32->input_ctx, ti->dwID);
1753+ }
1754+ }
1755+ CloseTouchInputHandle((HTOUCHINPUT)lParam);
1756+ talloc_free(inputs);
1757+ return 0;
1758+ }
17161759 }
17171760
17181761 if (message == w32->tbtn_created_msg) {
@@ -1996,6 +2039,8 @@ static MP_THREAD_VOID gui_thread(void *ptr) · 277 unmodified lines
19962039 update_backdrop(w32);
19972040 if (w32->opts->cursor_passthrough)
19982041 update_cursor_passthrough(w32);
2042+ if (w32->opts->native_touch)
2043+ update_native_touch(w32);
19992044
20002045 if (SUCCEEDED(OleInitialize(NULL))) {
20012046 ole_ok = true;
@@ -2199,6 +2244,8 @@ static int gui_thread_control(struct vo_w32_state *w32, int request, void *arg) · 197 unmodified lines
21992244 update_maximized_state(w32, false);
22002245 } else if (changed_option == &vo_opts->window_corners) {
22012246 update_corners_pref(w32);
2247+ } else if (changed_option == &vo_opts->native_touch) {
2248+ update_native_touch(w32);
22022249 } else if (changed_option == &vo_opts->geometry || changed_option == &vo_opts->autofit ||
22032250 changed_option == &vo_opts->autofit_smaller || changed_option == &vo_opts->autofit_larger)
22042251 {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t