From 855b15025c25eecfe007b6cd67efb41ec9231540 Mon Sep 17 00:00:00 2001 From: dijunkun Date: Tue, 14 Apr 2026 14:25:16 +0800 Subject: [PATCH] [fix] fix file transfer window interactions issue --- src/gui/render.h | 1 + src/gui/render_callback.cpp | 18 +++++-- src/gui/windows/control_window.cpp | 1 - src/gui/windows/file_transfer_window.cpp | 69 +++++++++++++----------- 4 files changed, 52 insertions(+), 37 deletions(-) diff --git a/src/gui/render.h b/src/gui/render.h index fee335bb..a5acb084 100644 --- a/src/gui/render.h +++ b/src/gui/render.h @@ -54,6 +54,7 @@ class Render { std::chrono::steady_clock::time_point file_send_last_update_time_; uint64_t file_send_last_bytes_ = 0; bool file_transfer_window_visible_ = false; + bool file_transfer_window_hovered_ = false; std::atomic current_file_id_{0}; struct QueuedFile { diff --git a/src/gui/render_callback.cpp b/src/gui/render_callback.cpp index 9e1364ab..dcbcc334 100644 --- a/src/gui/render_callback.cpp +++ b/src/gui/render_callback.cpp @@ -234,13 +234,20 @@ int Render::ProcessMouseEvent(const SDL_Event& event) { continue; } + const bool file_transfer_window_hovered = + props->file_transfer_.file_transfer_window_hovered_; + const bool overlay_hovered = props->control_bar_hovered_ || + props->display_selectable_hovered_ || + file_transfer_window_hovered; + const SDL_FRect render_rect = props->stream_render_rect_f_; if (render_rect.w <= 1.0f || render_rect.h <= 1.0f) { continue; } if (is_pointer_position_event && cursor_x >= render_rect.x && - cursor_x <= render_rect.x + render_rect.w && cursor_y >= render_rect.y && + cursor_x <= render_rect.x + render_rect.w && + cursor_y >= render_rect.y && cursor_y <= render_rect.y + render_rect.h) { controlled_remote_id_ = it.first; last_mouse_event.motion.x = cursor_x; @@ -276,7 +283,7 @@ int Render::ProcessMouseEvent(const SDL_Event& event) { remote_action.m.flag = MouseFlag::move; } - if (props->control_bar_hovered_ || props->display_selectable_hovered_) { + if (overlay_hovered) { break; } if (props->peer_) { @@ -322,7 +329,7 @@ int Render::ProcessMouseEvent(const SDL_Event& event) { remote_action.m.x = std::clamp(remote_action.m.x, 0.0f, 1.0f); remote_action.m.y = std::clamp(remote_action.m.y, 0.0f, 1.0f); - if (props->control_bar_hovered_) { + if (overlay_hovered) { continue; } if (props->peer_) { @@ -1028,8 +1035,9 @@ void Render::OnConnectionStatusCb(ConnectionStatus status, const char* user_id, // Keep Wayland capture session warm to avoid black screen on // subsequent reconnects. render->start_screen_capturer_ = true; - LOG_INFO("Keeping Wayland screen capturer running after " - "disconnect to preserve reconnect stability"); + LOG_INFO( + "Keeping Wayland screen capturer running after " + "disconnect to preserve reconnect stability"); } else { render->start_screen_capturer_ = false; } diff --git a/src/gui/windows/control_window.cpp b/src/gui/windows/control_window.cpp index 0183e38b..bd55e4a7 100644 --- a/src/gui/windows/control_window.cpp +++ b/src/gui/windows/control_window.cpp @@ -257,4 +257,3 @@ int Render::ControlWindow(std::shared_ptr& props) { return 0; } } // namespace crossdesk - diff --git a/src/gui/windows/file_transfer_window.cpp b/src/gui/windows/file_transfer_window.cpp index a9a33791..7872b37a 100644 --- a/src/gui/windows/file_transfer_window.cpp +++ b/src/gui/windows/file_transfer_window.cpp @@ -31,6 +31,7 @@ int BitrateDisplay(int bitrate) { int Render::FileTransferWindow( std::shared_ptr& props) { FileTransferState* state = props ? &props->file_transfer_ : &file_transfer_; + state->file_transfer_window_hovered_ = false; // Only show window if there are files in transfer list or currently // transferring @@ -72,8 +73,6 @@ int Render::FileTransferWindow( return 0; } - ImGuiIO& io = ImGui::GetIO(); - // Position window at bottom-left of stream window // Adjust window size based on number of files float file_transfer_window_width = main_window_width_ * 0.6f; @@ -82,15 +81,25 @@ int Render::FileTransferWindow( float pos_x = file_transfer_window_width * 0.05f; float pos_y = stream_window_height_ - file_transfer_window_height - file_transfer_window_width * 0.05; - float same_line_width = file_transfer_window_width * 0.1f; + + const ImVec2 mouse_pos = ImGui::GetMousePos(); + const bool mouse_in_window_rect = + mouse_pos.x >= pos_x && + mouse_pos.x <= pos_x + file_transfer_window_width && + mouse_pos.y >= pos_y && + mouse_pos.y <= pos_y + file_transfer_window_height; ImGui::SetNextWindowPos(ImVec2(pos_x, pos_y), ImGuiCond_Always); ImGui::SetNextWindowSize( ImVec2(file_transfer_window_width, file_transfer_window_height), ImGuiCond_Always); + if (mouse_in_window_rect) { + ImGui::SetNextWindowFocus(); + } // Set Chinese font for proper display - if (stream_windows_system_chinese_font_) { + const bool has_chinese_font = stream_windows_system_chinese_font_ != nullptr; + if (has_chinese_font) { ImGui::PushFont(stream_windows_system_chinese_font_); } @@ -103,24 +112,27 @@ int Render::FileTransferWindow( ImGui::SetWindowFontScale(0.5f); bool window_opened = true; - if (ImGui::Begin( - localization::file_transfer_progress[localization_language_index_] - .c_str(), - &window_opened, - ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | - ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings | - ImGuiWindowFlags_NoScrollbar)) { + const bool show_contents = ImGui::Begin( + localization::file_transfer_progress[localization_language_index_] + .c_str(), + &window_opened, + ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | + ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings | + ImGuiWindowFlags_NoScrollbar); + ImGui::PopStyleColor(4); + ImGui::PopStyleVar(2); + + state->file_transfer_window_hovered_ = + mouse_in_window_rect || + ImGui::IsWindowHovered(ImGuiHoveredFlags_RootAndChildWindows); + + if (!window_opened) { + state->file_transfer_window_visible_ = false; + } + + if (show_contents && window_opened) { ImGui::SetWindowFontScale(1.0f); ImGui::SetWindowFontScale(0.5f); - ImGui::PopStyleColor(4); - ImGui::PopStyleVar(2); - - // Close button handling - if (!window_opened) { - state->file_transfer_window_visible_ = false; - ImGui::End(); - return 0; - } // Display file list if (file_list.empty()) { @@ -225,21 +237,16 @@ int Render::FileTransferWindow( } ImGui::SetWindowFontScale(1.0f); ImGui::SetWindowFontScale(0.5f); - ImGui::End(); - ImGui::SetWindowFontScale(1.0f); - - // Pop Chinese font if it was pushed - if (stream_windows_system_chinese_font_) { - ImGui::PopFont(); - } - } else { - ImGui::PopStyleColor(4); - ImGui::PopStyleVar(2); } + + ImGui::End(); ImGui::SetWindowFontScale(1.0f); + if (has_chinese_font) { + ImGui::PopFont(); + } + return 0; } } // namespace crossdesk -