Compare commits

...

5 Commits

21 changed files with 907 additions and 28 deletions
+5
View File
@@ -242,6 +242,11 @@ jobs:
cd "${{ github.workspace }}\scripts\windows"
makensis /DVERSION=$env:VERSION_NUM nsis_script.nsi
- name: Build Portable CrossDesk
run: |
xmake f --CROSSDESK_VERSION=${{ env.VERSION_NUM }} --USE_CUDA=true --CROSSDESK_PORTABLE=true -y
xmake b -vy crossdesk
- name: Package Portable
shell: pwsh
run: |
+3 -14
View File
@@ -1,17 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<!-- 应用程序标识 -->
<assemblyIdentity
version="1.0.0.0"
processorArchitecture="*"
name="CrossDesk"
type="win32" />
<!-- 描述信息 -->
<description>CrossDesk Application</description>
<!-- 权限:要求管理员运行 -->
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
@@ -20,24 +16,17 @@
</security>
</trustInfo>
<!-- DPI 感知设置:支持高分屏 -->
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<!-- Windows Vista/7 风格 DPI 感知 -->
<dpiAware>true/pm</dpiAware>
<!-- Windows 10/11 高级 DPI 感知 -->
<dpiAwareness>PerMonitorV2</dpiAwareness>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/pm</dpiAware>
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
</windowsSettings>
</application>
<!-- Windows 兼容性声明 -->
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- 支持 Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
<!-- 支持 Windows 11(向下兼容 Win10 GUID -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
</application>
</compatibility>
</assembly>
</assembly>
+9
View File
@@ -1,2 +1,11 @@
// Application icon resource; load by the resource name IDI_ICON1.
IDI_ICON1 ICON "..\\..\\icons\\windows\\crossdesk.ico"
#define CREATEPROCESS_MANIFEST_RESOURCE_ID 1
#define RT_MANIFEST 24
#ifdef CROSSDESK_DEBUG
CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "crossdesk_debug.manifest"
#else
CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "crossdesk.manifest"
#endif
+32
View File
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
version="1.0.0.0"
name="CrossDesk"
type="win32" />
<description>CrossDesk Application</description>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="asInvoker" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/pm</dpiAware>
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
</windowsSettings>
</application>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
</application>
</compatibility>
</assembly>
@@ -269,10 +269,30 @@ inline bool IsFunctionKey(int key_code) {
}
}
CGEventFlags ToCGEventFlags(uint32_t injected_flags) {
CGEventFlags flags = 0;
if ((injected_flags & kMacInjectedModifierShift) != 0) {
flags |= kCGEventFlagMaskShift;
}
if ((injected_flags & kMacInjectedModifierControl) != 0) {
flags |= kCGEventFlagMaskControl;
}
if ((injected_flags & kMacInjectedModifierOption) != 0) {
flags |= kCGEventFlagMaskAlternate;
}
if ((injected_flags & kMacInjectedModifierCommand) != 0) {
flags |= kCGEventFlagMaskCommand;
}
return flags;
}
int KeyboardCapturer::SendKeyboardCommand(int key_code, bool is_down,
uint32_t scan_code, bool extended) {
(void)scan_code;
(void)extended;
const uint32_t injected_flags =
injected_modifier_state_.Update(key_code, is_down);
if (vkCodeToCGKeyCode.find(key_code) != vkCodeToCGKeyCode.end()) {
CGKeyCode cg_key_code = vkCodeToCGKeyCode[key_code];
CGEventRef event = CGEventCreateKeyboardEvent(NULL, cg_key_code, is_down);
@@ -281,7 +301,7 @@ int KeyboardCapturer::SendKeyboardCommand(int key_code, bool is_down,
return -1;
}
CGEventSetFlags(event, 0);
CGEventSetFlags(event, ToCGEventFlags(injected_flags));
CGEventPost(kCGHIDEventTap, event);
CFRelease(event);
@@ -10,6 +10,7 @@
#include <ApplicationServices/ApplicationServices.h>
#include "device_controller.h"
#include "macos_keyboard_modifier_state.h"
namespace crossdesk {
@@ -36,6 +37,7 @@ class KeyboardCapturer : public DeviceController {
bool option_flag_ = false;
bool command_flag_ = false;
int fn_key_code_ = 0x3F;
MacKeyboardModifierState injected_modifier_state_;
};
} // namespace crossdesk
#endif
@@ -0,0 +1,93 @@
/*
* @Author: DI JUNKUN
* @Date: 2026-05-21
* Copyright (c) 2026 by DI JUNKUN, All Rights Reserved.
*/
#ifndef _MACOS_KEYBOARD_MODIFIER_STATE_H_
#define _MACOS_KEYBOARD_MODIFIER_STATE_H_
#include <cstdint>
namespace crossdesk {
inline constexpr uint32_t kMacInjectedModifierShift = 1u << 0;
inline constexpr uint32_t kMacInjectedModifierControl = 1u << 1;
inline constexpr uint32_t kMacInjectedModifierOption = 1u << 2;
inline constexpr uint32_t kMacInjectedModifierCommand = 1u << 3;
class MacKeyboardModifierState {
public:
uint32_t Update(int key_code, bool is_down) {
bool* state = MutableStateForVk(key_code);
if (state != nullptr) {
*state = is_down;
}
return flags();
}
uint32_t flags() const {
uint32_t result = 0;
if (left_shift_down_ || right_shift_down_) {
result |= kMacInjectedModifierShift;
}
if (left_control_down_ || right_control_down_) {
result |= kMacInjectedModifierControl;
}
if (left_option_down_ || right_option_down_) {
result |= kMacInjectedModifierOption;
}
if (left_command_down_ || right_command_down_) {
result |= kMacInjectedModifierCommand;
}
return result;
}
void Clear() {
left_shift_down_ = false;
right_shift_down_ = false;
left_control_down_ = false;
right_control_down_ = false;
left_option_down_ = false;
right_option_down_ = false;
left_command_down_ = false;
right_command_down_ = false;
}
private:
bool* MutableStateForVk(int key_code) {
switch (key_code) {
case 0xA0: // VK_LSHIFT
return &left_shift_down_;
case 0xA1: // VK_RSHIFT
return &right_shift_down_;
case 0xA2: // VK_LCONTROL
return &left_control_down_;
case 0xA3: // VK_RCONTROL
return &right_control_down_;
case 0xA4: // VK_LMENU / left Option
return &left_option_down_;
case 0xA5: // VK_RMENU / right Option
return &right_option_down_;
case 0x5B: // VK_LWIN / left Command
return &left_command_down_;
case 0x5C: // VK_RWIN / right Command
return &right_command_down_;
default:
return nullptr;
}
}
bool left_shift_down_ = false;
bool right_shift_down_ = false;
bool left_control_down_ = false;
bool right_control_down_ = false;
bool left_option_down_ = false;
bool right_option_down_ = false;
bool left_command_down_ = false;
bool right_command_down_ = false;
};
} // namespace crossdesk
#endif
@@ -1,5 +1,7 @@
#include "mouse_controller.h"
#include <Windows.h>
#include "rd_log.h"
namespace crossdesk {
@@ -18,7 +20,14 @@ int MouseController::Destroy() { return 0; }
int MouseController::SendMouseCommand(RemoteAction remote_action,
int display_index) {
INPUT ip;
if (display_index < 0 ||
display_index >= static_cast<int>(display_info_list_.size())) {
LOG_WARN("Mouse command skipped, invalid display_index={}, displays={}",
display_index, display_info_list_.size());
return -1;
}
INPUT ip = {0};
if (remote_action.type == ControlType::mouse) {
ip.type = INPUT_MOUSE;
@@ -63,13 +72,25 @@ int MouseController::SendMouseCommand(RemoteAction remote_action,
ip.mi.time = 0;
SetCursorPos(ip.mi.dx, ip.mi.dy);
if (!SetCursorPos(ip.mi.dx, ip.mi.dy)) {
LOG_WARN("SetCursorPos failed for mouse x={}, y={}, flag={}, err={}",
ip.mi.dx, ip.mi.dy, static_cast<int>(remote_action.m.flag),
GetLastError());
return -1;
}
if (ip.mi.dwFlags != MOUSEEVENTF_MOVE) {
SendInput(1, &ip, sizeof(INPUT));
UINT sent = SendInput(1, &ip, sizeof(INPUT));
if (sent != 1) {
LOG_WARN(
"SendInput failed for mouse x={}, y={}, wheel={}, flag={}, err={}",
ip.mi.dx, ip.mi.dy, remote_action.m.s,
static_cast<int>(remote_action.m.flag), GetLastError());
return -1;
}
}
}
return 0;
}
} // namespace crossdesk
} // namespace crossdesk
+4 -2
View File
@@ -163,6 +163,7 @@ int Render::ControlBar(std::shared_ptr<SubStreamWindowProperties>& props) {
ImVec2 btn_min = ImGui::GetItemRectMin();
ImVec2 btn_size_actual = ImGui::GetItemRectSize();
props->display_selectable_hovered_ = false;
if (ImGui::BeginPopup("display")) {
ImGui::SetWindowFontScale(0.5f);
for (int i = 0; i < props->display_info_list_.size(); i++) {
@@ -178,8 +179,9 @@ int Render::ControlBar(std::shared_ptr<SubStreamWindowProperties>& props) {
props->control_data_label_.c_str());
}
}
props->display_selectable_hovered_ = ImGui::IsWindowHovered();
}
props->display_selectable_hovered_ =
ImGui::IsWindowHovered(ImGuiHoveredFlags_RootAndChildWindows);
ImGui::EndPopup();
}
@@ -486,4 +488,4 @@ int Render::NetTrafficStats(std::shared_ptr<SubStreamWindowProperties>& props) {
return 0;
}
} // namespace crossdesk
} // namespace crossdesk
+96 -1
View File
@@ -1,12 +1,98 @@
#include "path_manager.h"
#include <cstdint>
#include <cstdlib>
#include <vector>
#ifndef CROSSDESK_PORTABLE
#define CROSSDESK_PORTABLE 0
#endif
#if CROSSDESK_PORTABLE
#if defined(__APPLE__)
#include <mach-o/dyld.h>
#elif !defined(_WIN32)
#include <limits.h>
#include <unistd.h>
#endif
#endif
namespace {
#if CROSSDESK_PORTABLE
std::filesystem::path GetExecutableDirectory() {
#ifdef _WIN32
std::vector<wchar_t> buffer(MAX_PATH);
while (true) {
DWORD length =
GetModuleFileNameW(nullptr, buffer.data(),
static_cast<DWORD>(buffer.size()));
if (length == 0) {
return {};
}
if (length < buffer.size()) {
return std::filesystem::path(buffer.data(), buffer.data() + length)
.parent_path();
}
if (buffer.size() >= 32768) {
return {};
}
buffer.resize(buffer.size() * 2);
}
#elif defined(__APPLE__)
uint32_t size = 0;
_NSGetExecutablePath(nullptr, &size);
std::vector<char> buffer(size + 1);
if (_NSGetExecutablePath(buffer.data(), &size) != 0) {
return {};
}
std::error_code ec;
std::filesystem::path executable =
std::filesystem::weakly_canonical(buffer.data(), ec);
if (ec) {
executable = buffer.data();
}
return executable.parent_path();
#else
std::vector<char> buffer(PATH_MAX);
while (true) {
ssize_t length = readlink("/proc/self/exe", buffer.data(),
buffer.size() - 1);
if (length <= 0) {
return {};
}
if (static_cast<size_t>(length) < buffer.size() - 1) {
buffer[static_cast<size_t>(length)] = '\0';
return std::filesystem::path(buffer.data()).parent_path();
}
buffer.resize(buffer.size() * 2);
}
#endif
}
std::filesystem::path GetPortableRootPath() {
std::filesystem::path executable_dir = GetExecutableDirectory();
if (!executable_dir.empty()) {
return executable_dir;
}
std::error_code ec;
std::filesystem::path current = std::filesystem::current_path(ec);
return ec ? std::filesystem::path(".") : current;
}
#endif
} // namespace
namespace crossdesk {
PathManager::PathManager(const std::string& app_name) : app_name_(app_name) {}
std::filesystem::path PathManager::GetConfigPath() {
#if CROSSDESK_PORTABLE
return GetPortableRootPath() / "data";
#else
#ifdef _WIN32
return GetKnownFolder(FOLDERID_RoamingAppData) / app_name_;
#elif __APPLE__
@@ -14,9 +100,13 @@ std::filesystem::path PathManager::GetConfigPath() {
#else
return GetEnvOrDefault("XDG_CONFIG_HOME", GetHome() + "/.config") / app_name_;
#endif
#endif
}
std::filesystem::path PathManager::GetCachePath() {
#if CROSSDESK_PORTABLE
return GetPortableRootPath() / "data";
#else
#ifdef _WIN32
#ifdef CROSSDESK_DEBUG
return "cache";
@@ -28,9 +118,13 @@ std::filesystem::path PathManager::GetCachePath() {
#else
return GetEnvOrDefault("XDG_CACHE_HOME", GetHome() + "/.cache") / app_name_;
#endif
#endif
}
std::filesystem::path PathManager::GetLogPath() {
#if CROSSDESK_PORTABLE
return GetPortableRootPath() / "logs";
#else
#ifdef _WIN32
return GetKnownFolder(FOLDERID_LocalAppData) / app_name_ / "logs";
#elif __APPLE__
@@ -38,6 +132,7 @@ std::filesystem::path PathManager::GetLogPath() {
#else
return GetCachePath() / "logs";
#endif
#endif
}
bool PathManager::CreateDirectories(const std::filesystem::path& p) {
@@ -93,4 +188,4 @@ std::filesystem::path PathManager::GetEnvOrDefault(const char* env_var,
return std::filesystem::path(def);
}
} // namespace crossdesk
} // namespace crossdesk
+113 -2
View File
@@ -46,6 +46,13 @@ struct InputDesktopInfo {
std::string name;
};
struct SecureDesktopMouseRequest {
int x = 0;
int y = 0;
int wheel = 0;
int flag = 0;
};
struct ScopedEnvironmentBlock {
~ScopedEnvironmentBlock() {
if (environment != nullptr) {
@@ -339,6 +346,14 @@ std::string BuildSecureInputHelperKeyboardCommand(int key_code, bool is_down,
return stream.str();
}
std::string BuildSecureInputHelperMouseCommand(int x, int y, int wheel,
int flag) {
std::ostringstream stream;
stream << kCrossDeskSecureInputMouseCommandPrefix << x << ":" << y << ":"
<< wheel << ":" << flag;
return stream.str();
}
bool ParseSecureDesktopKeyboardIpcCommand(const std::string& command,
int* key_code_out, bool* is_down_out,
uint32_t* scan_code_out,
@@ -412,6 +427,57 @@ bool ParseSecureDesktopKeyboardIpcCommand(const std::string& command,
return false;
}
bool ParseSecureDesktopMouseIpcCommand(const std::string& command,
SecureDesktopMouseRequest* request_out) {
if (request_out == nullptr) {
return false;
}
if (command.rfind(kSecureDesktopMouseIpcCommandPrefix, 0) != 0) {
return false;
}
const size_t x_begin = sizeof(kSecureDesktopMouseIpcCommandPrefix) - 1;
size_t separator = command.find(':', x_begin);
if (separator == std::string::npos) {
return false;
}
try {
request_out->x = std::stoi(command.substr(x_begin, separator - x_begin));
} catch (...) {
return false;
}
const size_t y_begin = separator + 1;
separator = command.find(':', y_begin);
if (separator == std::string::npos) {
return false;
}
try {
request_out->y = std::stoi(command.substr(y_begin, separator - y_begin));
} catch (...) {
return false;
}
const size_t wheel_begin = separator + 1;
separator = command.find(':', wheel_begin);
if (separator == std::string::npos) {
return false;
}
try {
request_out->wheel =
std::stoi(command.substr(wheel_begin, separator - wheel_begin));
request_out->flag = std::stoi(command.substr(separator + 1));
} catch (...) {
return false;
}
return true;
}
bool CreateSessionSystemToken(DWORD session_id, HANDLE* token_out,
DWORD* error_code_out = nullptr) {
if (token_out == nullptr) {
@@ -1759,7 +1825,13 @@ std::string CrossDeskServiceHost::HandleIpcCommand(const std::string& command) {
if (ParseSecureDesktopKeyboardIpcCommand(normalized, &key_code, &is_down,
&scan_code, &extended)) {
return SendSecureDesktopKeyboardInput(key_code, is_down, scan_code,
extended);
extended);
}
SecureDesktopMouseRequest mouse_request;
if (ParseSecureDesktopMouseIpcCommand(normalized, &mouse_request)) {
return SendSecureDesktopMouseInput(mouse_request.x, mouse_request.y,
mouse_request.wheel,
mouse_request.flag);
}
return BuildErrorJson("unknown_command");
}
@@ -2014,6 +2086,45 @@ std::string CrossDeskServiceHost::SendSecureDesktopKeyboardInput(
1000);
}
std::string CrossDeskServiceHost::SendSecureDesktopMouseInput(int x, int y,
int wheel,
int flag) {
RefreshSessionState();
ReapSecureInputHelper();
EnsureSessionHelper();
DWORD target_session_id = 0xFFFFFFFF;
bool helper_running = false;
bool can_inject = false;
{
std::lock_guard<std::mutex> lock(state_mutex_);
target_session_id = active_session_id_;
helper_running = secure_input_helper_running_ &&
secure_input_helper_session_id_ == target_session_id;
can_inject = GetEffectiveSessionLockedLocked() || HasSecureInputUiLocked();
}
if (target_session_id == 0xFFFFFFFF) {
return BuildErrorJson("no_active_console_session");
}
if (!can_inject) {
return BuildErrorJson("secure_input_not_active");
}
if (!helper_running) {
StopSecureInputHelper();
if (!LaunchSecureInputHelper(target_session_id)) {
std::lock_guard<std::mutex> lock(state_mutex_);
return BuildErrorJson(secure_input_helper_last_error_.c_str(),
secure_input_helper_last_error_code_);
}
}
return QueryNamedPipeMessage(
GetCrossDeskSecureInputHelperPipeName(target_session_id),
BuildSecureInputHelperMouseCommand(x, y, wheel, flag), 1000);
}
bool InstallCrossDeskService(const std::wstring& binary_path) {
SC_HANDLE manager = OpenSCManagerW(nullptr, nullptr, SC_MANAGER_ALL_ACCESS);
if (manager == nullptr) {
@@ -2238,4 +2349,4 @@ std::string SendCrossDeskSecureDesktopMouseInput(int x, int y, int wheel,
BuildSecureDesktopMouseIpcCommand(x, y, wheel, flag), timeout_ms);
}
} // namespace crossdesk
} // namespace crossdesk
+2 -1
View File
@@ -64,6 +64,7 @@ class CrossDeskServiceHost {
std::string SendSecureDesktopKeyboardInput(int key_code, bool is_down,
uint32_t scan_code = 0,
bool extended = false);
std::string SendSecureDesktopMouseInput(int x, int y, int wheel, int flag);
static void WINAPI ServiceMain(DWORD argc, LPWSTR* argv);
static BOOL WINAPI ConsoleControlHandler(DWORD control_type);
@@ -150,4 +151,4 @@ std::string SendCrossDeskSecureDesktopMouseInput(int x, int y, int wheel,
} // namespace crossdesk
#endif
#endif
+78
View File
@@ -0,0 +1,78 @@
#include <filesystem>
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
namespace {
std::filesystem::path FindRepoRoot() {
std::filesystem::path current = std::filesystem::current_path();
while (!current.empty()) {
if (std::filesystem::exists(current / "xmake.lua") &&
std::filesystem::exists(current / "src/gui/toolbars/control_bar.cpp")) {
return current;
}
current = current.parent_path();
}
return {};
}
std::string ReadFile(const std::filesystem::path& path) {
std::ifstream file(path, std::ios::binary);
if (!file) {
return {};
}
std::ostringstream stream;
stream << file.rdbuf();
return stream.str();
}
bool ExpectContains(const char* name, const std::string& value,
const std::string& expected) {
if (value.find(expected) != std::string::npos) {
return true;
}
std::cerr << name << " missing expected text: " << expected << "\n";
return false;
}
bool ExpectResetBeforeDisplayPopup(const std::string& value) {
const std::string reset = "props->display_selectable_hovered_ = false;";
const std::string popup = "ImGui::BeginPopup(\"display\")";
const size_t reset_pos = value.find(reset);
const size_t popup_pos = value.find(popup);
if (reset_pos != std::string::npos && popup_pos != std::string::npos &&
reset_pos < popup_pos) {
return true;
}
std::cerr << "control_bar.cpp must clear display_selectable_hovered_ before "
"checking the display popup\n";
return false;
}
} // namespace
int main() {
const std::filesystem::path repo_root = FindRepoRoot();
if (repo_root.empty()) {
std::cerr << "failed to locate repository root\n";
return 1;
}
const std::string control_bar =
ReadFile(repo_root / "src/gui/toolbars/control_bar.cpp");
bool ok = true;
ok &= ExpectContains("control_bar.cpp", control_bar,
"props->display_selectable_hovered_ = false;");
ok &= ExpectContains("control_bar.cpp", control_bar,
"ImGui::IsWindowHovered("
"ImGuiHoveredFlags_RootAndChildWindows)");
ok &= ExpectResetBeforeDisplayPopup(control_bar);
return ok ? 0 : 1;
}
@@ -0,0 +1,60 @@
#include "macos_keyboard_modifier_state.h"
#include <cstdint>
#include <iostream>
namespace {
bool ExpectEqual(const char* name, uint32_t actual, uint32_t expected) {
if (actual == expected) {
return true;
}
std::cerr << name << " mismatch\n"
<< " expected: " << expected << "\n"
<< " actual: " << actual << "\n";
return false;
}
} // namespace
int main() {
crossdesk::MacKeyboardModifierState state;
bool ok = true;
ok &= ExpectEqual("initial flags", state.flags(), 0);
ok &= ExpectEqual("left shift down", state.Update(0xA0, true),
crossdesk::kMacInjectedModifierShift);
ok &= ExpectEqual("shifted semicolon keeps shift",
state.Update(0xBA, true),
crossdesk::kMacInjectedModifierShift);
ok &= ExpectEqual("semicolon up keeps shift", state.Update(0xBA, false),
crossdesk::kMacInjectedModifierShift);
ok &= ExpectEqual("right shift down while left held",
state.Update(0xA1, true),
crossdesk::kMacInjectedModifierShift);
ok &= ExpectEqual("left shift up while right held", state.Update(0xA0, false),
crossdesk::kMacInjectedModifierShift);
ok &= ExpectEqual("right shift up clears shift", state.Update(0xA1, false),
0);
ok &= ExpectEqual("left control down", state.Update(0xA2, true),
crossdesk::kMacInjectedModifierControl);
ok &= ExpectEqual("right alt adds option", state.Update(0xA5, true),
crossdesk::kMacInjectedModifierControl |
crossdesk::kMacInjectedModifierOption);
ok &= ExpectEqual("left command adds command", state.Update(0x5B, true),
crossdesk::kMacInjectedModifierControl |
crossdesk::kMacInjectedModifierOption |
crossdesk::kMacInjectedModifierCommand);
ok &= ExpectEqual("left control up leaves option command",
state.Update(0xA2, false),
crossdesk::kMacInjectedModifierOption |
crossdesk::kMacInjectedModifierCommand);
ok &= ExpectEqual("right alt up leaves command", state.Update(0xA5, false),
crossdesk::kMacInjectedModifierCommand);
ok &= ExpectEqual("left command up clears all", state.Update(0x5B, false),
0);
return ok ? 0 : 1;
}
+78
View File
@@ -0,0 +1,78 @@
#include "path_manager.h"
#include <cstdint>
#include <filesystem>
#include <iostream>
#include <string>
#ifdef _WIN32
#include <windows.h>
#elif defined(__APPLE__)
#include <mach-o/dyld.h>
#include <limits.h>
#else
#include <limits.h>
#include <unistd.h>
#endif
namespace {
std::filesystem::path GetExecutableDirectory() {
#ifdef _WIN32
wchar_t buffer[MAX_PATH] = {};
DWORD length = GetModuleFileNameW(nullptr, buffer, MAX_PATH);
if (length == 0 || length == MAX_PATH) {
return {};
}
return std::filesystem::path(buffer).parent_path();
#elif defined(__APPLE__)
char buffer[PATH_MAX] = {};
uint32_t size = sizeof(buffer);
if (_NSGetExecutablePath(buffer, &size) != 0) {
return {};
}
return std::filesystem::weakly_canonical(buffer).parent_path();
#else
char buffer[PATH_MAX] = {};
ssize_t length = readlink("/proc/self/exe", buffer, sizeof(buffer) - 1);
if (length <= 0) {
return {};
}
buffer[length] = '\0';
return std::filesystem::path(buffer).parent_path();
#endif
}
bool ExpectEqual(const char* name,
const std::filesystem::path& actual,
const std::filesystem::path& expected) {
if (actual.lexically_normal() == expected.lexically_normal()) {
return true;
}
std::cerr << name << " mismatch\n"
<< " expected: " << expected.string() << "\n"
<< " actual: " << actual.string() << "\n";
return false;
}
} // namespace
int main() {
const std::filesystem::path exe_dir = GetExecutableDirectory();
if (exe_dir.empty()) {
std::cerr << "failed to resolve executable directory\n";
return 1;
}
crossdesk::PathManager path_manager("CrossDesk");
const std::filesystem::path expected_data = exe_dir / "data";
const std::filesystem::path expected_logs = exe_dir / "logs";
bool ok = true;
ok &= ExpectEqual("config path", path_manager.GetConfigPath(), expected_data);
ok &= ExpectEqual("cache path", path_manager.GetCachePath(), expected_data);
ok &= ExpectEqual("log path", path_manager.GetLogPath(), expected_logs);
return ok ? 0 : 1;
}
+117
View File
@@ -0,0 +1,117 @@
#include <filesystem>
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#ifdef _WIN32
#include <windows.h>
#endif
namespace {
std::string ReadFile(const std::filesystem::path& path) {
std::ifstream file(path, std::ios::binary);
if (!file) {
return {};
}
std::ostringstream stream;
stream << file.rdbuf();
return stream.str();
}
std::filesystem::path FindRepoRoot() {
std::filesystem::path current = std::filesystem::current_path();
while (!current.empty()) {
if (std::filesystem::exists(current / "xmake.lua") &&
std::filesystem::exists(current / "scripts/windows/crossdesk.rc")) {
return current;
}
current = current.parent_path();
}
return {};
}
bool ExpectContains(const char* name, const std::string& value,
const std::string& expected) {
if (value.find(expected) != std::string::npos) {
return true;
}
std::cerr << name << " missing expected text: " << expected << "\n";
return false;
}
bool ExpectNotContains(const char* name, const std::string& value,
const std::string& unexpected) {
if (value.find(unexpected) == std::string::npos) {
return true;
}
std::cerr << name << " contains unexpected text: " << unexpected << "\n";
return false;
}
#ifdef _WIN32
bool ExpectActivationContext(const std::filesystem::path& manifest_path) {
ACTCTXW context = {};
context.cbSize = sizeof(context);
std::wstring source = manifest_path.wstring();
context.lpSource = source.c_str();
HANDLE activation_context = CreateActCtxW(&context);
if (activation_context == INVALID_HANDLE_VALUE) {
std::cerr << "CreateActCtxW failed for " << manifest_path.string()
<< ", error=" << GetLastError() << "\n";
return false;
}
ReleaseActCtx(activation_context);
return true;
}
#endif
} // namespace
int main() {
const std::filesystem::path repo_root = FindRepoRoot();
if (repo_root.empty()) {
std::cerr << "failed to locate repository root\n";
return 1;
}
const std::string rc = ReadFile(repo_root / "scripts/windows/crossdesk.rc");
const std::string manifest =
ReadFile(repo_root / "scripts/windows/crossdesk.manifest");
const std::string debug_manifest =
ReadFile(repo_root / "scripts/windows/crossdesk_debug.manifest");
bool ok = true;
ok &= ExpectContains("crossdesk.rc", rc, "crossdesk.manifest");
ok &= ExpectContains("crossdesk.rc", rc, "crossdesk_debug.manifest");
ok &= ExpectContains("crossdesk.rc", rc, "CROSSDESK_DEBUG");
ok &= ExpectContains("crossdesk.rc", rc, "RT_MANIFEST");
ok &= ExpectContains("crossdesk.manifest", manifest,
"level=\"requireAdministrator\"");
ok &= ExpectContains("crossdesk.manifest", manifest,
"http://schemas.microsoft.com/SMI/2005/WindowsSettings");
ok &= ExpectContains("crossdesk.manifest", manifest,
"http://schemas.microsoft.com/SMI/2016/WindowsSettings");
ok &= ExpectNotContains("crossdesk.manifest", manifest,
"processorArchitecture=\"*\"");
ok &= ExpectContains("crossdesk_debug.manifest", debug_manifest,
"level=\"asInvoker\"");
ok &= ExpectContains("crossdesk_debug.manifest", debug_manifest,
"http://schemas.microsoft.com/SMI/2005/WindowsSettings");
ok &= ExpectContains("crossdesk_debug.manifest", debug_manifest,
"http://schemas.microsoft.com/SMI/2016/WindowsSettings");
ok &= ExpectNotContains("crossdesk_debug.manifest", debug_manifest,
"processorArchitecture=\"*\"");
#ifdef _WIN32
ok &= ExpectActivationContext(repo_root / "scripts/windows/crossdesk.manifest");
ok &= ExpectActivationContext(
repo_root / "scripts/windows/crossdesk_debug.manifest");
#endif
return ok ? 0 : 1;
}
@@ -0,0 +1,63 @@
#include <filesystem>
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
namespace {
std::filesystem::path FindRepoRoot() {
std::filesystem::path current = std::filesystem::current_path();
while (!current.empty()) {
if (std::filesystem::exists(current / "xmake.lua") &&
std::filesystem::exists(
current / "src/device_controller/mouse/windows/mouse_controller.cpp")) {
return current;
}
current = current.parent_path();
}
return {};
}
std::string ReadFile(const std::filesystem::path& path) {
std::ifstream file(path, std::ios::binary);
if (!file) {
return {};
}
std::ostringstream stream;
stream << file.rdbuf();
return stream.str();
}
bool ExpectContains(const char* name, const std::string& value,
const std::string& expected) {
if (value.find(expected) != std::string::npos) {
return true;
}
std::cerr << name << " missing expected text: " << expected << "\n";
return false;
}
} // namespace
int main() {
const std::filesystem::path repo_root = FindRepoRoot();
if (repo_root.empty()) {
std::cerr << "failed to locate repository root\n";
return 1;
}
const std::string mouse_controller = ReadFile(
repo_root / "src/device_controller/mouse/windows/mouse_controller.cpp");
bool ok = true;
ok &= ExpectContains("mouse_controller.cpp", mouse_controller,
"INPUT ip = {0};");
ok &= ExpectContains("mouse_controller.cpp", mouse_controller,
"SetCursorPos failed");
ok &= ExpectContains("mouse_controller.cpp", mouse_controller,
"SendInput failed for mouse");
return ok ? 0 : 1;
}
+62
View File
@@ -0,0 +1,62 @@
#include <filesystem>
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
namespace {
std::filesystem::path FindRepoRoot() {
std::filesystem::path current = std::filesystem::current_path();
while (!current.empty()) {
if (std::filesystem::exists(current / "xmake.lua") &&
std::filesystem::exists(current / "src/service/windows/service_host.cpp")) {
return current;
}
current = current.parent_path();
}
return {};
}
std::string ReadFile(const std::filesystem::path& path) {
std::ifstream file(path, std::ios::binary);
if (!file) {
return {};
}
std::ostringstream stream;
stream << file.rdbuf();
return stream.str();
}
bool ExpectContains(const char* name, const std::string& value,
const std::string& expected) {
if (value.find(expected) != std::string::npos) {
return true;
}
std::cerr << name << " missing expected text: " << expected << "\n";
return false;
}
} // namespace
int main() {
const std::filesystem::path repo_root = FindRepoRoot();
if (repo_root.empty()) {
std::cerr << "failed to locate repository root\n";
return 1;
}
const std::string service_host =
ReadFile(repo_root / "src/service/windows/service_host.cpp");
bool ok = true;
ok &= ExpectContains("service_host.cpp", service_host,
"ParseSecureDesktopMouseIpcCommand");
ok &= ExpectContains("service_host.cpp", service_host,
"BuildSecureInputHelperMouseCommand");
ok &= ExpectContains("service_host.cpp", service_host,
"return SendSecureDesktopMouseInput");
return ok ? 0 : 1;
}
+8 -1
View File
@@ -23,6 +23,12 @@ function setup_options_and_dependencies()
set_description("Enable DRM capture on Linux (assumes dependencies are installed)")
option_end()
option("CROSSDESK_PORTABLE")
set_default(false)
set_showmenu(true)
set_description("Build CrossDesk as a portable package that stores data beside the executable")
option_end()
add_rules("mode.release", "mode.debug")
set_languages("c++17")
set_encodings("utf-8")
@@ -35,6 +41,7 @@ function setup_options_and_dependencies()
add_defines("USE_CUDA=" .. (is_config("USE_CUDA", true) and "1" or "0"))
add_defines("USE_WAYLAND=" .. (is_config("USE_WAYLAND", true) and "1" or "0"))
add_defines("USE_DRM=" .. (is_config("USE_DRM", true) and "1" or "0"))
add_defines("CROSSDESK_PORTABLE=" .. (is_config("CROSSDESK_PORTABLE", true) and "1" or "0"))
if is_mode("debug") then
add_defines("CROSSDESK_DEBUG")
@@ -47,4 +54,4 @@ function setup_options_and_dependencies()
add_requires("nlohmann_json 3.11.3")
add_requires("cpp-httplib v0.26.0", {configs = {ssl = true}})
add_requires("tinyfiledialogs 3.15.1")
end
end
+35 -1
View File
@@ -25,6 +25,40 @@ function setup_targets()
add_files("src/path_manager/*.cpp")
add_includedirs("src/path_manager", {public = true})
target("path_manager_portable_test")
set_kind("binary")
set_default(false)
add_defines("CROSSDESK_PORTABLE=1")
add_includedirs("src/path_manager")
add_files("tests/path_manager_portable_test.cpp",
"src/path_manager/path_manager.cpp")
target("macos_keyboard_modifier_state_test")
set_kind("binary")
set_default(false)
add_includedirs("src/device_controller")
add_files("tests/macos_keyboard_modifier_state_test.cpp")
target("windows_manifest_resource_test")
set_kind("binary")
set_default(false)
add_files("tests/windows_manifest_resource_test.cpp")
target("windows_service_mouse_ipc_test")
set_kind("binary")
set_default(false)
add_files("tests/windows_service_mouse_ipc_test.cpp")
target("windows_mouse_controller_safety_test")
set_kind("binary")
set_default(false)
add_files("tests/windows_mouse_controller_safety_test.cpp")
target("display_popup_hover_state_test")
set_kind("binary")
set_default(false)
add_files("tests/display_popup_hover_state_test.cpp")
target("screen_capturer")
set_kind("object")
add_deps("rd_log", "common")
@@ -195,4 +229,4 @@ function setup_targets()
add_deps("wgc_plugin", "crossdesk_service", "crossdesk_session_helper")
add_files("scripts/windows/crossdesk.rc")
end
end
end