[tomboy] Additional logic for Search All position restoration code



commit da8c5380a1b739fbeb87cb82859410c5e9f9a5c0
Author: Alex Tereschenko <frozen and blue gmail com>
Date:   Fri Nov 16 23:04:04 2012 +0100

    Additional logic for Search All position restoration code
    
    We'll now not only check if the saved monitor number matches, but also check if
    the saved position is actually within that monitor.
    
    Signed-off-by: Jared Jennings <jared jaredjennings org>

 Tomboy/RecentChanges.cs |   24 +++++++++++++++++++-----
 1 files changed, 19 insertions(+), 5 deletions(-)
---
diff --git a/Tomboy/RecentChanges.cs b/Tomboy/RecentChanges.cs
index 819d701..8977f63 100644
--- a/Tomboy/RecentChanges.cs
+++ b/Tomboy/RecentChanges.cs
@@ -1607,6 +1607,7 @@ namespace Tomboy
 			return;
 
 			new_mon = Screen.GetMonitorAtPoint ((int) x, (int) y);
+			Gdk.Rectangle new_mon_geom = Screen.GetMonitorGeometry (new_mon);
 			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);
@@ -1615,18 +1616,31 @@ namespace Tomboy
 			// 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.
+			/// However if the saved monitor number matches the current one, there's still a chance we'll
+			/// have wrong coordinates saved due to e.g. different monitors (with different resolution)
+			/// used at different times in single-monitor config, also see e.g. bgo#688296 when no explanation was found
+			bool restore_as_is = true;
 			if (new_mon == (int) mon) {
-				Logger.Info ("Saved monitor number does match the actual one - restoring as-is");
+				Logger.Info ("Saved monitor number does match the actual one...");
+				if (new_mon_geom.Contains((int) x, (int) y)) {
+					Logger.Info("...and saved window position is within it - restoring as-is.");
+				} else {
+					Logger.Info("...but saved window position is NOT within it - restoring to the center.");
+					restore_as_is = false;
+				}
+			} else {
+				Logger.Info ("Saved monitor number does NOT match the actual one - restoring to the center.");
+				restore_as_is = false;
+			}
+
+			if (restore_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);
+				//center of the screen
 				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);



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