mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-26 20:25:34 +08:00
Use sub windows to render main window
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
#include "main_window.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
@@ -9,17 +7,18 @@
|
||||
#include "localization.h"
|
||||
#include "log.h"
|
||||
#include "platform.h"
|
||||
#include "render.h"
|
||||
#include "screen_capturer_factory.h"
|
||||
|
||||
// Refresh Event
|
||||
#define REFRESH_EVENT (SDL_USEREVENT + 1)
|
||||
#define NV12_BUFFER_SIZE 1280 * 720 * 3 / 2
|
||||
|
||||
MainWindow::MainWindow() {}
|
||||
Render::Render() {}
|
||||
|
||||
MainWindow::~MainWindow() {}
|
||||
Render::~Render() {}
|
||||
|
||||
int MainWindow::SaveSettingsIntoCacheFile() {
|
||||
int Render::SaveSettingsIntoCacheFile() {
|
||||
cd_cache_file_ = fopen("cache.cd", "w+");
|
||||
if (!cd_cache_file_) {
|
||||
return -1;
|
||||
@@ -41,7 +40,7 @@ int MainWindow::SaveSettingsIntoCacheFile() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int MainWindow::LoadSettingsIntoCacheFile() {
|
||||
int Render::LoadSettingsIntoCacheFile() {
|
||||
cd_cache_file_ = fopen("cache.cd", "r+");
|
||||
if (!cd_cache_file_) {
|
||||
return -1;
|
||||
@@ -59,7 +58,7 @@ int MainWindow::LoadSettingsIntoCacheFile() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int MainWindow::StartScreenCapture() {
|
||||
int Render::StartScreenCapture() {
|
||||
screen_capturer_ = (ScreenCapturer *)screen_capturer_factory_->Create();
|
||||
ScreenCapturer::RECORD_DESKTOP_RECT rect;
|
||||
rect.left = 0;
|
||||
@@ -93,7 +92,7 @@ int MainWindow::StartScreenCapture() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int MainWindow::StopScreenCapture() {
|
||||
int Render::StopScreenCapture() {
|
||||
if (screen_capturer_) {
|
||||
LOG_INFO("Destroy screen capturer")
|
||||
screen_capturer_->Destroy();
|
||||
@@ -104,7 +103,7 @@ int MainWindow::StopScreenCapture() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int MainWindow::StartMouseControl() {
|
||||
int Render::StartMouseControl() {
|
||||
device_controller_factory_ = new DeviceControllerFactory();
|
||||
mouse_controller_ = (MouseController *)device_controller_factory_->Create(
|
||||
DeviceControllerFactory::Device::Mouse);
|
||||
@@ -119,7 +118,7 @@ int MainWindow::StartMouseControl() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int MainWindow::StopMouseControl() {
|
||||
int Render::StopMouseControl() {
|
||||
if (mouse_controller_) {
|
||||
mouse_controller_->Destroy();
|
||||
delete mouse_controller_;
|
||||
@@ -128,7 +127,7 @@ int MainWindow::StopMouseControl() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int MainWindow::CreateConnectionPeer() {
|
||||
int Render::CreateConnectionPeer() {
|
||||
mac_addr_str_ = GetMac();
|
||||
|
||||
params_.use_cfg_file = false;
|
||||
@@ -165,7 +164,7 @@ int MainWindow::CreateConnectionPeer() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int MainWindow::Run() {
|
||||
int Render::Run() {
|
||||
LoadSettingsIntoCacheFile();
|
||||
|
||||
localization_language_ = (ConfigCenter::LANGUAGE)language_button_value_;
|
||||
@@ -21,10 +21,10 @@
|
||||
#include "imgui_impl_sdlrenderer2.h"
|
||||
#include "screen_capturer_factory.h"
|
||||
|
||||
class MainWindow {
|
||||
class Render {
|
||||
public:
|
||||
MainWindow();
|
||||
~MainWindow();
|
||||
Render();
|
||||
~Render();
|
||||
|
||||
public:
|
||||
int Run();
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "device_controller.h"
|
||||
#include "localization.h"
|
||||
#include "main_window.h"
|
||||
#include "render.h"
|
||||
|
||||
// Refresh Event
|
||||
#define REFRESH_EVENT (SDL_USEREVENT + 1)
|
||||
@@ -11,7 +11,7 @@
|
||||
#define MOUSE_CONTROL 1
|
||||
#endif
|
||||
|
||||
int MainWindow::ProcessMouseKeyEven(SDL_Event &ev) {
|
||||
int Render::ProcessMouseKeyEven(SDL_Event &ev) {
|
||||
if (!control_mouse_) {
|
||||
return 0;
|
||||
}
|
||||
@@ -77,7 +77,7 @@ int MainWindow::ProcessMouseKeyEven(SDL_Event &ev) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MainWindow::SdlCaptureAudioIn(void *userdata, Uint8 *stream, int len) {
|
||||
void Render::SdlCaptureAudioIn(void *userdata, Uint8 *stream, int len) {
|
||||
if (1) {
|
||||
if ("Connected" == connection_status_str_) {
|
||||
SendData(peer_, DATA_TYPE::AUDIO, (const char *)stream, len);
|
||||
@@ -90,7 +90,7 @@ void MainWindow::SdlCaptureAudioIn(void *userdata, Uint8 *stream, int len) {
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::SdlCaptureAudioOut(void *userdata, Uint8 *stream, int len) {
|
||||
void Render::SdlCaptureAudioOut(void *userdata, Uint8 *stream, int len) {
|
||||
if (!audio_buffer_fresh_) {
|
||||
return;
|
||||
}
|
||||
@@ -108,10 +108,10 @@ void MainWindow::SdlCaptureAudioOut(void *userdata, Uint8 *stream, int len) {
|
||||
audio_buffer_fresh_ = false;
|
||||
}
|
||||
|
||||
void MainWindow::OnReceiveVideoBufferCb(const char *data, size_t size,
|
||||
const char *user_id,
|
||||
size_t user_id_size, void *user_data) {
|
||||
MainWindow *main_window = (MainWindow *)user_data;
|
||||
void Render::OnReceiveVideoBufferCb(const char *data, size_t size,
|
||||
const char *user_id, size_t user_id_size,
|
||||
void *user_data) {
|
||||
Render *main_window = (Render *)user_data;
|
||||
if (main_window->connection_established_) {
|
||||
memcpy(main_window->dst_buffer_, data, size);
|
||||
SDL_Event event;
|
||||
@@ -121,18 +121,18 @@ void MainWindow::OnReceiveVideoBufferCb(const char *data, size_t size,
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::OnReceiveAudioBufferCb(const char *data, size_t size,
|
||||
const char *user_id,
|
||||
size_t user_id_size, void *user_data) {
|
||||
MainWindow *main_window = (MainWindow *)user_data;
|
||||
void Render::OnReceiveAudioBufferCb(const char *data, size_t size,
|
||||
const char *user_id, size_t user_id_size,
|
||||
void *user_data) {
|
||||
Render *main_window = (Render *)user_data;
|
||||
main_window->audio_buffer_fresh_ = true;
|
||||
SDL_QueueAudio(main_window->output_dev_, data, (uint32_t)size);
|
||||
}
|
||||
|
||||
void MainWindow::OnReceiveDataBufferCb(const char *data, size_t size,
|
||||
const char *user_id, size_t user_id_size,
|
||||
void *user_data) {
|
||||
MainWindow *main_window = (MainWindow *)user_data;
|
||||
void Render::OnReceiveDataBufferCb(const char *data, size_t size,
|
||||
const char *user_id, size_t user_id_size,
|
||||
void *user_data) {
|
||||
Render *main_window = (Render *)user_data;
|
||||
std::string user(user_id, user_id_size);
|
||||
RemoteAction remote_action;
|
||||
memcpy(&remote_action, data, sizeof(remote_action));
|
||||
@@ -144,8 +144,8 @@ void MainWindow::OnReceiveDataBufferCb(const char *data, size_t size,
|
||||
#endif
|
||||
}
|
||||
|
||||
void MainWindow::OnSignalStatusCb(SignalStatus status, void *user_data) {
|
||||
MainWindow *main_window = (MainWindow *)user_data;
|
||||
void Render::OnSignalStatusCb(SignalStatus status, void *user_data) {
|
||||
Render *main_window = (Render *)user_data;
|
||||
main_window->signal_status_ = status;
|
||||
if (SignalStatus::SignalConnecting == status) {
|
||||
main_window->signal_status_str_ = "SignalConnecting";
|
||||
@@ -160,9 +160,8 @@ void MainWindow::OnSignalStatusCb(SignalStatus status, void *user_data) {
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::OnConnectionStatusCb(ConnectionStatus status,
|
||||
void *user_data) {
|
||||
MainWindow *main_window = (MainWindow *)user_data;
|
||||
void Render::OnConnectionStatusCb(ConnectionStatus status, void *user_data) {
|
||||
Render *main_window = (Render *)user_data;
|
||||
main_window->connection_status_ = status;
|
||||
if (ConnectionStatus::Connecting == status) {
|
||||
main_window->connection_status_str_ = "Connecting";
|
||||
Reference in New Issue
Block a user