From 7bbd10a50c20fb03fbbb1ec61eff5b4d9d155665 Mon Sep 17 00:00:00 2001 From: dijunkun Date: Thu, 22 Jan 2026 17:56:00 +0800 Subject: [PATCH] [fix] fix rendering issues in stream and server windows when the main window is minimized --- src/gui/render.cpp | 13 +----------- src/gui/render.h | 3 +++ src/gui/toolbars/title_bar.cpp | 35 ++++++++++++++++++++++++------- src/gui/windows/server_window.cpp | 6 +++--- 4 files changed, 34 insertions(+), 23 deletions(-) diff --git a/src/gui/render.cpp b/src/gui/render.cpp index e65f751..9a9a477 100644 --- a/src/gui/render.cpp +++ b/src/gui/render.cpp @@ -1103,29 +1103,18 @@ int Render::CreateServerWindow() { } #if _WIN32 - // Hide server window from the taskbar by making it an owned tool window. + // Hide server window from the taskbar by making it a tool window. { SDL_PropertiesID server_props = SDL_GetWindowProperties(server_window_); HWND server_hwnd = (HWND)SDL_GetPointerProperty( server_props, SDL_PROP_WINDOW_WIN32_HWND_POINTER, NULL); - HWND owner_hwnd = nullptr; - if (main_window_) { - SDL_PropertiesID main_props = SDL_GetWindowProperties(main_window_); - owner_hwnd = (HWND)SDL_GetPointerProperty( - main_props, SDL_PROP_WINDOW_WIN32_HWND_POINTER, NULL); - } - if (server_hwnd) { LONG_PTR ex_style = GetWindowLongPtr(server_hwnd, GWL_EXSTYLE); ex_style |= WS_EX_TOOLWINDOW; ex_style &= ~WS_EX_APPWINDOW; SetWindowLongPtr(server_hwnd, GWL_EXSTYLE, ex_style); - if (owner_hwnd) { - SetWindowLongPtr(server_hwnd, GWLP_HWNDPARENT, (LONG_PTR)owner_hwnd); - } - // Keep the server window above normal windows. SetWindowPos(server_hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED | SWP_NOACTIVATE); diff --git a/src/gui/render.h b/src/gui/render.h index abf8ad9..e3652d2 100644 --- a/src/gui/render.h +++ b/src/gui/render.h @@ -420,6 +420,9 @@ class Render { bool keyboard_capturer_is_started_ = false; bool foucs_on_main_window_ = false; bool foucs_on_stream_window_ = false; + bool main_window_minimized_ = false; + uint32_t last_main_minimize_request_tick_ = 0; + uint32_t last_stream_minimize_request_tick_ = 0; bool audio_capture_ = false; int main_window_width_real_ = 720; int main_window_height_real_ = 540; diff --git a/src/gui/toolbars/title_bar.cpp b/src/gui/toolbars/title_bar.cpp index d5fdbfe..a4ed464 100644 --- a/src/gui/toolbars/title_bar.cpp +++ b/src/gui/toolbars/title_bar.cpp @@ -15,14 +15,28 @@ int Render::TitleBar(bool main_window) { float title_bar_button_width = title_bar_button_width_; float title_bar_button_height = title_bar_button_height_; if (main_window) { - title_bar_width = io.DisplaySize.x; - title_bar_height = io.DisplaySize.y * TITLE_BAR_HEIGHT; - title_bar_height_padding = io.DisplaySize.y * (TITLE_BAR_HEIGHT + 0.01f); - title_bar_button_width = io.DisplaySize.x * TITLE_BAR_BUTTON_WIDTH; - title_bar_button_height = io.DisplaySize.y * TITLE_BAR_BUTTON_HEIGHT; - title_bar_height_ = title_bar_height; - title_bar_button_width_ = title_bar_button_width; - title_bar_button_height_ = title_bar_button_height; + // When the main window is minimized, Dear ImGui may report DisplaySize as + // (0, 0). Do not overwrite shared title-bar metrics with zeros, otherwise + // stream/server windows (which reuse these metrics) will lose their title + // bars and appear collapsed. + if (io.DisplaySize.x > 0.0f && io.DisplaySize.y > 0.0f) { + title_bar_width = io.DisplaySize.x; + title_bar_height = io.DisplaySize.y * TITLE_BAR_HEIGHT; + title_bar_height_padding = io.DisplaySize.y * (TITLE_BAR_HEIGHT + 0.01f); + title_bar_button_width = io.DisplaySize.x * TITLE_BAR_BUTTON_WIDTH; + title_bar_button_height = io.DisplaySize.y * TITLE_BAR_BUTTON_HEIGHT; + + title_bar_height_ = title_bar_height; + title_bar_button_width_ = title_bar_button_width; + title_bar_button_height_ = title_bar_button_height; + } else { + // Keep using last known good values. + title_bar_width = title_bar_width_; + title_bar_height = title_bar_height_; + title_bar_height_padding = title_bar_height_; + title_bar_button_width = title_bar_button_width_; + title_bar_button_height = title_bar_button_height_; + } } else { title_bar_width = io.DisplaySize.x; title_bar_height = title_bar_button_height_; @@ -187,6 +201,11 @@ int Render::TitleBar(bool main_window) { std::string window_minimize_button = "##minimize"; // ICON_FA_MINUS; if (ImGui::Button(window_minimize_button.c_str(), ImVec2(title_bar_button_width, title_bar_button_height))) { + if (main_window) { + last_main_minimize_request_tick_ = SDL_GetTicks(); + } else { + last_stream_minimize_request_tick_ = SDL_GetTicks(); + } SDL_MinimizeWindow(main_window ? main_window_ : stream_window_); } draw_list->AddLine( diff --git a/src/gui/windows/server_window.cpp b/src/gui/windows/server_window.cpp index 2763f4f..c9bdd0c 100644 --- a/src/gui/windows/server_window.cpp +++ b/src/gui/windows/server_window.cpp @@ -102,7 +102,7 @@ int Render::RemoteClientInfoWindow() { ImGui::PopStyleVar(); ImGui::PopStyleColor(); - ImGui::SetWindowFontScale(0.7f); + ImGui::SetWindowFontScale(0.6f); ImGui::Text("%s", localization::controller[localization_language_index_].c_str()); ImGui::SameLine(); @@ -121,7 +121,7 @@ int Render::RemoteClientInfoWindow() { ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(1.0f, 0.3f, 0.3f, 1.0f)); ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(1.0f, 0.5f, 0.5f, 1.0f)); ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 5.0f); - ImGui::SetWindowFontScale(0.7f); + ImGui::SetWindowFontScale(0.6f); if (ImGui::Button(ICON_FA_XMARK, ImVec2(close_connection_button_width, close_connection_button_height))) { LeaveConnection(peer_, self_hosted_id_); @@ -139,7 +139,7 @@ int Render::RemoteClientInfoWindow() { ImGuiWindowFlags_NoBringToFrontOnFocus); ImGui::PopStyleColor(); - ImGui::SetWindowFontScale(0.7f); + ImGui::SetWindowFontScale(0.6f); ImGui::AlignTextToFramePadding(); ImGui::Text( "%s", localization::file_transfer[localization_language_index_].c_str());