Fixed Window::setSize not working without the sf::Style::Resize style (#466)

This commit is contained in:
Laurent Gomila 2013-10-01 18:28:25 +02:00
parent eee18a515a
commit 980477c1f1
2 changed files with 19 additions and 4 deletions

View File

@ -90,7 +90,8 @@ m_atomClose (0),
m_oldVideoMode(-1), m_oldVideoMode(-1),
m_hiddenCursor(0), m_hiddenCursor(0),
m_keyRepeat (true), m_keyRepeat (true),
m_previousSize(-1, -1) m_previousSize(-1, -1),
m_useSizeHints(false)
{ {
// Open a connection with the X server // Open a connection with the X server
m_display = OpenDisplay(); m_display = OpenDisplay();
@ -120,7 +121,8 @@ m_atomClose (0),
m_oldVideoMode(-1), m_oldVideoMode(-1),
m_hiddenCursor(0), m_hiddenCursor(0),
m_keyRepeat (true), m_keyRepeat (true),
m_previousSize(-1, -1) m_previousSize(-1, -1),
m_useSizeHints(false)
{ {
// Open a connection with the X server // Open a connection with the X server
m_display = OpenDisplay(); m_display = OpenDisplay();
@ -236,9 +238,10 @@ m_previousSize(-1, -1)
// This is a hack to force some windows managers to disable resizing // This is a hack to force some windows managers to disable resizing
if (!(style & Style::Resize)) if (!(style & Style::Resize))
{ {
m_useSizeHints = true;
XSizeHints* sizeHints = XAllocSizeHints(); XSizeHints* sizeHints = XAllocSizeHints();
sizeHints->flags = PMinSize | PMaxSize; sizeHints->flags = PMinSize | PMaxSize;
sizeHints->min_width = sizeHints->max_width = width; sizeHints->min_width = sizeHints->max_width = width;
sizeHints->min_height = sizeHints->max_height = height; sizeHints->min_height = sizeHints->max_height = height;
XSetWMNormalHints(m_display, m_window, sizeHints); XSetWMNormalHints(m_display, m_window, sizeHints);
XFree(sizeHints); XFree(sizeHints);
@ -348,6 +351,17 @@ Vector2u WindowImplX11::getSize() const
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void WindowImplX11::setSize(const Vector2u& size) void WindowImplX11::setSize(const Vector2u& size)
{ {
// If we used size hint to fix the size of the window, we must update them
if (m_useSizeHints)
{
XSizeHints* sizeHints = XAllocSizeHints();
sizeHints->flags = PMinSize | PMaxSize;
sizeHints->min_width = sizeHints->max_width = size.x;
sizeHints->min_height = sizeHints->max_height = size.y;
XSetWMNormalHints(m_display, m_window, sizeHints);
XFree(sizeHints);
}
XResizeWindow(m_display, m_window, size.x, size.y); XResizeWindow(m_display, m_window, size.x, size.y);
XFlush(m_display); XFlush(m_display);
} }

View File

@ -222,8 +222,9 @@ private :
Atom m_atomClose; ///< Atom used to identify the close event Atom m_atomClose; ///< Atom used to identify the close event
int m_oldVideoMode; ///< Video mode in use before we switch to fullscreen int m_oldVideoMode; ///< Video mode in use before we switch to fullscreen
Cursor m_hiddenCursor; ///< As X11 doesn't provide cursor hidding, we must create a transparent one Cursor m_hiddenCursor; ///< As X11 doesn't provide cursor hidding, we must create a transparent one
bool m_keyRepeat; ///< Is the KeyRepeat feature enabled ? bool m_keyRepeat; ///< Is the KeyRepeat feature enabled?
Vector2i m_previousSize; ///< Previous size of the window, to find if a ConfigureNotify event is a resize event (could be a move event only) Vector2i m_previousSize; ///< Previous size of the window, to find if a ConfigureNotify event is a resize event (could be a move event only)
bool m_useSizeHints; ///< Is the size of the window fixed with size hints?
}; };
} // namespace priv } // namespace priv