Skip to content

Commit

Permalink
Normalize Aero clock flyout position and margin to Vista style
Browse files Browse the repository at this point in the history
  • Loading branch information
xoascf committed Jan 1, 2025
1 parent 2bc89bf commit 6bdc12f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
2 changes: 1 addition & 1 deletion RetroBar/PropertiesWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ private void LoadClockActions()
{
if (EnvironmentHelper.IsWindows10OrBetter)
{
return;
return;
}

// Remove options unsupported prior to Windows 10.
Expand Down
41 changes: 36 additions & 5 deletions RetroBar/Utilities/ClockFlyoutLauncher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6bdc12f

Please sign in to comment.