From 5812721e4822ae363866df2cc9fc762b25061c92 Mon Sep 17 00:00:00 2001 From: David Rosca Date: Sat, 19 Aug 2017 18:52:26 +0200 Subject: [PATCH] BrowserWindow: Fix failing to enter fullscreen sometimes --- src/lib/app/browserwindow.cpp | 23 ++++++++++++++++------- src/lib/app/browserwindow.h | 5 ++++- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/lib/app/browserwindow.cpp b/src/lib/app/browserwindow.cpp index 1eab597d7..2a41fddf2 100644 --- a/src/lib/app/browserwindow.cpp +++ b/src/lib/app/browserwindow.cpp @@ -683,6 +683,15 @@ void BrowserWindow::showSource(WebView *view) view->showSource(); } +void BrowserWindow::showNormal() +{ + if (m_normalWindowState & Qt::WindowMaximized) { + QMainWindow::showMaximized(); + } else { + QMainWindow::showNormal(); + } +} + SideBar* BrowserWindow::addSideBar() { if (m_sideBar) { @@ -786,9 +795,9 @@ void BrowserWindow::toggleFullScreen() } if (isFullScreen()) - setWindowState(windowState() & ~Qt::WindowFullScreen); + showNormal(); else - setWindowState(windowState() | Qt::WindowFullScreen); + showFullScreen(); } void BrowserWindow::enterHtmlFullScreen() @@ -1049,9 +1058,9 @@ bool BrowserWindow::event(QEvent* event) case QEvent::WindowStateChange: { QWindowStateChangeEvent* ev = static_cast(event); - if (!(ev->oldState() & Qt::WindowFullScreen) && windowState() & Qt::WindowFullScreen) { + if (!(m_oldWindowState & Qt::WindowFullScreen) && windowState() & Qt::WindowFullScreen) { // Enter fullscreen - m_windowStates = ev->oldState(); + m_normalWindowState = m_oldWindowState; m_statusBarVisible = statusBar()->isVisible(); #ifndef Q_OS_MACOS @@ -1063,7 +1072,7 @@ bool BrowserWindow::event(QEvent* event) m_navigationContainer->hide(); m_navigationToolbar->buttonExitFullscreen()->show(); } - else if (ev->oldState() & Qt::WindowFullScreen && !(windowState() & Qt::WindowFullScreen)) { + else if (m_oldWindowState & Qt::WindowFullScreen && !(windowState() & Qt::WindowFullScreen)) { // Leave fullscreen statusBar()->setVisible(m_statusBarVisible); #ifndef Q_OS_MACOS @@ -1074,13 +1083,13 @@ bool BrowserWindow::event(QEvent* event) m_navigationToolbar->setSuperMenuVisible(!m_menuBarVisible); m_navigationToolbar->buttonExitFullscreen()->hide(); m_isHtmlFullScreen = false; - - setWindowState(m_windowStates); } if (m_hideNavigationTimer) { m_hideNavigationTimer->stop(); } + + m_oldWindowState = windowState(); break; } diff --git a/src/lib/app/browserwindow.h b/src/lib/app/browserwindow.h index 51d4023ce..5e326fc34 100644 --- a/src/lib/app/browserwindow.h +++ b/src/lib/app/browserwindow.h @@ -141,6 +141,8 @@ public slots: void loadAddress(const QUrl &url); void showSource(WebView *view = Q_NULLPTR); + void showNormal(); + private slots: void addTab(); void openLocation(); @@ -211,7 +213,8 @@ private: bool m_menuBarVisible; bool m_statusBarVisible; bool m_isHtmlFullScreen; - Qt::WindowStates m_windowStates; + Qt::WindowStates m_oldWindowState = Qt::WindowNoState; + Qt::WindowStates m_normalWindowState = Qt::WindowNoState; QTimer* m_hideNavigationTimer; QList > m_deleteOnCloseWidgets;