Repository: qutebrowser/qutebrowser

Issue:
Exiting video player exits fullscreen
**Version info (see `:version`)**:
qutebrowser v1.5.1
Git commit: c7a21b37e-dirty (2018-10-10 08:23:17 +0200)
Backend: QtWebEngine (Chromium 65.0.3325.230)

CPython: 3.7.0
Qt: 5.11.2
PyQt: 5.11.3

sip: 4.19.13
colorama: 0.3.9
pypeg2: 2.15
jinja2: 2.10
pygments: 2.2.0
yaml: 3.13
cssutils: 1.0.2 $Id$
attr: 18.2.0
PyQt5.QtWebEngineWidgets: yes
PyQt5.QtWebKitWidgets: no
pdf.js: 1.10.100 (bundled)
sqlite: 3.24.0
QtNetwork SSL: Secure Transport, macOS 10.14

Style: QMacStyle
Platform: Darwin-18.0.0-x86_64-i386-64bit, 64bit
Frozen: True
Imported from /Applications/qutebrowser.app/Contents/MacOS/qutebrowser
Using Python from /Applications/qutebrowser.app/Contents/MacOS/qutebrowser
Qt library executable path: /Applications/qutebrowser.app/Contents/MacOS/PyQt5/Qt/libexec, data path: /Applications/qutebrowser.app/Contents/MacOS/PyQt5/Qt
OS Version: 10.14, x86_64

**Description**
On MacOS, when exiting fullscreen mode in any video player the whole browser will exit fullscreen mode. 
**How to reproduce**
Go to any video playing site. E.g youtube.com
Fullscreen the video
Exit the fullscreen
Exiting video player exits fullscreen
**Version info (see `:version`)**:
qutebrowser v1.5.1
Git commit: c7a21b37e-dirty (2018-10-10 08:23:17 +0200)
Backend: QtWebEngine (Chromium 65.0.3325.230)

CPython: 3.7.0
Qt: 5.11.2
PyQt: 5.11.3

sip: 4.19.13
colorama: 0.3.9
pypeg2: 2.15
jinja2: 2.10
pygments: 2.2.0
yaml: 3.13
cssutils: 1.0.2 $Id$
attr: 18.2.0
PyQt5.QtWebEngineWidgets: yes
PyQt5.QtWebKitWidgets: no
pdf.js: 1.10.100 (bundled)
sqlite: 3.24.0
QtNetwork SSL: Secure Transport, macOS 10.14

Style: QMacStyle
Platform: Darwin-18.0.0-x86_64-i386-64bit, 64bit
Frozen: True
Imported from /Applications/qutebrowser.app/Contents/MacOS/qutebrowser
Using Python from /Applications/qutebrowser.app/Contents/MacOS/qutebrowser
Qt library executable path: /Applications/qutebrowser.app/Contents/MacOS/PyQt5/Qt/libexec, data path: /Applications/qutebrowser.app/Contents/MacOS/PyQt5/Qt
OS Version: 10.14, x86_64

**Description**
On MacOS, when exiting fullscreen mode in any video player the whole browser will exit fullscreen mode. 
**How to reproduce**
Go to any video playing site. E.g youtube.com
Fullscreen the video
Exit the fullscreen


Discussion:
It also does this on linux under Xorg.
I noticed this too, thanks for reporting.

The code to fix this is [here](https://github.com/qutebrowser/qutebrowser/blob/master/qutebrowser/mainwindow/mainwindow.py#L516-L521).

Weirdly, it seems to have been introduced in 559059d244ccf95c56bd1c6f982f700ce13aa038, which was added in #3482, a PR which was trying to solve this problem...


cc @helbling
I can confirm the bug.
In 559059d and cd20c329 I got rid of the state variable window.state_before_fullscreen as the behaviour seemed to be correct at the time.
This is definitely no longer the case and we need to revert these commits.

First tests look good.
I will prepare a pull request.
It also does this on linux under Xorg.
I noticed this too, thanks for reporting.

The code to fix this is [here](https://github.com/qutebrowser/qutebrowser/blob/master/qutebrowser/mainwindow/mainwindow.py#L516-L521).

Weirdly, it seems to have been introduced in 559059d244ccf95c56bd1c6f982f700ce13aa038, which was added in #3482, a PR which was trying to solve this problem...


cc @helbling
I can confirm the bug.
In 559059d and cd20c329 I got rid of the state variable window.state_before_fullscreen as the behaviour seemed to be correct at the time.
This is definitely no longer the case and we need to revert these commits.

First tests look good.
I will prepare a pull request.

Resolving patch:
diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py
--- a/qutebrowser/browser/commands.py
+++ b/qutebrowser/browser/commands.py
@@ -34,7 +34,7 @@
                                  webelem, downloads)
 from qutebrowser.keyinput import modeman, keyutils
 from qutebrowser.utils import (message, usertypes, log, qtutils, urlutils,
-                               objreg, utils, standarddir)
+                               objreg, utils, standarddir, debug)
 from qutebrowser.utils.usertypes import KeyMode
 from qutebrowser.misc import editor, guiprocess, objects
 from qutebrowser.completion.models import urlmodel, miscmodels
@@ -1721,4 +1721,10 @@ def fullscreen(self, leave=False):
             return
 
         window = self._tabbed_browser.widget.window()
+
+        if not window.isFullScreen():
+            window.state_before_fullscreen = window.windowState()
         window.setWindowState(window.windowState() ^ Qt.WindowFullScreen)
+
+        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
--- a/qutebrowser/mainwindow/mainwindow.py
+++ b/qutebrowser/mainwindow/mainwindow.py
@@ -32,7 +32,7 @@
 from qutebrowser.api import cmdutils
 from qutebrowser.config import config, configfiles
 from qutebrowser.utils import (message, log, usertypes, qtutils, objreg, utils,
-                               jinja)
+                               jinja, debug)
 from qutebrowser.mainwindow import messageview, prompt
 from qutebrowser.completion import completionwidget, completer
 from qutebrowser.keyinput import modeman
@@ -137,6 +137,7 @@ 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.
@@ -238,6 +239,8 @@ def __init__(self, *, private, geometry=None, parent=None):
         objreg.get("app").new_window.emit(self)
         self._set_decoration(config.val.window.hide_decoration)
 
+        self.state_before_fullscreen = self.windowState()
+
     def _init_geometry(self, geometry):
         """Initialize the window geometry or load it from disk."""
         if geometry is not None:
@@ -517,9 +520,13 @@ def _set_decoration(self, hidden):
     def _on_fullscreen_requested(self, on):
         if not config.val.content.windowed_fullscreen:
             if on:
-                self.setWindowState(self.windowState() | Qt.WindowFullScreen)
+                self.state_before_fullscreen = self.windowState()
+                self.setWindowState(
+                    Qt.WindowFullScreen | self.state_before_fullscreen)
             elif self.isFullScreen():
-                self.setWindowState(self.windowState() & ~Qt.WindowFullScreen)
+                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()


Test patch: