From eac94a86b8c6d4bca869ae0b8dcf20f97157ab4c Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Mon, 11 Nov 2024 18:59:45 -0500 Subject: [PATCH 1/3] Use correct macros to get the mouse position. MSDN says: Do not use the LOWORD or HIWORD macros to extract the x- and y- coordinates of the cursor position because these macros return incorrect results on systems with multiple monitors. Systems with multiple monitors can have negative x- and y- coordinates, and LOWORD and HIWORD treat the coordinates as unsigned quantities. --- .../Plasma/PubUtilLib/plInputCore/plInputManager.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Sources/Plasma/PubUtilLib/plInputCore/plInputManager.cpp b/Sources/Plasma/PubUtilLib/plInputCore/plInputManager.cpp index 4ebc51d90d..617d20d587 100644 --- a/Sources/Plasma/PubUtilLib/plInputCore/plInputManager.cpp +++ b/Sources/Plasma/PubUtilLib/plInputCore/plInputManager.cpp @@ -42,6 +42,9 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com // plInputManager.cpp #include "HeadSpin.h" #include "hsWindows.h" +#ifdef WIN32 +# include +#endif #include "plInputManager.h" #include "plPipeline.h" @@ -294,10 +297,10 @@ void plInputManager::HandleWin32ControlEvent(UINT message, WPARAM Wparam, LPARAM plIMouseYEventMsg* pYMsg = new plIMouseYEventMsg; plIMouseBEventMsg* pBMsg = new plIMouseBEventMsg; - pXMsg->fWx = LOWORD(Lparam); - pXMsg->fX = (float)LOWORD(Lparam) / (float)rect.right; - pYMsg->fWy = HIWORD(Lparam); - pYMsg->fY = (float)HIWORD(Lparam) / (float)rect.bottom; + pXMsg->fWx = GET_X_LPARAM(Lparam); + pXMsg->fX = (float)GET_X_LPARAM(Lparam) / (float)rect.right; + pYMsg->fWy = GET_Y_LPARAM(Lparam); + pYMsg->fY = (float)GET_Y_LPARAM(Lparam) / (float)rect.bottom; // Apply mouse scale // pXMsg->fX *= fMouseScale; From aad3fd382b036b119da3921a6e96d5e4bc3510a5 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Mon, 11 Nov 2024 19:00:32 -0500 Subject: [PATCH 2/3] Don't scale mouse positions coming in from the OS. The OS is already giving us the correct coordinates. No need to scale them. --- Sources/Plasma/PubUtilLib/plInputCore/plInputDevice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Plasma/PubUtilLib/plInputCore/plInputDevice.cpp b/Sources/Plasma/PubUtilLib/plInputCore/plInputDevice.cpp index 614c20fe40..ede9b29834 100644 --- a/Sources/Plasma/PubUtilLib/plInputCore/plInputDevice.cpp +++ b/Sources/Plasma/PubUtilLib/plInputCore/plInputDevice.cpp @@ -492,7 +492,7 @@ bool plMouseDevice::MsgReceive(plMessage* msg) fXPos = pXMsg->fX; SetCursorX(fXPos); - fWXPos = pXMsg->fWx * fScale; + fWXPos = pXMsg->fWx; return true; } @@ -529,7 +529,7 @@ bool plMouseDevice::MsgReceive(plMessage* msg) else fYPos = pYMsg->fY; - fWYPos = pYMsg->fWy * fScale; + fWYPos = pYMsg->fWy; SetCursorY(fYPos); return true; From cf3c86b32f7ceb6f4476f3b46f92438a03bfe070 Mon Sep 17 00:00:00 2001 From: Colin Cornaby Date: Wed, 13 Nov 2024 21:27:36 -0500 Subject: [PATCH 3/3] Send scaled mouse coordinates from Apple client. Co-authored-by: Adam Johnson --- .../Plasma/Apps/plClient/Mac-Cocoa/PLSView.mm | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Sources/Plasma/Apps/plClient/Mac-Cocoa/PLSView.mm b/Sources/Plasma/Apps/plClient/Mac-Cocoa/PLSView.mm index a2a89b74d7..80efbe9ed0 100644 --- a/Sources/Plasma/Apps/plClient/Mac-Cocoa/PLSView.mm +++ b/Sources/Plasma/Apps/plClient/Mac-Cocoa/PLSView.mm @@ -191,18 +191,19 @@ - (void)updateClientMouseLocation:(NSEvent*)event CGPoint viewLocation = [self convertPoint:windowLocation fromView:nil]; NSRect windowViewBounds = self.bounds; - CGFloat deltaX = (windowLocation.x) / windowViewBounds.size.width; - CGFloat deltaY = + CGFloat xNormal = (windowLocation.x) / windowViewBounds.size.width; + CGFloat yNormal = (windowViewBounds.size.height - windowLocation.y) / windowViewBounds.size.height; plIMouseXEventMsg* pXMsg = new plIMouseXEventMsg; plIMouseYEventMsg* pYMsg = new plIMouseYEventMsg; - pXMsg->fWx = viewLocation.x; - pXMsg->fX = deltaX; + pXMsg->fX = xNormal; + pYMsg->fY = yNormal; - pYMsg->fWy = (windowViewBounds.size.height - windowLocation.y); - pYMsg->fY = deltaY; + // Plasma internally uses input coords as display coords + pXMsg->fWx = viewLocation.x * self.window.screen.backingScaleFactor; + pYMsg->fWy = (windowViewBounds.size.height - windowLocation.y) * self.window.screen.backingScaleFactor; @synchronized(self.layer) { if (self.inputManager) { @@ -219,7 +220,7 @@ - (void)updateClientMouseLocation:(NSEvent*)event newWindowLocation.x = CGRectGetMidX(self.window.contentView.bounds); // macOS won't generate a new message on warp, need to tell Plasma by hand - pXMsg->fWx = newWindowLocation.x; + pXMsg->fWx = newWindowLocation.x * self.window.screen.backingScaleFactor;; pXMsg->fX = 0.5f; self.inputManager->MsgReceive(pXMsg); } @@ -228,7 +229,7 @@ - (void)updateClientMouseLocation:(NSEvent*)event newWindowLocation.y = CGRectGetMidY(self.window.contentView.bounds); // macOS won't generate a new message on warp, need to tell Plasma by hand - pYMsg->fWy = newWindowLocation.y; + pYMsg->fWy = newWindowLocation.y * self.window.screen.backingScaleFactor;; pYMsg->fY = 0.5f; self.inputManager->MsgReceive(pYMsg); }