Skip to content

Commit

Permalink
Updated size handling
Browse files Browse the repository at this point in the history
  • Loading branch information
sadko4u committed Aug 2, 2024
1 parent d4d68d7 commit 7c8f800
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 43 deletions.
6 changes: 3 additions & 3 deletions include/lsp-plug.in/tk/widgets/containers/PopupWindow.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2023 Linux Studio Plugins Project <https://lsp-plug.in/>
* (C) 2023 Vladimir Sadovnikov <[email protected]>
* Copyright (C) 2024 Linux Studio Plugins Project <https://lsp-plug.in/>
* (C) 2024 Vladimir Sadovnikov <[email protected]>
*
* This file is part of lsp-tk-lib
* Created on: 16 июн. 2020 г.
Expand Down Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions include/lsp-plug.in/tk/widgets/containers/Window.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2023 Linux Studio Plugins Project <https://lsp-plug.in/>
* (C) 2023 Vladimir Sadovnikov <[email protected]>
* Copyright (C) 2024 Linux Studio Plugins Project <https://lsp-plug.in/>
* (C) 2024 Vladimir Sadovnikov <[email protected]>
*
* This file is part of lsp-tk-lib
* Created on: 16 июн. 2017 г.
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/main/widgets/containers/PopupWindow.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2023 Linux Studio Plugins Project <https://lsp-plug.in/>
* (C) 2023 Vladimir Sadovnikov <[email protected]>
* Copyright (C) 2024 Linux Studio Plugins Project <https://lsp-plug.in/>
* (C) 2024 Vladimir Sadovnikov <[email protected]>
*
* This file is part of lsp-tk-lib
* Created on: 16 июн. 2020 г.
Expand Down Expand Up @@ -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;
Expand Down
81 changes: 47 additions & 34 deletions src/main/widgets/containers/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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))
Expand Down Expand Up @@ -291,7 +305,7 @@ namespace lsp
return STATUS_OK;

if (resize_pending())
sync_size();
sync_size(false);

if (!redraw_pending())
return STATUS_OK;
Expand Down Expand Up @@ -545,8 +559,8 @@ namespace lsp
//// int(l.nMinHeight), int(l.nMaxHeight)
//// );
// }

query_resize();
sync_size(true);
}
if (sLayout.is(prop))
{
Expand Down Expand Up @@ -584,7 +598,7 @@ namespace lsp
// Update window parameters
if (pWindow != NULL)
{
sync_size();
sync_size(false);
update_pointer();
}

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -1002,13 +1013,15 @@ namespace lsp
{
sPosition.set(size->nLeft, size->nTop);
sWindowSize.set(size->nWidth, size->nHeight, sScaling.get());
sync_size(true);

return STATUS_OK;
}

status_t Window::resize_window(ssize_t width, ssize_t height)
{
sWindowSize.set(width, height, sScaling.get());
sync_size(true);
return STATUS_OK;
}

Expand Down

0 comments on commit 7c8f800

Please sign in to comment.