Removed MainWindowBindPositionBehavior
DELETE
WalletWasabi.Fluent/Behaviors/MainWindowPersistPositionBehavior.cs
-using Avalonia;
-using Avalonia.Controls;
-using ReactiveUI;
-using System.Reactive.Disposables;
-using System.Reactive.Linq;
-using WalletWasabi.Fluent.ViewModels;
-using System.Linq;
-
-namespace WalletWasabi.Fluent.Behaviors;
-
-public class MainWindowBindPositionBehavior : DisposingBehavior<Window>
-{
- protected override void OnAttached(CompositeDisposable disposables)
- {
- if (AssociatedObject is null)
- {
- return;
- }
-
- Observable.FromEventPattern(AssociatedObject, nameof(Window.DataContextChanged))
- .Subscribe(_ => BindPosition(disposables))
- .DisposeWith(disposables);
- }
-
- private void BindPosition(CompositeDisposable disposables)
- {
- if (AssociatedObject?.DataContext is MainViewModel vm)
- {
- Observable.FromEventPattern(AssociatedObject, nameof(Window.PositionChanged))
- .Subscribe(_ => vm.WindowPosition = AssociatedObject.Position)
- .DisposeWith(disposables);
-
- vm.WhenAnyValue(x => x.WindowPosition)
- .WhereNotNull()
- .Subscribe(x => AssociatedObject.Position = x!.Value)
- .DisposeWith(disposables);
-
- SetInitialPosition(vm);
- }
- }
-
- private void SetInitialPosition(MainViewModel vm)
- {
- if (vm.WindowState != WindowState.Normal)
- {
- return;
- }
-
- var centerX = (int)((AssociatedObject!.Screens.Primary.WorkingArea.Width - vm.WindowWidth) / 2);
- var centerY = (int)((AssociatedObject.Screens.Primary.WorkingArea.Height - vm.WindowHeight) / 2);
-
- var position =
- vm.WindowPosition
- ??= new PixelPoint(centerX, centerY);
-
- var isValidLeft =
- AssociatedObject.Screens.All.Any(s => s.Bounds.X <= position.X);
-
- var isValidRight =
- AssociatedObject.Screens.All.Any(s => s.Bounds.Right >= position.X);
-
- var isValidTop =
- AssociatedObject.Screens.All.Any(s => s.Bounds.TopLeft.Y <= position.Y);
-
- var isValidBottom =
- AssociatedObject.Screens.All.Any(s => s.Bounds.BottomRight.Y >= position.Y);
-
- var x =
- isValidLeft && isValidRight
- ? position.X
- : centerX;
-
- var y =
- isValidTop && isValidBottom
- ? position.Y
- : centerY;
-
- AssociatedObject.Position = new PixelPoint(x, y);
-
- var currentScreen = AssociatedObject.Screens.ScreenFromPoint(AssociatedObject.Position);
-
- var isValidWidth =
- currentScreen is { } && vm.WindowWidth * currentScreen.PixelDensity <= currentScreen.WorkingArea.Width * currentScreen.PixelDensity;
-
- var isValidHeight =
- currentScreen is { } && vm.WindowHeight * currentScreen.PixelDensity <= currentScreen.WorkingArea.Height;
-
- if (!isValidWidth || !isValidHeight)
- {
- vm.WindowState = WindowState.Maximized;
- AssociatedObject.Position = PixelPoint.Origin;
- currentScreen = AssociatedObject.Screens.ScreenFromPoint(AssociatedObject.Position);
-
- if (currentScreen is { })
- {
- vm.WindowHeight = currentScreen.WorkingArea.Height;
- vm.WindowWidth = currentScreen.WorkingArea.Width;
- }
- }
- }
-}

