mirror of
https://github.com/kunkundi/crossdesk.git
synced 2026-05-12 15:11:02 +08:00
Compare commits
15 Commits
ffa94986d5
...
latest
| Author | SHA1 | Date | |
|---|---|---|---|
| a3aedcb624 | |||
| 98b7c6c966 | |||
| b1d956af2c | |||
| b7a031bb7f | |||
| 15cce07b6e | |||
| 1d5d6f5121 | |||
| 5f541f5c8b | |||
| 71bce08549 | |||
| 37b9badb2a | |||
| 4089e80fe8 | |||
| 2be6e727ce | |||
| d3b886c3f6 | |||
| 97e48bfe71 | |||
| a8769dee06 | |||
| 855b15025c |
@@ -8,6 +8,8 @@ APP_VERSION="$1"
|
|||||||
ARCHITECTURE="amd64"
|
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"
|
||||||
|
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}"
|
||||||
@@ -41,11 +43,9 @@ Maintainer: $MAINTAINER
|
|||||||
Description: $DESCRIPTION
|
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, libasound2,
|
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
|
||||||
libpipewire-0.3-0, 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
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ APP_VERSION="$1"
|
|||||||
ARCHITECTURE="arm64"
|
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"
|
||||||
|
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}"
|
||||||
@@ -41,10 +43,9 @@ Maintainer: $MAINTAINER
|
|||||||
Description: $DESCRIPTION
|
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, libasound2,
|
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
|
||||||
libpipewire-0.3-0, 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
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
!define PRODUCT_WEB_SITE "https://www.crossdesk.cn/"
|
!define PRODUCT_WEB_SITE "https://www.crossdesk.cn/"
|
||||||
!define APP_NAME "CrossDesk"
|
!define APP_NAME "CrossDesk"
|
||||||
!define UNINSTALL_REG_KEY "CrossDesk"
|
!define UNINSTALL_REG_KEY "CrossDesk"
|
||||||
|
!define PRODUCT_SERVICE_NAME "CrossDeskService"
|
||||||
|
|
||||||
; Installer icon path
|
; Installer icon path
|
||||||
!define MUI_ICON "${__FILEDIR__}\..\..\icons\windows\crossdesk.ico"
|
!define MUI_ICON "${__FILEDIR__}\..\..\icons\windows\crossdesk.ico"
|
||||||
@@ -68,14 +69,21 @@ cancelInstall:
|
|||||||
Abort
|
Abort
|
||||||
|
|
||||||
installApp:
|
installApp:
|
||||||
|
Call StopInstalledService
|
||||||
|
|
||||||
SetOutPath "$INSTDIR"
|
SetOutPath "$INSTDIR"
|
||||||
SetOverwrite ifnewer
|
SetOverwrite ifnewer
|
||||||
|
|
||||||
; Main application executable path
|
; Main application executable path
|
||||||
File /oname=CrossDesk.exe "..\..\build\windows\x64\release\crossdesk.exe"
|
File /oname=CrossDesk.exe "..\..\build\windows\x64\release\crossdesk.exe"
|
||||||
|
; Bundle service-side binaries required by the Windows service flow
|
||||||
|
File "..\..\build\windows\x64\release\crossdesk_service.exe"
|
||||||
|
File "..\..\build\windows\x64\release\crossdesk_session_helper.exe"
|
||||||
; Bundle runtime DLLs from the release output directory
|
; Bundle runtime DLLs from the release output directory
|
||||||
File "..\..\build\windows\x64\release\*.dll"
|
File "..\..\build\windows\x64\release\*.dll"
|
||||||
|
|
||||||
|
Call RegisterInstalledService
|
||||||
|
|
||||||
; Write uninstall information
|
; Write uninstall information
|
||||||
WriteUninstaller "$INSTDIR\uninstall.exe"
|
WriteUninstaller "$INSTDIR\uninstall.exe"
|
||||||
|
|
||||||
@@ -122,8 +130,12 @@ cancelUninstall:
|
|||||||
Abort
|
Abort
|
||||||
|
|
||||||
uninstallApp:
|
uninstallApp:
|
||||||
|
Call un.UnregisterInstalledService
|
||||||
|
|
||||||
; Delete main executable and uninstaller
|
; Delete main executable and uninstaller
|
||||||
Delete "$INSTDIR\CrossDesk.exe"
|
Delete "$INSTDIR\CrossDesk.exe"
|
||||||
|
Delete "$INSTDIR\crossdesk_service.exe"
|
||||||
|
Delete "$INSTDIR\crossdesk_session_helper.exe"
|
||||||
Delete "$INSTDIR\uninstall.exe"
|
Delete "$INSTDIR\uninstall.exe"
|
||||||
|
|
||||||
; Recursively delete installation directory
|
; Recursively delete installation directory
|
||||||
@@ -148,3 +160,78 @@ SectionEnd
|
|||||||
Function LaunchApp
|
Function LaunchApp
|
||||||
Exec "$INSTDIR\CrossDesk.exe"
|
Exec "$INSTDIR\CrossDesk.exe"
|
||||||
FunctionEnd
|
FunctionEnd
|
||||||
|
|
||||||
|
Function StopInstalledService
|
||||||
|
IfFileExists "$INSTDIR\CrossDesk.exe" 0 stop_with_sc
|
||||||
|
IfFileExists "$INSTDIR\crossdesk_service.exe" 0 stop_with_sc
|
||||||
|
|
||||||
|
DetailPrint "Stopping existing CrossDesk service"
|
||||||
|
ExecWait '"$INSTDIR\CrossDesk.exe" --service-stop' $0
|
||||||
|
${If} $0 = 0
|
||||||
|
Return
|
||||||
|
${EndIf}
|
||||||
|
|
||||||
|
stop_with_sc:
|
||||||
|
DetailPrint "Stopping existing CrossDesk service via Service Control Manager"
|
||||||
|
ExecWait '"$SYSDIR\sc.exe" stop ${PRODUCT_SERVICE_NAME}' $0
|
||||||
|
${If} $0 != 0
|
||||||
|
${AndIf} $0 != 1060
|
||||||
|
${AndIf} $0 != 1062
|
||||||
|
MessageBox MB_ICONSTOP|MB_OK "Failed to stop the existing CrossDesk service. The installation will be aborted."
|
||||||
|
Abort
|
||||||
|
${EndIf}
|
||||||
|
Sleep 1500
|
||||||
|
FunctionEnd
|
||||||
|
|
||||||
|
Function RegisterInstalledService
|
||||||
|
IfFileExists "$INSTDIR\CrossDesk.exe" 0 missing_service_binary
|
||||||
|
IfFileExists "$INSTDIR\crossdesk_service.exe" 0 missing_service_binary
|
||||||
|
IfFileExists "$INSTDIR\crossdesk_session_helper.exe" 0 missing_service_binary
|
||||||
|
|
||||||
|
DetailPrint "Registering CrossDesk service"
|
||||||
|
ExecWait '"$INSTDIR\CrossDesk.exe" --service-install' $0
|
||||||
|
${If} $0 != 0
|
||||||
|
MessageBox MB_ICONSTOP|MB_OK "Failed to register the CrossDesk service. The installation will be aborted."
|
||||||
|
Abort
|
||||||
|
${EndIf}
|
||||||
|
|
||||||
|
DetailPrint "CrossDesk service registered for on-demand start"
|
||||||
|
|
||||||
|
Return
|
||||||
|
|
||||||
|
missing_service_binary:
|
||||||
|
MessageBox MB_ICONSTOP|MB_OK "CrossDesk service files are missing from the installer package. The installation will be aborted."
|
||||||
|
Abort
|
||||||
|
FunctionEnd
|
||||||
|
|
||||||
|
Function un.UnregisterInstalledService
|
||||||
|
IfFileExists "$INSTDIR\CrossDesk.exe" 0 unregister_with_sc
|
||||||
|
|
||||||
|
DetailPrint "Stopping CrossDesk service"
|
||||||
|
ExecWait '"$INSTDIR\CrossDesk.exe" --service-stop' $0
|
||||||
|
${If} $0 = 0
|
||||||
|
DetailPrint "Removing CrossDesk service"
|
||||||
|
ExecWait '"$INSTDIR\CrossDesk.exe" --service-uninstall' $0
|
||||||
|
${If} $0 = 0
|
||||||
|
Return
|
||||||
|
${EndIf}
|
||||||
|
${EndIf}
|
||||||
|
|
||||||
|
unregister_with_sc:
|
||||||
|
DetailPrint "Removing CrossDesk service via Service Control Manager"
|
||||||
|
ExecWait '"$SYSDIR\sc.exe" stop ${PRODUCT_SERVICE_NAME}' $0
|
||||||
|
${If} $0 != 0
|
||||||
|
${AndIf} $0 != 1060
|
||||||
|
${AndIf} $0 != 1062
|
||||||
|
MessageBox MB_ICONSTOP|MB_OK "Failed to stop the CrossDesk service. Uninstall will be aborted."
|
||||||
|
Abort
|
||||||
|
${EndIf}
|
||||||
|
Sleep 1500
|
||||||
|
|
||||||
|
ExecWait '"$SYSDIR\sc.exe" delete ${PRODUCT_SERVICE_NAME}' $0
|
||||||
|
${If} $0 != 0
|
||||||
|
${AndIf} $0 != 1060
|
||||||
|
MessageBox MB_ICONSTOP|MB_OK "Failed to remove the CrossDesk service. Uninstall will be aborted."
|
||||||
|
Abort
|
||||||
|
${EndIf}
|
||||||
|
FunctionEnd
|
||||||
|
|||||||
+21
-3
@@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
#include "service_host.h"
|
#include "service_host.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -53,7 +54,8 @@ void PrintServiceCliUsage() {
|
|||||||
<< " --service-uninstall Remove the installed Windows service\n"
|
<< " --service-uninstall Remove the installed Windows service\n"
|
||||||
<< " --service-start Start the Windows service\n"
|
<< " --service-start Start the Windows service\n"
|
||||||
<< " --service-stop Stop the Windows service\n"
|
<< " --service-stop Stop the Windows service\n"
|
||||||
<< " --service-sas Ask the service to send Secure Attention Sequence\n"
|
<< " --service-sas Ask the service to send Secure Attention "
|
||||||
|
"Sequence\n"
|
||||||
<< " --service-ping Ping the service over named pipe IPC\n"
|
<< " --service-ping Ping the service over named pipe IPC\n"
|
||||||
<< " --service-status Query service runtime status\n"
|
<< " --service-status Query service runtime status\n"
|
||||||
<< " --service-help Show this help\n";
|
<< " --service-help Show this help\n";
|
||||||
@@ -93,6 +95,19 @@ bool IsServiceCliCommand(const char* arg) {
|
|||||||
std::strcmp(arg, "--service-help") == 0;
|
std::strcmp(arg, "--service-help") == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TryStartManagedWindowsService() {
|
||||||
|
std::filesystem::path service_path = GetSiblingServiceExecutablePath();
|
||||||
|
if (service_path.empty() || !std::filesystem::exists(service_path)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!crossdesk::IsCrossDeskServiceInstalled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
crossdesk::StartCrossDeskService();
|
||||||
|
}
|
||||||
|
|
||||||
int HandleServiceCliCommand(const std::string& command) {
|
int HandleServiceCliCommand(const std::string& command) {
|
||||||
EnsureConsoleForCli();
|
EnsureConsoleForCli();
|
||||||
|
|
||||||
@@ -120,8 +135,7 @@ int HandleServiceCliCommand(const std::string& command) {
|
|||||||
|
|
||||||
if (command == "--service-uninstall") {
|
if (command == "--service-uninstall") {
|
||||||
bool success = crossdesk::UninstallCrossDeskService();
|
bool success = crossdesk::UninstallCrossDeskService();
|
||||||
std::cout << (success ? "uninstall ok" : "uninstall failed")
|
std::cout << (success ? "uninstall ok" : "uninstall failed") << std::endl;
|
||||||
<< std::endl;
|
|
||||||
return success ? 0 : 1;
|
return success ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,6 +196,10 @@ int main(int argc, char* argv[]) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
TryStartManagedWindowsService();
|
||||||
|
#endif
|
||||||
|
|
||||||
bool enable_daemon = false;
|
bool enable_daemon = false;
|
||||||
auto path_manager = std::make_unique<crossdesk::PathManager>("CrossDesk");
|
auto path_manager = std::make_unique<crossdesk::PathManager>("CrossDesk");
|
||||||
if (path_manager) {
|
if (path_manager) {
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|
||||||
@@ -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:
|
||||||
@@ -167,8 +175,7 @@ struct RemoteAction {
|
|||||||
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:
|
||||||
@@ -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:
|
||||||
|
|||||||
@@ -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,10 @@ inline bool IsFunctionKey(int key_code) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 (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);
|
||||||
|
|||||||
@@ -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:
|
||||||
CFMachPortRef event_tap_ = nullptr;
|
CFMachPortRef event_tap_ = nullptr;
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -98,6 +98,7 @@ std::map<int, int> vkCodeToCGKeyCode = {
|
|||||||
{0x67, 0x59}, // Numpad 7
|
{0x67, 0x59}, // Numpad 7
|
||||||
{0x68, 0x5B}, // Numpad 8
|
{0x68, 0x5B}, // Numpad 8
|
||||||
{0x69, 0x5C}, // Numpad 9
|
{0x69, 0x5C}, // Numpad 9
|
||||||
|
{0x90, 0x47}, // Num Lock / Keypad Clear
|
||||||
{0x6E, 0x41}, // Numpad .
|
{0x6E, 0x41}, // Numpad .
|
||||||
{0x6F, 0x4B}, // Numpad /
|
{0x6F, 0x4B}, // Numpad /
|
||||||
{0x6A, 0x43}, // Numpad *
|
{0x6A, 0x43}, // Numpad *
|
||||||
@@ -216,6 +217,7 @@ std::map<int, int> CGKeyCodeToVkCode = {
|
|||||||
{0x59, 0x67}, // Numpad 7
|
{0x59, 0x67}, // Numpad 7
|
||||||
{0x5B, 0x68}, // Numpad 8
|
{0x5B, 0x68}, // Numpad 8
|
||||||
{0x5C, 0x69}, // Numpad 9
|
{0x5C, 0x69}, // Numpad 9
|
||||||
|
{0x47, 0x90}, // Num Lock / Keypad Clear
|
||||||
{0x41, 0x6E}, // Numpad .
|
{0x41, 0x6E}, // Numpad .
|
||||||
{0x4B, 0x6F}, // Numpad /
|
{0x4B, 0x6F}, // Numpad /
|
||||||
{0x43, 0x6A}, // Numpad *
|
{0x43, 0x6A}, // Numpad *
|
||||||
@@ -336,6 +338,7 @@ std::map<int, int> vkCodeToX11KeySym = {
|
|||||||
{0x67, 0xFFB7}, // Numpad 7
|
{0x67, 0xFFB7}, // Numpad 7
|
||||||
{0x68, 0xFFB8}, // Numpad 8
|
{0x68, 0xFFB8}, // Numpad 8
|
||||||
{0x69, 0xFFB9}, // Numpad 9
|
{0x69, 0xFFB9}, // Numpad 9
|
||||||
|
{0x90, 0xFF7F}, // Num Lock
|
||||||
{0x6E, 0xFFAE}, // Numpad .
|
{0x6E, 0xFFAE}, // Numpad .
|
||||||
{0x6F, 0xFFAF}, // Numpad /
|
{0x6F, 0xFFAF}, // Numpad /
|
||||||
{0x6A, 0xFFAA}, // Numpad *
|
{0x6A, 0xFFAA}, // Numpad *
|
||||||
@@ -464,6 +467,7 @@ std::map<int, int> x11KeySymToVkCode = {
|
|||||||
{0xFFB7, 0x67}, // Numpad 7
|
{0xFFB7, 0x67}, // Numpad 7
|
||||||
{0xFFB8, 0x68}, // Numpad 8
|
{0xFFB8, 0x68}, // Numpad 8
|
||||||
{0xFFB9, 0x69}, // Numpad 9
|
{0xFFB9, 0x69}, // Numpad 9
|
||||||
|
{0xFF7F, 0x90}, // Num Lock
|
||||||
{0xFFAE, 0x6E}, // Numpad .
|
{0xFFAE, 0x6E}, // Numpad .
|
||||||
{0xFFAF, 0x6F}, // Numpad /
|
{0xFFAF, 0x6F}, // Numpad /
|
||||||
{0xFFAA, 0x6A}, // Numpad *
|
{0xFFAA, 0x6A}, // Numpad *
|
||||||
@@ -582,6 +586,7 @@ std::map<int, int> cgKeyCodeToX11KeySym = {
|
|||||||
{0x59, 0xFFB7}, // Numpad 7
|
{0x59, 0xFFB7}, // Numpad 7
|
||||||
{0x5B, 0xFFB8}, // Numpad 8
|
{0x5B, 0xFFB8}, // Numpad 8
|
||||||
{0x5C, 0xFFB9}, // Numpad 9
|
{0x5C, 0xFFB9}, // Numpad 9
|
||||||
|
{0x47, 0xFF7F}, // Num Lock / Keypad Clear
|
||||||
{0x41, 0xFFAE}, // Numpad .
|
{0x41, 0xFFAE}, // Numpad .
|
||||||
{0x4B, 0xFFAF}, // Numpad /
|
{0x4B, 0xFFAF}, // Numpad /
|
||||||
{0x43, 0xFFAA}, // Numpad *
|
{0x43, 0xFFAA}, // Numpad *
|
||||||
@@ -708,6 +713,7 @@ std::map<int, int> x11KeySymToCgKeyCode = {
|
|||||||
{0xFFB7, 0x59}, // Numpad 7
|
{0xFFB7, 0x59}, // Numpad 7
|
||||||
{0xFFB8, 0x5B}, // Numpad 8
|
{0xFFB8, 0x5B}, // Numpad 8
|
||||||
{0xFFB9, 0x5C}, // Numpad 9
|
{0xFFB9, 0x5C}, // Numpad 9
|
||||||
|
{0xFF7F, 0x47}, // Num Lock / Keypad Clear
|
||||||
{0xFFAE, 0x41}, // Numpad .
|
{0xFFAE, 0x41}, // Numpad .
|
||||||
{0xFFAF, 0x4B}, // Numpad /
|
{0xFFAF, 0x4B}, // Numpad /
|
||||||
{0xFFAA, 0x43}, // Numpad *
|
{0xFFAA, 0x43}, // Numpad *
|
||||||
|
|||||||
@@ -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
|
||||||
+49
-17
@@ -98,8 +98,7 @@ RemoteAction BuildWindowsServiceStatusAction(
|
|||||||
action.ss.available = status.available;
|
action.ss.available = status.available;
|
||||||
std::strncpy(action.ss.interactive_stage, status.interactive_stage.c_str(),
|
std::strncpy(action.ss.interactive_stage, status.interactive_stage.c_str(),
|
||||||
sizeof(action.ss.interactive_stage) - 1);
|
sizeof(action.ss.interactive_stage) - 1);
|
||||||
action.ss.interactive_stage[sizeof(action.ss.interactive_stage) - 1] =
|
action.ss.interactive_stage[sizeof(action.ss.interactive_stage) - 1] = '\0';
|
||||||
'\0';
|
|
||||||
return action;
|
return action;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -795,29 +794,51 @@ int Render::StopMouseController() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int Render::StartKeyboardCapturer() {
|
int Render::StartKeyboardCapturer() {
|
||||||
|
keyboard_capturer_uses_sdl_events_ = false;
|
||||||
|
|
||||||
|
#if defined(__linux__) && !defined(__APPLE__)
|
||||||
|
if (IsWaylandSession()) {
|
||||||
|
keyboard_capturer_uses_sdl_events_ = true;
|
||||||
|
LOG_INFO("Start keyboard capturer with SDL Wayland backend");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (!keyboard_capturer_) {
|
if (!keyboard_capturer_) {
|
||||||
LOG_INFO("keyboard capturer is nullptr");
|
keyboard_capturer_uses_sdl_events_ = true;
|
||||||
return -1;
|
LOG_WARN(
|
||||||
|
"keyboard capturer is nullptr, falling back to SDL keyboard events");
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
if (0 != keyboard_capturer_init_ret) {
|
if (0 != keyboard_capturer_init_ret) {
|
||||||
LOG_ERROR("Start keyboard capturer failed");
|
keyboard_capturer_uses_sdl_events_ = true;
|
||||||
|
LOG_WARN(
|
||||||
|
"Start keyboard capturer failed, falling back to SDL keyboard "
|
||||||
|
"events");
|
||||||
} else {
|
} else {
|
||||||
LOG_INFO("Start keyboard capturer");
|
LOG_INFO("Start keyboard capturer with native hook");
|
||||||
}
|
}
|
||||||
|
|
||||||
return keyboard_capturer_init_ret;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Render::StopKeyboardCapturer() {
|
int Render::StopKeyboardCapturer() {
|
||||||
|
if (keyboard_capturer_uses_sdl_events_) {
|
||||||
|
keyboard_capturer_uses_sdl_events_ = false;
|
||||||
|
LOG_INFO("Stop keyboard capturer with SDL keyboard backend");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (keyboard_capturer_) {
|
if (keyboard_capturer_) {
|
||||||
keyboard_capturer_->Unhook();
|
keyboard_capturer_->Unhook();
|
||||||
LOG_INFO("Stop keyboard capturer");
|
LOG_INFO("Stop keyboard capturer");
|
||||||
@@ -1883,8 +1904,8 @@ void Render::HandleWindowsServiceIntegration() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool has_connected_remote = std::any_of(
|
const bool has_connected_remote =
|
||||||
connection_status_.begin(), connection_status_.end(),
|
std::any_of(connection_status_.begin(), connection_status_.end(),
|
||||||
[](const auto& entry) {
|
[](const auto& entry) {
|
||||||
return entry.second == ConnectionStatus::Connected;
|
return entry.second == ConnectionStatus::Connected;
|
||||||
});
|
});
|
||||||
@@ -1894,8 +1915,7 @@ void Render::HandleWindowsServiceIntegration() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool force_broadcast = false;
|
bool force_broadcast = false;
|
||||||
if (pending_windows_service_sas_.exchange(false,
|
if (pending_windows_service_sas_.exchange(false, std::memory_order_relaxed)) {
|
||||||
std::memory_order_relaxed)) {
|
|
||||||
const std::string response =
|
const std::string response =
|
||||||
QueryCrossDeskService("sas", kWindowsServiceSasTimeoutMs);
|
QueryCrossDeskService("sas", kWindowsServiceSasTimeoutMs);
|
||||||
auto json = nlohmann::json::parse(response, nullptr, false);
|
auto json = nlohmann::json::parse(response, nullptr, false);
|
||||||
@@ -1931,10 +1951,12 @@ void Render::HandleWindowsServiceIntegration() {
|
|||||||
status.error_code != last_logged_service_error_code);
|
status.error_code != last_logged_service_error_code);
|
||||||
if (availability_changed || error_changed) {
|
if (availability_changed || error_changed) {
|
||||||
if (status.available) {
|
if (status.available) {
|
||||||
LOG_INFO("Local Windows service available for secure desktop integration");
|
LOG_INFO(
|
||||||
|
"Local Windows service available for secure desktop integration");
|
||||||
} else {
|
} else {
|
||||||
LOG_WARN(
|
LOG_WARN(
|
||||||
"Local Windows service unavailable, secure desktop integration disabled: error={}, code={}",
|
"Local Windows service unavailable, secure desktop integration "
|
||||||
|
"disabled: error={}, code={}",
|
||||||
status.error, status.error_code);
|
status.error, status.error_code);
|
||||||
}
|
}
|
||||||
last_logged_service_available = status.available;
|
last_logged_service_available = status.available;
|
||||||
@@ -1944,7 +1966,8 @@ void Render::HandleWindowsServiceIntegration() {
|
|||||||
} else if (last_logged_service_available ||
|
} else if (last_logged_service_available ||
|
||||||
last_logged_service_error != "invalid_service_status_json") {
|
last_logged_service_error != "invalid_service_status_json") {
|
||||||
LOG_WARN(
|
LOG_WARN(
|
||||||
"Local Windows service status query failed, secure desktop integration disabled");
|
"Local Windows service status query failed, secure desktop integration "
|
||||||
|
"disabled");
|
||||||
last_logged_service_available = false;
|
last_logged_service_available = false;
|
||||||
last_logged_service_error = "invalid_service_status_json";
|
last_logged_service_error = "invalid_service_status_json";
|
||||||
last_logged_service_error_code = 0;
|
last_logged_service_error_code = 0;
|
||||||
@@ -2670,7 +2693,7 @@ void Render::ProcessSdlEvent(const SDL_Event& event) {
|
|||||||
case SDL_EVENT_WINDOW_FOCUS_LOST:
|
case SDL_EVENT_WINDOW_FOCUS_LOST:
|
||||||
if (stream_window_ &&
|
if (stream_window_ &&
|
||||||
SDL_GetWindowID(stream_window_) == event.window.windowID) {
|
SDL_GetWindowID(stream_window_) == event.window.windowID) {
|
||||||
ForceReleasePressedModifiers();
|
ForceReleasePressedKeys();
|
||||||
focus_on_stream_window_ = false;
|
focus_on_stream_window_ = false;
|
||||||
} else if (main_window_ &&
|
} else if (main_window_ &&
|
||||||
SDL_GetWindowID(main_window_) == event.window.windowID) {
|
SDL_GetWindowID(main_window_) == event.window.windowID) {
|
||||||
@@ -2702,6 +2725,15 @@ void Render::ProcessSdlEvent(const SDL_Event& event) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case SDL_EVENT_KEY_DOWN:
|
||||||
|
case SDL_EVENT_KEY_UP:
|
||||||
|
if (keyboard_capturer_is_started_ && keyboard_capturer_uses_sdl_events_ &&
|
||||||
|
focus_on_stream_window_ && stream_window_ &&
|
||||||
|
SDL_GetWindowID(stream_window_) == event.key.windowID) {
|
||||||
|
ProcessKeyboardEvent(event);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (event.type == STREAM_REFRESH_EVENT) {
|
if (event.type == STREAM_REFRESH_EVENT) {
|
||||||
auto* props = static_cast<SubStreamWindowProperties*>(event.user.data1);
|
auto* props = static_cast<SubStreamWindowProperties*>(event.user.data1);
|
||||||
|
|||||||
+9
-7
@@ -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 {
|
||||||
@@ -282,8 +283,6 @@ class Render {
|
|||||||
std::shared_ptr<SubStreamWindowProperties>& props);
|
std::shared_ptr<SubStreamWindowProperties>& props);
|
||||||
void DrawReceivingScreenText(
|
void DrawReceivingScreenText(
|
||||||
std::shared_ptr<SubStreamWindowProperties>& props);
|
std::shared_ptr<SubStreamWindowProperties>& props);
|
||||||
void DrawRemoteUnlockStateText(
|
|
||||||
std::shared_ptr<SubStreamWindowProperties>& props);
|
|
||||||
void ResetRemoteServiceStatus(SubStreamWindowProperties& props);
|
void ResetRemoteServiceStatus(SubStreamWindowProperties& props);
|
||||||
void ApplyRemoteServiceStatus(SubStreamWindowProperties& props,
|
void ApplyRemoteServiceStatus(SubStreamWindowProperties& props,
|
||||||
const ServiceStatus& status);
|
const ServiceStatus& status);
|
||||||
@@ -340,10 +339,12 @@ 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 UpdatePressedModifierState(int key_code, bool is_down);
|
void TrackPressedKeyState(int key_code, bool is_down);
|
||||||
void ForceReleasePressedModifiers();
|
void ForceReleasePressedKeys();
|
||||||
|
int ProcessKeyboardEvent(const SDL_Event& event);
|
||||||
int ProcessMouseEvent(const SDL_Event& event);
|
int ProcessMouseEvent(const SDL_Event& event);
|
||||||
|
|
||||||
static void SdlCaptureAudioIn(void* userdata, Uint8* stream, int len);
|
static void SdlCaptureAudioIn(void* userdata, Uint8* stream, int len);
|
||||||
@@ -477,6 +478,7 @@ class Render {
|
|||||||
bool start_keyboard_capturer_ = false;
|
bool start_keyboard_capturer_ = false;
|
||||||
bool show_cursor_ = false;
|
bool show_cursor_ = false;
|
||||||
bool keyboard_capturer_is_started_ = false;
|
bool keyboard_capturer_is_started_ = false;
|
||||||
|
bool keyboard_capturer_uses_sdl_events_ = false;
|
||||||
bool foucs_on_main_window_ = false;
|
bool foucs_on_main_window_ = false;
|
||||||
bool focus_on_stream_window_ = false;
|
bool focus_on_stream_window_ = false;
|
||||||
bool main_window_minimized_ = false;
|
bool main_window_minimized_ = false;
|
||||||
@@ -532,8 +534,8 @@ class Render {
|
|||||||
std::string controlled_remote_id_ = "";
|
std::string controlled_remote_id_ = "";
|
||||||
std::string focused_remote_id_ = "";
|
std::string focused_remote_id_ = "";
|
||||||
std::string remote_client_id_ = "";
|
std::string remote_client_id_ = "";
|
||||||
std::unordered_set<int> pressed_modifier_keys_;
|
std::unordered_set<int> pressed_keyboard_keys_;
|
||||||
std::mutex pressed_modifier_keys_mutex_;
|
std::mutex pressed_keyboard_keys_mutex_;
|
||||||
SDL_Event last_mouse_event;
|
SDL_Event last_mouse_event;
|
||||||
SDL_AudioStream* output_stream_;
|
SDL_AudioStream* output_stream_;
|
||||||
uint32_t STREAM_REFRESH_EVENT = 0;
|
uint32_t STREAM_REFRESH_EVENT = 0;
|
||||||
|
|||||||
+313
-27
@@ -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,6 +29,253 @@ namespace crossdesk {
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
int TranslateSdlKeypadScancodeToVk(const SDL_KeyboardEvent& event) {
|
||||||
|
const bool numlock_enabled = (event.mod & SDL_KMOD_NUM) != 0;
|
||||||
|
|
||||||
|
switch (event.scancode) {
|
||||||
|
case SDL_SCANCODE_NUMLOCKCLEAR:
|
||||||
|
return 0x90;
|
||||||
|
case SDL_SCANCODE_KP_ENTER:
|
||||||
|
return 0x0D;
|
||||||
|
case SDL_SCANCODE_KP_0:
|
||||||
|
if (!numlock_enabled) {
|
||||||
|
return 0x2D;
|
||||||
|
}
|
||||||
|
return 0x60;
|
||||||
|
case SDL_SCANCODE_KP_1:
|
||||||
|
if (!numlock_enabled) {
|
||||||
|
return 0x23;
|
||||||
|
}
|
||||||
|
return 0x61;
|
||||||
|
case SDL_SCANCODE_KP_2:
|
||||||
|
if (!numlock_enabled) {
|
||||||
|
return 0x28;
|
||||||
|
}
|
||||||
|
return 0x62;
|
||||||
|
case SDL_SCANCODE_KP_3:
|
||||||
|
if (!numlock_enabled) {
|
||||||
|
return 0x22;
|
||||||
|
}
|
||||||
|
return 0x63;
|
||||||
|
case SDL_SCANCODE_KP_4:
|
||||||
|
if (!numlock_enabled) {
|
||||||
|
return 0x25;
|
||||||
|
}
|
||||||
|
return 0x64;
|
||||||
|
case SDL_SCANCODE_KP_5:
|
||||||
|
return 0x65;
|
||||||
|
case SDL_SCANCODE_KP_6:
|
||||||
|
if (!numlock_enabled) {
|
||||||
|
return 0x27;
|
||||||
|
}
|
||||||
|
return 0x66;
|
||||||
|
case SDL_SCANCODE_KP_7:
|
||||||
|
if (!numlock_enabled) {
|
||||||
|
return 0x24;
|
||||||
|
}
|
||||||
|
return 0x67;
|
||||||
|
case SDL_SCANCODE_KP_8:
|
||||||
|
if (!numlock_enabled) {
|
||||||
|
return 0x26;
|
||||||
|
}
|
||||||
|
return 0x68;
|
||||||
|
case SDL_SCANCODE_KP_9:
|
||||||
|
if (!numlock_enabled) {
|
||||||
|
return 0x21;
|
||||||
|
}
|
||||||
|
return 0x69;
|
||||||
|
case SDL_SCANCODE_KP_PERIOD:
|
||||||
|
case SDL_SCANCODE_KP_COMMA:
|
||||||
|
if (!numlock_enabled) {
|
||||||
|
return 0x2E;
|
||||||
|
}
|
||||||
|
return 0x6E;
|
||||||
|
case SDL_SCANCODE_KP_DIVIDE:
|
||||||
|
return 0x6F;
|
||||||
|
case SDL_SCANCODE_KP_MULTIPLY:
|
||||||
|
return 0x6A;
|
||||||
|
case SDL_SCANCODE_KP_MINUS:
|
||||||
|
return 0x6D;
|
||||||
|
case SDL_SCANCODE_KP_PLUS:
|
||||||
|
return 0x6B;
|
||||||
|
case SDL_SCANCODE_KP_EQUALS:
|
||||||
|
return 0xBB;
|
||||||
|
default:
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int TranslateSdlKeyboardEventToVk(const SDL_KeyboardEvent& event) {
|
||||||
|
const int keypad_key_code = TranslateSdlKeypadScancodeToVk(event);
|
||||||
|
if (keypad_key_code >= 0) {
|
||||||
|
return keypad_key_code;
|
||||||
|
}
|
||||||
|
|
||||||
|
const int key = static_cast<int>(event.key);
|
||||||
|
if (key >= 'a' && key <= 'z') {
|
||||||
|
return key - 'a' + 0x41;
|
||||||
|
}
|
||||||
|
if (key >= 'A' && key <= 'Z') {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
if (key >= '0' && key <= '9') {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (key) {
|
||||||
|
case ';':
|
||||||
|
return 0xBA;
|
||||||
|
case '\'':
|
||||||
|
return 0xDE;
|
||||||
|
case '`':
|
||||||
|
return 0xC0;
|
||||||
|
case ',':
|
||||||
|
return 0xBC;
|
||||||
|
case '.':
|
||||||
|
return 0xBE;
|
||||||
|
case '/':
|
||||||
|
return 0xBF;
|
||||||
|
case '\\':
|
||||||
|
return 0xDC;
|
||||||
|
case '[':
|
||||||
|
return 0xDB;
|
||||||
|
case ']':
|
||||||
|
return 0xDD;
|
||||||
|
case '-':
|
||||||
|
return 0xBD;
|
||||||
|
case '=':
|
||||||
|
return 0xBB;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (event.scancode) {
|
||||||
|
case SDL_SCANCODE_ESCAPE:
|
||||||
|
return 0x1B;
|
||||||
|
case SDL_SCANCODE_RETURN:
|
||||||
|
return 0x0D;
|
||||||
|
case SDL_SCANCODE_SPACE:
|
||||||
|
return 0x20;
|
||||||
|
case SDL_SCANCODE_BACKSPACE:
|
||||||
|
return 0x08;
|
||||||
|
case SDL_SCANCODE_TAB:
|
||||||
|
return 0x09;
|
||||||
|
case SDL_SCANCODE_PRINTSCREEN:
|
||||||
|
return 0x2C;
|
||||||
|
case SDL_SCANCODE_SCROLLLOCK:
|
||||||
|
return 0x91;
|
||||||
|
case SDL_SCANCODE_PAUSE:
|
||||||
|
return 0x13;
|
||||||
|
case SDL_SCANCODE_INSERT:
|
||||||
|
return 0x2D;
|
||||||
|
case SDL_SCANCODE_DELETE:
|
||||||
|
return 0x2E;
|
||||||
|
case SDL_SCANCODE_HOME:
|
||||||
|
return 0x24;
|
||||||
|
case SDL_SCANCODE_END:
|
||||||
|
return 0x23;
|
||||||
|
case SDL_SCANCODE_PAGEUP:
|
||||||
|
return 0x21;
|
||||||
|
case SDL_SCANCODE_PAGEDOWN:
|
||||||
|
return 0x22;
|
||||||
|
case SDL_SCANCODE_LEFT:
|
||||||
|
return 0x25;
|
||||||
|
case SDL_SCANCODE_RIGHT:
|
||||||
|
return 0x27;
|
||||||
|
case SDL_SCANCODE_UP:
|
||||||
|
return 0x26;
|
||||||
|
case SDL_SCANCODE_DOWN:
|
||||||
|
return 0x28;
|
||||||
|
case SDL_SCANCODE_F1:
|
||||||
|
return 0x70;
|
||||||
|
case SDL_SCANCODE_F2:
|
||||||
|
return 0x71;
|
||||||
|
case SDL_SCANCODE_F3:
|
||||||
|
return 0x72;
|
||||||
|
case SDL_SCANCODE_F4:
|
||||||
|
return 0x73;
|
||||||
|
case SDL_SCANCODE_F5:
|
||||||
|
return 0x74;
|
||||||
|
case SDL_SCANCODE_F6:
|
||||||
|
return 0x75;
|
||||||
|
case SDL_SCANCODE_F7:
|
||||||
|
return 0x76;
|
||||||
|
case SDL_SCANCODE_F8:
|
||||||
|
return 0x77;
|
||||||
|
case SDL_SCANCODE_F9:
|
||||||
|
return 0x78;
|
||||||
|
case SDL_SCANCODE_F10:
|
||||||
|
return 0x79;
|
||||||
|
case SDL_SCANCODE_F11:
|
||||||
|
return 0x7A;
|
||||||
|
case SDL_SCANCODE_F12:
|
||||||
|
return 0x7B;
|
||||||
|
case SDL_SCANCODE_CAPSLOCK:
|
||||||
|
return 0x14;
|
||||||
|
case SDL_SCANCODE_LSHIFT:
|
||||||
|
return 0xA0;
|
||||||
|
case SDL_SCANCODE_RSHIFT:
|
||||||
|
return 0xA1;
|
||||||
|
case SDL_SCANCODE_LCTRL:
|
||||||
|
return 0xA2;
|
||||||
|
case SDL_SCANCODE_RCTRL:
|
||||||
|
return 0xA3;
|
||||||
|
case SDL_SCANCODE_LALT:
|
||||||
|
return 0xA4;
|
||||||
|
case SDL_SCANCODE_RALT:
|
||||||
|
return 0xA5;
|
||||||
|
case SDL_SCANCODE_LGUI:
|
||||||
|
return 0x5B;
|
||||||
|
case SDL_SCANCODE_RGUI:
|
||||||
|
return 0x5C;
|
||||||
|
default:
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
@@ -36,8 +284,7 @@ bool BuildAbsoluteMousePosition(const std::vector<DisplayInfo>& displays,
|
|||||||
float normalized_y, int* absolute_x_out,
|
float normalized_y, int* absolute_x_out,
|
||||||
int* absolute_y_out) {
|
int* absolute_y_out) {
|
||||||
if (absolute_x_out == nullptr || absolute_y_out == nullptr ||
|
if (absolute_x_out == nullptr || absolute_y_out == nullptr ||
|
||||||
display_index < 0 ||
|
display_index < 0 || display_index >= static_cast<int>(displays.size())) {
|
||||||
display_index >= static_cast<int>(displays.size())) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,29 +399,29 @@ bool Render::IsModifierVkKey(int key_code) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Render::UpdatePressedModifierState(int key_code, bool is_down) {
|
void Render::TrackPressedKeyState(int key_code, bool is_down) {
|
||||||
if (!IsModifierVkKey(key_code)) {
|
if (!IsWaylandSession() && !IsModifierVkKey(key_code)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::lock_guard<std::mutex> lock(pressed_modifier_keys_mutex_);
|
std::lock_guard<std::mutex> lock(pressed_keyboard_keys_mutex_);
|
||||||
if (is_down) {
|
if (is_down) {
|
||||||
pressed_modifier_keys_.insert(key_code);
|
pressed_keyboard_keys_.insert(key_code);
|
||||||
} else {
|
} else {
|
||||||
pressed_modifier_keys_.erase(key_code);
|
pressed_keyboard_keys_.erase(key_code);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Render::ForceReleasePressedModifiers() {
|
void Render::ForceReleasePressedKeys() {
|
||||||
std::vector<int> pressed_keys;
|
std::vector<int> pressed_keys;
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(pressed_modifier_keys_mutex_);
|
std::lock_guard<std::mutex> lock(pressed_keyboard_keys_mutex_);
|
||||||
if (pressed_modifier_keys_.empty()) {
|
if (pressed_keyboard_keys_.empty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
pressed_keys.assign(pressed_modifier_keys_.begin(),
|
pressed_keys.assign(pressed_keyboard_keys_.begin(),
|
||||||
pressed_modifier_keys_.end());
|
pressed_keyboard_keys_.end());
|
||||||
pressed_modifier_keys_.clear();
|
pressed_keyboard_keys_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int key_code : pressed_keys) {
|
for (int key_code : pressed_keys) {
|
||||||
@@ -182,15 +429,26 @@ void Render::ForceReleasePressedModifiers() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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_;
|
||||||
@@ -210,11 +468,28 @@ int Render::SendKeyCommand(int key_code, bool is_down) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdatePressedModifierState(key_code, is_down);
|
TrackPressedKeyState(key_code, is_down);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Render::ProcessKeyboardEvent(const SDL_Event& event) {
|
||||||
|
if (event.type != SDL_EVENT_KEY_DOWN && event.type != SDL_EVENT_KEY_UP) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.type == SDL_EVENT_KEY_DOWN && event.key.repeat) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const int key_code = TranslateSdlKeyboardEventToVk(event.key);
|
||||||
|
if (key_code < 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return SendKeyCommand(key_code, event.type == SDL_EVENT_KEY_DOWN);
|
||||||
|
}
|
||||||
|
|
||||||
int Render::ProcessMouseEvent(const SDL_Event& event) {
|
int Render::ProcessMouseEvent(const SDL_Event& event) {
|
||||||
controlled_remote_id_ = "";
|
controlled_remote_id_ = "";
|
||||||
RemoteAction remote_action;
|
RemoteAction remote_action;
|
||||||
@@ -286,13 +561,20 @@ 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_ ||
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_pointer_position_event && cursor_x >= render_rect.x &&
|
if (is_pointer_position_event && cursor_x >= render_rect.x &&
|
||||||
cursor_x <= render_rect.x + render_rect.w && cursor_y >= render_rect.y &&
|
cursor_x <= render_rect.x + render_rect.w &&
|
||||||
|
cursor_y >= render_rect.y &&
|
||||||
cursor_y <= render_rect.y + render_rect.h) {
|
cursor_y <= render_rect.y + render_rect.h) {
|
||||||
controlled_remote_id_ = it.first;
|
controlled_remote_id_ = it.first;
|
||||||
last_mouse_event.motion.x = cursor_x;
|
last_mouse_event.motion.x = cursor_x;
|
||||||
@@ -328,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_) {
|
||||||
@@ -374,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_) {
|
||||||
@@ -827,9 +1109,9 @@ void Render::OnReceiveDataBufferCb(const char* data, size_t size,
|
|||||||
remote_action.m.x, remote_action.m.y,
|
remote_action.m.x, remote_action.m.y,
|
||||||
&absolute_x, &absolute_y)) {
|
&absolute_x, &absolute_y)) {
|
||||||
LOG_WARN(
|
LOG_WARN(
|
||||||
"Secure desktop mouse injection skipped, invalid display mapping: display_index={}, x={}, y={}",
|
"Secure desktop mouse injection skipped, invalid display "
|
||||||
render->selected_display_, remote_action.m.x,
|
"mapping: display_index={}, x={}, y={}",
|
||||||
remote_action.m.y);
|
render->selected_display_, remote_action.m.x, remote_action.m.y);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -842,7 +1124,8 @@ void Render::OnReceiveDataBufferCb(const char* data, size_t size,
|
|||||||
&render->last_local_secure_input_block_log_tick_, "local",
|
&render->last_local_secure_input_block_log_tick_, "local",
|
||||||
render->local_interactive_stage_.c_str());
|
render->local_interactive_stage_.c_str());
|
||||||
LOG_WARN(
|
LOG_WARN(
|
||||||
"Secure desktop mouse injection failed, x={}, y={}, wheel={}, flag={}, response={}",
|
"Secure desktop mouse injection failed, x={}, y={}, wheel={}, "
|
||||||
|
"flag={}, response={}",
|
||||||
absolute_x, absolute_y, remote_action.m.s,
|
absolute_x, absolute_y, remote_action.m.s,
|
||||||
static_cast<int>(remote_action.m.flag), response);
|
static_cast<int>(remote_action.m.flag), response);
|
||||||
}
|
}
|
||||||
@@ -852,8 +1135,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(
|
||||||
@@ -880,7 +1164,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;
|
||||||
@@ -1153,7 +1438,8 @@ void Render::OnConnectionStatusCb(ConnectionStatus status, const char* user_id,
|
|||||||
// Keep Wayland capture session warm to avoid black screen on
|
// Keep Wayland capture session warm to avoid black screen on
|
||||||
// subsequent reconnects.
|
// subsequent reconnects.
|
||||||
render->start_screen_capturer_ = true;
|
render->start_screen_capturer_ = true;
|
||||||
LOG_INFO("Keeping Wayland screen capturer running after "
|
LOG_INFO(
|
||||||
|
"Keeping Wayland screen capturer running after "
|
||||||
"disconnect to preserve reconnect stability");
|
"disconnect to preserve reconnect stability");
|
||||||
} else {
|
} else {
|
||||||
render->start_screen_capturer_ = false;
|
render->start_screen_capturer_ = false;
|
||||||
|
|||||||
@@ -193,94 +193,6 @@ 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());
|
||||||
|
|
||||||
if (props->remote_service_status_received_) {
|
|
||||||
ImGui::SameLine();
|
|
||||||
const RemoteUnlockState unlock_state = GetRemoteUnlockState(*props);
|
|
||||||
bool sas_button_style_pushed = false;
|
|
||||||
switch (unlock_state) {
|
|
||||||
case RemoteUnlockState::service_unavailable:
|
|
||||||
ImGui::PushStyleColor(ImGuiCol_Button,
|
|
||||||
ImVec4(185 / 255.0f, 28 / 255.0f,
|
|
||||||
28 / 255.0f, 1.0f));
|
|
||||||
sas_button_style_pushed = true;
|
|
||||||
break;
|
|
||||||
case RemoteUnlockState::credential_ui:
|
|
||||||
ImGui::PushStyleColor(ImGuiCol_Button,
|
|
||||||
ImVec4(22 / 255.0f, 163 / 255.0f,
|
|
||||||
74 / 255.0f, 1.0f));
|
|
||||||
sas_button_style_pushed = true;
|
|
||||||
break;
|
|
||||||
case RemoteUnlockState::lock_screen:
|
|
||||||
ImGui::PushStyleColor(ImGuiCol_Button,
|
|
||||||
ImVec4(202 / 255.0f, 138 / 255.0f,
|
|
||||||
4 / 255.0f, 1.0f));
|
|
||||||
sas_button_style_pushed = true;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
const bool can_send_sas =
|
|
||||||
props->connection_status_ == ConnectionStatus::Connected &&
|
|
||||||
props->peer_ != nullptr && props->remote_service_available_;
|
|
||||||
if (!can_send_sas) {
|
|
||||||
ImGui::BeginDisabled();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string sas_button = ICON_FA_UNLOCK_KEYHOLE;
|
|
||||||
ImGui::SetWindowFontScale(0.5f);
|
|
||||||
if (ImGui::Button(sas_button.c_str(),
|
|
||||||
ImVec2(button_width, button_height))) {
|
|
||||||
RemoteAction remote_action{};
|
|
||||||
remote_action.type = ControlType::service_command;
|
|
||||||
remote_action.c.flag = ServiceCommandFlag::send_sas;
|
|
||||||
std::string msg = remote_action.to_json();
|
|
||||||
SendReliableDataFrame(props->peer_, msg.c_str(), msg.size(),
|
|
||||||
props->control_data_label_.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!can_send_sas) {
|
|
||||||
ImGui::EndDisabled();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ImGui::IsItemHovered()) {
|
|
||||||
std::string tooltip = localization::send_sas[localization_language_index_];
|
|
||||||
switch (unlock_state) {
|
|
||||||
case RemoteUnlockState::service_unavailable:
|
|
||||||
tooltip = localization::remote_service_unavailable
|
|
||||||
[localization_language_index_];
|
|
||||||
break;
|
|
||||||
case RemoteUnlockState::credential_ui:
|
|
||||||
tooltip = localization::remote_password_box_visible
|
|
||||||
[localization_language_index_] +
|
|
||||||
"\n" +
|
|
||||||
localization::remote_unlock_requires_secure_desktop
|
|
||||||
[localization_language_index_];
|
|
||||||
break;
|
|
||||||
case RemoteUnlockState::lock_screen:
|
|
||||||
tooltip = localization::remote_lock_screen_hint
|
|
||||||
[localization_language_index_];
|
|
||||||
break;
|
|
||||||
case RemoteUnlockState::secure_desktop:
|
|
||||||
tooltip = localization::remote_secure_desktop_active
|
|
||||||
[localization_language_index_];
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui::BeginTooltip();
|
|
||||||
ImGui::PushTextWrapPos(button_width * 8.0f);
|
|
||||||
ImGui::TextWrapped("%s", tooltip.c_str());
|
|
||||||
ImGui::PopTextWrapPos();
|
|
||||||
ImGui::EndTooltip();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sas_button_style_pushed) {
|
|
||||||
ImGui::PopStyleColor();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
||||||
|
|||||||
@@ -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_] +
|
||||||
": ";
|
": ";
|
||||||
|
|||||||
@@ -257,4 +257,3 @@ int Render::ControlWindow(std::shared_ptr<SubStreamWindowProperties>& props) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
} // namespace crossdesk
|
} // namespace crossdesk
|
||||||
|
|
||||||
|
|||||||
@@ -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,25 +112,28 @@ 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::SetWindowFontScale(1.0f);
|
|
||||||
ImGui::SetWindowFontScale(0.5f);
|
|
||||||
ImGui::PopStyleColor(4);
|
ImGui::PopStyleColor(4);
|
||||||
ImGui::PopStyleVar(2);
|
ImGui::PopStyleVar(2);
|
||||||
|
|
||||||
// Close button handling
|
state->file_transfer_window_hovered_ =
|
||||||
|
mouse_in_window_rect ||
|
||||||
|
ImGui::IsWindowHovered(ImGuiHoveredFlags_RootAndChildWindows);
|
||||||
|
|
||||||
if (!window_opened) {
|
if (!window_opened) {
|
||||||
state->file_transfer_window_visible_ = false;
|
state->file_transfer_window_visible_ = false;
|
||||||
ImGui::End();
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (show_contents && window_opened) {
|
||||||
|
ImGui::SetWindowFontScale(1.0f);
|
||||||
|
ImGui::SetWindowFontScale(0.5f);
|
||||||
|
|
||||||
// Display file list
|
// Display file list
|
||||||
if (file_list.empty()) {
|
if (file_list.empty()) {
|
||||||
ImGui::Text("No files in transfer queue");
|
ImGui::Text("No files in transfer queue");
|
||||||
@@ -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::End();
|
||||||
ImGui::SetWindowFontScale(1.0f);
|
ImGui::SetWindowFontScale(1.0f);
|
||||||
|
|
||||||
// Pop Chinese font if it was pushed
|
if (has_chinese_font) {
|
||||||
if (stream_windows_system_chinese_font_) {
|
|
||||||
ImGui::PopFont();
|
ImGui::PopFont();
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
ImGui::PopStyleColor(4);
|
|
||||||
ImGui::PopStyleVar(2);
|
|
||||||
}
|
|
||||||
ImGui::SetWindowFontScale(1.0f);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace crossdesk
|
} // namespace crossdesk
|
||||||
|
|
||||||
|
|||||||
@@ -59,62 +59,6 @@ void Render::DrawReceivingScreenText(
|
|||||||
ImGui::TextColored(ImVec4(1.0f, 1.0f, 1.0f, 0.92f), "%s", text.c_str());
|
ImGui::TextColored(ImVec4(1.0f, 1.0f, 1.0f, 0.92f), "%s", text.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Render::DrawRemoteUnlockStateText(
|
|
||||||
std::shared_ptr<SubStreamWindowProperties>& props) {
|
|
||||||
if (!props->remote_service_status_received_ ||
|
|
||||||
!props->connection_established_ ||
|
|
||||||
props->connection_status_ != ConnectionStatus::Connected) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const RemoteUnlockState unlock_state = GetRemoteUnlockState(*props);
|
|
||||||
std::string text;
|
|
||||||
ImU32 background_color = IM_COL32(37, 99, 235, 220);
|
|
||||||
|
|
||||||
switch (unlock_state) {
|
|
||||||
case RemoteUnlockState::service_unavailable:
|
|
||||||
text = localization::remote_service_unavailable
|
|
||||||
[localization_language_index_];
|
|
||||||
background_color = IM_COL32(185, 28, 28, 220);
|
|
||||||
break;
|
|
||||||
case RemoteUnlockState::credential_ui:
|
|
||||||
text = localization::remote_password_box_visible
|
|
||||||
[localization_language_index_];
|
|
||||||
background_color = IM_COL32(22, 163, 74, 220);
|
|
||||||
break;
|
|
||||||
case RemoteUnlockState::lock_screen:
|
|
||||||
text = localization::remote_lock_screen_hint
|
|
||||||
[localization_language_index_];
|
|
||||||
background_color = IM_COL32(202, 138, 4, 220);
|
|
||||||
break;
|
|
||||||
case RemoteUnlockState::secure_desktop:
|
|
||||||
text = localization::remote_secure_desktop_active
|
|
||||||
[localization_language_index_];
|
|
||||||
background_color = IM_COL32(147, 51, 234, 220);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ImDrawList* draw_list = ImGui::GetWindowDrawList();
|
|
||||||
ImVec2 window_pos = ImGui::GetWindowPos();
|
|
||||||
ImVec2 window_size = ImGui::GetWindowSize();
|
|
||||||
ImVec2 text_size = ImGui::CalcTextSize(text.c_str());
|
|
||||||
float padding_x = title_bar_height_ * 0.45f;
|
|
||||||
float padding_y = title_bar_height_ * 0.18f;
|
|
||||||
float top_margin = fullscreen_button_pressed_ ? title_bar_height_ * 0.35f
|
|
||||||
: title_bar_height_ * 0.18f;
|
|
||||||
ImVec2 text_pos(window_pos.x + (window_size.x - text_size.x) * 0.5f,
|
|
||||||
window_pos.y + top_margin + padding_y);
|
|
||||||
ImVec2 rect_min(text_pos.x - padding_x, text_pos.y - padding_y);
|
|
||||||
ImVec2 rect_max(text_pos.x + text_size.x + padding_x,
|
|
||||||
text_pos.y + text_size.y + padding_y);
|
|
||||||
|
|
||||||
draw_list->AddRectFilled(rect_min, rect_max, background_color,
|
|
||||||
window_rounding_ * 0.9f);
|
|
||||||
draw_list->AddText(text_pos, IM_COL32(255, 255, 255, 255), text.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
void Render::CloseTab(decltype(client_properties_)::iterator& it) {
|
void Render::CloseTab(decltype(client_properties_)::iterator& it) {
|
||||||
// std::unique_lock lock(client_properties_mutex_);
|
// std::unique_lock lock(client_properties_mutex_);
|
||||||
if (it != client_properties_.end()) {
|
if (it != client_properties_.end()) {
|
||||||
@@ -229,7 +173,6 @@ int Render::StreamWindow() {
|
|||||||
FileTransferWindow(props);
|
FileTransferWindow(props);
|
||||||
|
|
||||||
DrawReceivingScreenText(props);
|
DrawReceivingScreenText(props);
|
||||||
DrawRemoteUnlockStateText(props);
|
|
||||||
|
|
||||||
focused_remote_id_ = props->remote_id_;
|
focused_remote_id_ = props->remote_id_;
|
||||||
|
|
||||||
@@ -332,7 +275,6 @@ int Render::StreamWindow() {
|
|||||||
FileTransferWindow(props);
|
FileTransferWindow(props);
|
||||||
|
|
||||||
DrawReceivingScreenText(props);
|
DrawReceivingScreenText(props);
|
||||||
DrawRemoteUnlockStateText(props);
|
|
||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|
||||||
|
|||||||
@@ -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,7 +401,7 @@ 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);
|
||||||
@@ -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();
|
||||||
|
|||||||
@@ -122,8 +122,7 @@ int ScreenCapturerX11::Init(const int fps, cb_desktop_data cb) {
|
|||||||
height_ = attr.height;
|
height_ = attr.height;
|
||||||
|
|
||||||
if ((width_ & 1) != 0 || (height_ & 1) != 0) {
|
if ((width_ & 1) != 0 || (height_ & 1) != 0) {
|
||||||
LOG_WARN(
|
LOG_WARN("X11 root size {}x{} is not even, aligning down to {}x{} for NV12",
|
||||||
"X11 root size {}x{} is not even, aligning down to {}x{} for NV12",
|
|
||||||
width_, height_, width_ & ~1, height_ & ~1);
|
width_, height_, width_ & ~1, height_ & ~1);
|
||||||
width_ &= ~1;
|
width_ &= ~1;
|
||||||
height_ &= ~1;
|
height_ &= ~1;
|
||||||
@@ -183,8 +182,9 @@ int ScreenCapturerX11::Start(bool show_cursor) {
|
|||||||
OnFrame();
|
OnFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(
|
const auto elapsed =
|
||||||
clock::now() - frame_start);
|
std::chrono::duration_cast<std::chrono::milliseconds>(clock::now() -
|
||||||
|
frame_start);
|
||||||
if (elapsed < frame_interval) {
|
if (elapsed < frame_interval) {
|
||||||
std::this_thread::sleep_for(frame_interval - elapsed);
|
std::this_thread::sleep_for(frame_interval - elapsed);
|
||||||
}
|
}
|
||||||
@@ -282,20 +282,16 @@ void ScreenCapturerX11::OnFrame() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool needs_copy = image->bytes_per_line != width_ * 4;
|
if (image->bits_per_pixel != 32 || image->bytes_per_line <= 0) {
|
||||||
std::vector<uint8_t> argb_buf;
|
LOG_WARN(
|
||||||
uint8_t* src_argb = nullptr;
|
"Unsupported X11 image layout: bits_per_pixel={}, bytes_per_line={}",
|
||||||
|
image->bits_per_pixel, image->bytes_per_line);
|
||||||
|
XDestroyImage(image);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (needs_copy) {
|
const uint8_t* src_argb = reinterpret_cast<const uint8_t*>(image->data);
|
||||||
argb_buf.resize(width_ * height_ * 4);
|
const int src_stride_argb = image->bytes_per_line;
|
||||||
for (int y = 0; y < height_; ++y) {
|
|
||||||
memcpy(&argb_buf[y * width_ * 4], image->data + y * image->bytes_per_line,
|
|
||||||
width_ * 4);
|
|
||||||
}
|
|
||||||
src_argb = argb_buf.data();
|
|
||||||
} else {
|
|
||||||
src_argb = reinterpret_cast<uint8_t*>(image->data);
|
|
||||||
}
|
|
||||||
|
|
||||||
const size_t y_size =
|
const size_t y_size =
|
||||||
static_cast<size_t>(width_) * static_cast<size_t>(height_);
|
static_cast<size_t>(width_) * static_cast<size_t>(height_);
|
||||||
@@ -307,8 +303,20 @@ void ScreenCapturerX11::OnFrame() {
|
|||||||
uv_plane_.resize(uv_size);
|
uv_plane_.resize(uv_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
libyuv::ARGBToNV12(src_argb, width_ * 4, y_plane_.data(), width_,
|
const int convert_ret =
|
||||||
uv_plane_.data(), width_, width_, height_);
|
use_abgr_to_nv12_
|
||||||
|
? libyuv::ABGRToNV12(src_argb, src_stride_argb, y_plane_.data(),
|
||||||
|
width_, uv_plane_.data(), width_, width_,
|
||||||
|
height_)
|
||||||
|
: libyuv::ARGBToNV12(src_argb, src_stride_argb, y_plane_.data(),
|
||||||
|
width_, uv_plane_.data(), width_, width_,
|
||||||
|
height_);
|
||||||
|
if (convert_ret != 0) {
|
||||||
|
LOG_WARN("X11 {} failed: {}",
|
||||||
|
use_abgr_to_nv12_ ? "ABGRToNV12" : "ARGBToNV12", convert_ret);
|
||||||
|
XDestroyImage(image);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<uint8_t> nv12;
|
std::vector<uint8_t> nv12;
|
||||||
nv12.reserve(y_plane_.size() + uv_plane_.size());
|
nv12.reserve(y_plane_.size() + uv_plane_.size());
|
||||||
@@ -416,16 +424,18 @@ bool ScreenCapturerX11::ProbeCapture() {
|
|||||||
x11_error = trap.SyncAndGetError();
|
x11_error = trap.SyncAndGetError();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (probe_image) {
|
|
||||||
XDestroyImage(probe_image);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (x11_error != 0 || !probe_image) {
|
if (x11_error != 0 || !probe_image) {
|
||||||
LOG_WARN("X11 probe XGetImage failed: x11_error={}, image={}", x11_error,
|
LOG_WARN("X11 probe XGetImage failed: x11_error={}, image={}", x11_error,
|
||||||
probe_image ? "valid" : "null");
|
probe_image ? "valid" : "null");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const bool red_in_low_byte = (probe_image->red_mask & 0x000000FFu) != 0;
|
||||||
|
const bool blue_in_low_byte = (probe_image->blue_mask & 0x000000FFu) != 0;
|
||||||
|
use_abgr_to_nv12_ = red_in_low_byte && !blue_in_low_byte;
|
||||||
|
|
||||||
|
XDestroyImage(probe_image);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} // namespace crossdesk
|
} // namespace crossdesk
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ class ScreenCapturerX11 : public ScreenCapturer {
|
|||||||
cb_desktop_data callback_;
|
cb_desktop_data callback_;
|
||||||
std::vector<DisplayInfo> display_info_list_;
|
std::vector<DisplayInfo> display_info_list_;
|
||||||
int capture_error_count_ = 0;
|
int capture_error_count_ = 0;
|
||||||
|
bool use_abgr_to_nv12_ = false;
|
||||||
|
|
||||||
std::vector<uint8_t> y_plane_;
|
std::vector<uint8_t> y_plane_;
|
||||||
std::vector<uint8_t> uv_plane_;
|
std::vector<uint8_t> uv_plane_;
|
||||||
|
|||||||
@@ -2,23 +2,22 @@
|
|||||||
|
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
|
|
||||||
#include <nlohmann/json.hpp>
|
|
||||||
|
|
||||||
#include <cmath>
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <cmath>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "interactive_state.h"
|
||||||
#include "rd_log.h"
|
#include "rd_log.h"
|
||||||
#include "screen_capturer_dxgi.h"
|
#include "screen_capturer_dxgi.h"
|
||||||
#include "screen_capturer_gdi.h"
|
#include "screen_capturer_gdi.h"
|
||||||
#include "interactive_state.h"
|
|
||||||
#include "service_host.h"
|
#include "service_host.h"
|
||||||
#include "session_helper_shared.h"
|
#include "session_helper_shared.h"
|
||||||
#include "wgc_plugin_api.h"
|
#include "wgc_plugin_api.h"
|
||||||
@@ -146,8 +145,7 @@ std::string ExtractPipeTextResponse(const std::vector<uint8_t>& response) {
|
|||||||
|
|
||||||
bool IsTransientSecureDesktopFrameError(const std::string& error_message) {
|
bool IsTransientSecureDesktopFrameError(const std::string& error_message) {
|
||||||
return error_message.rfind("pipe_unavailable:", 0) == 0 ||
|
return error_message.rfind("pipe_unavailable:", 0) == 0 ||
|
||||||
error_message.find("\"error\":\"bitblt_failed\"") !=
|
error_message.find("\"error\":\"bitblt_failed\"") != std::string::npos;
|
||||||
std::string::npos;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ReadPipeMessage(HANDLE pipe, std::vector<uint8_t>* response_out,
|
bool ReadPipeMessage(HANDLE pipe, std::vector<uint8_t>* response_out,
|
||||||
@@ -266,8 +264,8 @@ bool QuerySecureDesktopServiceStatus(SecureDesktopServiceStatus* status) {
|
|||||||
status->active_session_id = json.value("active_session_id", 0xFFFFFFFFu);
|
status->active_session_id = json.value("active_session_id", 0xFFFFFFFFu);
|
||||||
status->helper_running = json.value("secure_input_helper_running", false);
|
status->helper_running = json.value("secure_input_helper_running", false);
|
||||||
status->interactive_stage = json.value("interactive_stage", std::string());
|
status->interactive_stage = json.value("interactive_stage", std::string());
|
||||||
const bool secure_desktop_active = json.value(
|
const bool secure_desktop_active =
|
||||||
"interactive_secure_desktop_active",
|
json.value("interactive_secure_desktop_active",
|
||||||
json.value("secure_desktop_active", false));
|
json.value("secure_desktop_active", false));
|
||||||
status->capture_active =
|
status->capture_active =
|
||||||
status->active_session_id != 0xFFFFFFFF &&
|
status->active_session_id != 0xFFFFFFFF &&
|
||||||
@@ -287,7 +285,8 @@ bool QuerySecureDesktopHelperFrame(DWORD session_id, int left, int top,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::wstring pipe_name = GetCrossDeskSecureInputHelperPipeName(session_id);
|
const std::wstring pipe_name =
|
||||||
|
GetCrossDeskSecureInputHelperPipeName(session_id);
|
||||||
if (!WaitNamedPipeW(pipe_name.c_str(), kSecureDesktopHelperPipeTimeoutMs)) {
|
if (!WaitNamedPipeW(pipe_name.c_str(), kSecureDesktopHelperPipeTimeoutMs)) {
|
||||||
if (error_out != nullptr) {
|
if (error_out != nullptr) {
|
||||||
*error_out = "pipe_unavailable:" + std::to_string(GetLastError());
|
*error_out = "pipe_unavailable:" + std::to_string(GetLastError());
|
||||||
@@ -416,10 +415,8 @@ int ScreenCapturerWin::Init(const int fps, cb_desktop_data cb) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int ScreenCapturerWin::Destroy() {
|
int ScreenCapturerWin::Destroy() {
|
||||||
StopSecureCaptureThread();
|
Stop();
|
||||||
running_.store(false, std::memory_order_relaxed);
|
|
||||||
paused_.store(false, std::memory_order_relaxed);
|
paused_.store(false, std::memory_order_relaxed);
|
||||||
secure_desktop_capture_active_.store(false, std::memory_order_relaxed);
|
|
||||||
if (impl_) {
|
if (impl_) {
|
||||||
impl_->Destroy();
|
impl_->Destroy();
|
||||||
impl_.reset();
|
impl_.reset();
|
||||||
@@ -585,8 +582,8 @@ void ScreenCapturerWin::StopSecureCaptureThread() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ScreenCapturerWin::GetCurrentCaptureRegion(int* left, int* top,
|
bool ScreenCapturerWin::GetCurrentCaptureRegion(int* left, int* top, int* width,
|
||||||
int* width, int* height,
|
int* height,
|
||||||
std::string* display_name) {
|
std::string* display_name) {
|
||||||
if (left == nullptr || top == nullptr || width == nullptr ||
|
if (left == nullptr || top == nullptr || width == nullptr ||
|
||||||
height == nullptr || display_name == nullptr) {
|
height == nullptr || display_name == nullptr) {
|
||||||
@@ -653,11 +650,13 @@ void ScreenCapturerWin::SecureDesktopCaptureLoop() {
|
|||||||
if (service_changed || service_error_changed) {
|
if (service_changed || service_error_changed) {
|
||||||
if (status.service_available) {
|
if (status.service_available) {
|
||||||
LOG_INFO(
|
LOG_INFO(
|
||||||
"Windows capturer secure desktop service available, polling session_id={}",
|
"Windows capturer secure desktop service available, polling "
|
||||||
|
"session_id={}",
|
||||||
status.active_session_id);
|
status.active_session_id);
|
||||||
} else {
|
} else {
|
||||||
LOG_WARN(
|
LOG_WARN(
|
||||||
"Windows capturer secure desktop service unavailable: error={}, code={}",
|
"Windows capturer secure desktop service unavailable: "
|
||||||
|
"error={}, code={}",
|
||||||
status.error, status.error_code);
|
status.error, status.error_code);
|
||||||
}
|
}
|
||||||
last_service_available = status.service_available;
|
last_service_available = status.service_available;
|
||||||
@@ -665,8 +664,7 @@ void ScreenCapturerWin::SecureDesktopCaptureLoop() {
|
|||||||
}
|
}
|
||||||
} else if (last_service_available ||
|
} else if (last_service_available ||
|
||||||
last_service_error != "invalid_service_status_json") {
|
last_service_error != "invalid_service_status_json") {
|
||||||
LOG_WARN(
|
LOG_WARN("Windows capturer secure desktop service status query failed");
|
||||||
"Windows capturer secure desktop service status query failed");
|
|
||||||
last_service_available = false;
|
last_service_available = false;
|
||||||
last_service_error = "invalid_service_status_json";
|
last_service_error = "invalid_service_status_json";
|
||||||
}
|
}
|
||||||
@@ -677,7 +675,8 @@ void ScreenCapturerWin::SecureDesktopCaptureLoop() {
|
|||||||
status.interactive_stage != last_stage) {
|
status.interactive_stage != last_stage) {
|
||||||
capture_stage_started_tick = now;
|
capture_stage_started_tick = now;
|
||||||
LOG_INFO(
|
LOG_INFO(
|
||||||
"Windows capturer secure desktop state: active={}, stage='{}', session_id={}",
|
"Windows capturer secure desktop state: active={}, stage='{}', "
|
||||||
|
"session_id={}",
|
||||||
status.capture_active, status.interactive_stage,
|
status.capture_active, status.interactive_stage,
|
||||||
status.active_session_id);
|
status.active_session_id);
|
||||||
last_capture_active = status.capture_active;
|
last_capture_active = status.capture_active;
|
||||||
@@ -687,8 +686,8 @@ void ScreenCapturerWin::SecureDesktopCaptureLoop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!status.capture_active || status.active_session_id == 0xFFFFFFFF) {
|
if (!status.capture_active || status.active_session_id == 0xFFFFFFFF) {
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(
|
std::this_thread::sleep_for(
|
||||||
status.service_available ? 50 : 200));
|
std::chrono::milliseconds(status.service_available ? 50 : 200));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -721,12 +720,11 @@ void ScreenCapturerWin::SecureDesktopCaptureLoop() {
|
|||||||
} else {
|
} else {
|
||||||
const bool transient_error =
|
const bool transient_error =
|
||||||
IsTransientSecureDesktopFrameError(error_message);
|
IsTransientSecureDesktopFrameError(error_message);
|
||||||
const bool in_grace_period =
|
const bool in_grace_period = capture_stage_started_tick != 0 &&
|
||||||
capture_stage_started_tick != 0 &&
|
now - capture_stage_started_tick <
|
||||||
now - capture_stage_started_tick < kSecureDesktopTransientErrorGraceMs;
|
kSecureDesktopTransientErrorGraceMs;
|
||||||
const DWORD log_interval = transient_error
|
const DWORD log_interval =
|
||||||
? kSecureDesktopTransientErrorLogIntervalMs
|
transient_error ? kSecureDesktopTransientErrorLogIntervalMs : 1000;
|
||||||
: 1000;
|
|
||||||
if (transient_error && in_grace_period) {
|
if (transient_error && in_grace_period) {
|
||||||
std::this_thread::sleep_for(
|
std::this_thread::sleep_for(
|
||||||
std::chrono::milliseconds(frame_interval_ms));
|
std::chrono::milliseconds(frame_interval_ms));
|
||||||
@@ -734,7 +732,8 @@ void ScreenCapturerWin::SecureDesktopCaptureLoop() {
|
|||||||
}
|
}
|
||||||
if (now - last_error_tick >= log_interval) {
|
if (now - last_error_tick >= log_interval) {
|
||||||
LOG_WARN(
|
LOG_WARN(
|
||||||
"Windows capturer secure desktop frame query failed, stage='{}', session_id={}, error={}",
|
"Windows capturer secure desktop frame query failed, stage='{}', "
|
||||||
|
"session_id={}, error={}",
|
||||||
status.interactive_stage, status.active_session_id, error_message);
|
status.interactive_stage, status.active_session_id, error_message);
|
||||||
last_error_tick = now;
|
last_error_tick = now;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
#ifndef _CROSSDESK_INTERACTIVE_STATE_H_
|
/*
|
||||||
#define _CROSSDESK_INTERACTIVE_STATE_H_
|
* @Author: DI JUNKUN
|
||||||
|
* @Date: 2026-04-21
|
||||||
|
* Copyright (c) 2026 by DI JUNKUN, All Rights Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _INTERACTIVE_STATE_H_
|
||||||
|
#define _INTERACTIVE_STATE_H_
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
@@ -12,11 +18,11 @@ inline bool IsSecureDesktopInteractionRequired(
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline bool ShouldNormalizeUnlockToUserDesktop(
|
inline bool ShouldNormalizeUnlockToUserDesktop(
|
||||||
bool interactive_lock_screen_visible,
|
bool interactive_lock_screen_visible, const std::string& interactive_stage,
|
||||||
const std::string& interactive_stage, bool session_locked,
|
bool session_locked, bool interactive_logon_ui_visible,
|
||||||
bool interactive_logon_ui_visible, bool interactive_secure_desktop_active,
|
bool interactive_secure_desktop_active, bool credential_ui_visible,
|
||||||
bool credential_ui_visible, bool password_box_visible,
|
bool password_box_visible, bool unlock_ui_visible,
|
||||||
bool unlock_ui_visible, const std::string& last_session_event) {
|
const std::string& last_session_event) {
|
||||||
if (!interactive_lock_screen_visible && interactive_stage != "lock-screen") {
|
if (!interactive_lock_screen_visible && interactive_stage != "lock-screen") {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,8 @@ std::wstring GetExecutablePath() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PrintUsage() {
|
void PrintUsage() {
|
||||||
std::cout << "CrossDesk Windows service skeleton\n"
|
std::cout
|
||||||
|
<< "CrossDesk Windows service skeleton\n"
|
||||||
<< " --service Run under the Windows Service Control Manager\n"
|
<< " --service Run under the Windows Service Control Manager\n"
|
||||||
<< " --console Run the service loop in console mode\n"
|
<< " --console Run the service loop in console mode\n"
|
||||||
<< " --install Install the service for the current executable\n"
|
<< " --install Install the service for the current executable\n"
|
||||||
@@ -55,8 +56,7 @@ int main(int argc, char* argv[]) {
|
|||||||
}
|
}
|
||||||
if (command == "--uninstall") {
|
if (command == "--uninstall") {
|
||||||
bool success = crossdesk::UninstallCrossDeskService();
|
bool success = crossdesk::UninstallCrossDeskService();
|
||||||
std::cout << (success ? "uninstall ok" : "uninstall failed")
|
std::cout << (success ? "uninstall ok" : "uninstall failed") << std::endl;
|
||||||
<< std::endl;
|
|
||||||
return success ? 0 : 1;
|
return success ? 0 : 1;
|
||||||
}
|
}
|
||||||
if (command == "--start") {
|
if (command == "--start") {
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
#include "service_host.h"
|
#include "service_host.h"
|
||||||
|
|
||||||
#include <nlohmann/json.hpp>
|
#include <Aclapi.h>
|
||||||
|
#include <TlHelp32.h>
|
||||||
#include <Userenv.h>
|
#include <Userenv.h>
|
||||||
#include <WtsApi32.h>
|
#include <WtsApi32.h>
|
||||||
#include <sddl.h>
|
#include <sddl.h>
|
||||||
#include <TlHelp32.h>
|
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
@@ -26,10 +26,11 @@ namespace {
|
|||||||
|
|
||||||
using Json = nlohmann::json;
|
using Json = nlohmann::json;
|
||||||
|
|
||||||
constexpr char kSecureDesktopKeyboardIpcCommandPrefix[] =
|
constexpr char kSecureDesktopKeyboardIpcCommandPrefix[] = "secure-input-key:";
|
||||||
"secure-input-key:";
|
constexpr char kSecureDesktopMouseIpcCommandPrefix[] = "secure-input-mouse:";
|
||||||
constexpr char kSecureDesktopMouseIpcCommandPrefix[] =
|
constexpr wchar_t kCrossDeskClientProcessName[] = L"crossdesk.exe";
|
||||||
"secure-input-mouse:";
|
constexpr DWORD kCrossDeskClientMonitorIntervalMs = 1000;
|
||||||
|
constexpr ULONGLONG kCrossDeskClientMonitorStartupGraceMs = 5000;
|
||||||
|
|
||||||
using SendSasFunction = VOID(WINAPI*)(BOOL);
|
using SendSasFunction = VOID(WINAPI*)(BOOL);
|
||||||
|
|
||||||
@@ -160,6 +161,97 @@ std::string BuildErrorJson(const char* error, DWORD error_code = 0) {
|
|||||||
return stream.str();
|
return stream.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool HasRunningCrossDeskClientProcess() {
|
||||||
|
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
|
||||||
|
if (snapshot == INVALID_HANDLE_VALUE) {
|
||||||
|
LOG_ERROR("CreateToolhelp32Snapshot failed, error={}", GetLastError());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
PROCESSENTRY32W entry{};
|
||||||
|
entry.dwSize = sizeof(entry);
|
||||||
|
if (!Process32FirstW(snapshot, &entry)) {
|
||||||
|
DWORD error = GetLastError();
|
||||||
|
CloseHandle(snapshot);
|
||||||
|
if (error != ERROR_NO_MORE_FILES) {
|
||||||
|
LOG_ERROR("Process32FirstW failed, error={}", error);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
do {
|
||||||
|
if (_wcsicmp(entry.szExeFile, kCrossDeskClientProcessName) == 0) {
|
||||||
|
CloseHandle(snapshot);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} while (Process32NextW(snapshot, &entry));
|
||||||
|
|
||||||
|
DWORD error = GetLastError();
|
||||||
|
CloseHandle(snapshot);
|
||||||
|
if (error != ERROR_NO_MORE_FILES) {
|
||||||
|
LOG_ERROR("Process32NextW failed, error={}", error);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GrantCrossDeskServiceStartAccessToAuthenticatedUsers(SC_HANDLE service) {
|
||||||
|
if (service == nullptr) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
PACL existing_dacl = nullptr;
|
||||||
|
PACL updated_dacl = nullptr;
|
||||||
|
PSECURITY_DESCRIPTOR security_descriptor = nullptr;
|
||||||
|
DWORD error =
|
||||||
|
GetSecurityInfo(service, SE_SERVICE, DACL_SECURITY_INFORMATION, nullptr,
|
||||||
|
nullptr, &existing_dacl, nullptr, &security_descriptor);
|
||||||
|
if (error != ERROR_SUCCESS) {
|
||||||
|
LOG_ERROR("GetSecurityInfo failed, error={}", error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
BYTE sid_buffer[SECURITY_MAX_SID_SIZE] = {0};
|
||||||
|
DWORD sid_size = sizeof(sid_buffer);
|
||||||
|
if (!CreateWellKnownSid(WinAuthenticatedUserSid, nullptr, sid_buffer,
|
||||||
|
&sid_size)) {
|
||||||
|
error = GetLastError();
|
||||||
|
LOG_ERROR("CreateWellKnownSid failed, error={}", error);
|
||||||
|
LocalFree(security_descriptor);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
EXPLICIT_ACCESSW access{};
|
||||||
|
access.grfAccessPermissions = SERVICE_START | SERVICE_QUERY_STATUS;
|
||||||
|
access.grfAccessMode = SET_ACCESS;
|
||||||
|
access.grfInheritance = NO_INHERITANCE;
|
||||||
|
access.Trustee.TrusteeForm = TRUSTEE_IS_SID;
|
||||||
|
access.Trustee.TrusteeType = TRUSTEE_IS_WELL_KNOWN_GROUP;
|
||||||
|
access.Trustee.ptstrName = reinterpret_cast<LPWSTR>(sid_buffer);
|
||||||
|
|
||||||
|
error = SetEntriesInAclW(1, &access, existing_dacl, &updated_dacl);
|
||||||
|
if (error != ERROR_SUCCESS) {
|
||||||
|
LOG_ERROR("SetEntriesInAclW failed, error={}", error);
|
||||||
|
LocalFree(security_descriptor);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
error = SetSecurityInfo(service, SE_SERVICE, DACL_SECURITY_INFORMATION,
|
||||||
|
nullptr, nullptr, updated_dacl, nullptr);
|
||||||
|
if (error != ERROR_SUCCESS) {
|
||||||
|
LOG_ERROR("SetSecurityInfo failed, error={}", error);
|
||||||
|
LocalFree(updated_dacl);
|
||||||
|
LocalFree(security_descriptor);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
LocalFree(updated_dacl);
|
||||||
|
LocalFree(security_descriptor);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
std::string QueryNamedPipeMessage(const std::wstring& pipe_name,
|
std::string QueryNamedPipeMessage(const std::wstring& pipe_name,
|
||||||
const std::string& command,
|
const std::string& command,
|
||||||
DWORD timeout_ms) {
|
DWORD timeout_ms) {
|
||||||
@@ -221,36 +313,44 @@ 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();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string BuildSecureDesktopMouseIpcCommand(int x, int y, int wheel,
|
std::string BuildSecureDesktopMouseIpcCommand(int x, int y, int wheel,
|
||||||
int flag) {
|
int flag) {
|
||||||
std::ostringstream stream;
|
std::ostringstream stream;
|
||||||
stream << kSecureDesktopMouseIpcCommandPrefix << x << ":" << y << ":"
|
stream << kSecureDesktopMouseIpcCommandPrefix << x << ":" << y << ":" << wheel
|
||||||
<< wheel << ":" << flag;
|
<< ":" << flag;
|
||||||
return stream.str();
|
return stream.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string BuildSecureInputHelperKeyboardCommand(int key_code,
|
std::string BuildSecureInputHelperKeyboardCommand(int key_code, bool is_down,
|
||||||
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();
|
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;
|
||||||
}
|
}
|
||||||
@@ -267,13 +367,46 @@ 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;
|
||||||
@@ -487,15 +620,15 @@ std::string WideToUtf8(const std::wstring& value) {
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
int size_needed = WideCharToMultiByte(CP_UTF8, 0, value.c_str(), -1,
|
int size_needed = WideCharToMultiByte(CP_UTF8, 0, value.c_str(), -1, nullptr,
|
||||||
nullptr, 0, nullptr, nullptr);
|
0, nullptr, nullptr);
|
||||||
if (size_needed <= 1) {
|
if (size_needed <= 1) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string result(static_cast<size_t>(size_needed), '\0');
|
std::string result(static_cast<size_t>(size_needed), '\0');
|
||||||
WideCharToMultiByte(CP_UTF8, 0, value.c_str(), -1, result.data(),
|
WideCharToMultiByte(CP_UTF8, 0, value.c_str(), -1, result.data(), size_needed,
|
||||||
size_needed, nullptr, nullptr);
|
nullptr, nullptr);
|
||||||
result.pop_back();
|
result.pop_back();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -519,8 +652,7 @@ bool QuerySoftwareSasGeneration(DWORD* value_out, bool* existed_out) {
|
|||||||
DWORD value_size = sizeof(value);
|
DWORD value_size = sizeof(value);
|
||||||
DWORD type = REG_DWORD;
|
DWORD type = REG_DWORD;
|
||||||
LONG result = RegQueryValueExW(key, L"SoftwareSASGeneration", nullptr, &type,
|
LONG result = RegQueryValueExW(key, L"SoftwareSASGeneration", nullptr, &type,
|
||||||
reinterpret_cast<LPBYTE>(&value),
|
reinterpret_cast<LPBYTE>(&value), &value_size);
|
||||||
&value_size);
|
|
||||||
if (result == ERROR_SUCCESS && type == REG_DWORD) {
|
if (result == ERROR_SUCCESS && type == REG_DWORD) {
|
||||||
*value_out = value;
|
*value_out = value;
|
||||||
*existed_out = true;
|
*existed_out = true;
|
||||||
@@ -542,8 +674,7 @@ bool SetSoftwareSasGeneration(DWORD value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
result = RegSetValueExW(key, L"SoftwareSASGeneration", 0, REG_DWORD,
|
result = RegSetValueExW(key, L"SoftwareSASGeneration", 0, REG_DWORD,
|
||||||
reinterpret_cast<const BYTE*>(&value),
|
reinterpret_cast<const BYTE*>(&value), sizeof(value));
|
||||||
sizeof(value));
|
|
||||||
RegCloseKey(key);
|
RegCloseKey(key);
|
||||||
return result == ERROR_SUCCESS;
|
return result == ERROR_SUCCESS;
|
||||||
}
|
}
|
||||||
@@ -552,8 +683,8 @@ bool RestoreSoftwareSasGeneration(DWORD original_value, bool existed_before) {
|
|||||||
HKEY key = nullptr;
|
HKEY key = nullptr;
|
||||||
constexpr wchar_t kPolicyKey[] =
|
constexpr wchar_t kPolicyKey[] =
|
||||||
L"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System";
|
L"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System";
|
||||||
LONG result = RegOpenKeyExW(HKEY_LOCAL_MACHINE, kPolicyKey, 0, KEY_SET_VALUE,
|
LONG result =
|
||||||
&key);
|
RegOpenKeyExW(HKEY_LOCAL_MACHINE, kPolicyKey, 0, KEY_SET_VALUE, &key);
|
||||||
if (result != ERROR_SUCCESS) {
|
if (result != ERROR_SUCCESS) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -580,8 +711,8 @@ SasResult SendSasNow() {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* send_sas = reinterpret_cast<SendSasFunction>(
|
auto* send_sas =
|
||||||
GetProcAddress(sas_module, "SendSAS"));
|
reinterpret_cast<SendSasFunction>(GetProcAddress(sas_module, "SendSAS"));
|
||||||
if (send_sas == nullptr) {
|
if (send_sas == nullptr) {
|
||||||
result.error = "send_sas_proc_missing";
|
result.error = "send_sas_proc_missing";
|
||||||
result.error_code = GetLastError();
|
result.error_code = GetLastError();
|
||||||
@@ -625,8 +756,7 @@ struct PipeSecurityAttributes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool Initialize() {
|
bool Initialize() {
|
||||||
constexpr wchar_t kPipeSddl[] =
|
constexpr wchar_t kPipeSddl[] = L"D:(A;;GA;;;SY)(A;;GA;;;BA)(A;;GRGW;;;AU)";
|
||||||
L"D:(A;;GA;;;SY)(A;;GA;;;BA)(A;;GRGW;;;AU)";
|
|
||||||
if (!ConvertStringSecurityDescriptorToSecurityDescriptorW(
|
if (!ConvertStringSecurityDescriptorToSecurityDescriptorW(
|
||||||
kPipeSddl, SDDL_REVISION_1, &security_descriptor_, nullptr)) {
|
kPipeSddl, SDDL_REVISION_1, &security_descriptor_, nullptr)) {
|
||||||
return false;
|
return false;
|
||||||
@@ -654,8 +784,7 @@ struct KernelObjectSecurityAttributes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool Initialize() {
|
bool Initialize() {
|
||||||
constexpr wchar_t kObjectSddl[] =
|
constexpr wchar_t kObjectSddl[] = L"D:(A;;GA;;;SY)(A;;GA;;;BA)(A;;GA;;;AU)";
|
||||||
L"D:(A;;GA;;;SY)(A;;GA;;;BA)(A;;GA;;;AU)";
|
|
||||||
if (!ConvertStringSecurityDescriptorToSecurityDescriptorW(
|
if (!ConvertStringSecurityDescriptorToSecurityDescriptorW(
|
||||||
kObjectSddl, SDDL_REVISION_1, &security_descriptor_, nullptr)) {
|
kObjectSddl, SDDL_REVISION_1, &security_descriptor_, nullptr)) {
|
||||||
return false;
|
return false;
|
||||||
@@ -726,8 +855,7 @@ DWORD WINAPI CrossDeskServiceHost::ServiceControlHandler(
|
|||||||
case SERVICE_CONTROL_SESSIONCHANGE: {
|
case SERVICE_CONTROL_SESSIONCHANGE: {
|
||||||
DWORD session_id = 0xFFFFFFFF;
|
DWORD session_id = 0xFFFFFFFF;
|
||||||
if (event_data != nullptr) {
|
if (event_data != nullptr) {
|
||||||
auto* session =
|
auto* session = reinterpret_cast<WTSSESSION_NOTIFICATION*>(event_data);
|
||||||
reinterpret_cast<WTSSESSION_NOTIFICATION*>(event_data);
|
|
||||||
session_id = session->dwSessionId;
|
session_id = session->dwSessionId;
|
||||||
}
|
}
|
||||||
instance_->RecordSessionEvent(event_type, session_id);
|
instance_->RecordSessionEvent(event_type, session_id);
|
||||||
@@ -742,7 +870,8 @@ int CrossDeskServiceHost::RunAsService() {
|
|||||||
instance_ = this;
|
instance_ = this;
|
||||||
|
|
||||||
SERVICE_TABLE_ENTRYW service_table[] = {
|
SERVICE_TABLE_ENTRYW service_table[] = {
|
||||||
{const_cast<LPWSTR>(kCrossDeskServiceName), &CrossDeskServiceHost::ServiceMain},
|
{const_cast<LPWSTR>(kCrossDeskServiceName),
|
||||||
|
&CrossDeskServiceHost::ServiceMain},
|
||||||
{nullptr, nullptr}};
|
{nullptr, nullptr}};
|
||||||
|
|
||||||
if (!StartServiceCtrlDispatcherW(service_table)) {
|
if (!StartServiceCtrlDispatcherW(service_table)) {
|
||||||
@@ -820,6 +949,10 @@ int CrossDeskServiceHost::InitializeRuntime() {
|
|||||||
RefreshSessionState();
|
RefreshSessionState();
|
||||||
EnsureSessionHelper();
|
EnsureSessionHelper();
|
||||||
ipc_thread_ = std::thread(&CrossDeskServiceHost::IpcServerLoop, this);
|
ipc_thread_ = std::thread(&CrossDeskServiceHost::IpcServerLoop, this);
|
||||||
|
if (!console_mode_) {
|
||||||
|
client_process_monitor_thread_ =
|
||||||
|
std::thread(&CrossDeskServiceHost::ClientProcessMonitorLoop, this);
|
||||||
|
}
|
||||||
LOG_INFO("CrossDesk service runtime initialized, session_id={}",
|
LOG_INFO("CrossDesk service runtime initialized, session_id={}",
|
||||||
active_session_id_);
|
active_session_id_);
|
||||||
return 0;
|
return 0;
|
||||||
@@ -833,6 +966,10 @@ void CrossDeskServiceHost::ShutdownRuntime() {
|
|||||||
SetEvent(stop_event_);
|
SetEvent(stop_event_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (client_process_monitor_thread_.joinable()) {
|
||||||
|
client_process_monitor_thread_.join();
|
||||||
|
}
|
||||||
|
|
||||||
if (ipc_thread_.joinable()) {
|
if (ipc_thread_.joinable()) {
|
||||||
ipc_thread_.join();
|
ipc_thread_.join();
|
||||||
}
|
}
|
||||||
@@ -849,6 +986,34 @@ void CrossDeskServiceHost::RequestStop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CrossDeskServiceHost::ClientProcessMonitorLoop() {
|
||||||
|
const ULONGLONG monitor_started_at = GetTickCount64();
|
||||||
|
|
||||||
|
while (stop_event_ != nullptr) {
|
||||||
|
DWORD wait_result =
|
||||||
|
WaitForSingleObject(stop_event_, kCrossDeskClientMonitorIntervalMs);
|
||||||
|
if (wait_result == WAIT_OBJECT_0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (wait_result != WAIT_TIMEOUT) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GetTickCount64() - monitor_started_at <
|
||||||
|
kCrossDeskClientMonitorStartupGraceMs) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (HasRunningCrossDeskClientProcess()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_INFO("No crossdesk client process detected, stopping service");
|
||||||
|
RequestStop();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CrossDeskServiceHost::ReportServiceStatus(DWORD current_state,
|
void CrossDeskServiceHost::ReportServiceStatus(DWORD current_state,
|
||||||
DWORD win32_exit_code,
|
DWORD win32_exit_code,
|
||||||
DWORD wait_hint) {
|
DWORD wait_hint) {
|
||||||
@@ -897,7 +1062,8 @@ int CrossDeskServiceHost::RunServiceLoop(bool as_service) {
|
|||||||
|
|
||||||
if (console_mode_) {
|
if (console_mode_) {
|
||||||
SetConsoleCtrlHandler(&CrossDeskServiceHost::ConsoleControlHandler, TRUE);
|
SetConsoleCtrlHandler(&CrossDeskServiceHost::ConsoleControlHandler, TRUE);
|
||||||
std::cout << "CrossDesk service skeleton running in console mode. Press Ctrl+C to stop."
|
std::cout << "CrossDesk service skeleton running in console mode. Press "
|
||||||
|
"Ctrl+C to stop."
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -932,10 +1098,9 @@ void CrossDeskServiceHost::IpcServerLoop() {
|
|||||||
while (stop_event_ != nullptr &&
|
while (stop_event_ != nullptr &&
|
||||||
WaitForSingleObject(stop_event_, 0) != WAIT_OBJECT_0) {
|
WaitForSingleObject(stop_event_, 0) != WAIT_OBJECT_0) {
|
||||||
HANDLE pipe = CreateNamedPipeW(
|
HANDLE pipe = CreateNamedPipeW(
|
||||||
kCrossDeskServicePipeName,
|
kCrossDeskServicePipeName, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED,
|
||||||
PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED,
|
PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, 1, 4096, 4096, 0,
|
||||||
PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT,
|
pipe_attributes);
|
||||||
1, 4096, 4096, 0, pipe_attributes);
|
|
||||||
if (pipe == INVALID_HANDLE_VALUE) {
|
if (pipe == INVALID_HANDLE_VALUE) {
|
||||||
DWORD error = GetLastError();
|
DWORD error = GetLastError();
|
||||||
LOG_ERROR("CreateNamedPipeW failed, error={}", error);
|
LOG_ERROR("CreateNamedPipeW failed, error={}", error);
|
||||||
@@ -1068,8 +1233,7 @@ bool CrossDeskServiceHost::ShouldKeepSecureInputHelperLocked(
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return HasSecureInputUiLocked() ||
|
return HasSecureInputUiLocked() || (GetEffectiveSessionLockedLocked() &&
|
||||||
(GetEffectiveSessionLockedLocked() &&
|
|
||||||
IsHelperReportingLockScreenLocked());
|
IsHelperReportingLockScreenLocked());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1257,8 +1421,8 @@ bool CrossDeskServiceHost::LaunchSessionHelper(DWORD session_id) {
|
|||||||
event_attributes = event_security.get();
|
event_attributes = event_security.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
HANDLE stop_event_handle = CreateEventW(event_attributes, TRUE, FALSE,
|
HANDLE stop_event_handle =
|
||||||
stop_event_name.c_str());
|
CreateEventW(event_attributes, TRUE, FALSE, stop_event_name.c_str());
|
||||||
if (stop_event_handle == nullptr) {
|
if (stop_event_handle == nullptr) {
|
||||||
std::lock_guard<std::mutex> lock(state_mutex_);
|
std::lock_guard<std::mutex> lock(state_mutex_);
|
||||||
session_helper_last_error_ = "create_helper_stop_event_failed";
|
session_helper_last_error_ = "create_helper_stop_event_failed";
|
||||||
@@ -1280,8 +1444,8 @@ bool CrossDeskServiceHost::LaunchSessionHelper(DWORD session_id) {
|
|||||||
|
|
||||||
if (console_mode_ && process_session_id_ == session_id) {
|
if (console_mode_ && process_session_id_ == session_id) {
|
||||||
created = CreateProcessW(helper_path.c_str(), mutable_command_line.data(),
|
created = CreateProcessW(helper_path.c_str(), mutable_command_line.data(),
|
||||||
nullptr, nullptr, FALSE, CREATE_NO_WINDOW,
|
nullptr, nullptr, FALSE, CREATE_NO_WINDOW, nullptr,
|
||||||
nullptr, nullptr, &startup_info, &process_info);
|
nullptr, &startup_info, &process_info);
|
||||||
} else {
|
} else {
|
||||||
HANDLE user_token = nullptr;
|
HANDLE user_token = nullptr;
|
||||||
HANDLE primary_token = nullptr;
|
HANDLE primary_token = nullptr;
|
||||||
@@ -1315,8 +1479,7 @@ bool CrossDeskServiceHost::LaunchSessionHelper(DWORD session_id) {
|
|||||||
FALSE);
|
FALSE);
|
||||||
created = CreateProcessAsUserW(
|
created = CreateProcessAsUserW(
|
||||||
primary_token, helper_path.c_str(), mutable_command_line.data(),
|
primary_token, helper_path.c_str(), mutable_command_line.data(),
|
||||||
nullptr, nullptr, FALSE,
|
nullptr, nullptr, FALSE, CREATE_UNICODE_ENVIRONMENT | CREATE_NO_WINDOW,
|
||||||
CREATE_UNICODE_ENVIRONMENT | CREATE_NO_WINDOW,
|
|
||||||
environment_block.environment, nullptr, &startup_info, &process_info);
|
environment_block.environment, nullptr, &startup_info, &process_info);
|
||||||
DWORD error = created ? ERROR_SUCCESS : GetLastError();
|
DWORD error = created ? ERROR_SUCCESS : GetLastError();
|
||||||
CloseHandle(primary_token);
|
CloseHandle(primary_token);
|
||||||
@@ -1364,8 +1527,8 @@ bool CrossDeskServiceHost::LaunchSecureInputHelper(DWORD session_id) {
|
|||||||
event_attributes = event_security.get();
|
event_attributes = event_security.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
HANDLE stop_event_handle = CreateEventW(event_attributes, TRUE, FALSE,
|
HANDLE stop_event_handle =
|
||||||
stop_event_name.c_str());
|
CreateEventW(event_attributes, TRUE, FALSE, stop_event_name.c_str());
|
||||||
if (stop_event_handle == nullptr) {
|
if (stop_event_handle == nullptr) {
|
||||||
std::lock_guard<std::mutex> lock(state_mutex_);
|
std::lock_guard<std::mutex> lock(state_mutex_);
|
||||||
secure_input_helper_last_error_ =
|
secure_input_helper_last_error_ =
|
||||||
@@ -1388,8 +1551,8 @@ bool CrossDeskServiceHost::LaunchSecureInputHelper(DWORD session_id) {
|
|||||||
|
|
||||||
if (console_mode_ && process_session_id_ == session_id) {
|
if (console_mode_ && process_session_id_ == session_id) {
|
||||||
created = CreateProcessW(helper_path.c_str(), mutable_command_line.data(),
|
created = CreateProcessW(helper_path.c_str(), mutable_command_line.data(),
|
||||||
nullptr, nullptr, FALSE, CREATE_NO_WINDOW,
|
nullptr, nullptr, FALSE, CREATE_NO_WINDOW, nullptr,
|
||||||
nullptr, nullptr, &startup_info, &process_info);
|
nullptr, &startup_info, &process_info);
|
||||||
} else {
|
} else {
|
||||||
HANDLE primary_token = nullptr;
|
HANDLE primary_token = nullptr;
|
||||||
ScopedEnvironmentBlock environment_block;
|
ScopedEnvironmentBlock environment_block;
|
||||||
@@ -1397,8 +1560,7 @@ bool CrossDeskServiceHost::LaunchSecureInputHelper(DWORD session_id) {
|
|||||||
if (!CreateSessionSystemToken(session_id, &primary_token, &error)) {
|
if (!CreateSessionSystemToken(session_id, &primary_token, &error)) {
|
||||||
CloseHandle(stop_event_handle);
|
CloseHandle(stop_event_handle);
|
||||||
std::lock_guard<std::mutex> lock(state_mutex_);
|
std::lock_guard<std::mutex> lock(state_mutex_);
|
||||||
secure_input_helper_last_error_ =
|
secure_input_helper_last_error_ = "create_session_system_token_failed";
|
||||||
"create_session_system_token_failed";
|
|
||||||
secure_input_helper_last_error_code_ = error;
|
secure_input_helper_last_error_code_ = error;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -1407,16 +1569,14 @@ bool CrossDeskServiceHost::LaunchSecureInputHelper(DWORD session_id) {
|
|||||||
FALSE);
|
FALSE);
|
||||||
created = CreateProcessAsUserW(
|
created = CreateProcessAsUserW(
|
||||||
primary_token, helper_path.c_str(), mutable_command_line.data(),
|
primary_token, helper_path.c_str(), mutable_command_line.data(),
|
||||||
nullptr, nullptr, FALSE,
|
nullptr, nullptr, FALSE, CREATE_UNICODE_ENVIRONMENT | CREATE_NO_WINDOW,
|
||||||
CREATE_UNICODE_ENVIRONMENT | CREATE_NO_WINDOW,
|
|
||||||
environment_block.environment, nullptr, &startup_info, &process_info);
|
environment_block.environment, nullptr, &startup_info, &process_info);
|
||||||
error = created ? ERROR_SUCCESS : GetLastError();
|
error = created ? ERROR_SUCCESS : GetLastError();
|
||||||
CloseHandle(primary_token);
|
CloseHandle(primary_token);
|
||||||
if (!created) {
|
if (!created) {
|
||||||
CloseHandle(stop_event_handle);
|
CloseHandle(stop_event_handle);
|
||||||
std::lock_guard<std::mutex> lock(state_mutex_);
|
std::lock_guard<std::mutex> lock(state_mutex_);
|
||||||
secure_input_helper_last_error_ =
|
secure_input_helper_last_error_ = "create_secure_input_helper_failed";
|
||||||
"create_secure_input_helper_failed";
|
|
||||||
secure_input_helper_last_error_code_ = error;
|
secure_input_helper_last_error_code_ = error;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -1515,8 +1675,7 @@ void CrossDeskServiceHost::RefreshSessionHelperReportedState() {
|
|||||||
session_helper_report_session_id_ =
|
session_helper_report_session_id_ =
|
||||||
json.value("session_id", static_cast<DWORD>(0xFFFFFFFF));
|
json.value("session_id", static_cast<DWORD>(0xFFFFFFFF));
|
||||||
session_helper_report_process_id_ = json.value("process_id", 0u);
|
session_helper_report_process_id_ = json.value("process_id", 0u);
|
||||||
session_helper_report_session_locked_ =
|
session_helper_report_session_locked_ = json.value("session_locked", false);
|
||||||
json.value("session_locked", false);
|
|
||||||
session_helper_report_input_desktop_available_ =
|
session_helper_report_input_desktop_available_ =
|
||||||
json.value("input_desktop_available", false);
|
json.value("input_desktop_available", false);
|
||||||
session_helper_report_input_desktop_error_code_ =
|
session_helper_report_input_desktop_error_code_ =
|
||||||
@@ -1582,8 +1741,7 @@ void CrossDeskServiceHost::RecordSessionEvent(DWORD event_type,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string CrossDeskServiceHost::HandleIpcCommand(
|
std::string CrossDeskServiceHost::HandleIpcCommand(const std::string& command) {
|
||||||
const std::string& command) {
|
|
||||||
std::string normalized = ToLower(Trim(command));
|
std::string normalized = ToLower(Trim(command));
|
||||||
if (normalized == "ping") {
|
if (normalized == "ping") {
|
||||||
return "{\"ok\":true,\"reply\":\"pong\"}";
|
return "{\"ok\":true,\"reply\":\"pong\"}";
|
||||||
@@ -1596,9 +1754,12 @@ std::string CrossDeskServiceHost::HandleIpcCommand(
|
|||||||
}
|
}
|
||||||
int key_code = 0;
|
int key_code = 0;
|
||||||
bool is_down = false;
|
bool is_down = false;
|
||||||
if (ParseSecureDesktopKeyboardIpcCommand(normalized, &key_code,
|
uint32_t scan_code = 0;
|
||||||
&is_down)) {
|
bool extended = false;
|
||||||
return SendSecureDesktopKeyboardInput(key_code, is_down);
|
if (ParseSecureDesktopKeyboardIpcCommand(normalized, &key_code, &is_down,
|
||||||
|
&scan_code, &extended)) {
|
||||||
|
return SendSecureDesktopKeyboardInput(key_code, is_down, scan_code,
|
||||||
|
extended);
|
||||||
}
|
}
|
||||||
return BuildErrorJson("unknown_command");
|
return BuildErrorJson("unknown_command");
|
||||||
}
|
}
|
||||||
@@ -1658,8 +1819,8 @@ std::string CrossDeskServiceHost::BuildStatusResponse() {
|
|||||||
interactive_state_ready
|
interactive_state_ready
|
||||||
? (effective_session_locked && IsHelperReportingLockScreenLocked())
|
? (effective_session_locked && IsHelperReportingLockScreenLocked())
|
||||||
: false;
|
: false;
|
||||||
bool credential_ui_visible = interactive_state_ready
|
bool credential_ui_visible =
|
||||||
? session_helper_report_credential_ui_visible_
|
interactive_state_ready ? session_helper_report_credential_ui_visible_
|
||||||
: logon_ui_visible_;
|
: logon_ui_visible_;
|
||||||
bool unlock_ui_visible = interactive_state_ready
|
bool unlock_ui_visible = interactive_state_ready
|
||||||
? session_helper_report_unlock_ui_visible_
|
? session_helper_report_unlock_ui_visible_
|
||||||
@@ -1670,15 +1831,14 @@ std::string CrossDeskServiceHost::BuildStatusResponse() {
|
|||||||
bool interactive_logon_ui_visible =
|
bool interactive_logon_ui_visible =
|
||||||
interactive_state_ready ? session_helper_report_logon_ui_visible_
|
interactive_state_ready ? session_helper_report_logon_ui_visible_
|
||||||
: logon_ui_visible_;
|
: logon_ui_visible_;
|
||||||
bool interactive_session_locked =
|
bool interactive_session_locked = effective_session_locked ||
|
||||||
effective_session_locked || interactive_lock_screen_visible ||
|
interactive_lock_screen_visible ||
|
||||||
unlock_ui_visible;
|
unlock_ui_visible;
|
||||||
std::string interactive_input_desktop = EscapeJsonString(
|
std::string interactive_input_desktop = EscapeJsonString(
|
||||||
interactive_state_ready ? session_helper_report_input_desktop_
|
interactive_state_ready ? session_helper_report_input_desktop_
|
||||||
: input_desktop_name_);
|
: input_desktop_name_);
|
||||||
std::string interactive_stage = EscapeJsonString(
|
std::string interactive_stage = EscapeJsonString(DetermineInteractiveStage(
|
||||||
DetermineInteractiveStage(interactive_lock_screen_visible,
|
interactive_lock_screen_visible, credential_ui_visible,
|
||||||
credential_ui_visible,
|
|
||||||
interactive_secure_desktop_active));
|
interactive_secure_desktop_active));
|
||||||
std::ostringstream stream;
|
std::ostringstream stream;
|
||||||
stream << "{\"ok\":true,\"service\":\"CrossDeskService\""
|
stream << "{\"ok\":true,\"service\":\"CrossDeskService\""
|
||||||
@@ -1687,27 +1847,25 @@ std::string CrossDeskServiceHost::BuildStatusResponse() {
|
|||||||
<< ",\"session_locked\":" << (session_locked_ ? "true" : "false")
|
<< ",\"session_locked\":" << (session_locked_ ? "true" : "false")
|
||||||
<< ",\"interactive_state_ready\":"
|
<< ",\"interactive_state_ready\":"
|
||||||
<< (interactive_state_ready ? "true" : "false")
|
<< (interactive_state_ready ? "true" : "false")
|
||||||
<< ",\"interactive_state_source\":\""
|
<< ",\"interactive_state_source\":\"" << interactive_state_source
|
||||||
<< interactive_state_source << "\""
|
<< "\""
|
||||||
<< ",\"interactive_session_locked\":"
|
<< ",\"interactive_session_locked\":"
|
||||||
<< (interactive_session_locked ? "true" : "false")
|
<< (interactive_session_locked ? "true" : "false")
|
||||||
<< ",\"interactive_stage\":\"" << interactive_stage << "\""
|
<< ",\"interactive_stage\":\"" << interactive_stage << "\""
|
||||||
<< ",\"interactive_input_desktop\":\""
|
<< ",\"interactive_input_desktop\":\"" << interactive_input_desktop
|
||||||
<< interactive_input_desktop << "\""
|
<< "\""
|
||||||
<< ",\"interactive_lock_screen_visible\":"
|
<< ",\"interactive_lock_screen_visible\":"
|
||||||
<< (interactive_lock_screen_visible ? "true" : "false")
|
<< (interactive_lock_screen_visible ? "true" : "false")
|
||||||
<< ",\"interactive_logon_ui_visible\":"
|
<< ",\"interactive_logon_ui_visible\":"
|
||||||
<< (interactive_logon_ui_visible ? "true" : "false")
|
<< (interactive_logon_ui_visible ? "true" : "false")
|
||||||
<< ",\"interactive_secure_desktop_active\":"
|
<< ",\"interactive_secure_desktop_active\":"
|
||||||
<< (interactive_secure_desktop_active ? "true" : "false")
|
<< (interactive_secure_desktop_active ? "true" : "false")
|
||||||
<< ",\"unlock_ui_visible\":"
|
<< ",\"unlock_ui_visible\":" << (unlock_ui_visible ? "true" : "false")
|
||||||
<< (unlock_ui_visible ? "true" : "false")
|
|
||||||
<< ",\"credential_ui_visible\":"
|
<< ",\"credential_ui_visible\":"
|
||||||
<< (credential_ui_visible ? "true" : "false")
|
<< (credential_ui_visible ? "true" : "false")
|
||||||
<< ",\"password_box_visible\":"
|
<< ",\"password_box_visible\":"
|
||||||
<< (credential_ui_visible ? "true" : "false")
|
<< (credential_ui_visible ? "true" : "false")
|
||||||
<< ",\"logon_ui_visible\":"
|
<< ",\"logon_ui_visible\":" << (logon_ui_visible_ ? "true" : "false")
|
||||||
<< (logon_ui_visible_ ? "true" : "false")
|
|
||||||
<< ",\"secure_desktop_active\":"
|
<< ",\"secure_desktop_active\":"
|
||||||
<< (secure_desktop_active_ ? "true" : "false")
|
<< (secure_desktop_active_ ? "true" : "false")
|
||||||
<< ",\"input_desktop_available\":"
|
<< ",\"input_desktop_available\":"
|
||||||
@@ -1720,17 +1878,15 @@ std::string CrossDeskServiceHost::BuildStatusResponse() {
|
|||||||
<< ",\"session_helper_running\":"
|
<< ",\"session_helper_running\":"
|
||||||
<< (session_helper_running_ ? "true" : "false")
|
<< (session_helper_running_ ? "true" : "false")
|
||||||
<< ",\"session_helper_pid\":" << session_helper_process_id_
|
<< ",\"session_helper_pid\":" << session_helper_process_id_
|
||||||
<< ",\"session_helper_session_id\":"
|
<< ",\"session_helper_session_id\":" << session_helper_session_id_
|
||||||
<< session_helper_session_id_
|
|
||||||
<< ",\"session_helper_exit_code\":" << session_helper_exit_code_
|
<< ",\"session_helper_exit_code\":" << session_helper_exit_code_
|
||||||
<< ",\"session_helper_last_error\":\""
|
<< ",\"session_helper_last_error\":\"" << session_helper_last_error
|
||||||
<< session_helper_last_error << "\""
|
<< "\""
|
||||||
<< ",\"session_helper_last_error_code\":"
|
<< ",\"session_helper_last_error_code\":"
|
||||||
<< session_helper_last_error_code_
|
<< session_helper_last_error_code_ << ",\"session_helper_status_ok\":"
|
||||||
<< ",\"session_helper_status_ok\":"
|
|
||||||
<< (session_helper_status_ok_ ? "true" : "false")
|
<< (session_helper_status_ok_ ? "true" : "false")
|
||||||
<< ",\"session_helper_status_error\":\""
|
<< ",\"session_helper_status_error\":\"" << session_helper_status_error
|
||||||
<< session_helper_status_error << "\""
|
<< "\""
|
||||||
<< ",\"session_helper_status_error_code\":"
|
<< ",\"session_helper_status_error_code\":"
|
||||||
<< session_helper_status_error_code_
|
<< session_helper_status_error_code_
|
||||||
<< ",\"session_helper_report_session_id\":"
|
<< ",\"session_helper_report_session_id\":"
|
||||||
@@ -1760,17 +1916,15 @@ std::string CrossDeskServiceHost::BuildStatusResponse() {
|
|||||||
<< ",\"session_helper_report_state_age_ms\":"
|
<< ",\"session_helper_report_state_age_ms\":"
|
||||||
<< session_helper_report_state_age_ms_
|
<< session_helper_report_state_age_ms_
|
||||||
<< ",\"session_helper_report_uptime_ms\":"
|
<< ",\"session_helper_report_uptime_ms\":"
|
||||||
<< session_helper_report_uptime_ms_
|
<< session_helper_report_uptime_ms_ << ",\"session_helper_uptime_ms\":"
|
||||||
<< ",\"session_helper_uptime_ms\":"
|
|
||||||
<< (session_helper_started_at_tick_ >= started_at_tick_
|
<< (session_helper_started_at_tick_ >= started_at_tick_
|
||||||
? (GetTickCount64() - session_helper_started_at_tick_)
|
? (GetTickCount64() - session_helper_started_at_tick_)
|
||||||
: 0)
|
: 0)
|
||||||
<< ",\"secure_input_helper_path\":\""
|
<< ",\"secure_input_helper_path\":\"" << secure_input_helper_path
|
||||||
<< secure_input_helper_path << "\""
|
<< "\""
|
||||||
<< ",\"secure_input_helper_running\":"
|
<< ",\"secure_input_helper_running\":"
|
||||||
<< (secure_input_helper_running_ ? "true" : "false")
|
<< (secure_input_helper_running_ ? "true" : "false")
|
||||||
<< ",\"secure_input_helper_pid\":"
|
<< ",\"secure_input_helper_pid\":" << secure_input_helper_process_id_
|
||||||
<< secure_input_helper_process_id_
|
|
||||||
<< ",\"secure_input_helper_session_id\":"
|
<< ",\"secure_input_helper_session_id\":"
|
||||||
<< secure_input_helper_session_id_
|
<< secure_input_helper_session_id_
|
||||||
<< ",\"secure_input_helper_exit_code\":"
|
<< ",\"secure_input_helper_exit_code\":"
|
||||||
@@ -1783,8 +1937,7 @@ std::string CrossDeskServiceHost::BuildStatusResponse() {
|
|||||||
<< (secure_input_helper_started_at_tick_ >= started_at_tick_
|
<< (secure_input_helper_started_at_tick_ >= started_at_tick_
|
||||||
? (GetTickCount64() - secure_input_helper_started_at_tick_)
|
? (GetTickCount64() - secure_input_helper_started_at_tick_)
|
||||||
: 0)
|
: 0)
|
||||||
<< ",\"last_sas_success\":"
|
<< ",\"last_sas_success\":" << (last_sas_success_ ? "true" : "false")
|
||||||
<< (last_sas_success_ ? "true" : "false")
|
|
||||||
<< ",\"last_sas_error\":\"" << last_sas_error << "\""
|
<< ",\"last_sas_error\":\"" << last_sas_error << "\""
|
||||||
<< ",\"last_sas_error_code\":" << last_sas_error_code_
|
<< ",\"last_sas_error_code\":" << last_sas_error_code_
|
||||||
<< ",\"last_sas_uptime_ms\":"
|
<< ",\"last_sas_uptime_ms\":"
|
||||||
@@ -1821,8 +1974,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();
|
||||||
@@ -1856,7 +2009,9 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InstallCrossDeskService(const std::wstring& binary_path) {
|
bool InstallCrossDeskService(const std::wstring& binary_path) {
|
||||||
@@ -1869,7 +2024,7 @@ bool InstallCrossDeskService(const std::wstring& binary_path) {
|
|||||||
std::wstring service_command = L"\"" + binary_path + L"\" --service";
|
std::wstring service_command = L"\"" + binary_path + L"\" --service";
|
||||||
SC_HANDLE service = CreateServiceW(
|
SC_HANDLE service = CreateServiceW(
|
||||||
manager, kCrossDeskServiceName, kCrossDeskServiceDisplayName,
|
manager, kCrossDeskServiceName, kCrossDeskServiceDisplayName,
|
||||||
SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START,
|
SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS, SERVICE_DEMAND_START,
|
||||||
SERVICE_ERROR_NORMAL, service_command.c_str(), nullptr, nullptr, nullptr,
|
SERVICE_ERROR_NORMAL, service_command.c_str(), nullptr, nullptr, nullptr,
|
||||||
nullptr, nullptr);
|
nullptr, nullptr);
|
||||||
|
|
||||||
@@ -1882,17 +2037,18 @@ bool InstallCrossDeskService(const std::wstring& binary_path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
service = OpenServiceW(manager, kCrossDeskServiceName,
|
service = OpenServiceW(manager, kCrossDeskServiceName,
|
||||||
SERVICE_CHANGE_CONFIG | SERVICE_QUERY_STATUS);
|
SERVICE_CHANGE_CONFIG | SERVICE_QUERY_STATUS |
|
||||||
|
READ_CONTROL | WRITE_DAC);
|
||||||
if (service == nullptr) {
|
if (service == nullptr) {
|
||||||
LOG_ERROR("OpenServiceW failed, error={}", GetLastError());
|
LOG_ERROR("OpenServiceW failed, error={}", GetLastError());
|
||||||
CloseServiceHandle(manager);
|
CloseServiceHandle(manager);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ChangeServiceConfigW(
|
if (!ChangeServiceConfigW(service, SERVICE_NO_CHANGE, SERVICE_DEMAND_START,
|
||||||
service, SERVICE_NO_CHANGE, SERVICE_AUTO_START,
|
SERVICE_NO_CHANGE, service_command.c_str(),
|
||||||
SERVICE_NO_CHANGE, service_command.c_str(), nullptr, nullptr,
|
nullptr, nullptr, nullptr, nullptr, nullptr,
|
||||||
nullptr, nullptr, nullptr, kCrossDeskServiceDisplayName)) {
|
kCrossDeskServiceDisplayName)) {
|
||||||
LOG_ERROR("ChangeServiceConfigW failed, error={}", GetLastError());
|
LOG_ERROR("ChangeServiceConfigW failed, error={}", GetLastError());
|
||||||
CloseServiceHandle(service);
|
CloseServiceHandle(service);
|
||||||
CloseServiceHandle(manager);
|
CloseServiceHandle(manager);
|
||||||
@@ -1900,6 +2056,39 @@ bool InstallCrossDeskService(const std::wstring& binary_path) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!GrantCrossDeskServiceStartAccessToAuthenticatedUsers(service)) {
|
||||||
|
CloseServiceHandle(service);
|
||||||
|
CloseServiceHandle(manager);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
CloseServiceHandle(service);
|
||||||
|
CloseServiceHandle(manager);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsCrossDeskServiceInstalled() {
|
||||||
|
SC_HANDLE manager = OpenSCManagerW(nullptr, nullptr, SC_MANAGER_CONNECT);
|
||||||
|
if (manager == nullptr) {
|
||||||
|
LOG_ERROR("OpenSCManagerW failed, error={}", GetLastError());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
SC_HANDLE service =
|
||||||
|
OpenServiceW(manager, kCrossDeskServiceName, SERVICE_QUERY_STATUS);
|
||||||
|
if (service == nullptr) {
|
||||||
|
DWORD error = GetLastError();
|
||||||
|
CloseServiceHandle(manager);
|
||||||
|
if (error == ERROR_SERVICE_DOES_NOT_EXIST) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (error == ERROR_ACCESS_DENIED) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
LOG_ERROR("OpenServiceW failed, error={}", error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
CloseServiceHandle(service);
|
CloseServiceHandle(service);
|
||||||
CloseServiceHandle(manager);
|
CloseServiceHandle(manager);
|
||||||
return true;
|
return true;
|
||||||
@@ -1915,7 +2104,10 @@ bool StartCrossDeskService() {
|
|||||||
SC_HANDLE service =
|
SC_HANDLE service =
|
||||||
OpenServiceW(manager, kCrossDeskServiceName, SERVICE_START);
|
OpenServiceW(manager, kCrossDeskServiceName, SERVICE_START);
|
||||||
if (service == nullptr) {
|
if (service == nullptr) {
|
||||||
LOG_ERROR("OpenServiceW failed, error={}", GetLastError());
|
DWORD error = GetLastError();
|
||||||
|
if (error != ERROR_SERVICE_DOES_NOT_EXIST) {
|
||||||
|
LOG_ERROR("OpenServiceW failed, error={}", error);
|
||||||
|
}
|
||||||
CloseServiceHandle(manager);
|
CloseServiceHandle(manager);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -1973,8 +2165,8 @@ bool StopCrossDeskService(DWORD timeout_ms) {
|
|||||||
DWORD deadline = GetTickCount() + timeout_ms;
|
DWORD deadline = GetTickCount() + timeout_ms;
|
||||||
while (GetTickCount() < deadline) {
|
while (GetTickCount() < deadline) {
|
||||||
if (!QueryServiceStatusEx(service, SC_STATUS_PROCESS_INFO,
|
if (!QueryServiceStatusEx(service, SC_STATUS_PROCESS_INFO,
|
||||||
reinterpret_cast<LPBYTE>(&status),
|
reinterpret_cast<LPBYTE>(&status), sizeof(status),
|
||||||
sizeof(status), &bytes_needed)) {
|
&bytes_needed)) {
|
||||||
LOG_ERROR("QueryServiceStatusEx failed, error={}", GetLastError());
|
LOG_ERROR("QueryServiceStatusEx failed, error={}", GetLastError());
|
||||||
CloseServiceHandle(service);
|
CloseServiceHandle(service);
|
||||||
CloseServiceHandle(manager);
|
CloseServiceHandle(manager);
|
||||||
@@ -2001,7 +2193,8 @@ bool UninstallCrossDeskService() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
SC_HANDLE service = OpenServiceW(manager, kCrossDeskServiceName,
|
SC_HANDLE service =
|
||||||
|
OpenServiceW(manager, kCrossDeskServiceName,
|
||||||
DELETE | SERVICE_STOP | SERVICE_QUERY_STATUS);
|
DELETE | SERVICE_STOP | SERVICE_QUERY_STATUS);
|
||||||
if (service == nullptr) {
|
if (service == nullptr) {
|
||||||
DWORD error = GetLastError();
|
DWORD error = GetLastError();
|
||||||
@@ -2031,9 +2224,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,
|
||||||
|
|||||||
@@ -1,8 +1,15 @@
|
|||||||
#ifndef _CROSSDESK_SERVICE_HOST_H_
|
/*
|
||||||
#define _CROSSDESK_SERVICE_HOST_H_
|
* @Author: DI JUNKUN
|
||||||
|
* @Date: 2026-04-21
|
||||||
|
* Copyright (c) 2026 by DI JUNKUN, All Rights Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _SERVICE_HOST_H_
|
||||||
|
#define _SERVICE_HOST_H_
|
||||||
|
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
@@ -10,8 +17,7 @@
|
|||||||
namespace crossdesk {
|
namespace crossdesk {
|
||||||
|
|
||||||
inline constexpr wchar_t kCrossDeskServiceName[] = L"CrossDeskService";
|
inline constexpr wchar_t kCrossDeskServiceName[] = L"CrossDeskService";
|
||||||
inline constexpr wchar_t kCrossDeskServiceDisplayName[] =
|
inline constexpr wchar_t kCrossDeskServiceDisplayName[] = L"CrossDesk Service";
|
||||||
L"CrossDesk Service";
|
|
||||||
inline constexpr wchar_t kCrossDeskServicePipeName[] =
|
inline constexpr wchar_t kCrossDeskServicePipeName[] =
|
||||||
L"\\\\.\\pipe\\CrossDeskService";
|
L"\\\\.\\pipe\\CrossDeskService";
|
||||||
|
|
||||||
@@ -28,6 +34,7 @@ class CrossDeskServiceHost {
|
|||||||
int InitializeRuntime();
|
int InitializeRuntime();
|
||||||
void ShutdownRuntime();
|
void ShutdownRuntime();
|
||||||
void RequestStop();
|
void RequestStop();
|
||||||
|
void ClientProcessMonitorLoop();
|
||||||
void ReportServiceStatus(DWORD current_state, DWORD win32_exit_code,
|
void ReportServiceStatus(DWORD current_state, DWORD win32_exit_code,
|
||||||
DWORD wait_hint);
|
DWORD wait_hint);
|
||||||
void IpcServerLoop();
|
void IpcServerLoop();
|
||||||
@@ -54,19 +61,21 @@ 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);
|
||||||
|
|
||||||
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);
|
||||||
static DWORD WINAPI ServiceControlHandler(DWORD control, DWORD event_type,
|
static DWORD WINAPI ServiceControlHandler(DWORD control, DWORD event_type,
|
||||||
LPVOID event_data,
|
LPVOID event_data, LPVOID context);
|
||||||
LPVOID context);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SERVICE_STATUS_HANDLE status_handle_ = nullptr;
|
SERVICE_STATUS_HANDLE status_handle_ = nullptr;
|
||||||
SERVICE_STATUS service_status_{};
|
SERVICE_STATUS service_status_{};
|
||||||
HANDLE stop_event_ = nullptr;
|
HANDLE stop_event_ = nullptr;
|
||||||
std::thread ipc_thread_;
|
std::thread ipc_thread_;
|
||||||
|
std::thread client_process_monitor_thread_;
|
||||||
std::mutex state_mutex_;
|
std::mutex state_mutex_;
|
||||||
DWORD active_session_id_ = 0xFFFFFFFF;
|
DWORD active_session_id_ = 0xFFFFFFFF;
|
||||||
DWORD process_session_id_ = 0xFFFFFFFF;
|
DWORD process_session_id_ = 0xFFFFFFFF;
|
||||||
@@ -124,6 +133,7 @@ class CrossDeskServiceHost {
|
|||||||
static CrossDeskServiceHost* instance_;
|
static CrossDeskServiceHost* instance_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool IsCrossDeskServiceInstalled();
|
||||||
bool InstallCrossDeskService(const std::wstring& binary_path);
|
bool InstallCrossDeskService(const std::wstring& binary_path);
|
||||||
bool UninstallCrossDeskService();
|
bool UninstallCrossDeskService();
|
||||||
bool StartCrossDeskService();
|
bool StartCrossDeskService();
|
||||||
@@ -131,6 +141,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,
|
||||||
|
|||||||
@@ -1,17 +1,16 @@
|
|||||||
|
// clang-format off
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
|
|
||||||
#include <nlohmann/json.hpp>
|
|
||||||
|
|
||||||
#include <libyuv.h>
|
|
||||||
|
|
||||||
#include <TlHelp32.h>
|
#include <TlHelp32.h>
|
||||||
|
// clang-format on
|
||||||
#include <WtsApi32.h>
|
#include <WtsApi32.h>
|
||||||
|
#include <libyuv.h>
|
||||||
#include <sddl.h>
|
#include <sddl.h>
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
@@ -23,8 +22,8 @@
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
using crossdesk::InitLogger;
|
|
||||||
using crossdesk::get_logger;
|
using crossdesk::get_logger;
|
||||||
|
using crossdesk::InitLogger;
|
||||||
using Json = nlohmann::json;
|
using Json = nlohmann::json;
|
||||||
|
|
||||||
struct InputDesktopInfo {
|
struct InputDesktopInfo {
|
||||||
@@ -76,8 +75,7 @@ struct PipeSecurityAttributes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool Initialize() {
|
bool Initialize() {
|
||||||
constexpr wchar_t kPipeSddl[] =
|
constexpr wchar_t kPipeSddl[] = L"D:(A;;GA;;;SY)(A;;GA;;;BA)(A;;GRGW;;;AU)";
|
||||||
L"D:(A;;GA;;;SY)(A;;GA;;;BA)(A;;GRGW;;;AU)";
|
|
||||||
if (!ConvertStringSecurityDescriptorToSecurityDescriptorW(
|
if (!ConvertStringSecurityDescriptorToSecurityDescriptorW(
|
||||||
kPipeSddl, SDDL_REVISION_1, &security_descriptor_, nullptr)) {
|
kPipeSddl, SDDL_REVISION_1, &security_descriptor_, nullptr)) {
|
||||||
return false;
|
return false;
|
||||||
@@ -100,7 +98,8 @@ void InitializeHelperLogger() {
|
|||||||
static std::once_flag once_flag;
|
static std::once_flag once_flag;
|
||||||
std::call_once(once_flag, []() {
|
std::call_once(once_flag, []() {
|
||||||
crossdesk::PathManager path_manager("CrossDesk");
|
crossdesk::PathManager path_manager("CrossDesk");
|
||||||
std::filesystem::path log_path = path_manager.GetLogPath() / "session_helper";
|
std::filesystem::path log_path =
|
||||||
|
path_manager.GetLogPath() / "session_helper";
|
||||||
if (!log_path.empty() && path_manager.CreateDirectories(log_path)) {
|
if (!log_path.empty() && path_manager.CreateDirectories(log_path)) {
|
||||||
InitLogger(log_path.string());
|
InitLogger(log_path.string());
|
||||||
return;
|
return;
|
||||||
@@ -114,8 +113,8 @@ std::wstring Utf8ToWide(const std::string& value) {
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
int size_needed = MultiByteToWideChar(CP_UTF8, 0, value.c_str(), -1,
|
int size_needed =
|
||||||
nullptr, 0);
|
MultiByteToWideChar(CP_UTF8, 0, value.c_str(), -1, nullptr, 0);
|
||||||
if (size_needed <= 1) {
|
if (size_needed <= 1) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@@ -132,15 +131,15 @@ std::string WideToUtf8(const std::wstring& value) {
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
int size_needed = WideCharToMultiByte(CP_UTF8, 0, value.c_str(), -1,
|
int size_needed = WideCharToMultiByte(CP_UTF8, 0, value.c_str(), -1, nullptr,
|
||||||
nullptr, 0, nullptr, nullptr);
|
0, nullptr, nullptr);
|
||||||
if (size_needed <= 1) {
|
if (size_needed <= 1) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string result(static_cast<size_t>(size_needed), '\0');
|
std::string result(static_cast<size_t>(size_needed), '\0');
|
||||||
WideCharToMultiByte(CP_UTF8, 0, value.c_str(), -1, result.data(),
|
WideCharToMultiByte(CP_UTF8, 0, value.c_str(), -1, result.data(), size_needed,
|
||||||
size_needed, nullptr, nullptr);
|
nullptr, nullptr);
|
||||||
result.pop_back();
|
result.pop_back();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -330,8 +329,7 @@ std::string BuildHelperStatusResponse(HelperState* helper_state) {
|
|||||||
json["interactive_stage"] = DetermineInteractiveStage(
|
json["interactive_stage"] = DetermineInteractiveStage(
|
||||||
helper_state->lock_app_visible, credential_ui_visible,
|
helper_state->lock_app_visible, credential_ui_visible,
|
||||||
helper_state->secure_desktop_active);
|
helper_state->secure_desktop_active);
|
||||||
json["uptime_ms"] =
|
json["uptime_ms"] = GetTickCount64() >= helper_state->started_at_tick
|
||||||
GetTickCount64() >= helper_state->started_at_tick
|
|
||||||
? (GetTickCount64() - helper_state->started_at_tick)
|
? (GetTickCount64() - helper_state->started_at_tick)
|
||||||
: 0;
|
: 0;
|
||||||
json["state_age_ms"] =
|
json["state_age_ms"] =
|
||||||
@@ -349,12 +347,14 @@ void HelperIpcServerLoop(HANDLE stop_event, DWORD session_id,
|
|||||||
pipe_attributes = security_attributes.get();
|
pipe_attributes = security_attributes.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring pipe_name = crossdesk::GetCrossDeskSessionHelperPipeName(session_id);
|
std::wstring pipe_name =
|
||||||
while (stop_event == nullptr || WaitForSingleObject(stop_event, 0) != WAIT_OBJECT_0) {
|
crossdesk::GetCrossDeskSessionHelperPipeName(session_id);
|
||||||
|
while (stop_event == nullptr ||
|
||||||
|
WaitForSingleObject(stop_event, 0) != WAIT_OBJECT_0) {
|
||||||
HANDLE pipe = CreateNamedPipeW(
|
HANDLE pipe = CreateNamedPipeW(
|
||||||
pipe_name.c_str(), PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED,
|
pipe_name.c_str(), PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED,
|
||||||
PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, 1, 4096, 4096,
|
PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, 1, 4096, 4096, 0,
|
||||||
0, pipe_attributes);
|
pipe_attributes);
|
||||||
if (pipe == INVALID_HANDLE_VALUE) {
|
if (pipe == INVALID_HANDLE_VALUE) {
|
||||||
LOG_ERROR("CreateNamedPipeW failed in helper, error={}", GetLastError());
|
LOG_ERROR("CreateNamedPipeW failed in helper, error={}", GetLastError());
|
||||||
if (stop_event != nullptr) {
|
if (stop_event != nullptr) {
|
||||||
@@ -465,10 +465,9 @@ bool EnsureThreadDesktop(const wchar_t* desktop_name,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
HDESK desktop = OpenDesktopW(
|
HDESK desktop = OpenDesktopW(desktop_name, 0, FALSE,
|
||||||
desktop_name, 0, FALSE,
|
DESKTOP_CREATEWINDOW | DESKTOP_WRITEOBJECTS |
|
||||||
DESKTOP_CREATEWINDOW | DESKTOP_WRITEOBJECTS | DESKTOP_READOBJECTS |
|
DESKTOP_READOBJECTS | DESKTOP_SWITCHDESKTOP);
|
||||||
DESKTOP_SWITCHDESKTOP);
|
|
||||||
if (desktop == nullptr) {
|
if (desktop == nullptr) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -486,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) {
|
||||||
@@ -515,14 +550,19 @@ int InjectKeyboardInput(int key_code, bool is_down) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool ParseSecureInputKeyboardCommand(const std::string& command,
|
bool ParseSecureInputKeyboardCommand(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;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command.rfind(crossdesk::kCrossDeskSecureInputKeyboardCommandPrefix,
|
*scan_code_out = 0;
|
||||||
0) != 0) {
|
*extended_out = false;
|
||||||
|
|
||||||
|
if (command.rfind(crossdesk::kCrossDeskSecureInputKeyboardCommandPrefix, 0) !=
|
||||||
|
0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -539,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;
|
||||||
@@ -622,8 +695,7 @@ bool ParseSecureInputCaptureCommand(const std::string& command,
|
|||||||
for (int index = 0; index < 5; ++index) {
|
for (int index = 0; index < 5; ++index) {
|
||||||
const size_t separator = command.find(':', token_begin);
|
const size_t separator = command.find(':', token_begin);
|
||||||
const bool is_last = index == 4;
|
const bool is_last = index == 4;
|
||||||
const size_t token_end =
|
const size_t token_end = is_last ? command.size() : separator;
|
||||||
is_last ? command.size() : separator;
|
|
||||||
if (token_end == std::string::npos || token_end <= token_begin) {
|
if (token_end == std::string::npos || token_end <= token_begin) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -734,8 +806,7 @@ std::vector<uint8_t> CaptureSecureDesktopFrame(
|
|||||||
const DWORD error = GetLastError();
|
const DWORD error = GetLastError();
|
||||||
DeleteDC(mem_dc);
|
DeleteDC(mem_dc);
|
||||||
ReleaseDC(nullptr, screen_dc);
|
ReleaseDC(nullptr, screen_dc);
|
||||||
return BuildTextResponseBytes(
|
return BuildTextResponseBytes(BuildErrorJson("create_dib_failed", error));
|
||||||
BuildErrorJson("create_dib_failed", error));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HGDIOBJ old_bitmap = SelectObject(mem_dc, dib);
|
HGDIOBJ old_bitmap = SelectObject(mem_dc, dib);
|
||||||
@@ -746,8 +817,7 @@ std::vector<uint8_t> CaptureSecureDesktopFrame(
|
|||||||
DeleteObject(dib);
|
DeleteObject(dib);
|
||||||
DeleteDC(mem_dc);
|
DeleteDC(mem_dc);
|
||||||
ReleaseDC(nullptr, screen_dc);
|
ReleaseDC(nullptr, screen_dc);
|
||||||
return BuildTextResponseBytes(
|
return BuildTextResponseBytes(BuildErrorJson("bitblt_failed", error));
|
||||||
BuildErrorJson("bitblt_failed", error));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request.show_cursor) {
|
if (request.show_cursor) {
|
||||||
@@ -757,8 +827,8 @@ std::vector<uint8_t> CaptureSecureDesktopFrame(
|
|||||||
cursor_info.hCursor != nullptr) {
|
cursor_info.hCursor != nullptr) {
|
||||||
const int cursor_x = cursor_info.ptScreenPos.x - request.left;
|
const int cursor_x = cursor_info.ptScreenPos.x - request.left;
|
||||||
const int cursor_y = cursor_info.ptScreenPos.y - request.top;
|
const int cursor_y = cursor_info.ptScreenPos.y - request.top;
|
||||||
if (cursor_x >= -64 && cursor_y >= -64 &&
|
if (cursor_x >= -64 && cursor_y >= -64 && cursor_x < request.width + 64 &&
|
||||||
cursor_x < request.width + 64 && cursor_y < request.height + 64) {
|
cursor_y < request.height + 64) {
|
||||||
DrawIconEx(mem_dc, cursor_x, cursor_y, cursor_info.hCursor, 0, 0, 0,
|
DrawIconEx(mem_dc, cursor_x, cursor_y, cursor_info.hCursor, 0, 0, 0,
|
||||||
nullptr, DI_NORMAL);
|
nullptr, DI_NORMAL);
|
||||||
}
|
}
|
||||||
@@ -790,7 +860,8 @@ std::vector<uint8_t> CaptureSecureDesktopFrame(
|
|||||||
header.top = request.top;
|
header.top = request.top;
|
||||||
header.width = static_cast<uint32_t>(request.width);
|
header.width = static_cast<uint32_t>(request.width);
|
||||||
header.height = static_cast<uint32_t>(request.height);
|
header.height = static_cast<uint32_t>(request.height);
|
||||||
header.payload_size = static_cast<uint32_t>(capture_buffers->nv12_frame.size());
|
header.payload_size =
|
||||||
|
static_cast<uint32_t>(capture_buffers->nv12_frame.size());
|
||||||
|
|
||||||
std::vector<uint8_t> response(sizeof(header) +
|
std::vector<uint8_t> response(sizeof(header) +
|
||||||
capture_buffers->nv12_frame.size());
|
capture_buffers->nv12_frame.size());
|
||||||
@@ -804,20 +875,24 @@ std::vector<uint8_t> CaptureSecureDesktopFrame(
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::vector<uint8_t> HandleSecureInputHelperCommand(
|
std::vector<uint8_t> HandleSecureInputHelperCommand(
|
||||||
const std::string& command,
|
const std::string& command, SecureCaptureBuffers* capture_buffers) {
|
||||||
SecureCaptureBuffers* capture_buffers) {
|
|
||||||
if (command == "ping") {
|
if (command == "ping") {
|
||||||
return BuildTextResponseBytes("{\"ok\":true,\"reply\":\"pong\"}");
|
return BuildTextResponseBytes("{\"ok\":true,\"reply\":\"pong\"}");
|
||||||
}
|
}
|
||||||
|
|
||||||
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={}, err={}",
|
"Secure input helper SendInput failed for key_code={}, is_down={}, "
|
||||||
key_code, is_down, inject_result);
|
"scan_code={}, extended={}, err={}",
|
||||||
|
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)));
|
||||||
}
|
}
|
||||||
@@ -827,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());
|
||||||
}
|
}
|
||||||
@@ -836,7 +913,8 @@ std::vector<uint8_t> HandleSecureInputHelperCommand(
|
|||||||
const int inject_result = InjectMouseInput(mouse_request);
|
const int inject_result = InjectMouseInput(mouse_request);
|
||||||
if (inject_result != 0) {
|
if (inject_result != 0) {
|
||||||
LOG_WARN(
|
LOG_WARN(
|
||||||
"Secure input helper SendInput failed for mouse x={}, y={}, wheel={}, flag={}, err={}",
|
"Secure input helper SendInput failed for mouse x={}, y={}, "
|
||||||
|
"wheel={}, flag={}, err={}",
|
||||||
mouse_request.x, mouse_request.y, mouse_request.wheel,
|
mouse_request.x, mouse_request.y, mouse_request.wheel,
|
||||||
mouse_request.flag, inject_result);
|
mouse_request.flag, inject_result);
|
||||||
return BuildTextResponseBytes(BuildErrorJson(
|
return BuildTextResponseBytes(BuildErrorJson(
|
||||||
@@ -1010,7 +1088,9 @@ int main(int argc, char* argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (run_secure_input_helper) {
|
if (run_secure_input_helper) {
|
||||||
LOG_INFO("Secure input helper starting: pid={}, current_session_id={}, expected_session_id={}",
|
LOG_INFO(
|
||||||
|
"Secure input helper starting: pid={}, current_session_id={}, "
|
||||||
|
"expected_session_id={}",
|
||||||
GetCurrentProcessId(), current_session_id, expected_session_id);
|
GetCurrentProcessId(), current_session_id, expected_session_id);
|
||||||
if (expected_session_id != 0xFFFFFFFF &&
|
if (expected_session_id != 0xFFFFFFFF &&
|
||||||
expected_session_id != current_session_id) {
|
expected_session_id != current_session_id) {
|
||||||
@@ -1020,7 +1100,8 @@ int main(int argc, char* argv[]) {
|
|||||||
|
|
||||||
HDESK secure_desktop = nullptr;
|
HDESK secure_desktop = nullptr;
|
||||||
if (!EnsureThreadDesktop(L"Winlogon", &secure_desktop)) {
|
if (!EnsureThreadDesktop(L"Winlogon", &secure_desktop)) {
|
||||||
LOG_ERROR("Failed to switch secure input helper to Winlogon desktop, error={}",
|
LOG_ERROR(
|
||||||
|
"Failed to switch secure input helper to Winlogon desktop, error={}",
|
||||||
GetLastError());
|
GetLastError());
|
||||||
if (stop_event != nullptr) {
|
if (stop_event != nullptr) {
|
||||||
CloseHandle(stop_event);
|
CloseHandle(stop_event);
|
||||||
@@ -1042,7 +1123,9 @@ int main(int argc, char* argv[]) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_INFO("Session helper starting: pid={}, current_session_id={}, expected_session_id={}",
|
LOG_INFO(
|
||||||
|
"Session helper starting: pid={}, current_session_id={}, "
|
||||||
|
"expected_session_id={}",
|
||||||
GetCurrentProcessId(), current_session_id, expected_session_id);
|
GetCurrentProcessId(), current_session_id, expected_session_id);
|
||||||
|
|
||||||
HelperState helper_state;
|
HelperState helper_state;
|
||||||
@@ -1087,9 +1170,11 @@ int main(int argc, char* argv[]) {
|
|||||||
session_locked != last_session_locked ||
|
session_locked != last_session_locked ||
|
||||||
lock_app_visible != last_lock_app ||
|
lock_app_visible != last_lock_app ||
|
||||||
logon_ui_running != last_logon_ui ||
|
logon_ui_running != last_logon_ui ||
|
||||||
secure_desktop_active != last_secure_desktop ||
|
secure_desktop_active != last_secure_desktop || stage != last_stage) {
|
||||||
stage != last_stage) {
|
LOG_INFO(
|
||||||
LOG_INFO("Session helper state: session_id={}, input_desktop='{}', session_locked={}, lock_app_visible={}, logon_ui_running={}, secure_desktop_active={}, stage={}",
|
"Session helper state: session_id={}, input_desktop='{}', "
|
||||||
|
"session_locked={}, lock_app_visible={}, logon_ui_running={}, "
|
||||||
|
"secure_desktop_active={}, stage={}",
|
||||||
current_session_id, desktop_name, session_locked, lock_app_visible,
|
current_session_id, desktop_name, session_locked, lock_app_visible,
|
||||||
logon_ui_running, secure_desktop_active, stage);
|
logon_ui_running, secure_desktop_active, stage);
|
||||||
last_desktop_name = desktop_name;
|
last_desktop_name = desktop_name;
|
||||||
@@ -1100,8 +1185,9 @@ int main(int argc, char* argv[]) {
|
|||||||
last_stage = stage;
|
last_stage = stage;
|
||||||
}
|
}
|
||||||
|
|
||||||
DWORD wait_result =
|
DWORD wait_result = stop_event != nullptr
|
||||||
stop_event != nullptr ? WaitForSingleObject(stop_event, 1000) : WAIT_TIMEOUT;
|
? WaitForSingleObject(stop_event, 1000)
|
||||||
|
: WAIT_TIMEOUT;
|
||||||
if (wait_result == WAIT_OBJECT_0) {
|
if (wait_result == WAIT_OBJECT_0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
#ifndef _CROSSDESK_SESSION_HELPER_SHARED_H_
|
/*
|
||||||
#define _CROSSDESK_SESSION_HELPER_SHARED_H_
|
* @Author: DI JUNKUN
|
||||||
|
* @Date: 2026-04-21
|
||||||
|
* Copyright (c) 2026 by DI JUNKUN, All Rights Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _SESSION_HELPER_SHARED_H_
|
||||||
|
#define _SESSION_HELPER_SHARED_H_
|
||||||
|
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
|
|
||||||
@@ -15,12 +21,9 @@ inline constexpr wchar_t kCrossDeskSecureInputHelperPipePrefix[] =
|
|||||||
inline constexpr char kCrossDeskSessionHelperStatusCommand[] = "status";
|
inline constexpr char kCrossDeskSessionHelperStatusCommand[] = "status";
|
||||||
inline constexpr char kCrossDeskSecureInputKeyboardCommandPrefix[] =
|
inline constexpr char kCrossDeskSecureInputKeyboardCommandPrefix[] =
|
||||||
"keyboard:";
|
"keyboard:";
|
||||||
inline constexpr char kCrossDeskSecureInputMouseCommandPrefix[] =
|
inline constexpr char kCrossDeskSecureInputMouseCommandPrefix[] = "mouse:";
|
||||||
"mouse:";
|
inline constexpr char kCrossDeskSecureInputCaptureCommandPrefix[] = "capture:";
|
||||||
inline constexpr char kCrossDeskSecureInputCaptureCommandPrefix[] =
|
inline constexpr DWORD kCrossDeskSecureInputPipeBufferBytes = 16 * 1024 * 1024;
|
||||||
"capture:";
|
|
||||||
inline constexpr DWORD kCrossDeskSecureInputPipeBufferBytes =
|
|
||||||
16 * 1024 * 1024;
|
|
||||||
inline constexpr uint32_t kCrossDeskSecureDesktopFrameMagic = 0x50444358;
|
inline constexpr uint32_t kCrossDeskSecureDesktopFrameMagic = 0x50444358;
|
||||||
inline constexpr uint32_t kCrossDeskSecureDesktopFrameVersion = 1;
|
inline constexpr uint32_t kCrossDeskSecureDesktopFrameVersion = 1;
|
||||||
|
|
||||||
|
|||||||
+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",
|
||||||
|
|||||||
+1
-1
@@ -192,7 +192,7 @@ function setup_targets()
|
|||||||
add_files("src/service/windows/service_host.cpp")
|
add_files("src/service/windows/service_host.cpp")
|
||||||
add_includedirs("src/service/windows", {public = true})
|
add_includedirs("src/service/windows", {public = true})
|
||||||
add_links("Advapi32", "Wtsapi32", "Ole32", "Userenv")
|
add_links("Advapi32", "Wtsapi32", "Ole32", "Userenv")
|
||||||
add_deps("wgc_plugin")
|
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