Feature: Add native region, window and monitor capture to get_screenshot
New Windows clients advertise CLIENT_CAP_SCREEN_REGION and accept a 24-byte ScreenPreviewReqEx appended to the existing 8-byte preview request, so get_screenshot can capture a region, a window or a single monitor at 1:1 resolution instead of only the scaled virtual desktop. Successful v2 responses append an optional ScreenCaptureMeta block reporting the source rect and scale, letting callers map coordinates back for remote input. Old clients and old servers keep the v1 byte stream unchanged. The 8192 px per-side bound only applies to native (1:1) capture, where it guards bitmap memory; scaled captures are unaffected so ultra-wide virtual desktops (for example triple 4K) still produce thumbnails and previews. max_width is clamped to [64,1920] as before instead of rejected, matching the documented schema. Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
b2c0d81396
commit
235a8a622c
11 files changed
+668
-97
No files matched your search
+46
-1
@@ -142,6 +142,7 @@ inline int isValid_10s()
|
||||
#define CLIENT_CAP_EMBEDDED_ANCHOR 0x0040 // 当前靠「生成时内嵌的 TLS 信任锚」在加密(按运行时状态置位,不是能力声明)
|
||||
#define CLIENT_CAP_VIRTUAL_DESKTOP 0x0080 // 支持按 COMMAND_SCREEN_SPY 参数 buffer[11](wire 索引 12)强制抓取整个虚拟桌面(多显示器远程控制)
|
||||
#define CLIENT_CAP_WINDOW_INFO 0x0100 // 支持 COMMAND_MCP_WINDOW_INFO(带矩形/前后台/最小化状态的窗口列表)与窗口激活(CMD_WINDOW_ACTIVATE_FLAG)
|
||||
#define CLIENT_CAP_SCREEN_REGION 0x0200 // 支持 COMMAND_SCREEN_PREVIEW_REQ 扩展(区域/窗口/显示器原生分辨率截图)
|
||||
|
||||
#define TALK_DLG_MAXLEN 1024 // 最大输入字符长度
|
||||
|
||||
@@ -524,6 +525,7 @@ enum ScreenPreviewStatus {
|
||||
SCREEN_PREVIEW_CAPTURE_FAILED = 1, // 抓屏失败
|
||||
SCREEN_PREVIEW_ENCODE_FAILED = 2, // 编码失败
|
||||
SCREEN_PREVIEW_NOT_SUPPORTED = 3, // 平台不支持
|
||||
SCREEN_PREVIEW_BAD_TARGET = 4, // 目标无效:区域裁剪后为空/窗口不存在或已最小化/显示器序号越界
|
||||
};
|
||||
|
||||
enum ScreenPreviewFormat {
|
||||
@@ -544,10 +546,51 @@ struct ScreenPreviewRspHeader {
|
||||
uint16_t height; // 实际编码图高
|
||||
uint32_t bytes; // 图像字节数(紧随其后)
|
||||
uint8_t reserved[3];
|
||||
// 后接 data[bytes]
|
||||
// 后接 data[bytes],可选再跟一个 ScreenCaptureMeta
|
||||
}; // 头部 16 字节
|
||||
#pragma pack(pop)
|
||||
|
||||
// 截图目标模式(CLIENT_CAP_SCREEN_REGION)。v1 请求没有 mode 字段,等价于 VDESKTOP。
|
||||
enum ScreenCaptureMode {
|
||||
SCREEN_CAPTURE_VDESKTOP = 0, // 整个虚拟桌面(v1 行为,可缩放)
|
||||
SCREEN_CAPTURE_REGION = 1, // 虚拟桌面坐标系里的矩形
|
||||
SCREEN_CAPTURE_WINDOW = 2, // 按 hwnd 取窗口矩形(最小化窗口无法抓取)
|
||||
SCREEN_CAPTURE_MONITOR = 3, // 显示器序号(0 = 主显示器,其余按 EnumDisplayMonitors 顺序)
|
||||
};
|
||||
|
||||
// v2 请求扩展:紧跟在 ScreenPreviewReq(前 8 字节保持不变)之后。
|
||||
// 新服务端只对声明 CLIENT_CAP_SCREEN_REGION 的客户端发 v2;老客户端 memcpy 前 8 字节后
|
||||
// 忽略追加部分,老服务端永远只发 8 字节,新客户端按包长判断是 v1 还是 v2。
|
||||
#pragma pack(push, 1)
|
||||
struct ScreenPreviewReqEx {
|
||||
uint8_t mode; // ScreenCaptureMode
|
||||
uint8_t flags; // SCREEN_CAPTURE_F_*
|
||||
uint16_t monitor; // mode=MONITOR 时的显示器序号
|
||||
int32_t x, y; // mode=REGION 时的左上角(虚拟桌面坐标,可为负)
|
||||
int32_t w, h; // mode=REGION 时的宽高(>0)
|
||||
uint32_t hwnd; // mode=WINDOW 时的窗口句柄
|
||||
}; // 24 字节
|
||||
#pragma pack(pop)
|
||||
|
||||
#define SCREEN_CAPTURE_F_NATIVE 0x01 // 按源矩形 1:1 抓取,忽略 maxWidth(默认只在 v2 模式下生效)
|
||||
|
||||
// v2 响应可选尾块:紧跟在 JPEG 数据之后,声明实际抓取的源矩形,供调用方换算坐标。
|
||||
// 老服务端只按 header.bytes 取 JPEG,会忽略这段尾块,故可向后兼容。
|
||||
#define SCREEN_CAPTURE_META_MAGIC 0x324D4353u // 'SCM2'
|
||||
#pragma pack(push, 1)
|
||||
struct ScreenCaptureMeta {
|
||||
uint32_t magic; // SCREEN_CAPTURE_META_MAGIC
|
||||
int32_t x, y; // 实际抓取的源矩形左上角(虚拟桌面坐标)
|
||||
int32_t w, h; // 源矩形宽高(缩放前)
|
||||
uint8_t mode; // ScreenCaptureMode
|
||||
uint8_t scale; // 缩放百分比(100 = 原生)
|
||||
uint16_t reserved;
|
||||
}; // 24 字节
|
||||
#pragma pack(pop)
|
||||
|
||||
static_assert(sizeof(ScreenPreviewReqEx) == 24, "ScreenPreviewReqEx must be 24 bytes");
|
||||
static_assert(sizeof(ScreenCaptureMeta) == 24, "ScreenCaptureMeta must be 24 bytes");
|
||||
|
||||
static_assert(sizeof(ScreenPreviewReq) == 8, "ScreenPreviewReq must be 8 bytes");
|
||||
static_assert(sizeof(ScreenPreviewRspHeader) == 16, "ScreenPreviewRspHeader must be 16 bytes");
|
||||
|
||||
@@ -1231,6 +1274,8 @@ typedef struct LOGIN_INFOR {
|
||||
caps |= CLIENT_CAP_VIRTUAL_DESKTOP;
|
||||
// 窗口信息 RPC(矩形/z 序/前后台)与窗口激活。
|
||||
caps |= CLIENT_CAP_WINDOW_INFO;
|
||||
// 区域/窗口/显示器原生分辨率截图(COMMAND_SCREEN_PREVIEW_REQ 的 v2 扩展)。
|
||||
caps |= CLIENT_CAP_SCREEN_REGION;
|
||||
#elif defined(__linux__) && !defined(__ANDROID__)
|
||||
// Linux 客户端作为 C2C 目标端时会回执落盘结果(common/FileTransferV2.h)。
|
||||
// macOS 暂未接线(无全局主连接句柄),不声明——服务端就不会为它空等回执。
|
||||
|
||||
Reference in new issue
Block a user