From 982e09a4864a72b26eca86af8cbbb011ad4fcee1 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Fri, 6 Oct 2023 00:26:54 +0200 Subject: [PATCH] Qt: Remember last game window position and visibility - Remembers the last game window geometry and tries to apply it on boot - Remembers the last minimized/maximized/windowed/fullscreen state and tries to apply it on boot - All existing game window settings keep priority - Should work with multi-monitor setups as well - Ignored if the user forced a different screen with cli commands --- rpcs3/rpcs3qt/gs_frame.cpp | 15 +++++++++++++++ rpcs3/rpcs3qt/gui_application.cpp | 27 ++++++++++++++++++++++----- rpcs3/rpcs3qt/gui_settings.h | 3 +++ 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/rpcs3/rpcs3qt/gs_frame.cpp b/rpcs3/rpcs3qt/gs_frame.cpp index c0c4b60a6d..f14213cb52 100644 --- a/rpcs3/rpcs3qt/gs_frame.cpp +++ b/rpcs3/rpcs3qt/gs_frame.cpp @@ -579,6 +579,12 @@ bool gs_frame::get_mouse_lock_state() void gs_frame::hide_on_close() { + // Make sure not to save the hidden state, which is useless to us. + const Visibility current_visibility = visibility(); + m_gui_settings->SetValue(gui::gs_visibility, current_visibility == Visibility::Hidden ? Visibility::AutomaticVisibility : current_visibility); + m_gui_settings->SetValue(gui::gs_geometry, geometry()); + m_gui_settings->sync(); + if (!g_progr.load()) { // Hide the dialog before stopping if no progress bar is being shown. @@ -630,10 +636,19 @@ void gs_frame::show() Emu.CallFromMainThread([this]() { QWindow::show(); + if (g_cfg.misc.start_fullscreen || m_start_games_fullscreen) { setVisibility(FullScreen); } + else if (const QVariant var = m_gui_settings->GetValue(gui::gs_visibility); var.canConvert()) + { + // Restore saved visibility from last time. Make sure not to hide the window, or the user can't access it anymore. + if (const Visibility visibility = var.value(); visibility != Visibility::Hidden) + { + setVisibility(visibility); + } + } }); // if we do this before show, the QWinTaskbarProgress won't show diff --git a/rpcs3/rpcs3qt/gui_application.cpp b/rpcs3/rpcs3qt/gui_application.cpp index 6604f1ad99..cb07672173 100644 --- a/rpcs3/rpcs3qt/gui_application.cpp +++ b/rpcs3/rpcs3qt/gui_application.cpp @@ -323,7 +323,9 @@ std::unique_ptr gui_application::get_gs_frame() auto [w, h] = ::at32(g_video_out_resolution_map, g_cfg.video.resolution); - if (m_gui_settings->GetValue(gui::gs_resize).toBool()) + const bool resize_game_window = m_gui_settings->GetValue(gui::gs_resize).toBool(); + + if (resize_game_window) { if (m_gui_settings->GetValue(gui::gs_resize_manual).toBool()) { @@ -343,11 +345,12 @@ std::unique_ptr gui_application::get_gs_frame() // Use screen index set by CLI argument int screen_index = m_game_screen_index; + const int last_screen_index = m_gui_settings->GetValue(gui::gs_screen).toInt(); - // In no-gui mode: use last used screen if no CLI index was set - if (screen_index < 0 && !m_main_window) + // Use last used screen if no CLI index was set + if (screen_index < 0) { - screen_index = m_gui_settings->GetValue(gui::gs_screen).toInt(); + screen_index = last_screen_index; } // Try to find the specified screen @@ -378,7 +381,21 @@ std::unique_ptr gui_application::get_gs_frame() base_geometry = m_main_window ? m_main_window->frameGeometry() : primaryScreen()->geometry(); } - const QRect frame_geometry = gui::utils::create_centered_window_geometry(screen, base_geometry, w, h); + // Use saved geometry if possible. Ignore this if the last used screen is different than the requested screen. + QRect frame_geometry = screen_index != last_screen_index ? QRect{} : m_gui_settings->GetValue(gui::gs_geometry).value(); + + if (frame_geometry.isNull() || frame_geometry.isEmpty()) + { + // Center above main window or inside screen if the saved geometry is invalid + frame_geometry = gui::utils::create_centered_window_geometry(screen, base_geometry, w, h); + } + else if (resize_game_window) + { + // Apply size override to our saved geometry if needed + frame_geometry.setSize(QSize(w, h)); + } + + // Load AppIcon const QIcon app_icon = m_main_window ? m_main_window->GetAppIcon() : gui::utils::get_app_icon_from_path(Emu.GetBoot(), Emu.GetTitleID()); gs_frame* frame = nullptr; diff --git a/rpcs3/rpcs3qt/gui_settings.h b/rpcs3/rpcs3qt/gui_settings.h index 1ff437790b..8496f507e1 100644 --- a/rpcs3/rpcs3qt/gui_settings.h +++ b/rpcs3/rpcs3qt/gui_settings.h @@ -7,6 +7,7 @@ #include #include #include +#include namespace gui { @@ -226,6 +227,8 @@ namespace gui const gui_save gs_height = gui_save(gs_frame, "height", 720); const gui_save gs_hideMouseIdle = gui_save(gs_frame, "hideMouseOnIdle", false); const gui_save gs_hideMouseIdleTime = gui_save(gs_frame, "hideMouseOnIdleTime", 2000); + const gui_save gs_geometry = gui_save(gs_frame, "geometry", QRect()); + const gui_save gs_visibility = gui_save(gs_frame, "visibility", QWindow::Visibility::AutomaticVisibility); const gui_save tr_icon_color = gui_save(trophy, "icon_color", gl_icon_color); const gui_save tr_icon_height = gui_save(trophy, "icon_height", 75);