From 7c8f8009c69c9e06003394ad26c3ec7b5295c36e Mon Sep 17 00:00:00 2001 From: Vladimir Sadovnikov Date: Fri, 2 Aug 2024 13:51:07 +0300 Subject: [PATCH] Updated size handling --- .../tk/widgets/containers/PopupWindow.h | 6 +- .../tk/widgets/containers/Window.h | 6 +- src/main/widgets/containers/PopupWindow.cpp | 6 +- src/main/widgets/containers/Window.cpp | 81 +++++++++++-------- 4 files changed, 56 insertions(+), 43 deletions(-) diff --git a/include/lsp-plug.in/tk/widgets/containers/PopupWindow.h b/include/lsp-plug.in/tk/widgets/containers/PopupWindow.h index 6ef69c25..328e367a 100644 --- a/include/lsp-plug.in/tk/widgets/containers/PopupWindow.h +++ b/include/lsp-plug.in/tk/widgets/containers/PopupWindow.h @@ -1,6 +1,6 @@ /* - * Copyright (C) 2023 Linux Studio Plugins Project - * (C) 2023 Vladimir Sadovnikov + * Copyright (C) 2024 Linux Studio Plugins Project + * (C) 2024 Vladimir Sadovnikov * * This file is part of lsp-tk-lib * Created on: 16 июн. 2020 г. @@ -61,7 +61,7 @@ namespace lsp protected: virtual void hide_widget() override; virtual void show_widget() override; - virtual status_t sync_size() override; + virtual status_t sync_size(bool force) override; virtual void size_request(ws::size_limit_t *r) override; virtual status_t post_init(); diff --git a/include/lsp-plug.in/tk/widgets/containers/Window.h b/include/lsp-plug.in/tk/widgets/containers/Window.h index 89d5def6..7cf62dd9 100644 --- a/include/lsp-plug.in/tk/widgets/containers/Window.h +++ b/include/lsp-plug.in/tk/widgets/containers/Window.h @@ -1,6 +1,6 @@ /* - * Copyright (C) 2023 Linux Studio Plugins Project - * (C) 2023 Vladimir Sadovnikov + * Copyright (C) 2024 Linux Studio Plugins Project + * (C) 2024 Vladimir Sadovnikov * * This file is part of lsp-tk-lib * Created on: 16 июн. 2017 г. @@ -110,7 +110,7 @@ namespace lsp status_t do_render(); void do_destroy(); - virtual status_t sync_size(); + virtual status_t sync_size(bool force); status_t update_pointer(); // Mouse operations diff --git a/src/main/widgets/containers/PopupWindow.cpp b/src/main/widgets/containers/PopupWindow.cpp index 577dd88e..915d633b 100644 --- a/src/main/widgets/containers/PopupWindow.cpp +++ b/src/main/widgets/containers/PopupWindow.cpp @@ -1,6 +1,6 @@ /* - * Copyright (C) 2023 Linux Studio Plugins Project - * (C) 2023 Vladimir Sadovnikov + * Copyright (C) 2024 Linux Studio Plugins Project + * (C) 2024 Vladimir Sadovnikov * * This file is part of lsp-tk-lib * Created on: 16 июн. 2020 г. @@ -123,7 +123,7 @@ namespace lsp return STATUS_OK; } - status_t PopupWindow::sync_size() + status_t PopupWindow::sync_size(bool force) { ws::size_limit_t sr; ws::rectangle_t xr; diff --git a/src/main/widgets/containers/Window.cpp b/src/main/widgets/containers/Window.cpp index 0084492a..ed390eb8 100644 --- a/src/main/widgets/containers/Window.cpp +++ b/src/main/widgets/containers/Window.cpp @@ -175,17 +175,23 @@ namespace lsp return init_internal(true); } - status_t Window::sync_size() + status_t Window::sync_size(bool force) { // Request size limits of the window ws::size_limit_t sr; - ws::rectangle_t r; + ws::rectangle_t r, wsr; get_padded_size_limits(&sr); float scaling = lsp_max(0.0f, sScaling.get()); size_t border = lsp_max(0, sBorderSize.get()) * scaling; - sPosition.get(&r); sWindowSize.compute(&r, scaling); + pWindow->get_geometry(&wsr); + sPosition.get(&r); + +// lsp_trace("Current window geometry: x=%d, y=%d, w=%d, h=%d", +// int(r.nLeft), int(r.nTop), int(r.nWidth), int(r.nHeight)); +// lsp_trace("Window subsystem geometry: x=%d, y=%d, w=%d, h=%d", +// int(wsr.nLeft), int(wsr.nTop), int(wsr.nWidth), int(wsr.nHeight)); // Set window's size constraints and update geometry if (sPolicy.get() == WP_GREEDY) @@ -216,8 +222,16 @@ namespace lsp xr.nHeight = lsp_max(0, sr.nMinHeight) + border*2; // Maximize the width - r.nWidth = lsp_max(xr.nWidth, r.nWidth); - r.nHeight = lsp_max(xr.nHeight, r.nHeight); + if (force) + { + r.nWidth = lsp_max(xr.nWidth, r.nWidth); + r.nHeight = lsp_max(xr.nHeight, r.nHeight); + } + else + { + r.nWidth = lsp_max(xr.nWidth, r.nWidth, wsr.nWidth); + r.nHeight = lsp_max(xr.nHeight, r.nHeight, wsr.nHeight); + } } // Window size should be at least 1x1 pixel @@ -226,7 +240,7 @@ namespace lsp // Check if we need to resize window // lsp_trace("size constraints: w={%d, %d}, h={%d, %d}", -// int(sr.nMinWidth), int(sr.nMinHeight), int(sr.nMaxWidth), int(sr.nMaxHeight) +// int(sr.nMinWidth), int(sr.nMinHeight), int(sr.nMaxWidth), int(sr.nMaxHeight) // ); pWindow->set_size_constraints(&sr); if ((sSize.nWidth != r.nWidth) || (sSize.nHeight != r.nHeight)) @@ -291,7 +305,7 @@ namespace lsp return STATUS_OK; if (resize_pending()) - sync_size(); + sync_size(false); if (!redraw_pending()) return STATUS_OK; @@ -545,8 +559,8 @@ namespace lsp //// int(l.nMinHeight), int(l.nMaxHeight) //// ); // } - query_resize(); + sync_size(true); } if (sLayout.is(prop)) { @@ -584,7 +598,7 @@ namespace lsp // Update window parameters if (pWindow != NULL) { - sync_size(); + sync_size(false); update_pointer(); } @@ -764,33 +778,30 @@ namespace lsp if (!bMapped) break; - if (!(nFlags & RESIZE_PENDING)) - { - lsp_trace("resize to: l=%d, t=%d, w=%d, h=%d", int(e->nLeft), int(e->nTop), int(e->nWidth), int(e->nHeight)); + lsp_trace("resize to: l=%d, t=%d, w=%d, h=%d", int(e->nLeft), int(e->nTop), int(e->nWidth), int(e->nHeight)); - // Update the position of the window - if ((sSize.nLeft != e->nLeft) || (sSize.nTop != e->nTop)) - sPosition.commit_value(e->nLeft, e->nTop); + // Update the position of the window + if ((sSize.nLeft != e->nLeft) || (sSize.nTop != e->nTop)) + sPosition.commit_value(e->nLeft, e->nTop); - // Update size of the window - if ((sSize.nWidth != e->nWidth) || (sSize.nHeight != e->nHeight)) - { - // Realize the widget only if size has changed - sWindowSize.commit_value(e->nWidth, e->nHeight, sScaling.get()); - - ws::rectangle_t r = { - e->nLeft, - e->nTop, - e->nWidth, - e->nHeight - }; - realize_widget(&r); - } - else - { - sSize.nLeft = e->nLeft; - sSize.nTop = e->nTop; - } + // Update size of the window + if ((sSize.nWidth != e->nWidth) || (sSize.nHeight != e->nHeight)) + { + // Realize the widget only if size has changed + sWindowSize.commit_value(e->nWidth, e->nHeight, sScaling.get()); + + ws::rectangle_t r = { + e->nLeft, + e->nTop, + e->nWidth, + e->nHeight + }; + realize_widget(&r); + } + else + { + sSize.nLeft = e->nLeft; + sSize.nTop = e->nTop; } break; @@ -1002,6 +1013,7 @@ namespace lsp { sPosition.set(size->nLeft, size->nTop); sWindowSize.set(size->nWidth, size->nHeight, sScaling.get()); + sync_size(true); return STATUS_OK; } @@ -1009,6 +1021,7 @@ namespace lsp status_t Window::resize_window(ssize_t width, ssize_t height) { sWindowSize.set(width, height, sScaling.get()); + sync_size(true); return STATUS_OK; }