summaryrefslogtreecommitdiff
path: root/qutebrowser/config/qtargs.py
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2020-10-05 19:14:50 +0200
committerFlorian Bruhin <me@the-compiler.org>2020-10-05 20:16:07 +0200
commitb8db878cbec08f9162fe4fc65c2ee2eb19f27446 (patch)
tree7c574799dce0eae8dcb581447b347337cdc7a5ff /qutebrowser/config/qtargs.py
parente1484d9038f5282e39f6d2d957f3a1d246ab8251 (diff)
downloadqutebrowser-b8db878cbec08f9162fe4fc65c2ee2eb19f27446.tar.gz
qutebrowser-b8db878cbec08f9162fe4fc65c2ee2eb19f27446.zip
Handle smart dark mode setting with Qt 5.15.0
Fixes #5505
Diffstat (limited to 'qutebrowser/config/qtargs.py')
-rw-r--r--qutebrowser/config/qtargs.py41
1 files changed, 28 insertions, 13 deletions
diff --git a/qutebrowser/config/qtargs.py b/qutebrowser/config/qtargs.py
index a9d92e95d..46b54cf34 100644
--- a/qutebrowser/config/qtargs.py
+++ b/qutebrowser/config/qtargs.py
@@ -24,9 +24,15 @@ import sys
import typing
import argparse
+try:
+ from PyQt5.QtWebEngine import PYQT_WEBENGINE_VERSION
+except ImportError:
+ # Added in PyQt 5.13
+ PYQT_WEBENGINE_VERSION = None
+
from qutebrowser.config import config
from qutebrowser.misc import objects
-from qutebrowser.utils import usertypes, qtutils, utils
+from qutebrowser.utils import usertypes, qtutils, utils, log
def qt_args(namespace: argparse.Namespace) -> typing.List[str]:
@@ -63,17 +69,11 @@ def qt_args(namespace: argparse.Namespace) -> typing.List[str]:
def _darkmode_prefix() -> str:
"""Return the prefix to use for darkmode settings."""
- try:
- from PyQt5.QtWebEngine import PYQT_WEBENGINE_VERSION
- except ImportError:
- # Added in PyQt 5.13
+ if PYQT_WEBENGINE_VERSION is None or PYQT_WEBENGINE_VERSION < 0x050f02:
return 'darkMode'
-
- if PYQT_WEBENGINE_VERSION >= 0x050f02:
+ else:
# QtWebEngine 5.15.2 comes with Chromium 83
return 'forceDarkMode'
- else:
- return 'darkMode'
def _darkmode_settings() -> typing.Iterator[typing.Tuple[str, str]]:
@@ -111,6 +111,14 @@ def _darkmode_settings() -> typing.Iterator[typing.Tuple[str, str]]:
False: 'false',
}
+ # Our defaults for policy.images are different from Chromium's, so we mark it as
+ # mandatory setting - except on Qt 5.15.0 where we don't, so we don't get the
+ # workaround warning below if the setting wasn't explicitly customized.
+ smart_image_policy_broken = PYQT_WEBENGINE_VERSION == 0x050f00
+ mandatory_settings = set()
+ if not smart_image_policy_broken:
+ mandatory_settings.add('policy.images')
+
_setting_description_type = typing.Tuple[
str, # qutebrowser option name
str, # darkmode setting name
@@ -123,17 +131,17 @@ def _darkmode_settings() -> typing.Iterator[typing.Tuple[str, str]]:
('enabled', 'Enabled', bools),
('algorithm', 'InversionAlgorithm', algorithms),
] # type: typing.List[_setting_description_type]
- mandatory_setting = 'enabled'
+ mandatory_settings.add('enabled')
else:
settings = [
('algorithm', '', algorithms),
]
- mandatory_setting = 'algorithm'
+ mandatory_settings.add('algorithm')
settings += [
- ('contrast', 'Contrast', None),
('policy.images', 'ImagePolicy', image_policies),
('policy.page', 'PagePolicy', page_policies),
+ ('contrast', 'Contrast', None),
('threshold.text', 'TextBrightnessThreshold', None),
('threshold.background', 'BackgroundBrightnessThreshold', None),
('grayscale.all', 'Grayscale', bools),
@@ -147,10 +155,17 @@ def _darkmode_settings() -> typing.Iterator[typing.Tuple[str, str]]:
# actually turned on.
value = config.instance.get(
'colors.webpage.darkmode.' + setting,
- fallback=setting == mandatory_setting)
+ fallback=setting in mandatory_settings)
if isinstance(value, usertypes.Unset):
continue
+ if setting == 'policy.images' and value == 'smart' and smart_image_policy_broken:
+ # WORKAROUND for
+ # https://codereview.qt-project.org/c/qt/qtwebengine-chromium/+/304211
+ log.init.warning("Ignoring colors.webpage.darkmode.policy.images = smart "
+ "because of Qt 5.15.0 bug")
+ continue
+
if mapping is not None:
value = mapping[value]