[gimp] app: keep docks on the monitor in gimp_ui_configurer_move_docks_to_window()



commit 4bb63322d7226bfe401aff027d893906e5dd234c
Author: Michael Natterer <mitch gimp org>
Date:   Fri May 2 21:12:56 2014 +0200

    app: keep docks on the monitor in gimp_ui_configurer_move_docks_to_window()
    
    and don't move them to the very left and right of the screen, which might
    be on different monitors. Also clean up the function.

 app/gui/gimpuiconfigurer.c |   58 ++++++++++++++++++++++++++++---------------
 1 files changed, 38 insertions(+), 20 deletions(-)
---
diff --git a/app/gui/gimpuiconfigurer.c b/app/gui/gimpuiconfigurer.c
index 4d051df..bf5c7eb 100644
--- a/app/gui/gimpuiconfigurer.c
+++ b/app/gui/gimpuiconfigurer.c
@@ -76,7 +76,7 @@ static void              gimp_ui_configurer_separate_docks              (GimpUIC
                                                                          GimpImageWindow   
*source_image_window);
 static void              gimp_ui_configurer_move_docks_to_window        (GimpUIConfigurer  *ui_configurer,
                                                                          GimpDockColumns   *dock_columns,
-                                                                         GimpAlignmentType  
screen_side_destination);
+                                                                         GimpAlignmentType  screen_side);
 static void              gimp_ui_configurer_separate_shells             (GimpUIConfigurer  *ui_configurer,
                                                                          GimpImageWindow   
*source_image_window);
 static void              gimp_ui_configurer_configure_for_single_window (GimpUIConfigurer  *ui_configurer);
@@ -321,8 +321,7 @@ gimp_ui_configurer_separate_docks (GimpUIConfigurer  *ui_configurer,
 /**
  * gimp_ui_configurer_move_docks_to_window:
  * @dock_columns:
- * @screen_side_destination: At what side of the screen the dock window
- *                           should be put.
+ * @screen_side: At what side of the screen the dock window should be put.
  *
  * Moves docks in @dock_columns into a new #GimpDockWindow and
  * position it on the screen in a non-overlapping manner.
@@ -330,27 +329,34 @@ gimp_ui_configurer_separate_docks (GimpUIConfigurer  *ui_configurer,
 static void
 gimp_ui_configurer_move_docks_to_window (GimpUIConfigurer  *ui_configurer,
                                          GimpDockColumns   *dock_columns,
-                                         GimpAlignmentType  screen_side_destination)
+                                         GimpAlignmentType  screen_side)
 {
-  GdkScreen    *screen           = gtk_widget_get_screen (GTK_WIDGET (dock_columns));
-  gint          monitor          = gimp_widget_get_monitor (GTK_WIDGET (dock_columns));
-  GList        *docks            = g_list_copy (gimp_dock_columns_get_docks (dock_columns));
-  GList        *iter             = NULL;
-  gboolean      contains_toolbox = FALSE;
-  GtkWidget    *dock_window      = NULL;
-  GtkAllocation original_size    = { 0, 0, 0, 0 };
-
-  /* Are there docks to move at all? */
+  GdkScreen     *screen;
+  gint           monitor;
+  GdkRectangle   monitor_rect;
+  GList         *docks;
+  GList         *iter;
+  gboolean       contains_toolbox = FALSE;
+  GtkWidget     *dock_window;
+  GtkAllocation  original_size;
+  gchar          geometry[32];
+
+  docks = g_list_copy (gimp_dock_columns_get_docks (dock_columns));
   if (! docks)
     return;
 
+  screen  = gtk_widget_get_screen (GTK_WIDGET (dock_columns));
+  monitor = gimp_widget_get_monitor (GTK_WIDGET (dock_columns));
+
+  gdk_screen_get_monitor_geometry (screen, monitor, &monitor_rect);
+
   /* Remember the size so we can set the new dock window to the same
    * size
    */
   gtk_widget_get_allocation (GTK_WIDGET (dock_columns), &original_size);
 
   /* Do we need a toolbox window? */
-  for (iter = docks; iter; iter = iter->next)
+  for (iter = docks; iter; iter = g_list_next (iter))
     {
       GimpDock *dock = GIMP_DOCK (iter->data);
 
@@ -377,7 +383,7 @@ gimp_ui_configurer_move_docks_to_window (GimpUIConfigurer  *ui_configurer,
                                     -1 /*view_size*/,
                                     FALSE /*present*/);
 
-  for (iter = docks; iter; iter = iter->next)
+  for (iter = docks; iter; iter = g_list_next (iter))
     {
       GimpDock *dock = GIMP_DOCK (iter->data);
 
@@ -389,12 +395,24 @@ gimp_ui_configurer_move_docks_to_window (GimpUIConfigurer  *ui_configurer,
     }
 
   /* Position the window */
-  if (screen_side_destination == GIMP_ALIGN_LEFT)
-    gtk_window_parse_geometry (GTK_WINDOW (dock_window), "+0+0");
-  else if (screen_side_destination == GIMP_ALIGN_RIGHT)
-    gtk_window_parse_geometry (GTK_WINDOW (dock_window), "-0+0");
+  if (screen_side == GIMP_ALIGN_LEFT)
+    {
+      g_snprintf (geometry, sizeof (geometry), "%+d%+d",
+                  monitor_rect.x,
+                  monitor_rect.y);
+    }
+  else if (screen_side == GIMP_ALIGN_RIGHT)
+    {
+      g_snprintf (geometry, sizeof (geometry), "%+d%+d",
+                  monitor_rect.x + monitor_rect.width - original_size.width,
+                  monitor_rect.y);
+    }
   else
-    g_assert_not_reached ();
+    {
+      g_assert_not_reached ();
+    }
+
+  gtk_window_parse_geometry (GTK_WINDOW (dock_window), geometry);
 
   /* Try to keep the same size */
   gtk_window_set_default_size (GTK_WINDOW (dock_window),


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]