yuzu-emu
/
yuzu
Archived
1
0
Fork 0

deprecate usage of QDesktopWidget for going fullscreen

Idea works as follows, while going fullscreen we compare the current window geometry with
available screens and ask for an intersection rectangle, we go fullscreen where most of
the window is located

GuessCurrentScreen could also potentially be used to see which screen
the window is on for dynamic DPI handling
This commit is contained in:
Kyle Kienapfel 2022-06-05 15:03:03 -07:00
parent 8a858c2623
commit 941b663352
1 changed files with 15 additions and 3 deletions

View File

@ -52,7 +52,6 @@ static FileSys::VirtualFile VfsDirectoryCreateFileWrapper(const FileSys::Virtual
#define QT_NO_OPENGL #define QT_NO_OPENGL
#include <QClipboard> #include <QClipboard>
#include <QDesktopServices> #include <QDesktopServices>
#include <QDesktopWidget>
#include <QFile> #include <QFile>
#include <QFileDialog> #include <QFileDialog>
#include <QInputDialog> #include <QInputDialog>
@ -60,6 +59,7 @@ static FileSys::VirtualFile VfsDirectoryCreateFileWrapper(const FileSys::Virtual
#include <QProgressBar> #include <QProgressBar>
#include <QProgressDialog> #include <QProgressDialog>
#include <QPushButton> #include <QPushButton>
#include <QScreen>
#include <QShortcut> #include <QShortcut>
#include <QStatusBar> #include <QStatusBar>
#include <QString> #include <QString>
@ -1002,7 +1002,7 @@ void GMainWindow::InitializeHotkeys() {
void GMainWindow::SetDefaultUIGeometry() { void GMainWindow::SetDefaultUIGeometry() {
// geometry: 53% of the window contents are in the upper screen half, 47% in the lower half // geometry: 53% of the window contents are in the upper screen half, 47% in the lower half
const QRect screenRect = QApplication::desktop()->screenGeometry(this); const QRect screenRect = QGuiApplication::primaryScreen()->geometry();
const int w = screenRect.width() * 2 / 3; const int w = screenRect.width() * 2 / 3;
const int h = screenRect.height() * 2 / 3; const int h = screenRect.height() * 2 / 3;
@ -2581,6 +2581,18 @@ void GMainWindow::ToggleFullscreen() {
} }
} }
// We're going to return the screen that the given window has the most pixels on
static QScreen* GuessCurrentScreen(QWidget* window) {
const QList<QScreen*> screens = QGuiApplication::screens();
return *std::max_element(
screens.cbegin(), screens.cend(), [window](const QScreen* left, const QScreen* right) {
const QSize left_size = left->geometry().intersected(window->geometry()).size();
const QSize right_size = right->geometry().intersected(window->geometry()).size();
return (left_size.height() * left_size.width()) <
(right_size.height() * right_size.width());
});
}
void GMainWindow::ShowFullscreen() { void GMainWindow::ShowFullscreen() {
const auto show_fullscreen = [](QWidget* window) { const auto show_fullscreen = [](QWidget* window) {
if (Settings::values.fullscreen_mode.GetValue() == Settings::FullscreenMode::Exclusive) { if (Settings::values.fullscreen_mode.GetValue() == Settings::FullscreenMode::Exclusive) {
@ -2589,7 +2601,7 @@ void GMainWindow::ShowFullscreen() {
} }
window->hide(); window->hide();
window->setWindowFlags(window->windowFlags() | Qt::FramelessWindowHint); window->setWindowFlags(window->windowFlags() | Qt::FramelessWindowHint);
const auto screen_geometry = QApplication::desktop()->screenGeometry(window); const auto screen_geometry = GuessCurrentScreen(window)->geometry();
window->setGeometry(screen_geometry.x(), screen_geometry.y(), screen_geometry.width(), window->setGeometry(screen_geometry.x(), screen_geometry.y(), screen_geometry.width(),
screen_geometry.height() + 1); screen_geometry.height() + 1);
window->raise(); window->raise();