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 d78241d commit 9970056
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 30 deletions.
8 changes: 4 additions & 4 deletions include/private/x11/X11Window.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2020 Linux Studio Plugins Project <https://lsp-plug.in/>
* (C) 2020 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-ws-lib
* Created on: 10 окт. 2016 г.
Expand Down Expand Up @@ -79,13 +79,13 @@ namespace lsp
static bool check_click(const btn_event_t *ev);
static bool check_double_click(const btn_event_t *pe, const btn_event_t *ce);
void send_focus_event();
status_t commit_size();
status_t commit_size(const ws::rectangle_t *new_size);

protected:

void calc_constraints(rectangle_t *dst, const rectangle_t *req);

status_t do_update_constraints(bool disable=false);
status_t do_update_constraints(bool disable);

public:
explicit X11Window(X11Display *core, size_t screen, ::Window wnd, IEventHandler *handler, bool wrapper);
Expand Down
76 changes: 50 additions & 26 deletions src/main/x11/X11Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,10 @@ namespace lsp
sz.max_height = sSize.nHeight;
}

// lsp_trace("Window constraints: min_width=%d, min_height=%d, max_width=%d, max_height=%d",
// int(sz.min_width), int(sz.min_height), int(sz.max_width), int(sz.max_height)
// );
// lsp_trace("Window constraints: pos=(x=%d, y=%d), size=(w=%d, h=%d), min(w=%d, h=%d), max(w=%d, height=%d)",
// int(sz.x), int(sz.y), int(sz.width), int(sz.height),
// int(sz.min_width), int(sz.min_height), int(sz.max_width), int(sz.max_height)
// );

XSetWMNormalHints(pX11Display->x11display(), hWindow, &sz);
// pX11Display->sync();
Expand Down Expand Up @@ -517,8 +518,8 @@ namespace lsp
break;

// lsp_trace("new window location = %d x %d, size = %d x %d",
// int(ev->nLeft), int(ev->nTop),
// int(ev->nWidth), int(ev->nHeight));
// int(ev->nLeft), int(ev->nTop),
// int(ev->nWidth), int(ev->nHeight));
sSize.nLeft = ev->nLeft;
sSize.nTop = ev->nTop;
sSize.nWidth = ev->nWidth;
Expand Down Expand Up @@ -732,10 +733,7 @@ namespace lsp
sizeof(sMotif)/sizeof(long)
);


// lsp_trace("All seems to be OK");

status_t result = do_update_constraints();
status_t result = do_update_constraints(false);
pX11Display->flush();
return result;
}
Expand Down Expand Up @@ -801,32 +799,38 @@ namespace lsp
if (hParent <= 0)
::XMoveWindow(pX11Display->x11display(), hWindow, sSize.nLeft, sSize.nTop);
if (result == STATUS_OK)
result = do_update_constraints();
result = do_update_constraints(false);
if (result != STATUS_OK)
return result;
pX11Display->flush();

return STATUS_OK;
}

status_t X11Window::commit_size()
status_t X11Window::commit_size(const ws::rectangle_t *new_size)
{
if (hWindow == None)
return STATUS_OK;

// lsp_trace("old={%d, %d}, new={%d, %d}",
// int(sSize.nWidth), int(sSize.nHeight),
// int(new_size->nWidth), int(new_size->nHeight));

// Temporarily drop constraints
status_t result = do_update_constraints(true);
if (result != STATUS_OK)
return result;

// Resize window if needed
XWindowAttributes xwa;
::XGetWindowAttributes(pX11Display->x11display(), hWindow, &xwa);
// XWindowAttributes xwa;
// ::XGetWindowAttributes(pX11Display->x11display(), hWindow, &xwa);
// lsp_trace("XGetWindowAttributes -> x=%d, y=%d, w=%d h=%d", int(xwa.x), int(xwa.y), int(xwa.width), int(xwa.height));

if ((sSize.nWidth != xwa.width) || (sSize.nHeight != xwa.height))
if ((sSize.nWidth != new_size->nWidth) || (sSize.nHeight != new_size->nHeight))
{
// lsp_trace("XResizeWindow(%d, %d)", int(sSize.nWidth), int(sSize.nHeight));
// lsp_trace("XResizeWindow(%d, %d)", int(new_size->nWidth), int(new_size->nHeight));
sSize.nWidth = new_size->nWidth;
sSize.nHeight = new_size->nHeight;
::XResizeWindow(pX11Display->x11display(), hWindow, sSize.nWidth, sSize.nHeight);
}

Expand All @@ -843,16 +847,15 @@ namespace lsp
// int(sSize.nWidth), int(sSize.nHeight),
// int(width), int(height));

if ((sSize.nWidth == width) && (sSize.nHeight == height))
return STATUS_OK;
ws::rectangle_t new_size = sSize;

sSize.nWidth = width;
sSize.nHeight = height;
new_size.nWidth = width;
new_size.nHeight = height;

calc_constraints(&sSize, &sSize);
calc_constraints(&new_size, &new_size);
// lsp_trace("constrained: l=%d, t=%d, w=%d, h=%d", int(sSize.nLeft), int(sSize.nTop), int(sSize.nWidth), int(sSize.nHeight));

return commit_size();
return commit_size(&new_size);
}

status_t X11Window::set_geometry(const rectangle_t *realize)
Expand Down Expand Up @@ -909,16 +912,29 @@ namespace lsp

status_t X11Window::get_geometry(rectangle_t *realize)
{
if (realize != NULL)
*realize = sSize;
if (realize == NULL)
return STATUS_OK;

if (hWindow != None)
{
XWindowAttributes xwa;
::XGetWindowAttributes(pX11Display->x11display(), hWindow, &xwa);
sSize.nLeft = xwa.x;
sSize.nTop = xwa.y;
sSize.nWidth = xwa.width;
sSize.nHeight = xwa.height;
}

*realize = sSize;

return STATUS_OK;
}

status_t X11Window::get_absolute_geometry(rectangle_t *realize)
{
if (realize == NULL)
return STATUS_BAD_ARGUMENTS;
if (hWindow == 0)
if (hWindow == None)
{
realize->nLeft = 0;
realize->nTop = 0;
Expand All @@ -927,6 +943,13 @@ namespace lsp
return STATUS_BAD_STATE;
}

XWindowAttributes xwa;
::XGetWindowAttributes(pX11Display->x11display(), hWindow, &xwa);
sSize.nLeft = xwa.x;
sSize.nTop = xwa.y;
sSize.nWidth = xwa.width;
sSize.nHeight = xwa.height;

int x, y;
Window child;
Display *dpy = pX11Display->x11display();
Expand Down Expand Up @@ -1119,10 +1142,11 @@ namespace lsp
if (sConstraints.nMinHeight == 0)
sConstraints.nMinHeight = 1;

calc_constraints(&sSize, &sSize);
ws::rectangle_t new_size;
calc_constraints(&new_size, &sSize);
// lsp_trace("constrained: l=%d, t=%d, w=%d, h=%d", int(sSize.nLeft), int(sSize.nTop), int(sSize.nWidth), int(sSize.nHeight));

return commit_size();
return commit_size(&new_size);
}

status_t X11Window::get_size_constraints(size_limit_t *c)
Expand Down

0 comments on commit 9970056

Please sign in to comment.