@@ -2320,21 +2320,27 @@ bool MainWindow::nativeEvent(const QByteArray& eventType, void* message, qintptr
23202320 return true ;
23212321 }
23222322
2323+
23232324 if (msg->message == WM_INPUT)
23242325 {
2325- UINT dwSize = 40 ;
2326- static BYTE lpb[40 ];
2327- if (GetRawInputData ((HRAWINPUT)msg->lParam , RID_INPUT, lpb, &dwSize, sizeof (RAWINPUTHEADER)))
2326+ UINT dwSize = 0 ;
2327+ GetRawInputData ((HRAWINPUT)msg->lParam , RID_INPUT, nullptr , &dwSize, sizeof (RAWINPUTHEADER));
2328+
2329+ if (dwSize > 0 )
23282330 {
2329- const RAWINPUT* raw = (RAWINPUT*)lpb ;
2330- if (raw-> header . dwType == RIM_TYPEMOUSE )
2331+ std::vector<BYTE> lpb (dwSize) ;
2332+ if (GetRawInputData ((HRAWINPUT)msg-> lParam , RID_INPUT, lpb. data (), &dwSize, sizeof (RAWINPUTHEADER)) == dwSize )
23312333 {
2332- const RAWMOUSE& mouse = raw-> data . mouse ;
2333- if (mouse. usFlags == MOUSE_MOVE_ABSOLUTE || mouse. usFlags == MOUSE_MOVE_RELATIVE )
2334+ const RAWINPUT* raw = reinterpret_cast < const RAWINPUT*>(lpb. data ()) ;
2335+ if (raw-> header . dwType == RIM_TYPEMOUSE )
23342336 {
2335- POINT cursorPos;
2336- GetCursorPos (&cursorPos);
2337- checkMousePosition (cursorPos.x , cursorPos.y );
2337+ const RAWMOUSE& mouse = raw->data .mouse ;
2338+ if (mouse.usFlags == MOUSE_MOVE_ABSOLUTE || mouse.usFlags == MOUSE_MOVE_RELATIVE)
2339+ {
2340+ POINT cursorPos;
2341+ if (GetCursorPos (&cursorPos))
2342+ checkMousePosition (cursorPos.x , cursorPos.y );
2343+ }
23382344 }
23392345 }
23402346 }
@@ -2638,30 +2644,26 @@ void MainWindow::checkMousePosition(int x, int y)
26382644 if (!shouldMouseLock ())
26392645 return ;
26402646
2641- const QPoint globalCursorPos = {x, y};
2642- QRect windowBounds = isRenderingFullscreen () ? screen ()->geometry () : geometry ();
2643- if (windowBounds.contains (globalCursorPos))
2647+ // physical mouse position
2648+ const QPoint physicalPos (x, y);
2649+
2650+ // logical (DIP) frame rect
2651+ QRectF logicalBounds = isRenderingFullscreen () ? screen ()->geometry () : frameGeometry ();
2652+
2653+ // physical frame rect
2654+ const qreal scale = window ()->devicePixelRatioF ();
2655+ QRectF physicalBounds (
2656+ logicalBounds.x () * scale,
2657+ logicalBounds.y () * scale,
2658+ logicalBounds.width () * scale,
2659+ logicalBounds.height () * scale);
2660+
2661+ if (physicalBounds.contains (physicalPos))
26442662 return ;
26452663
26462664 Common::SetMousePosition (
2647- std::clamp (globalCursorPos.x (), windowBounds.left (), windowBounds.right ()),
2648- std::clamp (globalCursorPos.y (), windowBounds.top (), windowBounds.bottom ()));
2649-
2650- /*
2651- Provided below is how we would handle this if we were using low level hooks (What is used in Common::AttachMouseCb)
2652- We currently use rawmouse on Windows, so Common::SetMousePosition called directly works fine.
2653- */
2654- #if 0
2655- // We are currently in a low level hook. SetCursorPos here (what is in Common::SetMousePosition) will not work!
2656- // Let's (a)buse Qt's event loop to dispatch the call at a later time, outside of the hook.
2657- QMetaObject::invokeMethod(
2658- this, [=]() {
2659- Common::SetMousePosition(
2660- std::clamp(globalCursorPos.x(), windowBounds.left(), windowBounds.right()),
2661- std::clamp(globalCursorPos.y(), windowBounds.top(), windowBounds.bottom()));
2662- },
2663- Qt::QueuedConnection);
2664- #endif
2665+ std::clamp (physicalPos.x (), (int )physicalBounds.left (), (int )physicalBounds.right ()),
2666+ std::clamp (physicalPos.y (), (int )physicalBounds.top (), (int )physicalBounds.bottom ()));
26652667}
26662668
26672669void MainWindow::saveDisplayWindowGeometryToConfig ()
0 commit comments