[feat] add vertical pointer edge panning on mobile

This commit is contained in:
dijunkun
2026-10-18 22:02:17 +08:00
parent b948422bfe
commit acd56dfc29
7 changed files with 138 additions and 21 deletions
+1 -1
View File
@@ -7,7 +7,7 @@
- 官方或自托管 WSS 信令服务器;授权后进入前台即自动注册或登录本机身份,首页实时显示连接、重连及失败状态。发起桌面连接时复用该身份;切换服务器会重新登录,撤回授权会关闭连接。已有远程会话优先通过系统画中画保持连接,画中画不可用时由带连接通知的前台服务兜底;首页空闲信令在后台关闭。
- 优先使用 MediaCodec 硬件解码 H.264 / AV1,硬件缓冲区直接提交 Surface;设备无对应硬件、分辨率超限或运行失败时,按原编码格式回退到 OpenH264 / dav1d。软件输出由独立显示线程将 NV12 转 RGBA;只保留最新待显示帧。MiniRTC 原有的通用压缩帧解码队列保持不变。
- 48 kHz 单声道 PCM 播放,支持静音,音频队列有容量限制。
- 相对鼠标(触控板)和绝对位置模式;单指点击、绝对模式按住拖动、长按右键,以及外接键盘、鼠标。画面手势与 iOS 一致:双指捏合以触点为中心缩放(1–10 倍),放大后双指拖动画面,原始比例下双指上下滑动控制滚轮。
- 相对鼠标(触控板)和绝对位置模式;单指点击、绝对模式按住拖动、长按右键,以及外接键盘、鼠标。画面手势与 iOS 一致:双指捏合以触点为中心缩放(1–10 倍),放大后双指拖动画面,原始比例下双指上下滑动控制滚轮。相对鼠标移到可见画面的上、下边缘后继续向外移动,会反向上下平移画面,不触发左右平移;未放大时和按住虚拟鼠标键拖动时同样生效,停止移动即停止平移,抬手保留位置。移动到极限时,画面可见部分至少占当前显示区域高度的 20%,与缩放倍数无关;整幅画面高度不足该比例时完整保留,范围计入上下黑边;缩放结束及缩回 1 倍时保留平移位置,仅在超过可见边界时限制位置;切换显示器恢复居中。
- 横竖屏等比例显示、远端多显示器切换。与 iOS 一致的画面质量(低/中/高)、采集帧率(30/60 fps)、画面偏好;支持能力检测、电脑端确认、失败/5 秒超时回退及连续操作的应答排序。
- 根据常见移动设备解码能力和屏幕尺寸设置起始参数:显示长边不超过 1280 像素时默认低画质(最高 720p)/30 fps,其余默认中画质(最高 1080p)/30 fps。用户保存的画面偏好不变,仍可手动选择高画质或 60 fps。
- 网络状态按视频、音频、数据、合计展示收发速率和丢包率,并显示实际提交帧率、分辨率、画面延时、平滑 RTT、P2P/TURN 和实际 SRTP 状态。每秒刷新,过期或无效测量显示“—”。
@@ -3,6 +3,8 @@ package cn.crossdesk.mobile;
/** Shared button ownership and cursor position for the video surface and mouse bar. */
final class RemoteMouseInput {
interface Sender { void send(float x, float y, int flag, int wheel); }
interface RelativeMotion { void move(float dx, float dy); }
RelativeMotion relativeMotion;
private final Sender sender;
private float x = .5f, y = .5f;
private boolean gestureLeft, virtualLeft, virtualRight;
@@ -19,7 +21,8 @@ final class RemoteMouseInput {
}
void drag(float dx, float dy) {
if (!hasVirtualButton() || viewportWidth <= 0 || viewportHeight <= 0) return;
move(x + dx / viewportWidth, y + dy / viewportHeight);
if (relativeMotion != null) relativeMotion.move(dx, dy);
else move(x + dx / viewportWidth, y + dy / viewportHeight);
}
void gestureLeft(boolean down) {
if (down && hasVirtualButton()) return;
@@ -51,6 +51,7 @@ final class RemoteVideoView extends FrameLayout implements SurfaceHolder.Callbac
RemoteVideoView(Context context, NativeSession session) {
super(context); this.session = session;
mouseInput = new RemoteMouseInput(this::sendMouse);
mouseInput.relativeMotion = this::moveRelative;
setBackgroundColor(Color.BLACK);
video = new SurfaceView(context); video.getHolder().addCallback(this);
addView(video, new LayoutParams(1, 1, android.view.Gravity.CENTER));
@@ -147,14 +148,21 @@ final class RemoteVideoView extends FrameLayout implements SurfaceHolder.Callbac
cursor.invalidate();
}
@Override protected void onSizeChanged(int w,int h,int oldw,int oldh) { post(this::fit); }
private void moveRelative(float dx, float dy) {
if (pictureInPicture || viewport.width() <= 0 || viewport.height() <= 0) return;
viewport.panForPointer(y, dy);
applyViewport();
mouseInput.move(x + dx / viewport.width(), y + dy / viewport.height());
}
private boolean point(MotionEvent e) {
boolean touchpad = relative && e.getToolType(0) != MotionEvent.TOOL_TYPE_MOUSE;
float px=e.getX(),py=e.getY();
if (!touchpad && !viewport.contains(px,py)) return false;
if(touchpad){
if(e.getActionMasked()==MotionEvent.ACTION_MOVE){
x=Math.max(0,Math.min(1,x+(px-lastX)/Math.max(1,viewport.width())));
y=Math.max(0,Math.min(1,y+(py-lastY)/Math.max(1,viewport.height())));
moveRelative(px-lastX,py-lastY);
lastX=px;lastY=py;
return true;
}
}else{
x=viewport.normalizedX(px);
@@ -3,11 +3,14 @@ package cn.crossdesk.mobile;
/** Geometry shared by the video Surface, cursor and remote pointer input. */
final class RemoteViewport {
private static final float MAXIMUM_SCALE = 10;
private int baseWidth, baseHeight, baseLeft, baseTop;
private static final float MINIMUM_VISIBLE_HEIGHT_FRACTION = .2f;
private int baseWidth, baseHeight, baseLeft, baseTop, containerHeight;
private boolean edgePanned;
private float scale = 1, offsetX, offsetY;
void fit(int width, int height, int videoWidth, int videoHeight) {
if (width <= 0 || height <= 0 || videoWidth <= 0 || videoHeight <= 0) return;
containerHeight = height;
double fitScale = Math.min((double) width / videoWidth, (double) height / videoHeight);
baseWidth = Math.max(1, (int) (videoWidth * fitScale));
baseHeight = Math.max(1, (int) (videoHeight * fitScale));
@@ -54,18 +57,46 @@ final class RemoteViewport {
constrainOffset();
}
void finishGesture() {
if (!isZoomed()) reset();
void panForPointer(float y, float dy) {
if (baseHeight == 0 || !Float.isFinite(dy)) return;
float overflowY = pointerOverflow(top() + y * height(), dy,
Math.max(0, top()), Math.min(containerHeight, top() + height()));
if (overflowY == 0) return;
edgePanned = true;
panBy(0, -overflowY);
}
void reset() { scale = 1; offsetX = offsetY = 0; }
// Only the outward portion of this movement pans; an offscreen cursor must
// not make a tiny movement jump the viewport by its entire hidden distance.
private static float pointerOverflow(float position, float delta, float low, float high) {
if (delta > 0) return Math.min(delta, Math.max(0, position + delta - high));
if (delta < 0) return Math.max(delta, Math.min(0, position + delta - low));
return 0;
}
void finishGesture() {
if (!isZoomed()) {
scale = 1;
constrainOffset();
}
}
void reset() { scale = 1; offsetX = offsetY = 0; edgePanned = false; }
private void constrainOffset() {
// Keep the original fitted area covered, as on iOS, even with letterboxing.
float maximumX = baseWidth * (scale - 1) / 2;
float maximumY = baseHeight * (scale - 1) / 2;
float minimumY = -baseHeight * (scale - 1) / 2;
float maximumY = -minimumY;
if (edgePanned) {
// Reserve 20% of the viewport height regardless of zoom. If the
// whole image is shorter than that, keep its full height visible.
float visibleHeight = Math.min(height(), containerHeight * MINIMUM_VISIBLE_HEIGHT_FRACTION);
float centerY = baseTop + baseHeight / 2f;
minimumY = visibleHeight - centerY - height() / 2;
maximumY = containerHeight - visibleHeight - centerY + height() / 2;
}
offsetX = clamp(offsetX, -maximumX, maximumX);
offsetY = clamp(offsetY, -maximumY, maximumY);
offsetY = clamp(offsetY, minimumY, maximumY);
}
private static float clamp(float value, float minimum, float maximum) {