[fix] resolve tab bar dragging issue

This commit is contained in:
dijunkun
2025-12-06 18:46:04 +08:00
parent 1a883f0d6c
commit 1f6a2182be

View File

@@ -21,8 +21,6 @@
#define NV12_BUFFER_SIZE 1280 * 720 * 3 / 2 #define NV12_BUFFER_SIZE 1280 * 720 * 3 / 2
#define MOUSE_GRAB_PADDING 5
namespace crossdesk { namespace crossdesk {
std::vector<char> Render::SerializeRemoteAction(const RemoteAction& action) { std::vector<char> Render::SerializeRemoteAction(const RemoteAction& action) {
@@ -134,9 +132,39 @@ SDL_HitTestResult Render::HitTestCallback(SDL_Window* window,
int window_width, window_height; int window_width, window_height;
SDL_GetWindowSize(window, &window_width, &window_height); SDL_GetWindowSize(window, &window_width, &window_height);
if (area->y < 30 * render->dpi_scale_ && area->y > MOUSE_GRAB_PADDING && // check if curosor is in tab bar
area->x < window_width - 120 * render->dpi_scale_ && if (render->stream_window_inited_ && render->stream_window_created_ &&
area->x > MOUSE_GRAB_PADDING && !render->is_tab_bar_hovered_) { !render->fullscreen_button_pressed_ && render->stream_ctx_) {
ImGuiContext* prev_ctx = ImGui::GetCurrentContext();
ImGui::SetCurrentContext(render->stream_ctx_);
ImGuiWindow* tab_bar_window = ImGui::FindWindowByName("TabBar");
if (tab_bar_window && tab_bar_window->Active) {
ImGuiIO& io = ImGui::GetIO();
float scale_x = io.DisplayFramebufferScale.x;
float scale_y = io.DisplayFramebufferScale.y;
float tab_bar_x = tab_bar_window->Pos.x * scale_x;
float tab_bar_y = tab_bar_window->Pos.y * scale_y;
float tab_bar_width = tab_bar_window->Size.x * scale_x;
float tab_bar_height = tab_bar_window->Size.y * scale_y;
ImGui::SetCurrentContext(prev_ctx);
if (area->x >= tab_bar_x && area->x <= tab_bar_x + tab_bar_width &&
area->y >= tab_bar_y && area->y <= tab_bar_y + tab_bar_height) {
return SDL_HITTEST_NORMAL;
}
} else {
ImGui::SetCurrentContext(prev_ctx);
}
}
float mouse_grab_padding = render->title_bar_button_width_ * 0.16f;
if (area->y < render->title_bar_button_width_ &&
area->y > mouse_grab_padding &&
area->x < window_width - render->title_bar_button_width_ * 4.0f &&
area->x > mouse_grab_padding) {
return SDL_HITTEST_DRAGGABLE; return SDL_HITTEST_DRAGGABLE;
} }
@@ -144,25 +172,25 @@ SDL_HitTestResult Render::HitTestCallback(SDL_Window* window,
// return SDL_HITTEST_NORMAL; // return SDL_HITTEST_NORMAL;
// } // }
if (area->y < MOUSE_GRAB_PADDING) { if (area->y < mouse_grab_padding) {
if (area->x < MOUSE_GRAB_PADDING) { if (area->x < mouse_grab_padding) {
return SDL_HITTEST_RESIZE_TOPLEFT; return SDL_HITTEST_RESIZE_TOPLEFT;
} else if (area->x > window_width - MOUSE_GRAB_PADDING) { } else if (area->x > window_width - mouse_grab_padding) {
return SDL_HITTEST_RESIZE_TOPRIGHT; return SDL_HITTEST_RESIZE_TOPRIGHT;
} else { } else {
return SDL_HITTEST_RESIZE_TOP; return SDL_HITTEST_RESIZE_TOP;
} }
} else if (area->y > window_height - MOUSE_GRAB_PADDING) { } else if (area->y > window_height - mouse_grab_padding) {
if (area->x < MOUSE_GRAB_PADDING) { if (area->x < mouse_grab_padding) {
return SDL_HITTEST_RESIZE_BOTTOMLEFT; return SDL_HITTEST_RESIZE_BOTTOMLEFT;
} else if (area->x > window_width - MOUSE_GRAB_PADDING) { } else if (area->x > window_width - mouse_grab_padding) {
return SDL_HITTEST_RESIZE_BOTTOMRIGHT; return SDL_HITTEST_RESIZE_BOTTOMRIGHT;
} else { } else {
return SDL_HITTEST_RESIZE_BOTTOM; return SDL_HITTEST_RESIZE_BOTTOM;
} }
} else if (area->x < MOUSE_GRAB_PADDING) { } else if (area->x < mouse_grab_padding) {
return SDL_HITTEST_RESIZE_LEFT; return SDL_HITTEST_RESIZE_LEFT;
} else if (area->x > window_width - MOUSE_GRAB_PADDING) { } else if (area->x > window_width - mouse_grab_padding) {
return SDL_HITTEST_RESIZE_RIGHT; return SDL_HITTEST_RESIZE_RIGHT;
} }