From e24f93827c4c8876f3ad82d359bd388868424658 Mon Sep 17 00:00:00 2001 From: Josef Nemec Date: Fri, 5 May 2023 09:35:16 +0200 Subject: [PATCH] Fix: Desktop mode window state issues introduced with 10.15 update --- source/Playnite/Windows/WindowFactory.cs | 51 ++++++++++++++++-------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/source/Playnite/Windows/WindowFactory.cs b/source/Playnite/Windows/WindowFactory.cs index 65c1de47e..9e6135719 100644 --- a/source/Playnite/Windows/WindowFactory.cs +++ b/source/Playnite/Windows/WindowFactory.cs @@ -188,28 +188,45 @@ public static class WindowUtils public static void RestoreWindow(this Window window) { + // This is the only reliable method that also doesn't result in issues like this: + // https://www.reddit.com/r/playnite/comments/f6d73l/bug_full_screen_ui_wont_respond_to_left_stick/ + // Adapted from https://ask.xiaolee.net/questions/1040342 + try { - // This is the only reliable method that also doesn't result in issues like this: - // https://www.reddit.com/r/playnite/comments/f6d73l/bug_full_screen_ui_wont_respond_to_left_stick/ - // Adapted from https://ask.xiaolee.net/questions/1040342 - - // Show() call is needed when restoring from minimized state otherwise restored window will - // not render properly for some reason (will display just black). - // BUT we can't call it always otherwise it will bug out restore if atl-tabbing was - // used in the past for switching windows, see next comment... - if (window.WindowState == WindowState.Minimized || window.Visibility != Visibility.Visible) + if (PlayniteApplication.Current?.Mode == ApplicationMode.Fullscreen) { - window.Show(); - } + // Show() call is needed when restoring from minimized state otherwise restored window will + // not render properly for some reason (will display just black). + // BUT we can't call it always otherwise it will bug out restore if atl-tabbing was + // used in the past for switching windows, see next comment... + if (window.WindowState == WindowState.Minimized || window.Visibility != Visibility.Visible) + { + window.Show(); + } - // This needs to be set always otherwise restore will not work if user alt-tabbed out of Playnite. - // Yeah apparently switching windows is something Windows can't do reliably in 2023... - window.WindowState = WindowState.Normal; - if (!window.Activate()) + // This needs to be set always otherwise restore will not work if user alt-tabbed out of Playnite. + // Yeah apparently switching windows is something Windows can't do reliably in 2023... + window.WindowState = WindowState.Normal; + if (!window.Activate()) + { + window.Topmost = true; + window.Topmost = false; + } + } + else { - window.Topmost = true; - window.Topmost = false; + window.Show(); + if (!window.Activate()) + { + window.Topmost = true; + window.Topmost = false; + } + + if (window.WindowState == WindowState.Minimized) + { + window.WindowState = WindowState.Normal; + } } //Get the process ID for this window's thread