private void RestorePosition ()
{
object x = Preferences.Get (Preferences.SEARCH_WINDOW_X_POS);
object y = Preferences.Get (Preferences.SEARCH_WINDOW_Y_POS);
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)
|| mon == null || !(mon is int))
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);
// 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.
/// 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...");
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 {
//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);
Move (new_x, new_y);
hpaned.Position = (int) splitter_pos;
}