[tomboy] Aimed at fixing the off-screen Search window on some multi-monitor configurations



commit 5e53a5e1b984149fd6d37d74b0f1a21eebc25de9
Author: Alex Tereschenko <frozenblue zoho com>
Date:   Thu Mar 29 00:27:35 2012 +0200

    Aimed at fixing the off-screen Search window on some multi-monitor configurations
    
    We determine the number of the monitor upon saving the window position
    and during the restoration we check if that's the same one or not. If
    yes - we restore as-is (assuming that the setup didn't change and the
    coordinates should be valid), if no - we restore to the center of the
    screen.
    
    Signed-off-by: Jared Jennings <jjennings src gnome org>

 Tomboy/Preferences.cs   |    1 +
 Tomboy/RecentChanges.cs |   35 ++++++++++++++++++++++++++++++++---
 2 files changed, 33 insertions(+), 3 deletions(-)
---
diff --git a/Tomboy/Preferences.cs b/Tomboy/Preferences.cs
index 234b9a7..afb331d 100644
--- a/Tomboy/Preferences.cs
+++ b/Tomboy/Preferences.cs
@@ -51,6 +51,7 @@ namespace Tomboy
 		public const string SEARCH_WINDOW_WIDTH = "/apps/tomboy/search_window_width";
 		public const string SEARCH_WINDOW_HEIGHT = "/apps/tomboy/search_window_height";
 		public const string SEARCH_WINDOW_SPLITTER_POS = "/apps/tomboy/search_window_splitter_pos";
+		public const string SEARCH_WINDOW_MONITOR_NUM = "/apps/tomboy/search_window_monitor_num";
 
 		static IPreferencesClient client;
 
diff --git a/Tomboy/RecentChanges.cs b/Tomboy/RecentChanges.cs
index d40b2a4..1a7f41c 100644
--- a/Tomboy/RecentChanges.cs
+++ b/Tomboy/RecentChanges.cs
@@ -1568,15 +1568,18 @@ namespace Tomboy
 			int y;
 			int width;
 			int height;
+			int mon;
 
 			GetPosition(out x, out y);
 			GetSize(out width, out height);
+			mon = Screen.GetMonitorAtPoint(x, y);
 			
 			Preferences.Set (Preferences.SEARCH_WINDOW_X_POS, x);
 			Preferences.Set (Preferences.SEARCH_WINDOW_Y_POS, y);
 			Preferences.Set (Preferences.SEARCH_WINDOW_WIDTH, width);
 			Preferences.Set (Preferences.SEARCH_WINDOW_HEIGHT, height);
 			Preferences.Set (Preferences.SEARCH_WINDOW_SPLITTER_POS, hpaned.Position);
+			Preferences.Set (Preferences.SEARCH_WINDOW_MONITOR_NUM, mon);
 		}
 
 		private void RestorePosition ()
@@ -1586,18 +1589,44 @@ namespace Tomboy
 			object width = Preferences.Get (Preferences.SEARCH_WINDOW_WIDTH);
 			object height = Preferences.Get (Preferences.SEARCH_WINDOW_HEIGHT);
 			object splitter_pos = Preferences.Get (Preferences.SEARCH_WINDOW_SPLITTER_POS);
+			object mon = Preferences.Get (Preferences.SEARCH_WINDOW_MONITOR_NUM);
+			int new_mon, new_x, new_y;
 
 			if (x == null || !(x is int)
 				|| y == null || !(y is int)
 				|| width == null || !(width is int)
 				|| height == null || !(height is int)
-				|| splitter_pos == null || !(splitter_pos is int))
+				|| splitter_pos == null || !(splitter_pos is int)
+				|| mon == null || !(mon is int))
 			return;
-		
+
+			new_mon = Screen.GetMonitorAtPoint ((int) x, (int) y);
+			Logger.Info ("Monitor number returned by GetMonitorAtPoint (actual) is: {0}", new_mon);
+			Logger.Info ("Saved monitor number is: {0}", mon);
+			Logger.Info ("Saved Search window position is {0} x {1}", (int) x, (int) y);
+
+			// If saved monitor number doesn't match the one returned by GetMonitorAtPoint for saved coords
+			// then it means that something has changed in the monitors layout and saved coordinates may not be valid.
+			// Therefore we'll restore the window to the center of the monitor closest to the saved coordinates.
+			/// It will be returned by the same GetMonitorAtPoint call.
+			if (new_mon == (int) mon) {
+				Logger.Info ("Saved monitor number does match the actual one - restoring as-is");
+				new_x = (int) x;
+				new_y = (int) y;
+			} else {
+				Logger.Info ("Saved monitor number does NOT match the actual one - restoring to the center");
+				//getting the monitor size to calculate the center
+				Gdk.Rectangle new_mon_geom = Screen.GetMonitorGeometry (new_mon);
+				new_x = new_mon_geom.Right/2 - (int) width/2;
+				new_y = new_mon_geom.Bottom/2 - (int) height/2;
+			}
+
+			Logger.Info ("Restoring Search window to position {0} x {1} at monitor {2}", new_x, new_y, new_mon);
 			DefaultSize =
 				new Gdk.Size ((int) width, (int) height);
-			Move ((int) x, (int) y);
+			Move (new_x, new_y);
 			hpaned.Position = (int) splitter_pos;
+
 		}
 
 		private void OnExitingEvent (object sender, EventArgs args)



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