|
1 | 1 | // Copyright (c) 2025 Kirill Gavrilov |
2 | 2 |
|
| 3 | +#ifdef _WIN32 |
| 4 | + // should be included before other headers to avoid missing definitions |
| 5 | + #include <windows.h> |
| 6 | +#endif |
| 7 | + |
3 | 8 | #include "OcctQtTools.h" |
4 | 9 |
|
5 | 10 | #include <Aspect_ScrollDelta.hxx> |
6 | 11 | #include <Message.hxx> |
| 12 | +#include <NCollection_LocalArray.hxx> |
7 | 13 | #include <OpenGl_Caps.hxx> |
8 | 14 | #include <OSD_Environment.hxx> |
9 | 15 | #include <Standard_Version.hxx> |
10 | 16 | #include <V3d_View.hxx> |
| 17 | +#include <WNT_HIDSpaceMouse.hxx> |
11 | 18 |
|
12 | 19 | #include <Standard_WarningsDisable.hxx> |
13 | 20 | #include <QCoreApplication> |
@@ -366,6 +373,76 @@ bool OcctQtTools::qtHandleTouchEvent(Aspect_WindowInputListener& theListener, |
366 | 373 | return hasUpdates; |
367 | 374 | } |
368 | 375 |
|
| 376 | +// ================================================================ |
| 377 | +// Function : qtRegisterRawInput |
| 378 | +// ================================================================ |
| 379 | +bool OcctQtTools::qtRegisterRawInput(Aspect_Drawable theWinId) |
| 380 | +{ |
| 381 | +#ifdef _WIN32 |
| 382 | + // handle raw WM_INPUT events to catch input from WNT_HIDSpaceMouse (HID_USAGE_GENERIC_MULTI_AXIS_CONTROLLER); |
| 383 | + // the same could be done also done for tracking precise mouse input (HID_USAGE_GENERIC_MOUSE RIM_TYPEMOUSE) |
| 384 | + RAWINPUTDEVICE aRawSpace = {}; |
| 385 | + aRawSpace.usUsagePage = 0x01; // HID_USAGE_PAGE_GENERIC from hidusage.h |
| 386 | + aRawSpace.usUsage = 0x08; // HID_USAGE_GENERIC_MULTI_AXIS_CONTROLLER |
| 387 | + aRawSpace.dwFlags = 0; // RIDEV_DEVNOTIFY |
| 388 | + aRawSpace.hwndTarget = (HWND )theWinId; |
| 389 | + if (!RegisterRawInputDevices(&aRawSpace, 1, sizeof(aRawSpace))) |
| 390 | + { |
| 391 | + Message::SendTrace() << "Warning: RegisterRawInputDevices() failed to register RAW multi-axis controller input"; |
| 392 | + return false; |
| 393 | + } |
| 394 | + return true; |
| 395 | +#else |
| 396 | + (void)theWinId; |
| 397 | + return false; |
| 398 | +#endif |
| 399 | +} |
| 400 | + |
| 401 | +// ================================================================ |
| 402 | +// Function : qtHandleNativeEvent |
| 403 | +// ================================================================ |
| 404 | +bool OcctQtTools::qtHandleNativeEvent(Aspect_WindowInputListener& theListener, |
| 405 | + const Handle(V3d_View)& theView, |
| 406 | + const QByteArray& theEventType, |
| 407 | + void* theMsg) |
| 408 | +{ |
| 409 | + (void)theEventType, (void)theMsg, (void)theView, (void)theListener; |
| 410 | +#ifdef _WIN32 |
| 411 | + if (theEventType == "windows_generic_MSG") |
| 412 | + { |
| 413 | + MSG* aMsg = reinterpret_cast<MSG*>(theMsg); |
| 414 | + if (aMsg->message != WM_INPUT) |
| 415 | + return false; |
| 416 | + |
| 417 | + UINT aSize = 0; |
| 418 | + ::GetRawInputData((HRAWINPUT )aMsg->lParam, RID_INPUT, nullptr, &aSize, sizeof(RAWINPUTHEADER)); |
| 419 | + NCollection_LocalArray<BYTE> aRawData(aSize); |
| 420 | + if (aSize == 0 || ::GetRawInputData((HRAWINPUT )aMsg->lParam, RID_INPUT, aRawData, &aSize, sizeof(RAWINPUTHEADER)) != aSize) |
| 421 | + return false; |
| 422 | + |
| 423 | + const RAWINPUT* aRawInput = (RAWINPUT* )(BYTE* )aRawData; |
| 424 | + if (aRawInput->header.dwType != RIM_TYPEHID) |
| 425 | + return false; |
| 426 | + |
| 427 | + RID_DEVICE_INFO aDevInfo; |
| 428 | + aDevInfo.cbSize = sizeof(RID_DEVICE_INFO); |
| 429 | + UINT aDevInfoSize = sizeof(RID_DEVICE_INFO); |
| 430 | + if (::GetRawInputDeviceInfoW (aRawInput->header.hDevice, RIDI_DEVICEINFO, &aDevInfo, &aDevInfoSize) != sizeof(RID_DEVICE_INFO) |
| 431 | + || (aDevInfo.hid.dwVendorId != WNT_HIDSpaceMouse::VENDOR_ID_LOGITECH |
| 432 | + && aDevInfo.hid.dwVendorId != WNT_HIDSpaceMouse::VENDOR_ID_3DCONNEXION)) |
| 433 | + return false; |
| 434 | + |
| 435 | + // see also 3d mouse input settings in AIS_ViewController to tune behavior |
| 436 | + WNT_HIDSpaceMouse aSpaceData(aDevInfo.hid.dwProductId, aRawInput->data.hid.bRawData, aRawInput->data.hid.dwSizeHid); |
| 437 | + if (theListener.Update3dMouse(aSpaceData)) |
| 438 | + return true; |
| 439 | + |
| 440 | + return false; |
| 441 | + } |
| 442 | +#endif |
| 443 | + return false; |
| 444 | +} |
| 445 | + |
369 | 446 | // ================================================================ |
370 | 447 | // Function : qtMouseButtons2VKeys |
371 | 448 | // ================================================================ |
|
0 commit comments