diff --git a/rpcs3/main.cpp b/rpcs3/main.cpp index 38cfe9db9b..844fa4e9db 100644 --- a/rpcs3/main.cpp +++ b/rpcs3/main.cpp @@ -277,6 +277,7 @@ constexpr auto arg_commit_db = "get-commit-db"; // Arguments that can be used with a gui application constexpr auto arg_no_gui = "no-gui"; constexpr auto arg_fullscreen = "fullscreen"; // only useful with no-gui +constexpr auto arg_gs_screen = "game-screen"; constexpr auto arg_high_dpi = "hidpi"; constexpr auto arg_rounding = "dpi-rounding"; constexpr auto arg_styles = "styles"; @@ -629,6 +630,8 @@ int main(int argc, char** argv) parser.addOption(QCommandLineOption(arg_headless, "Run RPCS3 in headless mode.")); parser.addOption(QCommandLineOption(arg_no_gui, "Run RPCS3 without its GUI.")); parser.addOption(QCommandLineOption(arg_fullscreen, "Run games in fullscreen mode. Only used when no-gui is set.")); + const QCommandLineOption screen_option(arg_gs_screen, "Forces the emulator to use the specified screen for the game window.", "index", ""); + parser.addOption(screen_option); parser.addOption(QCommandLineOption(arg_high_dpi, "Enables Qt High Dpi Scaling.", "enabled", "1")); parser.addOption(QCommandLineOption(arg_rounding, "Sets the Qt::HighDpiScaleFactorRoundingPolicy for values like 150% zoom.", "rounding", "4")); parser.addOption(QCommandLineOption(arg_styles, "Lists the available styles.")); @@ -956,6 +959,18 @@ int main(int argc, char** argv) gui_app->SetStartGamesFullscreen(true); } + if (parser.isSet(arg_gs_screen)) + { + const int game_screen_index = parser.value(arg_gs_screen).toInt(); + + if (game_screen_index < 0) + { + report_fatal_error(fmt::format("The option '%s' can only be used with numbers >= 0 (you used %d)", arg_gs_screen, game_screen_index)); + } + + gui_app->SetGameScreenIndex(game_screen_index); + } + if (!gui_app->Init()) { Emu.Quit(true); diff --git a/rpcs3/rpcs3qt/gui_application.cpp b/rpcs3/rpcs3qt/gui_application.cpp index 4d1248be91..56bd944be9 100644 --- a/rpcs3/rpcs3qt/gui_application.cpp +++ b/rpcs3/rpcs3qt/gui_application.cpp @@ -288,10 +288,37 @@ std::unique_ptr gui_application::get_gs_frame() } } - const auto screen = m_main_window ? m_main_window->screen() : primaryScreen(); - const auto base_geometry = m_main_window ? m_main_window->frameGeometry() : primaryScreen()->geometry(); - const auto frame_geometry = gui::utils::create_centered_window_geometry(screen, base_geometry, w, h); - const auto app_icon = m_main_window ? m_main_window->GetAppIcon() : gui::utils::get_app_icon_from_path(Emu.GetBoot(), Emu.GetTitleID()); + QScreen* screen = nullptr; + QRect base_geometry{}; + + if (m_game_screen_index >= 0) + { + const QList available_screens = screens(); + + if (m_game_screen_index < available_screens.count()) + { + screen = ::at32(available_screens, m_game_screen_index); + + if (screen) + { + base_geometry = screen->geometry(); + } + } + + if (!screen) + { + gui_log.error("The selected game screen with index %d is not available (available screens: %d)", m_game_screen_index, available_screens.count()); + } + } + + if (!screen) + { + screen = m_main_window ? m_main_window->screen() : primaryScreen(); + 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); + 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_application.h b/rpcs3/rpcs3qt/gui_application.h index f5fca9c36e..762a8a045a 100644 --- a/rpcs3/rpcs3qt/gui_application.h +++ b/rpcs3/rpcs3qt/gui_application.h @@ -49,6 +49,11 @@ public: m_start_games_fullscreen = start_games_fullscreen; } + void SetGameScreenIndex(int screen_index = -1) + { + m_game_screen_index = screen_index; + } + /** Call this method before calling app.exec */ bool Init() override; @@ -88,6 +93,7 @@ private: bool m_use_cli_style = false; bool m_with_cli_boot = false; bool m_start_games_fullscreen = false; + int m_game_screen_index = -1; private Q_SLOTS: void OnChangeStyleSheetRequest();