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

+66 -12
View File
@@ -2648,8 +2648,12 @@
isAndroidRemote = msg.client_type === 'APK';
updateAndroidNavbar();
// Refresh cursor overlay and immersive layout
document.getElementById('cursor-overlay').classList.toggle(
'active', controlEnabled && isTouchDevice && !isAndroidRemote);
if (controlEnabled) {
document.getElementById('cursor-overlay').classList.toggle(
'active', isTouchDevice && !isAndroidRemote);
} else {
renderRemoteCursor();
}
if (isTouchDevice) updateUIForOrientation();
}
initDecoder(msg.width, msg.height);
@@ -2662,8 +2666,18 @@
// Update remote cursor visual: native CSS cursor on desktop,
// overlay variant on touch. 254=custom (unsupported), 255=unsupported.
currentCursorIndex = msg.index;
remoteCursor.index = msg.index;
// 服务端每帧带上光标位置(帧坐标 == canvas 坐标)。老版本服务端
// 只发 index,此时 known 保持 false,退回原来的表现。
if (typeof msg.x === 'number' && typeof msg.y === 'number') {
remoteCursor.x = msg.x;
remoteCursor.y = msg.y;
remoteCursor.known = true;
}
if (controlEnabled) {
applyRemoteCursor(msg.index);
} else {
renderRemoteCursor();
}
break;
}
@@ -2778,6 +2792,8 @@
// Update input shortcuts position after canvas resize
requestAnimationFrame(updateInputShortcutsPosition);
// 分辨率变了:非控制态的远程光标按新画布重新定位
requestAnimationFrame(renderRemoteCursor);
// Windows/Linux/macOS clients send bottom-up H.264 (BMP convention) → flip.
// Android MediaCodec sends top-down H.264 → no flip needed.
@@ -5193,6 +5209,11 @@
];
let currentCursorIndex = 1; // Default: arrow
// 远程真实光标位置(服务端随每帧回报)。抓屏画面本身不含光标,所以非控制态
// 由浏览器自己画一个。known=false 表示服务端还没上报过位置(老版本服务端),
// 这时退回浏览器自己的指针,保持原有观感。
let remoteCursor = { x: 0, y: 0, index: 1, known: false };
// IDC_* index -> CSS class on .cursor-overlay (touch-mode visual cursor).
// Indices not listed (0,2,4,6,8,14, custom) fall back to default arrow.
const cursorOverlayClassMap = {
@@ -5226,6 +5247,28 @@
}
}
// 非控制态的光标渲染:把远程光标画在它真正所在的位置上,同时藏起浏览器
// 自己的箭头,否则屏幕上会同时出现两个指针。控制态不走这里——桌面端本地
// 指针本身就是远程光标,触摸端由 updateCursorOverlay 画触控光标。
function renderRemoteCursor() {
if (controlEnabled) return;
const canvas = document.getElementById('screen-canvas');
const overlay = document.getElementById('cursor-overlay');
if (!canvas || !overlay) return;
// 屏幕墙(以及没打开远程桌面时)不画:多路光标会落在同一个固定层上。
const screenPage = document.getElementById('screen-page');
const onScreen = !!screenPage && screenPage.classList.contains('active');
// Android 直连模式没有指针概念(手指即指针),不画。
const show = onScreen && remoteCursor.known && !isAndroidRemote;
canvas.style.cursor = show ? 'none' : 'default';
overlay.className = 'cursor-overlay' + (show ? ' active' : '');
const cls = cursorOverlayClassMap[remoteCursor.index];
if (show) {
if (cls) overlay.classList.add(cls);
positionCursorOverlay(remoteCursor.x, remoteCursor.y);
}
}
// Floating toolbar state
let toolbarVisible = false;
let toolbarHideTimer = null;
@@ -5481,17 +5524,18 @@
// Cursor handling
const canvas = document.getElementById('screen-canvas');
const cursorOverlay = document.getElementById('cursor-overlay');
// Touch: hide native cursor and show our overlay (touchpad mode).
// Desktop: native CSS cursor is set by applyRemoteCursor below.
if (controlEnabled && isTouchDevice) {
canvas.style.cursor = 'none';
} else if (!controlEnabled) {
canvas.style.cursor = 'default';
}
// Android direct mode: no cursor overlay (finger IS the pointer)
cursorOverlay.classList.toggle('active', controlEnabled && isTouchDevice && !isAndroidRemote);
if (controlEnabled) {
// Touch: hide native cursor and show our overlay (touchpad mode).
// Desktop: native CSS cursor is set by applyRemoteCursor below.
if (isTouchDevice) {
canvas.style.cursor = 'none';
}
// Android direct mode: no cursor overlay (finger IS the pointer)
cursorOverlay.classList.toggle('active', isTouchDevice && !isAndroidRemote);
applyRemoteCursor(currentCursorIndex);
} else {
// 非控制态:藏起本地指针,只留远程真实光标
renderRemoteCursor();
}
// Sync the keyboard lock: in fullscreen + control mode, ESC and F11
// must be passed through to the remote OS instead of triggering the
@@ -5505,9 +5549,16 @@
// Only used on touch devices (touchpad mode)
function updateCursorOverlay(canvasX, canvasY) {
if (!controlEnabled || !isTouchDevice) return;
positionCursorOverlay(canvasX, canvasY);
}
// Place the overlay at a canvas coordinate, applying the zoom/pan
// transform. Shared by the touch control cursor and the non-control
// remote cursor.
function positionCursorOverlay(canvasX, canvasY) {
const canvas = document.getElementById('screen-canvas');
const cursorOverlay = document.getElementById('cursor-overlay');
if (!canvas || !cursorOverlay) return;
// Get canvas base position (without transform, use container + offset)
// offsetLeft/offsetTop are layout positions, unaffected by CSS transform
const container = document.querySelector('.canvas-container');
@@ -5679,6 +5730,8 @@
canvas.style.transformOrigin = zoomState.originX + '% ' + zoomState.originY + '%';
canvas.style.transform = 'scale(' + zoomState.scale + ') translate(' + zoomState.translateX + 'px, ' + zoomState.translateY + 'px)';
}
// 非控制态:缩放/平移后远程光标要跟着画面走
if (!controlEnabled) renderRemoteCursor();
}
function getPinchDistance(touches) {
@@ -6634,6 +6687,7 @@
// Strip any cursor-* variant on the overlay, leaving the bare default arrow.
document.getElementById('cursor-overlay').className = 'cursor-overlay';
currentCursorIndex = 1; // Reset to default arrow
remoteCursor = { x: 0, y: 0, index: 1, known: false }; // 切设备后位置作废
// Reset zoom state
zoomState.scale = 1;