]> Pileus Git - ~andy/gtk/commitdiff
win32: Ensure newly mapped toplevels are inside the workarea
authorAlexander Larsson <alexl@redhat.com>
Wed, 2 Nov 2011 13:30:23 +0000 (14:30 +0100)
committerAlexander Larsson <alexl@redhat.com>
Thu, 10 Nov 2011 16:41:10 +0000 (17:41 +0100)
This is what e.g. metacity does, and its needed to e.g. get the inital
position of the gimp dock window right.

gdk/win32/gdkwindow-win32.c

index f2154abf2fe70d79fd4d1424b16e3935ad5b5f7e..4985103a01dd640bf6a2727866d90bbeecc37ccb 100644 (file)
@@ -1065,6 +1065,57 @@ show_window_internal (GdkWindow *window,
                               SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER));
     }
 
+  if (!already_mapped &&
+      GDK_WINDOW_TYPE (window) == GDK_WINDOW_TOPLEVEL &&
+      !window_impl->override_redirect)
+    {
+      /* Ensure new windows are fully onscreen */
+      RECT window_rect;
+      HMONITOR monitor;
+      MONITORINFO mi;
+      int x, y;
+
+      GetWindowRect (GDK_WINDOW_HWND (window), &window_rect);
+
+      monitor = MonitorFromWindow (GDK_WINDOW_HWND (window), MONITOR_DEFAULTTONEAREST);
+      mi.cbSize = sizeof (mi);
+      if (monitor && GetMonitorInfo (monitor, &mi))
+       {
+         x = window_rect.left;
+         y = window_rect.top;
+
+         if (window_rect.right > mi.rcWork.right)
+           {
+             window_rect.left -= (window_rect.right - mi.rcWork.right);
+             window_rect.right -= (window_rect.right - mi.rcWork.right);
+           }
+
+         if (window_rect.bottom > mi.rcWork.bottom)
+           {
+             window_rect.top -= (window_rect.bottom - mi.rcWork.bottom);
+             window_rect.bottom -= (window_rect.bottom - mi.rcWork.bottom);
+           }
+
+         if (window_rect.left < mi.rcWork.left)
+           {
+             window_rect.right += (mi.rcWork.left - window_rect.left);
+             window_rect.left += (mi.rcWork.left - window_rect.left);
+           }
+
+         if (window_rect.top < mi.rcWork.top)
+           {
+             window_rect.bottom += (mi.rcWork.top - window_rect.top);
+             window_rect.top += (mi.rcWork.top - window_rect.top);
+           }
+
+         if (x != window_rect.left || y != window_rect.top)
+           API_CALL (SetWindowPos, (GDK_WINDOW_HWND (window), NULL,
+                                    window_rect.left, window_rect.top, 0, 0,
+                                    SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER));
+       }
+    }
+
+
   if (window->state & GDK_WINDOW_STATE_FULLSCREEN)
     {
       gdk_window_fullscreen (window);