Cleanup: Use XAllocSizeHints, move to helper.

Dynamic allocation (XAllocSizeHints) is recommended due to struct
potentially changing in future. Also move the repated code block
to a helper function.

Bug: angleproject:7840
Change-Id: I1e91c7adc0e36e31a385263f5d1a556520ece45c
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4048661
Auto-Submit: Roman Lavrov <romanl@google.com>
Commit-Queue: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
This commit is contained in:
Roman Lavrov
2022-11-22 14:34:16 -05:00
committed by Angle LUCI CQ
parent 68b47e58aa
commit c86f0988e0

View File

@@ -250,6 +250,22 @@ static void AddX11KeyStateToEvent(Event *event, unsigned int state)
event->Key.System = state & Mod4Mask;
}
void setWindowSizeHints(Display *display, Window window, int width, int height)
{
// Set PMinSize and PMaxSize on XSizeHints so windows larger than the screen do not get adjusted
// to screen size
XSizeHints *sizeHints = XAllocSizeHints();
sizeHints->flags = PMinSize | PMaxSize;
sizeHints->min_width = width;
sizeHints->min_height = height;
sizeHints->max_width = width;
sizeHints->max_height = height;
XSetWMNormalHints(display, window, sizeHints);
XFree(sizeHints);
}
} // namespace
X11Window::X11Window()
@@ -361,16 +377,7 @@ bool X11Window::initializeImpl(const std::string &name, int width, int height)
return false;
}
// Set PMinSize and PMaxSize on XSizeHints so windows larger than the screen do not get adjusted
// to screen size
XSizeHints sizeHints = {
.flags = PMinSize | PMaxSize,
.min_width = width,
.min_height = height,
.max_width = width,
.max_height = height,
};
XSetWMNormalHints(mDisplay, mWindow, &sizeHints);
setWindowSizeHints(mDisplay, mWindow, width, height);
XFlush(mDisplay);
@@ -457,19 +464,9 @@ bool X11Window::setPosition(int x, int y)
bool X11Window::resize(int width, int height)
{
setWindowSizeHints(mDisplay, mWindow, width, height);
XResizeWindow(mDisplay, mWindow, width, height);
// Set PMinSize and PMaxSize on XSizeHints so windows larger than the screen do not get adjusted
// to screen size
XSizeHints sizeHints = {
.flags = PMinSize | PMaxSize,
.min_width = width,
.min_height = height,
.max_width = width,
.max_height = height,
};
XSetWMNormalHints(mDisplay, mWindow, &sizeHints);
XFlush(mDisplay);
Timer timer;