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
35 lines
1.5 KiB
C++
35 lines
1.5 KiB
C++
// ScreenPreview.h
|
||
// 屏幕截图:按目标(虚拟桌面 / 区域 / 窗口 / 显示器)抓取 → 等比缩放 → JPEG 编码,
|
||
// 供 COMMAND_SCREEN_PREVIEW_REQ 响应使用。
|
||
#pragma once
|
||
|
||
#include <vector>
|
||
|
||
// 抓取目标(ScreenCaptureMode 见 common/commands.h)
|
||
struct CaptureTarget {
|
||
int mode = 0; // 0=虚拟桌面 1=区域 2=窗口 3=显示器
|
||
bool native = false; // true = 按源尺寸 1:1 抓取,忽略 maxWidth
|
||
int maxWidth = 0; // native=false 时的目标宽度上限
|
||
int x = 0, y = 0; // mode=区域:左上角(虚拟桌面坐标,可为负)
|
||
int w = 0, h = 0; // mode=区域:宽高(>0)
|
||
unsigned long hwnd = 0; // mode=窗口
|
||
int monitor = 0; // mode=显示器:0 = 主显示器
|
||
};
|
||
|
||
// 实际抓取结果;源矩形为裁剪到虚拟桌面之后的坐标,scale 为缩放百分比(100 = 原生)
|
||
struct CaptureResult {
|
||
int x = 0, y = 0;
|
||
int w = 0, h = 0;
|
||
int scale = 100;
|
||
int outWidth = 0, outHeight = 0;
|
||
};
|
||
|
||
// 抓取并按需缩放、编码成 JPEG。返回 0 表示成功;非 0 见 ScreenPreviewStatus。
|
||
int CaptureAndEncodeScreenshot(const CaptureTarget& target, int quality,
|
||
std::vector<unsigned char>& out, CaptureResult& result);
|
||
|
||
// 整虚拟桌面 + 等比缩放到 maxWidth(v1 请求的旧入口)
|
||
int CaptureAndEncodePreview(int maxWidth, int quality,
|
||
std::vector<unsigned char>& out,
|
||
int& outWidth, int& outHeight);
|