Files
SimpleRemoter/client/ScreenManager.h
T
yuanyuanxianganddeepseek-flash a190c21217 Feature: make remote desktop tuning per client
The tuning switches lived in the master's Advanced menu and were saved
globally, so two hosts could not use different settings. The client already
sends ScreenSettings when a remote desktop starts, so the state belongs
there: the four items now sit in the remote desktop window's system menu,
directly below Screen quality, and are saved per client.

ScreenSettings had a 40-byte Reserved area at offset 56; four bytes became
TuningFlags, keeping the struct at 100 bytes with Capabilities at 96. A new
Capabilities bit marks a value written by a versioned master; old clients,
and new clients never configured, report 0 and are not trusted.

CMD_SCREEN_TUNING now ends with a version byte. A five-byte command comes
from an older master that does not know the server-only adaptive bit: the
client applies those three bits to the session but does not save them. A
fresh client starts at 0, so an old master still gets pre-feature
behaviour; the new master's 0xE default is persisted on its first session.
The per-client master copy stays as the old-client fallback, and the old
global [settings] Tuning* keys are honoured when neither exists, so an
explicit opt-out survives the migration.

Verified on the Debug server with the in-process test client: a fresh
client stored 0xE on first use; toggling VBV wrote 0xF to both sides; after
deleting the master copy and reopening, the menu restored VBV from the
client report.

Co-Authored-By: deepseek-flash
2026-11-07 14:11:47 +01:00

148 lines
6.0 KiB
C++

