-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Qt: Add display monitor selector #14196
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
Open
jasaaved
wants to merge
5
commits into
PCSX2:master
Choose a base branch
from
jasaaved:Multiple-Displays
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+90
−8
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
078b2c2
Qt: Add display monitor selector
jasaaved 5310c9a
Qt: Restore main window position
jasaaved 771078a
Misc: Merge branch 'PCSX2:master' into Multiple-Displays
jasaaved 93364e2
Qt: Remove recentering if main already at target
jasaaved ddacf90
Qt: use restoreDisplayWindowsGeometryfromConfig
jasaaved File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2549,6 +2549,9 @@ void MainWindow::createDisplayWidget(bool fullscreen, bool render_to_main) | |
| } | ||
|
|
||
| m_display_surface = new DisplaySurface(); | ||
| const int monitor_index = Host::GetBaseIntSettingValue("UI", "DisplayMonitor", 0); | ||
| const QList<QScreen*> screens = QGuiApplication::screens(); | ||
| QScreen* target_screen = (monitor_index > 0 && monitor_index <= screens.size()) ? screens[monitor_index - 1] : QGuiApplication::primaryScreen(); | ||
| if (fullscreen || !render_to_main) | ||
| { | ||
| #ifdef DISPLAY_SURFACE_WINDOW | ||
|
|
@@ -2569,10 +2572,12 @@ void MainWindow::createDisplayWidget(bool fullscreen, bool render_to_main) | |
| { | ||
| // On Wayland, while move/restoreGeometry can't position the window, it can influence which screen they show up on. | ||
| // Other platforms can position windows fine, but the only thing that matters here is the screen. | ||
| m_display_surface->setScreen(target_screen); | ||
|
|
||
| #ifdef DISPLAY_SURFACE_WINDOW | ||
| if (isVisible() && g_emu_thread->shouldRenderToMain()) | ||
| m_display_surface->setPosition(screen()->availableGeometry().topLeft()); | ||
| m_display_surface->create(); | ||
| if (monitor_index > 0 || (isVisible() && g_emu_thread->shouldRenderToMain())) | ||
| m_display_surface->setPosition(target_screen->availableGeometry().topLeft()); | ||
| else | ||
| restoreDisplayWindowGeometryFromConfig(); | ||
|
|
||
|
|
@@ -2581,8 +2586,8 @@ void MainWindow::createDisplayWidget(bool fullscreen, bool render_to_main) | |
| else | ||
| m_display_surface->showNormal(); | ||
| #else | ||
| if (isVisible() && g_emu_thread->shouldRenderToMain()) | ||
| m_display_container->move(screen()->availableGeometry().topLeft()); | ||
| if (monitor_index > 0 || (isVisible() && g_emu_thread->shouldRenderToMain())) | ||
| m_display_container->move(target_screen->availableGeometry().topLeft()); | ||
| else | ||
| restoreDisplayWindowGeometryFromConfig(); | ||
|
|
||
|
|
@@ -2598,18 +2603,33 @@ void MainWindow::createDisplayWidget(bool fullscreen, bool render_to_main) | |
| if (m_is_temporarily_windowed && g_emu_thread->shouldRenderToMain()) | ||
| m_display_surface->setGeometry(geometry()); | ||
| else | ||
| restoreDisplayWindowGeometryFromConfig(); | ||
| restoreDisplayWindowGeometryFromConfig(monitor_index > 0 ? target_screen : nullptr); | ||
| m_display_surface->showNormal(); | ||
| #else | ||
| if (m_is_temporarily_windowed && g_emu_thread->shouldRenderToMain()) | ||
| m_display_container->setGeometry(geometry()); | ||
| else | ||
| restoreDisplayWindowGeometryFromConfig(); | ||
| restoreDisplayWindowGeometryFromConfig(monitor_index > 0 ? target_screen : nullptr); | ||
| m_display_container->showNormal(); | ||
| #endif | ||
| } | ||
| else | ||
| { | ||
| if (monitor_index > 0) | ||
| { | ||
| if (screen() != target_screen) | ||
| m_pre_game_main_window_geometry = saveGeometry(); | ||
|
|
||
| if (!m_target_screen_main_window_geometry.isEmpty()) | ||
| restoreGeometry(m_target_screen_main_window_geometry); | ||
| else | ||
| { | ||
| const QRect screenGeo = target_screen->availableGeometry(); | ||
| const QPoint center(screenGeo.x() + (screenGeo.width() - width()) / 2, | ||
| screenGeo.y() + (screenGeo.height() - height()) / 2); | ||
| move(center); | ||
| } | ||
| } | ||
|
Comment on lines
+2618
to
+2632
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above |
||
| pxAssertRel(m_ui.mainContainer->count() == 1, "Has no display widget"); | ||
| m_ui.mainContainer->addWidget(m_display_container); | ||
| m_ui.mainContainer->setCurrentIndex(1); | ||
|
|
@@ -2716,6 +2736,18 @@ void MainWindow::destroyDisplayWidget(bool show_game_list) | |
| { | ||
| pxAssertRel(m_ui.mainContainer->indexOf(m_display_container) == 1, "Display widget in stack"); | ||
| m_ui.mainContainer->removeWidget(m_display_container); | ||
| if (!m_pre_game_main_window_geometry.isEmpty()) | ||
| { | ||
| const int monitor_index = Host::GetBaseIntSettingValue("UI", "DisplayMonitor", 0); | ||
| const QList<QScreen*> screens = QGuiApplication::screens(); | ||
| QScreen* target_screen = (monitor_index > 0 && monitor_index <= screens.size()) ? screens[monitor_index - 1] : nullptr; | ||
| if (target_screen && screen() == target_screen) | ||
| m_target_screen_main_window_geometry = saveGeometry(); | ||
| else | ||
| m_target_screen_main_window_geometry.clear(); | ||
| restoreGeometry(m_pre_game_main_window_geometry); | ||
| m_pre_game_main_window_geometry.clear(); | ||
| } | ||
| if (show_game_list) | ||
| { | ||
| m_ui.mainContainer->setCurrentIndex(0); | ||
|
|
@@ -2827,10 +2859,11 @@ void MainWindow::saveDisplayWindowGeometryToConfig() | |
| } | ||
| } | ||
|
|
||
| void MainWindow::restoreDisplayWindowGeometryFromConfig() | ||
| void MainWindow::restoreDisplayWindowGeometryFromConfig(QScreen* target_screen) | ||
| { | ||
| const std::string geometry_b64 = Host::GetBaseStringSettingValue("UI", "DisplayWindowGeometry"); | ||
| const QByteArray geometry = QByteArray::fromBase64(QByteArray::fromStdString(geometry_b64)); | ||
|
|
||
| if (!geometry.isEmpty()) | ||
| { | ||
| m_display_surface->restoreGeometry(geometry); | ||
|
|
@@ -2849,6 +2882,28 @@ void MainWindow::restoreDisplayWindowGeometryFromConfig() | |
| m_display_surface->resize(640, 480); | ||
| #else | ||
| m_display_container->resize(640, 480); | ||
| #endif | ||
| } | ||
|
|
||
| // if a target screen is specified and the window is not on it, center on it | ||
| if (target_screen) | ||
| { | ||
| #ifdef DISPLAY_SURFACE_WINDOW | ||
| if (!target_screen->availableGeometry().contains(m_display_surface->geometry())) | ||
| { | ||
| const QRect screenGeo = target_screen->availableGeometry(); | ||
| const QPoint center(screenGeo.x() + (screenGeo.width() - m_display_surface->width()) / 2, | ||
| screenGeo.y() + (screenGeo.height() - m_display_surface->height()) / 2); | ||
| m_display_surface->setGeometry(QRect(center, m_display_surface->size())); | ||
| } | ||
| #else | ||
| if (!target_screen->availableGeometry().contains(m_display_container->geometry())) | ||
| { | ||
| const QRect screenGeo = target_screen->availableGeometry(); | ||
| const QPoint center(screenGeo.x() + (screenGeo.width() - m_display_container->width()) / 2, | ||
| screenGeo.y() + (screenGeo.height() - m_display_container->height()) / 2); | ||
| m_display_container->setGeometry(QRect(center, m_display_container->size())); | ||
| } | ||
| #endif | ||
| } | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why
-1on the index? isn't the combobox index (which gets saved to the settings) zero-based?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the default monitor takes up two slots in the combo box (default and monitor 1, in this case monitor 1 is my default). For example, monitor 2 is index 2 in the combo box but monitor 2 is in index 1 in what Qt returns in screens. That's why I subtract 1.
In my setup, my combobox looks like: Default, Monitor 1, Monitor 2. Default is always at index 0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, I missed the first
addItem()on line 126. That explains it, thanks.