From 0e8678b1822398d0561640ec4d4cacf4e68c34aa Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Tue, 9 Oct 2018 18:10:59 +1100 Subject: [PATCH] [host] correct mouse position with hotspot offset --- host/Capture/DXGI.cpp | 20 ++++++++++++++------ host/Capture/DXGI.h | 1 + 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/host/Capture/DXGI.cpp b/host/Capture/DXGI.cpp index 1129d023..c7b7b869 100644 --- a/host/Capture/DXGI.cpp +++ b/host/Capture/DXGI.cpp @@ -414,13 +414,19 @@ unsigned int Capture::DXGI::Capture() { // always report the mouse position to prevent the guest losing sync (ie: dragging windows) POINT curPos; - if (GetCursorPos(&curPos) && (curPos.x != m_lastCursorX || curPos.y != m_lastCursorY)) + if (GetCursorPos(&curPos)) { - ret |= GRAB_STATUS_CURSOR; - cursor.hasPos = true; - cursor.x = m_lastCursorX = curPos.x; - cursor.y = m_lastCursorY = curPos.y; - cursor.visible = m_lastMouseVis; + curPos.x -= m_hotSpot.x; + curPos.y -= m_hotSpot.y; + + if (curPos.x != m_lastCursorX || curPos.y != m_lastCursorY) + { + ret |= GRAB_STATUS_CURSOR; + cursor.hasPos = true; + cursor.x = m_lastCursorX = curPos.x; + cursor.y = m_lastCursorY = curPos.y; + cursor.visible = m_lastMouseVis; + } } } @@ -478,6 +484,8 @@ unsigned int Capture::DXGI::Capture() cursor.w = shapeInfo.Width; cursor.h = shapeInfo.Height; cursor.pitch = shapeInfo.Pitch; + m_hotSpot.x = shapeInfo.HotSpot.x; + m_hotSpot.y = shapeInfo.HotSpot.y; } if (ret & GRAB_STATUS_CURSOR) diff --git a/host/Capture/DXGI.h b/host/Capture/DXGI.h index 0fb769b1..4db6343a 100644 --- a/host/Capture/DXGI.h +++ b/host/Capture/DXGI.h @@ -104,5 +104,6 @@ namespace Capture int m_lastCursorX, m_lastCursorY; BOOL m_lastMouseVis; + POINT m_hotSpot; }; }; \ No newline at end of file