From da1b2d8311ca78eccd3e9875598562ce6bf05cab Mon Sep 17 00:00:00 2001
From: Andrei Karas <akaras@inbox.ru>
Date: Tue, 12 Apr 2011 20:17:36 +0300
Subject: Fix windows size if part of window showed out of screen.

---
 src/gui/widgets/window.cpp | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

(limited to 'src/gui/widgets')

diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp
index 14f39a4c3..72530db8f 100644
--- a/src/gui/widgets/window.cpp
+++ b/src/gui/widgets/window.cpp
@@ -665,6 +665,22 @@ void Window::loadWindowState()
 
     // Check if the window is off screen...
     checkIfIsOffScreen();
+
+    if (viewport)
+    {
+        int width = getWidth();
+        int height = getHeight();
+
+        if (getX() + width >= viewport->getWidth())
+            width = viewport->getWidth() - getX() - 1;
+        if (getY() + height >= viewport->getHeight())
+            height = viewport->getHeight() - getY() - 1;
+        if (width < 0)
+            width = 0;
+        if (height < 0)
+            height = 0;
+        setSize(width, height);
+    }
 }
 
 void Window::saveWindowState()
-- 
cgit v1.2.3-70-g09d2