Browse Source

Merge pull request #66528 from bruvzg/win_no_mm

[Windows] Ignore excessive wintab mouse move events.
Rémi Verschelde 2 years ago
parent
commit
7f113042c0
1 changed files with 14 additions and 11 deletions
  1. 14 11
      platform/windows/display_server_windows.cpp

+ 14 - 11
platform/windows/display_server_windows.cpp

@@ -2554,24 +2554,27 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
 			if ((tablet_get_current_driver() == "wintab") && wintab_available && windows[window_id].wtctx) {
 				PACKET packet;
 				if (wintab_WTPacket(windows[window_id].wtctx, wParam, &packet)) {
-					float pressure = float(packet.pkNormalPressure - windows[window_id].min_pressure) / float(windows[window_id].max_pressure - windows[window_id].min_pressure);
-					windows[window_id].last_pressure = pressure;
+					POINT coords;
+					GetCursorPos(&coords);
+					ScreenToClient(windows[window_id].hWnd, &coords);
+
 					windows[window_id].last_pressure_update = 0;
 
+					float pressure = float(packet.pkNormalPressure - windows[window_id].min_pressure) / float(windows[window_id].max_pressure - windows[window_id].min_pressure);
 					double azim = (packet.pkOrientation.orAzimuth / 10.0f) * (Math_PI / 180);
 					double alt = Math::tan((Math::abs(packet.pkOrientation.orAltitude / 10.0f)) * (Math_PI / 180));
+					bool inverted = packet.pkStatus & TPS_INVERT;
 
-					if (windows[window_id].tilt_supported) {
-						windows[window_id].last_tilt = Vector2(Math::atan(Math::sin(azim) / alt), Math::atan(Math::cos(azim) / alt));
-					} else {
-						windows[window_id].last_tilt = Vector2();
-					}
+					Vector2 tilt = (windows[window_id].tilt_supported) ? Vector2(Math::atan(Math::sin(azim) / alt), Math::atan(Math::cos(azim) / alt)) : Vector2();
 
-					windows[window_id].last_pen_inverted = packet.pkStatus & TPS_INVERT;
+					// Nothing changed, ignore event.
+					if (!old_invalid && coords.x == old_x && coords.y == old_y && windows[window_id].last_pressure == pressure && windows[window_id].last_tilt == tilt && windows[window_id].last_pen_inverted == inverted) {
+						break;
+					}
 
-					POINT coords;
-					GetCursorPos(&coords);
-					ScreenToClient(windows[window_id].hWnd, &coords);
+					windows[window_id].last_pressure = pressure;
+					windows[window_id].last_tilt = tilt;
+					windows[window_id].last_pen_inverted = inverted;
 
 					// Don't calculate relative mouse movement if we don't have focus in CAPTURED mode.
 					if (!windows[window_id].window_has_focus && mouse_mode == MOUSE_MODE_CAPTURED) {