mirror of
https://github.com/kunkundi/crossdesk.git
synced 2026-03-24 09:07:31 +08:00
Compare commits
27 Commits
v1.2.3
...
ef02403da6
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ef02403da6 | ||
|
|
adfab363c1 | ||
|
|
123d4cf595 | ||
|
|
19feb8ff49 | ||
|
|
9223bf9d2d | ||
|
|
11b5f87841 | ||
|
|
cea59fb453 | ||
|
|
3a179bf480 | ||
|
|
b9c53024f1 | ||
|
|
62b37ad698 | ||
|
|
de56cd5d3b | ||
|
|
8d9d78185a | ||
|
|
b10a6512fe | ||
|
|
a94da8802f | ||
|
|
4e6f82d00c | ||
|
|
5e2ad99ec0 | ||
|
|
8ab50ea362 | ||
|
|
25e9958a69 | ||
|
|
410ea8b96b | ||
|
|
e656664cad | ||
|
|
0e6cee0961 | ||
|
|
42506b8c1d | ||
|
|
e35365d162 | ||
|
|
bf1c0f796d | ||
|
|
547532b28c | ||
|
|
a91e23abf6 | ||
|
|
2b324f636b |
75
.github/workflows/build.yml
vendored
75
.github/workflows/build.yml
vendored
@@ -15,76 +15,28 @@ env:
|
|||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
# Linux amd64
|
build-linux:
|
||||||
build-linux-amd64:
|
name: Build Linux (${{ matrix.arch }})
|
||||||
name: Build on Ubuntu 22.04 amd64
|
runs-on: ${{ matrix.runner }}
|
||||||
runs-on: ubuntu-22.04
|
|
||||||
container:
|
|
||||||
image: crossdesk/ubuntu20.04:latest
|
|
||||||
options: --user root
|
|
||||||
steps:
|
|
||||||
- name: Extract version number
|
|
||||||
id: version
|
|
||||||
run: |
|
|
||||||
VERSION="${GITHUB_REF##*/}"
|
|
||||||
VERSION_NUM="${VERSION#v}"
|
|
||||||
echo "VERSION_NUM=${VERSION_NUM}" >> $GITHUB_ENV
|
|
||||||
|
|
||||||
- name: Set legal Debian version
|
|
||||||
shell: bash
|
|
||||||
id: set_deb_version
|
|
||||||
run: |
|
|
||||||
SHORT_SHA=$(echo "${GITHUB_SHA}" | cut -c1-7)
|
|
||||||
BUILD_DATE=$(TZ=Asia/Shanghai date +%Y%m%d)
|
|
||||||
if [[ ! "${VERSION_NUM}" =~ ^[0-9] ]]; then
|
|
||||||
LEGAL_VERSION="v0.0.0-${VERSION_NUM}-${BUILD_DATE}-${SHORT_SHA}"
|
|
||||||
else
|
|
||||||
LEGAL_VERSION="v${VERSION_NUM}-${BUILD_DATE}-${SHORT_SHA}"
|
|
||||||
fi
|
|
||||||
echo "LEGAL_VERSION=${LEGAL_VERSION}" >> $GITHUB_ENV
|
|
||||||
echo "BUILD_DATE=${BUILD_DATE}" >> $GITHUB_ENV
|
|
||||||
|
|
||||||
- name: Checkout code
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
submodules: recursive
|
|
||||||
|
|
||||||
- name: Build CrossDesk
|
|
||||||
env:
|
|
||||||
CUDA_PATH: /usr/local/cuda
|
|
||||||
XMAKE_GLOBALDIR: /data
|
|
||||||
run: |
|
|
||||||
ls -la $XMAKE_GLOBALDIR
|
|
||||||
xmake f --CROSSDESK_VERSION=${LEGAL_VERSION} --USE_CUDA=true --root -y
|
|
||||||
xmake b -vy --root crossdesk
|
|
||||||
|
|
||||||
- name: Package
|
|
||||||
run: |
|
|
||||||
chmod +x ./scripts/linux/pkg_amd64.sh
|
|
||||||
./scripts/linux/pkg_amd64.sh ${LEGAL_VERSION}
|
|
||||||
|
|
||||||
- name: Upload artifact
|
|
||||||
uses: actions/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: crossdesk-linux-amd64-${{ env.LEGAL_VERSION }}
|
|
||||||
path: ${{ github.workspace }}/crossdesk-linux-amd64-${{ env.LEGAL_VERSION }}.deb
|
|
||||||
|
|
||||||
# Linux arm64
|
|
||||||
build-linux-arm64:
|
|
||||||
name: Build on Ubuntu 22.04 arm64
|
|
||||||
runs-on: ubuntu-22.04-arm
|
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
|
- arch: amd64
|
||||||
|
runner: ubuntu-22.04
|
||||||
|
image: crossdesk/ubuntu20.04:latest
|
||||||
|
package_script: ./scripts/linux/pkg_amd64.sh
|
||||||
|
|
||||||
- arch: arm64
|
- arch: arm64
|
||||||
|
runner: ubuntu-22.04-arm
|
||||||
image: crossdesk/ubuntu20.04-arm64v8:latest
|
image: crossdesk/ubuntu20.04-arm64v8:latest
|
||||||
package_script: ./scripts/linux/pkg_arm64.sh
|
package_script: ./scripts/linux/pkg_arm64.sh
|
||||||
|
|
||||||
container:
|
container:
|
||||||
image: ${{ matrix.image }}
|
image: ${{ matrix.image }}
|
||||||
options: --user root
|
options: --user root
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Extract version number
|
- name: Extract version number
|
||||||
id: version
|
|
||||||
run: |
|
run: |
|
||||||
VERSION="${GITHUB_REF##*/}"
|
VERSION="${GITHUB_REF##*/}"
|
||||||
VERSION_NUM="${VERSION#v}"
|
VERSION_NUM="${VERSION#v}"
|
||||||
@@ -92,15 +44,16 @@ jobs:
|
|||||||
|
|
||||||
- name: Set legal Debian version
|
- name: Set legal Debian version
|
||||||
shell: bash
|
shell: bash
|
||||||
id: set_deb_version
|
|
||||||
run: |
|
run: |
|
||||||
SHORT_SHA=$(echo "${GITHUB_SHA}" | cut -c1-7)
|
SHORT_SHA=$(echo "${GITHUB_SHA}" | cut -c1-7)
|
||||||
BUILD_DATE=$(TZ=Asia/Shanghai date +%Y%m%d)
|
BUILD_DATE=$(TZ=Asia/Shanghai date +%Y%m%d)
|
||||||
|
|
||||||
if [[ ! "${VERSION_NUM}" =~ ^[0-9] ]]; then
|
if [[ ! "${VERSION_NUM}" =~ ^[0-9] ]]; then
|
||||||
LEGAL_VERSION="v0.0.0-${VERSION_NUM}-${BUILD_DATE}-${SHORT_SHA}"
|
LEGAL_VERSION="v0.0.0-${VERSION_NUM}-${BUILD_DATE}-${SHORT_SHA}"
|
||||||
else
|
else
|
||||||
LEGAL_VERSION="v${VERSION_NUM}-${BUILD_DATE}-${SHORT_SHA}"
|
LEGAL_VERSION="v${VERSION_NUM}-${BUILD_DATE}-${SHORT_SHA}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "LEGAL_VERSION=${LEGAL_VERSION}" >> $GITHUB_ENV
|
echo "LEGAL_VERSION=${LEGAL_VERSION}" >> $GITHUB_ENV
|
||||||
echo "BUILD_DATE=${BUILD_DATE}" >> $GITHUB_ENV
|
echo "BUILD_DATE=${BUILD_DATE}" >> $GITHUB_ENV
|
||||||
|
|
||||||
@@ -313,7 +266,7 @@ jobs:
|
|||||||
name: Publish Release
|
name: Publish Release
|
||||||
if: startsWith(github.ref, 'refs/tags/v')
|
if: startsWith(github.ref, 'refs/tags/v')
|
||||||
needs:
|
needs:
|
||||||
[build-linux-amd64, build-linux-arm64, build-macos, build-windows-x64]
|
[build-linux, build-macos, build-windows-x64]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
|||||||
@@ -138,6 +138,39 @@ productbuild \
|
|||||||
|
|
||||||
echo "PKG package created: ${PKG_NAME}"
|
echo "PKG package created: ${PKG_NAME}"
|
||||||
|
|
||||||
|
# Set custom icon for PKG file
|
||||||
|
if [ -f "${ICON_PATH}" ]; then
|
||||||
|
echo "Setting custom icon for PKG file..."
|
||||||
|
# Create a temporary iconset from icns
|
||||||
|
TEMP_ICON_DIR=$(mktemp -d)
|
||||||
|
cp "${ICON_PATH}" "${TEMP_ICON_DIR}/icon.icns"
|
||||||
|
|
||||||
|
# Use sips to create a png from icns for the icon
|
||||||
|
sips -s format png "${TEMP_ICON_DIR}/icon.icns" --out "${TEMP_ICON_DIR}/icon.png" 2>/dev/null || true
|
||||||
|
|
||||||
|
# Method: Use osascript to set file icon (works on macOS)
|
||||||
|
osascript <<APPLESCRIPT
|
||||||
|
use framework "Foundation"
|
||||||
|
use framework "AppKit"
|
||||||
|
|
||||||
|
set iconPath to POSIX file "${TEMP_ICON_DIR}/icon.icns"
|
||||||
|
set targetPath to POSIX file "$(pwd)/${PKG_NAME}"
|
||||||
|
|
||||||
|
set iconImage to current application's NSImage's alloc()'s initWithContentsOfFile:(POSIX path of iconPath)
|
||||||
|
set workspace to current application's NSWorkspace's sharedWorkspace()
|
||||||
|
workspace's setIcon:iconImage forFile:(POSIX path of targetPath) options:0
|
||||||
|
APPLESCRIPT
|
||||||
|
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
echo "Custom icon set successfully for ${PKG_NAME}"
|
||||||
|
else
|
||||||
|
echo "Warning: Failed to set custom icon (this is optional)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
rm -rf "${TEMP_ICON_DIR}"
|
||||||
|
fi
|
||||||
|
echo "Set icon finished"
|
||||||
|
|
||||||
rm -rf build_pkg_temp build_pkg_scripts ${APP_BUNDLE}
|
rm -rf build_pkg_temp build_pkg_scripts ${APP_BUNDLE}
|
||||||
|
|
||||||
echo "PKG package created successfully."
|
echo "PKG package created successfully."
|
||||||
|
|||||||
@@ -138,6 +138,39 @@ productbuild \
|
|||||||
|
|
||||||
echo "PKG package created: ${PKG_NAME}"
|
echo "PKG package created: ${PKG_NAME}"
|
||||||
|
|
||||||
|
# Set custom icon for PKG file
|
||||||
|
if [ -f "${ICON_PATH}" ]; then
|
||||||
|
echo "Setting custom icon for PKG file..."
|
||||||
|
# Create a temporary iconset from icns
|
||||||
|
TEMP_ICON_DIR=$(mktemp -d)
|
||||||
|
cp "${ICON_PATH}" "${TEMP_ICON_DIR}/icon.icns"
|
||||||
|
|
||||||
|
# Use sips to create a png from icns for the icon
|
||||||
|
sips -s format png "${TEMP_ICON_DIR}/icon.icns" --out "${TEMP_ICON_DIR}/icon.png" 2>/dev/null || true
|
||||||
|
|
||||||
|
# Method: Use osascript to set file icon (works on macOS)
|
||||||
|
osascript <<APPLESCRIPT
|
||||||
|
use framework "Foundation"
|
||||||
|
use framework "AppKit"
|
||||||
|
|
||||||
|
set iconPath to POSIX file "${TEMP_ICON_DIR}/icon.icns"
|
||||||
|
set targetPath to POSIX file "$(pwd)/${PKG_NAME}"
|
||||||
|
|
||||||
|
set iconImage to current application's NSImage's alloc()'s initWithContentsOfFile:(POSIX path of iconPath)
|
||||||
|
set workspace to current application's NSWorkspace's sharedWorkspace()
|
||||||
|
workspace's setIcon:iconImage forFile:(POSIX path of targetPath) options:0
|
||||||
|
APPLESCRIPT
|
||||||
|
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
echo "Custom icon set successfully for ${PKG_NAME}"
|
||||||
|
else
|
||||||
|
echo "Warning: Failed to set custom icon (this is optional)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
rm -rf "${TEMP_ICON_DIR}"
|
||||||
|
fi
|
||||||
|
echo "Set icon finished"
|
||||||
|
|
||||||
rm -rf build_pkg_temp build_pkg_scripts ${APP_BUNDLE}
|
rm -rf build_pkg_temp build_pkg_scripts ${APP_BUNDLE}
|
||||||
|
|
||||||
echo "PKG package created successfully."
|
echo "PKG package created successfully."
|
||||||
|
|||||||
63
src/common/rounded_corner_button.cpp
Normal file
63
src/common/rounded_corner_button.cpp
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
#include "rounded_corner_button.h"
|
||||||
|
|
||||||
|
namespace crossdesk {
|
||||||
|
bool RoundedCornerButton(const char* label, const ImVec2& size, float rounding,
|
||||||
|
ImDrawFlags round_flags, bool enabled,
|
||||||
|
ImU32 normal_col, ImU32 hover_col, ImU32 active_col,
|
||||||
|
ImU32 border_col) {
|
||||||
|
ImGuiWindow* current_window = ImGui::GetCurrentWindow();
|
||||||
|
if (current_window->SkipItems) return false;
|
||||||
|
|
||||||
|
const ImGuiStyle& style = ImGui::GetStyle();
|
||||||
|
|
||||||
|
ImGuiID button_id = current_window->GetID(label);
|
||||||
|
ImVec2 cursor_pos = current_window->DC.CursorPos;
|
||||||
|
ImVec2 button_size = ImGui::CalcItemSize(size, 0.0f, 0.0f);
|
||||||
|
ImRect button_rect(cursor_pos, ImVec2(cursor_pos.x + button_size.x,
|
||||||
|
cursor_pos.y + button_size.y));
|
||||||
|
ImGui::ItemSize(button_rect);
|
||||||
|
if (!ImGui::ItemAdd(button_rect, button_id)) return false;
|
||||||
|
|
||||||
|
bool is_hovered = false, is_held = false;
|
||||||
|
bool is_pressed = false;
|
||||||
|
if (enabled) {
|
||||||
|
is_pressed =
|
||||||
|
ImGui::ButtonBehavior(button_rect, button_id, &is_hovered, &is_held);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (normal_col == 0) normal_col = ImGui::GetColorU32(ImGuiCol_Button);
|
||||||
|
if (hover_col == 0) hover_col = ImGui::GetColorU32(ImGuiCol_ButtonHovered);
|
||||||
|
if (active_col == 0) active_col = ImGui::GetColorU32(ImGuiCol_ButtonActive);
|
||||||
|
if (border_col == 0) border_col = ImGui::GetColorU32(ImGuiCol_Border);
|
||||||
|
|
||||||
|
ImU32 fill_color = normal_col;
|
||||||
|
if (is_held && is_hovered)
|
||||||
|
fill_color = active_col;
|
||||||
|
else if (is_hovered)
|
||||||
|
fill_color = hover_col;
|
||||||
|
|
||||||
|
if (!enabled) fill_color = IM_COL32(120, 120, 120, 180);
|
||||||
|
|
||||||
|
ImDrawList* window_draw_list = ImGui::GetWindowDrawList();
|
||||||
|
|
||||||
|
window_draw_list->AddRectFilled(button_rect.Min, button_rect.Max, fill_color,
|
||||||
|
rounding, round_flags);
|
||||||
|
|
||||||
|
if (style.FrameBorderSize > 0.0f) {
|
||||||
|
window_draw_list->AddRect(button_rect.Min, button_rect.Max, border_col,
|
||||||
|
rounding, round_flags, style.FrameBorderSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
ImU32 text_color =
|
||||||
|
ImGui::GetColorU32(enabled ? ImGuiCol_Text : ImGuiCol_TextDisabled);
|
||||||
|
|
||||||
|
const char* label_end = ImGui::FindRenderedTextEnd(label);
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_Text,
|
||||||
|
ImGui::ColorConvertU32ToFloat4(text_color));
|
||||||
|
ImGui::RenderTextClipped(button_rect.Min, button_rect.Max, label, label_end,
|
||||||
|
nullptr, ImVec2(0.5f, 0.5f), &button_rect);
|
||||||
|
ImGui::PopStyleColor();
|
||||||
|
|
||||||
|
return is_pressed;
|
||||||
|
}
|
||||||
|
} // namespace crossdesk
|
||||||
20
src/common/rounded_corner_button.h
Normal file
20
src/common/rounded_corner_button.h
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* @Author: DI JUNKUN
|
||||||
|
* @Date: 2026-02-26
|
||||||
|
* Copyright (c) 2026 by DI JUNKUN, All Rights Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _ROUNDED_CORNER_BUTTON_H_
|
||||||
|
#define _ROUNDED_CORNER_BUTTON_H_
|
||||||
|
|
||||||
|
#include "imgui.h"
|
||||||
|
#include "imgui_internal.h"
|
||||||
|
|
||||||
|
namespace crossdesk {
|
||||||
|
bool RoundedCornerButton(const char* label, const ImVec2& size, float rounding,
|
||||||
|
ImDrawFlags round_flags, bool enabled = true,
|
||||||
|
ImU32 normal_col = 0, ImU32 hover_col = 0,
|
||||||
|
ImU32 active_col = 0, ImU32 border_col = 0);
|
||||||
|
} // namespace crossdesk
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -71,7 +71,7 @@ class ConfigCenter {
|
|||||||
const char* section_ = "Settings";
|
const char* section_ = "Settings";
|
||||||
|
|
||||||
LANGUAGE language_ = LANGUAGE::CHINESE;
|
LANGUAGE language_ = LANGUAGE::CHINESE;
|
||||||
VIDEO_QUALITY video_quality_ = VIDEO_QUALITY::MEDIUM;
|
VIDEO_QUALITY video_quality_ = VIDEO_QUALITY::HIGH;
|
||||||
VIDEO_FRAME_RATE video_frame_rate_ = VIDEO_FRAME_RATE::FPS_60;
|
VIDEO_FRAME_RATE video_frame_rate_ = VIDEO_FRAME_RATE::FPS_60;
|
||||||
VIDEO_ENCODE_FORMAT video_encode_format_ = VIDEO_ENCODE_FORMAT::H264;
|
VIDEO_ENCODE_FORMAT video_encode_format_ = VIDEO_ENCODE_FORMAT::H264;
|
||||||
bool hardware_video_codec_ = false;
|
bool hardware_video_codec_ = false;
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -205,11 +205,25 @@ static std::vector<std::string> browse = {
|
|||||||
reinterpret_cast<const char*>(u8"浏览"), "Browse"};
|
reinterpret_cast<const char*>(u8"浏览"), "Browse"};
|
||||||
static std::vector<std::string> default_desktop = {
|
static std::vector<std::string> default_desktop = {
|
||||||
reinterpret_cast<const char*>(u8"桌面"), "Desktop"};
|
reinterpret_cast<const char*>(u8"桌面"), "Desktop"};
|
||||||
|
|
||||||
#if _WIN32
|
|
||||||
static std::vector<std::string> minimize_to_tray = {
|
static std::vector<std::string> minimize_to_tray = {
|
||||||
reinterpret_cast<const char*>(u8"退出时最小化到系统托盘:"),
|
reinterpret_cast<const char*>(u8"退出时最小化到系统托盘:"),
|
||||||
"Minimize to system tray when exit:"};
|
"Minimize to system tray when exit:"};
|
||||||
|
static std::vector<std::string> resolution = {
|
||||||
|
reinterpret_cast<const char*>(u8"分辨率"), "Res"};
|
||||||
|
static std::vector<std::string> connection_mode = {
|
||||||
|
reinterpret_cast<const char*>(u8"连接模式"), "Mode"};
|
||||||
|
static std::vector<std::string> connection_mode_direct = {
|
||||||
|
reinterpret_cast<const char*>(u8"直连"), "Direct"};
|
||||||
|
static std::vector<std::string> connection_mode_relay = {
|
||||||
|
reinterpret_cast<const char*>(u8"中继"), "Relay"};
|
||||||
|
static std::vector<std::string> online = {
|
||||||
|
reinterpret_cast<const char*>(u8"在线"), "Online"};
|
||||||
|
static std::vector<std::string> offline = {
|
||||||
|
reinterpret_cast<const char*>(u8"离线"), "Offline"};
|
||||||
|
static std::vector<std::string> device_offline = {
|
||||||
|
reinterpret_cast<const char*>(u8"设备离线"), "Device Offline"};
|
||||||
|
|
||||||
|
#if _WIN32
|
||||||
static std::vector<LPCWSTR> exit_program = {L"退出", L"Exit"};
|
static std::vector<LPCWSTR> exit_program = {L"退出", L"Exit"};
|
||||||
#endif
|
#endif
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
|
|||||||
36
src/gui/device_presence.h
Normal file
36
src/gui/device_presence.h
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* @Author: DI JUNKUN
|
||||||
|
* @Date: 2026-02-28
|
||||||
|
* Copyright (c) 2026 by DI JUNKUN, All Rights Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _DEVICE_PRESENCE_H_
|
||||||
|
#define _DEVICE_PRESENCE_H_
|
||||||
|
|
||||||
|
#include <mutex>
|
||||||
|
#include <string>
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
|
class DevicePresence {
|
||||||
|
public:
|
||||||
|
void SetOnline(const std::string& device_id, bool online) {
|
||||||
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
|
cache_[device_id] = online;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsOnline(const std::string& device_id) const {
|
||||||
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
|
return cache_.count(device_id) > 0 && cache_.at(device_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Clear() {
|
||||||
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
|
cache_.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::unordered_map<std::string, bool> cache_;
|
||||||
|
mutable std::mutex mutex_;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -101,7 +101,7 @@ int Render::LocalWindow() {
|
|||||||
ImGuiCol_WindowBg,
|
ImGuiCol_WindowBg,
|
||||||
ImVec4(1.0f, 1.0f, 1.0f, 1.0f - (float)time_duration));
|
ImVec4(1.0f, 1.0f, 1.0f, 1.0f - (float)time_duration));
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 5.0f);
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 6.0f);
|
||||||
ImGui::Begin("ConnectionStatusWindow", nullptr,
|
ImGui::Begin("ConnectionStatusWindow", nullptr,
|
||||||
ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove |
|
ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove |
|
||||||
ImGuiWindowFlags_NoSavedSettings);
|
ImGuiWindowFlags_NoSavedSettings);
|
||||||
@@ -180,7 +180,7 @@ int Render::LocalWindow() {
|
|||||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f);
|
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f);
|
||||||
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(1.0, 1.0, 1.0, 1.0));
|
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(1.0, 1.0, 1.0, 1.0));
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 1.0f);
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 1.0f);
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 5.0f);
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 6.0f);
|
||||||
|
|
||||||
ImGui::Begin("ResetPasswordWindow", nullptr,
|
ImGui::Begin("ResetPasswordWindow", nullptr,
|
||||||
ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove |
|
ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove |
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ int Render::RecentConnectionsWindow() {
|
|||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
float recent_connection_window_width = io.DisplaySize.x;
|
float recent_connection_window_width = io.DisplaySize.x;
|
||||||
float recent_connection_window_height =
|
float recent_connection_window_height =
|
||||||
io.DisplaySize.y * (0.46f - STATUS_BAR_HEIGHT);
|
io.DisplaySize.y * (0.455f - STATUS_BAR_HEIGHT);
|
||||||
ImGui::SetNextWindowPos(ImVec2(0, io.DisplaySize.y * 0.55f),
|
ImGui::SetNextWindowPos(ImVec2(0, io.DisplaySize.y * 0.55f),
|
||||||
ImGuiCond_Always);
|
ImGuiCond_Always);
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
|
||||||
@@ -122,6 +122,8 @@ int Render::ShowRecentConnections() {
|
|||||||
it.second.remote_host_name = "unknown";
|
it.second.remote_host_name = "unknown";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool online = device_presence_.IsOnline(it.second.remote_id);
|
||||||
|
|
||||||
ImVec2 image_screen_pos = ImVec2(
|
ImVec2 image_screen_pos = ImVec2(
|
||||||
ImGui::GetCursorScreenPos().x + recent_connection_image_width * 0.04f,
|
ImGui::GetCursorScreenPos().x + recent_connection_image_width * 0.04f,
|
||||||
ImGui::GetCursorScreenPos().y + recent_connection_image_height * 0.08f);
|
ImGui::GetCursorScreenPos().y + recent_connection_image_height * 0.08f);
|
||||||
@@ -133,6 +135,30 @@ int Render::ShowRecentConnections() {
|
|||||||
(ImTextureID)(intptr_t)it.second.texture,
|
(ImTextureID)(intptr_t)it.second.texture,
|
||||||
ImVec2(recent_connection_image_width, recent_connection_image_height));
|
ImVec2(recent_connection_image_width, recent_connection_image_height));
|
||||||
|
|
||||||
|
ImDrawList* draw_list = ImGui::GetWindowDrawList();
|
||||||
|
ImVec2 circle_pos =
|
||||||
|
ImVec2(image_screen_pos.x + recent_connection_image_width * 0.07f,
|
||||||
|
image_screen_pos.y + recent_connection_image_height * 0.12f);
|
||||||
|
ImU32 fill_color =
|
||||||
|
online ? IM_COL32(0, 255, 0, 255) : IM_COL32(140, 140, 140, 255);
|
||||||
|
ImU32 border_color = IM_COL32(255, 255, 255, 255);
|
||||||
|
float dot_radius = recent_connection_image_height * 0.06f;
|
||||||
|
draw_list->AddCircleFilled(circle_pos, dot_radius * 1.25f, border_color,
|
||||||
|
100);
|
||||||
|
draw_list->AddCircleFilled(circle_pos, dot_radius, fill_color, 100);
|
||||||
|
if (ImGui::IsMouseHoveringRect(
|
||||||
|
ImVec2(circle_pos.x - dot_radius, circle_pos.y - dot_radius),
|
||||||
|
ImVec2(circle_pos.x + dot_radius, circle_pos.y + dot_radius))) {
|
||||||
|
ImGui::BeginTooltip();
|
||||||
|
ImGui::SetWindowFontScale(0.5f);
|
||||||
|
ImGui::Text(
|
||||||
|
"%s",
|
||||||
|
online ? localization::online[localization_language_index_].c_str()
|
||||||
|
: localization::offline[localization_language_index_].c_str());
|
||||||
|
ImGui::SetWindowFontScale(1.0f);
|
||||||
|
ImGui::EndTooltip();
|
||||||
|
}
|
||||||
|
|
||||||
// remote id display button
|
// remote id display button
|
||||||
{
|
{
|
||||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0.2f));
|
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0.2f));
|
||||||
@@ -159,7 +185,11 @@ int Render::ShowRecentConnections() {
|
|||||||
if (ImGui::IsItemHovered()) {
|
if (ImGui::IsItemHovered()) {
|
||||||
ImGui::BeginTooltip();
|
ImGui::BeginTooltip();
|
||||||
ImGui::SetWindowFontScale(0.5f);
|
ImGui::SetWindowFontScale(0.5f);
|
||||||
ImGui::Text("%s", it.second.remote_host_name.c_str());
|
std::string display_host_name_with_presence =
|
||||||
|
it.second.remote_host_name + " " +
|
||||||
|
(online ? localization::online[localization_language_index_]
|
||||||
|
: localization::offline[localization_language_index_]);
|
||||||
|
ImGui::Text("%s", display_host_name_with_presence.c_str());
|
||||||
ImGui::SetWindowFontScale(1.0f);
|
ImGui::SetWindowFontScale(1.0f);
|
||||||
ImGui::EndTooltip();
|
ImGui::EndTooltip();
|
||||||
}
|
}
|
||||||
@@ -210,8 +240,14 @@ int Render::ShowRecentConnections() {
|
|||||||
if (ImGui::Button(connect_to_this_connection_button_name.c_str(),
|
if (ImGui::Button(connect_to_this_connection_button_name.c_str(),
|
||||||
ImVec2(recent_connection_button_width,
|
ImVec2(recent_connection_button_width,
|
||||||
recent_connection_button_height))) {
|
recent_connection_button_height))) {
|
||||||
ConnectTo(it.second.remote_id, it.second.password.c_str(),
|
if (online) {
|
||||||
it.second.remember_password);
|
ConnectTo(it.second.remote_id, it.second.password.c_str(),
|
||||||
|
it.second.remember_password);
|
||||||
|
} else {
|
||||||
|
show_offline_warning_window_ = true;
|
||||||
|
offline_warning_text_ =
|
||||||
|
localization::device_offline[localization_language_index_];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ImGui::SetWindowFontScale(1.0f);
|
ImGui::SetWindowFontScale(1.0f);
|
||||||
@@ -242,6 +278,9 @@ int Render::ShowRecentConnections() {
|
|||||||
if (show_confirm_delete_connection_) {
|
if (show_confirm_delete_connection_) {
|
||||||
ConfirmDeleteConnection();
|
ConfirmDeleteConnection();
|
||||||
}
|
}
|
||||||
|
if (show_offline_warning_window_) {
|
||||||
|
OfflineWarningWindow();
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -254,9 +293,9 @@ int Render::ConfirmDeleteConnection() {
|
|||||||
ImVec2(io.DisplaySize.x * 0.33f, io.DisplaySize.y * 0.33f));
|
ImVec2(io.DisplaySize.x * 0.33f, io.DisplaySize.y * 0.33f));
|
||||||
|
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f);
|
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f);
|
||||||
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(1.0, 1.0, 1.0, 1.0));
|
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 1.0f);
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 1.0f);
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 5.0f);
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 6.0f);
|
||||||
|
|
||||||
ImGui::Begin("ConfirmDeleteConnectionWindow", nullptr,
|
ImGui::Begin("ConfirmDeleteConnectionWindow", nullptr,
|
||||||
ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove |
|
ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove |
|
||||||
@@ -299,4 +338,45 @@ int Render::ConfirmDeleteConnection() {
|
|||||||
ImGui::PopStyleVar();
|
ImGui::PopStyleVar();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Render::OfflineWarningWindow() {
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
ImGui::SetNextWindowPos(
|
||||||
|
ImVec2(io.DisplaySize.x * 0.33f, io.DisplaySize.y * 0.33f));
|
||||||
|
ImGui::SetNextWindowSize(
|
||||||
|
ImVec2(io.DisplaySize.x * 0.33f, io.DisplaySize.y * 0.33f));
|
||||||
|
|
||||||
|
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f);
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
|
||||||
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 1.0f);
|
||||||
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 6.0f);
|
||||||
|
|
||||||
|
ImGui::Begin("OfflineWarningWindow", nullptr,
|
||||||
|
ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove |
|
||||||
|
ImGuiWindowFlags_NoSavedSettings);
|
||||||
|
ImGui::PopStyleVar(2);
|
||||||
|
ImGui::PopStyleColor();
|
||||||
|
|
||||||
|
auto window_width = ImGui::GetWindowSize().x;
|
||||||
|
auto window_height = ImGui::GetWindowSize().y;
|
||||||
|
|
||||||
|
ImGui::SetCursorPosX(window_width * 0.43f);
|
||||||
|
ImGui::SetCursorPosY(window_height * 0.67f);
|
||||||
|
ImGui::SetWindowFontScale(0.5f);
|
||||||
|
if (ImGui::Button(localization::ok[localization_language_index_].c_str()) ||
|
||||||
|
ImGui::IsKeyPressed(ImGuiKey_Enter) ||
|
||||||
|
ImGui::IsKeyPressed(ImGuiKey_Escape)) {
|
||||||
|
show_offline_warning_window_ = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto text_width = ImGui::CalcTextSize(offline_warning_text_.c_str()).x;
|
||||||
|
ImGui::SetCursorPosX((window_width - text_width) * 0.5f);
|
||||||
|
ImGui::SetCursorPosY(window_height * 0.2f);
|
||||||
|
ImGui::Text("%s", offline_warning_text_.c_str());
|
||||||
|
ImGui::SetWindowFontScale(1.0f);
|
||||||
|
|
||||||
|
ImGui::End();
|
||||||
|
ImGui::PopStyleVar();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
} // namespace crossdesk
|
} // namespace crossdesk
|
||||||
@@ -195,7 +195,7 @@ int Render::ConnectTo(const std::string& remote_id, const char* password,
|
|||||||
props->control_window_min_width_ = title_bar_height_ * 0.65f;
|
props->control_window_min_width_ = title_bar_height_ * 0.65f;
|
||||||
props->control_window_min_height_ = title_bar_height_ * 1.3f;
|
props->control_window_min_height_ = title_bar_height_ * 1.3f;
|
||||||
props->control_window_max_width_ = title_bar_height_ * 9.0f;
|
props->control_window_max_width_ = title_bar_height_ * 9.0f;
|
||||||
props->control_window_max_height_ = title_bar_height_ * 6.0f;
|
props->control_window_max_height_ = title_bar_height_ * 7.0f;
|
||||||
|
|
||||||
if (!props->peer_) {
|
if (!props->peer_) {
|
||||||
LOG_INFO("Create peer [{}] instance failed", props->local_id_);
|
LOG_INFO("Create peer [{}] instance failed", props->local_id_);
|
||||||
|
|||||||
@@ -298,7 +298,7 @@ SDL_HitTestResult Render::HitTestCallback(SDL_Window* window,
|
|||||||
float mouse_grab_padding = render->title_bar_button_width_ * 0.16f;
|
float mouse_grab_padding = render->title_bar_button_width_ * 0.16f;
|
||||||
if (area->y < render->title_bar_button_width_ &&
|
if (area->y < render->title_bar_button_width_ &&
|
||||||
area->y > mouse_grab_padding &&
|
area->y > mouse_grab_padding &&
|
||||||
area->x < window_width - render->title_bar_button_width_ * 4.0f &&
|
area->x < window_width - render->title_bar_button_width_ * 3.0f &&
|
||||||
area->x > mouse_grab_padding) {
|
area->x > mouse_grab_padding) {
|
||||||
return SDL_HITTEST_DRAGGABLE;
|
return SDL_HITTEST_DRAGGABLE;
|
||||||
}
|
}
|
||||||
@@ -810,6 +810,7 @@ int Render::CreateConnectionPeer() {
|
|||||||
params_.on_receive_video_frame = OnReceiveVideoBufferCb;
|
params_.on_receive_video_frame = OnReceiveVideoBufferCb;
|
||||||
|
|
||||||
params_.on_signal_status = OnSignalStatusCb;
|
params_.on_signal_status = OnSignalStatusCb;
|
||||||
|
params_.on_signal_message = OnSignalMessageCb;
|
||||||
params_.on_connection_status = OnConnectionStatusCb;
|
params_.on_connection_status = OnConnectionStatusCb;
|
||||||
params_.on_net_status_report = OnNetStatusReport;
|
params_.on_net_status_report = OnNetStatusReport;
|
||||||
|
|
||||||
@@ -893,7 +894,7 @@ void Render::UpdateInteractions() {
|
|||||||
mouse_controller_is_started_ = false;
|
mouse_controller_is_started_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (start_keyboard_capturer_ && foucs_on_stream_window_) {
|
if (start_keyboard_capturer_ && focus_on_stream_window_) {
|
||||||
if (!keyboard_capturer_is_started_) {
|
if (!keyboard_capturer_is_started_) {
|
||||||
StartKeyboardCapturer();
|
StartKeyboardCapturer();
|
||||||
keyboard_capturer_is_started_ = true;
|
keyboard_capturer_is_started_ = true;
|
||||||
@@ -914,9 +915,10 @@ int Render::CreateMainWindow() {
|
|||||||
ImGui::SetCurrentContext(main_ctx_);
|
ImGui::SetCurrentContext(main_ctx_);
|
||||||
|
|
||||||
if (!SDL_CreateWindowAndRenderer(
|
if (!SDL_CreateWindowAndRenderer(
|
||||||
"Remote Desk", (int)main_window_width_, (int)main_window_height_,
|
"CrossDesk Main Window", (int)main_window_width_,
|
||||||
|
(int)main_window_height_,
|
||||||
SDL_WINDOW_HIGH_PIXEL_DENSITY | SDL_WINDOW_BORDERLESS |
|
SDL_WINDOW_HIGH_PIXEL_DENSITY | SDL_WINDOW_BORDERLESS |
|
||||||
SDL_WINDOW_HIDDEN,
|
SDL_WINDOW_HIDDEN | SDL_WINDOW_TRANSPARENT,
|
||||||
&main_window_, &main_renderer_)) {
|
&main_window_, &main_renderer_)) {
|
||||||
LOG_ERROR("Error creating MainWindow and MainRenderer: {}", SDL_GetError());
|
LOG_ERROR("Error creating MainWindow and MainRenderer: {}", SDL_GetError());
|
||||||
return -1;
|
return -1;
|
||||||
@@ -946,6 +948,8 @@ int Render::CreateMainWindow() {
|
|||||||
// for window region action
|
// for window region action
|
||||||
SDL_SetWindowHitTest(main_window_, HitTestCallback, this);
|
SDL_SetWindowHitTest(main_window_, HitTestCallback, this);
|
||||||
|
|
||||||
|
SDL_SetRenderDrawBlendMode(main_renderer_, SDL_BLENDMODE_BLEND);
|
||||||
|
|
||||||
SetupFontAndStyle(&main_windows_system_chinese_font_);
|
SetupFontAndStyle(&main_windows_system_chinese_font_);
|
||||||
|
|
||||||
ImGuiStyle& style = ImGui::GetStyle();
|
ImGuiStyle& style = ImGui::GetStyle();
|
||||||
@@ -1002,9 +1006,10 @@ int Render::CreateStreamWindow() {
|
|||||||
ImGui::SetCurrentContext(stream_ctx_);
|
ImGui::SetCurrentContext(stream_ctx_);
|
||||||
|
|
||||||
if (!SDL_CreateWindowAndRenderer(
|
if (!SDL_CreateWindowAndRenderer(
|
||||||
"Stream window", (int)stream_window_width_,
|
"CrossDesk Stream Window", (int)stream_window_width_,
|
||||||
(int)stream_window_height_,
|
(int)stream_window_height_,
|
||||||
SDL_WINDOW_HIGH_PIXEL_DENSITY | SDL_WINDOW_BORDERLESS,
|
SDL_WINDOW_HIGH_PIXEL_DENSITY | SDL_WINDOW_BORDERLESS |
|
||||||
|
SDL_WINDOW_TRANSPARENT,
|
||||||
&stream_window_, &stream_renderer_)) {
|
&stream_window_, &stream_renderer_)) {
|
||||||
LOG_ERROR("Error creating stream_window_ and stream_renderer_: {}",
|
LOG_ERROR("Error creating stream_window_ and stream_renderer_: {}",
|
||||||
SDL_GetError());
|
SDL_GetError());
|
||||||
@@ -1018,6 +1023,8 @@ int Render::CreateStreamWindow() {
|
|||||||
// for window region action
|
// for window region action
|
||||||
SDL_SetWindowHitTest(stream_window_, HitTestCallback, this);
|
SDL_SetWindowHitTest(stream_window_, HitTestCallback, this);
|
||||||
|
|
||||||
|
SDL_SetRenderDrawBlendMode(stream_renderer_, SDL_BLENDMODE_BLEND);
|
||||||
|
|
||||||
SetupFontAndStyle(&stream_windows_system_chinese_font_);
|
SetupFontAndStyle(&stream_windows_system_chinese_font_);
|
||||||
|
|
||||||
ImGuiStyle& style = ImGui::GetStyle();
|
ImGuiStyle& style = ImGui::GetStyle();
|
||||||
@@ -1073,12 +1080,12 @@ int Render::CreateServerWindow() {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
ImGui::SetCurrentContext(server_ctx_);
|
ImGui::SetCurrentContext(server_ctx_);
|
||||||
if (!SDL_CreateWindowAndRenderer("Server window", (int)server_window_width_,
|
if (!SDL_CreateWindowAndRenderer(
|
||||||
(int)server_window_height_,
|
"CrossDesk Server Window", (int)server_window_width_,
|
||||||
SDL_WINDOW_HIGH_PIXEL_DENSITY |
|
(int)server_window_height_,
|
||||||
SDL_WINDOW_BORDERLESS |
|
SDL_WINDOW_HIGH_PIXEL_DENSITY | SDL_WINDOW_BORDERLESS |
|
||||||
SDL_WINDOW_TRANSPARENT,
|
SDL_WINDOW_TRANSPARENT,
|
||||||
&server_window_, &server_renderer_)) {
|
&server_window_, &server_renderer_)) {
|
||||||
LOG_ERROR("Error creating server_window_ and server_renderer_: {}",
|
LOG_ERROR("Error creating server_window_ and server_renderer_: {}",
|
||||||
SDL_GetError());
|
SDL_GetError());
|
||||||
return -1;
|
return -1;
|
||||||
@@ -1290,6 +1297,8 @@ int Render::DrawMainWindow() {
|
|||||||
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
|
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
|
||||||
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 6.0f);
|
||||||
|
|
||||||
ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_Always);
|
ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_Always);
|
||||||
ImGui::SetNextWindowSize(ImVec2(io.DisplaySize.x, io.DisplaySize.y),
|
ImGui::SetNextWindowSize(ImVec2(io.DisplaySize.x, io.DisplaySize.y),
|
||||||
ImGuiCond_Always);
|
ImGuiCond_Always);
|
||||||
@@ -1298,6 +1307,7 @@ int Render::DrawMainWindow() {
|
|||||||
ImGuiWindowFlags_NoBringToFrontOnFocus |
|
ImGuiWindowFlags_NoBringToFrontOnFocus |
|
||||||
ImGuiWindowFlags_NoDocking);
|
ImGuiWindowFlags_NoDocking);
|
||||||
ImGui::PopStyleColor();
|
ImGui::PopStyleColor();
|
||||||
|
ImGui::PopStyleVar();
|
||||||
|
|
||||||
TitleBar(true);
|
TitleBar(true);
|
||||||
|
|
||||||
@@ -1318,6 +1328,7 @@ int Render::DrawMainWindow() {
|
|||||||
ImGui::Render();
|
ImGui::Render();
|
||||||
SDL_SetRenderScale(main_renderer_, io.DisplayFramebufferScale.x,
|
SDL_SetRenderScale(main_renderer_, io.DisplayFramebufferScale.x,
|
||||||
io.DisplayFramebufferScale.y);
|
io.DisplayFramebufferScale.y);
|
||||||
|
SDL_SetRenderDrawColor(main_renderer_, 0, 0, 0, 0);
|
||||||
SDL_RenderClear(main_renderer_);
|
SDL_RenderClear(main_renderer_);
|
||||||
ImGui_ImplSDLRenderer3_RenderDrawData(ImGui::GetDrawData(), main_renderer_);
|
ImGui_ImplSDLRenderer3_RenderDrawData(ImGui::GetDrawData(), main_renderer_);
|
||||||
SDL_RenderPresent(main_renderer_);
|
SDL_RenderPresent(main_renderer_);
|
||||||
@@ -1367,6 +1378,7 @@ int Render::DrawStreamWindow() {
|
|||||||
ImGui::Render();
|
ImGui::Render();
|
||||||
SDL_SetRenderScale(stream_renderer_, io.DisplayFramebufferScale.x,
|
SDL_SetRenderScale(stream_renderer_, io.DisplayFramebufferScale.x,
|
||||||
io.DisplayFramebufferScale.y);
|
io.DisplayFramebufferScale.y);
|
||||||
|
SDL_SetRenderDrawColor(stream_renderer_, 0, 0, 0, 255);
|
||||||
SDL_RenderClear(stream_renderer_);
|
SDL_RenderClear(stream_renderer_);
|
||||||
|
|
||||||
// std::shared_lock lock(client_properties_mutex_);
|
// std::shared_lock lock(client_properties_mutex_);
|
||||||
@@ -1393,24 +1405,20 @@ int Render::DrawServerWindow() {
|
|||||||
LOG_ERROR("Server context is null");
|
LOG_ERROR("Server context is null");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (server_window_) {
|
|
||||||
int w = 0;
|
|
||||||
int h = 0;
|
|
||||||
SDL_GetWindowSize(server_window_, &w, &h);
|
|
||||||
if (w > 0 && h > 0) {
|
|
||||||
server_window_width_ = (float)w;
|
|
||||||
server_window_height_ = (float)h;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui::SetCurrentContext(server_ctx_);
|
ImGui::SetCurrentContext(server_ctx_);
|
||||||
ImGui_ImplSDLRenderer3_NewFrame();
|
ImGui_ImplSDLRenderer3_NewFrame();
|
||||||
ImGui_ImplSDL3_NewFrame();
|
ImGui_ImplSDL3_NewFrame();
|
||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
|
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
server_window_width_ = io.DisplaySize.x;
|
||||||
|
server_window_height_ = io.DisplaySize.y;
|
||||||
|
|
||||||
ServerWindow();
|
ServerWindow();
|
||||||
ImGui::Render();
|
ImGui::Render();
|
||||||
SDL_SetRenderDrawColor(server_renderer_, 255, 255, 255, 255);
|
SDL_SetRenderScale(server_renderer_, io.DisplayFramebufferScale.x,
|
||||||
|
io.DisplayFramebufferScale.y);
|
||||||
|
SDL_SetRenderDrawColor(server_renderer_, 0, 0, 0, 0);
|
||||||
SDL_RenderClear(server_renderer_);
|
SDL_RenderClear(server_renderer_);
|
||||||
ImGui_ImplSDLRenderer3_RenderDrawData(ImGui::GetDrawData(), server_renderer_);
|
ImGui_ImplSDLRenderer3_RenderDrawData(ImGui::GetDrawData(), server_renderer_);
|
||||||
SDL_RenderPresent(server_renderer_);
|
SDL_RenderPresent(server_renderer_);
|
||||||
@@ -1586,6 +1594,7 @@ void Render::MainLoop() {
|
|||||||
|
|
||||||
UpdateLabels();
|
UpdateLabels();
|
||||||
HandleRecentConnections();
|
HandleRecentConnections();
|
||||||
|
HandleConnectionStatusChange();
|
||||||
HandleStreamWindow();
|
HandleStreamWindow();
|
||||||
HandleServerWindow();
|
HandleServerWindow();
|
||||||
|
|
||||||
@@ -1625,10 +1634,46 @@ void Render::HandleRecentConnections() {
|
|||||||
LOG_INFO("Load recent connection thumbnails");
|
LOG_INFO("Load recent connection thumbnails");
|
||||||
}
|
}
|
||||||
reload_recent_connections_ = false;
|
reload_recent_connections_ = false;
|
||||||
|
|
||||||
|
recent_connection_ids_.clear();
|
||||||
|
for (const auto& conn : recent_connections_) {
|
||||||
|
recent_connection_ids_.push_back(conn.first);
|
||||||
|
}
|
||||||
|
need_to_send_recent_connections_ = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Render::HandleConnectionStatusChange() {
|
||||||
|
if (signal_connected_ && peer_ && need_to_send_recent_connections_) {
|
||||||
|
if (!recent_connection_ids_.empty()) {
|
||||||
|
nlohmann::json j;
|
||||||
|
j["type"] = "recent_connections_presence";
|
||||||
|
j["user_id"] = client_id_;
|
||||||
|
j["devices"] = nlohmann::json::array();
|
||||||
|
for (const auto& id : recent_connection_ids_) {
|
||||||
|
std::string pure_id = id;
|
||||||
|
size_t pos_y = pure_id.find('Y');
|
||||||
|
size_t pos_n = pure_id.find('N');
|
||||||
|
size_t pos = std::string::npos;
|
||||||
|
if (pos_y != std::string::npos &&
|
||||||
|
(pos_n == std::string::npos || pos_y < pos_n)) {
|
||||||
|
pos = pos_y;
|
||||||
|
} else if (pos_n != std::string::npos) {
|
||||||
|
pos = pos_n;
|
||||||
|
}
|
||||||
|
if (pos != std::string::npos) {
|
||||||
|
pure_id = pure_id.substr(0, pos);
|
||||||
|
}
|
||||||
|
j["devices"].push_back(pure_id);
|
||||||
|
}
|
||||||
|
auto s = j.dump();
|
||||||
|
SendSignalMessage(peer_, s.data(), s.size());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
need_to_send_recent_connections_ = false;
|
||||||
|
}
|
||||||
|
|
||||||
void Render::HandleStreamWindow() {
|
void Render::HandleStreamWindow() {
|
||||||
if (need_to_create_stream_window_) {
|
if (need_to_create_stream_window_) {
|
||||||
CreateStreamWindow();
|
CreateStreamWindow();
|
||||||
@@ -2051,7 +2096,8 @@ void Render::UpdateRenderRect() {
|
|||||||
(int)(render_area_width * video_ratio_reverse)};
|
(int)(render_area_width * video_ratio_reverse)};
|
||||||
} else if (render_area_width > render_area_height * video_ratio) {
|
} else if (render_area_width > render_area_height * video_ratio) {
|
||||||
props->stream_render_rect_ = {
|
props->stream_render_rect_ = {
|
||||||
(int)abs(render_area_width - render_area_height * video_ratio) / 2,
|
(int)abs(render_area_width - render_area_height * video_ratio) / 2 +
|
||||||
|
(int)props->render_window_x_,
|
||||||
(int)props->render_window_y_, (int)(render_area_height * video_ratio),
|
(int)props->render_window_y_, (int)(render_area_height * video_ratio),
|
||||||
(int)render_area_height};
|
(int)render_area_height};
|
||||||
} else {
|
} else {
|
||||||
@@ -2176,7 +2222,7 @@ void Render::ProcessSdlEvent(const SDL_Event& event) {
|
|||||||
case SDL_EVENT_WINDOW_FOCUS_GAINED:
|
case SDL_EVENT_WINDOW_FOCUS_GAINED:
|
||||||
if (stream_window_ &&
|
if (stream_window_ &&
|
||||||
SDL_GetWindowID(stream_window_) == event.window.windowID) {
|
SDL_GetWindowID(stream_window_) == event.window.windowID) {
|
||||||
foucs_on_stream_window_ = true;
|
focus_on_stream_window_ = true;
|
||||||
} else if (main_window_ &&
|
} else if (main_window_ &&
|
||||||
SDL_GetWindowID(main_window_) == event.window.windowID) {
|
SDL_GetWindowID(main_window_) == event.window.windowID) {
|
||||||
foucs_on_main_window_ = true;
|
foucs_on_main_window_ = true;
|
||||||
@@ -2186,7 +2232,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) {
|
||||||
foucs_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) {
|
||||||
foucs_on_main_window_ = false;
|
foucs_on_main_window_ = false;
|
||||||
@@ -2200,7 +2246,7 @@ void Render::ProcessSdlEvent(const SDL_Event& event) {
|
|||||||
case SDL_EVENT_MOUSE_BUTTON_DOWN:
|
case SDL_EVENT_MOUSE_BUTTON_DOWN:
|
||||||
case SDL_EVENT_MOUSE_BUTTON_UP:
|
case SDL_EVENT_MOUSE_BUTTON_UP:
|
||||||
case SDL_EVENT_MOUSE_WHEEL:
|
case SDL_EVENT_MOUSE_WHEEL:
|
||||||
if (foucs_on_stream_window_) {
|
if (focus_on_stream_window_) {
|
||||||
ProcessMouseEvent(event);
|
ProcessMouseEvent(event);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
#include "IconsFontAwesome6.h"
|
#include "IconsFontAwesome6.h"
|
||||||
#include "config_center.h"
|
#include "config_center.h"
|
||||||
#include "device_controller_factory.h"
|
#include "device_controller_factory.h"
|
||||||
|
#include "device_presence.h"
|
||||||
#include "imgui.h"
|
#include "imgui.h"
|
||||||
#include "imgui_impl_sdl3.h"
|
#include "imgui_impl_sdl3.h"
|
||||||
#include "imgui_impl_sdlrenderer3.h"
|
#include "imgui_impl_sdlrenderer3.h"
|
||||||
@@ -192,6 +193,7 @@ class Render {
|
|||||||
void UpdateLabels();
|
void UpdateLabels();
|
||||||
void UpdateInteractions();
|
void UpdateInteractions();
|
||||||
void HandleRecentConnections();
|
void HandleRecentConnections();
|
||||||
|
void HandleConnectionStatusChange();
|
||||||
void HandleStreamWindow();
|
void HandleStreamWindow();
|
||||||
void HandleServerWindow();
|
void HandleServerWindow();
|
||||||
void Cleanup();
|
void Cleanup();
|
||||||
@@ -255,6 +257,7 @@ class Render {
|
|||||||
int DrawStreamWindow();
|
int DrawStreamWindow();
|
||||||
int DrawServerWindow();
|
int DrawServerWindow();
|
||||||
int ConfirmDeleteConnection();
|
int ConfirmDeleteConnection();
|
||||||
|
int OfflineWarningWindow();
|
||||||
int NetTrafficStats(std::shared_ptr<SubStreamWindowProperties>& props);
|
int NetTrafficStats(std::shared_ptr<SubStreamWindowProperties>& props);
|
||||||
void DrawConnectionStatusText(
|
void DrawConnectionStatusText(
|
||||||
std::shared_ptr<SubStreamWindowProperties>& props);
|
std::shared_ptr<SubStreamWindowProperties>& props);
|
||||||
@@ -286,6 +289,9 @@ class Render {
|
|||||||
static void OnSignalStatusCb(SignalStatus status, const char* user_id,
|
static void OnSignalStatusCb(SignalStatus status, const char* user_id,
|
||||||
size_t user_id_size, void* user_data);
|
size_t user_id_size, void* user_data);
|
||||||
|
|
||||||
|
static void OnSignalMessageCb(const char* message, size_t size,
|
||||||
|
void* user_data);
|
||||||
|
|
||||||
static void OnConnectionStatusCb(ConnectionStatus status, const char* user_id,
|
static void OnConnectionStatusCb(ConnectionStatus status, const char* user_id,
|
||||||
size_t user_id_size, void* user_data);
|
size_t user_id_size, void* user_data);
|
||||||
|
|
||||||
@@ -402,9 +408,12 @@ class Render {
|
|||||||
// recent connections
|
// recent connections
|
||||||
std::vector<std::pair<std::string, Thumbnail::RecentConnection>>
|
std::vector<std::pair<std::string, Thumbnail::RecentConnection>>
|
||||||
recent_connections_;
|
recent_connections_;
|
||||||
|
std::vector<std::string> recent_connection_ids_;
|
||||||
int recent_connection_image_width_ = 160;
|
int recent_connection_image_width_ = 160;
|
||||||
int recent_connection_image_height_ = 90;
|
int recent_connection_image_height_ = 90;
|
||||||
uint32_t recent_connection_image_save_time_ = 0;
|
uint32_t recent_connection_image_save_time_ = 0;
|
||||||
|
DevicePresence device_presence_;
|
||||||
|
bool need_to_send_recent_connections_ = true;
|
||||||
|
|
||||||
// main window render
|
// main window render
|
||||||
SDL_Window* main_window_ = nullptr;
|
SDL_Window* main_window_ = nullptr;
|
||||||
@@ -434,7 +443,7 @@ class Render {
|
|||||||
bool show_cursor_ = false;
|
bool show_cursor_ = false;
|
||||||
bool keyboard_capturer_is_started_ = false;
|
bool keyboard_capturer_is_started_ = false;
|
||||||
bool foucs_on_main_window_ = false;
|
bool foucs_on_main_window_ = false;
|
||||||
bool foucs_on_stream_window_ = false;
|
bool focus_on_stream_window_ = false;
|
||||||
bool main_window_minimized_ = false;
|
bool main_window_minimized_ = false;
|
||||||
uint32_t last_main_minimize_request_tick_ = 0;
|
uint32_t last_main_minimize_request_tick_ = 0;
|
||||||
uint32_t last_stream_minimize_request_tick_ = 0;
|
uint32_t last_stream_minimize_request_tick_ = 0;
|
||||||
@@ -569,9 +578,11 @@ class Render {
|
|||||||
bool is_server_mode_ = false;
|
bool is_server_mode_ = false;
|
||||||
bool reload_recent_connections_ = true;
|
bool reload_recent_connections_ = true;
|
||||||
bool show_confirm_delete_connection_ = false;
|
bool show_confirm_delete_connection_ = false;
|
||||||
|
bool show_offline_warning_window_ = false;
|
||||||
bool delete_connection_ = false;
|
bool delete_connection_ = false;
|
||||||
bool is_tab_bar_hovered_ = false;
|
bool is_tab_bar_hovered_ = false;
|
||||||
std::string delete_connection_name_ = "";
|
std::string delete_connection_name_ = "";
|
||||||
|
std::string offline_warning_text_ = "";
|
||||||
bool re_enter_remote_id_ = false;
|
bool re_enter_remote_id_ = false;
|
||||||
double copy_start_time_ = 0;
|
double copy_start_time_ = 0;
|
||||||
SignalStatus signal_status_ = SignalStatus::SignalClosed;
|
SignalStatus signal_status_ = SignalStatus::SignalClosed;
|
||||||
@@ -622,10 +633,10 @@ class Render {
|
|||||||
char self_hosted_id_[17] = "";
|
char self_hosted_id_[17] = "";
|
||||||
char self_hosted_user_id_[17] = "";
|
char self_hosted_user_id_[17] = "";
|
||||||
int language_button_value_ = 0;
|
int language_button_value_ = 0;
|
||||||
int video_quality_button_value_ = 0;
|
int video_quality_button_value_ = 2;
|
||||||
int video_frame_rate_button_value_ = 1;
|
int video_frame_rate_button_value_ = 1;
|
||||||
int video_encode_format_button_value_ = 0;
|
int video_encode_format_button_value_ = 0;
|
||||||
bool enable_hardware_video_codec_ = false;
|
bool enable_hardware_video_codec_ = true;
|
||||||
bool enable_turn_ = true;
|
bool enable_turn_ = true;
|
||||||
bool enable_srtp_ = false;
|
bool enable_srtp_ = false;
|
||||||
char signal_server_ip_[256] = "api.crossdesk.cn";
|
char signal_server_ip_[256] = "api.crossdesk.cn";
|
||||||
@@ -677,4 +688,4 @@ class Render {
|
|||||||
FileTransferState file_transfer_;
|
FileTransferState file_transfer_;
|
||||||
};
|
};
|
||||||
} // namespace crossdesk
|
} // namespace crossdesk
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
#include <unordered_set>
|
||||||
|
|
||||||
#include "clipboard.h"
|
#include "clipboard.h"
|
||||||
#include "device_controller.h"
|
#include "device_controller.h"
|
||||||
@@ -20,6 +21,47 @@
|
|||||||
|
|
||||||
namespace crossdesk {
|
namespace crossdesk {
|
||||||
|
|
||||||
|
void Render::OnSignalMessageCb(const char* message, size_t size,
|
||||||
|
void* user_data) {
|
||||||
|
Render* render = (Render*)user_data;
|
||||||
|
if (!render || !message || size == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
std::string s(message, size);
|
||||||
|
auto j = nlohmann::json::parse(s, nullptr, false);
|
||||||
|
if (j.is_discarded() || !j.contains("type") || !j["type"].is_string()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
std::string type = j["type"].get<std::string>();
|
||||||
|
if (type == "presence") {
|
||||||
|
if (j.contains("devices") && j["devices"].is_array()) {
|
||||||
|
for (auto& dev : j["devices"]) {
|
||||||
|
if (!dev.is_object()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!dev.contains("id") || !dev["id"].is_string()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!dev.contains("online") || !dev["online"].is_boolean()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
std::string id = dev["id"].get<std::string>();
|
||||||
|
bool online = dev["online"].get<bool>();
|
||||||
|
render->device_presence_.SetOnline(id, online);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (type == "presence_update") {
|
||||||
|
if (j.contains("id") && j["id"].is_string() && j.contains("online") &&
|
||||||
|
j["online"].is_boolean()) {
|
||||||
|
std::string id = j["id"].get<std::string>();
|
||||||
|
bool online = j["online"].get<bool>();
|
||||||
|
if (!id.empty()) {
|
||||||
|
render->device_presence_.SetOnline(id, online);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int Render::SendKeyCommand(int key_code, bool is_down) {
|
int Render::SendKeyCommand(int key_code, bool is_down) {
|
||||||
RemoteAction remote_action;
|
RemoteAction remote_action;
|
||||||
remote_action.type = ControlType::keyboard;
|
remote_action.type = ControlType::keyboard;
|
||||||
@@ -104,11 +146,10 @@ int Render::ProcessMouseEvent(const SDL_Event& event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (props->control_bar_hovered_ || props->display_selectable_hovered_) {
|
if (props->control_bar_hovered_ || props->display_selectable_hovered_) {
|
||||||
remote_action.m.flag = MouseFlag::move;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string msg = remote_action.to_json();
|
|
||||||
if (props->peer_) {
|
if (props->peer_) {
|
||||||
|
std::string msg = remote_action.to_json();
|
||||||
SendDataFrame(props->peer_, msg.c_str(), msg.size(),
|
SendDataFrame(props->peer_, msg.c_str(), msg.size(),
|
||||||
props->data_label_.c_str());
|
props->data_label_.c_str());
|
||||||
}
|
}
|
||||||
@@ -154,8 +195,11 @@ int Render::ProcessMouseEvent(const SDL_Event& event) {
|
|||||||
(float)(last_mouse_event.button.y - props->stream_render_rect_.y) /
|
(float)(last_mouse_event.button.y - props->stream_render_rect_.y) /
|
||||||
render_height;
|
render_height;
|
||||||
|
|
||||||
std::string msg = remote_action.to_json();
|
if (props->control_bar_hovered_) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (props->peer_) {
|
if (props->peer_) {
|
||||||
|
std::string msg = remote_action.to_json();
|
||||||
SendDataFrame(props->peer_, msg.c_str(), msg.size(),
|
SendDataFrame(props->peer_, msg.c_str(), msg.size(),
|
||||||
props->data_label_.c_str());
|
props->data_label_.c_str());
|
||||||
}
|
}
|
||||||
@@ -448,9 +492,9 @@ void Render::OnReceiveDataBufferCb(const char* data, size_t size,
|
|||||||
const double bps =
|
const double bps =
|
||||||
(static_cast<double>(delta_bytes) * 8.0) / delta_seconds;
|
(static_cast<double>(delta_bytes) * 8.0) / delta_seconds;
|
||||||
if (bps > 0.0) {
|
if (bps > 0.0) {
|
||||||
const double capped = (std::min)(
|
const double capped =
|
||||||
bps,
|
(std::min)(bps, static_cast<double>(
|
||||||
static_cast<double>((std::numeric_limits<uint32_t>::max)()));
|
(std::numeric_limits<uint32_t>::max)()));
|
||||||
estimated_rate_bps = static_cast<uint32_t>(capped);
|
estimated_rate_bps = static_cast<uint32_t>(capped);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -566,13 +610,6 @@ void Render::OnReceiveDataBufferCb(const char* data, size_t size,
|
|||||||
remote_action.i.host_name, remote_action.i.host_name_size);
|
remote_action.i.host_name, remote_action.i.host_name_size);
|
||||||
LOG_INFO("Remote hostname: [{}]",
|
LOG_INFO("Remote hostname: [{}]",
|
||||||
render->connection_host_names_[remote_id]);
|
render->connection_host_names_[remote_id]);
|
||||||
|
|
||||||
for (int i = 0; i < remote_action.i.display_num; i++) {
|
|
||||||
render->display_info_list_.push_back(
|
|
||||||
DisplayInfo(remote_action.i.display_list[i],
|
|
||||||
remote_action.i.left[i], remote_action.i.top[i],
|
|
||||||
remote_action.i.right[i], remote_action.i.bottom[i]));
|
|
||||||
}
|
|
||||||
FreeRemoteAction(remote_action);
|
FreeRemoteAction(remote_action);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -141,7 +141,7 @@ int Render::ControlBar(std::shared_ptr<SubStreamWindowProperties>& props) {
|
|||||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f);
|
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f);
|
||||||
if (props->control_bar_expand_) {
|
if (props->control_bar_expand_) {
|
||||||
ImGui::SetCursorPosX(props->is_control_bar_in_left_
|
ImGui::SetCursorPosX(props->is_control_bar_in_left_
|
||||||
? props->control_window_width_ * 1.03f
|
? props->control_window_width_ * 0.03f
|
||||||
: props->control_window_width_ * 0.17f);
|
: props->control_window_width_ * 0.17f);
|
||||||
|
|
||||||
ImDrawList* draw_list = ImGui::GetWindowDrawList();
|
ImDrawList* draw_list = ImGui::GetWindowDrawList();
|
||||||
@@ -359,13 +359,11 @@ int Render::ControlBar(std::shared_ptr<SubStreamWindowProperties>& props) {
|
|||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
float expand_button_pos_x =
|
float expand_button_pos_x = props->control_bar_expand_
|
||||||
props->control_bar_expand_ ? (props->is_control_bar_in_left_
|
? (props->is_control_bar_in_left_
|
||||||
? props->control_window_width_ * 1.917f
|
? props->control_window_width_ * 0.917f
|
||||||
: props->control_window_width_ * 0.03f)
|
: props->control_window_width_ * 0.03f)
|
||||||
: (props->is_control_bar_in_left_
|
: props->control_window_width_ * 0.11f;
|
||||||
? props->control_window_width_ * 1.02f
|
|
||||||
: props->control_window_width_ * 0.23f);
|
|
||||||
|
|
||||||
ImGui::SetCursorPosX(expand_button_pos_x);
|
ImGui::SetCursorPosX(expand_button_pos_x);
|
||||||
|
|
||||||
@@ -397,9 +395,7 @@ int Render::ControlBar(std::shared_ptr<SubStreamWindowProperties>& props) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int Render::NetTrafficStats(std::shared_ptr<SubStreamWindowProperties>& props) {
|
int Render::NetTrafficStats(std::shared_ptr<SubStreamWindowProperties>& props) {
|
||||||
ImGui::SetCursorPos(ImVec2(props->is_control_bar_in_left_
|
ImGui::SetCursorPos(ImVec2(props->control_window_width_ * 0.048f,
|
||||||
? props->control_window_width_ * 1.02f
|
|
||||||
: props->control_window_width_ * 0.02f,
|
|
||||||
props->control_window_min_height_));
|
props->control_window_min_height_));
|
||||||
ImGui::SetWindowFontScale(0.5f);
|
ImGui::SetWindowFontScale(0.5f);
|
||||||
if (ImGui::BeginTable("NetTrafficStats", 4, ImGuiTableFlags_BordersH,
|
if (ImGui::BeginTable("NetTrafficStats", 4, ImGuiTableFlags_BordersH,
|
||||||
@@ -460,12 +456,33 @@ int Render::NetTrafficStats(std::shared_ptr<SubStreamWindowProperties>& props) {
|
|||||||
LossRateDisplay(props->net_traffic_stats_.total_inbound_stats.loss_rate);
|
LossRateDisplay(props->net_traffic_stats_.total_inbound_stats.loss_rate);
|
||||||
|
|
||||||
ImGui::TableNextColumn();
|
ImGui::TableNextColumn();
|
||||||
ImGui::Text("FPS");
|
ImGui::Text("FPS:");
|
||||||
ImGui::TableNextColumn();
|
ImGui::TableNextColumn();
|
||||||
ImGui::Text("%d", props->fps_);
|
ImGui::Text("%d", props->fps_);
|
||||||
ImGui::TableNextColumn();
|
ImGui::TableNextColumn();
|
||||||
ImGui::TableNextColumn();
|
ImGui::TableNextColumn();
|
||||||
|
|
||||||
|
ImGui::TableNextColumn();
|
||||||
|
ImGui::Text("%s:",
|
||||||
|
localization::resolution[localization_language_index_].c_str());
|
||||||
|
ImGui::TableNextColumn();
|
||||||
|
ImGui::Text("%dx%d", props->video_width_, props->video_height_);
|
||||||
|
ImGui::TableNextColumn();
|
||||||
|
ImGui::TableNextColumn();
|
||||||
|
|
||||||
|
ImGui::TableNextColumn();
|
||||||
|
ImGui::Text(
|
||||||
|
"%s:",
|
||||||
|
localization::connection_mode[localization_language_index_].c_str());
|
||||||
|
ImGui::TableNextColumn();
|
||||||
|
ImGui::Text(
|
||||||
|
"%s",
|
||||||
|
props->traversal_mode_ == 0
|
||||||
|
? localization::connection_mode_direct[localization_language_index_]
|
||||||
|
.c_str()
|
||||||
|
: localization::connection_mode_relay[localization_language_index_]
|
||||||
|
.c_str());
|
||||||
|
|
||||||
ImGui::EndTable();
|
ImGui::EndTable();
|
||||||
}
|
}
|
||||||
ImGui::SetWindowFontScale(1.0f);
|
ImGui::SetWindowFontScale(1.0f);
|
||||||
|
|||||||
@@ -9,25 +9,27 @@ int Render::StatusBar() {
|
|||||||
float status_bar_width = io.DisplaySize.x;
|
float status_bar_width = io.DisplaySize.x;
|
||||||
float status_bar_height = io.DisplaySize.y * STATUS_BAR_HEIGHT;
|
float status_bar_height = io.DisplaySize.y * STATUS_BAR_HEIGHT;
|
||||||
|
|
||||||
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
|
|
||||||
static bool a, b, c, d, e;
|
static bool a, b, c, d, e;
|
||||||
ImGui::SetNextWindowPos(ImVec2(0, io.DisplaySize.y * (1 - STATUS_BAR_HEIGHT)),
|
ImGui::SetNextWindowPos(ImVec2(0, io.DisplaySize.y * (1 - STATUS_BAR_HEIGHT)),
|
||||||
ImGuiCond_Always);
|
ImGuiCond_Always);
|
||||||
|
|
||||||
ImGui::BeginChild(
|
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(1.0f, 1.0f, 1.0f, 0.0f));
|
||||||
"StatusBar", ImVec2(status_bar_width, status_bar_height),
|
ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(1.0f, 1.0f, 1.0f, 0.0f));
|
||||||
ImGuiChildFlags_Border,
|
ImGui::BeginChild("StatusBar", ImVec2(status_bar_width, status_bar_height),
|
||||||
ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoBringToFrontOnFocus);
|
ImGuiChildFlags_Border,
|
||||||
|
ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove |
|
||||||
|
ImGuiWindowFlags_NoBringToFrontOnFocus);
|
||||||
|
ImGui::PopStyleColor(2);
|
||||||
|
|
||||||
ImVec2 dot_pos = ImVec2(status_bar_width * 0.025f,
|
ImVec2 dot_pos = ImVec2(status_bar_width * 0.025f,
|
||||||
io.DisplaySize.y * (1 - STATUS_BAR_HEIGHT * 0.5f));
|
io.DisplaySize.y * (1 - STATUS_BAR_HEIGHT * 0.5f));
|
||||||
ImDrawList* draw_list = ImGui::GetWindowDrawList();
|
ImDrawList* draw_list = ImGui::GetWindowDrawList();
|
||||||
|
draw_list->AddCircleFilled(dot_pos, status_bar_height * 0.25f,
|
||||||
|
ImColor(1.0f, 1.0f, 1.0f), 100);
|
||||||
draw_list->AddCircleFilled(dot_pos, status_bar_height * 0.2f,
|
draw_list->AddCircleFilled(dot_pos, status_bar_height * 0.2f,
|
||||||
ImColor(signal_connected_ ? 0.0f : 1.0f,
|
ImColor(signal_connected_ ? 0.0f : 1.0f,
|
||||||
signal_connected_ ? 1.0f : 0.0f, 0.0f),
|
signal_connected_ ? 1.0f : 0.0f, 0.0f),
|
||||||
100);
|
100);
|
||||||
draw_list->AddCircle(dot_pos, status_bar_height * 0.25f,
|
|
||||||
ImColor(1.0f, 1.0f, 1.0f), 100);
|
|
||||||
|
|
||||||
ImGui::SetWindowFontScale(0.6f);
|
ImGui::SetWindowFontScale(0.6f);
|
||||||
draw_list->AddText(
|
draw_list->AddText(
|
||||||
@@ -40,7 +42,6 @@ int Render::StatusBar() {
|
|||||||
.c_str());
|
.c_str());
|
||||||
ImGui::SetWindowFontScale(1.0f);
|
ImGui::SetWindowFontScale(1.0f);
|
||||||
|
|
||||||
ImGui::PopStyleColor();
|
|
||||||
ImGui::EndChild();
|
ImGui::EndChild();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#include "localization.h"
|
#include "localization.h"
|
||||||
#include "rd_log.h"
|
#include "rd_log.h"
|
||||||
#include "render.h"
|
#include "render.h"
|
||||||
|
#include "rounded_corner_button.h"
|
||||||
|
|
||||||
constexpr double kNewVersionIconBlinkIntervalSec = 2.0;
|
constexpr double kNewVersionIconBlinkIntervalSec = 2.0;
|
||||||
constexpr double kNewVersionIconBlinkOnTimeSec = 1.0;
|
constexpr double kNewVersionIconBlinkOnTimeSec = 1.0;
|
||||||
@@ -23,7 +24,7 @@ int Render::TitleBar(bool main_window) {
|
|||||||
if (io.DisplaySize.x > 0.0f && io.DisplaySize.y > 0.0f) {
|
if (io.DisplaySize.x > 0.0f && io.DisplaySize.y > 0.0f) {
|
||||||
title_bar_width = io.DisplaySize.x;
|
title_bar_width = io.DisplaySize.x;
|
||||||
title_bar_height = io.DisplaySize.y * TITLE_BAR_HEIGHT;
|
title_bar_height = io.DisplaySize.y * TITLE_BAR_HEIGHT;
|
||||||
title_bar_height_padding = io.DisplaySize.y * (TITLE_BAR_HEIGHT + 0.01f);
|
title_bar_height_padding = io.DisplaySize.y * TITLE_BAR_HEIGHT;
|
||||||
title_bar_button_width = io.DisplaySize.x * TITLE_BAR_BUTTON_WIDTH;
|
title_bar_button_width = io.DisplaySize.x * TITLE_BAR_BUTTON_WIDTH;
|
||||||
title_bar_button_height = io.DisplaySize.y * TITLE_BAR_BUTTON_HEIGHT;
|
title_bar_button_height = io.DisplaySize.y * TITLE_BAR_BUTTON_HEIGHT;
|
||||||
|
|
||||||
@@ -45,7 +46,7 @@ int Render::TitleBar(bool main_window) {
|
|||||||
title_bar_button_height = title_bar_button_height_;
|
title_bar_button_height = title_bar_button_height_;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
|
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(1.0f, 1.0f, 1.0f, 0.0f));
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
|
||||||
ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_Always);
|
ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_Always);
|
||||||
ImGui::BeginChild(main_window ? "MainTitleBar" : "StreamTitleBar",
|
ImGui::BeginChild(main_window ? "MainTitleBar" : "StreamTitleBar",
|
||||||
@@ -285,8 +286,20 @@ int Render::TitleBar(bool main_window) {
|
|||||||
float xmark_pos_y = title_bar_button_height * 0.5f;
|
float xmark_pos_y = title_bar_button_height * 0.5f;
|
||||||
float xmark_size = title_bar_button_width * 0.33f;
|
float xmark_size = title_bar_button_width * 0.33f;
|
||||||
std::string close_button = "##xmark"; // ICON_FA_XMARK;
|
std::string close_button = "##xmark"; // ICON_FA_XMARK;
|
||||||
if (ImGui::Button(close_button.c_str(),
|
bool close_button_clicked = false;
|
||||||
ImVec2(title_bar_button_width, title_bar_button_height))) {
|
if (main_window) {
|
||||||
|
close_button_clicked = RoundedCornerButton(
|
||||||
|
close_button.c_str(),
|
||||||
|
ImVec2(title_bar_button_width, title_bar_button_height), 8.5f,
|
||||||
|
ImDrawFlags_RoundCornersTopRight, true, IM_COL32(0, 0, 0, 0),
|
||||||
|
IM_COL32(250, 0, 0, 255), IM_COL32(255, 0, 0, 128));
|
||||||
|
} else {
|
||||||
|
close_button_clicked =
|
||||||
|
ImGui::Button(close_button.c_str(),
|
||||||
|
ImVec2(title_bar_button_width, title_bar_button_height));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (close_button_clicked) {
|
||||||
#if _WIN32
|
#if _WIN32
|
||||||
if (enable_minimize_to_tray_) {
|
if (enable_minimize_to_tray_) {
|
||||||
tray_->MinimizeToTray();
|
tray_->MinimizeToTray();
|
||||||
@@ -299,6 +312,7 @@ int Render::TitleBar(bool main_window) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
draw_list->AddLine(ImVec2(xmark_pos_x - xmark_size / 2 - 0.25f,
|
draw_list->AddLine(ImVec2(xmark_pos_x - xmark_size / 2 - 0.25f,
|
||||||
xmark_pos_y - xmark_size / 2 + 0.75f),
|
xmark_pos_y - xmark_size / 2 + 0.75f),
|
||||||
ImVec2(xmark_pos_x + xmark_size / 2 - 1.5f,
|
ImVec2(xmark_pos_x + xmark_size / 2 - 1.5f,
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ int Render::AboutWindow() {
|
|||||||
|
|
||||||
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
|
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 1.0f);
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 1.0f);
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 5.0f);
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 6.0f);
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f);
|
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f);
|
||||||
ImGui::SetWindowFontScale(0.5f);
|
ImGui::SetWindowFontScale(0.5f);
|
||||||
ImGui::Begin(
|
ImGui::Begin(
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ bool Render::ConnectionStatusWindow(
|
|||||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f);
|
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f);
|
||||||
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
|
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 1.0f);
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 1.0f);
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 5.0f);
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 6.0f);
|
||||||
|
|
||||||
ImGui::Begin("ConnectionStatusWindow", nullptr,
|
ImGui::Begin("ConnectionStatusWindow", nullptr,
|
||||||
ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove |
|
ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove |
|
||||||
|
|||||||
@@ -42,50 +42,74 @@ int Render::ControlWindow(std::shared_ptr<SubStreamWindowProperties>& props) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(1, 1, 1, 1));
|
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0, 0, 0, 0));
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowMinSize, ImVec2(0, 0));
|
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 10.0f);
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 10.0f);
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, 10.0f);
|
ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, 10.0f);
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
|
||||||
|
|
||||||
ImGui::SetNextWindowSize(
|
float y_boundary = fullscreen_button_pressed_ ? 0.0f : title_bar_height_;
|
||||||
ImVec2(props->control_window_width_, props->control_window_height_),
|
float container_x = 0.0f;
|
||||||
ImGuiCond_Always);
|
float container_y = y_boundary;
|
||||||
|
float container_w = stream_window_width_;
|
||||||
|
float container_h = stream_window_height_ - y_boundary;
|
||||||
|
|
||||||
ImGui::SetNextWindowPos(ImVec2(0, title_bar_height_), ImGuiCond_Once);
|
ImGui::SetNextWindowSize(ImVec2(container_w, container_h), ImGuiCond_Always);
|
||||||
|
ImGui::SetNextWindowPos(ImVec2(container_x, container_y), ImGuiCond_Always);
|
||||||
|
|
||||||
float pos_x = 0;
|
float pos_x = 0;
|
||||||
float pos_y = 0;
|
float pos_y = 0;
|
||||||
float y_boundary = fullscreen_button_pressed_ ? 0 : title_bar_height_;
|
|
||||||
|
|
||||||
if (props->reset_control_bar_pos_) {
|
std::string container_window_title =
|
||||||
float new_cursor_pos_x = 0;
|
props->remote_id_ + "ControlContainerWindow";
|
||||||
float new_cursor_pos_y = 0;
|
ImGui::Begin(container_window_title.c_str(), nullptr,
|
||||||
|
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize |
|
||||||
|
ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoDocking |
|
||||||
|
ImGuiWindowFlags_NoBackground);
|
||||||
|
ImGui::PopStyleVar();
|
||||||
|
|
||||||
|
ImVec2 container_pos = ImGui::GetWindowPos();
|
||||||
|
|
||||||
|
if (ImGui::IsMouseDown(ImGuiMouseButton_Left) &&
|
||||||
|
props->control_bar_hovered_) {
|
||||||
|
float current_x_rel = props->control_window_pos_.x - container_pos.x;
|
||||||
|
float current_y_rel = props->control_window_pos_.y - container_pos.y;
|
||||||
|
ImVec2 delta = ImGui::GetIO().MouseDelta;
|
||||||
|
pos_x = current_x_rel + delta.x;
|
||||||
|
pos_y = current_y_rel + delta.y;
|
||||||
|
if (pos_x < 0.0f) pos_x = 0.0f;
|
||||||
|
if (pos_y < 0.0f) pos_y = 0.0f;
|
||||||
|
if (pos_x + props->control_window_width_ > container_w)
|
||||||
|
pos_x = container_w - props->control_window_width_;
|
||||||
|
if (pos_y + props->control_window_height_ > container_h)
|
||||||
|
pos_y = container_h - props->control_window_height_;
|
||||||
|
} else if (props->reset_control_bar_pos_) {
|
||||||
|
float new_cursor_pos_x = 0.0f;
|
||||||
|
float new_cursor_pos_y = 0.0f;
|
||||||
|
|
||||||
// set control window pos
|
// set control window pos
|
||||||
if (props->control_window_pos_.y + props->control_window_height_ >
|
float current_y_rel = props->control_window_pos_.y - container_pos.y;
|
||||||
stream_window_height_) {
|
if (current_y_rel + props->control_window_height_ > container_h) {
|
||||||
pos_y = stream_window_height_ - props->control_window_height_;
|
pos_y = container_h - props->control_window_height_;
|
||||||
} else if (props->control_window_pos_.y < y_boundary) {
|
} else if (current_y_rel < 0.0f) {
|
||||||
pos_y = y_boundary;
|
pos_y = 0.0f;
|
||||||
} else {
|
} else {
|
||||||
pos_y = props->control_window_pos_.y;
|
pos_y = current_y_rel;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (props->is_control_bar_in_left_) {
|
if (props->is_control_bar_in_left_) {
|
||||||
pos_x = 0;
|
pos_x = 0.0f;
|
||||||
} else {
|
} else {
|
||||||
pos_x = stream_window_width_ - props->control_window_width_;
|
pos_x = container_w - props->control_window_width_;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::SetNextWindowPos(ImVec2(pos_x, pos_y), ImGuiCond_Always);
|
|
||||||
|
|
||||||
if (0 != props->mouse_diff_control_bar_pos_x_ &&
|
if (0 != props->mouse_diff_control_bar_pos_x_ &&
|
||||||
0 != props->mouse_diff_control_bar_pos_y_) {
|
0 != props->mouse_diff_control_bar_pos_y_) {
|
||||||
// set cursor pos
|
// set cursor pos
|
||||||
new_cursor_pos_x = pos_x + props->mouse_diff_control_bar_pos_x_;
|
new_cursor_pos_x =
|
||||||
new_cursor_pos_y = pos_y + props->mouse_diff_control_bar_pos_y_;
|
container_pos.x + pos_x + props->mouse_diff_control_bar_pos_x_;
|
||||||
|
new_cursor_pos_y =
|
||||||
|
container_pos.y + pos_y + props->mouse_diff_control_bar_pos_y_;
|
||||||
|
|
||||||
SDL_WarpMouseInWindow(stream_window_, (int)new_cursor_pos_x,
|
SDL_WarpMouseInWindow(stream_window_, (int)new_cursor_pos_x,
|
||||||
(int)new_cursor_pos_y);
|
(int)new_cursor_pos_y);
|
||||||
@@ -94,12 +118,14 @@ int Render::ControlWindow(std::shared_ptr<SubStreamWindowProperties>& props) {
|
|||||||
} else if (!props->reset_control_bar_pos_ &&
|
} else if (!props->reset_control_bar_pos_ &&
|
||||||
ImGui::IsMouseReleased(ImGuiMouseButton_Left) ||
|
ImGui::IsMouseReleased(ImGuiMouseButton_Left) ||
|
||||||
props->control_window_width_is_changing_) {
|
props->control_window_width_is_changing_) {
|
||||||
if (props->control_window_pos_.x <= stream_window_width_ * 0.5f) {
|
float current_x_rel = props->control_window_pos_.x - container_pos.x;
|
||||||
if (props->control_window_pos_.y + props->control_window_height_ >
|
float current_y_rel = props->control_window_pos_.y - container_pos.y;
|
||||||
stream_window_height_) {
|
if (current_x_rel <= container_w * 0.5f) {
|
||||||
pos_y = stream_window_height_ - props->control_window_height_;
|
pos_x = 0.0f;
|
||||||
|
if (current_y_rel + props->control_window_height_ > container_h) {
|
||||||
|
pos_y = container_h - props->control_window_height_;
|
||||||
} else {
|
} else {
|
||||||
pos_y = props->control_window_pos_.y;
|
pos_y = current_y_rel;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (props->control_bar_expand_) {
|
if (props->control_bar_expand_) {
|
||||||
@@ -118,47 +144,53 @@ int Render::ControlWindow(std::shared_ptr<SubStreamWindowProperties>& props) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
props->is_control_bar_in_left_ = true;
|
props->is_control_bar_in_left_ = true;
|
||||||
} else if (props->control_window_pos_.x > stream_window_width_ * 0.5f) {
|
} else if (current_x_rel > container_w * 0.5f) {
|
||||||
pos_x = 0;
|
pos_x = container_w - props->control_window_width_;
|
||||||
pos_y =
|
pos_y = (current_y_rel >= 0.0f &&
|
||||||
(props->control_window_pos_.y >= y_boundary &&
|
current_y_rel <= container_h - props->control_window_height_)
|
||||||
props->control_window_pos_.y <=
|
? current_y_rel
|
||||||
stream_window_height_ - props->control_window_height_)
|
: (current_y_rel < 0.0f
|
||||||
? props->control_window_pos_.y
|
? 0.0f
|
||||||
: (props->control_window_pos_.y <
|
: (container_h - props->control_window_height_));
|
||||||
(fullscreen_button_pressed_ ? 0 : title_bar_height_)
|
|
||||||
? (fullscreen_button_pressed_ ? 0 : title_bar_height_)
|
|
||||||
: (stream_window_height_ - props->control_window_height_));
|
|
||||||
|
|
||||||
if (props->control_bar_expand_) {
|
if (props->control_bar_expand_) {
|
||||||
if (props->control_window_width_ >= props->control_window_max_width_) {
|
if (props->control_window_width_ >= props->control_window_max_width_) {
|
||||||
props->control_window_width_ = props->control_window_max_width_;
|
props->control_window_width_ = props->control_window_max_width_;
|
||||||
props->control_window_width_is_changing_ = false;
|
props->control_window_width_is_changing_ = false;
|
||||||
pos_x = stream_window_width_ - props->control_window_max_width_;
|
pos_x = container_w - props->control_window_max_width_;
|
||||||
} else {
|
} else {
|
||||||
props->control_window_width_is_changing_ = true;
|
props->control_window_width_is_changing_ = true;
|
||||||
pos_x = stream_window_width_ - props->control_window_width_;
|
pos_x = container_w - props->control_window_width_;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (props->control_window_width_ <= props->control_window_min_width_) {
|
if (props->control_window_width_ <= props->control_window_min_width_) {
|
||||||
props->control_window_width_ = props->control_window_min_width_;
|
props->control_window_width_ = props->control_window_min_width_;
|
||||||
props->control_window_width_is_changing_ = false;
|
props->control_window_width_is_changing_ = false;
|
||||||
pos_x = stream_window_width_ - props->control_window_min_width_;
|
pos_x = container_w - props->control_window_min_width_;
|
||||||
} else {
|
} else {
|
||||||
props->control_window_width_is_changing_ = true;
|
props->control_window_width_is_changing_ = true;
|
||||||
pos_x = stream_window_width_ - props->control_window_width_;
|
pos_x = container_w - props->control_window_width_;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
props->is_control_bar_in_left_ = false;
|
props->is_control_bar_in_left_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (props->control_window_pos_.y + props->control_window_height_ >
|
if (current_y_rel + props->control_window_height_ > container_h) {
|
||||||
stream_window_height_) {
|
pos_y = container_h - props->control_window_height_;
|
||||||
pos_y = stream_window_height_ - props->control_window_height_;
|
} else if (current_y_rel < 0.0f) {
|
||||||
} else if (props->control_window_pos_.y < y_boundary) {
|
pos_y = 0.0f;
|
||||||
pos_y = y_boundary;
|
|
||||||
}
|
}
|
||||||
ImGui::SetNextWindowPos(ImVec2(pos_x, pos_y), ImGuiCond_Always);
|
} else {
|
||||||
|
float current_x_rel = props->control_window_pos_.x - container_pos.x;
|
||||||
|
float current_y_rel = props->control_window_pos_.y - container_pos.y;
|
||||||
|
pos_x = current_x_rel;
|
||||||
|
pos_y = current_y_rel;
|
||||||
|
if (pos_x < 0.0f) pos_x = 0.0f;
|
||||||
|
if (pos_y < 0.0f) pos_y = 0.0f;
|
||||||
|
if (pos_x + props->control_window_width_ > container_w)
|
||||||
|
pos_x = container_w - props->control_window_width_;
|
||||||
|
if (pos_y + props->control_window_height_ > container_h)
|
||||||
|
pos_y = container_h - props->control_window_height_;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (props->control_bar_expand_ && props->control_window_height_is_changing_) {
|
if (props->control_bar_expand_ && props->control_window_height_is_changing_) {
|
||||||
@@ -180,10 +212,20 @@ int Render::ControlWindow(std::shared_ptr<SubStreamWindowProperties>& props) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string control_window_title = props->remote_id_ + "ControlWindow";
|
std::string control_window_title = props->remote_id_ + "ControlWindow";
|
||||||
ImGui::Begin(control_window_title.c_str(), nullptr,
|
|
||||||
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize |
|
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
|
||||||
ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoDocking);
|
static bool a, b, c, d, e;
|
||||||
ImGui::PopStyleVar();
|
float child_cursor_x = pos_x;
|
||||||
|
float child_cursor_y = pos_y;
|
||||||
|
ImGui::SetCursorPos(ImVec2(child_cursor_x, child_cursor_y));
|
||||||
|
|
||||||
|
std::string control_child_window_title =
|
||||||
|
props->remote_id_ + "ControlChildWindow";
|
||||||
|
ImGui::BeginChild(
|
||||||
|
control_child_window_title.c_str(),
|
||||||
|
ImVec2(props->control_window_width_, props->control_window_height_),
|
||||||
|
ImGuiChildFlags_Border, ImGuiWindowFlags_NoDecoration);
|
||||||
|
ImGui::PopStyleColor();
|
||||||
|
|
||||||
props->control_window_pos_ = ImGui::GetWindowPos();
|
props->control_window_pos_ = ImGui::GetWindowPos();
|
||||||
SDL_GetMouseState(&props->mouse_pos_x_, &props->mouse_pos_y_);
|
SDL_GetMouseState(&props->mouse_pos_x_, &props->mouse_pos_y_);
|
||||||
@@ -192,31 +234,26 @@ int Render::ControlWindow(std::shared_ptr<SubStreamWindowProperties>& props) {
|
|||||||
props->mouse_diff_control_bar_pos_y_ =
|
props->mouse_diff_control_bar_pos_y_ =
|
||||||
props->mouse_pos_y_ - props->control_window_pos_.y;
|
props->mouse_pos_y_ - props->control_window_pos_.y;
|
||||||
|
|
||||||
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
|
if (props->control_window_pos_.y < container_pos.y ||
|
||||||
static bool a, b, c, d, e;
|
props->control_window_pos_.y + props->control_window_height_ >
|
||||||
ImGui::SetNextWindowPos(
|
(container_pos.y + container_h) ||
|
||||||
ImVec2(props->is_control_bar_in_left_
|
props->control_window_pos_.x < container_pos.x ||
|
||||||
? props->control_window_pos_.x - props->control_window_width_
|
props->control_window_pos_.x + props->control_window_width_ >
|
||||||
: props->control_window_pos_.x,
|
(container_pos.x + container_w)) {
|
||||||
props->control_window_pos_.y),
|
ImGui::ClearActiveID();
|
||||||
ImGuiCond_Always);
|
props->reset_control_bar_pos_ = true;
|
||||||
|
props->mouse_diff_control_bar_pos_x_ = 0;
|
||||||
std::string control_child_window_title =
|
props->mouse_diff_control_bar_pos_y_ = 0;
|
||||||
props->remote_id_ + "ControlChildWindow";
|
}
|
||||||
ImGui::BeginChild(control_child_window_title.c_str(),
|
|
||||||
ImVec2(props->control_window_width_ * 2.0f,
|
|
||||||
props->control_window_height_),
|
|
||||||
ImGuiChildFlags_Border, ImGuiWindowFlags_NoDecoration);
|
|
||||||
ImGui::PopStyleColor();
|
|
||||||
|
|
||||||
ControlBar(props);
|
ControlBar(props);
|
||||||
props->control_bar_hovered_ = ImGui::IsWindowHovered();
|
props->control_bar_hovered_ = ImGui::IsWindowHovered();
|
||||||
|
|
||||||
ImGui::EndChild();
|
ImGui::EndChild();
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
ImGui::PopStyleVar(4);
|
ImGui::PopStyleVar(3);
|
||||||
ImGui::PopStyleColor();
|
ImGui::PopStyleColor();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
} // namespace crossdesk
|
} // namespace crossdesk
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ int Render::SettingWindow() {
|
|||||||
int settings_items_offset = 0;
|
int settings_items_offset = 0;
|
||||||
|
|
||||||
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
|
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 5.0f);
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 6.0f);
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f);
|
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f);
|
||||||
|
|
||||||
ImGui::Begin(localization::settings[localization_language_index_].c_str(),
|
ImGui::Begin(localization::settings[localization_language_index_].c_str(),
|
||||||
@@ -331,10 +331,14 @@ int Render::SettingWindow() {
|
|||||||
ImGui::EndTooltip();
|
ImGui::EndTooltip();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#if _WIN32
|
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
|
|
||||||
{
|
{
|
||||||
|
#ifndef _WIN32
|
||||||
|
ImGui::BeginDisabled();
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.5f, 0.5f, 0.5f, 1.0f));
|
||||||
|
#endif
|
||||||
settings_items_offset += settings_items_padding;
|
settings_items_offset += settings_items_padding;
|
||||||
ImGui::SetCursorPosY(settings_items_offset);
|
ImGui::SetCursorPosY(settings_items_offset);
|
||||||
ImGui::AlignTextToFramePadding();
|
ImGui::AlignTextToFramePadding();
|
||||||
@@ -350,8 +354,11 @@ int Render::SettingWindow() {
|
|||||||
|
|
||||||
ImGui::Checkbox("##enable_minimize_to_tray_",
|
ImGui::Checkbox("##enable_minimize_to_tray_",
|
||||||
&enable_minimize_to_tray_);
|
&enable_minimize_to_tray_);
|
||||||
}
|
#ifndef _WIN32
|
||||||
|
ImGui::PopStyleColor();
|
||||||
|
ImGui::EndDisabled();
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
|
|
||||||
@@ -365,7 +372,7 @@ int Render::SettingWindow() {
|
|||||||
.c_str());
|
.c_str());
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
if (ConfigCenter::LANGUAGE::CHINESE == localization_language_) {
|
if (ConfigCenter::LANGUAGE::CHINESE == localization_language_) {
|
||||||
ImGui::SetCursorPosX(title_bar_button_width_ * 2.8f);
|
ImGui::SetCursorPosX(title_bar_button_width_ * 2.82f);
|
||||||
} else {
|
} else {
|
||||||
ImGui::SetCursorPosX(title_bar_button_width_ * 4.3f);
|
ImGui::SetCursorPosX(title_bar_button_width_ * 4.3f);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ int Render::MainWindow() {
|
|||||||
ImGui::SetNextWindowPos(ImVec2(0.0f, io.DisplaySize.y * (TITLE_BAR_HEIGHT)),
|
ImGui::SetNextWindowPos(ImVec2(0.0f, io.DisplaySize.y * (TITLE_BAR_HEIGHT)),
|
||||||
ImGuiCond_Always);
|
ImGuiCond_Always);
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
|
||||||
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
|
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(1.0f, 1.0f, 1.0f, 0.0f));
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(1.0f, 1.0f, 1.0f, 0.0f));
|
||||||
ImGui::BeginChild(
|
ImGui::BeginChild(
|
||||||
"DeskWindow",
|
"DeskWindow",
|
||||||
ImVec2(local_remote_window_width, local_remote_window_height),
|
ImVec2(local_remote_window_width, local_remote_window_height),
|
||||||
@@ -22,7 +23,7 @@ int Render::MainWindow() {
|
|||||||
ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove |
|
ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove |
|
||||||
ImGuiWindowFlags_NoBringToFrontOnFocus);
|
ImGuiWindowFlags_NoBringToFrontOnFocus);
|
||||||
ImGui::PopStyleVar();
|
ImGui::PopStyleVar();
|
||||||
ImGui::PopStyleColor();
|
ImGui::PopStyleColor(2);
|
||||||
|
|
||||||
LocalWindow();
|
LocalWindow();
|
||||||
|
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ int Render::RequestPermissionWindow() {
|
|||||||
|
|
||||||
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
|
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 1.0f);
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 1.0f);
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 5.0f);
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 6.0f);
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f);
|
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f);
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
|
||||||
|
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ int Render::SelfHostedServerWindow() {
|
|||||||
{
|
{
|
||||||
ImGui::SetWindowFontScale(0.5f);
|
ImGui::SetWindowFontScale(0.5f);
|
||||||
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
|
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 5.0f);
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 6.0f);
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f);
|
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f);
|
||||||
|
|
||||||
ImGui::Begin(localization::self_hosted_server_settings
|
ImGui::Begin(localization::self_hosted_server_settings
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include "localization.h"
|
#include "localization.h"
|
||||||
#include "rd_log.h"
|
#include "rd_log.h"
|
||||||
#include "render.h"
|
#include "render.h"
|
||||||
|
#include "rounded_corner_button.h"
|
||||||
|
|
||||||
namespace crossdesk {
|
namespace crossdesk {
|
||||||
|
|
||||||
@@ -48,17 +49,19 @@ int Render::ServerWindow() {
|
|||||||
ImGui::SetNextWindowSize(ImVec2(server_window_width_, server_window_height_),
|
ImGui::SetNextWindowSize(ImVec2(server_window_width_, server_window_height_),
|
||||||
ImGuiCond_Always);
|
ImGuiCond_Always);
|
||||||
ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_Always);
|
ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_Always);
|
||||||
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 6.0f);
|
||||||
ImGui::Begin("##server_window", nullptr,
|
ImGui::Begin("##server_window", nullptr,
|
||||||
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize |
|
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize |
|
||||||
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse |
|
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse |
|
||||||
ImGuiWindowFlags_NoScrollbar |
|
ImGuiWindowFlags_NoScrollbar |
|
||||||
ImGuiWindowFlags_NoScrollWithMouse);
|
ImGuiWindowFlags_NoScrollWithMouse);
|
||||||
|
ImGui::PopStyleVar();
|
||||||
|
|
||||||
server_window_title_bar_height_ = title_bar_height_;
|
server_window_title_bar_height_ = title_bar_height_;
|
||||||
|
|
||||||
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
|
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(1.0f, 1.0f, 1.0f, 0.0f));
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
|
||||||
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 6.0f);
|
||||||
ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_Always);
|
ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_Always);
|
||||||
ImGui::BeginChild(
|
ImGui::BeginChild(
|
||||||
"ServerTitleBar",
|
"ServerTitleBar",
|
||||||
@@ -83,9 +86,13 @@ int Render::ServerWindow() {
|
|||||||
const char* icon =
|
const char* icon =
|
||||||
server_window_collapsed_ ? ICON_FA_ANGLE_DOWN : ICON_FA_ANGLE_UP;
|
server_window_collapsed_ ? ICON_FA_ANGLE_DOWN : ICON_FA_ANGLE_UP;
|
||||||
std::string toggle_label = std::string(icon) + "##server_toggle";
|
std::string toggle_label = std::string(icon) + "##server_toggle";
|
||||||
if (ImGui::Button(toggle_label.c_str(),
|
|
||||||
ImVec2(server_title_bar_button_width,
|
bool toggle_clicked = RoundedCornerButton(
|
||||||
server_title_bar_button_height))) {
|
toggle_label.c_str(),
|
||||||
|
ImVec2(server_title_bar_button_width, server_title_bar_button_height),
|
||||||
|
8.5f, ImDrawFlags_RoundCornersTopLeft, true, IM_COL32(0, 0, 0, 0),
|
||||||
|
IM_COL32(0, 0, 0, 25), IM_COL32(255, 255, 255, 255));
|
||||||
|
if (toggle_clicked) {
|
||||||
if (server_window_) {
|
if (server_window_) {
|
||||||
int w = 0;
|
int w = 0;
|
||||||
int h = 0;
|
int h = 0;
|
||||||
@@ -114,7 +121,7 @@ int Render::ServerWindow() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ImGui::EndChild();
|
ImGui::EndChild();
|
||||||
ImGui::PopStyleVar();
|
ImGui::PopStyleVar(2);
|
||||||
ImGui::PopStyleColor();
|
ImGui::PopStyleColor();
|
||||||
|
|
||||||
RemoteClientInfoWindow();
|
RemoteClientInfoWindow();
|
||||||
|
|||||||
@@ -117,7 +117,9 @@ int Render::StreamWindow() {
|
|||||||
ImGui::SetWindowFontScale(0.6f);
|
ImGui::SetWindowFontScale(0.6f);
|
||||||
|
|
||||||
ImGui::SetNextWindowSize(
|
ImGui::SetNextWindowSize(
|
||||||
ImVec2(stream_window_width_, stream_window_height_),
|
ImVec2(stream_window_width_,
|
||||||
|
stream_window_height_ -
|
||||||
|
(fullscreen_button_pressed_ ? 0 : title_bar_height_)),
|
||||||
ImGuiCond_Always);
|
ImGuiCond_Always);
|
||||||
ImGui::SetNextWindowPos(
|
ImGui::SetNextWindowPos(
|
||||||
ImVec2(0, fullscreen_button_pressed_ ? 0 : title_bar_height_),
|
ImVec2(0, fullscreen_button_pressed_ ? 0 : title_bar_height_),
|
||||||
@@ -138,7 +140,7 @@ int Render::StreamWindow() {
|
|||||||
UpdateRenderRect();
|
UpdateRenderRect();
|
||||||
|
|
||||||
ControlWindow(props);
|
ControlWindow(props);
|
||||||
|
|
||||||
// Show file transfer window if needed
|
// Show file transfer window if needed
|
||||||
FileTransferWindow(props);
|
FileTransferWindow(props);
|
||||||
|
|
||||||
@@ -151,12 +153,12 @@ int Render::StreamWindow() {
|
|||||||
// std::unique_lock unique_lock(client_properties_mutex_);
|
// std::unique_lock unique_lock(client_properties_mutex_);
|
||||||
auto erase_it = client_properties_.find(remote_id_to_erase);
|
auto erase_it = client_properties_.find(remote_id_to_erase);
|
||||||
if (erase_it != client_properties_.end()) {
|
if (erase_it != client_properties_.end()) {
|
||||||
erase_it = client_properties_.erase(erase_it);
|
// Ensure we flush pending STREAM_REFRESH_EVENT events and
|
||||||
if (client_properties_.empty()) {
|
// clean up peer resources before erasing the entry, otherwise
|
||||||
SDL_Event event;
|
// SDL events may still hold raw pointers to freed
|
||||||
event.type = SDL_EVENT_QUIT;
|
// SubStreamWindowProperties (including video_frame_mutex_),
|
||||||
SDL_PushEvent(&event);
|
// leading to std::system_error when locking.
|
||||||
}
|
CloseTab(erase_it);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// lock.lock();
|
// lock.lock();
|
||||||
@@ -217,7 +219,9 @@ int Render::StreamWindow() {
|
|||||||
|
|
||||||
if (props->tab_selected_) {
|
if (props->tab_selected_) {
|
||||||
ImGui::SetNextWindowSize(
|
ImGui::SetNextWindowSize(
|
||||||
ImVec2(stream_window_width_, stream_window_height_),
|
ImVec2(stream_window_width_,
|
||||||
|
stream_window_height_ -
|
||||||
|
(fullscreen_button_pressed_ ? 0 : title_bar_height_)),
|
||||||
ImGuiCond_Always);
|
ImGuiCond_Always);
|
||||||
ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_Always);
|
ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_Always);
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
|
||||||
@@ -236,10 +240,10 @@ int Render::StreamWindow() {
|
|||||||
UpdateRenderRect();
|
UpdateRenderRect();
|
||||||
|
|
||||||
ControlWindow(props);
|
ControlWindow(props);
|
||||||
|
|
||||||
// Show file transfer window if needed
|
// Show file transfer window if needed
|
||||||
FileTransferWindow(props);
|
FileTransferWindow(props);
|
||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|
||||||
if (!props->peer_) {
|
if (!props->peer_) {
|
||||||
@@ -251,12 +255,7 @@ int Render::StreamWindow() {
|
|||||||
// std::unique_lock unique_lock(client_properties_mutex_);
|
// std::unique_lock unique_lock(client_properties_mutex_);
|
||||||
auto erase_it = client_properties_.find(remote_id_to_erase);
|
auto erase_it = client_properties_.find(remote_id_to_erase);
|
||||||
if (erase_it != client_properties_.end()) {
|
if (erase_it != client_properties_.end()) {
|
||||||
client_properties_.erase(erase_it);
|
CloseTab(erase_it);
|
||||||
if (client_properties_.empty()) {
|
|
||||||
SDL_Event event;
|
|
||||||
event.type = SDL_EVENT_QUIT;
|
|
||||||
SDL_PushEvent(&event);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// lock.lock();
|
// lock.lock();
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ int Render::UpdateNotificationWindow() {
|
|||||||
|
|
||||||
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
|
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 1.0f);
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 1.0f);
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 5.0f);
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 6.0f);
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f);
|
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f);
|
||||||
ImGui::Begin(
|
ImGui::Begin(
|
||||||
localization::notification[localization_language_index_].c_str(),
|
localization::notification[localization_language_index_].c_str(),
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
#define _SCREEN_CAPTURER_FACTORY_H_
|
#define _SCREEN_CAPTURER_FACTORY_H_
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include "screen_capturer_wgc.h"
|
#include "screen_capturer_win.h"
|
||||||
#elif __linux__
|
#elif __linux__
|
||||||
#include "screen_capturer_x11.h"
|
#include "screen_capturer_x11.h"
|
||||||
#elif __APPLE__
|
#elif __APPLE__
|
||||||
@@ -25,7 +25,7 @@ class ScreenCapturerFactory {
|
|||||||
public:
|
public:
|
||||||
ScreenCapturer* Create() {
|
ScreenCapturer* Create() {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
return new ScreenCapturerWgc();
|
return new ScreenCapturerWin();
|
||||||
#elif __linux__
|
#elif __linux__
|
||||||
return new ScreenCapturerX11();
|
return new ScreenCapturerX11();
|
||||||
#elif __APPLE__
|
#elif __APPLE__
|
||||||
@@ -37,4 +37,4 @@ class ScreenCapturerFactory {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
} // namespace crossdesk
|
} // namespace crossdesk
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
333
src/screen_capturer/windows/screen_capturer_dxgi.cpp
Normal file
333
src/screen_capturer/windows/screen_capturer_dxgi.cpp
Normal file
@@ -0,0 +1,333 @@
|
|||||||
|
#include "screen_capturer_dxgi.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <chrono>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "libyuv.h"
|
||||||
|
#include "rd_log.h"
|
||||||
|
|
||||||
|
namespace crossdesk {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
std::string WideToUtf8(const std::wstring& wstr) {
|
||||||
|
if (wstr.empty()) return {};
|
||||||
|
int size_needed = WideCharToMultiByte(
|
||||||
|
CP_UTF8, 0, wstr.data(), (int)wstr.size(), nullptr, 0, nullptr, nullptr);
|
||||||
|
std::string result(size_needed, 0);
|
||||||
|
WideCharToMultiByte(CP_UTF8, 0, wstr.data(), (int)wstr.size(), result.data(),
|
||||||
|
size_needed, nullptr, nullptr);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string CleanDisplayName(const std::wstring& wide_name) {
|
||||||
|
std::string name = WideToUtf8(wide_name);
|
||||||
|
name.erase(std::remove_if(name.begin(), name.end(),
|
||||||
|
[](unsigned char c) { return !std::isalnum(c); }),
|
||||||
|
name.end());
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
ScreenCapturerDxgi::ScreenCapturerDxgi() {}
|
||||||
|
ScreenCapturerDxgi::~ScreenCapturerDxgi() {
|
||||||
|
Stop();
|
||||||
|
Destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
int ScreenCapturerDxgi::Init(const int fps, cb_desktop_data cb) {
|
||||||
|
fps_ = fps;
|
||||||
|
callback_ = cb;
|
||||||
|
if (!callback_) {
|
||||||
|
LOG_ERROR("DXGI: callback is null");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!InitializeDxgi()) {
|
||||||
|
LOG_ERROR("DXGI: initialize DXGI failed");
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
|
||||||
|
EnumerateDisplays();
|
||||||
|
if (display_info_list_.empty()) {
|
||||||
|
LOG_ERROR("DXGI: no displays found");
|
||||||
|
return -3;
|
||||||
|
}
|
||||||
|
|
||||||
|
monitor_index_ = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ScreenCapturerDxgi::Destroy() {
|
||||||
|
Stop();
|
||||||
|
ReleaseDuplication();
|
||||||
|
outputs_.clear();
|
||||||
|
d3d_context_.Reset();
|
||||||
|
d3d_device_.Reset();
|
||||||
|
dxgi_factory_.Reset();
|
||||||
|
if (nv12_frame_) {
|
||||||
|
delete[] nv12_frame_;
|
||||||
|
nv12_frame_ = nullptr;
|
||||||
|
nv12_width_ = 0;
|
||||||
|
nv12_height_ = 0;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ScreenCapturerDxgi::Start(bool show_cursor) {
|
||||||
|
if (running_) return 0;
|
||||||
|
show_cursor_ = show_cursor;
|
||||||
|
|
||||||
|
if (!CreateDuplicationForMonitor(monitor_index_)) {
|
||||||
|
LOG_ERROR("DXGI: create duplication failed for monitor {}",
|
||||||
|
monitor_index_.load());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
paused_ = false;
|
||||||
|
running_ = true;
|
||||||
|
thread_ = std::thread([this]() { CaptureLoop(); });
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ScreenCapturerDxgi::Stop() {
|
||||||
|
if (!running_) return 0;
|
||||||
|
running_ = false;
|
||||||
|
if (thread_.joinable()) thread_.join();
|
||||||
|
ReleaseDuplication();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ScreenCapturerDxgi::Pause(int monitor_index) {
|
||||||
|
paused_ = true;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ScreenCapturerDxgi::Resume(int monitor_index) {
|
||||||
|
paused_ = false;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ScreenCapturerDxgi::SwitchTo(int monitor_index) {
|
||||||
|
if (monitor_index < 0 || monitor_index >= (int)display_info_list_.size()) {
|
||||||
|
LOG_ERROR("DXGI: invalid monitor index {}", monitor_index);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
paused_ = true;
|
||||||
|
monitor_index_ = monitor_index;
|
||||||
|
ReleaseDuplication();
|
||||||
|
if (!CreateDuplicationForMonitor(monitor_index_)) {
|
||||||
|
LOG_ERROR("DXGI: create duplication failed for monitor {}",
|
||||||
|
monitor_index_.load());
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
paused_ = false;
|
||||||
|
LOG_INFO("DXGI: switched to monitor {}:{}", monitor_index_.load(),
|
||||||
|
display_info_list_[monitor_index_].name);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ScreenCapturerDxgi::InitializeDxgi() {
|
||||||
|
UINT flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
|
||||||
|
#ifdef _DEBUG
|
||||||
|
flags |= D3D11_CREATE_DEVICE_DEBUG;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
D3D_FEATURE_LEVEL feature_levels[] = {
|
||||||
|
D3D_FEATURE_LEVEL_11_1, D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_1,
|
||||||
|
D3D_FEATURE_LEVEL_10_0};
|
||||||
|
|
||||||
|
D3D_FEATURE_LEVEL out_level{};
|
||||||
|
HRESULT hr = D3D11CreateDevice(
|
||||||
|
nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr, flags, feature_levels,
|
||||||
|
ARRAYSIZE(feature_levels), D3D11_SDK_VERSION, d3d_device_.GetAddressOf(),
|
||||||
|
&out_level, d3d_context_.GetAddressOf());
|
||||||
|
if (FAILED(hr)) {
|
||||||
|
hr = D3D11CreateDevice(nullptr, D3D_DRIVER_TYPE_WARP, nullptr, flags,
|
||||||
|
feature_levels, ARRAYSIZE(feature_levels),
|
||||||
|
D3D11_SDK_VERSION, d3d_device_.GetAddressOf(),
|
||||||
|
&out_level, d3d_context_.GetAddressOf());
|
||||||
|
if (FAILED(hr)) {
|
||||||
|
LOG_ERROR("DXGI: D3D11CreateDevice failed, hr={}", (int)hr);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
hr = CreateDXGIFactory1(
|
||||||
|
__uuidof(IDXGIFactory1),
|
||||||
|
reinterpret_cast<void**>(dxgi_factory_.GetAddressOf()));
|
||||||
|
if (FAILED(hr)) {
|
||||||
|
LOG_ERROR("DXGI: CreateDXGIFactory1 failed, hr={}", (int)hr);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScreenCapturerDxgi::EnumerateDisplays() {
|
||||||
|
display_info_list_.clear();
|
||||||
|
outputs_.clear();
|
||||||
|
|
||||||
|
Microsoft::WRL::ComPtr<IDXGIAdapter> adapter;
|
||||||
|
for (UINT a = 0;
|
||||||
|
dxgi_factory_->EnumAdapters(a, adapter.ReleaseAndGetAddressOf()) !=
|
||||||
|
DXGI_ERROR_NOT_FOUND;
|
||||||
|
++a) {
|
||||||
|
Microsoft::WRL::ComPtr<IDXGIOutput> output;
|
||||||
|
for (UINT o = 0; adapter->EnumOutputs(o, output.ReleaseAndGetAddressOf()) !=
|
||||||
|
DXGI_ERROR_NOT_FOUND;
|
||||||
|
++o) {
|
||||||
|
DXGI_OUTPUT_DESC desc{};
|
||||||
|
if (FAILED(output->GetDesc(&desc))) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
std::string name = CleanDisplayName(desc.DeviceName);
|
||||||
|
MONITORINFOEX mi{};
|
||||||
|
mi.cbSize = sizeof(MONITORINFOEX);
|
||||||
|
if (GetMonitorInfo(desc.Monitor, &mi)) {
|
||||||
|
bool is_primary = (mi.dwFlags & MONITORINFOF_PRIMARY) ? true : false;
|
||||||
|
DisplayInfo info((void*)desc.Monitor, name, is_primary,
|
||||||
|
mi.rcMonitor.left, mi.rcMonitor.top,
|
||||||
|
mi.rcMonitor.right, mi.rcMonitor.bottom);
|
||||||
|
// primary first
|
||||||
|
if (is_primary)
|
||||||
|
display_info_list_.insert(display_info_list_.begin(), info);
|
||||||
|
else
|
||||||
|
display_info_list_.push_back(info);
|
||||||
|
outputs_.push_back(output);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ScreenCapturerDxgi::CreateDuplicationForMonitor(int monitor_index) {
|
||||||
|
if (monitor_index < 0 || monitor_index >= (int)outputs_.size()) return false;
|
||||||
|
Microsoft::WRL::ComPtr<IDXGIOutput1> output1;
|
||||||
|
HRESULT hr = outputs_[monitor_index]->QueryInterface(
|
||||||
|
IID_PPV_ARGS(output1.GetAddressOf()));
|
||||||
|
if (FAILED(hr)) {
|
||||||
|
LOG_ERROR("DXGI: Query IDXGIOutput1 failed, hr={}", (int)hr);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
duplication_.Reset();
|
||||||
|
hr = output1->DuplicateOutput(d3d_device_.Get(), duplication_.GetAddressOf());
|
||||||
|
if (FAILED(hr)) {
|
||||||
|
LOG_ERROR("DXGI: DuplicateOutput failed, hr={}", (int)hr);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
staging_.Reset();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScreenCapturerDxgi::ReleaseDuplication() {
|
||||||
|
staging_.Reset();
|
||||||
|
if (duplication_) {
|
||||||
|
duplication_->ReleaseFrame();
|
||||||
|
}
|
||||||
|
duplication_.Reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScreenCapturerDxgi::CaptureLoop() {
|
||||||
|
const int timeout_ms = 33;
|
||||||
|
while (running_) {
|
||||||
|
if (paused_) {
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!duplication_) {
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
DXGI_OUTDUPL_FRAME_INFO frame_info{};
|
||||||
|
Microsoft::WRL::ComPtr<IDXGIResource> desktop_resource;
|
||||||
|
HRESULT hr = duplication_->AcquireNextFrame(
|
||||||
|
timeout_ms, &frame_info, desktop_resource.GetAddressOf());
|
||||||
|
if (hr == DXGI_ERROR_WAIT_TIMEOUT) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (FAILED(hr)) {
|
||||||
|
LOG_ERROR("DXGI: AcquireNextFrame failed, hr={}", (int)hr);
|
||||||
|
// attempt to recreate duplication
|
||||||
|
ReleaseDuplication();
|
||||||
|
CreateDuplicationForMonitor(monitor_index_);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Microsoft::WRL::ComPtr<ID3D11Texture2D> acquired_tex;
|
||||||
|
if (desktop_resource) {
|
||||||
|
hr = desktop_resource->QueryInterface(
|
||||||
|
IID_PPV_ARGS(acquired_tex.GetAddressOf()));
|
||||||
|
if (FAILED(hr)) {
|
||||||
|
duplication_->ReleaseFrame();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
duplication_->ReleaseFrame();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
D3D11_TEXTURE2D_DESC src_desc{};
|
||||||
|
acquired_tex->GetDesc(&src_desc);
|
||||||
|
|
||||||
|
if (!staging_) {
|
||||||
|
D3D11_TEXTURE2D_DESC staging_desc = src_desc;
|
||||||
|
staging_desc.Usage = D3D11_USAGE_STAGING;
|
||||||
|
staging_desc.BindFlags = 0;
|
||||||
|
staging_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
|
||||||
|
staging_desc.MiscFlags = 0;
|
||||||
|
hr = d3d_device_->CreateTexture2D(&staging_desc, nullptr,
|
||||||
|
staging_.GetAddressOf());
|
||||||
|
if (FAILED(hr)) {
|
||||||
|
LOG_ERROR("DXGI: CreateTexture2D staging failed, hr={}", (int)hr);
|
||||||
|
duplication_->ReleaseFrame();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
d3d_context_->CopyResource(staging_.Get(), acquired_tex.Get());
|
||||||
|
|
||||||
|
D3D11_MAPPED_SUBRESOURCE mapped{};
|
||||||
|
hr = d3d_context_->Map(staging_.Get(), 0, D3D11_MAP_READ, 0, &mapped);
|
||||||
|
if (FAILED(hr)) {
|
||||||
|
duplication_->ReleaseFrame();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
int logical_width = static_cast<int>(src_desc.Width);
|
||||||
|
int even_width = logical_width & ~1;
|
||||||
|
int even_height = static_cast<int>(src_desc.Height) & ~1;
|
||||||
|
if (even_width <= 0 || even_height <= 0) {
|
||||||
|
d3d_context_->Unmap(staging_.Get(), 0);
|
||||||
|
duplication_->ReleaseFrame();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
int nv12_size = even_width * even_height * 3 / 2;
|
||||||
|
if (!nv12_frame_ || nv12_width_ != even_width ||
|
||||||
|
nv12_height_ != even_height) {
|
||||||
|
delete[] nv12_frame_;
|
||||||
|
nv12_frame_ = new unsigned char[nv12_size];
|
||||||
|
nv12_width_ = even_width;
|
||||||
|
nv12_height_ = even_height;
|
||||||
|
}
|
||||||
|
|
||||||
|
libyuv::ARGBToNV12(static_cast<const uint8_t*>(mapped.pData),
|
||||||
|
static_cast<int>(mapped.RowPitch), nv12_frame_,
|
||||||
|
even_width, nv12_frame_ + even_width * even_height,
|
||||||
|
even_width, even_width, even_height);
|
||||||
|
|
||||||
|
if (callback_) {
|
||||||
|
callback_(nv12_frame_, nv12_size, even_width, even_height,
|
||||||
|
display_info_list_[monitor_index_].name.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
d3d_context_->Unmap(staging_.Get(), 0);
|
||||||
|
duplication_->ReleaseFrame();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace crossdesk
|
||||||
79
src/screen_capturer/windows/screen_capturer_dxgi.h
Normal file
79
src/screen_capturer/windows/screen_capturer_dxgi.h
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
* @Author: DI JUNKUN
|
||||||
|
* @Date: 2026-02-27
|
||||||
|
* Copyright (c) 2026 by DI JUNKUN, All Rights Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _SCREEN_CAPTURER_DXGI_H_
|
||||||
|
#define _SCREEN_CAPTURER_DXGI_H_
|
||||||
|
|
||||||
|
#include <Windows.h>
|
||||||
|
#include <d3d11.h>
|
||||||
|
#include <dxgi1_2.h>
|
||||||
|
#include <wrl/client.h>
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
|
#include <functional>
|
||||||
|
#include <memory>
|
||||||
|
#include <mutex>
|
||||||
|
#include <string>
|
||||||
|
#include <thread>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "rd_log.h"
|
||||||
|
#include "screen_capturer.h"
|
||||||
|
|
||||||
|
namespace crossdesk {
|
||||||
|
|
||||||
|
class ScreenCapturerDxgi : public ScreenCapturer {
|
||||||
|
public:
|
||||||
|
ScreenCapturerDxgi();
|
||||||
|
~ScreenCapturerDxgi();
|
||||||
|
|
||||||
|
public:
|
||||||
|
int Init(const int fps, cb_desktop_data cb) override;
|
||||||
|
int Destroy() override;
|
||||||
|
int Start(bool show_cursor) override;
|
||||||
|
int Stop() override;
|
||||||
|
|
||||||
|
int Pause(int monitor_index) override;
|
||||||
|
int Resume(int monitor_index) override;
|
||||||
|
|
||||||
|
int SwitchTo(int monitor_index) override;
|
||||||
|
|
||||||
|
std::vector<DisplayInfo> GetDisplayInfoList() override {
|
||||||
|
return display_info_list_;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool InitializeDxgi();
|
||||||
|
void EnumerateDisplays();
|
||||||
|
bool CreateDuplicationForMonitor(int monitor_index);
|
||||||
|
void CaptureLoop();
|
||||||
|
void ReleaseDuplication();
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<DisplayInfo> display_info_list_;
|
||||||
|
std::vector<Microsoft::WRL::ComPtr<IDXGIOutput>> outputs_;
|
||||||
|
|
||||||
|
Microsoft::WRL::ComPtr<IDXGIFactory1> dxgi_factory_;
|
||||||
|
Microsoft::WRL::ComPtr<ID3D11Device> d3d_device_;
|
||||||
|
Microsoft::WRL::ComPtr<ID3D11DeviceContext> d3d_context_;
|
||||||
|
Microsoft::WRL::ComPtr<IDXGIOutputDuplication> duplication_;
|
||||||
|
Microsoft::WRL::ComPtr<ID3D11Texture2D> staging_;
|
||||||
|
|
||||||
|
std::atomic<bool> running_{false};
|
||||||
|
std::atomic<bool> paused_{false};
|
||||||
|
std::atomic<int> monitor_index_{0};
|
||||||
|
std::atomic<bool> show_cursor_{true};
|
||||||
|
std::thread thread_;
|
||||||
|
int fps_ = 60;
|
||||||
|
cb_desktop_data callback_ = nullptr;
|
||||||
|
|
||||||
|
unsigned char* nv12_frame_ = nullptr;
|
||||||
|
int nv12_width_ = 0;
|
||||||
|
int nv12_height_ = 0;
|
||||||
|
};
|
||||||
|
} // namespace crossdesk
|
||||||
|
|
||||||
|
#endif
|
||||||
206
src/screen_capturer/windows/screen_capturer_gdi.cpp
Normal file
206
src/screen_capturer/windows/screen_capturer_gdi.cpp
Normal file
@@ -0,0 +1,206 @@
|
|||||||
|
#include "screen_capturer_gdi.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <chrono>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "libyuv.h"
|
||||||
|
#include "rd_log.h"
|
||||||
|
|
||||||
|
namespace crossdesk {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
std::string WideToUtf8(const std::wstring& wstr) {
|
||||||
|
if (wstr.empty()) return {};
|
||||||
|
int size_needed = WideCharToMultiByte(
|
||||||
|
CP_UTF8, 0, wstr.data(), (int)wstr.size(), nullptr, 0, nullptr, nullptr);
|
||||||
|
std::string result(size_needed, 0);
|
||||||
|
WideCharToMultiByte(CP_UTF8, 0, wstr.data(), (int)wstr.size(), result.data(),
|
||||||
|
size_needed, nullptr, nullptr);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string CleanDisplayName(const std::wstring& wide_name) {
|
||||||
|
std::string name = WideToUtf8(wide_name);
|
||||||
|
name.erase(std::remove_if(name.begin(), name.end(),
|
||||||
|
[](unsigned char c) { return !std::isalnum(c); }),
|
||||||
|
name.end());
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
ScreenCapturerGdi::ScreenCapturerGdi() {}
|
||||||
|
ScreenCapturerGdi::~ScreenCapturerGdi() {
|
||||||
|
Stop();
|
||||||
|
Destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL CALLBACK ScreenCapturerGdi::EnumMonitorProc(HMONITOR hMonitor, HDC, LPRECT,
|
||||||
|
LPARAM data) {
|
||||||
|
auto displays = reinterpret_cast<std::vector<DisplayInfo>*>(data);
|
||||||
|
MONITORINFOEX mi{};
|
||||||
|
mi.cbSize = sizeof(MONITORINFOEX);
|
||||||
|
if (GetMonitorInfo(hMonitor, &mi)) {
|
||||||
|
std::string name = CleanDisplayName(mi.szDevice);
|
||||||
|
bool is_primary = (mi.dwFlags & MONITORINFOF_PRIMARY) ? true : false;
|
||||||
|
DisplayInfo info((void*)hMonitor, name, is_primary, mi.rcMonitor.left,
|
||||||
|
mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom);
|
||||||
|
if (is_primary)
|
||||||
|
displays->insert(displays->begin(), info);
|
||||||
|
else
|
||||||
|
displays->push_back(info);
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScreenCapturerGdi::EnumerateDisplays() {
|
||||||
|
display_info_list_.clear();
|
||||||
|
EnumDisplayMonitors(nullptr, nullptr, EnumMonitorProc,
|
||||||
|
(LPARAM)&display_info_list_);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ScreenCapturerGdi::Init(const int fps, cb_desktop_data cb) {
|
||||||
|
fps_ = fps;
|
||||||
|
callback_ = cb;
|
||||||
|
if (!callback_) {
|
||||||
|
LOG_ERROR("GDI: callback is null");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
EnumerateDisplays();
|
||||||
|
if (display_info_list_.empty()) {
|
||||||
|
LOG_ERROR("GDI: no displays found");
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
monitor_index_ = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ScreenCapturerGdi::Destroy() {
|
||||||
|
Stop();
|
||||||
|
if (nv12_frame_) {
|
||||||
|
delete[] nv12_frame_;
|
||||||
|
nv12_frame_ = nullptr;
|
||||||
|
nv12_width_ = 0;
|
||||||
|
nv12_height_ = 0;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ScreenCapturerGdi::Start(bool show_cursor) {
|
||||||
|
if (running_) return 0;
|
||||||
|
show_cursor_ = show_cursor;
|
||||||
|
paused_ = false;
|
||||||
|
running_ = true;
|
||||||
|
thread_ = std::thread([this]() { CaptureLoop(); });
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ScreenCapturerGdi::Stop() {
|
||||||
|
if (!running_) return 0;
|
||||||
|
running_ = false;
|
||||||
|
if (thread_.joinable()) thread_.join();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ScreenCapturerGdi::Pause(int monitor_index) {
|
||||||
|
paused_ = true;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ScreenCapturerGdi::Resume(int monitor_index) {
|
||||||
|
paused_ = false;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ScreenCapturerGdi::SwitchTo(int monitor_index) {
|
||||||
|
if (monitor_index < 0 || monitor_index >= (int)display_info_list_.size()) {
|
||||||
|
LOG_ERROR("GDI: invalid monitor index {}", monitor_index);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
monitor_index_ = monitor_index;
|
||||||
|
LOG_INFO("GDI: switched to monitor {}:{}", monitor_index_.load(),
|
||||||
|
display_info_list_[monitor_index_].name);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScreenCapturerGdi::CaptureLoop() {
|
||||||
|
int interval_ms = fps_ > 0 ? (1000 / fps_) : 16;
|
||||||
|
HDC screen_dc = GetDC(nullptr);
|
||||||
|
while (running_) {
|
||||||
|
if (paused_) {
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!screen_dc) {
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto& di = display_info_list_[monitor_index_];
|
||||||
|
int left = di.left;
|
||||||
|
int top = di.top;
|
||||||
|
int width = di.width & ~1;
|
||||||
|
int height = di.height & ~1;
|
||||||
|
if (width <= 0 || height <= 0) {
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(interval_ms));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
BITMAPINFO bmi{};
|
||||||
|
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
||||||
|
bmi.bmiHeader.biWidth = width;
|
||||||
|
bmi.bmiHeader.biHeight = -height;
|
||||||
|
bmi.bmiHeader.biPlanes = 1;
|
||||||
|
bmi.bmiHeader.biBitCount = 32;
|
||||||
|
bmi.bmiHeader.biCompression = BI_RGB;
|
||||||
|
|
||||||
|
void* bits = nullptr;
|
||||||
|
HDC mem_dc = CreateCompatibleDC(screen_dc);
|
||||||
|
HBITMAP dib =
|
||||||
|
CreateDIBSection(mem_dc, &bmi, DIB_RGB_COLORS, &bits, nullptr, 0);
|
||||||
|
HGDIOBJ old = SelectObject(mem_dc, dib);
|
||||||
|
|
||||||
|
BitBlt(mem_dc, 0, 0, width, height, screen_dc, left, top,
|
||||||
|
SRCCOPY | CAPTUREBLT);
|
||||||
|
|
||||||
|
if (show_cursor_) {
|
||||||
|
CURSORINFO ci{};
|
||||||
|
ci.cbSize = sizeof(CURSORINFO);
|
||||||
|
if (GetCursorInfo(&ci) && ci.flags == CURSOR_SHOWING && ci.hCursor) {
|
||||||
|
POINT pt = ci.ptScreenPos;
|
||||||
|
int cx = pt.x - left;
|
||||||
|
int cy = pt.y - top;
|
||||||
|
if (cx >= -64 && cy >= -64 && cx < width + 64 && cy < height + 64) {
|
||||||
|
DrawIconEx(mem_dc, cx, cy, ci.hCursor, 0, 0, 0, nullptr, DI_NORMAL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int stride_argb = width * 4;
|
||||||
|
int nv12_size = width * height * 3 / 2;
|
||||||
|
if (!nv12_frame_ || nv12_width_ != width || nv12_height_ != height) {
|
||||||
|
delete[] nv12_frame_;
|
||||||
|
nv12_frame_ = new unsigned char[nv12_size];
|
||||||
|
nv12_width_ = width;
|
||||||
|
nv12_height_ = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
libyuv::ARGBToNV12(static_cast<const uint8_t*>(bits), stride_argb,
|
||||||
|
nv12_frame_, width, nv12_frame_ + width * height, width,
|
||||||
|
width, height);
|
||||||
|
|
||||||
|
if (callback_) {
|
||||||
|
callback_(nv12_frame_, nv12_size, width, height, di.name.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
SelectObject(mem_dc, old);
|
||||||
|
DeleteObject(dib);
|
||||||
|
DeleteDC(mem_dc);
|
||||||
|
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(interval_ms));
|
||||||
|
}
|
||||||
|
ReleaseDC(nullptr, screen_dc);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace crossdesk
|
||||||
66
src/screen_capturer/windows/screen_capturer_gdi.h
Normal file
66
src/screen_capturer/windows/screen_capturer_gdi.h
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
/*
|
||||||
|
* @Author: DI JUNKUN
|
||||||
|
* @Date: 2026-02-27
|
||||||
|
* Copyright (c) 2026 by DI JUNKUN, All Rights Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _SCREEN_CAPTURER_GDI_H_
|
||||||
|
#define _SCREEN_CAPTURER_GDI_H_
|
||||||
|
|
||||||
|
#include <Windows.h>
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
|
#include <functional>
|
||||||
|
#include <mutex>
|
||||||
|
#include <string>
|
||||||
|
#include <thread>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "rd_log.h"
|
||||||
|
#include "screen_capturer.h"
|
||||||
|
|
||||||
|
namespace crossdesk {
|
||||||
|
|
||||||
|
class ScreenCapturerGdi : public ScreenCapturer {
|
||||||
|
public:
|
||||||
|
ScreenCapturerGdi();
|
||||||
|
~ScreenCapturerGdi();
|
||||||
|
|
||||||
|
public:
|
||||||
|
int Init(const int fps, cb_desktop_data cb) override;
|
||||||
|
int Destroy() override;
|
||||||
|
int Start(bool show_cursor) override;
|
||||||
|
int Stop() override;
|
||||||
|
|
||||||
|
int Pause(int monitor_index) override;
|
||||||
|
int Resume(int monitor_index) override;
|
||||||
|
|
||||||
|
int SwitchTo(int monitor_index) override;
|
||||||
|
|
||||||
|
std::vector<DisplayInfo> GetDisplayInfoList() override {
|
||||||
|
return display_info_list_;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
static BOOL CALLBACK EnumMonitorProc(HMONITOR hMonitor, HDC, LPRECT,
|
||||||
|
LPARAM data);
|
||||||
|
void EnumerateDisplays();
|
||||||
|
void CaptureLoop();
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<DisplayInfo> display_info_list_;
|
||||||
|
std::atomic<bool> running_{false};
|
||||||
|
std::atomic<bool> paused_{false};
|
||||||
|
std::atomic<int> monitor_index_{0};
|
||||||
|
std::atomic<bool> show_cursor_{true};
|
||||||
|
std::thread thread_;
|
||||||
|
int fps_ = 60;
|
||||||
|
cb_desktop_data callback_ = nullptr;
|
||||||
|
|
||||||
|
unsigned char* nv12_frame_ = nullptr;
|
||||||
|
int nv12_width_ = 0;
|
||||||
|
int nv12_height_ = 0;
|
||||||
|
};
|
||||||
|
} // namespace crossdesk
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -56,8 +56,6 @@ BOOL WINAPI EnumMonitorProc(HMONITOR hmonitor, [[maybe_unused]] HDC hdc,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (monitor_info_.dwFlags == DISPLAY_DEVICE_MIRRORING_DRIVER) return true;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,6 +163,8 @@ int ScreenCapturerWgc::Start(bool show_cursor) {
|
|||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool any_started = false;
|
||||||
|
int last_error = 0;
|
||||||
for (int i = 0; i < sessions_.size(); i++) {
|
for (int i = 0; i < sessions_.size(); i++) {
|
||||||
if (sessions_[i].inited_ == false) {
|
if (sessions_[i].inited_ == false) {
|
||||||
LOG_ERROR("Session {} not inited", i);
|
LOG_ERROR("Session {} not inited", i);
|
||||||
@@ -174,17 +174,27 @@ int ScreenCapturerWgc::Start(bool show_cursor) {
|
|||||||
if (sessions_[i].running_) {
|
if (sessions_[i].running_) {
|
||||||
LOG_ERROR("Session {} is already running", i);
|
LOG_ERROR("Session {} is already running", i);
|
||||||
} else {
|
} else {
|
||||||
sessions_[i].session_->Start(show_cursor);
|
int ret = sessions_[i].session_->Start(show_cursor);
|
||||||
|
if (ret != 0) {
|
||||||
|
LOG_ERROR("Session {} start failed, ret={}", i, ret);
|
||||||
|
last_error = ret;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (i != 0) {
|
if (i != 0) {
|
||||||
sessions_[i].session_->Pause();
|
sessions_[i].session_->Pause();
|
||||||
sessions_[i].paused_ = true;
|
sessions_[i].paused_ = true;
|
||||||
}
|
}
|
||||||
sessions_[i].running_ = true;
|
sessions_[i].running_ = true;
|
||||||
|
any_started = true;
|
||||||
}
|
}
|
||||||
running_ = true;
|
running_ = running_ || any_started;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!any_started) {
|
||||||
|
LOG_ERROR("WGC: no session started successfully");
|
||||||
|
return last_error != 0 ? last_error : -1;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -327,4 +337,4 @@ void ScreenCapturerWgc::CleanUp() {
|
|||||||
sessions_.clear();
|
sessions_.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // namespace crossdesk
|
} // namespace crossdesk
|
||||||
|
|||||||
@@ -57,8 +57,8 @@ class ScreenCapturerWgc : public ScreenCapturer,
|
|||||||
|
|
||||||
std::vector<WgcSessionInfo> sessions_;
|
std::vector<WgcSessionInfo> sessions_;
|
||||||
|
|
||||||
std::atomic_bool running_;
|
std::atomic_bool running_{false};
|
||||||
std::atomic_bool inited_;
|
std::atomic_bool inited_{false};
|
||||||
|
|
||||||
int fps_ = 60;
|
int fps_ = 60;
|
||||||
|
|
||||||
@@ -72,4 +72,4 @@ class ScreenCapturerWgc : public ScreenCapturer,
|
|||||||
std::mutex frame_mutex_;
|
std::mutex frame_mutex_;
|
||||||
};
|
};
|
||||||
} // namespace crossdesk
|
} // namespace crossdesk
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
198
src/screen_capturer/windows/screen_capturer_win.cpp
Normal file
198
src/screen_capturer/windows/screen_capturer_win.cpp
Normal file
@@ -0,0 +1,198 @@
|
|||||||
|
#include "screen_capturer_win.h"
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "rd_log.h"
|
||||||
|
#include "screen_capturer_dxgi.h"
|
||||||
|
#include "screen_capturer_gdi.h"
|
||||||
|
#include "screen_capturer_wgc.h"
|
||||||
|
|
||||||
|
namespace crossdesk {
|
||||||
|
|
||||||
|
ScreenCapturerWin::ScreenCapturerWin() {}
|
||||||
|
ScreenCapturerWin::~ScreenCapturerWin() { Destroy(); }
|
||||||
|
|
||||||
|
int ScreenCapturerWin::Init(const int fps, cb_desktop_data cb) {
|
||||||
|
fps_ = fps;
|
||||||
|
cb_orig_ = cb;
|
||||||
|
cb_ = [this](unsigned char* data, int size, int w, int h,
|
||||||
|
const char* display_name) {
|
||||||
|
std::string mapped_name;
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(alias_mutex_);
|
||||||
|
auto it = label_alias_.find(display_name);
|
||||||
|
if (it != label_alias_.end())
|
||||||
|
mapped_name = it->second;
|
||||||
|
else
|
||||||
|
mapped_name = display_name;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(alias_mutex_);
|
||||||
|
if (canonical_labels_.find(mapped_name) == canonical_labels_.end()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (cb_orig_) cb_orig_(data, size, w, h, mapped_name.c_str());
|
||||||
|
};
|
||||||
|
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
impl_ = std::make_unique<ScreenCapturerWgc>();
|
||||||
|
ret = impl_->Init(fps_, cb_);
|
||||||
|
if (ret == 0) {
|
||||||
|
LOG_INFO("Windows capturer: using WGC");
|
||||||
|
BuildCanonicalFromImpl();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_WARN("Windows capturer: WGC init failed (ret={}), try DXGI", ret);
|
||||||
|
impl_.reset();
|
||||||
|
|
||||||
|
impl_ = std::make_unique<ScreenCapturerDxgi>();
|
||||||
|
ret = impl_->Init(fps_, cb_);
|
||||||
|
if (ret == 0) {
|
||||||
|
LOG_INFO("Windows capturer: using DXGI Desktop Duplication");
|
||||||
|
BuildCanonicalFromImpl();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_WARN("Windows capturer: DXGI init failed (ret={}), fallback to GDI", ret);
|
||||||
|
impl_.reset();
|
||||||
|
|
||||||
|
impl_ = std::make_unique<ScreenCapturerGdi>();
|
||||||
|
ret = impl_->Init(fps_, cb_);
|
||||||
|
if (ret == 0) {
|
||||||
|
LOG_INFO("Windows capturer: using GDI BitBlt");
|
||||||
|
BuildCanonicalFromImpl();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_ERROR("Windows capturer: all implementations failed, ret={}", ret);
|
||||||
|
impl_.reset();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ScreenCapturerWin::Destroy() {
|
||||||
|
if (impl_) {
|
||||||
|
impl_->Destroy();
|
||||||
|
impl_.reset();
|
||||||
|
}
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(alias_mutex_);
|
||||||
|
label_alias_.clear();
|
||||||
|
handle_to_canonical_.clear();
|
||||||
|
canonical_labels_.clear();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ScreenCapturerWin::Start(bool show_cursor) {
|
||||||
|
if (!impl_) return -1;
|
||||||
|
int ret = impl_->Start(show_cursor);
|
||||||
|
if (ret == 0) return 0;
|
||||||
|
|
||||||
|
LOG_WARN("Windows capturer: Start failed (ret={}), trying fallback", ret);
|
||||||
|
|
||||||
|
auto try_init_start = [&](std::unique_ptr<ScreenCapturer> cand) -> bool {
|
||||||
|
int r = cand->Init(fps_, cb_);
|
||||||
|
if (r != 0) return false;
|
||||||
|
int s = cand->Start(show_cursor);
|
||||||
|
if (s == 0) {
|
||||||
|
impl_ = std::move(cand);
|
||||||
|
RebuildAliasesFromImpl();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (dynamic_cast<ScreenCapturerWgc*>(impl_.get())) {
|
||||||
|
if (try_init_start(std::make_unique<ScreenCapturerDxgi>())) {
|
||||||
|
LOG_INFO("Windows capturer: fallback to DXGI");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (try_init_start(std::make_unique<ScreenCapturerGdi>())) {
|
||||||
|
LOG_INFO("Windows capturer: fallback to GDI");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
} else if (dynamic_cast<ScreenCapturerDxgi*>(impl_.get())) {
|
||||||
|
if (try_init_start(std::make_unique<ScreenCapturerGdi>())) {
|
||||||
|
LOG_INFO("Windows capturer: fallback to GDI");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_ERROR("Windows capturer: all fallbacks failed to start");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ScreenCapturerWin::Stop() {
|
||||||
|
if (!impl_) return 0;
|
||||||
|
return impl_->Stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
int ScreenCapturerWin::Pause(int monitor_index) {
|
||||||
|
if (!impl_) return -1;
|
||||||
|
return impl_->Pause(monitor_index);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ScreenCapturerWin::Resume(int monitor_index) {
|
||||||
|
if (!impl_) return -1;
|
||||||
|
return impl_->Resume(monitor_index);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ScreenCapturerWin::SwitchTo(int monitor_index) {
|
||||||
|
if (!impl_) return -1;
|
||||||
|
return impl_->SwitchTo(monitor_index);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<DisplayInfo> ScreenCapturerWin::GetDisplayInfoList() {
|
||||||
|
if (!impl_) return {};
|
||||||
|
return impl_->GetDisplayInfoList();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScreenCapturerWin::BuildCanonicalFromImpl() {
|
||||||
|
std::lock_guard<std::mutex> lock(alias_mutex_);
|
||||||
|
handle_to_canonical_.clear();
|
||||||
|
label_alias_.clear();
|
||||||
|
canonical_displays_ = impl_->GetDisplayInfoList();
|
||||||
|
canonical_labels_.clear();
|
||||||
|
for (const auto& di : canonical_displays_) {
|
||||||
|
handle_to_canonical_[di.handle] = di.name;
|
||||||
|
canonical_labels_.insert(di.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScreenCapturerWin::RebuildAliasesFromImpl() {
|
||||||
|
std::lock_guard<std::mutex> lock(alias_mutex_);
|
||||||
|
label_alias_.clear();
|
||||||
|
auto current = impl_->GetDisplayInfoList();
|
||||||
|
auto similar = [&](const DisplayInfo& a, const DisplayInfo& b) {
|
||||||
|
int dl = std::abs(a.left - b.left);
|
||||||
|
int dt = std::abs(a.top - b.top);
|
||||||
|
int dw = std::abs(a.width - b.width);
|
||||||
|
int dh = std::abs(a.height - b.height);
|
||||||
|
return dl <= 10 && dt <= 10 && dw <= 20 && dh <= 20;
|
||||||
|
};
|
||||||
|
for (const auto& di : current) {
|
||||||
|
std::string canonical;
|
||||||
|
auto it = handle_to_canonical_.find(di.handle);
|
||||||
|
if (it != handle_to_canonical_.end()) {
|
||||||
|
canonical = it->second;
|
||||||
|
} else {
|
||||||
|
for (const auto& c : canonical_displays_) {
|
||||||
|
if (similar(di, c) || (di.is_primary && c.is_primary)) {
|
||||||
|
canonical = c.name;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!canonical.empty() && canonical != di.name) {
|
||||||
|
label_alias_[di.name] = canonical;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace crossdesk
|
||||||
54
src/screen_capturer/windows/screen_capturer_win.h
Normal file
54
src/screen_capturer/windows/screen_capturer_win.h
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* @Author: DI JUNKUN
|
||||||
|
* @Date: 2026-02-27
|
||||||
|
* Copyright (c) 2026 by DI JUNKUN, All Rights Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _SCREEN_CAPTURER_WIN_H_
|
||||||
|
#define _SCREEN_CAPTURER_WIN_H_
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <mutex>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <unordered_set>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "screen_capturer.h"
|
||||||
|
|
||||||
|
namespace crossdesk {
|
||||||
|
|
||||||
|
class ScreenCapturerWin : public ScreenCapturer {
|
||||||
|
public:
|
||||||
|
ScreenCapturerWin();
|
||||||
|
~ScreenCapturerWin();
|
||||||
|
|
||||||
|
public:
|
||||||
|
int Init(const int fps, cb_desktop_data cb) override;
|
||||||
|
int Destroy() override;
|
||||||
|
int Start(bool show_cursor) override;
|
||||||
|
int Stop() override;
|
||||||
|
|
||||||
|
int Pause(int monitor_index) override;
|
||||||
|
int Resume(int monitor_index) override;
|
||||||
|
|
||||||
|
int SwitchTo(int monitor_index) override;
|
||||||
|
|
||||||
|
std::vector<DisplayInfo> GetDisplayInfoList() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::unique_ptr<ScreenCapturer> impl_;
|
||||||
|
int fps_ = 60;
|
||||||
|
cb_desktop_data cb_;
|
||||||
|
cb_desktop_data cb_orig_;
|
||||||
|
|
||||||
|
std::unordered_map<void*, std::string> handle_to_canonical_;
|
||||||
|
std::unordered_map<std::string, std::string> label_alias_;
|
||||||
|
std::mutex alias_mutex_;
|
||||||
|
std::vector<DisplayInfo> canonical_displays_;
|
||||||
|
std::unordered_set<std::string> canonical_labels_;
|
||||||
|
|
||||||
|
void BuildCanonicalFromImpl();
|
||||||
|
void RebuildAliasesFromImpl();
|
||||||
|
};
|
||||||
|
} // namespace crossdesk
|
||||||
|
#endif
|
||||||
@@ -7,6 +7,8 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
#include "rd_log.h"
|
||||||
|
|
||||||
#define CHECK_INIT \
|
#define CHECK_INIT \
|
||||||
if (!is_initialized_) { \
|
if (!is_initialized_) { \
|
||||||
std::cout << "AE_NEED_INIT" << std::endl; \
|
std::cout << "AE_NEED_INIT" << std::endl; \
|
||||||
@@ -64,6 +66,7 @@ int WgcSessionImpl::Start(bool show_cursor) {
|
|||||||
|
|
||||||
CHECK_INIT;
|
CHECK_INIT;
|
||||||
try {
|
try {
|
||||||
|
last_show_cursor_ = show_cursor;
|
||||||
if (!capture_session_) {
|
if (!capture_session_) {
|
||||||
auto current_size = capture_item_.Size();
|
auto current_size = capture_item_.Size();
|
||||||
capture_framepool_ =
|
capture_framepool_ =
|
||||||
@@ -89,13 +92,12 @@ int WgcSessionImpl::Start(bool show_cursor) {
|
|||||||
// we need to test the performance later
|
// we need to test the performance later
|
||||||
// loop_ = std::thread(std::bind(&WgcSessionImpl::message_func, this));
|
// loop_ = std::thread(std::bind(&WgcSessionImpl::message_func, this));
|
||||||
|
|
||||||
capture_session_.StartCapture();
|
|
||||||
|
|
||||||
capture_session_.IsCursorCaptureEnabled(show_cursor);
|
capture_session_.IsCursorCaptureEnabled(show_cursor);
|
||||||
|
capture_session_.StartCapture();
|
||||||
|
|
||||||
error = 0;
|
error = 0;
|
||||||
} catch (winrt::hresult_error) {
|
} catch (winrt::hresult_error) {
|
||||||
std::cout << "AE_WGC_CREATE_CAPTURER_FAILED" << std::endl;
|
LOG_ERROR("AE_WGC_CREATE_CAPTURER_FAILED");
|
||||||
return 86;
|
return 86;
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
return 86;
|
return 86;
|
||||||
@@ -246,8 +248,15 @@ void WgcSessionImpl::OnFrame(
|
|||||||
auto frame_captured =
|
auto frame_captured =
|
||||||
GetDXGIInterfaceFromObject<ID3D11Texture2D>(frame.Surface());
|
GetDXGIInterfaceFromObject<ID3D11Texture2D>(frame.Surface());
|
||||||
|
|
||||||
if (!d3d11_texture_mapped_ || is_new_size)
|
if (!d3d11_texture_mapped_ || is_new_size) {
|
||||||
CreateMappedTexture(frame_captured);
|
HRESULT tex_hr = CreateMappedTexture(frame_captured);
|
||||||
|
if (FAILED(tex_hr)) {
|
||||||
|
OutputDebugStringW(
|
||||||
|
(L"CreateMappedTexture failed: " + std::to_wstring(tex_hr))
|
||||||
|
.c_str());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
d3d11_device_context_->CopyResource(d3d11_texture_mapped_.get(),
|
d3d11_device_context_->CopyResource(d3d11_texture_mapped_.get(),
|
||||||
frame_captured.get());
|
frame_captured.get());
|
||||||
@@ -262,6 +271,7 @@ void WgcSessionImpl::OnFrame(
|
|||||||
if (FAILED(hr)) {
|
if (FAILED(hr)) {
|
||||||
OutputDebugStringW(
|
OutputDebugStringW(
|
||||||
(L"map resource failed: " + std::to_wstring(hr)).c_str());
|
(L"map resource failed: " + std::to_wstring(hr)).c_str());
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy data from map_result.pData
|
// copy data from map_result.pData
|
||||||
@@ -290,7 +300,24 @@ void WgcSessionImpl::OnFrame(
|
|||||||
void WgcSessionImpl::OnClosed(
|
void WgcSessionImpl::OnClosed(
|
||||||
winrt::Windows::Graphics::Capture::GraphicsCaptureItem const&,
|
winrt::Windows::Graphics::Capture::GraphicsCaptureItem const&,
|
||||||
winrt::Windows::Foundation::IInspectable const&) {
|
winrt::Windows::Foundation::IInspectable const&) {
|
||||||
OutputDebugStringW(L"WgcSessionImpl::OnClosed");
|
std::lock_guard locker(lock_);
|
||||||
|
try {
|
||||||
|
CleanUp();
|
||||||
|
is_initialized_ = false;
|
||||||
|
if (Initialize() == 0) {
|
||||||
|
int ret = Start(last_show_cursor_);
|
||||||
|
if (ret == 0) {
|
||||||
|
OutputDebugStringW(L"WgcSessionImpl::OnClosed: auto recovered");
|
||||||
|
} else {
|
||||||
|
OutputDebugStringW(L"WgcSessionImpl::OnClosed: recover Start failed");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
OutputDebugStringW(
|
||||||
|
L"WgcSessionImpl::OnClosed: recover Initialize failed");
|
||||||
|
}
|
||||||
|
} catch (...) {
|
||||||
|
OutputDebugStringW(L"WgcSessionImpl::OnClosed: exception during recover");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int WgcSessionImpl::Initialize() {
|
int WgcSessionImpl::Initialize() {
|
||||||
@@ -313,7 +340,7 @@ int WgcSessionImpl::Initialize() {
|
|||||||
d3d11_device->GetImmediateContext(d3d11_device_context_.put());
|
d3d11_device->GetImmediateContext(d3d11_device_context_.put());
|
||||||
|
|
||||||
} catch (winrt::hresult_error) {
|
} catch (winrt::hresult_error) {
|
||||||
std::cout << "AE_WGC_CREATE_CAPTURER_FAILED" << std::endl;
|
LOG_ERROR("AE_WGC_CREATE_CAPTURER_FAILED");
|
||||||
return 86;
|
return 86;
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
return 86;
|
return 86;
|
||||||
@@ -378,4 +405,4 @@ LRESULT CALLBACK WindowProc(HWND window, UINT message, WPARAM w_param,
|
|||||||
// ::CloseWindow(hwnd_);
|
// ::CloseWindow(hwnd_);
|
||||||
// ::DestroyWindow(hwnd_);
|
// ::DestroyWindow(hwnd_);
|
||||||
// }
|
// }
|
||||||
} // namespace crossdesk
|
} // namespace crossdesk
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ class WgcSessionImpl : public WgcSession {
|
|||||||
bool is_initialized_ = false;
|
bool is_initialized_ = false;
|
||||||
bool is_running_ = false;
|
bool is_running_ = false;
|
||||||
bool is_paused_ = false;
|
bool is_paused_ = false;
|
||||||
|
bool last_show_cursor_ = false;
|
||||||
|
|
||||||
wgc_session_observer* observer_ = nullptr;
|
wgc_session_observer* observer_ = nullptr;
|
||||||
|
|
||||||
@@ -116,4 +117,4 @@ class WgcSessionImpl : public WgcSession {
|
|||||||
// return result;
|
// return result;
|
||||||
// }
|
// }
|
||||||
} // namespace crossdesk
|
} // namespace crossdesk
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Submodule submodules/minirtc updated: 28ca08bce9...24a76443bb
@@ -39,7 +39,7 @@ if is_os("windows") then
|
|||||||
add_requires("libyuv", "miniaudio 0.11.21")
|
add_requires("libyuv", "miniaudio 0.11.21")
|
||||||
add_links("Shell32", "windowsapp", "dwmapi", "User32", "kernel32",
|
add_links("Shell32", "windowsapp", "dwmapi", "User32", "kernel32",
|
||||||
"SDL3-static", "gdi32", "winmm", "setupapi", "version",
|
"SDL3-static", "gdi32", "winmm", "setupapi", "version",
|
||||||
"Imm32", "iphlpapi")
|
"Imm32", "iphlpapi", "d3d11", "dxgi")
|
||||||
add_cxflags("/WX")
|
add_cxflags("/WX")
|
||||||
set_runtimes("MT")
|
set_runtimes("MT")
|
||||||
elseif is_os("linux") then
|
elseif is_os("linux") then
|
||||||
|
|||||||
Reference in New Issue
Block a user