diff --git a/doc/changelog.asciidoc b/doc/changelog.asciidoc index 420df0858..4e4ba40dd 100644 --- a/doc/changelog.asciidoc +++ b/doc/changelog.asciidoc @@ -15,6 +15,16 @@ breaking changes (such as renamed commands) can happen in minor releases. // `Fixed` for any bug fixes. // `Security` to invite users to upgrade in case of vulnerabilities. +v1.10.0 (unreleased) +-------------------- + +Added +~~~~~ + +- New `colors.webpage.force_dark_color_scheme` setting which allows forcing + `prefer-color-scheme: dark` colors for websites (QtWebEngine with Qt 5.14 or + newer). + v1.9.0 (2020-01-08) ------------------- diff --git a/doc/help/settings.asciidoc b/doc/help/settings.asciidoc index 7cab1dbe9..0835bfc2a 100644 --- a/doc/help/settings.asciidoc +++ b/doc/help/settings.asciidoc @@ -109,6 +109,7 @@ |<>|Background color of selected odd tabs. |<>|Foreground color of selected odd tabs. |<>|Background color for webpages if unset (or empty to use the theme's color). +|<>|Force `prefer-color-scheme: dark` colors for websites. |<>|Number of commands to save in the command history. |<>|Delay (in milliseconds) before updating completions after typing a character. |<>|Height (in pixels or as percentage of the window) of the completion. @@ -1504,6 +1505,18 @@ Type: <> Default: +pass:[white]+ +[[colors.webpage.force_dark_color_scheme]] +=== colors.webpage.force_dark_color_scheme +Force `prefer-color-scheme: dark` colors for websites. + +Type: <> + +Default: +pass:[false]+ + +On QtWebEngine, this setting requires Qt 5.14 or newer. + +On QtWebKit, this setting is unavailable. + [[completion.cmd_history_max_items]] === completion.cmd_history_max_items Number of commands to save in the command history. diff --git a/qutebrowser/config/configdata.yml b/qutebrowser/config/configdata.yml index bce3eb524..c5f0ed99b 100644 --- a/qutebrowser/config/configdata.yml +++ b/qutebrowser/config/configdata.yml @@ -2499,6 +2499,14 @@ colors.webpage.bg: desc: "Background color for webpages if unset (or empty to use the theme's color)." +colors.webpage.force_dark_color_scheme: + default: false + type: Bool + desc: "Force `prefer-color-scheme: dark` colors for websites." + backend: + QtWebEngine: Qt 5.14 + QtWebKit: false + ## fonts fonts.monospace: diff --git a/qutebrowser/config/configinit.py b/qutebrowser/config/configinit.py index 63048371f..180c2b168 100644 --- a/qutebrowser/config/configinit.py +++ b/qutebrowser/config/configinit.py @@ -267,6 +267,12 @@ def _qtwebengine_args(namespace: argparse.Namespace) -> typing.Iterator[str]: False: '--autoplay-policy=user-gesture-required', } + if qtutils.version_check('5.14'): + settings['colors.webpage.force_dark_color_scheme'] = { + True: '--force-dark-mode', + False: None, + } + for setting, args in sorted(settings.items()): arg = args[config.instance.get(setting)] if arg is not None: diff --git a/tests/unit/config/test_configinit.py b/tests/unit/config/test_configinit.py index 15eae696c..da95b94bc 100644 --- a/tests/unit/config/test_configinit.py +++ b/tests/unit/config/test_configinit.py @@ -636,6 +636,27 @@ class TestQtArgs: else: assert arg in args + @pytest.mark.parametrize('force, new_qt, added', [ + (True, True, True), + (True, False, False), + (False, True, False), + (False, False, False), + ]) + def test_force_dark_color_scheme(self, config_stub, monkeypatch, parser, + force, new_qt, added): + monkeypatch.setattr(configinit.qtutils, 'version_check', + lambda version, exact=False, compiled=True: + new_qt) + + monkeypatch.setattr(configinit.objects, 'backend', + usertypes.Backend.QtWebEngine) + + config_stub.val.colors.webpage.force_dark_color_scheme = force + parsed = parser.parse_args([]) + args = configinit.qt_args(parsed) + + assert ('--force-dark-mode' in args) == added + @pytest.mark.parametrize('arg, confval, used', [ # overridden by commandline arg