From 430073817cf1b242896fb6813474ab55ce0388af Mon Sep 17 00:00:00 2001 From: Evan Husted Date: Thu, 17 Oct 2024 11:51:40 -0500 Subject: [PATCH] UI: Fix diaglog popups doubling the window controls and laying text over the menu bar. --- src/Ryujinx/UI/Applet/AvaHostUIHandler.cs | 6 ++--- .../Applet/AvaloniaDynamicTextInputHandler.cs | 2 +- .../UI/Applet/ErrorAppletWindow.axaml.cs | 2 +- src/Ryujinx/UI/Helpers/ContentDialogHelper.cs | 2 +- src/Ryujinx/UI/Models/SaveModel.cs | 2 +- .../UI/ViewModels/AmiiboWindowViewModel.cs | 4 +-- .../UI/ViewModels/Input/InputViewModel.cs | 16 ++++-------- .../UI/Views/Main/MainMenuBarView.axaml.cs | 15 +++++------ .../UI/Views/Main/MainStatusBarView.axaml.cs | 11 ++++---- .../UI/Views/Main/MainViewControls.axaml.cs | 5 ++-- src/Ryujinx/UI/Windows/AmiiboWindow.axaml | 4 +-- src/Ryujinx/UI/Windows/AmiiboWindow.axaml.cs | 2 +- src/Ryujinx/UI/Windows/CheatWindow.axaml | 4 +-- src/Ryujinx/UI/Windows/CheatWindow.axaml.cs | 2 +- .../Windows/ContentDialogOverlayWindow.axaml | 8 +++--- .../ContentDialogOverlayWindow.axaml.cs | 2 +- src/Ryujinx/UI/Windows/MainWindow.axaml | 4 +-- src/Ryujinx/UI/Windows/MainWindow.axaml.cs | 12 +++++---- src/Ryujinx/UI/Windows/SettingsWindow.axaml | 4 +-- .../UI/Windows/SettingsWindow.axaml.cs | 2 +- src/Ryujinx/UI/Windows/StyleableWindow.cs | 26 ++++++++++++++++++- 21 files changed, 75 insertions(+), 60 deletions(-) diff --git a/src/Ryujinx/UI/Applet/AvaHostUIHandler.cs b/src/Ryujinx/UI/Applet/AvaHostUIHandler.cs index d72f75cff..4bcf8eb94 100644 --- a/src/Ryujinx/UI/Applet/AvaHostUIHandler.cs +++ b/src/Ryujinx/UI/Applet/AvaHostUIHandler.cs @@ -122,7 +122,7 @@ namespace Ryujinx.Ava.UI.Applet { try { - MainWindow.ViewModel.AppHost.NpadManager.BlockInputUpdates(); + _parent.ViewModel.AppHost.NpadManager.BlockInputUpdates(); var response = await SwkbdAppletDialog.ShowInputDialog(LocaleManager.Instance[LocaleKeys.SoftwareKeyboard], args); if (response.Result == UserResult.Ok) @@ -144,7 +144,7 @@ namespace Ryujinx.Ava.UI.Applet }); dialogCloseEvent.WaitOne(); - MainWindow.ViewModel.AppHost.NpadManager.UnblockInputUpdates(); + _parent.ViewModel.AppHost.NpadManager.UnblockInputUpdates(); userText = error ? null : inputText; @@ -154,7 +154,7 @@ namespace Ryujinx.Ava.UI.Applet public void ExecuteProgram(Switch device, ProgramSpecifyKind kind, ulong value) { device.Configuration.UserChannelPersistence.ExecuteProgram(kind, value); - MainWindow.ViewModel.AppHost?.Stop(); + _parent.ViewModel.AppHost?.Stop(); } public bool DisplayErrorAppletDialog(string title, string message, string[] buttons) diff --git a/src/Ryujinx/UI/Applet/AvaloniaDynamicTextInputHandler.cs b/src/Ryujinx/UI/Applet/AvaloniaDynamicTextInputHandler.cs index 89bdfe748..0e7cfb8e6 100644 --- a/src/Ryujinx/UI/Applet/AvaloniaDynamicTextInputHandler.cs +++ b/src/Ryujinx/UI/Applet/AvaloniaDynamicTextInputHandler.cs @@ -129,7 +129,7 @@ namespace Ryujinx.Ava.UI.Applet Dispatcher.UIThread.Post(() => { _hiddenTextBox.Clear(); - MainWindow.ViewModel.RendererHostControl.Focus(); + _parent.ViewModel.RendererHostControl.Focus(); _parent = null; }); diff --git a/src/Ryujinx/UI/Applet/ErrorAppletWindow.axaml.cs b/src/Ryujinx/UI/Applet/ErrorAppletWindow.axaml.cs index ec6f76825..552aaaa19 100644 --- a/src/Ryujinx/UI/Applet/ErrorAppletWindow.axaml.cs +++ b/src/Ryujinx/UI/Applet/ErrorAppletWindow.axaml.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace Ryujinx.Ava.UI.Applet { - internal partial class ErrorAppletWindow : StyleableWindow + internal partial class ErrorAppletWindow : StyleableAppWindow { private readonly Window _owner; private object _buttonResponse; diff --git a/src/Ryujinx/UI/Helpers/ContentDialogHelper.cs b/src/Ryujinx/UI/Helpers/ContentDialogHelper.cs index 28f4c0e98..e1634e62a 100644 --- a/src/Ryujinx/UI/Helpers/ContentDialogHelper.cs +++ b/src/Ryujinx/UI/Helpers/ContentDialogHelper.cs @@ -85,7 +85,7 @@ namespace Ryujinx.Ava.UI.Helpers } public static Task ShowDeferredContentDialog( - StyleableWindow window, + Window window, string title, string primaryText, string secondaryText, diff --git a/src/Ryujinx/UI/Models/SaveModel.cs b/src/Ryujinx/UI/Models/SaveModel.cs index 86608a1c0..cfc397c6e 100644 --- a/src/Ryujinx/UI/Models/SaveModel.cs +++ b/src/Ryujinx/UI/Models/SaveModel.cs @@ -47,7 +47,7 @@ namespace Ryujinx.Ava.UI.Models TitleId = info.ProgramId; UserId = info.UserId; - var appData = MainWindow.ViewModel.Applications.FirstOrDefault(x => x.IdString.Equals(TitleIdString, StringComparison.OrdinalIgnoreCase)); + var appData = MainWindow.MainWindowViewModel.Applications.FirstOrDefault(x => x.IdString.Equals(TitleIdString, StringComparison.OrdinalIgnoreCase)); InGameList = appData != null; diff --git a/src/Ryujinx/UI/ViewModels/AmiiboWindowViewModel.cs b/src/Ryujinx/UI/ViewModels/AmiiboWindowViewModel.cs index 76d8a9c61..9591ebeb7 100644 --- a/src/Ryujinx/UI/ViewModels/AmiiboWindowViewModel.cs +++ b/src/Ryujinx/UI/ViewModels/AmiiboWindowViewModel.cs @@ -33,7 +33,7 @@ namespace Ryujinx.Ava.UI.ViewModels private readonly string _amiiboJsonPath; private readonly byte[] _amiiboLogoBytes; private readonly HttpClient _httpClient; - private readonly StyleableWindow _owner; + private readonly StyleableAppWindow _owner; private Bitmap _amiiboImage; private List _amiiboList; @@ -49,7 +49,7 @@ namespace Ryujinx.Ava.UI.ViewModels private static readonly AmiiboJsonSerializerContext _serializerContext = new(JsonHelper.GetDefaultSerializerOptions()); - public AmiiboWindowViewModel(StyleableWindow owner, string lastScannedAmiiboId, string titleId) + public AmiiboWindowViewModel(StyleableAppWindow owner, string lastScannedAmiiboId, string titleId) { _owner = owner; diff --git a/src/Ryujinx/UI/ViewModels/Input/InputViewModel.cs b/src/Ryujinx/UI/ViewModels/Input/InputViewModel.cs index d1c29f15d..40acb7676 100644 --- a/src/Ryujinx/UI/ViewModels/Input/InputViewModel.cs +++ b/src/Ryujinx/UI/ViewModels/Input/InputViewModel.cs @@ -244,7 +244,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input _mainWindow.InputManager.GamepadDriver.OnGamepadConnected += HandleOnGamepadConnected; _mainWindow.InputManager.GamepadDriver.OnGamepadDisconnected += HandleOnGamepadDisconnected; - MainWindow.ViewModel.AppHost?.NpadManager.BlockInputUpdates(); + _mainWindow.ViewModel.AppHost?.NpadManager.BlockInputUpdates(); _isLoaded = false; @@ -357,18 +357,12 @@ namespace Ryujinx.Ava.UI.ViewModels.Input private void HandleOnGamepadDisconnected(string id) { - Dispatcher.UIThread.Post(() => - { - LoadDevices(); - }); + Dispatcher.UIThread.Post(LoadDevices); } private void HandleOnGamepadConnected(string id) { - Dispatcher.UIThread.Post(() => - { - LoadDevices(); - }); + Dispatcher.UIThread.Post(LoadDevices); } private string GetCurrentGamepadId() @@ -847,7 +841,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input } } - MainWindow.ViewModel.AppHost?.NpadManager.ReloadConfiguration(newConfig, ConfigurationState.Instance.Hid.EnableKeyboard, ConfigurationState.Instance.Hid.EnableMouse); + _mainWindow.ViewModel.AppHost?.NpadManager.ReloadConfiguration(newConfig, ConfigurationState.Instance.Hid.EnableKeyboard, ConfigurationState.Instance.Hid.EnableMouse); // Atomically replace and signal input change. // NOTE: Do not modify InputConfig.Value directly as other code depends on the on-change event. @@ -879,7 +873,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input _mainWindow.InputManager.GamepadDriver.OnGamepadConnected -= HandleOnGamepadConnected; _mainWindow.InputManager.GamepadDriver.OnGamepadDisconnected -= HandleOnGamepadDisconnected; - MainWindow.ViewModel.AppHost?.NpadManager.UnblockInputUpdates(); + _mainWindow.ViewModel.AppHost?.NpadManager.UnblockInputUpdates(); SelectedGamepad?.Dispose(); diff --git a/src/Ryujinx/UI/Views/Main/MainMenuBarView.axaml.cs b/src/Ryujinx/UI/Views/Main/MainMenuBarView.axaml.cs index f6fe253a5..5a64c502b 100644 --- a/src/Ryujinx/UI/Views/Main/MainMenuBarView.axaml.cs +++ b/src/Ryujinx/UI/Views/Main/MainMenuBarView.axaml.cs @@ -95,26 +95,23 @@ namespace Ryujinx.Ava.UI.Views.Main if (VisualRoot is MainWindow window) { - Window = window; + DataContext = ViewModel = window.ViewModel; } - - ViewModel = MainWindow.ViewModel; - DataContext = ViewModel; } private async void StopEmulation_Click(object sender, RoutedEventArgs e) { - await MainWindow.ViewModel.AppHost?.ShowExitPrompt().OrCompleted()!; + await ViewModel.AppHost?.ShowExitPrompt().OrCompleted()!; } private void PauseEmulation_Click(object sender, RoutedEventArgs e) { - MainWindow.ViewModel.AppHost?.Pause(); + ViewModel.AppHost?.Pause(); } private void ResumeEmulation_Click(object sender, RoutedEventArgs e) { - MainWindow.ViewModel.AppHost?.Resume(); + ViewModel.AppHost?.Resume(); } public async void OpenSettings(object sender, RoutedEventArgs e) @@ -178,7 +175,7 @@ namespace Ryujinx.Ava.UI.Views.Main Window.VirtualFileSystem, ViewModel.AppHost.Device.Processes.ActiveApplication.ProgramIdText, name, - MainWindow.ViewModel.SelectedApplication.Path).ShowDialog(Window); + ViewModel.SelectedApplication.Path).ShowDialog(Window); ViewModel.AppHost.Device.EnableCheats(); } @@ -186,7 +183,7 @@ namespace Ryujinx.Ava.UI.Views.Main private void ScanAmiiboMenuItem_AttachedToVisualTree(object sender, VisualTreeAttachmentEventArgs e) { if (sender is MenuItem) - ViewModel.IsAmiiboRequested = MainWindow.ViewModel.AppHost.Device.System.SearchingForAmiibo(out _); + ViewModel.IsAmiiboRequested = ViewModel.AppHost.Device.System.SearchingForAmiibo(out _); } private async void InstallFileTypes_Click(object sender, RoutedEventArgs e) diff --git a/src/Ryujinx/UI/Views/Main/MainStatusBarView.axaml.cs b/src/Ryujinx/UI/Views/Main/MainStatusBarView.axaml.cs index 39b00ea33..98024b49a 100644 --- a/src/Ryujinx/UI/Views/Main/MainStatusBarView.axaml.cs +++ b/src/Ryujinx/UI/Views/Main/MainStatusBarView.axaml.cs @@ -26,16 +26,15 @@ namespace Ryujinx.Ava.UI.Views.Main if (VisualRoot is MainWindow window) { Window = window; + DataContext = window.ViewModel; } - - DataContext = MainWindow.ViewModel; } private void VsyncStatus_PointerReleased(object sender, PointerReleasedEventArgs e) { - MainWindow.ViewModel.AppHost.ToggleVSync(); + Window.ViewModel.AppHost.ToggleVSync(); - Logger.Info?.Print(LogClass.Application, $"VSync toggled to: {MainWindow.ViewModel.AppHost.Device.EnableDeviceVsync}"); + Logger.Info?.Print(LogClass.Application, $"VSync toggled to: {Window.ViewModel.AppHost.Device.EnableDeviceVsync}"); } private void DockedStatus_PointerReleased(object sender, PointerReleasedEventArgs e) @@ -57,9 +56,9 @@ namespace Ryujinx.Ava.UI.Views.Main private void VolumeStatus_OnPointerWheelChanged(object sender, PointerWheelEventArgs e) { // Change the volume by 5% at a time - float newValue = MainWindow.ViewModel.Volume + (float)e.Delta.Y * 0.05f; + float newValue = Window.ViewModel.Volume + (float)e.Delta.Y * 0.05f; - MainWindow.ViewModel.Volume = newValue switch + Window.ViewModel.Volume = newValue switch { < 0 => 0, > 1 => 1, diff --git a/src/Ryujinx/UI/Views/Main/MainViewControls.axaml.cs b/src/Ryujinx/UI/Views/Main/MainViewControls.axaml.cs index 3e9931648..d5f7fbd1c 100644 --- a/src/Ryujinx/UI/Views/Main/MainViewControls.axaml.cs +++ b/src/Ryujinx/UI/Views/Main/MainViewControls.axaml.cs @@ -22,12 +22,11 @@ namespace Ryujinx.Ava.UI.Views.Main { base.OnAttachedToVisualTree(e); - if (VisualRoot is MainWindow) + if (VisualRoot is MainWindow window) { - ViewModel = MainWindow.ViewModel; + DataContext = ViewModel = window.ViewModel; } - DataContext = ViewModel; } public void Sort_Checked(object sender, RoutedEventArgs args) diff --git a/src/Ryujinx/UI/Windows/AmiiboWindow.axaml b/src/Ryujinx/UI/Windows/AmiiboWindow.axaml index c587aa873..973019d89 100644 --- a/src/Ryujinx/UI/Windows/AmiiboWindow.axaml +++ b/src/Ryujinx/UI/Windows/AmiiboWindow.axaml @@ -1,4 +1,4 @@ - - + diff --git a/src/Ryujinx/UI/Windows/AmiiboWindow.axaml.cs b/src/Ryujinx/UI/Windows/AmiiboWindow.axaml.cs index af14ddb96..a2a087311 100644 --- a/src/Ryujinx/UI/Windows/AmiiboWindow.axaml.cs +++ b/src/Ryujinx/UI/Windows/AmiiboWindow.axaml.cs @@ -5,7 +5,7 @@ using Ryujinx.UI.Common.Models.Amiibo; namespace Ryujinx.Ava.UI.Windows { - public partial class AmiiboWindow : StyleableWindow + public partial class AmiiboWindow : StyleableAppWindow { public AmiiboWindow(bool showAll, string lastScannedAmiiboId, string titleId) { diff --git a/src/Ryujinx/UI/Windows/CheatWindow.axaml b/src/Ryujinx/UI/Windows/CheatWindow.axaml index 57d5f7eff..716090c1c 100644 --- a/src/Ryujinx/UI/Windows/CheatWindow.axaml +++ b/src/Ryujinx/UI/Windows/CheatWindow.axaml @@ -1,4 +1,4 @@ - - + diff --git a/src/Ryujinx/UI/Windows/CheatWindow.axaml.cs b/src/Ryujinx/UI/Windows/CheatWindow.axaml.cs index 0a02e5f01..58b0ab587 100644 --- a/src/Ryujinx/UI/Windows/CheatWindow.axaml.cs +++ b/src/Ryujinx/UI/Windows/CheatWindow.axaml.cs @@ -14,7 +14,7 @@ using System.Linq; namespace Ryujinx.Ava.UI.Windows { - public partial class CheatWindow : StyleableWindow + public partial class CheatWindow : StyleableAppWindow { private readonly string _enabledCheatsPath; public bool NoCheatsFound { get; } diff --git a/src/Ryujinx/UI/Windows/ContentDialogOverlayWindow.axaml b/src/Ryujinx/UI/Windows/ContentDialogOverlayWindow.axaml index 8b52baded..d56dd2a0d 100644 --- a/src/Ryujinx/UI/Windows/ContentDialogOverlayWindow.axaml +++ b/src/Ryujinx/UI/Windows/ContentDialogOverlayWindow.axaml @@ -1,4 +1,4 @@ - - + - + - + diff --git a/src/Ryujinx/UI/Windows/ContentDialogOverlayWindow.axaml.cs b/src/Ryujinx/UI/Windows/ContentDialogOverlayWindow.axaml.cs index 0e2410247..c5f6b15eb 100644 --- a/src/Ryujinx/UI/Windows/ContentDialogOverlayWindow.axaml.cs +++ b/src/Ryujinx/UI/Windows/ContentDialogOverlayWindow.axaml.cs @@ -9,7 +9,7 @@ namespace Ryujinx.Ava.UI.Windows { InitializeComponent(); - TransparencyLevelHint = new[] { WindowTransparencyLevel.Transparent }; + TransparencyLevelHint = [WindowTransparencyLevel.Transparent]; WindowStartupLocation = WindowStartupLocation.Manual; SystemDecorations = SystemDecorations.None; ExtendClientAreaTitleBarHeightHint = 0; diff --git a/src/Ryujinx/UI/Windows/MainWindow.axaml b/src/Ryujinx/UI/Windows/MainWindow.axaml index 3a2e02c26..c60c68327 100644 --- a/src/Ryujinx/UI/Windows/MainWindow.axaml +++ b/src/Ryujinx/UI/Windows/MainWindow.axaml @@ -1,4 +1,4 @@ - - + diff --git a/src/Ryujinx/UI/Windows/MainWindow.axaml.cs b/src/Ryujinx/UI/Windows/MainWindow.axaml.cs index f151e69af..b299912b3 100644 --- a/src/Ryujinx/UI/Windows/MainWindow.axaml.cs +++ b/src/Ryujinx/UI/Windows/MainWindow.axaml.cs @@ -35,9 +35,11 @@ using System.Threading.Tasks; namespace Ryujinx.Ava.UI.Windows { - public partial class MainWindow : StyleableWindow + public partial class MainWindow : StyleableAppWindow { - internal static MainWindowViewModel ViewModel { get; private set; } + internal static MainWindowViewModel MainWindowViewModel { get; private set; } + + public MainWindowViewModel ViewModel { get; } internal readonly AvaHostUIHandler UiHandler; @@ -69,7 +71,7 @@ namespace Ryujinx.Ava.UI.Windows public MainWindow() { - DataContext = ViewModel = new MainWindowViewModel(); + DataContext = ViewModel = MainWindowViewModel = new MainWindowViewModel(); InitializeComponent(); Load(); @@ -78,8 +80,8 @@ namespace Ryujinx.Ava.UI.Windows ViewModel.Title = App.FormatTitle(); - TitleBar.ExtendsContentIntoTitleBar = true; - TitleBar.TitleBarHitTestType = TitleBarHitTestType.Complex; + //TitleBar.ExtendsContentIntoTitleBar = true; + //TitleBar.TitleBarHitTestType = TitleBarHitTestType.Complex; // NOTE: Height of MenuBar and StatusBar is not usable here, since it would still be 0 at this point. diff --git a/src/Ryujinx/UI/Windows/SettingsWindow.axaml b/src/Ryujinx/UI/Windows/SettingsWindow.axaml index de3c2291a..d2e0048ed 100644 --- a/src/Ryujinx/UI/Windows/SettingsWindow.axaml +++ b/src/Ryujinx/UI/Windows/SettingsWindow.axaml @@ -1,4 +1,4 @@ - - + diff --git a/src/Ryujinx/UI/Windows/SettingsWindow.axaml.cs b/src/Ryujinx/UI/Windows/SettingsWindow.axaml.cs index 2fe1bd19c..2a6835078 100644 --- a/src/Ryujinx/UI/Windows/SettingsWindow.axaml.cs +++ b/src/Ryujinx/UI/Windows/SettingsWindow.axaml.cs @@ -8,7 +8,7 @@ using System; namespace Ryujinx.Ava.UI.Windows { - public partial class SettingsWindow : StyleableWindow + public partial class SettingsWindow : StyleableAppWindow { internal SettingsViewModel ViewModel { get; set; } diff --git a/src/Ryujinx/UI/Windows/StyleableWindow.cs b/src/Ryujinx/UI/Windows/StyleableWindow.cs index b62af9824..bc6e53cb0 100644 --- a/src/Ryujinx/UI/Windows/StyleableWindow.cs +++ b/src/Ryujinx/UI/Windows/StyleableWindow.cs @@ -11,7 +11,31 @@ using System.Reflection; namespace Ryujinx.Ava.UI.Windows { - public class StyleableWindow : AppWindow + public class StyleableAppWindow : AppWindow + { + public StyleableAppWindow() + { + WindowStartupLocation = WindowStartupLocation.CenterOwner; + TransparencyLevelHint = [WindowTransparencyLevel.None]; + + LocaleManager.Instance.LocaleChanged += LocaleChanged; + LocaleChanged(); + } + + private void LocaleChanged() + { + FlowDirection = LocaleManager.Instance.IsRTL() ? FlowDirection.RightToLeft : FlowDirection.LeftToRight; + } + + protected override void OnApplyTemplate(TemplateAppliedEventArgs e) + { + base.OnApplyTemplate(e); + + ExtendClientAreaChromeHints = ExtendClientAreaChromeHints.SystemChrome | ExtendClientAreaChromeHints.OSXThickTitleBar; + } + } + + public class StyleableWindow : Window { public StyleableWindow() {