mirror of
https://github.com/kunkundi/crossdesk.git
synced 2026-03-30 21:48:13 +08:00
Compare commits
2 Commits
f5d0291b5a
...
web-client
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4dd3c3e073 | ||
|
|
4ba4f17a6b |
@@ -329,8 +329,9 @@ int Render::ScreenCapturerInit() {
|
|||||||
|
|
||||||
int Render::StartScreenCapturer() {
|
int Render::StartScreenCapturer() {
|
||||||
if (screen_capturer_) {
|
if (screen_capturer_) {
|
||||||
LOG_INFO("Start screen capturer");
|
LOG_INFO("Start screen capturer, show cursor: {}", show_cursor_);
|
||||||
screen_capturer_->Start();
|
|
||||||
|
screen_capturer_->Start(show_cursor_);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -316,6 +316,7 @@ class Render {
|
|||||||
bool start_speaker_capturer_ = false;
|
bool start_speaker_capturer_ = false;
|
||||||
bool speaker_capturer_is_started_ = false;
|
bool speaker_capturer_is_started_ = false;
|
||||||
bool start_keyboard_capturer_ = true;
|
bool start_keyboard_capturer_ = true;
|
||||||
|
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 foucs_on_stream_window_ = false;
|
||||||
|
|||||||
@@ -464,6 +464,13 @@ void Render::OnConnectionStatusCb(ConnectionStatus status, const char* user_id,
|
|||||||
#else
|
#else
|
||||||
render->start_mouse_controller_ = true;
|
render->start_mouse_controller_ = true;
|
||||||
#endif
|
#endif
|
||||||
|
if (std::all_of(render->connection_status_.begin(),
|
||||||
|
render->connection_status_.end(), [](const auto& kv) {
|
||||||
|
return kv.first.find("web") != std::string::npos;
|
||||||
|
})) {
|
||||||
|
render->show_cursor_ = true;
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ConnectionStatus::Closed: {
|
case ConnectionStatus::Closed: {
|
||||||
@@ -486,6 +493,14 @@ void Render::OnConnectionStatusCb(ConnectionStatus status, const char* user_id,
|
|||||||
|
|
||||||
render->connection_status_.erase(remote_id);
|
render->connection_status_.erase(remote_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (std::all_of(render->connection_status_.begin(),
|
||||||
|
render->connection_status_.end(), [](const auto& kv) {
|
||||||
|
return kv.first.find("web") == std::string::npos;
|
||||||
|
})) {
|
||||||
|
render->show_cursor_ = false;
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -36,9 +36,21 @@ int ScreenCapturerX11::Init(const int fps, cb_desktop_data cb) {
|
|||||||
XRRCrtcInfo* crtc_info =
|
XRRCrtcInfo* crtc_info =
|
||||||
XRRGetCrtcInfo(display_, screen_res_, output_info->crtc);
|
XRRGetCrtcInfo(display_, screen_res_, output_info->crtc);
|
||||||
|
|
||||||
display_info_list_.push_back(
|
std::string name(output_info->name);
|
||||||
DisplayInfo((void*)display_, output_info->name, true, crtc_info->x,
|
|
||||||
crtc_info->y, crtc_info->width, crtc_info->height));
|
if (name.empty()) {
|
||||||
|
name = "Display" + std::to_string(i + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// clean display name, remove non-alphanumeric characters
|
||||||
|
name.erase(
|
||||||
|
std::remove_if(name.begin(), name.end(),
|
||||||
|
[](unsigned char c) { return !std::isalnum(c); }),
|
||||||
|
name.end());
|
||||||
|
|
||||||
|
display_info_list_.push_back(DisplayInfo(
|
||||||
|
(void*)display_, name, true, crtc_info->x, crtc_info->y,
|
||||||
|
crtc_info->x + crtc_info->width, crtc_info->y + crtc_info->height));
|
||||||
|
|
||||||
XRRFreeCrtcInfo(crtc_info);
|
XRRFreeCrtcInfo(crtc_info);
|
||||||
}
|
}
|
||||||
@@ -86,7 +98,7 @@ int ScreenCapturerX11::Destroy() {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ScreenCapturerX11::Start() {
|
int ScreenCapturerX11::Start(bool show_cursor) {
|
||||||
if (running_) return 0;
|
if (running_) return 0;
|
||||||
running_ = true;
|
running_ = true;
|
||||||
paused_ = false;
|
paused_ = false;
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
#include <X11/Xutil.h>
|
#include <X11/Xutil.h>
|
||||||
#include <X11/extensions/Xrandr.h>
|
#include <X11/extensions/Xrandr.h>
|
||||||
|
#include <X11/extensions/Xfixes.h>
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
@@ -30,7 +31,7 @@ class ScreenCapturerX11 : public ScreenCapturer {
|
|||||||
public:
|
public:
|
||||||
int Init(const int fps, cb_desktop_data cb) override;
|
int Init(const int fps, cb_desktop_data cb) override;
|
||||||
int Destroy() override;
|
int Destroy() override;
|
||||||
int Start() override;
|
int Start(bool show_cursor) override;
|
||||||
int Stop() override;
|
int Stop() override;
|
||||||
|
|
||||||
int Pause(int monitor_index) override;
|
int Pause(int monitor_index) override;
|
||||||
@@ -54,6 +55,7 @@ class ScreenCapturerX11 : public ScreenCapturer {
|
|||||||
std::atomic<bool> running_{false};
|
std::atomic<bool> running_{false};
|
||||||
std::atomic<bool> paused_{false};
|
std::atomic<bool> paused_{false};
|
||||||
std::atomic<int> monitor_index_{0};
|
std::atomic<int> monitor_index_{0};
|
||||||
|
std::atomic<bool> show_cursor_{true};
|
||||||
int fps_ = 60;
|
int fps_ = 60;
|
||||||
cb_desktop_data callback_;
|
cb_desktop_data callback_;
|
||||||
std::vector<DisplayInfo> display_info_list_;
|
std::vector<DisplayInfo> display_info_list_;
|
||||||
@@ -61,6 +63,9 @@ class ScreenCapturerX11 : public ScreenCapturer {
|
|||||||
// 缓冲区
|
// 缓冲区
|
||||||
std::vector<uint8_t> y_plane_;
|
std::vector<uint8_t> y_plane_;
|
||||||
std::vector<uint8_t> uv_plane_;
|
std::vector<uint8_t> uv_plane_;
|
||||||
|
|
||||||
|
// 鼠标光标相关
|
||||||
|
void DrawCursor(XImage* image, int x, int y);
|
||||||
};
|
};
|
||||||
} // namespace crossdesk
|
} // namespace crossdesk
|
||||||
#endif
|
#endif
|
||||||
@@ -28,8 +28,8 @@ int ScreenCapturerSck::Destroy() {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ScreenCapturerSck::Start() {
|
int ScreenCapturerSck::Start(bool show_cursor) {
|
||||||
screen_capturer_sck_impl_->Start();
|
screen_capturer_sck_impl_->Start(show_cursor);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ class ScreenCapturerSck : public ScreenCapturer {
|
|||||||
public:
|
public:
|
||||||
int Init(const int fps, cb_desktop_data cb) override;
|
int Init(const int fps, cb_desktop_data cb) override;
|
||||||
int Destroy() override;
|
int Destroy() override;
|
||||||
int Start() override;
|
int Start(bool show_cursor) override;
|
||||||
int Stop() override;
|
int Stop() override;
|
||||||
|
|
||||||
int Pause(int monitor_index) override;
|
int Pause(int monitor_index) override;
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ class API_AVAILABLE(macos(14.0)) ScreenCapturerSckImpl : public ScreenCapturer {
|
|||||||
public:
|
public:
|
||||||
int Init(const int fps, cb_desktop_data cb) override;
|
int Init(const int fps, cb_desktop_data cb) override;
|
||||||
|
|
||||||
int Start() override;
|
int Start(bool show_cursor) override;
|
||||||
|
|
||||||
int SwitchTo(int monitor_index) override;
|
int SwitchTo(int monitor_index) override;
|
||||||
|
|
||||||
@@ -80,6 +80,7 @@ class API_AVAILABLE(macos(14.0)) ScreenCapturerSckImpl : public ScreenCapturer {
|
|||||||
int width_ = 0;
|
int width_ = 0;
|
||||||
int height_ = 0;
|
int height_ = 0;
|
||||||
int fps_ = 60;
|
int fps_ = 60;
|
||||||
|
bool show_cursor_ = false;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Called by SckHelper when shareable content is returned by ScreenCaptureKit. `content` will be
|
// Called by SckHelper when shareable content is returned by ScreenCaptureKit. `content` will be
|
||||||
@@ -225,13 +226,17 @@ int ScreenCapturerSckImpl::Init(const int fps, cb_desktop_data cb) {
|
|||||||
CGRect bounds = CGDisplayBounds(display_id);
|
CGRect bounds = CGDisplayBounds(display_id);
|
||||||
bool is_primary = CGDisplayIsMain(display_id);
|
bool is_primary = CGDisplayIsMain(display_id);
|
||||||
|
|
||||||
std::string name;
|
std::string name = GetDisplayName(display_id);
|
||||||
name = GetDisplayName(display_id);
|
|
||||||
|
|
||||||
if (name.empty()) {
|
if (name.empty()) {
|
||||||
name = "Display " + std::to_string(unnamed_count++);
|
name = "Display" + std::to_string(unnamed_count++);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// clean display name, remove non-alphanumeric characters
|
||||||
|
name.erase(
|
||||||
|
std::remove_if(name.begin(), name.end(), [](unsigned char c) { return !std::isalnum(c); }),
|
||||||
|
name.end());
|
||||||
|
|
||||||
DisplayInfo info((void *)(uintptr_t)display_id, name, is_primary,
|
DisplayInfo info((void *)(uintptr_t)display_id, name, is_primary,
|
||||||
static_cast<int>(bounds.origin.x), static_cast<int>(bounds.origin.y),
|
static_cast<int>(bounds.origin.x), static_cast<int>(bounds.origin.y),
|
||||||
static_cast<int>(bounds.origin.x + bounds.size.width),
|
static_cast<int>(bounds.origin.x + bounds.size.width),
|
||||||
@@ -246,7 +251,8 @@ int ScreenCapturerSckImpl::Init(const int fps, cb_desktop_data cb) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ScreenCapturerSckImpl::Start() {
|
int ScreenCapturerSckImpl::Start(bool show_cursor) {
|
||||||
|
show_cursor_ = show_cursor;
|
||||||
StartOrReconfigureCapturer();
|
StartOrReconfigureCapturer();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -328,7 +334,7 @@ void ScreenCapturerSckImpl::OnShareableContentCreated(SCShareableContent *conten
|
|||||||
excludingWindows:@[]];
|
excludingWindows:@[]];
|
||||||
SCStreamConfiguration *config = [[SCStreamConfiguration alloc] init];
|
SCStreamConfiguration *config = [[SCStreamConfiguration alloc] init];
|
||||||
config.pixelFormat = kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange;
|
config.pixelFormat = kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange;
|
||||||
config.showsCursor = false;
|
config.showsCursor = show_cursor_;
|
||||||
config.width = filter.contentRect.size.width * filter.pointPixelScale;
|
config.width = filter.contentRect.size.width * filter.pointPixelScale;
|
||||||
config.height = filter.contentRect.size.height * filter.pointPixelScale;
|
config.height = filter.contentRect.size.height * filter.pointPixelScale;
|
||||||
config.captureResolution = SCCaptureResolutionAutomatic;
|
config.captureResolution = SCCaptureResolutionAutomatic;
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ class ScreenCapturer {
|
|||||||
public:
|
public:
|
||||||
virtual int Init(const int fps, cb_desktop_data cb) = 0;
|
virtual int Init(const int fps, cb_desktop_data cb) = 0;
|
||||||
virtual int Destroy() = 0;
|
virtual int Destroy() = 0;
|
||||||
virtual int Start() = 0;
|
virtual int Start(bool show_cursor) = 0;
|
||||||
virtual int Stop() = 0;
|
virtual int Stop() = 0;
|
||||||
virtual int Pause(int monitor_index) = 0;
|
virtual int Pause(int monitor_index) = 0;
|
||||||
virtual int Resume(int monitor_index) = 0;
|
virtual int Resume(int monitor_index) = 0;
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ int ScreenCapturerWgc::Init(const int fps, cb_desktop_data cb) {
|
|||||||
|
|
||||||
int ScreenCapturerWgc::Destroy() { return 0; }
|
int ScreenCapturerWgc::Destroy() { return 0; }
|
||||||
|
|
||||||
int ScreenCapturerWgc::Start() {
|
int ScreenCapturerWgc::Start(bool show_cursor) {
|
||||||
if (running_ == true) {
|
if (running_ == true) {
|
||||||
LOG_ERROR("Screen capturer already running");
|
LOG_ERROR("Screen capturer already running");
|
||||||
return 0;
|
return 0;
|
||||||
@@ -172,7 +172,7 @@ int ScreenCapturerWgc::Start() {
|
|||||||
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();
|
sessions_[i].session_->Start(show_cursor);
|
||||||
|
|
||||||
if (i != 0) {
|
if (i != 0) {
|
||||||
sessions_[i].session_->Pause();
|
sessions_[i].session_->Pause();
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ class ScreenCapturerWgc : public ScreenCapturer,
|
|||||||
|
|
||||||
int Init(const int fps, cb_desktop_data cb) override;
|
int Init(const int fps, cb_desktop_data cb) override;
|
||||||
int Destroy() override;
|
int Destroy() override;
|
||||||
int Start() override;
|
int Start(bool show_cursor) override;
|
||||||
int Stop() override;
|
int Stop() override;
|
||||||
|
|
||||||
int Pause(int monitor_index) override;
|
int Pause(int monitor_index) override;
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ class WgcSession {
|
|||||||
|
|
||||||
virtual void RegisterObserver(wgc_session_observer* observer) = 0;
|
virtual void RegisterObserver(wgc_session_observer* observer) = 0;
|
||||||
|
|
||||||
virtual int Start() = 0;
|
virtual int Start(bool show_cursor) = 0;
|
||||||
virtual int Stop() = 0;
|
virtual int Stop() = 0;
|
||||||
|
|
||||||
virtual int Pause() = 0;
|
virtual int Pause() = 0;
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ void WgcSessionImpl::RegisterObserver(wgc_session_observer* observer) {
|
|||||||
observer_ = observer;
|
observer_ = observer;
|
||||||
}
|
}
|
||||||
|
|
||||||
int WgcSessionImpl::Start() {
|
int WgcSessionImpl::Start(bool show_cursor) {
|
||||||
std::lock_guard locker(lock_);
|
std::lock_guard locker(lock_);
|
||||||
|
|
||||||
if (is_running_) return 0;
|
if (is_running_) return 0;
|
||||||
@@ -91,7 +91,7 @@ int WgcSessionImpl::Start() {
|
|||||||
|
|
||||||
capture_session_.StartCapture();
|
capture_session_.StartCapture();
|
||||||
|
|
||||||
capture_session_.IsCursorCaptureEnabled(false);
|
capture_session_.IsCursorCaptureEnabled(show_cursor);
|
||||||
|
|
||||||
error = 0;
|
error = 0;
|
||||||
} catch (winrt::hresult_error) {
|
} catch (winrt::hresult_error) {
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ class WgcSessionImpl : public WgcSession {
|
|||||||
|
|
||||||
void RegisterObserver(wgc_session_observer* observer) override;
|
void RegisterObserver(wgc_session_observer* observer) override;
|
||||||
|
|
||||||
int Start() override;
|
int Start(bool show_cursor) override;
|
||||||
int Stop() override;
|
int Stop() override;
|
||||||
|
|
||||||
int Pause() override;
|
int Pause() override;
|
||||||
|
|||||||
Reference in New Issue
Block a user