Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qt: Remember last game window position and visibility #14713

Merged
merged 1 commit into from Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions rpcs3/rpcs3qt/gs_frame.cpp
Expand Up @@ -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.
Expand Down Expand Up @@ -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<Visibility>())
{
// 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 != Visibility::Hidden)
{
setVisibility(visibility);
}
}
});

// if we do this before show, the QWinTaskbarProgress won't show
Expand Down
27 changes: 22 additions & 5 deletions rpcs3/rpcs3qt/gui_application.cpp
Expand Up @@ -323,7 +323,9 @@ std::unique_ptr<gs_frame> 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())
{
Expand All @@ -343,11 +345,12 @@ std::unique_ptr<gs_frame> 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
Expand Down Expand Up @@ -378,7 +381,21 @@ std::unique_ptr<gs_frame> 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<QRect>();

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;
Expand Down
3 changes: 3 additions & 0 deletions rpcs3/rpcs3qt/gui_settings.h
Expand Up @@ -7,6 +7,7 @@
#include <QSize>
#include <QColor>
#include <QMessageBox>
#include <QWindow>

namespace gui
{
Expand Down Expand Up @@ -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);
Expand Down