mirror of
https://github.com/Ryujinx/Ryujinx.git
synced 2025-06-28 23:50:46 -07:00
Allow window to remember its size, position and state (GTK + Avalonia) (#4657)
* Update ConfigurationState.cs * Update ConfigurationFileFormat.cs * Update MainWindow.cs * Update ConfigurationFileFormat.cs * Update ConfigurationState.cs * Update MainWindow.cs * Update MainWindow.cs * Update Ryujinx.Ui.Common/Configuration/ConfigurationState.cs Co-authored-by: gdkchan <gab.dark.100@gmail.com> * Update MainWindow.cs * Update Ryujinx/Ui/MainWindow.cs Co-authored-by: gdkchan <gab.dark.100@gmail.com> * Initial properties * Viewmodel adjustments and additions * abstract and monitor dimension changes * Remove position from ViewModel and simplify methods * Remove unused dep * Update configuration and fix typo from AA * review changes * Review changes * Screensize checks - Ava * Review changes 2 * basic review changes * Standardise GTK/Ava functions * Actually call function --------- Co-authored-by: HaizenTrist <123991082+HaizenTrist@users.noreply.github.com> Co-authored-by: gdkchan <gab.dark.100@gmail.com>
This commit is contained in:
@ -95,6 +95,9 @@ namespace Ryujinx.Ava.UI.ViewModels
|
||||
private string _currentEmulatedGamePath;
|
||||
private AutoResetEvent _rendererWaitEvent;
|
||||
private WindowState _windowState;
|
||||
private double _windowWidth;
|
||||
private double _windowHeight;
|
||||
|
||||
private bool _isActive;
|
||||
|
||||
public ApplicationData ListSelectedApplication;
|
||||
@ -622,6 +625,28 @@ namespace Ryujinx.Ava.UI.ViewModels
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public double WindowWidth
|
||||
{
|
||||
get => _windowWidth;
|
||||
set
|
||||
{
|
||||
_windowWidth = value;
|
||||
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public double WindowHeight
|
||||
{
|
||||
get => _windowHeight;
|
||||
set
|
||||
{
|
||||
_windowHeight = value;
|
||||
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsGrid => Glyph == Glyph.Grid;
|
||||
public bool IsList => Glyph == Glyph.List;
|
||||
|
@ -12,15 +12,14 @@
|
||||
Cursor="{Binding Cursor}"
|
||||
Title="{Binding Title}"
|
||||
WindowState="{Binding WindowState}"
|
||||
Width="1280"
|
||||
Height="777"
|
||||
Width="{Binding WindowWidth}"
|
||||
Height="{Binding WindowHeight}"
|
||||
MinWidth="1092"
|
||||
MinHeight="672"
|
||||
d:DesignHeight="720"
|
||||
d:DesignWidth="1280"
|
||||
x:CompileBindings="True"
|
||||
x:DataType="viewModels:MainWindowViewModel"
|
||||
WindowStartupLocation="CenterScreen"
|
||||
mc:Ignorable="d"
|
||||
Focusable="True">
|
||||
<Window.Styles>
|
||||
|
@ -62,6 +62,8 @@ namespace Ryujinx.Ava.UI.Windows
|
||||
|
||||
DataContext = ViewModel;
|
||||
|
||||
SetWindowSizePosition();
|
||||
|
||||
InitializeComponent();
|
||||
Load();
|
||||
|
||||
@ -297,6 +299,51 @@ namespace Ryujinx.Ava.UI.Windows
|
||||
LoadHotKeys();
|
||||
}
|
||||
|
||||
private void SetWindowSizePosition()
|
||||
{
|
||||
PixelPoint SavedPoint = new PixelPoint(ConfigurationState.Instance.Ui.WindowStartup.WindowPositionX,
|
||||
ConfigurationState.Instance.Ui.WindowStartup.WindowPositionY);
|
||||
|
||||
ViewModel.WindowHeight = ConfigurationState.Instance.Ui.WindowStartup.WindowSizeHeight * Program.WindowScaleFactor;
|
||||
ViewModel.WindowWidth = ConfigurationState.Instance.Ui.WindowStartup.WindowSizeWidth * Program.WindowScaleFactor;
|
||||
|
||||
ViewModel.WindowState = ConfigurationState.Instance.Ui.WindowStartup.WindowMaximized.Value is true ? WindowState.Maximized : WindowState.Normal;
|
||||
|
||||
if (CheckScreenBounds(SavedPoint))
|
||||
{
|
||||
Position = SavedPoint;
|
||||
}
|
||||
|
||||
else WindowStartupLocation = WindowStartupLocation.CenterScreen;
|
||||
}
|
||||
|
||||
private bool CheckScreenBounds(PixelPoint configPoint)
|
||||
{
|
||||
for (int i = 0; i < Screens.ScreenCount; i++)
|
||||
{
|
||||
if (Screens.All[i].Bounds.Contains(configPoint))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Logger.Warning?.Print(LogClass.Application, $"Failed to find valid start-up coordinates. Defaulting to primary monitor center.");
|
||||
return false;
|
||||
}
|
||||
|
||||
private void SaveWindowSizePosition()
|
||||
{
|
||||
ConfigurationState.Instance.Ui.WindowStartup.WindowSizeHeight.Value = (int)Height;
|
||||
ConfigurationState.Instance.Ui.WindowStartup.WindowSizeWidth.Value = (int)Width;
|
||||
|
||||
ConfigurationState.Instance.Ui.WindowStartup.WindowPositionX.Value = Position.X;
|
||||
ConfigurationState.Instance.Ui.WindowStartup.WindowPositionY.Value = Position.Y;
|
||||
|
||||
ConfigurationState.Instance.Ui.WindowStartup.WindowMaximized.Value = WindowState == WindowState.Maximized;
|
||||
|
||||
MainWindowViewModel.SaveConfig();
|
||||
}
|
||||
|
||||
protected override void OnOpened(EventArgs e)
|
||||
{
|
||||
base.OnOpened(e);
|
||||
@ -388,6 +435,8 @@ namespace Ryujinx.Ava.UI.Windows
|
||||
return;
|
||||
}
|
||||
|
||||
SaveWindowSizePosition();
|
||||
|
||||
ApplicationLibrary.CancelLoading();
|
||||
InputManager.Dispose();
|
||||
Program.Exit();
|
||||
|
Reference in New Issue
Block a user