The Linux client now answers COMMAND_SCREEN_PREVIEW_REQ, so a host with an X11 desktop gets a thumbnail when it is double-clicked in the online list, a frame in the list's Preview column, and an image from the MCP get_screenshot tool. Previously only Windows clients advertised the capability and Linux hosts showed "预览不可用" after a four second wait. The client does not encode JPEG. Stock desktops ship libjpeg.so.8 whose struct layout is the distribution's ABI (JPEG_LIB_VERSION 80), while the in-tree jpeglib.h is libjpeg-turbo 3.1.1 (62), and libturbojpeg is not installed by default; dlopening the system library against that header fails with "Wrong JPEG library version: library is 80, caller expects 62". Instead the client sends raw pixels in a new screen preview format, SCREEN_PREVIEW_FMT_BGRX: top-down rows of B,G,R,X with no row padding, already scaled to the requested width. The server re-encodes to JPEG at the single ingress point, so the preview popup, the list thumbnail cache and the MCP tool keep consuming JPEG only. Capture follows the path ScreenHandler already uses: root window copied into an offscreen pixmap with an IncludeInferiors GC, then XGetImage, which avoids BadMatch under compositing window managers. The X11 type declarations and the dlopen loader moved out of ScreenHandler.h into linux/X11Loader.h so both users share one dlsym table. The full-size image is never materialized: a box filter reads straight from the XImage rows (honouring bytes_per_line) into the output buffer, scales to maxWidth without upscaling, and clamps the height to 1080 so a portrait 4K desktop cannot produce a 26 MB packet. Rows and columns come out even, which they are for JPEG anyway. The capability bit is now honest about the runtime. LOGIN_INFOR grows DefaultCaps()/SetCaps(), and the client recomputes the bits before every login and re-login: CLIENT_CAP_SCREEN_PREVIEW is set only when DISPLAY is present and the X server actually opens. A headless host therefore gets -32005 "Host does not support screen preview" from MCP instead of a timeout, and a host whose session appears after boot picks it up on the next reconnect. Requests are handled on a detached worker thread behind a single-flight guard (matching the Windows client), so a slow XGetImage never stalls the receive thread and a burst of requests degrades to "no preview" rather than queueing. If the worker thread cannot be created, the guard is released again, so one failure cannot leave every later request rejected as busy until the client restarts. The MCP design note claimed the capability was declared by Windows only, and the get_screenshot tool description said the same; both now say what the code does (Windows always, Linux when a display is reachable). Server side, NormalizeScreenPreviewPacket runs in MessageHandle before the MCP handoff and the PostMessage to the UI thread. It validates that width/height are within the values the server itself can ask for and that bytes equals width*height*4, converts with a stack Gdiplus::Bitmap over the packet's own pixels (no copy, and no DEBUG_NEW trouble), and rewrites the header to JPEG. The encoder output is read back by seeking the stream rather than GlobalSize, so the packet carries no heap-block padding after the EOI marker. Malformed packets are dropped; failure statuses pass through untouched so the existing code can report them. Tested against a Debug server with the WSL Ubuntu 24.04 build as the client. get_screenshot returned valid JPEGs at max_width 480 (480x142, 1.7 KB) and 1920 (1920x570, 17.9 KB), repeatably; the list showed a thumbnail for the GUI client and N/A for a second copy started without DISPLAY, which also answered -32005. The box filter and the BGRX to JPEG conversion were checked separately with quadrant fixtures: the browser over the synthetic B,G,R,X buffer recovers red/green/blue/white in the right channels and the downscale averages, handles non-integer ratios and row padding, and rejects 24bpp and upscaling. The captured frames come out black under WSLg because Xwayland keeps no root pixmap there; that is the compositor, not this code, and Xorg sessions capture normally. Co-Authored-By: deepseek-flash
60 lines
2.0 KiB
CMake
60 lines
2.0 KiB
CMake
# 编译方法:cmake . && make
|
||
# 设置 CMake 最低版本要求
|
||
set(CMAKE_VERBOSE_MAKEFILE ON)
|
||
set(CMAKE_CXX_STANDARD 11)
|
||
set(CMAKE_CXX_STANDARD_REQUIRED 11)
|
||
|
||
cmake_minimum_required(VERSION 3.22)
|
||
|
||
# 定义项目名称和版本
|
||
project(SimpleRemoter VERSION 1.0)
|
||
|
||
# 对于C++项目,确保标准库也静态链接
|
||
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++ -static-libgcc")
|
||
endif()
|
||
|
||
# X11 通过 dlopen 运行时加载,编译时无需 X11 开发库
|
||
|
||
include_directories(${CMAKE_SOURCE_DIR}/mterm)
|
||
|
||
# 额外的包含目录
|
||
include_directories(../)
|
||
include_directories(../client)
|
||
include_directories(../compress)
|
||
|
||
# 添加可执行文件
|
||
set(SOURCES
|
||
main.cpp
|
||
ScreenPreview.cpp # 屏幕预览(缩略图)抓屏,见 ScreenPreview.h
|
||
../client/Buffer.cpp
|
||
../client/IOCPClient.cpp
|
||
../client/TlsChannelLinux.cpp # Linux 客户端单向 TLS(OpenSSL),见 client/TlsChannel.h
|
||
../client/sign_shim_unix.cpp
|
||
)
|
||
add_executable(ghost ${SOURCES})
|
||
|
||
|
||
# 设置为可以调试
|
||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
|
||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")
|
||
|
||
# 链接 ZSTD 库
|
||
message(STATUS "链接库文件: ${CMAKE_SOURCE_DIR}/lib/libzstd.a")
|
||
target_link_libraries(ghost PRIVATE "${CMAKE_SOURCE_DIR}/lib/libzstd.a")
|
||
|
||
# 链接私有签名库(提供 signMessage / verifyMessage,源码不开源)
|
||
# 该库由 SimplePlugins 仓库本地构建后放置于 lib/,构建机需先准备好
|
||
target_link_libraries(ghost PRIVATE "${CMAKE_SOURCE_DIR}/lib/libsign.a")
|
||
|
||
# libsign.a 内部使用 OpenSSL HMAC,需要在最终可执行链接 libcrypto;
|
||
# 客户端传输层 TLS(client/TlsChannelLinux.cpp)另需 libssl。
|
||
find_package(OpenSSL REQUIRED)
|
||
target_link_libraries(ghost PRIVATE OpenSSL::Crypto OpenSSL::SSL)
|
||
|
||
# 链接 dl 库(dlopen/dlsym 用于运行时加载 X11)
|
||
target_link_libraries(ghost PRIVATE dl)
|
||
|
||
# 链接 pthread 库(std::thread 需要)
|
||
target_link_libraries(ghost PRIVATE pthread)
|