Skip to content

Commit 4134ba3

Browse files
committed
Merge branch 'new-constraints' into devel
* Updated window size handling
2 parents daa8bd2 + e392a79 commit 4134ba3

File tree

4 files changed

+50
-69
lines changed

4 files changed

+50
-69
lines changed

include/lsp-plug.in/tk/widgets/containers/PopupWindow.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ namespace lsp
6161
protected:
6262
virtual void hide_widget() override;
6363
virtual void show_widget() override;
64-
virtual status_t sync_size(bool force) override;
64+
virtual status_t sync_size() override;
6565
virtual void size_request(ws::size_limit_t *r) override;
6666

6767
virtual status_t post_init();

include/lsp-plug.in/tk/widgets/containers/Window.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ namespace lsp
8787
Overlay *wWidget; // Widget
8888
} overlay_t;
8989

90+
enum size_hints_t
91+
{
92+
HSIZE_MINIMIZE_SIZE = 1 << 0, // Minimize the size of the window
93+
};
94+
9095
public:
9196
static const w_class_t metadata;
9297

@@ -97,6 +102,7 @@ namespace lsp
97102
Widget *pFocused; // Focused widget
98103
bool bMapped;
99104
bool bOverridePointer;
105+
uint32_t nSizeHints; // Size hints
100106
ws::surface_type_t enSurfaceType; // Surface type
101107
float fScaling; // Cached scaling factor
102108
Shortcuts sShortcuts; // Shortcuts
@@ -146,7 +152,7 @@ namespace lsp
146152
void draw_widgets(ws::ISurface *s);
147153
void auto_close_overlays(const ws::event_t *ev);
148154
Overlay *find_overlay(ssize_t x, ssize_t y);
149-
virtual status_t sync_size(bool force);
155+
virtual status_t sync_size();
150156
status_t update_pointer();
151157

152158
// Mouse operations

src/main/widgets/containers/PopupWindow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ namespace lsp
123123
return STATUS_OK;
124124
}
125125

126-
status_t PopupWindow::sync_size(bool force)
126+
status_t PopupWindow::sync_size()
127127
{
128128
ws::size_limit_t sr;
129129
ws::rectangle_t xr;

src/main/widgets/containers/Window.cpp

Lines changed: 41 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ namespace lsp
9393
pNativeHandle = handle;
9494
bMapped = false;
9595
bOverridePointer= false;
96+
nSizeHints = 0;
97+
9698
enSurfaceType = ws::ST_UNKNOWN;
9799
fScaling = 1.0f;
98100
pActor = NULL;
@@ -187,8 +189,9 @@ namespace lsp
187189
return init_internal(true);
188190
}
189191

