From 3685acc549607aac1f264827695afccf852a3861 Mon Sep 17 00:00:00 2001 From: dijunkun Date: Thu, 25 Jul 2024 10:10:37 +0800 Subject: [PATCH] [feat] set window resizable only in streaming state --- src/single_window/render.cpp | 30 +++++++++++++++--------------- src/single_window/render.h | 3 +++ 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/single_window/render.cpp b/src/single_window/render.cpp index ff7c9c9..3c7ac39 100644 --- a/src/single_window/render.cpp +++ b/src/single_window/render.cpp @@ -218,11 +218,10 @@ int Render::Run() { #endif // Create main window with SDL_Renderer graphics context - SDL_WindowFlags window_flags = - (SDL_WindowFlags)(SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_RESIZABLE); - main_window_ = SDL_CreateWindow("Remote Desk", SDL_WINDOWPOS_UNDEFINED, - SDL_WINDOWPOS_UNDEFINED, main_window_width_, - main_window_height_, window_flags); + SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_ALLOW_HIGHDPI); + main_window_ = SDL_CreateWindow( + "Remote Desk", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, + main_window_width_default_, main_window_height_default_, window_flags); main_renderer_ = SDL_CreateRenderer( main_window_, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED); @@ -408,8 +407,17 @@ int Render::Run() { ImGui::PopStyleVar(); ImGui::PopStyleColor(); if (streaming_ && is_client_mode_) { + if (!resizable_) { + resizable_ = !resizable_; + SDL_SetWindowResizable(main_window_, SDL_TRUE); + } + ControlWindow(); } else { + if (resizable_) { + resizable_ = !resizable_; + SDL_SetWindowResizable(main_window_, SDL_FALSE); + } MainWindow(); } @@ -428,10 +436,8 @@ int Render::Run() { connection_established_ = false; received_frame_ = false; is_client_mode_ = false; - SDL_SetWindowSize(main_window_, main_window_width_last_, - main_window_height_last_); - SDL_SetWindowPosition(main_window_, SDL_WINDOWPOS_CENTERED, - SDL_WINDOWPOS_CENTERED); + SDL_SetWindowSize(main_window_, main_window_width_default_, + main_window_height_default_); continue; } else { LOG_INFO("Quit program"); @@ -440,11 +446,6 @@ int Render::Run() { } else if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) { SDL_GetWindowSize(main_window_, &main_window_width_, &main_window_height_); - if (!streaming_) { - main_window_width_last_ = main_window_width_; - main_window_height_last_ = main_window_height_; - } - if (main_window_width_ * 9 < main_window_height_ * 16) { stream_render_rect_.x = 0; stream_render_rect_.y = @@ -463,7 +464,6 @@ int Render::Run() { stream_render_rect_.w = main_window_width_; stream_render_rect_.h = main_window_height_; } - } else if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE) { if (connection_established_) { diff --git a/src/single_window/render.h b/src/single_window/render.h index f2c3f7a..6a53da2 100644 --- a/src/single_window/render.h +++ b/src/single_window/render.h @@ -122,6 +122,8 @@ class Render { private: int screen_width_ = 1280; int screen_height_ = 720; + int main_window_width_default_ = 960; + int main_window_height_default_ = 540; int main_window_width_ = 960; int main_window_height_ = 540; int main_window_width_last_ = 960; @@ -160,6 +162,7 @@ class Render { SDL_Rect stream_render_rect_; uint32_t stream_pixformat_ = 0; + bool resizable_ = false; bool inited_ = false; bool exit_ = false; bool exit_video_window_ = false;