From 980477c1f124d890b428ffc3e1079fe02a4b4915 Mon Sep 17 00:00:00 2001 From: Laurent Gomila Date: Tue, 1 Oct 2013 18:28:25 +0200 Subject: [PATCH] Fixed Window::setSize not working without the sf::Style::Resize style (#466) --- src/SFML/Window/Linux/WindowImplX11.cpp | 20 +++++++++++++++++--- src/SFML/Window/Linux/WindowImplX11.hpp | 3 ++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/SFML/Window/Linux/WindowImplX11.cpp b/src/SFML/Window/Linux/WindowImplX11.cpp index 1b712103f..9b541b37f 100644 --- a/src/SFML/Window/Linux/WindowImplX11.cpp +++ b/src/SFML/Window/Linux/WindowImplX11.cpp @@ -90,7 +90,8 @@ m_atomClose (0), m_oldVideoMode(-1), m_hiddenCursor(0), m_keyRepeat (true), -m_previousSize(-1, -1) +m_previousSize(-1, -1), +m_useSizeHints(false) { // Open a connection with the X server m_display = OpenDisplay(); @@ -120,7 +121,8 @@ m_atomClose (0), m_oldVideoMode(-1), m_hiddenCursor(0), m_keyRepeat (true), -m_previousSize(-1, -1) +m_previousSize(-1, -1), +m_useSizeHints(false) { // Open a connection with the X server m_display = OpenDisplay(); @@ -236,9 +238,10 @@ m_previousSize(-1, -1) // This is a hack to force some windows managers to disable resizing if (!(style & Style::Resize)) { + m_useSizeHints = true; XSizeHints* sizeHints = XAllocSizeHints(); 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; XSetWMNormalHints(m_display, m_window, sizeHints); XFree(sizeHints); @@ -348,6 +351,17 @@ Vector2u WindowImplX11::getSize() const //////////////////////////////////////////////////////////// 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); XFlush(m_display); } diff --git a/src/SFML/Window/Linux/WindowImplX11.hpp b/src/SFML/Window/Linux/WindowImplX11.hpp index 613fa7bf7..97d9e4e28 100644 --- a/src/SFML/Window/Linux/WindowImplX11.hpp +++ b/src/SFML/Window/Linux/WindowImplX11.hpp @@ -222,8 +222,9 @@ private : Atom m_atomClose; ///< Atom used to identify the close event 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 - 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) + bool m_useSizeHints; ///< Is the size of the window fixed with size hints? }; } // namespace priv