diff gui/wm/ws.c @ 33998:ca20e4098c1d

Preserve x and y position of a double-size window if possible. Only change position in an evDoubleSize event if necessary. Do so by "dragging" the window towards the upper left if it no longer fits into the screen. Add a new function wsMoveWindowWithin() to accomplish this.
author ib
date Thu, 08 Sep 2011 15:31:25 +0000
parents acf8545dc4b5
children 3cf824f66821
line wrap: on
line diff
--- a/gui/wm/ws.c	Thu Sep 08 14:00:12 2011 +0000
+++ b/gui/wm/ws.c	Thu Sep 08 15:31:25 2011 +0000
@@ -1085,6 +1085,41 @@
         win->ReSize(win->X, win->Y, win->Width, win->Height);
 }
 
+/**
+ * @brief Move the window to the x and y position, but if it no longer fits
+ *        into the screen, reposition it towards the upper left.
+ *
+ * @param win pointer to a ws window structure
+ * @param abs flag whether the position is real/absolute (True) or mock (False)
+ * @param x x position of the window (real/absolute or mock)
+ * @param y y position of the window (real/absolute or mock)
+ */
+void wsMoveWindowWithin(wsTWindow *win, Bool abs, int x, int y)
+{
+    Bool fitting = True;
+
+    wsMoveWindow(win, abs, x, y);
+
+    if (win->X + win->Width + 1 > wsMaxX) {
+        fitting = False;
+        win->X  = wsMaxX - win->Width;
+
+        if (win->X < 0)
+            win->X = 0;
+    }
+
+    if (win->Y + win->Height + 1 > wsMaxY) {
+        fitting = False;
+        win->Y  = wsMaxY - win->Height;
+
+        if (win->Y < 0)
+            win->Y = 0;
+    }
+
+    if (!fitting)
+        wsMoveWindow(win, True, win->X, win->Y);
+}
+
 // ----------------------------------------------------------------------------------------------
 //    Resize window to sx, sy.
 // ----------------------------------------------------------------------------------------------