190-
status_t Window::sync_size(bool force)
192+
status_t Window::sync_size()
191193
{
194+
lsp_finally { nSizeHints = 0; };
192195
// Request size limits of the window
193196
ws::size_limit_t sr;
194197
ws::rectangle_t r, wsr;
@@ -233,8 +236,8 @@ namespace lsp
233236
xr.nWidth = lsp_max(0, sr.nMinWidth) + border*2;
234237
xr.nHeight = lsp_max(0, sr.nMinHeight) + border*2;
235238

236-
// Maximize the width
237-
if (force)
239+
// Need to maximize the size?
240+
if (nSizeHints & HSIZE_MINIMIZE_SIZE)
238241
{
239242
r.nWidth = lsp_max(xr.nWidth, r.nWidth);
240243
r.nHeight = lsp_max(xr.nHeight, r.nHeight);
@@ -251,14 +254,18 @@ namespace lsp
251254
r.nHeight = lsp_max(r.nHeight, 1);
252255

253256
// Check if we need to resize window
254-
// lsp_trace("size constraints: w={%d, %d}, h={%d, %d}",
255-
// int(sr.nMinWidth), int(sr.nMinHeight), int(sr.nMaxWidth), int(sr.nMaxHeight)
256-
// );
257-
// lsp_trace("computed size: w=%d, h=%d", int(r.nWidth), int(r.nHeight));
258-
pWindow->set_size_constraints(&sr);
259-
if ((sSize.nWidth != r.nWidth) || (sSize.nHeight != r.nHeight))
257+
if ((wsr.nWidth != r.nWidth) || (wsr.nHeight != r.nHeight))
260258
{
261-
pWindow->resize(r.nWidth, r.nHeight);
259+
if (nSizeHints & HSIZE_MINIMIZE_SIZE)
260+
{
261+
// lsp_trace("forcing window resize constraints: w=(%d, %d), h=(%d, %d), size: (%d, %d) -> (%d, %d)",
262+
// int(sr.nMinWidth), int(sr.nMaxWidth), int(sr.nMinHeight), int(sr.nMaxHeight),
263+
// int(wsr.nWidth), int(wsr.nHeight),
264+
// int(r.nWidth), int(r.nHeight));
265+
pWindow->set_size_constraints(&sr);
266+
pWindow->resize(r.nWidth, r.nHeight);
267+
}
268+
262269
sWindowSize.commit_value(r.nWidth, r.nHeight, scaling);
263270
}
264271

@@ -373,7 +380,7 @@ namespace lsp
373380
return STATUS_OK;
374381

375382
if (resize_pending())
376-
sync_size(false);
383+
sync_size();
377384

378385
update_pointer();
379386

@@ -388,7 +395,7 @@ namespace lsp
388395
enSurfaceType = s->type();
389396

390397
// #ifdef LSP_TRACE
391-
// system::time_millis_t time = system::get_time_millis();
398+
// const system::time_millis_t start = system::get_time_millis();
392399
// #endif /* LSP_TRACE */
393400
ws::rectangle_t xr;
394401
xr.nLeft = 0;
@@ -400,8 +407,9 @@ namespace lsp
400407
commit_redraw();
401408

402409
// #ifdef LSP_TRACE
403-
// time = system::get_time_millis() - time;
404-
// lsp_trace("Window %p render time: %ld ms", this, long(time));
410+
// const system::time_millis_t end = system::get_time_millis();
411+
// lsp_trace("Window %p render time: start=%lld, end=%lld, time=%ld ms",
412+
// this, (long long)start, (long long)(end), (long)(end - start));
405413
// #endif /* LSP_TRACE */
406414

407415
return STATUS_OK;
@@ -653,32 +661,10 @@ namespace lsp
653661
if (sPosition.is(prop))
654662
pWindow->move(sPosition.left(), sPosition.top());
655663

656-
if (prop->one_of(sSizeConstraints, sScaling, sActions, sWindowState, sFontScaling, sWindowSize))
664+
if (prop->one_of(sScaling, sActions, sWindowState, sFontScaling, sWindowSize, sSizeConstraints))
657665
{
658-
// float scaling = lsp_max(0.0f, sScaling.get());
659-
//
660-
// ws::size_limit_t l;
661-
// sSizeConstraints.compute(&l, scaling);
662-
// pWindow->set_size_constraints(&l);
663-
//
664-
// if ((scaling != fScaling) && (bMapped))
665-
// {
666-
// ws::rectangle_t rect;
667-
// ws::size_limit_t l;
668-
// sWindowSize.compute(&rect, scaling);
669-
// sSizeConstraints.compute(&l, scaling);
670-
//
671-
// fScaling = scaling;
672-
// pWindow->set_size_constraints(-1, -1, -1, -1);
673-
// pWindow->resize(rect.nWidth, rect.nHeight);
674-
// pWindow->set_size_constraints(&l);
675-
//// lsp_trace("Setting size constraints: w={%d, %d}, h={%d, %d}",
676-
//// int(l.nMinWidth), int(l.nMaxWidth),
677-
//// int(l.nMinHeight), int(l.nMaxHeight)
678-
//// );
679-
// }
666+
nSizeHints = HSIZE_MINIMIZE_SIZE;
680667
query_resize();
681-
sync_size(true);
682668
}
683669
if (sLayout.is(prop))
684670
{
@@ -720,7 +706,7 @@ namespace lsp
720706
// Update window parameters
721707
if (pWindow != NULL)
722708
{
723-
sync_size(false);
709+
sync_size();
724710
update_pointer();
725711
}
726712

@@ -763,7 +749,7 @@ namespace lsp
763749
}
764750

765751
// Show over the actor window
766-
sync_size(false);
752+
sync_size();
767753
pWindow->show(wnd);
768754
if (is_dialog)
769755
pWindow->take_focus();
@@ -974,28 +960,17 @@ namespace lsp
974960
lsp_trace("resize to: l=%d, t=%d, w=%d, h=%d", int(e->nLeft), int(e->nTop), int(e->nWidth), int(e->nHeight));
975961

976962
// Update the position of the window
977-
if ((sSize.nLeft != e->nLeft) || (sSize.nTop != e->nTop))
978-
sPosition.commit_value(e->nLeft, e->nTop);
963+
sPosition.commit_value(e->nLeft, e->nTop);
964+
sWindowSize.commit_value(e->nWidth, e->nHeight, sScaling.get());
965+
966+
sSize.nLeft = e->nLeft;
967+
sSize.nTop = e->nTop;
968+
sSize.nWidth = e->nWidth;
969+
sSize.nHeight = e->nHeight;
970+
971+
sSlots.execute(SLOT_RESIZE, this, &ev);
972+
query_resize();
979973

980-
// Update size of the window
981-
if ((sSize.nWidth != e->nWidth) || (sSize.nHeight != e->nHeight))
982-
{
983-
// Realize the widget only if size has changed
984-
sWindowSize.commit_value(e->nWidth, e->nHeight, sScaling.get());
985-
986-
ws::rectangle_t r = {
987-
e->nLeft,
988-
e->nTop,
989-
e->nWidth,
990-
e->nHeight
991-
};
992-
realize_widget(&r);
993-
}
994-
else
995-
{
996-
sSize.nLeft = e->nLeft;
997-
sSize.nTop = e->nTop;
998-
}
999974
break;
1000975

1001976
//-------------------------------------------------------------
@@ -1220,17 +1195,17 @@ namespace lsp
12201195

12211196
status_t Window::resize_window(const ws::rectangle_t *size)
12221197
{
1223-
sPosition.set(size->nLeft, size->nTop);
1224-
sWindowSize.set(size->nWidth, size->nHeight, sScaling.get());
1225-
sync_size(true);
1198+
if (pWindow != NULL)
1199+
pWindow->set_geometry(size);
12261200

12271201
return STATUS_OK;
12281202
}
12291203

12301204
status_t Window::resize_window(ssize_t width, ssize_t height)
12311205
{
1232-
sWindowSize.set(width, height, sScaling.get());
1233-
sync_size(true);
1206+
if (pWindow != NULL)
1207+
pWindow->resize(width, height);
1208+
12341209
return STATUS_OK;
12351210
}
12361211

0 commit comments

Comments
 (0)