UI: detect and save when window is maximized, and restore it as such. fixes #1135

This commit is contained in:
Arisotura
2021-06-20 02:21:48 +02:00
parent 1cd477db71
commit 5b9f972625
2 changed files with 39 additions and 10 deletions

View File

@ -1226,6 +1226,10 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent)
sigaction(SIGINT, &sa, 0); sigaction(SIGINT, &sa, 0);
#endif #endif
oldW = Config::WindowWidth;
oldH = Config::WindowHeight;
oldMax = Config::WindowMaximized!=0;
setWindowTitle("melonDS " MELONDS_VERSION); setWindowTitle("melonDS " MELONDS_VERSION);
setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose);
setAcceptDrops(true); setAcceptDrops(true);
@ -1238,11 +1242,11 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent)
connect(actOpenROM, &QAction::triggered, this, &MainWindow::onOpenFile); connect(actOpenROM, &QAction::triggered, this, &MainWindow::onOpenFile);
actOpenROM->setShortcut(QKeySequence(QKeySequence::StandardKey::Open)); actOpenROM->setShortcut(QKeySequence(QKeySequence::StandardKey::Open));
actOpenROMArchive = menu->addAction("Open ROM inside Archive..."); actOpenROMArchive = menu->addAction("Open ROM inside archive...");
connect(actOpenROMArchive, &QAction::triggered, this, &MainWindow::onOpenFileArchive); connect(actOpenROMArchive, &QAction::triggered, this, &MainWindow::onOpenFileArchive);
actOpenROMArchive->setShortcut(QKeySequence(Qt::Key_O | Qt::CTRL | Qt::SHIFT)); actOpenROMArchive->setShortcut(QKeySequence(Qt::Key_O | Qt::CTRL | Qt::SHIFT));
recentMenu = menu->addMenu("Open Recent"); recentMenu = menu->addMenu("Open recent");
for (int i = 0; i < 10; ++i) for (int i = 0; i < 10; ++i)
{ {
char* item = Config::RecentROMList[i]; char* item = Config::RecentROMList[i];
@ -1507,7 +1511,11 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent)
resize(Config::WindowWidth, Config::WindowHeight); resize(Config::WindowWidth, Config::WindowHeight);
show(); if (oldMax)
showMaximized();
else
show();
createScreenPanel(); createScreenPanel();
for (int i = 0; i < 9; i++) for (int i = 0; i < 9; i++)
@ -1619,13 +1627,30 @@ void MainWindow::resizeEvent(QResizeEvent* event)
int w = event->size().width(); int w = event->size().width();
int h = event->size().height(); int h = event->size().height();
if (mainWindow != nullptr && !mainWindow->isFullScreen()) if (!isFullScreen())
{ {
// this is ugly
// thing is, when maximizing the window, we first receive the resizeEvent
// with a new size matching the screen, then the changeEvent telling us that
// the maximized flag was updated
oldW = Config::WindowWidth;
oldH = Config::WindowHeight;
oldMax = isMaximized();
Config::WindowWidth = w; Config::WindowWidth = w;
Config::WindowHeight = h; Config::WindowHeight = h;
} }
}
// TODO: detect when the window gets maximized! void MainWindow::changeEvent(QEvent* event)
{
if (isMaximized() && !oldMax)
{
Config::WindowWidth = oldW;
Config::WindowHeight = oldH;
}
Config::WindowMaximized = isMaximized() ? 1:0;
} }
void MainWindow::keyPressEvent(QKeyEvent* event) void MainWindow::keyPressEvent(QKeyEvent* event)

View File

@ -78,7 +78,7 @@ signals:
void windowLimitFPSChange(); void windowLimitFPSChange();
void screenLayoutChange(); void screenLayoutChange();
void windowFullscreenToggle(); void windowFullscreenToggle();
void swapScreensToggle(); void swapScreensToggle();
@ -120,7 +120,7 @@ protected:
int numScreens; int numScreens;
bool touching; bool touching;
void showCursor(); void showCursor();
}; };
@ -200,11 +200,12 @@ public:
bool hasOGL; bool hasOGL;
QOpenGLContext* getOGLContext(); QOpenGLContext* getOGLContext();
void onAppStateChanged(Qt::ApplicationState state); void onAppStateChanged(Qt::ApplicationState state);
protected: protected:
void resizeEvent(QResizeEvent* event) override; void resizeEvent(QResizeEvent* event) override;
void changeEvent(QEvent* event) override;
void keyPressEvent(QKeyEvent* event) override; void keyPressEvent(QKeyEvent* event) override;
void keyReleaseEvent(QKeyEvent* event) override; void keyReleaseEvent(QKeyEvent* event) override;
@ -268,7 +269,7 @@ private slots:
void onEmuStop(); void onEmuStop();
void onUpdateVideoSettings(bool glchange); void onUpdateVideoSettings(bool glchange);
void onFullscreenToggled(); void onFullscreenToggled();
private: private:
@ -283,9 +284,12 @@ private:
void createScreenPanel(); void createScreenPanel();
QString loadErrorStr(int error); QString loadErrorStr(int error);
bool pausedManually; bool pausedManually;
int oldW, oldH;
bool oldMax;
public: public:
QWidget* panel; QWidget* panel;
ScreenPanelGL* panelGL; ScreenPanelGL* panelGL;