Repository: qutebrowser/qutebrowser
Pull request: Fullscreen enter option
Add `--enter` to `:fullscreen` to only enter, but never leave fullscreen mode. Without any force :-)

Closes: #4828

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/qutebrowser/qutebrowser/4833)
<!-- Reviewable:end -->


Problem statement:
Force full screen
Currently qutebrowser only provides a toggle for full screen. Thereby it is not possible to just start it in full screen mode independent of the state it is in. For example, chromium provides "--fullscreen" to start in full screen mode.

For qutebrowser the feature could be added as "--force" for the available :fullscreen.

If this feature get's accepted I would be happy to provide a PR.

Hints from issue discussion:
There's already `:fullscreen --leave` to only leave fullscreen, so for symmetry with that I'd probably call it `:fullscreen --enter`. Other than that, sounds simple enough, go ahead!

Commit message: updated documentation

Patch to review:
diff --git a/doc/help/commands.asciidoc b/doc/help/commands.asciidoc
index b2fc99a5edf..ae9ada9fdef 100644
--- a/doc/help/commands.asciidoc
+++ b/doc/help/commands.asciidoc
@@ -556,12 +556,14 @@ How many pages to go forward.
 
 [[fullscreen]]
 === fullscreen
-Syntax: +:fullscreen [*--leave*]+
+Syntax: +:fullscreen [*--leave*] [*--enter*]+
 
 Toggle fullscreen mode.
 
 ==== optional arguments
 * +*-l*+, +*--leave*+: Only leave fullscreen if it was entered by the page.
+* +*-e*+, +*--enter*+: Activate fullscreen and do not toggle if it is already active.
+
 
 [[greasemonkey-reload]]
 === greasemonkey-reload
diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py
index 55c42595d74..1e578975a36 100644
--- a/qutebrowser/browser/commands.py
+++ b/qutebrowser/browser/commands.py
@@ -1721,11 +1721,13 @@ def _open_if_changed(self, url=None, old_url=None, bg=False, tab=False,
                          private=private, related=related)
 
     @cmdutils.register(instance='command-dispatcher', scope='window')
-    def fullscreen(self, leave=False):
+    def fullscreen(self, leave=False, enter=False):
         """Toggle fullscreen mode.
 
         Args:
             leave: Only leave fullscreen if it was entered by the page.
+            enter: Activate fullscreen and do not toggle if it is already
+                   active.
         """
         if leave:
             tab = self._current_widget()
@@ -1737,6 +1739,12 @@ def fullscreen(self, leave=False):
 
         window = self._tabbed_browser.widget.window()
 
+        if enter:
+            if window.isFullScreen():
+                return
+            window.setWindowState(Qt.WindowFullScreen)
+            return
+
         if not window.isFullScreen():
             window.state_before_fullscreen = window.windowState()
         window.setWindowState(window.windowState() ^ Qt.WindowFullScreen)


Code review comments:
diff_hunk: @@ -1737,6 +1739,12 @@ def fullscreen(self, leave=False):
 
         window = self._tabbed_browser.widget.window()
 
+        if enter:
+            if window.isFullScreen():
+                return
+            window.setWindowState(Qt.WindowFullScreen)
+            return
+
         if not window.isFullScreen():
             window.state_before_fullscreen = window.windowState()
         window.setWindowState(window.windowState() ^ Qt.WindowFullScreen)
path: qutebrowser/browser/commands.py
text: @user1:
This properly preserves existing flags, while `window.setWindowState(Qt.WindowFullScreen)` above does not. Doing `window.setWindowState(window.windowState() | Qt.WindowFullScreen)` instead (with `--enter`) would probably be better. Then you can also get rid of the `window.isFullScreen()` check above, as setting the window state to the existing value doesn't do anything.

@author:
implemented as suggested