From 7eacea1057c78e1f29c0ea6934e5fbecbf92c297 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Tue, 4 Jul 2017 14:12:21 +0200 Subject: [PATCH 1/6] Preserve fullscreen when exiting video fullscreen Fixes #2778 --- qutebrowser/browser/webengine/webenginetab.py | 1 + qutebrowser/mainwindow/mainwindow.py | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/qutebrowser/browser/webengine/webenginetab.py b/qutebrowser/browser/webengine/webenginetab.py index 0a4c2dfc7..494ba840c 100644 --- a/qutebrowser/browser/webengine/webenginetab.py +++ b/qutebrowser/browser/webengine/webenginetab.py @@ -615,6 +615,7 @@ class WebEngineTab(browsertab.AbstractTab): def shutdown(self): self.shutting_down.emit() + self.action.exit_fullscreen() if qtutils.version_check('5.8', exact=True): # WORKAROUND for # https://bugreports.qt.io/browse/QTBUG-58563 diff --git a/qutebrowser/mainwindow/mainwindow.py b/qutebrowser/mainwindow/mainwindow.py index 067b536bf..5ea212b18 100644 --- a/qutebrowser/mainwindow/mainwindow.py +++ b/qutebrowser/mainwindow/mainwindow.py @@ -128,6 +128,8 @@ class MainWindow(QWidget): _commandrunner: The main CommandRunner instance. _overlays: Widgets shown as overlay for the current webpage. _private: Whether the window is in private browsing mode. + _restore_fullscreen: Whether to restore the fullscreen after leaving + a video fullscreen. """ def __init__(self, *, private, geometry=None, parent=None): @@ -217,6 +219,8 @@ class MainWindow(QWidget): objreg.get("app").new_window.emit(self) + self._restore_fullscreen = False + def _init_geometry(self, geometry): """Initialize the window geometry or load it from disk.""" if geometry is not None: @@ -483,9 +487,14 @@ class MainWindow(QWidget): @pyqtSlot(bool) def _on_fullscreen_requested(self, on): if on: + self._restore_fullscreen = self.isFullScreen() self.showFullScreen() - else: + elif not self._restore_fullscreen: self.showNormal() + else: + self._restore_fullscreen = self.isFullScreen() + log.misc.debug('on: {}, restore fullscreen: {}' + .format(on, self._restore_fullscreen)) @cmdutils.register(instance='main-window', scope='window') @pyqtSlot() From 7ea7a2f3fd029fc58e78965151974262de2d567a Mon Sep 17 00:00:00 2001 From: Christian Helbling Date: Tue, 4 Jul 2017 17:50:07 +0200 Subject: [PATCH 2/6] restore maximized state on :fullscreen and when exiting video fullscreen --- qutebrowser/browser/commands.py | 6 +++++- qutebrowser/mainwindow/mainwindow.py | 13 ++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 3d8516fe2..e3b7398ed 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -2171,6 +2171,10 @@ class CommandDispatcher: window = self._tabbed_browser.window() if window.isFullScreen(): - window.showNormal() + if window._restore_maximized: + window.showMaximized() + else: + window.showNormal() else: + window._restore_maximized = window.isMaximized() window.showFullScreen() diff --git a/qutebrowser/mainwindow/mainwindow.py b/qutebrowser/mainwindow/mainwindow.py index 5ea212b18..d8fe052b1 100644 --- a/qutebrowser/mainwindow/mainwindow.py +++ b/qutebrowser/mainwindow/mainwindow.py @@ -130,6 +130,8 @@ class MainWindow(QWidget): _private: Whether the window is in private browsing mode. _restore_fullscreen: Whether to restore the fullscreen after leaving a video fullscreen. + _restore_maximized: Whether to restore maximized window after leaving + a video fullscreen. """ def __init__(self, *, private, geometry=None, parent=None): @@ -220,6 +222,7 @@ class MainWindow(QWidget): objreg.get("app").new_window.emit(self) self._restore_fullscreen = False + self._restore_maximized = self.isMaximized() def _init_geometry(self, geometry): """Initialize the window geometry or load it from disk.""" @@ -488,13 +491,17 @@ class MainWindow(QWidget): def _on_fullscreen_requested(self, on): if on: self._restore_fullscreen = self.isFullScreen() + self._restore_maximized = self.isMaximized() self.showFullScreen() elif not self._restore_fullscreen: - self.showNormal() + if self._restore_maximized: + self.showMaximized() + else: + self.showNormal() else: self._restore_fullscreen = self.isFullScreen() - log.misc.debug('on: {}, restore fullscreen: {}' - .format(on, self._restore_fullscreen)) + log.misc.debug('on: {}, restore fullscreen: {}, restore maximized: {}' + .format(on, self._restore_fullscreen, self._restore_maximized)) @cmdutils.register(instance='main-window', scope='window') @pyqtSlot() From 20db65e430beb7bbe9f6f0b895dcaea34c64cd55 Mon Sep 17 00:00:00 2001 From: Christian Helbling Date: Tue, 4 Jul 2017 22:56:44 +0200 Subject: [PATCH 3/6] preserve window state when exiting video fullscreen --- qutebrowser/browser/commands.py | 7 ++----- qutebrowser/mainwindow/mainwindow.py | 22 ++++++---------------- 2 files changed, 8 insertions(+), 21 deletions(-) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index e3b7398ed..080c3e209 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -2171,10 +2171,7 @@ class CommandDispatcher: window = self._tabbed_browser.window() if window.isFullScreen(): - if window._restore_maximized: - window.showMaximized() - else: - window.showNormal() + window.setWindowState(window._state_before_fullscreen & ~Qt.WindowFullScreen) else: - window._restore_maximized = window.isMaximized() + window._state_before_fullscreen = window.windowState() window.showFullScreen() diff --git a/qutebrowser/mainwindow/mainwindow.py b/qutebrowser/mainwindow/mainwindow.py index d8fe052b1..2fac3f51a 100644 --- a/qutebrowser/mainwindow/mainwindow.py +++ b/qutebrowser/mainwindow/mainwindow.py @@ -128,10 +128,7 @@ class MainWindow(QWidget): _commandrunner: The main CommandRunner instance. _overlays: Widgets shown as overlay for the current webpage. _private: Whether the window is in private browsing mode. - _restore_fullscreen: Whether to restore the fullscreen after leaving - a video fullscreen. - _restore_maximized: Whether to restore maximized window after leaving - a video fullscreen. + _state_before_fullscreen: window state before activation of fullscreen """ def __init__(self, *, private, geometry=None, parent=None): @@ -221,8 +218,7 @@ class MainWindow(QWidget): objreg.get("app").new_window.emit(self) - self._restore_fullscreen = False - self._restore_maximized = self.isMaximized() + self._state_before_fullscreen = self.windowState() def _init_geometry(self, geometry): """Initialize the window geometry or load it from disk.""" @@ -490,18 +486,12 @@ class MainWindow(QWidget): @pyqtSlot(bool) def _on_fullscreen_requested(self, on): if on: - self._restore_fullscreen = self.isFullScreen() - self._restore_maximized = self.isMaximized() + self._state_before_fullscreen = self.windowState() self.showFullScreen() - elif not self._restore_fullscreen: - if self._restore_maximized: - self.showMaximized() - else: - self.showNormal() else: - self._restore_fullscreen = self.isFullScreen() - log.misc.debug('on: {}, restore fullscreen: {}, restore maximized: {}' - .format(on, self._restore_fullscreen, self._restore_maximized)) + self.setWindowState(self._state_before_fullscreen) + log.misc.debug('on: {}, state before fullscreen: {}' + .format(on, self._state_before_fullscreen)) @cmdutils.register(instance='main-window', scope='window') @pyqtSlot() From 361251bf538c61239b8c007b5643ba993dc2e0b9 Mon Sep 17 00:00:00 2001 From: Christian Helbling Date: Tue, 4 Jul 2017 23:30:06 +0200 Subject: [PATCH 4/6] mark public attribute as public, fix debug output --- qutebrowser/browser/commands.py | 8 +++++--- qutebrowser/mainwindow/mainwindow.py | 14 +++++++------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 080c3e209..9f7cef9d4 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -38,7 +38,7 @@ from qutebrowser.browser import (urlmarks, browsertab, inspector, navigate, webelem, downloads) from qutebrowser.keyinput import modeman from qutebrowser.utils import (message, usertypes, log, qtutils, urlutils, - objreg, utils, typing) + objreg, utils, typing, debug) from qutebrowser.utils.usertypes import KeyMode from qutebrowser.misc import editor, guiprocess from qutebrowser.completion.models import instances, sortfilter @@ -2171,7 +2171,9 @@ class CommandDispatcher: window = self._tabbed_browser.window() if window.isFullScreen(): - window.setWindowState(window._state_before_fullscreen & ~Qt.WindowFullScreen) + window.setWindowState(window.state_before_fullscreen & ~Qt.WindowFullScreen) else: - window._state_before_fullscreen = window.windowState() + window.state_before_fullscreen = window.windowState() window.showFullScreen() + log.misc.debug('state before fullscreen: {}' + .format(debug.qflags_key(Qt, window.state_before_fullscreen))) diff --git a/qutebrowser/mainwindow/mainwindow.py b/qutebrowser/mainwindow/mainwindow.py index 2fac3f51a..6edabda09 100644 --- a/qutebrowser/mainwindow/mainwindow.py +++ b/qutebrowser/mainwindow/mainwindow.py @@ -30,7 +30,7 @@ from PyQt5.QtWidgets import QWidget, QVBoxLayout, QApplication, QSizePolicy from qutebrowser.commands import runners, cmdutils from qutebrowser.config import config -from qutebrowser.utils import message, log, usertypes, qtutils, objreg, utils +from qutebrowser.utils import message, log, usertypes, qtutils, objreg, utils, debug from qutebrowser.mainwindow import tabbedbrowser, messageview, prompt from qutebrowser.mainwindow.statusbar import bar from qutebrowser.completion import completionwidget, completer @@ -123,12 +123,12 @@ class MainWindow(QWidget): Attributes: status: The StatusBar widget. tabbed_browser: The TabbedBrowser widget. + state_before_fullscreen: window state before activation of fullscreen. _downloadview: The DownloadView widget. _vbox: The main QVBoxLayout. _commandrunner: The main CommandRunner instance. _overlays: Widgets shown as overlay for the current webpage. _private: Whether the window is in private browsing mode. - _state_before_fullscreen: window state before activation of fullscreen """ def __init__(self, *, private, geometry=None, parent=None): @@ -218,7 +218,7 @@ class MainWindow(QWidget): objreg.get("app").new_window.emit(self) - self._state_before_fullscreen = self.windowState() + self.state_before_fullscreen = self.windowState() def _init_geometry(self, geometry): """Initialize the window geometry or load it from disk.""" @@ -486,12 +486,12 @@ class MainWindow(QWidget): @pyqtSlot(bool) def _on_fullscreen_requested(self, on): if on: - self._state_before_fullscreen = self.windowState() + self.state_before_fullscreen = self.windowState() self.showFullScreen() else: - self.setWindowState(self._state_before_fullscreen) - log.misc.debug('on: {}, state before fullscreen: {}' - .format(on, self._state_before_fullscreen)) + self.setWindowState(self.state_before_fullscreen) + log.misc.debug('on: {}, state before fullscreen: {}'.format( + on, debug.qflags_key(Qt, self.state_before_fullscreen))) @cmdutils.register(instance='main-window', scope='window') @pyqtSlot() From d179450c29a9dfbe0eff08ca84fddfbd3967615d Mon Sep 17 00:00:00 2001 From: Christian Helbling Date: Thu, 6 Jul 2017 15:35:52 +0200 Subject: [PATCH 5/6] :fullscreen, enter video fullscreen, :fullscreen, exit video fullscreen should not go into video fullscreen --- qutebrowser/mainwindow/mainwindow.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qutebrowser/mainwindow/mainwindow.py b/qutebrowser/mainwindow/mainwindow.py index 6edabda09..88ffcf383 100644 --- a/qutebrowser/mainwindow/mainwindow.py +++ b/qutebrowser/mainwindow/mainwindow.py @@ -488,7 +488,7 @@ class MainWindow(QWidget): if on: self.state_before_fullscreen = self.windowState() self.showFullScreen() - else: + elif self.isFullScreen(): self.setWindowState(self.state_before_fullscreen) log.misc.debug('on: {}, state before fullscreen: {}'.format( on, debug.qflags_key(Qt, self.state_before_fullscreen))) From 6d9e5dc931bff543eebaf97bb063b7c7c24a0224 Mon Sep 17 00:00:00 2001 From: Christian Helbling Date: Fri, 7 Jul 2017 11:30:18 +0200 Subject: [PATCH 6/6] avoid too long lines --- qutebrowser/browser/commands.py | 7 ++++--- qutebrowser/mainwindow/mainwindow.py | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 9f7cef9d4..f0585bba0 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -2171,9 +2171,10 @@ class CommandDispatcher: window = self._tabbed_browser.window() if window.isFullScreen(): - window.setWindowState(window.state_before_fullscreen & ~Qt.WindowFullScreen) + window.setWindowState( + window.state_before_fullscreen & ~Qt.WindowFullScreen) else: window.state_before_fullscreen = window.windowState() window.showFullScreen() - log.misc.debug('state before fullscreen: {}' - .format(debug.qflags_key(Qt, window.state_before_fullscreen))) + log.misc.debug('state before fullscreen: {}'.format( + debug.qflags_key(Qt, window.state_before_fullscreen))) diff --git a/qutebrowser/mainwindow/mainwindow.py b/qutebrowser/mainwindow/mainwindow.py index 88ffcf383..2f43ba58e 100644 --- a/qutebrowser/mainwindow/mainwindow.py +++ b/qutebrowser/mainwindow/mainwindow.py @@ -30,7 +30,8 @@ from PyQt5.QtWidgets import QWidget, QVBoxLayout, QApplication, QSizePolicy from qutebrowser.commands import runners, cmdutils from qutebrowser.config import config -from qutebrowser.utils import message, log, usertypes, qtutils, objreg, utils, debug +from qutebrowser.utils import (message, log, usertypes, qtutils, objreg, utils, + debug) from qutebrowser.mainwindow import tabbedbrowser, messageview, prompt from qutebrowser.mainwindow.statusbar import bar from qutebrowser.completion import completionwidget, completer