mirror of
https://github.com/kunkundi/crossdesk.git
synced 2026-07-04 13:13:51 +08:00
Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 82c0cbbad4 | |||
| ce004af379 | |||
| 15bd9e9fdc | |||
| 37aabeaf72 | |||
| 473737ac9b | |||
| 1e29ec708f | |||
| 515d517a99 | |||
| a3aedcb624 | |||
| 98b7c6c966 | |||
| b1d956af2c | |||
| b7a031bb7f | |||
| 15cce07b6e | |||
| a8769dee06 | |||
| 855b15025c |
@@ -242,6 +242,11 @@ jobs:
|
|||||||
cd "${{ github.workspace }}\scripts\windows"
|
cd "${{ github.workspace }}\scripts\windows"
|
||||||
makensis /DVERSION=$env:VERSION_NUM nsis_script.nsi
|
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
|
- name: Package Portable
|
||||||
shell: pwsh
|
shell: pwsh
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ ARCHITECTURE="amd64"
|
|||||||
MAINTAINER="Junkun Di <junkun.di@hotmail.com>"
|
MAINTAINER="Junkun Di <junkun.di@hotmail.com>"
|
||||||
DESCRIPTION="A simple cross-platform remote desktop client."
|
DESCRIPTION="A simple cross-platform remote desktop client."
|
||||||
ALSA_RUNTIME_DEP="libasound2 | libasound2t64"
|
ALSA_RUNTIME_DEP="libasound2 | libasound2t64"
|
||||||
PIPEWIRE_RUNTIME_DEP="libpipewire-0.3-0 | libpipewire-0.3-0t64"
|
PORTAL_RUNTIME_RECOMMENDS="xdg-desktop-portal, xdg-desktop-portal-gtk | xdg-desktop-portal-kde | xdg-desktop-portal-wlr"
|
||||||
|
|
||||||
# Remove 'v' prefix from version for Debian package (Debian version must start with digit)
|
# Remove 'v' prefix from version for Debian package (Debian version must start with digit)
|
||||||
DEB_VERSION="${APP_VERSION#v}"
|
DEB_VERSION="${APP_VERSION#v}"
|
||||||
@@ -44,10 +44,8 @@ Description: $DESCRIPTION
|
|||||||
Depends: libc6 (>= 2.29), libstdc++6 (>= 9), libx11-6, libxcb1,
|
Depends: libc6 (>= 2.29), libstdc++6 (>= 9), libx11-6, libxcb1,
|
||||||
libxcb-randr0, libxcb-xtest0, libxcb-xinerama0, libxcb-shape0,
|
libxcb-randr0, libxcb-xtest0, libxcb-xinerama0, libxcb-shape0,
|
||||||
libxcb-xkb1, libxcb-xfixes0, libxv1, libxtst6, $ALSA_RUNTIME_DEP,
|
libxcb-xkb1, libxcb-xfixes0, libxv1, libxtst6, $ALSA_RUNTIME_DEP,
|
||||||
libsndio7.0, libxcb-shm0, libpulse0, libdrm2, libdbus-1-3,
|
libsndio7.0, libxcb-shm0, libpulse0, libdrm2, libdbus-1-3
|
||||||
$PIPEWIRE_RUNTIME_DEP, xdg-desktop-portal,
|
Recommends: $PORTAL_RUNTIME_RECOMMENDS, nvidia-cuda-toolkit
|
||||||
xdg-desktop-portal-gtk | xdg-desktop-portal-kde | xdg-desktop-portal-wlr
|
|
||||||
Recommends: nvidia-cuda-toolkit
|
|
||||||
Priority: optional
|
Priority: optional
|
||||||
Section: utils
|
Section: utils
|
||||||
EOF
|
EOF
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ ARCHITECTURE="arm64"
|
|||||||
MAINTAINER="Junkun Di <junkun.di@hotmail.com>"
|
MAINTAINER="Junkun Di <junkun.di@hotmail.com>"
|
||||||
DESCRIPTION="A simple cross-platform remote desktop client."
|
DESCRIPTION="A simple cross-platform remote desktop client."
|
||||||
ALSA_RUNTIME_DEP="libasound2 | libasound2t64"
|
ALSA_RUNTIME_DEP="libasound2 | libasound2t64"
|
||||||
PIPEWIRE_RUNTIME_DEP="libpipewire-0.3-0 | libpipewire-0.3-0t64"
|
PORTAL_RUNTIME_RECOMMENDS="xdg-desktop-portal, xdg-desktop-portal-gtk | xdg-desktop-portal-kde | xdg-desktop-portal-wlr"
|
||||||
|
|
||||||
# Remove 'v' prefix from version for Debian package (Debian version must start with digit)
|
# Remove 'v' prefix from version for Debian package (Debian version must start with digit)
|
||||||
DEB_VERSION="${APP_VERSION#v}"
|
DEB_VERSION="${APP_VERSION#v}"
|
||||||
@@ -44,9 +44,8 @@ Description: $DESCRIPTION
|
|||||||
Depends: libc6 (>= 2.29), libstdc++6 (>= 9), libx11-6, libxcb1,
|
Depends: libc6 (>= 2.29), libstdc++6 (>= 9), libx11-6, libxcb1,
|
||||||
libxcb-randr0, libxcb-xtest0, libxcb-xinerama0, libxcb-shape0,
|
libxcb-randr0, libxcb-xtest0, libxcb-xinerama0, libxcb-shape0,
|
||||||
libxcb-xkb1, libxcb-xfixes0, libxv1, libxtst6, $ALSA_RUNTIME_DEP,
|
libxcb-xkb1, libxcb-xfixes0, libxv1, libxtst6, $ALSA_RUNTIME_DEP,
|
||||||
libsndio7.0, libxcb-shm0, libpulse0, libdrm2, libdbus-1-3,
|
libsndio7.0, libxcb-shm0, libpulse0, libdrm2, libdbus-1-3
|
||||||
$PIPEWIRE_RUNTIME_DEP, xdg-desktop-portal,
|
Recommends: $PORTAL_RUNTIME_RECOMMENDS
|
||||||
xdg-desktop-portal-gtk | xdg-desktop-portal-kde | xdg-desktop-portal-wlr
|
|
||||||
Priority: optional
|
Priority: optional
|
||||||
Section: utils
|
Section: utils
|
||||||
EOF
|
EOF
|
||||||
|
|||||||
@@ -1,17 +1,13 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
|
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
|
||||||
|
|
||||||
<!-- 应用程序标识 -->
|
|
||||||
<assemblyIdentity
|
<assemblyIdentity
|
||||||
version="1.0.0.0"
|
version="1.0.0.0"
|
||||||
processorArchitecture="*"
|
|
||||||
name="CrossDesk"
|
name="CrossDesk"
|
||||||
type="win32" />
|
type="win32" />
|
||||||
|
|
||||||
<!-- 描述信息 -->
|
|
||||||
<description>CrossDesk Application</description>
|
<description>CrossDesk Application</description>
|
||||||
|
|
||||||
<!-- 权限:要求管理员运行 -->
|
|
||||||
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
|
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
|
||||||
<security>
|
<security>
|
||||||
<requestedPrivileges>
|
<requestedPrivileges>
|
||||||
@@ -20,24 +16,17 @@
|
|||||||
</security>
|
</security>
|
||||||
</trustInfo>
|
</trustInfo>
|
||||||
|
|
||||||
<!-- DPI 感知设置:支持高分屏 -->
|
|
||||||
<application xmlns="urn:schemas-microsoft-com:asm.v3">
|
<application xmlns="urn:schemas-microsoft-com:asm.v3">
|
||||||
<windowsSettings>
|
<windowsSettings>
|
||||||
<!-- Windows Vista/7 风格 DPI 感知 -->
|
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/pm</dpiAware>
|
||||||
<dpiAware>true/pm</dpiAware>
|
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
|
||||||
<!-- Windows 10/11 高级 DPI 感知 -->
|
|
||||||
<dpiAwareness>PerMonitorV2</dpiAwareness>
|
|
||||||
</windowsSettings>
|
</windowsSettings>
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
<!-- Windows 兼容性声明 -->
|
|
||||||
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
|
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
|
||||||
<application>
|
<application>
|
||||||
<!-- 支持 Windows 10 -->
|
|
||||||
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
|
|
||||||
<!-- 支持 Windows 11(向下兼容 Win10 GUID) -->
|
|
||||||
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
|
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
|
||||||
</application>
|
</application>
|
||||||
</compatibility>
|
</compatibility>
|
||||||
|
|
||||||
</assembly>
|
</assembly>
|
||||||
|
|||||||
@@ -1,2 +1,11 @@
|
|||||||
// Application icon resource; load by the resource name IDI_ICON1.
|
// Application icon resource; load by the resource name IDI_ICON1.
|
||||||
IDI_ICON1 ICON "..\\..\\icons\\windows\\crossdesk.ico"
|
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
|
||||||
|
|||||||
@@ -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>
|
||||||
@@ -7,9 +7,10 @@
|
|||||||
#ifndef _DEVICE_CONTROLLER_H_
|
#ifndef _DEVICE_CONTROLLER_H_
|
||||||
#define _DEVICE_CONTROLLER_H_
|
#define _DEVICE_CONTROLLER_H_
|
||||||
|
|
||||||
#include <cstring>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <cstring>
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
@@ -39,7 +40,7 @@ typedef enum {
|
|||||||
wheel_horizontal
|
wheel_horizontal
|
||||||
} MouseFlag;
|
} MouseFlag;
|
||||||
typedef enum { key_down = 0, key_up } KeyFlag;
|
typedef enum { key_down = 0, key_up } KeyFlag;
|
||||||
typedef enum { send_sas = 0 } ServiceCommandFlag;
|
typedef enum { send_sas = 0, lock_workstation } ServiceCommandFlag;
|
||||||
typedef struct {
|
typedef struct {
|
||||||
float x;
|
float x;
|
||||||
float y;
|
float y;
|
||||||
@@ -49,6 +50,8 @@ typedef struct {
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
size_t key_value;
|
size_t key_value;
|
||||||
|
uint32_t scan_code;
|
||||||
|
bool extended;
|
||||||
KeyFlag flag;
|
KeyFlag flag;
|
||||||
} Key;
|
} Key;
|
||||||
|
|
||||||
@@ -103,7 +106,10 @@ struct RemoteAction {
|
|||||||
{"x", a.m.x}, {"y", a.m.y}, {"s", a.m.s}, {"flag", a.m.flag}};
|
{"x", a.m.x}, {"y", a.m.y}, {"s", a.m.s}, {"flag", a.m.flag}};
|
||||||
break;
|
break;
|
||||||
case ControlType::keyboard:
|
case ControlType::keyboard:
|
||||||
j["keyboard"] = {{"key_value", a.k.key_value}, {"flag", a.k.flag}};
|
j["keyboard"] = {{"key_value", a.k.key_value},
|
||||||
|
{"scan_code", a.k.scan_code},
|
||||||
|
{"extended", a.k.extended},
|
||||||
|
{"flag", a.k.flag}};
|
||||||
break;
|
break;
|
||||||
case ControlType::audio_capture:
|
case ControlType::audio_capture:
|
||||||
j["audio_capture"] = a.a;
|
j["audio_capture"] = a.a;
|
||||||
@@ -113,8 +119,7 @@ struct RemoteAction {
|
|||||||
break;
|
break;
|
||||||
case ControlType::service_status:
|
case ControlType::service_status:
|
||||||
j["service_status"] = {{"available", a.ss.available},
|
j["service_status"] = {{"available", a.ss.available},
|
||||||
{"interactive_stage",
|
{"interactive_stage", a.ss.interactive_stage}};
|
||||||
a.ss.interactive_stage}};
|
|
||||||
break;
|
break;
|
||||||
case ControlType::service_command:
|
case ControlType::service_command:
|
||||||
j["service_command"] = {{"flag", a.c.flag}};
|
j["service_command"] = {{"flag", a.c.flag}};
|
||||||
@@ -152,6 +157,9 @@ struct RemoteAction {
|
|||||||
break;
|
break;
|
||||||
case ControlType::keyboard:
|
case ControlType::keyboard:
|
||||||
out.k.key_value = j.at("keyboard").at("key_value").get<size_t>();
|
out.k.key_value = j.at("keyboard").at("key_value").get<size_t>();
|
||||||
|
out.k.scan_code =
|
||||||
|
j.at("keyboard").value("scan_code", static_cast<uint32_t>(0));
|
||||||
|
out.k.extended = j.at("keyboard").value("extended", false);
|
||||||
out.k.flag = (KeyFlag)j.at("keyboard").at("flag").get<int>();
|
out.k.flag = (KeyFlag)j.at("keyboard").at("flag").get<int>();
|
||||||
break;
|
break;
|
||||||
case ControlType::audio_capture:
|
case ControlType::audio_capture:
|
||||||
@@ -164,16 +172,15 @@ struct RemoteAction {
|
|||||||
const auto& service_status_json = j.at("service_status");
|
const auto& service_status_json = j.at("service_status");
|
||||||
out.ss.available = service_status_json.value("available", false);
|
out.ss.available = service_status_json.value("available", false);
|
||||||
std::string interactive_stage =
|
std::string interactive_stage =
|
||||||
service_status_json.value("interactive_stage", std::string());
|
service_status_json.value("interactive_stage", std::string());
|
||||||
std::strncpy(out.ss.interactive_stage, interactive_stage.c_str(),
|
std::strncpy(out.ss.interactive_stage, interactive_stage.c_str(),
|
||||||
sizeof(out.ss.interactive_stage) - 1);
|
sizeof(out.ss.interactive_stage) - 1);
|
||||||
out.ss.interactive_stage[sizeof(out.ss.interactive_stage) - 1] =
|
out.ss.interactive_stage[sizeof(out.ss.interactive_stage) - 1] = '\0';
|
||||||
'\0';
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ControlType::service_command:
|
case ControlType::service_command:
|
||||||
out.c.flag = static_cast<ServiceCommandFlag>(
|
out.c.flag = static_cast<ServiceCommandFlag>(
|
||||||
j.at("service_command").at("flag").get<int>());
|
j.at("service_command").at("flag").get<int>());
|
||||||
break;
|
break;
|
||||||
case ControlType::host_infomation: {
|
case ControlType::host_infomation: {
|
||||||
std::string host_name =
|
std::string host_name =
|
||||||
@@ -212,8 +219,8 @@ struct RemoteAction {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// int key_code, bool is_down
|
// int key_code, bool is_down, uint32_t scan_code, bool extended
|
||||||
typedef void (*OnKeyAction)(int, bool, void*);
|
typedef void (*OnKeyAction)(int, bool, uint32_t, bool, void*);
|
||||||
|
|
||||||
class DeviceController {
|
class DeviceController {
|
||||||
public:
|
public:
|
||||||
@@ -228,4 +235,4 @@ class DeviceController {
|
|||||||
// virtual int Unhook();
|
// virtual int Unhook();
|
||||||
};
|
};
|
||||||
} // namespace crossdesk
|
} // namespace crossdesk
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include "keyboard_converter.h"
|
#include "keyboard_converter.h"
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
#include "rd_log.h"
|
#include "rd_log.h"
|
||||||
|
#include "windows_key_metadata.h"
|
||||||
|
|
||||||
namespace crossdesk {
|
namespace crossdesk {
|
||||||
|
|
||||||
@@ -35,9 +36,12 @@ static int KeyboardEventHandler(Display* display, XEvent* event) {
|
|||||||
|
|
||||||
int key_code = key_it->second;
|
int key_code = key_it->second;
|
||||||
bool is_key_down = (event->xkey.type == KeyPress);
|
bool is_key_down = (event->xkey.type == KeyPress);
|
||||||
|
uint32_t scan_code = 0;
|
||||||
|
bool extended = false;
|
||||||
|
LookupWindowsKeyMetadataFromVk(key_code, &scan_code, &extended);
|
||||||
|
|
||||||
if (g_on_key_action) {
|
if (g_on_key_action) {
|
||||||
g_on_key_action(key_code, is_key_down, g_user_ptr);
|
g_on_key_action(key_code, is_key_down, scan_code, extended, g_user_ptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@@ -146,7 +150,10 @@ int KeyboardCapturer::Unhook() {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int KeyboardCapturer::SendKeyboardCommand(int key_code, bool is_down) {
|
int KeyboardCapturer::SendKeyboardCommand(int key_code, bool is_down,
|
||||||
|
uint32_t scan_code, bool extended) {
|
||||||
|
(void)scan_code;
|
||||||
|
(void)extended;
|
||||||
if (IsWaylandSession()) {
|
if (IsWaylandSession()) {
|
||||||
if (!use_wayland_portal_ && !wayland_init_attempted_) {
|
if (!use_wayland_portal_ && !wayland_init_attempted_) {
|
||||||
wayland_init_attempted_ = true;
|
wayland_init_attempted_ = true;
|
||||||
@@ -154,12 +161,14 @@ int KeyboardCapturer::SendKeyboardCommand(int key_code, bool is_down) {
|
|||||||
use_wayland_portal_ = true;
|
use_wayland_portal_ = true;
|
||||||
LOG_INFO("Keyboard controller initialized with Wayland portal backend");
|
LOG_INFO("Keyboard controller initialized with Wayland portal backend");
|
||||||
} else {
|
} else {
|
||||||
LOG_WARN("Wayland keyboard control init failed, falling back to X11/XTest backend");
|
LOG_WARN(
|
||||||
|
"Wayland keyboard control init failed, falling back to X11/XTest "
|
||||||
|
"backend");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (use_wayland_portal_) {
|
if (use_wayland_portal_) {
|
||||||
return SendWaylandKeyboardCommand(key_code, is_down);
|
return SendWaylandKeyboardCommand(key_code, is_down, scan_code, extended);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,12 +32,15 @@ class KeyboardCapturer : public DeviceController {
|
|||||||
public:
|
public:
|
||||||
virtual int Hook(OnKeyAction on_key_action, void* user_ptr);
|
virtual int Hook(OnKeyAction on_key_action, void* user_ptr);
|
||||||
virtual int Unhook();
|
virtual int Unhook();
|
||||||
virtual int SendKeyboardCommand(int key_code, bool is_down);
|
virtual int SendKeyboardCommand(int key_code, bool is_down,
|
||||||
|
uint32_t scan_code = 0,
|
||||||
|
bool extended = false);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool InitWaylandPortal();
|
bool InitWaylandPortal();
|
||||||
void CleanupWaylandPortal();
|
void CleanupWaylandPortal();
|
||||||
int SendWaylandKeyboardCommand(int key_code, bool is_down);
|
int SendWaylandKeyboardCommand(int key_code, bool is_down, uint32_t scan_code,
|
||||||
|
bool extended);
|
||||||
bool NotifyWaylandKeyboardKeysym(int keysym, uint32_t state);
|
bool NotifyWaylandKeyboardKeysym(int keysym, uint32_t state);
|
||||||
bool NotifyWaylandKeyboardKeycode(int keycode, uint32_t state);
|
bool NotifyWaylandKeyboardKeycode(int keycode, uint32_t state);
|
||||||
bool SendWaylandPortalVoidCall(const char* method_name,
|
bool SendWaylandPortalVoidCall(const char* method_name,
|
||||||
|
|||||||
@@ -575,8 +575,12 @@ void KeyboardCapturer::CleanupWaylandPortal() {
|
|||||||
wayland_session_handle_.clear();
|
wayland_session_handle_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
int KeyboardCapturer::SendWaylandKeyboardCommand(int key_code, bool is_down) {
|
int KeyboardCapturer::SendWaylandKeyboardCommand(int key_code, bool is_down,
|
||||||
|
uint32_t scan_code,
|
||||||
|
bool extended) {
|
||||||
#if defined(CROSSDESK_HAS_WAYLAND_CAPTURER) && CROSSDESK_HAS_WAYLAND_CAPTURER
|
#if defined(CROSSDESK_HAS_WAYLAND_CAPTURER) && CROSSDESK_HAS_WAYLAND_CAPTURER
|
||||||
|
(void)scan_code;
|
||||||
|
(void)extended;
|
||||||
if (!dbus_connection_ || wayland_session_handle_.empty()) {
|
if (!dbus_connection_ || wayland_session_handle_.empty()) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -613,6 +617,8 @@ int KeyboardCapturer::SendWaylandKeyboardCommand(int key_code, bool is_down) {
|
|||||||
#else
|
#else
|
||||||
(void)key_code;
|
(void)key_code;
|
||||||
(void)is_down;
|
(void)is_down;
|
||||||
|
(void)scan_code;
|
||||||
|
(void)extended;
|
||||||
return -1;
|
return -1;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ CGEventRef eventCallback(CGEventTapProxy proxy, CGEventType type,
|
|||||||
CGEventGetIntegerValueField(event, kCGKeyboardEventKeycode));
|
CGEventGetIntegerValueField(event, kCGKeyboardEventKeycode));
|
||||||
int vk_code = ResolveVkCodeFromMacEvent(event, key_code, is_key_down);
|
int vk_code = ResolveVkCodeFromMacEvent(event, key_code, is_key_down);
|
||||||
if (vk_code >= 0) {
|
if (vk_code >= 0) {
|
||||||
g_on_key_action(vk_code, is_key_down, g_user_ptr);
|
g_on_key_action(vk_code, is_key_down, 0, false, g_user_ptr);
|
||||||
}
|
}
|
||||||
} else if (type == kCGEventFlagsChanged) {
|
} else if (type == kCGEventFlagsChanged) {
|
||||||
CGEventFlags current_flags = CGEventGetFlags(event);
|
CGEventFlags current_flags = CGEventGetFlags(event);
|
||||||
@@ -135,35 +135,40 @@ CGEventRef eventCallback(CGEventTapProxy proxy, CGEventType type,
|
|||||||
bool caps_lock_state = (current_flags & kCGEventFlagMaskAlphaShift) != 0;
|
bool caps_lock_state = (current_flags & kCGEventFlagMaskAlphaShift) != 0;
|
||||||
if (caps_lock_state != keyboard_capturer->caps_lock_flag_) {
|
if (caps_lock_state != keyboard_capturer->caps_lock_flag_) {
|
||||||
keyboard_capturer->caps_lock_flag_ = caps_lock_state;
|
keyboard_capturer->caps_lock_flag_ = caps_lock_state;
|
||||||
g_on_key_action(vk_code, keyboard_capturer->caps_lock_flag_, g_user_ptr);
|
g_on_key_action(vk_code, keyboard_capturer->caps_lock_flag_, 0, false,
|
||||||
|
g_user_ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// shift
|
// shift
|
||||||
bool shift_state = (current_flags & kCGEventFlagMaskShift) != 0;
|
bool shift_state = (current_flags & kCGEventFlagMaskShift) != 0;
|
||||||
if (shift_state != keyboard_capturer->shift_flag_) {
|
if (shift_state != keyboard_capturer->shift_flag_) {
|
||||||
keyboard_capturer->shift_flag_ = shift_state;
|
keyboard_capturer->shift_flag_ = shift_state;
|
||||||
g_on_key_action(vk_code, keyboard_capturer->shift_flag_, g_user_ptr);
|
g_on_key_action(vk_code, keyboard_capturer->shift_flag_, 0, false,
|
||||||
|
g_user_ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// control
|
// control
|
||||||
bool control_state = (current_flags & kCGEventFlagMaskControl) != 0;
|
bool control_state = (current_flags & kCGEventFlagMaskControl) != 0;
|
||||||
if (control_state != keyboard_capturer->control_flag_) {
|
if (control_state != keyboard_capturer->control_flag_) {
|
||||||
keyboard_capturer->control_flag_ = control_state;
|
keyboard_capturer->control_flag_ = control_state;
|
||||||
g_on_key_action(vk_code, keyboard_capturer->control_flag_, g_user_ptr);
|
g_on_key_action(vk_code, keyboard_capturer->control_flag_, 0, false,
|
||||||
|
g_user_ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// option
|
// option
|
||||||
bool option_state = (current_flags & kCGEventFlagMaskAlternate) != 0;
|
bool option_state = (current_flags & kCGEventFlagMaskAlternate) != 0;
|
||||||
if (option_state != keyboard_capturer->option_flag_) {
|
if (option_state != keyboard_capturer->option_flag_) {
|
||||||
keyboard_capturer->option_flag_ = option_state;
|
keyboard_capturer->option_flag_ = option_state;
|
||||||
g_on_key_action(vk_code, keyboard_capturer->option_flag_, g_user_ptr);
|
g_on_key_action(vk_code, keyboard_capturer->option_flag_, 0, false,
|
||||||
|
g_user_ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// command
|
// command
|
||||||
bool command_state = (current_flags & kCGEventFlagMaskCommand) != 0;
|
bool command_state = (current_flags & kCGEventFlagMaskCommand) != 0;
|
||||||
if (command_state != keyboard_capturer->command_flag_) {
|
if (command_state != keyboard_capturer->command_flag_) {
|
||||||
keyboard_capturer->command_flag_ = command_state;
|
keyboard_capturer->command_flag_ = command_state;
|
||||||
g_on_key_action(vk_code, keyboard_capturer->command_flag_, g_user_ptr);
|
g_on_key_action(vk_code, keyboard_capturer->command_flag_, 0, false,
|
||||||
|
g_user_ptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -264,7 +269,30 @@ inline bool IsFunctionKey(int key_code) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int KeyboardCapturer::SendKeyboardCommand(int key_code, bool is_down) {
|
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()) {
|
if (vkCodeToCGKeyCode.find(key_code) != vkCodeToCGKeyCode.end()) {
|
||||||
CGKeyCode cg_key_code = vkCodeToCGKeyCode[key_code];
|
CGKeyCode cg_key_code = vkCodeToCGKeyCode[key_code];
|
||||||
CGEventRef event = CGEventCreateKeyboardEvent(NULL, cg_key_code, is_down);
|
CGEventRef event = CGEventCreateKeyboardEvent(NULL, cg_key_code, is_down);
|
||||||
@@ -273,7 +301,7 @@ int KeyboardCapturer::SendKeyboardCommand(int key_code, bool is_down) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
CGEventSetFlags(event, 0);
|
CGEventSetFlags(event, ToCGEventFlags(injected_flags));
|
||||||
CGEventPost(kCGHIDEventTap, event);
|
CGEventPost(kCGHIDEventTap, event);
|
||||||
CFRelease(event);
|
CFRelease(event);
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#include <ApplicationServices/ApplicationServices.h>
|
#include <ApplicationServices/ApplicationServices.h>
|
||||||
|
|
||||||
#include "device_controller.h"
|
#include "device_controller.h"
|
||||||
|
#include "macos_keyboard_modifier_state.h"
|
||||||
|
|
||||||
namespace crossdesk {
|
namespace crossdesk {
|
||||||
|
|
||||||
@@ -21,7 +22,9 @@ class KeyboardCapturer : public DeviceController {
|
|||||||
public:
|
public:
|
||||||
virtual int Hook(OnKeyAction on_key_action, void* user_ptr);
|
virtual int Hook(OnKeyAction on_key_action, void* user_ptr);
|
||||||
virtual int Unhook();
|
virtual int Unhook();
|
||||||
virtual int SendKeyboardCommand(int key_code, bool is_down);
|
virtual int SendKeyboardCommand(int key_code, bool is_down,
|
||||||
|
uint32_t scan_code = 0,
|
||||||
|
bool extended = false);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CFMachPortRef event_tap_ = nullptr;
|
CFMachPortRef event_tap_ = nullptr;
|
||||||
@@ -34,6 +37,7 @@ class KeyboardCapturer : public DeviceController {
|
|||||||
bool option_flag_ = false;
|
bool option_flag_ = false;
|
||||||
bool command_flag_ = false;
|
bool command_flag_ = false;
|
||||||
int fn_key_code_ = 0x3F;
|
int fn_key_code_ = 0x3F;
|
||||||
|
MacKeyboardModifierState injected_modifier_state_;
|
||||||
};
|
};
|
||||||
} // namespace crossdesk
|
} // namespace crossdesk
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -7,14 +7,56 @@ namespace crossdesk {
|
|||||||
static OnKeyAction g_on_key_action = nullptr;
|
static OnKeyAction g_on_key_action = nullptr;
|
||||||
static void* g_user_ptr = nullptr;
|
static void* g_user_ptr = nullptr;
|
||||||
|
|
||||||
|
static int NormalizeModifierVkCode(const KBDLLHOOKSTRUCT* kb_data) {
|
||||||
|
if (kb_data == nullptr) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (kb_data->vkCode != VK_SHIFT && kb_data->vkCode != VK_CONTROL &&
|
||||||
|
kb_data->vkCode != VK_MENU) {
|
||||||
|
return static_cast<int>(kb_data->vkCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
UINT scan_code = static_cast<UINT>(kb_data->scanCode & 0xFF);
|
||||||
|
if ((kb_data->flags & LLKHF_EXTENDED) != 0) {
|
||||||
|
scan_code |= 0xE000;
|
||||||
|
}
|
||||||
|
|
||||||
|
const UINT normalized_vk = MapVirtualKeyW(scan_code, MAPVK_VSC_TO_VK_EX);
|
||||||
|
if (normalized_vk != 0) {
|
||||||
|
return static_cast<int>(normalized_vk);
|
||||||
|
}
|
||||||
|
|
||||||
|
return static_cast<int>(kb_data->vkCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool PreferSideSpecificVkInjection(int key_code) {
|
||||||
|
switch (key_code) {
|
||||||
|
case VK_LSHIFT:
|
||||||
|
case VK_RSHIFT:
|
||||||
|
case VK_LCONTROL:
|
||||||
|
case VK_RCONTROL:
|
||||||
|
case VK_LMENU:
|
||||||
|
case VK_RMENU:
|
||||||
|
case VK_LWIN:
|
||||||
|
case VK_RWIN:
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) {
|
LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) {
|
||||||
if (nCode == HC_ACTION && g_on_key_action) {
|
if (nCode == HC_ACTION && g_on_key_action) {
|
||||||
KBDLLHOOKSTRUCT* kbData = reinterpret_cast<KBDLLHOOKSTRUCT*>(lParam);
|
KBDLLHOOKSTRUCT* kbData = reinterpret_cast<KBDLLHOOKSTRUCT*>(lParam);
|
||||||
|
const int key_code = NormalizeModifierVkCode(kbData);
|
||||||
|
|
||||||
if (wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN) {
|
if (wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN) {
|
||||||
g_on_key_action(kbData->vkCode, true, g_user_ptr);
|
g_on_key_action(key_code, true, kbData->scanCode,
|
||||||
|
(kbData->flags & LLKHF_EXTENDED) != 0, g_user_ptr);
|
||||||
} else if (wParam == WM_KEYUP || wParam == WM_SYSKEYUP) {
|
} else if (wParam == WM_KEYUP || wParam == WM_SYSKEYUP) {
|
||||||
g_on_key_action(kbData->vkCode, false, g_user_ptr);
|
g_on_key_action(key_code, false, kbData->scanCode,
|
||||||
|
(kbData->flags & LLKHF_EXTENDED) != 0, g_user_ptr);
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -49,20 +91,40 @@ int KeyboardCapturer::Unhook() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// apply remote keyboard commands to the local machine
|
// apply remote keyboard commands to the local machine
|
||||||
int KeyboardCapturer::SendKeyboardCommand(int key_code, bool is_down) {
|
int KeyboardCapturer::SendKeyboardCommand(int key_code, bool is_down,
|
||||||
|
uint32_t scan_code, bool extended) {
|
||||||
INPUT input = {0};
|
INPUT input = {0};
|
||||||
input.type = INPUT_KEYBOARD;
|
input.type = INPUT_KEYBOARD;
|
||||||
input.ki.wVk = (WORD)key_code;
|
|
||||||
|
|
||||||
const UINT scan_code =
|
const bool prefer_vk = PreferSideSpecificVkInjection(key_code);
|
||||||
MapVirtualKeyW(static_cast<UINT>(key_code), MAPVK_VK_TO_VSC_EX);
|
const UINT resolved_scan_code =
|
||||||
if (scan_code != 0) {
|
scan_code != 0
|
||||||
|
? static_cast<UINT>(scan_code & 0xFF) | (extended ? 0xE000u : 0u)
|
||||||
|
: MapVirtualKeyW(static_cast<UINT>(key_code), MAPVK_VK_TO_VSC_EX);
|
||||||
|
|
||||||
|
if (scan_code != 0 && !prefer_vk) {
|
||||||
input.ki.wVk = 0;
|
input.ki.wVk = 0;
|
||||||
input.ki.wScan = static_cast<WORD>(scan_code & 0xFF);
|
input.ki.wScan = static_cast<WORD>(scan_code & 0xFF);
|
||||||
input.ki.dwFlags |= KEYEVENTF_SCANCODE;
|
input.ki.dwFlags |= KEYEVENTF_SCANCODE;
|
||||||
if ((scan_code & 0xFF00) != 0) {
|
if (extended) {
|
||||||
input.ki.dwFlags |= KEYEVENTF_EXTENDEDKEY;
|
input.ki.dwFlags |= KEYEVENTF_EXTENDEDKEY;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
input.ki.wVk = (WORD)key_code;
|
||||||
|
|
||||||
|
if (prefer_vk && resolved_scan_code != 0) {
|
||||||
|
input.ki.wScan = static_cast<WORD>(resolved_scan_code & 0xFF);
|
||||||
|
if ((resolved_scan_code & 0xFF00) != 0) {
|
||||||
|
input.ki.dwFlags |= KEYEVENTF_EXTENDEDKEY;
|
||||||
|
}
|
||||||
|
} else if (resolved_scan_code != 0) {
|
||||||
|
input.ki.wVk = 0;
|
||||||
|
input.ki.wScan = static_cast<WORD>(resolved_scan_code & 0xFF);
|
||||||
|
input.ki.dwFlags |= KEYEVENTF_SCANCODE;
|
||||||
|
if ((resolved_scan_code & 0xFF00) != 0) {
|
||||||
|
input.ki.dwFlags |= KEYEVENTF_EXTENDEDKEY;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_down) {
|
if (!is_down) {
|
||||||
|
|||||||
@@ -21,7 +21,9 @@ class KeyboardCapturer : public DeviceController {
|
|||||||
public:
|
public:
|
||||||
virtual int Hook(OnKeyAction on_key_action, void* user_ptr);
|
virtual int Hook(OnKeyAction on_key_action, void* user_ptr);
|
||||||
virtual int Unhook();
|
virtual int Unhook();
|
||||||
virtual int SendKeyboardCommand(int key_code, bool is_down);
|
virtual int SendKeyboardCommand(int key_code, bool is_down,
|
||||||
|
uint32_t scan_code = 0,
|
||||||
|
bool extended = false);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
HHOOK keyboard_hook_ = nullptr;
|
HHOOK keyboard_hook_ = nullptr;
|
||||||
|
|||||||
@@ -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 "mouse_controller.h"
|
||||||
|
|
||||||
|
#include <Windows.h>
|
||||||
|
|
||||||
#include "rd_log.h"
|
#include "rd_log.h"
|
||||||
|
|
||||||
namespace crossdesk {
|
namespace crossdesk {
|
||||||
@@ -18,7 +20,14 @@ int MouseController::Destroy() { return 0; }
|
|||||||
|
|
||||||
int MouseController::SendMouseCommand(RemoteAction remote_action,
|
int MouseController::SendMouseCommand(RemoteAction remote_action,
|
||||||
int display_index) {
|
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) {
|
if (remote_action.type == ControlType::mouse) {
|
||||||
ip.type = INPUT_MOUSE;
|
ip.type = INPUT_MOUSE;
|
||||||
@@ -63,13 +72,25 @@ int MouseController::SendMouseCommand(RemoteAction remote_action,
|
|||||||
|
|
||||||
ip.mi.time = 0;
|
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) {
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
} // namespace crossdesk
|
} // namespace crossdesk
|
||||||
|
|||||||
@@ -0,0 +1,89 @@
|
|||||||
|
/*
|
||||||
|
* @Author: DI JUNKUN
|
||||||
|
* @Date: 2026-05-07
|
||||||
|
* Copyright (c) 2026 by DI JUNKUN, All Rights Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _WINDOWS_KEY_METADATA_H_
|
||||||
|
#define _WINDOWS_KEY_METADATA_H_
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
namespace crossdesk {
|
||||||
|
|
||||||
|
inline bool LookupWindowsKeyMetadataFromVk(int key_code,
|
||||||
|
uint32_t* scan_code_out,
|
||||||
|
bool* extended_out) {
|
||||||
|
if (scan_code_out == nullptr || extended_out == nullptr) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (key_code) {
|
||||||
|
case 0x21: // Page Up
|
||||||
|
*scan_code_out = 0x49;
|
||||||
|
*extended_out = true;
|
||||||
|
return true;
|
||||||
|
case 0x22: // Page Down
|
||||||
|
*scan_code_out = 0x51;
|
||||||
|
*extended_out = true;
|
||||||
|
return true;
|
||||||
|
case 0x23: // End
|
||||||
|
*scan_code_out = 0x4F;
|
||||||
|
*extended_out = true;
|
||||||
|
return true;
|
||||||
|
case 0x24: // Home
|
||||||
|
*scan_code_out = 0x47;
|
||||||
|
*extended_out = true;
|
||||||
|
return true;
|
||||||
|
case 0x25: // Left Arrow
|
||||||
|
*scan_code_out = 0x4B;
|
||||||
|
*extended_out = true;
|
||||||
|
return true;
|
||||||
|
case 0x26: // Up Arrow
|
||||||
|
*scan_code_out = 0x48;
|
||||||
|
*extended_out = true;
|
||||||
|
return true;
|
||||||
|
case 0x27: // Right Arrow
|
||||||
|
*scan_code_out = 0x4D;
|
||||||
|
*extended_out = true;
|
||||||
|
return true;
|
||||||
|
case 0x28: // Down Arrow
|
||||||
|
*scan_code_out = 0x50;
|
||||||
|
*extended_out = true;
|
||||||
|
return true;
|
||||||
|
case 0x2D: // Insert
|
||||||
|
*scan_code_out = 0x52;
|
||||||
|
*extended_out = true;
|
||||||
|
return true;
|
||||||
|
case 0x2E: // Delete
|
||||||
|
*scan_code_out = 0x53;
|
||||||
|
*extended_out = true;
|
||||||
|
return true;
|
||||||
|
case 0x6F: // Numpad /
|
||||||
|
*scan_code_out = 0x35;
|
||||||
|
*extended_out = true;
|
||||||
|
return true;
|
||||||
|
case 0xA3: // Right Ctrl
|
||||||
|
*scan_code_out = 0x1D;
|
||||||
|
*extended_out = true;
|
||||||
|
return true;
|
||||||
|
case 0xA5: // Right Alt
|
||||||
|
*scan_code_out = 0x38;
|
||||||
|
*extended_out = true;
|
||||||
|
return true;
|
||||||
|
case 0x5B: // Left Win
|
||||||
|
*scan_code_out = 0x5B;
|
||||||
|
*extended_out = true;
|
||||||
|
return true;
|
||||||
|
case 0x5C: // Right Win
|
||||||
|
*scan_code_out = 0x5C;
|
||||||
|
*extended_out = true;
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace crossdesk
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -51,7 +51,9 @@ struct TranslationRow {
|
|||||||
X(release_mouse, u8"释放", "Release", u8"Освободить") \
|
X(release_mouse, u8"释放", "Release", u8"Освободить") \
|
||||||
X(audio_capture, u8"声音", "Audio", u8"Звук") \
|
X(audio_capture, u8"声音", "Audio", u8"Звук") \
|
||||||
X(mute, u8" 静音", " Mute", u8"Без звука") \
|
X(mute, u8" 静音", " Mute", u8"Без звука") \
|
||||||
|
X(send_shortcut, u8"发送组合键", "Send Shortcut", u8"Сочетания клавиш") \
|
||||||
X(send_sas, u8"发送SAS", "Send SAS", u8"Отправить SAS") \
|
X(send_sas, u8"发送SAS", "Send SAS", u8"Отправить SAS") \
|
||||||
|
X(lock_remote, u8"锁定远端", "Lock Remote", u8"Заблокировать") \
|
||||||
X(remote_password_box_visible, u8"远端密码框已出现", \
|
X(remote_password_box_visible, u8"远端密码框已出现", \
|
||||||
"Remote password box visible", u8"Окно ввода пароля видно") \
|
"Remote password box visible", u8"Окно ввода пароля видно") \
|
||||||
X(remote_lock_screen_hint, u8"远端处于锁屏封面,可发送SAS", \
|
X(remote_lock_screen_hint, u8"远端处于锁屏封面,可发送SAS", \
|
||||||
|
|||||||
@@ -204,11 +204,11 @@ int Render::ConnectTo(const std::string& remote_id, const char* password,
|
|||||||
props->params_.user_id = props->local_id_.c_str();
|
props->params_.user_id = props->local_id_.c_str();
|
||||||
props->peer_ = CreatePeer(&props->params_);
|
props->peer_ = CreatePeer(&props->params_);
|
||||||
|
|
||||||
props->control_window_width_ = title_bar_height_ * 9.0f;
|
props->control_window_width_ = title_bar_height_ * 10.0f;
|
||||||
props->control_window_height_ = title_bar_height_ * 1.3f;
|
props->control_window_height_ = title_bar_height_ * 1.3f;
|
||||||
props->control_window_min_width_ = title_bar_height_ * 0.65f;
|
props->control_window_min_width_ = title_bar_height_ * 0.65f;
|
||||||
props->control_window_min_height_ = title_bar_height_ * 1.3f;
|
props->control_window_min_height_ = title_bar_height_ * 1.3f;
|
||||||
props->control_window_max_width_ = title_bar_height_ * 9.0f;
|
props->control_window_max_width_ = title_bar_height_ * 10.0f;
|
||||||
props->control_window_max_height_ = title_bar_height_ * 7.0f;
|
props->control_window_max_height_ = title_bar_height_ * 7.0f;
|
||||||
|
|
||||||
props->connection_status_ = ConnectionStatus::Connecting;
|
props->connection_status_ = ConnectionStatus::Connecting;
|
||||||
@@ -272,4 +272,4 @@ int Render::ConnectTo(const std::string& remote_id, const char* password,
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
} // namespace crossdesk
|
} // namespace crossdesk
|
||||||
|
|||||||
+3
-2
@@ -812,10 +812,11 @@ int Render::StartKeyboardCapturer() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int keyboard_capturer_init_ret = keyboard_capturer_->Hook(
|
int keyboard_capturer_init_ret = keyboard_capturer_->Hook(
|
||||||
[](int key_code, bool is_down, void* user_ptr) {
|
[](int key_code, bool is_down, uint32_t scan_code, bool extended,
|
||||||
|
void* user_ptr) {
|
||||||
if (user_ptr) {
|
if (user_ptr) {
|
||||||
Render* render = (Render*)user_ptr;
|
Render* render = (Render*)user_ptr;
|
||||||
render->SendKeyCommand(key_code, is_down);
|
render->SendKeyCommand(key_code, is_down, scan_code, extended);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
this);
|
this);
|
||||||
|
|||||||
+6
-3
@@ -62,6 +62,7 @@ class Render {
|
|||||||
std::chrono::steady_clock::time_point file_send_last_update_time_;
|
std::chrono::steady_clock::time_point file_send_last_update_time_;
|
||||||
uint64_t file_send_last_bytes_ = 0;
|
uint64_t file_send_last_bytes_ = 0;
|
||||||
bool file_transfer_window_visible_ = false;
|
bool file_transfer_window_visible_ = false;
|
||||||
|
bool file_transfer_window_hovered_ = false;
|
||||||
std::atomic<uint32_t> current_file_id_{0};
|
std::atomic<uint32_t> current_file_id_{0};
|
||||||
|
|
||||||
struct QueuedFile {
|
struct QueuedFile {
|
||||||
@@ -114,6 +115,7 @@ class Render {
|
|||||||
bool is_control_bar_in_left_ = true;
|
bool is_control_bar_in_left_ = true;
|
||||||
bool control_bar_hovered_ = false;
|
bool control_bar_hovered_ = false;
|
||||||
bool display_selectable_hovered_ = false;
|
bool display_selectable_hovered_ = false;
|
||||||
|
bool shortcut_selectable_hovered_ = false;
|
||||||
bool control_bar_expand_ = true;
|
bool control_bar_expand_ = true;
|
||||||
bool reset_control_bar_pos_ = false;
|
bool reset_control_bar_pos_ = false;
|
||||||
bool control_window_width_is_changing_ = false;
|
bool control_window_width_is_changing_ = false;
|
||||||
@@ -124,10 +126,10 @@ class Render {
|
|||||||
float sub_stream_window_width_ = 1280;
|
float sub_stream_window_width_ = 1280;
|
||||||
float sub_stream_window_height_ = 720;
|
float sub_stream_window_height_ = 720;
|
||||||
float control_window_min_width_ = 20;
|
float control_window_min_width_ = 20;
|
||||||
float control_window_max_width_ = 230;
|
float control_window_max_width_ = 300;
|
||||||
float control_window_min_height_ = 38;
|
float control_window_min_height_ = 38;
|
||||||
float control_window_max_height_ = 180;
|
float control_window_max_height_ = 180;
|
||||||
float control_window_width_ = 230;
|
float control_window_width_ = 300;
|
||||||
float control_window_height_ = 38;
|
float control_window_height_ = 38;
|
||||||
float control_bar_pos_x_ = 0;
|
float control_bar_pos_x_ = 0;
|
||||||
float control_bar_pos_y_ = 30;
|
float control_bar_pos_y_ = 30;
|
||||||
@@ -338,7 +340,8 @@ class Render {
|
|||||||
static void FreeRemoteAction(RemoteAction& action);
|
static void FreeRemoteAction(RemoteAction& action);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int SendKeyCommand(int key_code, bool is_down);
|
int SendKeyCommand(int key_code, bool is_down, uint32_t scan_code = 0,
|
||||||
|
bool extended = false);
|
||||||
static bool IsModifierVkKey(int key_code);
|
static bool IsModifierVkKey(int key_code);
|
||||||
void TrackPressedKeyState(int key_code, bool is_down);
|
void TrackPressedKeyState(int key_code, bool is_down);
|
||||||
void ForceReleasePressedKeys();
|
void ForceReleasePressedKeys();
|
||||||
|
|||||||
+110
-10
@@ -17,6 +17,7 @@
|
|||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
#include "rd_log.h"
|
#include "rd_log.h"
|
||||||
#include "render.h"
|
#include "render.h"
|
||||||
|
#include "windows_key_metadata.h"
|
||||||
#if _WIN32
|
#if _WIN32
|
||||||
#include "interactive_state.h"
|
#include "interactive_state.h"
|
||||||
#include "service_host.h"
|
#include "service_host.h"
|
||||||
@@ -28,34 +29,66 @@ namespace crossdesk {
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
int TranslateSdlKeypadScancodeToVk(SDL_Scancode scancode) {
|
int TranslateSdlKeypadScancodeToVk(const SDL_KeyboardEvent& event) {
|
||||||
switch (scancode) {
|
const bool numlock_enabled = (event.mod & SDL_KMOD_NUM) != 0;
|
||||||
|
|
||||||
|
switch (event.scancode) {
|
||||||
case SDL_SCANCODE_NUMLOCKCLEAR:
|
case SDL_SCANCODE_NUMLOCKCLEAR:
|
||||||
return 0x90;
|
return 0x90;
|
||||||
case SDL_SCANCODE_KP_ENTER:
|
case SDL_SCANCODE_KP_ENTER:
|
||||||
return 0x0D;
|
return 0x0D;
|
||||||
case SDL_SCANCODE_KP_0:
|
case SDL_SCANCODE_KP_0:
|
||||||
|
if (!numlock_enabled) {
|
||||||
|
return 0x2D;
|
||||||
|
}
|
||||||
return 0x60;
|
return 0x60;
|
||||||
case SDL_SCANCODE_KP_1:
|
case SDL_SCANCODE_KP_1:
|
||||||
|
if (!numlock_enabled) {
|
||||||
|
return 0x23;
|
||||||
|
}
|
||||||
return 0x61;
|
return 0x61;
|
||||||
case SDL_SCANCODE_KP_2:
|
case SDL_SCANCODE_KP_2:
|
||||||
|
if (!numlock_enabled) {
|
||||||
|
return 0x28;
|
||||||
|
}
|
||||||
return 0x62;
|
return 0x62;
|
||||||
case SDL_SCANCODE_KP_3:
|
case SDL_SCANCODE_KP_3:
|
||||||
|
if (!numlock_enabled) {
|
||||||
|
return 0x22;
|
||||||
|
}
|
||||||
return 0x63;
|
return 0x63;
|
||||||
case SDL_SCANCODE_KP_4:
|
case SDL_SCANCODE_KP_4:
|
||||||
|
if (!numlock_enabled) {
|
||||||
|
return 0x25;
|
||||||
|
}
|
||||||
return 0x64;
|
return 0x64;
|
||||||
case SDL_SCANCODE_KP_5:
|
case SDL_SCANCODE_KP_5:
|
||||||
return 0x65;
|
return 0x65;
|
||||||
case SDL_SCANCODE_KP_6:
|
case SDL_SCANCODE_KP_6:
|
||||||
|
if (!numlock_enabled) {
|
||||||
|
return 0x27;
|
||||||
|
}
|
||||||
return 0x66;
|
return 0x66;
|
||||||
case SDL_SCANCODE_KP_7:
|
case SDL_SCANCODE_KP_7:
|
||||||
|
if (!numlock_enabled) {
|
||||||
|
return 0x24;
|
||||||
|
}
|
||||||
return 0x67;
|
return 0x67;
|
||||||
case SDL_SCANCODE_KP_8:
|
case SDL_SCANCODE_KP_8:
|
||||||
|
if (!numlock_enabled) {
|
||||||
|
return 0x26;
|
||||||
|
}
|
||||||
return 0x68;
|
return 0x68;
|
||||||
case SDL_SCANCODE_KP_9:
|
case SDL_SCANCODE_KP_9:
|
||||||
|
if (!numlock_enabled) {
|
||||||
|
return 0x21;
|
||||||
|
}
|
||||||
return 0x69;
|
return 0x69;
|
||||||
case SDL_SCANCODE_KP_PERIOD:
|
case SDL_SCANCODE_KP_PERIOD:
|
||||||
case SDL_SCANCODE_KP_COMMA:
|
case SDL_SCANCODE_KP_COMMA:
|
||||||
|
if (!numlock_enabled) {
|
||||||
|
return 0x2E;
|
||||||
|
}
|
||||||
return 0x6E;
|
return 0x6E;
|
||||||
case SDL_SCANCODE_KP_DIVIDE:
|
case SDL_SCANCODE_KP_DIVIDE:
|
||||||
return 0x6F;
|
return 0x6F;
|
||||||
@@ -73,7 +106,7 @@ int TranslateSdlKeypadScancodeToVk(SDL_Scancode scancode) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int TranslateSdlKeyboardEventToVk(const SDL_KeyboardEvent& event) {
|
int TranslateSdlKeyboardEventToVk(const SDL_KeyboardEvent& event) {
|
||||||
const int keypad_key_code = TranslateSdlKeypadScancodeToVk(event.scancode);
|
const int keypad_key_code = TranslateSdlKeypadScancodeToVk(event);
|
||||||
if (keypad_key_code >= 0) {
|
if (keypad_key_code >= 0) {
|
||||||
return keypad_key_code;
|
return keypad_key_code;
|
||||||
}
|
}
|
||||||
@@ -200,6 +233,49 @@ int TranslateSdlKeyboardEventToVk(const SDL_KeyboardEvent& event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int NormalizeWindowsModifierVk(int key_code, uint32_t scan_code,
|
||||||
|
bool extended) {
|
||||||
|
#if _WIN32
|
||||||
|
if (key_code != 0x10 && key_code != 0x11 && key_code != 0x12) {
|
||||||
|
return key_code;
|
||||||
|
}
|
||||||
|
|
||||||
|
UINT scan_code_with_prefix = static_cast<UINT>(scan_code & 0xFF);
|
||||||
|
if (extended) {
|
||||||
|
scan_code_with_prefix |= 0xE000;
|
||||||
|
}
|
||||||
|
|
||||||
|
const UINT normalized_vk =
|
||||||
|
MapVirtualKeyW(scan_code_with_prefix, MAPVK_VSC_TO_VK_EX);
|
||||||
|
return normalized_vk != 0 ? static_cast<int>(normalized_vk) : key_code;
|
||||||
|
#else
|
||||||
|
(void)scan_code;
|
||||||
|
(void)extended;
|
||||||
|
return key_code;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void PopulateWindowsKeyMetadataFromVk(int key_code, uint32_t* scan_code_out,
|
||||||
|
bool* extended_out) {
|
||||||
|
if (scan_code_out == nullptr || extended_out == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if _WIN32
|
||||||
|
const UINT scan_code =
|
||||||
|
MapVirtualKeyW(static_cast<UINT>(key_code), MAPVK_VK_TO_VSC_EX);
|
||||||
|
if (scan_code == 0) {
|
||||||
|
LookupWindowsKeyMetadataFromVk(key_code, scan_code_out, extended_out);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
*scan_code_out = static_cast<uint32_t>(scan_code & 0xFF);
|
||||||
|
*extended_out = (scan_code & 0xFF00) != 0;
|
||||||
|
#else
|
||||||
|
LookupWindowsKeyMetadataFromVk(key_code, scan_code_out, extended_out);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
#if _WIN32
|
#if _WIN32
|
||||||
constexpr uint32_t kSecureDesktopInputLogIntervalMs = 2000;
|
constexpr uint32_t kSecureDesktopInputLogIntervalMs = 2000;
|
||||||
|
|
||||||
@@ -353,15 +429,26 @@ void Render::ForceReleasePressedKeys() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Render::SendKeyCommand(int key_code, bool is_down) {
|
int Render::SendKeyCommand(int key_code, bool is_down, uint32_t scan_code,
|
||||||
RemoteAction remote_action;
|
bool extended) {
|
||||||
|
RemoteAction remote_action{};
|
||||||
remote_action.type = ControlType::keyboard;
|
remote_action.type = ControlType::keyboard;
|
||||||
if (is_down) {
|
if (is_down) {
|
||||||
remote_action.k.flag = KeyFlag::key_down;
|
remote_action.k.flag = KeyFlag::key_down;
|
||||||
} else {
|
} else {
|
||||||
remote_action.k.flag = KeyFlag::key_up;
|
remote_action.k.flag = KeyFlag::key_up;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (scan_code == 0) {
|
||||||
|
PopulateWindowsKeyMetadataFromVk(key_code, &scan_code, &extended);
|
||||||
|
}
|
||||||
|
#if _WIN32
|
||||||
|
key_code = NormalizeWindowsModifierVk(key_code, scan_code, extended);
|
||||||
|
#endif
|
||||||
|
|
||||||
remote_action.k.key_value = key_code;
|
remote_action.k.key_value = key_code;
|
||||||
|
remote_action.k.scan_code = scan_code;
|
||||||
|
remote_action.k.extended = extended;
|
||||||
|
|
||||||
std::string target_id = controlled_remote_id_.empty() ? focused_remote_id_
|
std::string target_id = controlled_remote_id_.empty() ? focused_remote_id_
|
||||||
: controlled_remote_id_;
|
: controlled_remote_id_;
|
||||||
@@ -474,6 +561,12 @@ int Render::ProcessMouseEvent(const SDL_Event& event) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const bool file_transfer_window_hovered =
|
||||||
|
props->file_transfer_.file_transfer_window_hovered_;
|
||||||
|
const bool overlay_hovered =
|
||||||
|
props->control_bar_hovered_ || props->display_selectable_hovered_ ||
|
||||||
|
props->shortcut_selectable_hovered_ || file_transfer_window_hovered;
|
||||||
|
|
||||||
const SDL_FRect render_rect = props->stream_render_rect_f_;
|
const SDL_FRect render_rect = props->stream_render_rect_f_;
|
||||||
if (render_rect.w <= 1.0f || render_rect.h <= 1.0f) {
|
if (render_rect.w <= 1.0f || render_rect.h <= 1.0f) {
|
||||||
continue;
|
continue;
|
||||||
@@ -517,7 +610,7 @@ int Render::ProcessMouseEvent(const SDL_Event& event) {
|
|||||||
remote_action.m.flag = MouseFlag::move;
|
remote_action.m.flag = MouseFlag::move;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (props->control_bar_hovered_ || props->display_selectable_hovered_) {
|
if (overlay_hovered) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (props->peer_) {
|
if (props->peer_) {
|
||||||
@@ -563,7 +656,7 @@ int Render::ProcessMouseEvent(const SDL_Event& event) {
|
|||||||
remote_action.m.x = std::clamp(remote_action.m.x, 0.0f, 1.0f);
|
remote_action.m.x = std::clamp(remote_action.m.x, 0.0f, 1.0f);
|
||||||
remote_action.m.y = std::clamp(remote_action.m.y, 0.0f, 1.0f);
|
remote_action.m.y = std::clamp(remote_action.m.y, 0.0f, 1.0f);
|
||||||
|
|
||||||
if (props->control_bar_hovered_) {
|
if (overlay_hovered) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (props->peer_) {
|
if (props->peer_) {
|
||||||
@@ -970,6 +1063,11 @@ void Render::OnReceiveDataBufferCb(const char* data, size_t size,
|
|||||||
if (remote_action.c.flag == ServiceCommandFlag::send_sas) {
|
if (remote_action.c.flag == ServiceCommandFlag::send_sas) {
|
||||||
render->pending_windows_service_sas_.store(true,
|
render->pending_windows_service_sas_.store(true,
|
||||||
std::memory_order_relaxed);
|
std::memory_order_relaxed);
|
||||||
|
} else if (remote_action.c.flag == ServiceCommandFlag::lock_workstation) {
|
||||||
|
if (!LockWorkStation()) {
|
||||||
|
LOG_WARN("Remote lock workstation request failed, error={}",
|
||||||
|
GetLastError());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return;
|
return;
|
||||||
@@ -1042,8 +1140,9 @@ void Render::OnReceiveDataBufferCb(const char* data, size_t size,
|
|||||||
if (remote_action.type == ControlType::keyboard) {
|
if (remote_action.type == ControlType::keyboard) {
|
||||||
const int key_code = static_cast<int>(remote_action.k.key_value);
|
const int key_code = static_cast<int>(remote_action.k.key_value);
|
||||||
const bool is_down = remote_action.k.flag == KeyFlag::key_down;
|
const bool is_down = remote_action.k.flag == KeyFlag::key_down;
|
||||||
const std::string response =
|
const std::string response = SendCrossDeskSecureDesktopKeyInput(
|
||||||
SendCrossDeskSecureDesktopKeyInput(key_code, is_down, 1000);
|
key_code, is_down, remote_action.k.scan_code,
|
||||||
|
remote_action.k.extended, 1000);
|
||||||
auto json = nlohmann::json::parse(response, nullptr, false);
|
auto json = nlohmann::json::parse(response, nullptr, false);
|
||||||
if (json.is_discarded() || !json.value("ok", false)) {
|
if (json.is_discarded() || !json.value("ok", false)) {
|
||||||
LogSecureDesktopInputBlocked(
|
LogSecureDesktopInputBlocked(
|
||||||
@@ -1070,7 +1169,8 @@ void Render::OnReceiveDataBufferCb(const char* data, size_t size,
|
|||||||
render->keyboard_capturer_) {
|
render->keyboard_capturer_) {
|
||||||
render->keyboard_capturer_->SendKeyboardCommand(
|
render->keyboard_capturer_->SendKeyboardCommand(
|
||||||
(int)remote_action.k.key_value,
|
(int)remote_action.k.key_value,
|
||||||
remote_action.k.flag == KeyFlag::key_down);
|
remote_action.k.flag == KeyFlag::key_down, remote_action.k.scan_code,
|
||||||
|
remote_action.k.extended);
|
||||||
} else if (remote_action.type == ControlType::display_id &&
|
} else if (remote_action.type == ControlType::display_id &&
|
||||||
render->screen_capturer_) {
|
render->screen_capturer_) {
|
||||||
render->selected_display_ = remote_action.d;
|
render->selected_display_ = remote_action.d;
|
||||||
|
|||||||
@@ -163,6 +163,7 @@ int Render::ControlBar(std::shared_ptr<SubStreamWindowProperties>& props) {
|
|||||||
ImVec2 btn_min = ImGui::GetItemRectMin();
|
ImVec2 btn_min = ImGui::GetItemRectMin();
|
||||||
ImVec2 btn_size_actual = ImGui::GetItemRectSize();
|
ImVec2 btn_size_actual = ImGui::GetItemRectSize();
|
||||||
|
|
||||||
|
props->display_selectable_hovered_ = false;
|
||||||
if (ImGui::BeginPopup("display")) {
|
if (ImGui::BeginPopup("display")) {
|
||||||
ImGui::SetWindowFontScale(0.5f);
|
ImGui::SetWindowFontScale(0.5f);
|
||||||
for (int i = 0; i < props->display_info_list_.size(); i++) {
|
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->control_data_label_.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
props->display_selectable_hovered_ = ImGui::IsWindowHovered();
|
|
||||||
}
|
}
|
||||||
|
props->display_selectable_hovered_ =
|
||||||
|
ImGui::IsWindowHovered(ImGuiHoveredFlags_RootAndChildWindows);
|
||||||
ImGui::EndPopup();
|
ImGui::EndPopup();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,6 +195,61 @@ int Render::ControlBar(std::shared_ptr<SubStreamWindowProperties>& props) {
|
|||||||
text_pos, IM_COL32(0, 0, 0, 255),
|
text_pos, IM_COL32(0, 0, 0, 255),
|
||||||
std::to_string(props->selected_display_ + 1).c_str());
|
std::to_string(props->selected_display_ + 1).c_str());
|
||||||
|
|
||||||
|
auto send_service_command = [&](ServiceCommandFlag flag,
|
||||||
|
const char* log_action) {
|
||||||
|
if (props->connection_status_ == ConnectionStatus::Connected &&
|
||||||
|
props->peer_) {
|
||||||
|
RemoteAction remote_action;
|
||||||
|
remote_action.type = ControlType::service_command;
|
||||||
|
remote_action.c.flag = flag;
|
||||||
|
std::string msg = remote_action.to_json();
|
||||||
|
int ret = SendReliableDataFrame(props->peer_, msg.c_str(), msg.size(),
|
||||||
|
props->control_data_label_.c_str());
|
||||||
|
if (ret != 0) {
|
||||||
|
LOG_WARN("Send {} command failed, remote_id={}, ret={}", log_action,
|
||||||
|
props->remote_id_, ret);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ImGui::SameLine();
|
||||||
|
std::string shortcut = ICON_FA_KEYBOARD;
|
||||||
|
ImGui::SetWindowFontScale(0.5f);
|
||||||
|
if (ImGui::Button(shortcut.c_str(), ImVec2(button_width, button_height))) {
|
||||||
|
ImGui::OpenPopup("shortcut");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ImGui::IsItemHovered()) {
|
||||||
|
ImGui::BeginTooltip();
|
||||||
|
ImGui::SetWindowFontScale(0.5f);
|
||||||
|
ImGui::Text(
|
||||||
|
"%s",
|
||||||
|
localization::send_shortcut[localization_language_index_].c_str());
|
||||||
|
ImGui::SetWindowFontScale(1.0f);
|
||||||
|
ImGui::EndTooltip();
|
||||||
|
}
|
||||||
|
|
||||||
|
props->shortcut_selectable_hovered_ = false;
|
||||||
|
if (ImGui::BeginPopup("shortcut")) {
|
||||||
|
ImGui::SetWindowFontScale(0.5f);
|
||||||
|
std::string sas_label =
|
||||||
|
"Ctrl+Alt+Del - " +
|
||||||
|
localization::send_sas[localization_language_index_];
|
||||||
|
std::string lock_label =
|
||||||
|
"Win+L - " + localization::lock_remote[localization_language_index_];
|
||||||
|
if (ImGui::Selectable(sas_label.c_str())) {
|
||||||
|
send_service_command(ServiceCommandFlag::send_sas, "SAS");
|
||||||
|
}
|
||||||
|
if (ImGui::Selectable(lock_label.c_str())) {
|
||||||
|
send_service_command(ServiceCommandFlag::lock_workstation,
|
||||||
|
"remote lock");
|
||||||
|
}
|
||||||
|
props->shortcut_selectable_hovered_ =
|
||||||
|
ImGui::IsWindowHovered(ImGuiHoveredFlags_RootAndChildWindows);
|
||||||
|
ImGui::SetWindowFontScale(1.0f);
|
||||||
|
ImGui::EndPopup();
|
||||||
|
}
|
||||||
|
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
float mouse_x = ImGui::GetCursorScreenPos().x;
|
float mouse_x = ImGui::GetCursorScreenPos().x;
|
||||||
float mouse_y = ImGui::GetCursorScreenPos().y;
|
float mouse_y = ImGui::GetCursorScreenPos().y;
|
||||||
@@ -486,4 +543,4 @@ int Render::NetTrafficStats(std::shared_ptr<SubStreamWindowProperties>& props) {
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
} // namespace crossdesk
|
} // namespace crossdesk
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ int Render::AboutWindow() {
|
|||||||
ImGui::SetCursorPosX(about_window_width * 0.1f);
|
ImGui::SetCursorPosX(about_window_width * 0.1f);
|
||||||
ImGui::Text("%s", text.c_str());
|
ImGui::Text("%s", text.c_str());
|
||||||
|
|
||||||
if (0) {
|
if (update_available_ && show_new_version_icon_in_menu_) {
|
||||||
std::string new_version_available =
|
std::string new_version_available =
|
||||||
localization::new_version_available[localization_language_index_] +
|
localization::new_version_available[localization_language_index_] +
|
||||||
": ";
|
": ";
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ int BitrateDisplay(int bitrate) {
|
|||||||
int Render::FileTransferWindow(
|
int Render::FileTransferWindow(
|
||||||
std::shared_ptr<SubStreamWindowProperties>& props) {
|
std::shared_ptr<SubStreamWindowProperties>& props) {
|
||||||
FileTransferState* state = props ? &props->file_transfer_ : &file_transfer_;
|
FileTransferState* state = props ? &props->file_transfer_ : &file_transfer_;
|
||||||
|
state->file_transfer_window_hovered_ = false;
|
||||||
|
|
||||||
// Only show window if there are files in transfer list or currently
|
// Only show window if there are files in transfer list or currently
|
||||||
// transferring
|
// transferring
|
||||||
@@ -72,8 +73,6 @@ int Render::FileTransferWindow(
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
|
|
||||||
// Position window at bottom-left of stream window
|
// Position window at bottom-left of stream window
|
||||||
// Adjust window size based on number of files
|
// Adjust window size based on number of files
|
||||||
float file_transfer_window_width = main_window_width_ * 0.6f;
|
float file_transfer_window_width = main_window_width_ * 0.6f;
|
||||||
@@ -82,15 +81,25 @@ int Render::FileTransferWindow(
|
|||||||
float pos_x = file_transfer_window_width * 0.05f;
|
float pos_x = file_transfer_window_width * 0.05f;
|
||||||
float pos_y = stream_window_height_ - file_transfer_window_height -
|
float pos_y = stream_window_height_ - file_transfer_window_height -
|
||||||
file_transfer_window_width * 0.05;
|
file_transfer_window_width * 0.05;
|
||||||
float same_line_width = file_transfer_window_width * 0.1f;
|
|
||||||
|
const ImVec2 mouse_pos = ImGui::GetMousePos();
|
||||||
|
const bool mouse_in_window_rect =
|
||||||
|
mouse_pos.x >= pos_x &&
|
||||||
|
mouse_pos.x <= pos_x + file_transfer_window_width &&
|
||||||
|
mouse_pos.y >= pos_y &&
|
||||||
|
mouse_pos.y <= pos_y + file_transfer_window_height;
|
||||||
|
|
||||||
ImGui::SetNextWindowPos(ImVec2(pos_x, pos_y), ImGuiCond_Always);
|
ImGui::SetNextWindowPos(ImVec2(pos_x, pos_y), ImGuiCond_Always);
|
||||||
ImGui::SetNextWindowSize(
|
ImGui::SetNextWindowSize(
|
||||||
ImVec2(file_transfer_window_width, file_transfer_window_height),
|
ImVec2(file_transfer_window_width, file_transfer_window_height),
|
||||||
ImGuiCond_Always);
|
ImGuiCond_Always);
|
||||||
|
if (mouse_in_window_rect) {
|
||||||
|
ImGui::SetNextWindowFocus();
|
||||||
|
}
|
||||||
|
|
||||||
// Set Chinese font for proper display
|
// Set Chinese font for proper display
|
||||||
if (stream_windows_system_chinese_font_) {
|
const bool has_chinese_font = stream_windows_system_chinese_font_ != nullptr;
|
||||||
|
if (has_chinese_font) {
|
||||||
ImGui::PushFont(stream_windows_system_chinese_font_);
|
ImGui::PushFont(stream_windows_system_chinese_font_);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,24 +112,27 @@ int Render::FileTransferWindow(
|
|||||||
|
|
||||||
ImGui::SetWindowFontScale(0.5f);
|
ImGui::SetWindowFontScale(0.5f);
|
||||||
bool window_opened = true;
|
bool window_opened = true;
|
||||||
if (ImGui::Begin(
|
const bool show_contents = ImGui::Begin(
|
||||||
localization::file_transfer_progress[localization_language_index_]
|
localization::file_transfer_progress[localization_language_index_]
|
||||||
.c_str(),
|
.c_str(),
|
||||||
&window_opened,
|
&window_opened,
|
||||||
ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize |
|
ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize |
|
||||||
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings |
|
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings |
|
||||||
ImGuiWindowFlags_NoScrollbar)) {
|
ImGuiWindowFlags_NoScrollbar);
|
||||||
|
ImGui::PopStyleColor(4);
|
||||||
|
ImGui::PopStyleVar(2);
|
||||||
|
|
||||||
|
state->file_transfer_window_hovered_ =
|
||||||
|
mouse_in_window_rect ||
|
||||||
|
ImGui::IsWindowHovered(ImGuiHoveredFlags_RootAndChildWindows);
|
||||||
|
|
||||||
|
if (!window_opened) {
|
||||||
|
state->file_transfer_window_visible_ = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (show_contents && window_opened) {
|
||||||
ImGui::SetWindowFontScale(1.0f);
|
ImGui::SetWindowFontScale(1.0f);
|
||||||
ImGui::SetWindowFontScale(0.5f);
|
ImGui::SetWindowFontScale(0.5f);
|
||||||
ImGui::PopStyleColor(4);
|
|
||||||
ImGui::PopStyleVar(2);
|
|
||||||
|
|
||||||
// Close button handling
|
|
||||||
if (!window_opened) {
|
|
||||||
state->file_transfer_window_visible_ = false;
|
|
||||||
ImGui::End();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Display file list
|
// Display file list
|
||||||
if (file_list.empty()) {
|
if (file_list.empty()) {
|
||||||
@@ -225,21 +237,16 @@ int Render::FileTransferWindow(
|
|||||||
}
|
}
|
||||||
ImGui::SetWindowFontScale(1.0f);
|
ImGui::SetWindowFontScale(1.0f);
|
||||||
ImGui::SetWindowFontScale(0.5f);
|
ImGui::SetWindowFontScale(0.5f);
|
||||||
ImGui::End();
|
|
||||||
ImGui::SetWindowFontScale(1.0f);
|
|
||||||
|
|
||||||
// Pop Chinese font if it was pushed
|
|
||||||
if (stream_windows_system_chinese_font_) {
|
|
||||||
ImGui::PopFont();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ImGui::PopStyleColor(4);
|
|
||||||
ImGui::PopStyleVar(2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ImGui::End();
|
||||||
ImGui::SetWindowFontScale(1.0f);
|
ImGui::SetWindowFontScale(1.0f);
|
||||||
|
|
||||||
|
if (has_chinese_font) {
|
||||||
|
ImGui::PopFont();
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace crossdesk
|
} // namespace crossdesk
|
||||||
|
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ int Render::UpdateNotificationWindow() {
|
|||||||
ImGui::SetWindowFontScale(0.55f);
|
ImGui::SetWindowFontScale(0.55f);
|
||||||
std::string title =
|
std::string title =
|
||||||
localization::new_version_available[localization_language_index_] +
|
localization::new_version_available[localization_language_index_] +
|
||||||
": v" + latest_version_;
|
": " + latest_version_;
|
||||||
ImGui::Text("%s", title.c_str());
|
ImGui::Text("%s", title.c_str());
|
||||||
ImGui::SetWindowFontScale(0.1f);
|
ImGui::SetWindowFontScale(0.1f);
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,98 @@
|
|||||||
#include "path_manager.h"
|
#include "path_manager.h"
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
#include <cstdlib>
|
#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 {
|
namespace crossdesk {
|
||||||
|
|
||||||
PathManager::PathManager(const std::string& app_name) : app_name_(app_name) {}
|
PathManager::PathManager(const std::string& app_name) : app_name_(app_name) {}
|
||||||
|
|
||||||
std::filesystem::path PathManager::GetConfigPath() {
|
std::filesystem::path PathManager::GetConfigPath() {
|
||||||
|
#if CROSSDESK_PORTABLE
|
||||||
|
return GetPortableRootPath() / "data";
|
||||||
|
#else
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
return GetKnownFolder(FOLDERID_RoamingAppData) / app_name_;
|
return GetKnownFolder(FOLDERID_RoamingAppData) / app_name_;
|
||||||
#elif __APPLE__
|
#elif __APPLE__
|
||||||
@@ -14,9 +100,13 @@ std::filesystem::path PathManager::GetConfigPath() {
|
|||||||
#else
|
#else
|
||||||
return GetEnvOrDefault("XDG_CONFIG_HOME", GetHome() + "/.config") / app_name_;
|
return GetEnvOrDefault("XDG_CONFIG_HOME", GetHome() + "/.config") / app_name_;
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
std::filesystem::path PathManager::GetCachePath() {
|
std::filesystem::path PathManager::GetCachePath() {
|
||||||
|
#if CROSSDESK_PORTABLE
|
||||||
|
return GetPortableRootPath() / "data";
|
||||||
|
#else
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#ifdef CROSSDESK_DEBUG
|
#ifdef CROSSDESK_DEBUG
|
||||||
return "cache";
|
return "cache";
|
||||||
@@ -28,9 +118,13 @@ std::filesystem::path PathManager::GetCachePath() {
|
|||||||
#else
|
#else
|
||||||
return GetEnvOrDefault("XDG_CACHE_HOME", GetHome() + "/.cache") / app_name_;
|
return GetEnvOrDefault("XDG_CACHE_HOME", GetHome() + "/.cache") / app_name_;
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
std::filesystem::path PathManager::GetLogPath() {
|
std::filesystem::path PathManager::GetLogPath() {
|
||||||
|
#if CROSSDESK_PORTABLE
|
||||||
|
return GetPortableRootPath() / "logs";
|
||||||
|
#else
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
return GetKnownFolder(FOLDERID_LocalAppData) / app_name_ / "logs";
|
return GetKnownFolder(FOLDERID_LocalAppData) / app_name_ / "logs";
|
||||||
#elif __APPLE__
|
#elif __APPLE__
|
||||||
@@ -38,6 +132,7 @@ std::filesystem::path PathManager::GetLogPath() {
|
|||||||
#else
|
#else
|
||||||
return GetCachePath() / "logs";
|
return GetCachePath() / "logs";
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PathManager::CreateDirectories(const std::filesystem::path& p) {
|
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);
|
return std::filesystem::path(def);
|
||||||
}
|
}
|
||||||
} // namespace crossdesk
|
} // namespace crossdesk
|
||||||
|
|||||||
@@ -57,6 +57,11 @@ int ScreenCapturerWayland::Init(const int fps, cb_desktop_data cb) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!EnsurePipeWireRuntimeAvailable()) {
|
||||||
|
LOG_ERROR("Wayland screen capturer requires PipeWire 0.3 runtime");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
fps_ = fps;
|
fps_ = fps;
|
||||||
callback_ = cb;
|
callback_ = cb;
|
||||||
pointer_granted_ = false;
|
pointer_granted_ = false;
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ class ScreenCapturerWayland : public ScreenCapturer {
|
|||||||
bool SelectPortalDevices();
|
bool SelectPortalDevices();
|
||||||
bool SelectPortalSource();
|
bool SelectPortalSource();
|
||||||
bool StartPortalSession();
|
bool StartPortalSession();
|
||||||
|
bool EnsurePipeWireRuntimeAvailable() const;
|
||||||
bool OpenPipeWireRemote();
|
bool OpenPipeWireRemote();
|
||||||
bool SetupPipeWireStream(bool relaxed_connect, PipeWireConnectMode mode);
|
bool SetupPipeWireStream(bool relaxed_connect, PipeWireConnectMode mode);
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#if CROSSDESK_WAYLAND_BUILD_ENABLED
|
#if CROSSDESK_WAYLAND_BUILD_ENABLED
|
||||||
|
|
||||||
|
#include <dlfcn.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
@@ -10,6 +11,7 @@
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
#include <mutex>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@@ -20,6 +22,143 @@ namespace crossdesk {
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
struct PipeWireDynamicApi {
|
||||||
|
void* library = nullptr;
|
||||||
|
bool available = false;
|
||||||
|
|
||||||
|
decltype(&::pw_init) init = nullptr;
|
||||||
|
decltype(&::pw_deinit) deinit = nullptr;
|
||||||
|
decltype(&::pw_thread_loop_new) thread_loop_new = nullptr;
|
||||||
|
decltype(&::pw_thread_loop_destroy) thread_loop_destroy = nullptr;
|
||||||
|
decltype(&::pw_thread_loop_get_loop) thread_loop_get_loop = nullptr;
|
||||||
|
decltype(&::pw_thread_loop_start) thread_loop_start = nullptr;
|
||||||
|
decltype(&::pw_thread_loop_stop) thread_loop_stop = nullptr;
|
||||||
|
decltype(&::pw_thread_loop_lock) thread_loop_lock = nullptr;
|
||||||
|
decltype(&::pw_thread_loop_unlock) thread_loop_unlock = nullptr;
|
||||||
|
decltype(&::pw_thread_loop_wait) thread_loop_wait = nullptr;
|
||||||
|
decltype(&::pw_thread_loop_signal) thread_loop_signal = nullptr;
|
||||||
|
decltype(&::pw_context_new) context_new = nullptr;
|
||||||
|
decltype(&::pw_context_destroy) context_destroy = nullptr;
|
||||||
|
decltype(&::pw_context_connect_fd) context_connect_fd = nullptr;
|
||||||
|
decltype(&::pw_properties_new) properties_new = nullptr;
|
||||||
|
decltype(&::pw_properties_set) properties_set = nullptr;
|
||||||
|
decltype(&::pw_stream_new) stream_new = nullptr;
|
||||||
|
decltype(&::pw_stream_add_listener) stream_add_listener = nullptr;
|
||||||
|
decltype(&::pw_stream_state_as_string) stream_state_as_string = nullptr;
|
||||||
|
decltype(&::pw_stream_connect) stream_connect = nullptr;
|
||||||
|
decltype(&::pw_stream_update_params) stream_update_params = nullptr;
|
||||||
|
decltype(&::pw_stream_set_active) stream_set_active = nullptr;
|
||||||
|
decltype(&::pw_stream_disconnect) stream_disconnect = nullptr;
|
||||||
|
decltype(&::pw_stream_destroy) stream_destroy = nullptr;
|
||||||
|
decltype(&::pw_stream_dequeue_buffer) stream_dequeue_buffer = nullptr;
|
||||||
|
decltype(&::pw_stream_queue_buffer) stream_queue_buffer = nullptr;
|
||||||
|
decltype(&::pw_core_disconnect) core_disconnect = nullptr;
|
||||||
|
decltype(&::pw_proxy_destroy) proxy_destroy = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
bool LoadPipeWireSymbol(void* library, T* function, const char* symbol_name) {
|
||||||
|
*function = reinterpret_cast<T>(dlsym(library, symbol_name));
|
||||||
|
if (*function != nullptr) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_ERROR("Unable to find PipeWire symbol {}", symbol_name);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UnloadPipeWireApi(PipeWireDynamicApi* api) {
|
||||||
|
if (api->library != nullptr) {
|
||||||
|
dlclose(api->library);
|
||||||
|
}
|
||||||
|
*api = PipeWireDynamicApi{};
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LoadPipeWireApi(PipeWireDynamicApi* api) {
|
||||||
|
static constexpr const char* kPipeWireLibraries[] = {
|
||||||
|
"libpipewire-0.3.so.0",
|
||||||
|
"libpipewire-0.3.so",
|
||||||
|
};
|
||||||
|
|
||||||
|
for (const char* library_name : kPipeWireLibraries) {
|
||||||
|
api->library = dlopen(library_name, RTLD_LAZY | RTLD_LOCAL);
|
||||||
|
if (api->library != nullptr) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (api->library == nullptr) {
|
||||||
|
LOG_WARN("PipeWire 0.3 runtime library is unavailable");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!LoadPipeWireSymbol(api->library, &api->init, "pw_init") ||
|
||||||
|
!LoadPipeWireSymbol(api->library, &api->deinit, "pw_deinit") ||
|
||||||
|
!LoadPipeWireSymbol(api->library, &api->thread_loop_new,
|
||||||
|
"pw_thread_loop_new") ||
|
||||||
|
!LoadPipeWireSymbol(api->library, &api->thread_loop_destroy,
|
||||||
|
"pw_thread_loop_destroy") ||
|
||||||
|
!LoadPipeWireSymbol(api->library, &api->thread_loop_get_loop,
|
||||||
|
"pw_thread_loop_get_loop") ||
|
||||||
|
!LoadPipeWireSymbol(api->library, &api->thread_loop_start,
|
||||||
|
"pw_thread_loop_start") ||
|
||||||
|
!LoadPipeWireSymbol(api->library, &api->thread_loop_stop,
|
||||||
|
"pw_thread_loop_stop") ||
|
||||||
|
!LoadPipeWireSymbol(api->library, &api->thread_loop_lock,
|
||||||
|
"pw_thread_loop_lock") ||
|
||||||
|
!LoadPipeWireSymbol(api->library, &api->thread_loop_unlock,
|
||||||
|
"pw_thread_loop_unlock") ||
|
||||||
|
!LoadPipeWireSymbol(api->library, &api->thread_loop_wait,
|
||||||
|
"pw_thread_loop_wait") ||
|
||||||
|
!LoadPipeWireSymbol(api->library, &api->thread_loop_signal,
|
||||||
|
"pw_thread_loop_signal") ||
|
||||||
|
!LoadPipeWireSymbol(api->library, &api->context_new, "pw_context_new") ||
|
||||||
|
!LoadPipeWireSymbol(api->library, &api->context_destroy,
|
||||||
|
"pw_context_destroy") ||
|
||||||
|
!LoadPipeWireSymbol(api->library, &api->context_connect_fd,
|
||||||
|
"pw_context_connect_fd") ||
|
||||||
|
!LoadPipeWireSymbol(api->library, &api->properties_new,
|
||||||
|
"pw_properties_new") ||
|
||||||
|
!LoadPipeWireSymbol(api->library, &api->properties_set,
|
||||||
|
"pw_properties_set") ||
|
||||||
|
!LoadPipeWireSymbol(api->library, &api->stream_new, "pw_stream_new") ||
|
||||||
|
!LoadPipeWireSymbol(api->library, &api->stream_add_listener,
|
||||||
|
"pw_stream_add_listener") ||
|
||||||
|
!LoadPipeWireSymbol(api->library, &api->stream_state_as_string,
|
||||||
|
"pw_stream_state_as_string") ||
|
||||||
|
!LoadPipeWireSymbol(api->library, &api->stream_connect,
|
||||||
|
"pw_stream_connect") ||
|
||||||
|
!LoadPipeWireSymbol(api->library, &api->stream_update_params,
|
||||||
|
"pw_stream_update_params") ||
|
||||||
|
!LoadPipeWireSymbol(api->library, &api->stream_set_active,
|
||||||
|
"pw_stream_set_active") ||
|
||||||
|
!LoadPipeWireSymbol(api->library, &api->stream_disconnect,
|
||||||
|
"pw_stream_disconnect") ||
|
||||||
|
!LoadPipeWireSymbol(api->library, &api->stream_destroy,
|
||||||
|
"pw_stream_destroy") ||
|
||||||
|
!LoadPipeWireSymbol(api->library, &api->stream_dequeue_buffer,
|
||||||
|
"pw_stream_dequeue_buffer") ||
|
||||||
|
!LoadPipeWireSymbol(api->library, &api->stream_queue_buffer,
|
||||||
|
"pw_stream_queue_buffer") ||
|
||||||
|
!LoadPipeWireSymbol(api->library, &api->core_disconnect,
|
||||||
|
"pw_core_disconnect") ||
|
||||||
|
!LoadPipeWireSymbol(api->library, &api->proxy_destroy,
|
||||||
|
"pw_proxy_destroy")) {
|
||||||
|
UnloadPipeWireApi(api);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
api->available = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const PipeWireDynamicApi* GetPipeWireApi() {
|
||||||
|
static PipeWireDynamicApi api;
|
||||||
|
static std::once_flag once;
|
||||||
|
std::call_once(once, []() { LoadPipeWireApi(&api); });
|
||||||
|
return api.available ? &api : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
const char* PipeWireFormatName(uint32_t spa_format) {
|
const char* PipeWireFormatName(uint32_t spa_format) {
|
||||||
switch (spa_format) {
|
switch (spa_format) {
|
||||||
case SPA_VIDEO_FORMAT_BGRx:
|
case SPA_VIDEO_FORMAT_BGRx:
|
||||||
@@ -76,6 +215,7 @@ double SnapLikelyFractionalScale(double observed_scale) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct PipeWireTargetLookupState {
|
struct PipeWireTargetLookupState {
|
||||||
|
const PipeWireDynamicApi* pipewire = nullptr;
|
||||||
pw_thread_loop* loop = nullptr;
|
pw_thread_loop* loop = nullptr;
|
||||||
uint32_t target_node_id = 0;
|
uint32_t target_node_id = 0;
|
||||||
int sync_seq = -1;
|
int sync_seq = -1;
|
||||||
@@ -87,11 +227,13 @@ struct PipeWireTargetLookupState {
|
|||||||
std::string LookupPipeWireTargetObjectSerial(pw_core* core,
|
std::string LookupPipeWireTargetObjectSerial(pw_core* core,
|
||||||
pw_thread_loop* loop,
|
pw_thread_loop* loop,
|
||||||
uint32_t node_id) {
|
uint32_t node_id) {
|
||||||
if (!core || !loop || node_id == 0) {
|
const PipeWireDynamicApi* pipewire = GetPipeWireApi();
|
||||||
|
if (!pipewire || !core || !loop || node_id == 0) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
PipeWireTargetLookupState state;
|
PipeWireTargetLookupState state;
|
||||||
|
state.pipewire = pipewire;
|
||||||
state.loop = loop;
|
state.loop = loop;
|
||||||
state.target_node_id = node_id;
|
state.target_node_id = node_id;
|
||||||
|
|
||||||
@@ -138,7 +280,7 @@ std::string LookupPipeWireTargetObjectSerial(pw_core* core,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
state->done = true;
|
state->done = true;
|
||||||
pw_thread_loop_signal(state->loop, false);
|
state->pipewire->thread_loop_signal(state->loop, false);
|
||||||
};
|
};
|
||||||
core_events.error = [](void* userdata, uint32_t id, int seq, int res,
|
core_events.error = [](void* userdata, uint32_t id, int seq, int res,
|
||||||
const char* message) {
|
const char* message) {
|
||||||
@@ -152,7 +294,7 @@ std::string LookupPipeWireTargetObjectSerial(pw_core* core,
|
|||||||
LOG_WARN("PipeWire registry lookup error: {}",
|
LOG_WARN("PipeWire registry lookup error: {}",
|
||||||
message ? message : "unknown");
|
message ? message : "unknown");
|
||||||
state->done = true;
|
state->done = true;
|
||||||
pw_thread_loop_signal(state->loop, false);
|
state->pipewire->thread_loop_signal(state->loop, false);
|
||||||
};
|
};
|
||||||
|
|
||||||
pw_registry_add_listener(registry, ®istry_listener, ®istry_events,
|
pw_registry_add_listener(registry, ®istry_listener, ®istry_events,
|
||||||
@@ -161,12 +303,12 @@ std::string LookupPipeWireTargetObjectSerial(pw_core* core,
|
|||||||
state.sync_seq = pw_core_sync(core, PW_ID_CORE, 0);
|
state.sync_seq = pw_core_sync(core, PW_ID_CORE, 0);
|
||||||
|
|
||||||
while (!state.done) {
|
while (!state.done) {
|
||||||
pw_thread_loop_wait(loop);
|
pipewire->thread_loop_wait(loop);
|
||||||
}
|
}
|
||||||
|
|
||||||
spa_hook_remove(®istry_listener);
|
spa_hook_remove(®istry_listener);
|
||||||
spa_hook_remove(&core_listener);
|
spa_hook_remove(&core_listener);
|
||||||
pw_proxy_destroy(reinterpret_cast<pw_proxy*>(registry));
|
pipewire->proxy_destroy(reinterpret_cast<pw_proxy*>(registry));
|
||||||
return state.found ? state.object_serial : "";
|
return state.found ? state.object_serial : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,56 +330,68 @@ int BytesPerPixel(uint32_t spa_format) {
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
bool ScreenCapturerWayland::EnsurePipeWireRuntimeAvailable() const {
|
||||||
|
return GetPipeWireApi() != nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
bool ScreenCapturerWayland::SetupPipeWireStream(bool relaxed_connect,
|
bool ScreenCapturerWayland::SetupPipeWireStream(bool relaxed_connect,
|
||||||
PipeWireConnectMode mode) {
|
PipeWireConnectMode mode) {
|
||||||
|
const PipeWireDynamicApi* pipewire = GetPipeWireApi();
|
||||||
|
if (!pipewire) {
|
||||||
|
LOG_ERROR("PipeWire 0.3 runtime library is unavailable");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (pipewire_fd_ < 0 || pipewire_node_id_ == 0) {
|
if (pipewire_fd_ < 0 || pipewire_node_id_ == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pipewire_initialized_) {
|
if (!pipewire_initialized_) {
|
||||||
pw_init(nullptr, nullptr);
|
pipewire->init(nullptr, nullptr);
|
||||||
pipewire_initialized_ = true;
|
pipewire_initialized_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
pw_thread_loop_ = pw_thread_loop_new("crossdesk-wayland-capture", nullptr);
|
pw_thread_loop_ =
|
||||||
|
pipewire->thread_loop_new("crossdesk-wayland-capture", nullptr);
|
||||||
if (!pw_thread_loop_) {
|
if (!pw_thread_loop_) {
|
||||||
LOG_ERROR("Failed to create PipeWire thread loop");
|
LOG_ERROR("Failed to create PipeWire thread loop");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pw_thread_loop_start(pw_thread_loop_) < 0) {
|
if (pipewire->thread_loop_start(pw_thread_loop_) < 0) {
|
||||||
LOG_ERROR("Failed to start PipeWire thread loop");
|
LOG_ERROR("Failed to start PipeWire thread loop");
|
||||||
CleanupPipeWire();
|
CleanupPipeWire();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
pipewire_thread_loop_started_ = true;
|
pipewire_thread_loop_started_ = true;
|
||||||
|
|
||||||
pw_thread_loop_lock(pw_thread_loop_);
|
pipewire->thread_loop_lock(pw_thread_loop_);
|
||||||
|
|
||||||
pw_context_ =
|
pw_context_ = pipewire->context_new(
|
||||||
pw_context_new(pw_thread_loop_get_loop(pw_thread_loop_), nullptr, 0);
|
pipewire->thread_loop_get_loop(pw_thread_loop_), nullptr, 0);
|
||||||
if (!pw_context_) {
|
if (!pw_context_) {
|
||||||
LOG_ERROR("Failed to create PipeWire context");
|
LOG_ERROR("Failed to create PipeWire context");
|
||||||
pw_thread_loop_unlock(pw_thread_loop_);
|
pipewire->thread_loop_unlock(pw_thread_loop_);
|
||||||
CleanupPipeWire();
|
CleanupPipeWire();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
pw_core_ = pw_context_connect_fd(pw_context_, pipewire_fd_, nullptr, 0);
|
pw_core_ =
|
||||||
|
pipewire->context_connect_fd(pw_context_, pipewire_fd_, nullptr, 0);
|
||||||
if (!pw_core_) {
|
if (!pw_core_) {
|
||||||
LOG_ERROR("Failed to connect to PipeWire remote");
|
LOG_ERROR("Failed to connect to PipeWire remote");
|
||||||
pw_thread_loop_unlock(pw_thread_loop_);
|
pipewire->thread_loop_unlock(pw_thread_loop_);
|
||||||
CleanupPipeWire();
|
CleanupPipeWire();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
pipewire_fd_ = -1;
|
pipewire_fd_ = -1;
|
||||||
|
|
||||||
pw_properties* stream_props =
|
pw_properties* stream_props = pipewire->properties_new(
|
||||||
pw_properties_new(PW_KEY_MEDIA_TYPE, "Video", PW_KEY_MEDIA_CATEGORY,
|
PW_KEY_MEDIA_TYPE, "Video", PW_KEY_MEDIA_CATEGORY, "Capture",
|
||||||
"Capture", PW_KEY_MEDIA_ROLE, "Screen", nullptr);
|
PW_KEY_MEDIA_ROLE, "Screen", nullptr);
|
||||||
if (!stream_props) {
|
if (!stream_props) {
|
||||||
LOG_ERROR("Failed to allocate PipeWire stream properties");
|
LOG_ERROR("Failed to allocate PipeWire stream properties");
|
||||||
pw_thread_loop_unlock(pw_thread_loop_);
|
pipewire->thread_loop_unlock(pw_thread_loop_);
|
||||||
CleanupPipeWire();
|
CleanupPipeWire();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -247,8 +401,8 @@ bool ScreenCapturerWayland::SetupPipeWireStream(bool relaxed_connect,
|
|||||||
target_object_serial = LookupPipeWireTargetObjectSerial(
|
target_object_serial = LookupPipeWireTargetObjectSerial(
|
||||||
pw_core_, pw_thread_loop_, pipewire_node_id_);
|
pw_core_, pw_thread_loop_, pipewire_node_id_);
|
||||||
if (!target_object_serial.empty()) {
|
if (!target_object_serial.empty()) {
|
||||||
pw_properties_set(stream_props, PW_KEY_TARGET_OBJECT,
|
pipewire->properties_set(stream_props, PW_KEY_TARGET_OBJECT,
|
||||||
target_object_serial.c_str());
|
target_object_serial.c_str());
|
||||||
LOG_INFO("PipeWire target object serial for node {} is {}",
|
LOG_INFO("PipeWire target object serial for node {} is {}",
|
||||||
pipewire_node_id_, target_object_serial);
|
pipewire_node_id_, target_object_serial);
|
||||||
} else {
|
} else {
|
||||||
@@ -260,10 +414,10 @@ bool ScreenCapturerWayland::SetupPipeWireStream(bool relaxed_connect,
|
|||||||
}
|
}
|
||||||
|
|
||||||
pw_stream_ =
|
pw_stream_ =
|
||||||
pw_stream_new(pw_core_, "CrossDesk Wayland Capture", stream_props);
|
pipewire->stream_new(pw_core_, "CrossDesk Wayland Capture", stream_props);
|
||||||
if (!pw_stream_) {
|
if (!pw_stream_) {
|
||||||
LOG_ERROR("Failed to create PipeWire stream");
|
LOG_ERROR("Failed to create PipeWire stream");
|
||||||
pw_thread_loop_unlock(pw_thread_loop_);
|
pipewire->thread_loop_unlock(pw_thread_loop_);
|
||||||
CleanupPipeWire();
|
CleanupPipeWire();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -289,9 +443,11 @@ bool ScreenCapturerWayland::SetupPipeWireStream(bool relaxed_connect,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_INFO("PipeWire stream state: {} -> {}",
|
const PipeWireDynamicApi* pipewire = GetPipeWireApi();
|
||||||
pw_stream_state_as_string(old_state),
|
LOG_INFO(
|
||||||
pw_stream_state_as_string(state));
|
"PipeWire stream state: {} -> {}",
|
||||||
|
pipewire ? pipewire->stream_state_as_string(old_state) : "unknown",
|
||||||
|
pipewire ? pipewire->stream_state_as_string(state) : "unknown");
|
||||||
};
|
};
|
||||||
events.param_changed = [](void* userdata, uint32_t id,
|
events.param_changed = [](void* userdata, uint32_t id,
|
||||||
const struct spa_pod* param) {
|
const struct spa_pod* param) {
|
||||||
@@ -369,7 +525,10 @@ bool ScreenCapturerWayland::SetupPipeWireStream(bool relaxed_connect,
|
|||||||
SPA_POD_Int(sizeof(struct spa_meta_header))));
|
SPA_POD_Int(sizeof(struct spa_meta_header))));
|
||||||
|
|
||||||
if (self->pw_stream_) {
|
if (self->pw_stream_) {
|
||||||
pw_stream_update_params(self->pw_stream_, params, param_count);
|
const PipeWireDynamicApi* pipewire = GetPipeWireApi();
|
||||||
|
if (pipewire) {
|
||||||
|
pipewire->stream_update_params(self->pw_stream_, params, param_count);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
self->pipewire_format_ready_.store(true);
|
self->pipewire_format_ready_.store(true);
|
||||||
|
|
||||||
@@ -457,7 +616,7 @@ bool ScreenCapturerWayland::SetupPipeWireStream(bool relaxed_connect,
|
|||||||
return events;
|
return events;
|
||||||
}();
|
}();
|
||||||
|
|
||||||
pw_stream_add_listener(pw_stream_, listener, &stream_events, this);
|
pipewire->stream_add_listener(pw_stream_, listener, &stream_events, this);
|
||||||
pipewire_format_ready_.store(false);
|
pipewire_format_ready_.store(false);
|
||||||
pipewire_stream_start_ms_.store(NowMs());
|
pipewire_stream_start_ms_.store(NowMs());
|
||||||
pipewire_last_frame_ms_.store(0);
|
pipewire_last_frame_ms_.store(0);
|
||||||
@@ -501,7 +660,7 @@ bool ScreenCapturerWayland::SetupPipeWireStream(bool relaxed_connect,
|
|||||||
|
|
||||||
if (param_count == 0) {
|
if (param_count == 0) {
|
||||||
LOG_ERROR("No valid PipeWire format params were built");
|
LOG_ERROR("No valid PipeWire format params were built");
|
||||||
pw_thread_loop_unlock(pw_thread_loop_);
|
pipewire->thread_loop_unlock(pw_thread_loop_);
|
||||||
CleanupPipeWire();
|
CleanupPipeWire();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -522,12 +681,12 @@ bool ScreenCapturerWayland::SetupPipeWireStream(bool relaxed_connect,
|
|||||||
PipeWireConnectModeName(mode), pipewire_node_id_, target_id,
|
PipeWireConnectModeName(mode), pipewire_node_id_, target_id,
|
||||||
target_object_serial.empty() ? "none" : target_object_serial.c_str(),
|
target_object_serial.empty() ? "none" : target_object_serial.c_str(),
|
||||||
relaxed_connect, param_count, fixed_size.width, fixed_size.height);
|
relaxed_connect, param_count, fixed_size.width, fixed_size.height);
|
||||||
const int ret = pw_stream_connect(
|
const int ret = pipewire->stream_connect(
|
||||||
pw_stream_, PW_DIRECTION_INPUT, target_id,
|
pw_stream_, PW_DIRECTION_INPUT, target_id,
|
||||||
static_cast<pw_stream_flags>(PW_STREAM_FLAG_AUTOCONNECT |
|
static_cast<pw_stream_flags>(PW_STREAM_FLAG_AUTOCONNECT |
|
||||||
PW_STREAM_FLAG_MAP_BUFFERS),
|
PW_STREAM_FLAG_MAP_BUFFERS),
|
||||||
param_count > 0 ? params : nullptr, static_cast<uint32_t>(param_count));
|
param_count > 0 ? params : nullptr, static_cast<uint32_t>(param_count));
|
||||||
pw_thread_loop_unlock(pw_thread_loop_);
|
pipewire->thread_loop_unlock(pw_thread_loop_);
|
||||||
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
LOG_ERROR("pw_stream_connect failed: {}", spa_strerror(ret));
|
LOG_ERROR("pw_stream_connect failed: {}", spa_strerror(ret));
|
||||||
@@ -539,16 +698,17 @@ bool ScreenCapturerWayland::SetupPipeWireStream(bool relaxed_connect,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ScreenCapturerWayland::CleanupPipeWire() {
|
void ScreenCapturerWayland::CleanupPipeWire() {
|
||||||
|
const PipeWireDynamicApi* pipewire = GetPipeWireApi();
|
||||||
const bool need_lock =
|
const bool need_lock =
|
||||||
pw_thread_loop_ &&
|
pipewire && pw_thread_loop_ &&
|
||||||
(pw_stream_ != nullptr || pw_core_ != nullptr || pw_context_ != nullptr);
|
(pw_stream_ != nullptr || pw_core_ != nullptr || pw_context_ != nullptr);
|
||||||
if (need_lock) {
|
if (need_lock) {
|
||||||
pw_thread_loop_lock(pw_thread_loop_);
|
pipewire->thread_loop_lock(pw_thread_loop_);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pw_stream_) {
|
if (pw_stream_ && pipewire) {
|
||||||
pw_stream_set_active(pw_stream_, false);
|
pipewire->stream_set_active(pw_stream_, false);
|
||||||
pw_stream_disconnect(pw_stream_);
|
pipewire->stream_disconnect(pw_stream_);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stream_listener_) {
|
if (stream_listener_) {
|
||||||
@@ -557,33 +717,34 @@ void ScreenCapturerWayland::CleanupPipeWire() {
|
|||||||
stream_listener_ = nullptr;
|
stream_listener_ = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pw_stream_) {
|
if (pw_stream_ && pipewire) {
|
||||||
pw_stream_destroy(pw_stream_);
|
pipewire->stream_destroy(pw_stream_);
|
||||||
pw_stream_ = nullptr;
|
|
||||||
}
|
}
|
||||||
|
pw_stream_ = nullptr;
|
||||||
|
|
||||||
if (pw_core_) {
|
if (pw_core_ && pipewire) {
|
||||||
pw_core_disconnect(pw_core_);
|
pipewire->core_disconnect(pw_core_);
|
||||||
pw_core_ = nullptr;
|
|
||||||
}
|
}
|
||||||
|
pw_core_ = nullptr;
|
||||||
|
|
||||||
if (pw_context_) {
|
if (pw_context_ && pipewire) {
|
||||||
pw_context_destroy(pw_context_);
|
pipewire->context_destroy(pw_context_);
|
||||||
pw_context_ = nullptr;
|
|
||||||
}
|
}
|
||||||
|
pw_context_ = nullptr;
|
||||||
|
|
||||||
if (need_lock) {
|
if (need_lock) {
|
||||||
pw_thread_loop_unlock(pw_thread_loop_);
|
pipewire->thread_loop_unlock(pw_thread_loop_);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pw_thread_loop_) {
|
if (pw_thread_loop_ && pipewire) {
|
||||||
if (pipewire_thread_loop_started_) {
|
if (pipewire_thread_loop_started_) {
|
||||||
pw_thread_loop_stop(pw_thread_loop_);
|
pipewire->thread_loop_stop(pw_thread_loop_);
|
||||||
pipewire_thread_loop_started_ = false;
|
pipewire_thread_loop_started_ = false;
|
||||||
}
|
}
|
||||||
pw_thread_loop_destroy(pw_thread_loop_);
|
pipewire->thread_loop_destroy(pw_thread_loop_);
|
||||||
pw_thread_loop_ = nullptr;
|
|
||||||
}
|
}
|
||||||
|
pw_thread_loop_ = nullptr;
|
||||||
|
pipewire_thread_loop_started_ = false;
|
||||||
|
|
||||||
if (pipewire_fd_ >= 0) {
|
if (pipewire_fd_ >= 0) {
|
||||||
close(pipewire_fd_);
|
close(pipewire_fd_);
|
||||||
@@ -594,23 +755,24 @@ void ScreenCapturerWayland::CleanupPipeWire() {
|
|||||||
pipewire_stream_start_ms_.store(0);
|
pipewire_stream_start_ms_.store(0);
|
||||||
pipewire_last_frame_ms_.store(0);
|
pipewire_last_frame_ms_.store(0);
|
||||||
|
|
||||||
if (pipewire_initialized_) {
|
if (pipewire_initialized_ && pipewire) {
|
||||||
pw_deinit();
|
pipewire->deinit();
|
||||||
pipewire_initialized_ = false;
|
|
||||||
}
|
}
|
||||||
|
pipewire_initialized_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenCapturerWayland::HandlePipeWireBuffer() {
|
void ScreenCapturerWayland::HandlePipeWireBuffer() {
|
||||||
if (!pw_stream_) {
|
const PipeWireDynamicApi* pipewire = GetPipeWireApi();
|
||||||
|
if (!pw_stream_ || !pipewire) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pw_buffer* buffer = pw_stream_dequeue_buffer(pw_stream_);
|
pw_buffer* buffer = pipewire->stream_dequeue_buffer(pw_stream_);
|
||||||
if (!buffer) {
|
if (!buffer) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto requeue = [&]() { pw_stream_queue_buffer(pw_stream_, buffer); };
|
auto requeue = [&]() { pipewire->stream_queue_buffer(pw_stream_, buffer); };
|
||||||
|
|
||||||
if (paused_) {
|
if (paused_) {
|
||||||
requeue();
|
requeue();
|
||||||
|
|||||||
@@ -46,6 +46,13 @@ struct InputDesktopInfo {
|
|||||||
std::string name;
|
std::string name;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct SecureDesktopMouseRequest {
|
||||||
|
int x = 0;
|
||||||
|
int y = 0;
|
||||||
|
int wheel = 0;
|
||||||
|
int flag = 0;
|
||||||
|
};
|
||||||
|
|
||||||
struct ScopedEnvironmentBlock {
|
struct ScopedEnvironmentBlock {
|
||||||
~ScopedEnvironmentBlock() {
|
~ScopedEnvironmentBlock() {
|
||||||
if (environment != nullptr) {
|
if (environment != nullptr) {
|
||||||
@@ -313,10 +320,12 @@ std::string QueryNamedPipeMessage(const std::wstring& pipe_name,
|
|||||||
return std::string(buffer, buffer + bytes_read);
|
return std::string(buffer, buffer + bytes_read);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string BuildSecureDesktopKeyboardIpcCommand(int key_code, bool is_down) {
|
std::string BuildSecureDesktopKeyboardIpcCommand(int key_code, bool is_down,
|
||||||
|
uint32_t scan_code,
|
||||||
|
bool extended) {
|
||||||
std::ostringstream stream;
|
std::ostringstream stream;
|
||||||
stream << kSecureDesktopKeyboardIpcCommandPrefix << key_code << ":"
|
stream << kSecureDesktopKeyboardIpcCommandPrefix << key_code << ":"
|
||||||
<< (is_down ? 1 : 0);
|
<< (is_down ? 1 : 0) << ":" << scan_code << ":" << (extended ? 1 : 0);
|
||||||
return stream.str();
|
return stream.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -328,20 +337,35 @@ std::string BuildSecureDesktopMouseIpcCommand(int x, int y, int wheel,
|
|||||||
return stream.str();
|
return stream.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string BuildSecureInputHelperKeyboardCommand(int key_code, bool is_down) {
|
std::string BuildSecureInputHelperKeyboardCommand(int key_code, bool is_down,
|
||||||
|
uint32_t scan_code,
|
||||||
|
bool extended) {
|
||||||
std::ostringstream stream;
|
std::ostringstream stream;
|
||||||
stream << kCrossDeskSecureInputKeyboardCommandPrefix << key_code << ":"
|
stream << kCrossDeskSecureInputKeyboardCommandPrefix << key_code << ":"
|
||||||
<< (is_down ? 1 : 0);
|
<< (is_down ? 1 : 0) << ":" << scan_code << ":" << (extended ? 1 : 0);
|
||||||
|
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();
|
return stream.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ParseSecureDesktopKeyboardIpcCommand(const std::string& command,
|
bool ParseSecureDesktopKeyboardIpcCommand(const std::string& command,
|
||||||
int* key_code_out,
|
int* key_code_out, bool* is_down_out,
|
||||||
bool* is_down_out) {
|
uint32_t* scan_code_out,
|
||||||
if (key_code_out == nullptr || is_down_out == nullptr) {
|
bool* extended_out) {
|
||||||
|
if (key_code_out == nullptr || is_down_out == nullptr ||
|
||||||
|
scan_code_out == nullptr || extended_out == nullptr) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*scan_code_out = 0;
|
||||||
|
*extended_out = false;
|
||||||
|
|
||||||
if (command.rfind(kSecureDesktopKeyboardIpcCommandPrefix, 0) != 0) {
|
if (command.rfind(kSecureDesktopKeyboardIpcCommandPrefix, 0) != 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -358,18 +382,102 @@ bool ParseSecureDesktopKeyboardIpcCommand(const std::string& command,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string state = command.substr(separator + 1);
|
const size_t scan_separator = command.find(':', separator + 1);
|
||||||
|
const std::string state =
|
||||||
|
scan_separator == std::string::npos
|
||||||
|
? command.substr(separator + 1)
|
||||||
|
: command.substr(separator + 1, scan_separator - separator - 1);
|
||||||
if (state == "1" || state == "down") {
|
if (state == "1" || state == "down") {
|
||||||
*is_down_out = true;
|
*is_down_out = true;
|
||||||
|
} else if (state == "0" || state == "up") {
|
||||||
|
*is_down_out = false;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (scan_separator == std::string::npos) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (state == "0" || state == "up") {
|
|
||||||
*is_down_out = false;
|
const size_t extended_separator = command.find(':', scan_separator + 1);
|
||||||
|
const std::string scan_code_str =
|
||||||
|
extended_separator == std::string::npos
|
||||||
|
? command.substr(scan_separator + 1)
|
||||||
|
: command.substr(scan_separator + 1,
|
||||||
|
extended_separator - scan_separator - 1);
|
||||||
|
try {
|
||||||
|
*scan_code_out = static_cast<uint32_t>(std::stoul(scan_code_str));
|
||||||
|
} catch (...) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (extended_separator == std::string::npos) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string extended_str = command.substr(extended_separator + 1);
|
||||||
|
if (extended_str == "1" || extended_str == "true") {
|
||||||
|
*extended_out = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (extended_str == "0" || extended_str == "false") {
|
||||||
|
*extended_out = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
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,
|
bool CreateSessionSystemToken(DWORD session_id, HANDLE* token_out,
|
||||||
DWORD* error_code_out = nullptr) {
|
DWORD* error_code_out = nullptr) {
|
||||||
if (token_out == nullptr) {
|
if (token_out == nullptr) {
|
||||||
@@ -1712,8 +1820,18 @@ std::string CrossDeskServiceHost::HandleIpcCommand(const std::string& command) {
|
|||||||
}
|
}
|
||||||
int key_code = 0;
|
int key_code = 0;
|
||||||
bool is_down = false;
|
bool is_down = false;
|
||||||
if (ParseSecureDesktopKeyboardIpcCommand(normalized, &key_code, &is_down)) {
|
uint32_t scan_code = 0;
|
||||||
return SendSecureDesktopKeyboardInput(key_code, is_down);
|
bool extended = false;
|
||||||
|
if (ParseSecureDesktopKeyboardIpcCommand(normalized, &key_code, &is_down,
|
||||||
|
&scan_code, &extended)) {
|
||||||
|
return SendSecureDesktopKeyboardInput(key_code, is_down, scan_code,
|
||||||
|
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");
|
return BuildErrorJson("unknown_command");
|
||||||
}
|
}
|
||||||
@@ -1928,8 +2046,8 @@ std::string CrossDeskServiceHost::SendSecureAttentionSequence() {
|
|||||||
return "{\"ok\":true,\"sent\":\"sas\"}";
|
return "{\"ok\":true,\"sent\":\"sas\"}";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string CrossDeskServiceHost::SendSecureDesktopKeyboardInput(int key_code,
|
std::string CrossDeskServiceHost::SendSecureDesktopKeyboardInput(
|
||||||
bool is_down) {
|
int key_code, bool is_down, uint32_t scan_code, bool extended) {
|
||||||
RefreshSessionState();
|
RefreshSessionState();
|
||||||
ReapSecureInputHelper();
|
ReapSecureInputHelper();
|
||||||
EnsureSessionHelper();
|
EnsureSessionHelper();
|
||||||
@@ -1963,7 +2081,48 @@ std::string CrossDeskServiceHost::SendSecureDesktopKeyboardInput(int key_code,
|
|||||||
|
|
||||||
return QueryNamedPipeMessage(
|
return QueryNamedPipeMessage(
|
||||||
GetCrossDeskSecureInputHelperPipeName(target_session_id),
|
GetCrossDeskSecureInputHelperPipeName(target_session_id),
|
||||||
BuildSecureInputHelperKeyboardCommand(key_code, is_down), 1000);
|
BuildSecureInputHelperKeyboardCommand(key_code, is_down, scan_code,
|
||||||
|
extended),
|
||||||
|
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) {
|
bool InstallCrossDeskService(const std::wstring& binary_path) {
|
||||||
@@ -2176,9 +2335,12 @@ std::string QueryCrossDeskService(const std::string& command,
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string SendCrossDeskSecureDesktopKeyInput(int key_code, bool is_down,
|
std::string SendCrossDeskSecureDesktopKeyInput(int key_code, bool is_down,
|
||||||
|
uint32_t scan_code,
|
||||||
|
bool extended,
|
||||||
DWORD timeout_ms) {
|
DWORD timeout_ms) {
|
||||||
return QueryCrossDeskService(
|
return QueryCrossDeskService(BuildSecureDesktopKeyboardIpcCommand(
|
||||||
BuildSecureDesktopKeyboardIpcCommand(key_code, is_down), timeout_ms);
|
key_code, is_down, scan_code, extended),
|
||||||
|
timeout_ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string SendCrossDeskSecureDesktopMouseInput(int x, int y, int wheel,
|
std::string SendCrossDeskSecureDesktopMouseInput(int x, int y, int wheel,
|
||||||
@@ -2187,4 +2349,4 @@ std::string SendCrossDeskSecureDesktopMouseInput(int x, int y, int wheel,
|
|||||||
BuildSecureDesktopMouseIpcCommand(x, y, wheel, flag), timeout_ms);
|
BuildSecureDesktopMouseIpcCommand(x, y, wheel, flag), timeout_ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace crossdesk
|
} // namespace crossdesk
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
@@ -60,7 +61,10 @@ class CrossDeskServiceHost {
|
|||||||
std::string HandleIpcCommand(const std::string& command);
|
std::string HandleIpcCommand(const std::string& command);
|
||||||
std::string BuildStatusResponse();
|
std::string BuildStatusResponse();
|
||||||
std::string SendSecureAttentionSequence();
|
std::string SendSecureAttentionSequence();
|
||||||
std::string SendSecureDesktopKeyboardInput(int key_code, bool is_down);
|
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 void WINAPI ServiceMain(DWORD argc, LPWSTR* argv);
|
||||||
static BOOL WINAPI ConsoleControlHandler(DWORD control_type);
|
static BOOL WINAPI ConsoleControlHandler(DWORD control_type);
|
||||||
@@ -138,6 +142,8 @@ bool StopCrossDeskService(DWORD timeout_ms = 5000);
|
|||||||
std::string QueryCrossDeskService(const std::string& command,
|
std::string QueryCrossDeskService(const std::string& command,
|
||||||
DWORD timeout_ms = 1000);
|
DWORD timeout_ms = 1000);
|
||||||
std::string SendCrossDeskSecureDesktopKeyInput(int key_code, bool is_down,
|
std::string SendCrossDeskSecureDesktopKeyInput(int key_code, bool is_down,
|
||||||
|
uint32_t scan_code = 0,
|
||||||
|
bool extended = false,
|
||||||
DWORD timeout_ms = 1000);
|
DWORD timeout_ms = 1000);
|
||||||
std::string SendCrossDeskSecureDesktopMouseInput(int x, int y, int wheel,
|
std::string SendCrossDeskSecureDesktopMouseInput(int x, int y, int wheel,
|
||||||
int flag,
|
int flag,
|
||||||
@@ -145,4 +151,4 @@ std::string SendCrossDeskSecureDesktopMouseInput(int x, int y, int wheel,
|
|||||||
|
|
||||||
} // namespace crossdesk
|
} // namespace crossdesk
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -485,20 +485,56 @@ bool EnsureThreadDesktop(const wchar_t* desktop_name,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int InjectKeyboardInput(int key_code, bool is_down) {
|
bool PreferSideSpecificVkInjection(int key_code) {
|
||||||
|
switch (key_code) {
|
||||||
|
case VK_LSHIFT:
|
||||||
|
case VK_RSHIFT:
|
||||||
|
case VK_LCONTROL:
|
||||||
|
case VK_RCONTROL:
|
||||||
|
case VK_LMENU:
|
||||||
|
case VK_RMENU:
|
||||||
|
case VK_LWIN:
|
||||||
|
case VK_RWIN:
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int InjectKeyboardInput(int key_code, bool is_down, uint32_t scan_code,
|
||||||
|
bool extended) {
|
||||||
INPUT input = {0};
|
INPUT input = {0};
|
||||||
input.type = INPUT_KEYBOARD;
|
input.type = INPUT_KEYBOARD;
|
||||||
input.ki.wVk = static_cast<WORD>(key_code);
|
|
||||||
|
|
||||||
const UINT scan_code =
|
const bool prefer_vk = PreferSideSpecificVkInjection(key_code);
|
||||||
MapVirtualKeyW(static_cast<UINT>(key_code), MAPVK_VK_TO_VSC_EX);
|
const UINT resolved_scan_code =
|
||||||
if (scan_code != 0) {
|
scan_code != 0
|
||||||
|
? static_cast<UINT>(scan_code & 0xFF) | (extended ? 0xE000u : 0u)
|
||||||
|
: MapVirtualKeyW(static_cast<UINT>(key_code), MAPVK_VK_TO_VSC_EX);
|
||||||
|
|
||||||
|
if (scan_code != 0 && !prefer_vk) {
|
||||||
input.ki.wVk = 0;
|
input.ki.wVk = 0;
|
||||||
input.ki.wScan = static_cast<WORD>(scan_code & 0xFF);
|
input.ki.wScan = static_cast<WORD>(scan_code & 0xFF);
|
||||||
input.ki.dwFlags |= KEYEVENTF_SCANCODE;
|
input.ki.dwFlags |= KEYEVENTF_SCANCODE;
|
||||||
if ((scan_code & 0xFF00) != 0) {
|
if (extended) {
|
||||||
input.ki.dwFlags |= KEYEVENTF_EXTENDEDKEY;
|
input.ki.dwFlags |= KEYEVENTF_EXTENDEDKEY;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
input.ki.wVk = static_cast<WORD>(key_code);
|
||||||
|
|
||||||
|
if (prefer_vk && resolved_scan_code != 0) {
|
||||||
|
input.ki.wScan = static_cast<WORD>(resolved_scan_code & 0xFF);
|
||||||
|
if ((resolved_scan_code & 0xFF00) != 0) {
|
||||||
|
input.ki.dwFlags |= KEYEVENTF_EXTENDEDKEY;
|
||||||
|
}
|
||||||
|
} else if (resolved_scan_code != 0) {
|
||||||
|
input.ki.wVk = 0;
|
||||||
|
input.ki.wScan = static_cast<WORD>(resolved_scan_code & 0xFF);
|
||||||
|
input.ki.dwFlags |= KEYEVENTF_SCANCODE;
|
||||||
|
if ((resolved_scan_code & 0xFF00) != 0) {
|
||||||
|
input.ki.dwFlags |= KEYEVENTF_EXTENDEDKEY;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_down) {
|
if (!is_down) {
|
||||||
@@ -514,11 +550,17 @@ int InjectKeyboardInput(int key_code, bool is_down) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool ParseSecureInputKeyboardCommand(const std::string& command,
|
bool ParseSecureInputKeyboardCommand(const std::string& command,
|
||||||
int* key_code_out, bool* is_down_out) {
|
int* key_code_out, bool* is_down_out,
|
||||||
if (key_code_out == nullptr || is_down_out == nullptr) {
|
uint32_t* scan_code_out,
|
||||||
|
bool* extended_out) {
|
||||||
|
if (key_code_out == nullptr || is_down_out == nullptr ||
|
||||||
|
scan_code_out == nullptr || extended_out == nullptr) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*scan_code_out = 0;
|
||||||
|
*extended_out = false;
|
||||||
|
|
||||||
if (command.rfind(crossdesk::kCrossDeskSecureInputKeyboardCommandPrefix, 0) !=
|
if (command.rfind(crossdesk::kCrossDeskSecureInputKeyboardCommandPrefix, 0) !=
|
||||||
0) {
|
0) {
|
||||||
return false;
|
return false;
|
||||||
@@ -537,13 +579,46 @@ bool ParseSecureInputKeyboardCommand(const std::string& command,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string state = command.substr(separator + 1);
|
const size_t scan_separator = command.find(':', separator + 1);
|
||||||
|
const std::string state =
|
||||||
|
scan_separator == std::string::npos
|
||||||
|
? command.substr(separator + 1)
|
||||||
|
: command.substr(separator + 1, scan_separator - separator - 1);
|
||||||
if (state == "1" || state == "down") {
|
if (state == "1" || state == "down") {
|
||||||
*is_down_out = true;
|
*is_down_out = true;
|
||||||
|
} else if (state == "0" || state == "up") {
|
||||||
|
*is_down_out = false;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (scan_separator == std::string::npos) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (state == "0" || state == "up") {
|
|
||||||
*is_down_out = false;
|
const size_t extended_separator = command.find(':', scan_separator + 1);
|
||||||
|
const std::string scan_code_str =
|
||||||
|
extended_separator == std::string::npos
|
||||||
|
? command.substr(scan_separator + 1)
|
||||||
|
: command.substr(scan_separator + 1,
|
||||||
|
extended_separator - scan_separator - 1);
|
||||||
|
try {
|
||||||
|
*scan_code_out = static_cast<uint32_t>(std::stoul(scan_code_str));
|
||||||
|
} catch (...) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (extended_separator == std::string::npos) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string extended_str = command.substr(extended_separator + 1);
|
||||||
|
if (extended_str == "1" || extended_str == "true") {
|
||||||
|
*extended_out = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (extended_str == "0" || extended_str == "false") {
|
||||||
|
*extended_out = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -807,13 +882,17 @@ std::vector<uint8_t> HandleSecureInputHelperCommand(
|
|||||||
|
|
||||||
int key_code = 0;
|
int key_code = 0;
|
||||||
bool is_down = false;
|
bool is_down = false;
|
||||||
if (ParseSecureInputKeyboardCommand(command, &key_code, &is_down)) {
|
uint32_t scan_code = 0;
|
||||||
const int inject_result = InjectKeyboardInput(key_code, is_down);
|
bool extended = false;
|
||||||
|
if (ParseSecureInputKeyboardCommand(command, &key_code, &is_down, &scan_code,
|
||||||
|
&extended)) {
|
||||||
|
const int inject_result =
|
||||||
|
InjectKeyboardInput(key_code, is_down, scan_code, extended);
|
||||||
if (inject_result != 0) {
|
if (inject_result != 0) {
|
||||||
LOG_WARN(
|
LOG_WARN(
|
||||||
"Secure input helper SendInput failed for key_code={}, is_down={}, "
|
"Secure input helper SendInput failed for key_code={}, is_down={}, "
|
||||||
"err={}",
|
"scan_code={}, extended={}, err={}",
|
||||||
key_code, is_down, inject_result);
|
key_code, is_down, scan_code, extended, inject_result);
|
||||||
return BuildTextResponseBytes(BuildErrorJson(
|
return BuildTextResponseBytes(BuildErrorJson(
|
||||||
"send_input_failed", static_cast<DWORD>(inject_result)));
|
"send_input_failed", static_cast<DWORD>(inject_result)));
|
||||||
}
|
}
|
||||||
@@ -823,6 +902,8 @@ std::vector<uint8_t> HandleSecureInputHelperCommand(
|
|||||||
json["injected"] = "keyboard";
|
json["injected"] = "keyboard";
|
||||||
json["key_code"] = key_code;
|
json["key_code"] = key_code;
|
||||||
json["is_down"] = is_down;
|
json["is_down"] = is_down;
|
||||||
|
json["scan_code"] = scan_code;
|
||||||
|
json["extended"] = extended;
|
||||||
json["desktop"] = WideToUtf8(GetCurrentThreadDesktopNameW());
|
json["desktop"] = WideToUtf8(GetCurrentThreadDesktopNameW());
|
||||||
return BuildTextResponseBytes(json.dump());
|
return BuildTextResponseBytes(json.dump());
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
Submodule submodules/minirtc updated: a9259b3be3...b8affa443e
@@ -0,0 +1,97 @@
|
|||||||
|
#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;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ExpectResetBeforeShortcutPopup(const std::string& value) {
|
||||||
|
const std::string reset = "props->shortcut_selectable_hovered_ = false;";
|
||||||
|
const std::string popup = "ImGui::BeginPopup(\"shortcut\")";
|
||||||
|
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 shortcut_selectable_hovered_ before "
|
||||||
|
"checking the shortcut 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);
|
||||||
|
ok &= ExpectContains("control_bar.cpp", control_bar,
|
||||||
|
"props->shortcut_selectable_hovered_ =");
|
||||||
|
ok &= ExpectResetBeforeShortcutPopup(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;
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -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
@@ -23,6 +23,12 @@ function setup_options_and_dependencies()
|
|||||||
set_description("Enable DRM capture on Linux (assumes dependencies are installed)")
|
set_description("Enable DRM capture on Linux (assumes dependencies are installed)")
|
||||||
option_end()
|
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")
|
add_rules("mode.release", "mode.debug")
|
||||||
set_languages("c++17")
|
set_languages("c++17")
|
||||||
set_encodings("utf-8")
|
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_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_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("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
|
if is_mode("debug") then
|
||||||
add_defines("CROSSDESK_DEBUG")
|
add_defines("CROSSDESK_DEBUG")
|
||||||
@@ -47,4 +54,4 @@ function setup_options_and_dependencies()
|
|||||||
add_requires("nlohmann_json 3.11.3")
|
add_requires("nlohmann_json 3.11.3")
|
||||||
add_requires("cpp-httplib v0.26.0", {configs = {ssl = true}})
|
add_requires("cpp-httplib v0.26.0", {configs = {ssl = true}})
|
||||||
add_requires("tinyfiledialogs 3.15.1")
|
add_requires("tinyfiledialogs 3.15.1")
|
||||||
end
|
end
|
||||||
|
|||||||
+1
-1
@@ -49,7 +49,7 @@ function setup_platform_settings()
|
|||||||
end
|
end
|
||||||
|
|
||||||
if is_config("USE_WAYLAND", true) then
|
if is_config("USE_WAYLAND", true) then
|
||||||
add_links("dbus-1", "pipewire-0.3")
|
add_links("dbus-1")
|
||||||
add_defines("CROSSDESK_HAS_WAYLAND_CAPTURER=1")
|
add_defines("CROSSDESK_HAS_WAYLAND_CAPTURER=1")
|
||||||
add_existing_include_dirs({
|
add_existing_include_dirs({
|
||||||
"/usr/include/dbus-1.0",
|
"/usr/include/dbus-1.0",
|
||||||
|
|||||||
+38
-1
@@ -25,6 +25,40 @@ function setup_targets()
|
|||||||
add_files("src/path_manager/*.cpp")
|
add_files("src/path_manager/*.cpp")
|
||||||
add_includedirs("src/path_manager", {public = true})
|
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")
|
target("screen_capturer")
|
||||||
set_kind("object")
|
set_kind("object")
|
||||||
add_deps("rd_log", "common")
|
add_deps("rd_log", "common")
|
||||||
@@ -159,6 +193,9 @@ function setup_targets()
|
|||||||
add_packages("libyuv")
|
add_packages("libyuv")
|
||||||
add_deps("rd_log", "path_manager")
|
add_deps("rd_log", "path_manager")
|
||||||
add_defines("CROSSDESK_WGC_PLUGIN_BUILD=1")
|
add_defines("CROSSDESK_WGC_PLUGIN_BUILD=1")
|
||||||
|
-- Keep the project on C++17 while C++/WinRT still falls back to
|
||||||
|
-- MSVC's deprecated experimental coroutine header.
|
||||||
|
add_defines("_SILENCE_EXPERIMENTAL_COROUTINE_DEPRECATION_WARNINGS")
|
||||||
add_links("windowsapp")
|
add_links("windowsapp")
|
||||||
add_files("src/screen_capturer/windows/screen_capturer_wgc.cpp",
|
add_files("src/screen_capturer/windows/screen_capturer_wgc.cpp",
|
||||||
"src/screen_capturer/windows/wgc_session_impl.cpp",
|
"src/screen_capturer/windows/wgc_session_impl.cpp",
|
||||||
@@ -195,4 +232,4 @@ function setup_targets()
|
|||||||
add_deps("wgc_plugin", "crossdesk_service", "crossdesk_session_helper")
|
add_deps("wgc_plugin", "crossdesk_service", "crossdesk_session_helper")
|
||||||
add_files("scripts/windows/crossdesk.rc")
|
add_files("scripts/windows/crossdesk.rc")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user