diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2020-05-04 12:49:29 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-04 12:49:29 +0200 |
commit | a6d83f7f3d856929156e4c56e33b95920a24283c (patch) | |
tree | ad464182bc9a5d2d2dd9d2302b5a91106dfdd067 | |
parent | 2df844d5b311fc8d8b18040020df82c73d4365dd (diff) | |
parent | 012894789443dbb4f1882c11fd08b4c2f1618a0f (diff) |
Merge pull request #38439 from bruvzg/mouse_pressure
Make non pressure sensitive device behavior consistent.
-rw-r--r-- | platform/linuxbsd/display_server_x11.cpp | 11 | ||||
-rw-r--r-- | platform/linuxbsd/display_server_x11.h | 1 | ||||
-rw-r--r-- | platform/windows/display_server_windows.cpp | 13 | ||||
-rw-r--r-- | platform/windows/display_server_windows.h | 16 |
4 files changed, 37 insertions, 4 deletions
diff --git a/platform/linuxbsd/display_server_x11.cpp b/platform/linuxbsd/display_server_x11.cpp index b5052667a7..dd9298d667 100644 --- a/platform/linuxbsd/display_server_x11.cpp +++ b/platform/linuxbsd/display_server_x11.cpp @@ -2359,6 +2359,7 @@ void DisplayServerX11::process_events() { xi.pressure = 0; xi.tilt = Vector2(); + xi.pressure_supported = false; while (XPending(x11_display) > 0) { XEvent event; @@ -2421,9 +2422,11 @@ void DisplayServerX11::process_events() { Map<int, Vector2>::Element *pen_pressure = xi.pen_pressure_range.find(device_id); if (pen_pressure) { Vector2 pen_pressure_range = pen_pressure->value(); - if (pen_pressure_range != Vector2()) + if (pen_pressure_range != Vector2()) { + xi.pressure_supported = true; xi.pressure = (*values - pen_pressure_range[0]) / (pen_pressure_range[1] - pen_pressure_range[0]); + } } values++; @@ -2782,7 +2785,11 @@ void DisplayServerX11::process_events() { mm.instance(); mm->set_window_id(window_id); - mm->set_pressure(xi.pressure); + if (xi.pressure_supported) { + mm->set_pressure(xi.pressure); + } else { + mm->set_pressure((mouse_get_button_state() & (1 << (BUTTON_LEFT - 1))) ? 1.0f : 0.0f); + } mm->set_tilt(xi.tilt); // Make the absolute position integral so it doesn't look _too_ weird :) diff --git a/platform/linuxbsd/display_server_x11.h b/platform/linuxbsd/display_server_x11.h index 3dc06745a1..b5ea71f72a 100644 --- a/platform/linuxbsd/display_server_x11.h +++ b/platform/linuxbsd/display_server_x11.h @@ -176,6 +176,7 @@ class DisplayServerX11 : public DisplayServer { XIEventMask all_event_mask; Map<int, Vector2> state; double pressure; + bool pressure_supported; Vector2 tilt; Vector2 mouse_pos_to_filter; Vector2 relative_motion; diff --git a/platform/windows/display_server_windows.cpp b/platform/windows/display_server_windows.cpp index e4fe7f04d0..a31d8cccaa 100644 --- a/platform/windows/display_server_windows.cpp +++ b/platform/windows/display_server_windows.cpp @@ -1928,6 +1928,7 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA mm->set_control(control_mem); mm->set_shift(shift_mem); mm->set_alt(alt_mem); + mm->set_pressure((raw->data.mouse.ulButtons & RI_MOUSE_LEFT_BUTTON_DOWN) ? 1.0f : 0.0f); mm->set_button_mask(last_button_state); @@ -2038,8 +2039,14 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA mm.instance(); mm->set_window_id(window_id); - mm->set_pressure(pen_info.pressure ? (float)pen_info.pressure / 1024 : 0); - mm->set_tilt(Vector2(pen_info.tiltX ? (float)pen_info.tiltX / 90 : 0, pen_info.tiltY ? (float)pen_info.tiltY / 90 : 0)); + if (pen_info.penMask & PEN_MASK_PRESSURE) { + mm->set_pressure((float)pen_info.pressure / 1024); + } else { + mm->set_pressure((HIWORD(wParam) & POINTER_MESSAGE_FLAG_FIRSTBUTTON) ? 1.0f : 0.0f); + } + if ((pen_info.penMask & PEN_MASK_TILT_X) && (pen_info.penMask & PEN_MASK_TILT_Y)) { + mm->set_tilt(Vector2((float)pen_info.tiltX / 90, (float)pen_info.tiltY / 90)); + } mm->set_control((wParam & MK_CONTROL) != 0); mm->set_shift((wParam & MK_SHIFT) != 0); @@ -2138,6 +2145,8 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA mm->set_shift((wParam & MK_SHIFT) != 0); mm->set_alt(alt_mem); + mm->set_pressure((wParam & MK_LBUTTON) ? 1.0f : 0.0f); + mm->set_button_mask(last_button_state); mm->set_position(Vector2(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))); diff --git a/platform/windows/display_server_windows.h b/platform/windows/display_server_windows.h index 6243f54cfa..f6880d1021 100644 --- a/platform/windows/display_server_windows.h +++ b/platform/windows/display_server_windows.h @@ -75,6 +75,22 @@ typedef UINT32 POINTER_FLAGS; typedef UINT32 PEN_FLAGS; typedef UINT32 PEN_MASK; +#ifndef PEN_MASK_PRESSURE +#define PEN_MASK_PRESSURE 0x00000001 +#endif + +#ifndef PEN_MASK_TILT_X +#define PEN_MASK_TILT_X 0x00000004 +#endif + +#ifndef PEN_MASK_TILT_Y +#define PEN_MASK_TILT_Y 0x00000008 +#endif + +#ifndef POINTER_MESSAGE_FLAG_FIRSTBUTTON +#define POINTER_MESSAGE_FLAG_FIRSTBUTTON 0x00000010 +#endif + enum tagPOINTER_INPUT_TYPE { PT_POINTER = 0x00000001, PT_TOUCH = 0x00000002, |