MODIFY
WalletWasabi.Fluent/UiConfig.cs
WalletWasabi.Fluent/UiConfig.cs
@@ -18,10 +18,6 @@ public class UiConfig : ConfigBase
private bool _darkModeEnabled;
private string? _lastSelectedWallet;
private string _windowState = "Normal";
- private int? _windowX;
- private int? _windowY;
- private double? _windowWidth;
- private double? _windowHeight;
private bool _runOnSystemStartup;
private bool _oobe;
private bool _hideOnClose;
@@ -59,18 +55,6 @@ public class UiConfig : ConfigBase
.Skip(1) // Won't save on UiConfig creation.
.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe(_ => ToFile());
-
- this.WhenAnyValue(
- x => x.WindowState,
- x => x.WindowX,
- x => x.WindowY,
- x => x.WindowWidth,
- x => x.WindowHeight,
- (_, _, _, _, _) => Unit.Default)
- .Throttle(TimeSpan.FromMilliseconds(750))
- .Skip(1) // Won't save on UiConfig creation.
- .ObserveOn(RxApp.MainThreadScheduler)
- .Subscribe(_ => ToFile());
}
[JsonProperty(PropertyName = "Oobe", DefaultValueHandling = DefaultValueHandling.Populate)]
@@ -89,34 +73,6 @@ public class UiConfig : ConfigBase
internal set => RaiseAndSetIfChanged(ref _windowState, value);
}
- [JsonProperty(PropertyName = "WindowX")]
- public int? WindowX
- {
- get => _windowX;
- internal set => RaiseAndSetIfChanged(ref _windowX, value);
- }
-
- [JsonProperty(PropertyName = "WindowY")]
- public int? WindowY
- {
- get => _windowY;
- internal set => RaiseAndSetIfChanged(ref _windowY, value);
- }
-
- [JsonProperty(PropertyName = "WindowWidth")]
- public double? WindowWidth
- {
- get => _windowWidth;
- internal set => RaiseAndSetIfChanged(ref _windowWidth, value);
- }
-
- [JsonProperty(PropertyName = "WindowHeight")]
- public double? WindowHeight
- {
- get => _windowHeight;
- internal set => RaiseAndSetIfChanged(ref _windowHeight, value);
- }
-
[DefaultValue(2)]
[JsonProperty(PropertyName = "FeeTarget", DefaultValueHandling = DefaultValueHandling.Populate)]
public int FeeTarget

MODIFY
WalletWasabi.Fluent/ViewModels/MainViewModel.cs
WalletWasabi.Fluent/ViewModels/MainViewModel.cs
@@ -38,21 +38,10 @@ public partial class MainViewModel : ViewModelBase
[AutoNotify] private WindowState _windowState;
[AutoNotify] private bool _isOobeBackgroundVisible;
[AutoNotify] private bool _isCoinJoinActive;
- [AutoNotify] private double _windowWidth;
- [AutoNotify] private double _windowHeight;
- [AutoNotify] private PixelPoint? _windowPosition;
public MainViewModel()
{
_windowState = (WindowState)Enum.Parse(typeof(WindowState), Services.UiConfig.WindowState);
- _windowWidth = Services.UiConfig.WindowWidth ?? 1280;
- _windowHeight = Services.UiConfig.WindowHeight ?? 960;
-
- var (x, y) = (Services.UiConfig.WindowX, Services.UiConfig.WindowY);
- if (x != null && y != null)
- {
- _windowPosition = new PixelPoint(x.Value, y.Value);
- }
_dialogScreen = new DialogScreenViewModel();
@@ -84,23 +73,11 @@ public partial class MainViewModel : ViewModelBase
RxApp.MainThreadScheduler.Schedule(async () => await _navBar.InitialiseAsync());
- this.WhenAnyValue(x => x.WindowState, x => x.WindowPosition, x => x.WindowWidth, x => x.WindowHeight)
- .Where(x => x.Item1 != WindowState.Minimized)
- .Where(x => x.Item2 != new PixelPoint(-32000, -32000)) // value when minimized
+ this.WhenAnyValue(x => x.WindowState)
.ObserveOn(RxApp.MainThreadScheduler)
- .Subscribe(t =>
+ .Subscribe(state =>
{
- var (state, position, width, height) = t;
-
Services.UiConfig.WindowState = state.ToString();
- if (position is { })
- {
- Services.UiConfig.WindowX = position.Value.X;
- Services.UiConfig.WindowY = position.Value.Y;
- }
-
- Services.UiConfig.WindowWidth = width;
- Services.UiConfig.WindowHeight = height;
switch (state)
{

MODIFY
WalletWasabi.Fluent/Views/MainWindow.axaml
WalletWasabi.Fluent/Views/MainWindow.axaml
x:Name="MainWindow"
x:CompileBindings="True"
MinWidth="720" MinHeight="480"
- Width="{Binding WindowWidth, Mode=TwoWay}"
- Height="{Binding WindowHeight, Mode=TwoWay}"
- WindowStartupLocation="Manual"
+ WindowStartupLocation="CenterScreen"
Background="{x:Null}"
TransparencyLevelHint="AcrylicBlur"
ExtendClientAreaTitleBarHeightHint="50"
<i:Interaction.Behaviors>
<behaviors:RegisterNotificationHostBehavior />
<behaviors:ShowWalletCoinsOnKeyCombinationBehavior Key1="LeftCtrl" Key2="D" Key3="C" />
- <behaviors:MainWindowBindPositionBehavior />
</i:Interaction.Behaviors>
<Panel Margin="{Binding #MainWindow.OffScreenMargin}">

Removed MainWindowBindPositionBehavior