public static void LoadWindowLocation(Window mainWindow, EditViewPopup editPopup, MiniTimerWindow miniTimer) { if (editPopup != null) { editPopup.Width = Toggl.GetEditViewWidth(); } if (Toggl.GetWindowMaximized()) { mainWindow.WindowState = WindowState.Maximized; } else if (Toggl.GetWindowMinimized()) { mainWindow.WindowState = WindowState.Minimized; } long x = 0, y = 0, h = 0, w = 0; if (Toggl.WindowSettings(ref x, ref y, ref h, ref w) && ValidateWindowSettings(x, y, h, w)) { mainWindow.Left = x; mainWindow.Top = y; mainWindow.Width = w; mainWindow.Height = h; Toggl.Debug("Retrieved window location and size ({0}x{1} by {2}x{3})", x, y, w, h); } else { mainWindow.Width = 330; mainWindow.Height = 510; Toggl.Debug("Failed to retrieve window location and size. Setting the default size."); } // First try to shift the window onto the bounding box of visible screens if (ShiftWindowOntoVisibleArea(mainWindow)) { Toggl.Debug("Shifted main window onto visible area"); } // Then handle the case where the window is in the bounding box but not on any of the screens if (!VisibleOnAnyScreen(mainWindow)) { var location = Screen.PrimaryScreen.WorkingArea.Location; mainWindow.Left = location.X; mainWindow.Top = location.Y; Toggl.Debug("Force moved window to primary screen"); } if (miniTimer != null) { x = Toggl.GetMiniTimerX(); y = Toggl.GetMiniTimerY(); w = Toggl.GetMiniTimerW(); miniTimer.Left = x; miniTimer.Top = y; miniTimer.Width = w; Toggl.Debug("Retrieved mini timer location ({0}x{1} by {2})", x, y, w); CheckMinitimerVisibility(miniTimer); } }
public static void LoadWindowLocation(Window mainWindow, EditViewPopup editPopup, MiniTimerWindow miniTimer) { if (editPopup != null) { editPopup.Width = Toggl.GetEditViewWidth(); } if (Toggl.GetWindowMaximized()) { mainWindow.WindowState = WindowState.Maximized; } else if (Toggl.GetWindowMinimized()) { mainWindow.WindowState = WindowState.Minimized; } long x = 0, y = 0, h = 0, w = 0; if (Toggl.WindowSettings(ref x, ref y, ref h, ref w)) { mainWindow.Left = x; mainWindow.Top = y; mainWindow.Width = w; mainWindow.Height = h; Toggl.Debug("Retrieved window location and size ({0}x{1} by {2}x{3})", x, y, w, h); } else { Toggl.Debug("Failed to retrieve window location and size"); } if (!visibleOnAnyScreen(mainWindow)) { var location = Screen.PrimaryScreen.WorkingArea.Location; mainWindow.Left = location.X; mainWindow.Top = location.Y; Toggl.Debug("Force moved window to primary screen"); } if (miniTimer != null) { x = Toggl.GetMiniTimerX(); y = Toggl.GetMiniTimerY(); w = Toggl.GetMiniTimerW(); miniTimer.Left = x; miniTimer.Top = y; miniTimer.Width = w; Toggl.Debug("Retrieved mini timer location ({0}x{1} by {2})", x, y, w); if (!visibleOnAnyScreen(miniTimer)) { var location = Screen.PrimaryScreen.WorkingArea.Location; miniTimer.Left = location.X; miniTimer.Top = location.Y; Toggl.Debug("Force moved mini timer to primary screen"); } } }