Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion FluentFlyoutWPF/Classes/Utils/MonitorUtil.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2024-2026 The FluentFlyout Authors
// Copyright (c) 2024-2026 The FluentFlyout Authors
// SPDX-License-Identifier: GPL-3.0-or-later

using FluentFlyout.Classes;
Expand Down Expand Up @@ -75,6 +75,35 @@ public static MonitorInfo GetMonitor(Window window, MonitorFromWindowFlags flag
return GetMonitor(new WindowInteropHelper(window).Handle, flag);
}

internal static MonitorInfo GetMonitor(POINT point, MonitorFromWindowFlags flag = MonitorFromWindowFlags.DEFAULTTONEAREST)
{
var hMonitor = MonitorFromPoint(point, flag);
return GetMonitorInfoInternal(hMonitor);
}

public static Rect GetWorkAreaDips(double left, double top)
{
if (double.IsNaN(left) || double.IsNaN(top))
{
return SystemParameters.WorkArea;
}

var monitor = GetMonitor(new POINT { X = (int)left, Y = (int)top });
if (monitor.workArea.IsEmpty)
{
return SystemParameters.WorkArea;
}

double dpiX = monitor.dpiX > 0 ? monitor.dpiX : 96.0;
double dpiY = monitor.dpiY > 0 ? monitor.dpiY : 96.0;

return new Rect(
monitor.workArea.Left * 96.0 / dpiX,
monitor.workArea.Top * 96.0 / dpiY,
monitor.workArea.Width * 96.0 / dpiX,
monitor.workArea.Height * 96.0 / dpiY);
}

public static IReadOnlyList<MonitorInfo> GetMonitors()
{
List<MonitorInfo> result = [];
Expand Down
41 changes: 41 additions & 0 deletions FluentFlyoutWPF/SettingsWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using FluentFlyout.Classes;
using FluentFlyout.Classes.Settings;
using FluentFlyoutWPF.Classes.Utils;
using FluentFlyoutWPF.Pages;
using System.Text.RegularExpressions;
using System.Windows;
Expand Down Expand Up @@ -41,6 +42,32 @@ public SettingsWindow()
InitializeComponent();
instance = this;

var settings = SettingsManager.Current;

Width = settings.SettingsWindowWidth >= MinWidth ? settings.SettingsWindowWidth : 900;
Height = settings.SettingsWindowHeight >= MinHeight ? settings.SettingsWindowHeight : 700;

if (!double.IsNaN(settings.SettingsWindowLeft) && !double.IsNaN(settings.SettingsWindowTop))
{
WindowStartupLocation = WindowStartupLocation.Manual;
var workArea = MonitorUtil.GetWorkAreaDips(settings.SettingsWindowLeft, settings.SettingsWindowTop);

Width = Math.Max(MinWidth, Math.Min(Width, workArea.Width));
Height = Math.Max(MinHeight, Math.Min(Height, workArea.Height));

Left = Math.Max(workArea.Left, Math.Min(settings.SettingsWindowLeft, workArea.Right - Width));
Top = Math.Max(workArea.Top, Math.Min(settings.SettingsWindowTop, workArea.Bottom - Height));
}
else
{
WindowStartupLocation = WindowStartupLocation.CenterScreen;
}

if (settings.SettingsWindowState == WindowState.Maximized)
{
WindowState = WindowState.Maximized;
}

Closed += (s, e) => instance = null;
DataContext = SettingsManager.Current;

Expand Down Expand Up @@ -239,8 +266,21 @@ await Dispatcher.InvokeAsync(() =>
BuildSearchItems();
}


private void SettingsWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
var settings = SettingsManager.Current;
var bounds = WindowState == WindowState.Normal ? new Rect(Left, Top, ActualWidth, ActualHeight) : RestoreBounds;

if (bounds.Width >= MinWidth && bounds.Height >= MinHeight)
{
settings.SettingsWindowWidth = bounds.Width;
settings.SettingsWindowHeight = bounds.Height;
settings.SettingsWindowLeft = bounds.Left;
settings.SettingsWindowTop = bounds.Top;
settings.SettingsWindowState = WindowState == WindowState.Maximized ? WindowState.Maximized : WindowState.Normal;
}

SettingsManager.SaveSettings();
}

Expand All @@ -264,6 +304,7 @@ private void ResetScrollPosition()
}), System.Windows.Threading.DispatcherPriority.Loaded);
}


// helper functions to traverse visual tree

private static T? FindChildByName<T>(DependencyObject parent, string name) where T : FrameworkElement
Expand Down
35 changes: 35 additions & 0 deletions FluentFlyoutWPF/ViewModels/UserSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,36 @@ .. typeof(UserSettings)
.Select(property => property.Name)
];

/// <summary>
/// Saved width of the settings window
/// </summary>
[ObservableProperty]
public partial double SettingsWindowWidth { get; set; }

/// <summary>
/// Saved height of the settings window
/// </summary>
[ObservableProperty]
public partial double SettingsWindowHeight { get; set; }

/// <summary>
/// Saved horizontal position of the settings window
/// </summary>
[ObservableProperty]
public partial double SettingsWindowLeft { get; set; }

/// <summary>
/// Saved vertical position of the settings window
/// </summary>
[ObservableProperty]
public partial double SettingsWindowTop { get; set; }

/// <summary>
/// Saved window state of the settings window
/// </summary>
[ObservableProperty]
public partial WindowState SettingsWindowState { get; set; }

/// <summary>
/// Use a compact layout
/// </summary>
Expand Down Expand Up @@ -719,6 +749,11 @@ public UserSettings()
NextUpDuration = 2000;
NIconLeftClick = 0;
CenterTitleArtist = false;
SettingsWindowWidth = 900;
SettingsWindowHeight = 700;
SettingsWindowLeft = double.NaN;
SettingsWindowTop = double.NaN;
SettingsWindowState = WindowState.Normal;
FlyoutAnimationEasingStyle = 2;
LockKeysEnabled = true;
LockKeysCapsEnabled = true;
Expand Down
Loading