Feature: Draw the remote cursor in the web desktop out of control mode

Screen frames are captured without the pointer composed in (GDI SRCCOPY,
DXGI), so browsers only ever knew the cursor's shape index and could show a
cursor just in control mode, where the local pointer stands in for the remote
one. Both servers now relay the cursor position that every per-frame header
already carries: shape changes go out immediately, position changes at most
every 50 ms, and an unchanged cursor is re-sent once a second so a viewer that
joins while the pointer is idle still learns where it is.

The page hides the local pointer and draws the remote cursor at its true
position while out of control mode; entering control mode restores exactly the
old behaviour (remote-shaped CSS cursor on desktop, touchpad pointer on touch).
A server that never sends x/y leaves the page on its previous fallback.

The C++ server broadcasts from the per-frame path, so header-only frames keep a
static desktop's cursor fresh; the Go hub dedups and throttles before fanning
out. Tests cover the throttle/refresh rules and the relayed payload.

Co-Authored-By: deepseek-flash
This commit is contained in:
yuanyuanxianganddeepseek-flash committed 2026-10-26 17:44:13 +01:00
1 parent 6236ed1eb4
commit bfb17d0d25
12 files changed
+322 -65

No files matched your search

+29 -8
View File
@@ -1415,6 +1415,31 @@ VOID CScreenSpyDlg::DrawFirstScreen(void)
PostMessage(WM_PAINT);//触发WM_PAINT消息
}
// 把远程光标的位置/类型同步给 Web 客户端。抓屏画面本身不含光标(GDI/DXGI 都不合成),
// 非控制态的浏览器靠这条消息在画面上自己画一个光标。
// 类型变化 → 立即发(force=true);
// 位置变化 → 50ms 节流;
// 完全静止 → 每秒重发一次,让刚打开页面的观察者也能立刻看到光标位置
// (否则要等远程鼠标下一次移动)。
void CScreenSpyDlg::BroadcastCursorToWeb(bool force)
{
if (!m_bIsWebSession || !WebService().IsRunning()) return;
ULONGLONG now = GetTickCount64();
ULONGLONG since = now - m_nLastCursorBroadcast;
bool reshaped = force || m_bCursorIndex != m_bBroadcastCursorIndex;
bool moved = m_ClientCursorPos.x != m_ptBroadcastCursor.x ||
m_ClientCursorPos.y != m_ptBroadcastCursor.y;
if (!reshaped) {
if (since < 50) return; // 位置变化节流
if (!moved && since < 1000) return; // 静止时每秒兜底一次
}
m_nLastCursorBroadcast = now;
m_bBroadcastCursorIndex = m_bCursorIndex;
m_ptBroadcastCursor = m_ClientCursorPos;
WebService().BroadcastCursor(m_ClientID, m_bCursorIndex,
(int)m_ClientCursorPos.x, (int)m_ClientCursorPos.y);
}
VOID CScreenSpyDlg::DrawNextScreenDiff(bool keyFrame)
{
//该函数不是直接画到屏幕上,而是更新一下变化部分的屏幕数据然后调用
@@ -1452,10 +1477,6 @@ VOID CScreenSpyDlg::DrawNextScreenDiff(bool keyFrame)
m_bCursorIndex = m_ContextObject->InDeCompressedBuffer.GetBuffer(2+sizeof(POINT))[0];
if (bOldCursorIndex != m_bCursorIndex) {
bChange = TRUE;
// 通知 Web 客户端光标变化 (只有 Web 会话的对话框才广播)
if (m_bIsWebSession && WebService().IsRunning()) {
WebService().BroadcastCursor(m_ClientID, m_bCursorIndex);
}
if (m_bIsCtrl && !m_bIsTraceCursor) {//替换指定窗口所属类的WNDCLASSEX结构
HCURSOR cursor;
if (m_bCursorIndex == 254) { // -2: 使用自定义光标
@@ -1473,6 +1494,8 @@ VOID CScreenSpyDlg::DrawNextScreenDiff(bool keyFrame)
#endif
}
}
// 通知 Web 客户端光标位置/类型(内部按类型变化/位置节流/每秒兜底决定是否真发)
BroadcastCursorToWeb(false);
// 屏幕是否变化
if (NextScreenLength > 0) {
@@ -1638,11 +1661,9 @@ VOID CScreenSpyDlg::DrawScrollFrame()
m_bCursorIndex = m_ContextObject->InDeCompressedBuffer.GetBuffer(2 + sizeof(POINT))[0];
if (bOldCursorIndex != m_bCursorIndex) {
bChange = TRUE;
// 通知 Web 客户端光标变化 (只有 Web 会话的对话框才广播)
if (m_bIsWebSession && WebService().IsRunning()) {
WebService().BroadcastCursor(m_ClientID, m_bCursorIndex);
}
}
// 通知 Web 客户端光标位置/类型(内部按类型变化/位置节流/每秒兜底决定是否真发)
BroadcastCursorToWeb(false);
// 读取滚动参数
LPBYTE buffer = m_ContextObject->InDeCompressedBuffer.GetBuffer(ulHeadLength);
+7
View File
@@ -218,6 +218,10 @@ public:
bool IsWebSession() const { return m_bIsWebSession.load(); }
void SetWebSession(bool isWeb) { m_bIsWebSession.store(isWeb); }
// 把远程光标的位置/类型同步给 Web 客户端(非控制态由浏览器自己画光标)。
// force=true 用于类型变化,跳过节流立即发送。
void BroadcastCursorToWeb(bool force);
VOID SendNext(void);
VOID OnReceiveComplete();
HDC m_hFullDC;
@@ -264,6 +268,9 @@ public:
std::atomic<bool> m_bIsWebSession{false}; // True if this dialog was created by Web request (atomic for thread safety)
std::string m_strSaveNotice; // 截图保存路径提示
ULONGLONG m_nSaveNoticeTime = 0; // 截图提示开始时间
ULONGLONG m_nLastCursorBroadcast = 0; // 上次向 Web 广播光标的时间(50ms 节流)
BYTE m_bBroadcastCursorIndex = 0; // 上次广播的光标类型
POINT m_ptBroadcastCursor = {0, 0}; // 上次广播的光标位置
BOOL m_bUsingFRP = FALSE;
// 文件接收进度对话框(用于 Linux Ctrl+C -> 服务端 Ctrl+V)
+4 -1
View File
@@ -2344,7 +2344,7 @@ void CWebService::NotifyAudioState(uint64_t device_id, bool enabled) {
}
}
void CWebService::BroadcastCursor(uint64_t device_id, uint8_t cursor_index) {
void CWebService::BroadcastCursor(uint64_t device_id, uint8_t cursor_index, int x, int y) {
if (m_bStopping) return;
// Build JSON message
@@ -2352,6 +2352,9 @@ void CWebService::BroadcastCursor(uint64_t device_id, uint8_t cursor_index) {
res["cmd"] = "cursor";
res["id"] = std::to_string(device_id);
res["index"] = cursor_index;
// 位置是发送位图(即浏览器 canvas)坐标系;老页面忽略这两个字段。
res["x"] = x;
res["y"] = y;
Json::StreamWriterBuilder builder;
builder["indentation"] = "";
+5 -2
View File
@@ -167,8 +167,11 @@ public:
// clients watching this device and caches it for newcomers.
void NotifyAudioState(uint64_t device_id, bool enabled);
// Cursor change notification (called from ScreenSpyDlg)
void BroadcastCursor(uint64_t device_id, uint8_t cursor_index);
// Cursor notification (called from ScreenSpyDlg): the shape index plus the
// position in the transmitted frame's coordinate space. The browser draws
// the remote cursor itself while it is not in control mode — the captured
// frames never contain one.
void BroadcastCursor(uint64_t device_id, uint8_t cursor_index, int x, int y);
// 远程剪贴板文本回传通知(called from ScreenSpyDlg,payload 为 UTF-8)
void NotifyClipboardText(uint64_t device_id, const std::string& text);