From dc522a0d08e324881b5c3fe945e7f637ea1e612b Mon Sep 17 00:00:00 2001 From: Babib3l Date: Tue, 12 May 2026 12:59:22 +0200 Subject: [PATCH] Fix fullscreen monitor selection on Windows When Avalonia cannot resolve a screen from the window visual, fall back to the screen containing the window center before using the primary display. Also place the fullscreen window at the selected screen bounds instead of always using the desktop origin, preventing fullscreen from moving to the primary monitor. --- .../UI/ViewModels/MainWindowViewModel.cs | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/Ryujinx/UI/ViewModels/MainWindowViewModel.cs b/src/Ryujinx/UI/ViewModels/MainWindowViewModel.cs index ff38bb6ba..44e22f812 100644 --- a/src/Ryujinx/UI/ViewModels/MainWindowViewModel.cs +++ b/src/Ryujinx/UI/ViewModels/MainWindowViewModel.cs @@ -2060,6 +2060,20 @@ namespace Ryujinx.Ava.UI.ViewModels nint hwnd = Window.TryGetPlatformHandle()?.Handle ?? nint.Zero; if (hwnd == nint.Zero) return; + PixelPoint windowCenter = new( + Window.Position.X + (int)(Window.Bounds.Width / 2), + Window.Position.Y + (int)(Window.Bounds.Height / 2)); + + var screen = + Window.Screens.ScreenFromVisual(Window) ?? + Window.Screens.ScreenFromPoint(windowCenter) ?? + Window.Screens.Primary; + + if (screen == null) + { + return; // Can't determine screen size, don't attempt fullscreen + } + // Save current style and placement _savedWindowStyle = Win32NativeInterop.GetWindowLongPtrW(hwnd, Win32NativeInterop.GWL_STYLE); @@ -2067,19 +2081,10 @@ namespace Ryujinx.Ava.UI.ViewModels Win32NativeInterop.SetWindowLongPtrW(hwnd, Win32NativeInterop.GWL_STYLE, unchecked((nint)(Win32NativeInterop.WS_POPUP | Win32NativeInterop.WS_VISIBLE))); - Avalonia.Platform.Screen? screen = Window.Screens.ScreenFromVisual(Window); - if (screen == null) - { - screen = Window.Screens.Primary; - } - if (screen == null) - { - return; // Can't determine screen size, don't attempt fullscreen - } int w = screen.Bounds.Width; int h = screen.Bounds.Height; - Win32NativeInterop.SetWindowPos(hwnd, nint.Zero, 0, 0, w, h, + Win32NativeInterop.SetWindowPos(hwnd, nint.Zero, screen.Bounds.X, screen.Bounds.Y, w, h, Win32NativeInterop.SWP_NOZORDER | Win32NativeInterop.SWP_NOACTIVATE | Win32NativeInterop.SWP_FRAMECHANGED); WindowState = WindowState.FullScreen;