From e4446d0939156cf542f4c6455bdef36cff69c00d Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 4 Aug 2019 17:40:07 +0200 Subject: X11: Factor out size hints calculation --- pugl/detail/x11.c | 51 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 21 deletions(-) (limited to 'pugl/detail/x11.c') diff --git a/pugl/detail/x11.c b/pugl/detail/x11.c index dd54644..1e1f96f 100644 --- a/pugl/detail/x11.c +++ b/pugl/detail/x11.c @@ -139,6 +139,35 @@ puglFindView(PuglWorld* world, const Window window) return NULL; } +static XSizeHints +getSizeHints(const PuglView* view) +{ + XSizeHints sizeHints = {0}; + + if (!view->hints[PUGL_RESIZABLE]) { + sizeHints.flags = PMinSize|PMaxSize; + sizeHints.min_width = (int)view->frame.width; + sizeHints.min_height = (int)view->frame.height; + sizeHints.max_width = (int)view->frame.width; + sizeHints.max_height = (int)view->frame.height; + } else { + if (view->minWidth || view->minHeight) { + sizeHints.flags = PMinSize; + sizeHints.min_width = view->minWidth; + sizeHints.min_height = view->minHeight; + } + if (view->minAspectX) { + sizeHints.flags |= PAspect; + sizeHints.min_aspect.x = view->minAspectX; + sizeHints.min_aspect.y = view->minAspectY; + sizeHints.max_aspect.x = view->maxAspectX; + sizeHints.max_aspect.y = view->maxAspectY; + } + } + + return sizeHints; +} + int puglCreateWindow(PuglView* view, const char* title) { @@ -179,27 +208,7 @@ puglCreateWindow(PuglView* view, const char* title) return 3; } - XSizeHints sizeHints = {0}; - if (!view->hints[PUGL_RESIZABLE]) { - sizeHints.flags = PMinSize|PMaxSize; - sizeHints.min_width = width; - sizeHints.min_height = height; - sizeHints.max_width = width; - sizeHints.max_height = height; - } else { - if (view->minWidth || view->minHeight) { - sizeHints.flags = PMinSize; - sizeHints.min_width = view->minWidth; - sizeHints.min_height = view->minHeight; - } - if (view->minAspectX) { - sizeHints.flags |= PAspect; - sizeHints.min_aspect.x = view->minAspectX; - sizeHints.min_aspect.y = view->minAspectY; - sizeHints.max_aspect.x = view->maxAspectX; - sizeHints.max_aspect.y = view->maxAspectY; - } - } + XSizeHints sizeHints = getSizeHints(view); XSetNormalHints(display, win, &sizeHints); if (title) { -- cgit v1.2.1