diff --git a/RetroBar/PropertiesWindow.xaml.cs b/RetroBar/PropertiesWindow.xaml.cs index 61c08315..2331b3cc 100644 --- a/RetroBar/PropertiesWindow.xaml.cs +++ b/RetroBar/PropertiesWindow.xaml.cs @@ -284,7 +284,7 @@ private void LoadClockActions() { if (EnvironmentHelper.IsWindows10OrBetter) { - return; + return; } // Remove options unsupported prior to Windows 10. diff --git a/RetroBar/Utilities/ClockFlyoutLauncher.cs b/RetroBar/Utilities/ClockFlyoutLauncher.cs index 6708eca2..3d416cc0 100644 --- a/RetroBar/Utilities/ClockFlyoutLauncher.cs +++ b/RetroBar/Utilities/ClockFlyoutLauncher.cs @@ -63,12 +63,43 @@ private static void FixAeroClockFlyoutPosition(Screen taskbarScreen) return; } - GetWindowRect(clockFlyoutHwnd, out Rect clockFlyoutRect); + if (!GetWindowRect(clockFlyoutHwnd, out Rect rect)) + { + return; + } + + var wa = taskbarScreen.WorkingArea; + int newX = rect.Left, newY = rect.Top; + + // Max margin (as used in Windows 7) + int snap = 15; + // Vista margin + int margin = 7; + + // Move to closest edge if the flyout is too close to the screen edge + if (Math.Abs(newX - wa.Left) <= snap) // Left + { + newX = wa.Left + margin; + } + else if (Math.Abs(rect.Right - wa.Right) <= snap) // Right + { + newX = wa.Right - rect.Width - margin; + } + + if (Math.Abs(newY - wa.Top) <= snap) // Top + { + newY = wa.Top + margin; + } + else if (Math.Abs(rect.Bottom - wa.Bottom) <= snap) // Bottom + { + newY = wa.Bottom - rect.Height - margin; + } + + // Keep the flyout inside the working area + newX = Math.Max(wa.Left + margin, Math.Min(newX, wa.Right - rect.Width - margin)); + newY = Math.Max(wa.Top + margin, Math.Min(newY, wa.Bottom - rect.Height - margin)); - // Keep the flyout at least 15 by 15 pixels inside the working area - int newX = (int)Math.Max(taskbarScreen.WorkingArea.Left + 15, Math.Min(taskbarScreen.WorkingArea.Right - (clockFlyoutRect.Width) - 15, clockFlyoutRect.Left)); - int newY = (int)Math.Max(taskbarScreen.WorkingArea.Top + 15, Math.Min(taskbarScreen.WorkingArea.Bottom - (clockFlyoutRect.Height) - 15, clockFlyoutRect.Top)); - SetWindowPos(clockFlyoutHwnd, IntPtr.Zero, newX, newY, 0, 0, (int)(NoPosFlags)); + SetWindowPos(clockFlyoutHwnd, IntPtr.Zero, newX, newY, 0, 0, (int)NoPosFlags); } #endregion Aero clock