Fix(cursor): correct trace cursor position on multi-monitor capture

This commit is contained in:
yuanyuanxiang
2026-05-22 23:24:26 +02:00
parent 62e962f216
commit 99fc15ae41
2 changed files with 26 additions and 6 deletions

View File

@@ -639,11 +639,10 @@ public:
// 写入算法类型
data[0] = algo;
// 写入光标位置
// 写入光标位置(虚拟桌面绝对坐标 → 发送坐标系)
POINT CursorPos;
GetCursorPos(&CursorPos);
CursorPos.x /= m_wZoom;
CursorPos.y /= m_hZoom;
PointConversionInverse(CursorPos);
memcpy(data + 1, &CursorPos, sizeof(POINT));
// 写入当前光标类型(支持自定义光标)
@@ -851,11 +850,10 @@ public:
// 写入使用了哪种算法
memcpy(data, (LPBYTE)&algo, sizeof(BYTE));
// 写入光标位置
// 写入光标位置(虚拟桌面绝对坐标 → 发送坐标系)
POINT CursorPos;
GetCursorPos(&CursorPos);
CursorPos.x /= m_wZoom;
CursorPos.y /= m_hZoom;
PointConversionInverse(CursorPos);
memcpy(data + sizeof(BYTE), (LPBYTE)&CursorPos, sizeof(POINT));
// 写入当前光标类型(支持自定义光标)
@@ -1025,6 +1023,26 @@ public:
pt.y += m_iScreenY;
}
// 鼠标位置反向转换将客户端绝对坐标GetCursorPos转换为发送坐标系逐项是 PointConversion 的逆
virtual void PointConversionInverse(POINT& pt) const
{
// 3'. 减去屏幕偏移(多显示器)
pt.x -= m_iScreenX;
pt.y -= m_iScreenY;
// 2'. 反向 DPI 缩放
if (m_bZoomed) {
pt.x = (LONG)(pt.x / m_wZoom);
pt.y = (LONG)(pt.y / m_hZoom);
}
// 1'. full → send 缩放(位图下采样传输时)
int sendWidth = m_BitmapInfor_Send->bmiHeader.biWidth;
int sendHeight = m_BitmapInfor_Send->bmiHeader.biHeight;
if (sendWidth != (int)m_ulFullWidth || sendHeight != (int)m_ulFullHeight) {
pt.x = (LONG)((double)pt.x * sendWidth / m_ulFullWidth + 0.5);
pt.y = (LONG)((double)pt.y * sendHeight / m_ulFullHeight + 0.5);
}
}
// 获取位图结构信息
virtual const LPBITMAPINFO& GetBIData() const
{