// ScreenManager.h: interface for the CScreenManager class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_SCREENMANAGER_H__511DF666_6E18_4408_8BD5_8AB8CD1AEF8F__INCLUDED_)
#define AFX_SCREENMANAGER_H__511DF666_6E18_4408_8BD5_8AB8CD1AEF8F__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "Manager.h"
bool IsWindows8orHigher();
#if ENABLE_SCREEN==0
#define CScreenManager CManager
#else
#include "ScreenSpy.h"
#include "ScreenCapture.h"
// WASAPI 前向声明 (COM 接口)
struct IMMDevice;
struct IAudioClient;
struct IAudioCaptureClient;
// WAVEFORMATEX 使用 void* 避免包含头文件
bool LaunchApplication(TCHAR* pszApplicationFilePath, TCHAR* pszDesktopName);
BOOL IsRunningAsSystem();
class IOCPClient;
struct UserParam;
class CScreenManager : public CManager
{
public:
CScreenManager(IOCPClient* ClientObject, int n, void* user = nullptr, BOOL priv=FALSE);
virtual ~CScreenManager();
HANDLE m_hWorkThread;
ScreenSettings m_ScreenSettings = { 20 };
QualityProfile m_QualityProfiles[QUALITY_COUNT]; // 本地质量配置(可被服务端覆盖)
// 远程桌面调优开关位(CMD_SCREEN_TUNING 下发)。客户端把它存进本机配置,
// 并写进 ScreenSettings.TuningFlags 随位图信息上报,主控端下次打开远程桌面
// 时据此恢复勾选状态。没有本机记录时按 0 运行(加开关前的行为),等新主控端
// 下发后再保存;不能默认 TUNING_DEFAULT,否则被老主控端打开也会悄悄开启调优。
int m_nTuningFlags = 0;
virtual void InitScreenSpy();
void LoadQualityProfiles(); // 从配置文件加载质量配置
void SaveQualityProfiles(); // 保存质量配置到配置文件
static DWORD WINAPI WorkThreadProc(LPVOID lParam);
VOID SendBitMapInfo();
VOID OnReceive(PBYTE szBuffer, ULONG ulLength);
ScreenCapture* m_ScreenSpyObject;
VOID SendFirstScreen();
const char* GetNextScreen(ULONG &ulNextSendLength);
VOID SendNextScreen(const char* szBuffer, ULONG ulNextSendLength);
VOID ProcessCommand(LPBYTE szBuffer, ULONG ulLength);
UserParam *m_pUserParam = NULL;
INT_PTR m_ptrUser;
HDESK g_hDesk;
BOOL m_isGDI;
std::string m_DesktopID;
BOOL m_bIsWorking;
BOOL m_bIsBlockInput;
RECT m_ROI = {0};
HWND m_hTargetWnd = NULL; // 窗口捕获目标(NULL=全屏)
bool m_bDynamicForeground = false; // true=每帧自动跟踪前景窗口(HWND sentinel=-1触发)
BOOL m_SwitchScreen = TRUE;
BOOL SendClientClipboard(BOOL fast);
VOID UpdateClientClipboard(char *szBuffer, ULONG ulLength);
std::string m_hash;
std::string m_hmac;
CONNECT_ADDRESS *m_conn = nullptr;
uint64_t m_MyClientID = 0; // V2: 本机客户端ID
void SetConnection(CONNECT_ADDRESS* conn)
{
m_conn = conn;
if (conn) m_MyClientID = conn->clientID;
}
bool IsRunAsService() const
{
if (m_conn && (m_conn->iStartup == Startup_GhostMsc || m_conn->iStartup == Startup_TestRunMsc))
return true;
static BOOL is_run_as_system = IsRunningAsSystem();
return is_run_as_system;
}
// 获取当前活动桌面(带写权限,用于锁屏等安全桌面)
// 使用独立的静态变量避免与WorkThreadProc的g_hDesk并发冲突
HDESK s_inputDesk = NULL;
clock_t s_lastCheck = 0;
DWORD s_lastThreadId = 0;
bool SwitchScreen();
bool RestartScreen(BOOL switchScreen = FALSE);
void SwitchToNextWindow(); // 切换到下一个窗口(类似 Alt+Tab)
virtual BOOL OnReconnect();
uint64_t m_nReconnectTime = 0; // 重连开始时间
uint64_t m_DlgID = 0;
BOOL m_SendFirst = FALSE;
std::string m_Signature;
// 虚拟桌面
BOOL m_virtual;
POINT m_point;
POINT m_lastPoint;
BOOL m_lmouseDown;
HWND m_hResMoveWindow;
LRESULT m_resMoveType;
BOOL m_rmouseDown; // 标记右键是否按下
POINT m_rclickPoint; // 右键点击坐标
HWND m_rclickWnd; // 右键窗口
int m_nSwitchWindowIndex = 0; // 切换窗口索引
// ========== 系统音频捕获 (WASAPI Loopback) ==========
volatile BOOL m_bAudioThreadRunning = FALSE;// 音频线程运行标志(独立于视频线程)
volatile BOOL m_bAudioInitialized = FALSE; // WASAPI 是否已初始化
// 主控请求重发音频格式包:带格式的首包可能比 TOKEN_BITMAPINFO 先到,被主控当未知
// 命令丢掉;主控发现没收过格式时会发 enable 控制命令来要一次。幂等:格式没变主控不重建。
volatile BOOL m_bAudioFormatResend = FALSE;
// 请求音频线程重建 WASAPI 捕获客户端。系统休眠/恢复后旧的捕获客户端会作废,
// 但 GetNextPacketSize 不报错、永远返回 0,从此再也收不到包(主控那边看起来
// 一切正常)。COM 对象只允许音频线程自己释放,所以这里只登记标志。
volatile BOOL m_bAudioDeviceDirty = FALSE;
HANDLE m_hAudioThread = NULL; // 音频线程句柄
HANDLE m_hAudioEvent = NULL; // 控制线程挂起/唤醒
// WASAPI 相关
IMMDevice* m_pAudioDevice = nullptr;
IAudioClient* m_pAudioClient = nullptr;
IAudioCaptureClient* m_pCaptureClient = nullptr;
void* m_pWaveFormat = nullptr; // 实际类型: WAVEFORMATEX*
BOOL InitWASAPILoopback(); // 初始化 WASAPI Loopback
void UninitWASAPI(); // 释放 WASAPI 资源
static DWORD WINAPI AudioThreadProc(LPVOID lpParam); // 音频捕获线程
void HandleAudioCtrl(BYTE enable, BYTE persist); // 处理音频控制命令
};
#endif
#endif // !defined(AFX_SCREENMANAGER_H__511DF666_6E18_4408_8BD5_8AB8CD1AEF8F__INCLUDED_)