summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/changelog.asciidoc20
-rw-r--r--doc/help/settings.asciidoc73
-rw-r--r--qutebrowser/browser/webengine/darkmode.py95
-rw-r--r--qutebrowser/browser/webengine/webenginesettings.py6
-rw-r--r--qutebrowser/config/configdata.yml70
-rw-r--r--qutebrowser/config/qtargs.py13
-rw-r--r--tests/unit/browser/webengine/test_darkmode.py53
7 files changed, 173 insertions, 157 deletions
diff --git a/doc/changelog.asciidoc b/doc/changelog.asciidoc
index b7014e1f7..57570776b 100644
--- a/doc/changelog.asciidoc
+++ b/doc/changelog.asciidoc
@@ -19,12 +19,30 @@ breaking changes (such as renamed commands) can happen in minor releases.
v3.1.0 (unreleased)
-------------------
+Removed
+~~~~~~~
+
+- The darkmode settings `grayscale.all`, `grayscale.images` and
+ `increase_text_contrast` got removed, following removals in Chromium.
+
+Added
+~~~~~
+
+- New `smart-simple` value for `colors.webpage.darkmode.policy.images`, which on
+ QtWebEngine 6.6+ uses a simpler classification algorithm to decide whether to
+ invert images.
+
Changed
~~~~~~~
- (TODO) Upgraded the bundled Qt version to 6.6.1, based on Chromium 112. Note
this is only relevant for the macOS/Windows releases, on Linux those will be
upgraded via your distribution packages.
+- The `colors.webpage.darkmode.threshold.text` setting got renamed to
+ `colors.webpage.darkmode.threshold.foreground`, following a rename in
+ Chromium.
+- With Qt 6.6, the `content.canvas_reading` setting now works without a restart
+ and supports URL patterns.
Fixed
~~~~~
@@ -36,6 +54,8 @@ Fixed
restriction for the default application of
`qt.workarounds.disable_accelerated_2d_canvas` as the issue was still
evident on Qt 6.6.0. (#7489)
+- The `colors.webpage.darkmode.threshold.foreground` setting (`.text` in older
+ versions) now works correctly with Qt 6.4+.
[[v3.0.2]]
diff --git a/doc/help/settings.asciidoc b/doc/help/settings.asciidoc
index de42839ce..b6f61ab03 100644
--- a/doc/help/settings.asciidoc
+++ b/doc/help/settings.asciidoc
@@ -118,13 +118,10 @@
|<<colors.webpage.darkmode.algorithm,colors.webpage.darkmode.algorithm>>|Which algorithm to use for modifying how colors are rendered with darkmode.
|<<colors.webpage.darkmode.contrast,colors.webpage.darkmode.contrast>>|Contrast for dark mode.
|<<colors.webpage.darkmode.enabled,colors.webpage.darkmode.enabled>>|Render all web contents using a dark theme.
-|<<colors.webpage.darkmode.grayscale.all,colors.webpage.darkmode.grayscale.all>>|Render all colors as grayscale.
-|<<colors.webpage.darkmode.grayscale.images,colors.webpage.darkmode.grayscale.images>>|Desaturation factor for images in dark mode.
-|<<colors.webpage.darkmode.increase_text_contrast,colors.webpage.darkmode.increase_text_contrast>>|Increase text contrast by drawing an outline of the uninverted color.
|<<colors.webpage.darkmode.policy.images,colors.webpage.darkmode.policy.images>>|Which images to apply dark mode to.
|<<colors.webpage.darkmode.policy.page,colors.webpage.darkmode.policy.page>>|Which pages to apply dark mode to.
|<<colors.webpage.darkmode.threshold.background,colors.webpage.darkmode.threshold.background>>|Threshold for inverting background elements with dark mode.
-|<<colors.webpage.darkmode.threshold.text,colors.webpage.darkmode.threshold.text>>|Threshold for inverting text with dark mode.
+|<<colors.webpage.darkmode.threshold.foreground,colors.webpage.darkmode.threshold.foreground>>|Threshold for inverting text with dark mode.
|<<colors.webpage.preferred_color_scheme,colors.webpage.preferred_color_scheme>>|Value to use for `prefers-color-scheme:` for websites.
|<<completion.cmd_history_max_items,completion.cmd_history_max_items>>|Number of commands to save in the command history.
|<<completion.delay,completion.delay>>|Delay (in milliseconds) before updating completions after typing a character.
@@ -1681,67 +1678,16 @@ Default: +pass:[0.0]+
=== colors.webpage.darkmode.enabled
Render all web contents using a dark theme.
Example configurations from Chromium's `chrome://flags`:
-
- "With simple HSL/CIELAB/RGB-based inversion": Set
- `colors.webpage.darkmode.algorithm` accordingly.
-
-- "With selective image inversion": Set
- `colors.webpage.darkmode.policy.images` to `smart`.
-
-- "With selective inversion of non-image elements": Set
- `colors.webpage.darkmode.threshold.text` to 150 and
- `colors.webpage.darkmode.threshold.background` to 205.
-
-- "With selective inversion of everything": Combines the two variants
- above.
-
-- "With increased text contrast": Set
- `colors.webpage.darkmode.increase_text_contrast` (QtWebEngine 6.3+)
-
-This setting requires a restart.
-
-This setting is only available with the QtWebEngine backend.
-
-Type: <<types,Bool>>
-
-Default: +pass:[false]+
-
-[[colors.webpage.darkmode.grayscale.all]]
-=== colors.webpage.darkmode.grayscale.all
-Render all colors as grayscale.
-This only has an effect when `colors.webpage.darkmode.algorithm` is set to `lightness-hsl` or `brightness-rgb`.
-
-This setting requires a restart.
+ `colors.webpage.darkmode.algorithm` accordingly, and
+ set `colors.webpage.darkmode.policy.images` to `never`.
-This setting is only available with the QtWebEngine backend.
-
-Type: <<types,Bool>>
-
-Default: +pass:[false]+
-
-[[colors.webpage.darkmode.grayscale.images]]
-=== colors.webpage.darkmode.grayscale.images
-Desaturation factor for images in dark mode.
-If set to 0, images are left as-is. If set to 1, images are completely grayscale. Values between 0 and 1 desaturate the colors accordingly.
+- "With selective image inversion": qutebrowser default settings.
This setting requires a restart.
This setting is only available with the QtWebEngine backend.
-Type: <<types,Float>>
-
-Default: +pass:[0.0]+
-
-[[colors.webpage.darkmode.increase_text_contrast]]
-=== colors.webpage.darkmode.increase_text_contrast
-Increase text contrast by drawing an outline of the uninverted color.
-
-This setting requires a restart.
-
-On QtWebEngine, this setting requires Qt 6.3 or newer.
-
-On QtWebKit, this setting is unavailable.
-
Type: <<types,Bool>>
Default: +pass:[false]+
@@ -1749,7 +1695,6 @@ Default: +pass:[false]+
[[colors.webpage.darkmode.policy.images]]
=== colors.webpage.darkmode.policy.images
Which images to apply dark mode to.
-With QtWebEngine 5.15.0, this setting can cause frequent renderer process crashes due to a https://codereview.qt-project.org/c/qt/qtwebengine-chromium/+/304211[bug in Qt].
This setting requires a restart.
@@ -1762,6 +1707,7 @@ Valid values:
* +always+: Apply dark mode filter to all images.
* +never+: Never apply dark mode filter to any images.
* +smart+: Apply dark mode based on image content. Not available with Qt 5.15.0.
+ * +smart-simple+: On QtWebEngine 6.6, use a simpler algorithm for smart mode (based on numbers of colors and transparency), rather than an ML-based model. Same as 'smart' on older QtWebEnigne versions.
Default: +pass:[smart]+
@@ -1787,7 +1733,7 @@ Default: +pass:[smart]+
=== colors.webpage.darkmode.threshold.background
Threshold for inverting background elements with dark mode.
Background elements with brightness above this threshold will be inverted, and below it will be left as in the original, non-dark-mode page. Set to 256 to never invert the color or to 0 to always invert it.
-Note: This behavior is the opposite of `colors.webpage.darkmode.threshold.text`!
+Note: This behavior is the opposite of `colors.webpage.darkmode.threshold.foreground`!
This setting requires a restart.
@@ -1797,8 +1743,8 @@ Type: <<types,Int>>
Default: +pass:[0]+
-[[colors.webpage.darkmode.threshold.text]]
-=== colors.webpage.darkmode.threshold.text
+[[colors.webpage.darkmode.threshold.foreground]]
+=== colors.webpage.darkmode.threshold.foreground
Threshold for inverting text with dark mode.
Text colors with brightness below this threshold will be inverted, and above it will be left as in the original, non-dark-mode page. Set to 256 to always invert text color or to 0 to never invert text color.
@@ -2139,8 +2085,9 @@ Default: empty
=== content.canvas_reading
Allow websites to read canvas elements.
Note this is needed for some websites to work properly.
+On QtWebEngine < 6.6, this setting requires a restart and does not support URL patterns, only the global setting is applied.
-This setting requires a restart.
+This setting supports link:configuring{outfilesuffix}#patterns[URL patterns].
This setting is only available with the QtWebEngine backend.
diff --git a/qutebrowser/browser/webengine/darkmode.py b/qutebrowser/browser/webengine/darkmode.py
index 99bf58789..37d050d87 100644
--- a/qutebrowser/browser/webengine/darkmode.py
+++ b/qutebrowser/browser/webengine/darkmode.py
@@ -85,7 +85,34 @@ Qt 6.3
------
- New IncreaseTextContrast:
-https://chromium-review.googlesource.com/c/chromium/src/+/2893236
+ https://chromium-review.googlesource.com/c/chromium/src/+/2893236
+ (UNSUPPORTED because dropped in 6.5)
+
+Qt 6.4
+------
+
+- Renamed TextBrightnessThreshold to ForegroundBrightnessThreshold
+
+ "Correct brightness threshold of darkmode color classifier"
+ https://chromium-review.googlesource.com/c/chromium/src/+/3344100
+
+ "Rename text_classifier to foreground_classifier"
+ https://chromium-review.googlesource.com/c/chromium/src/+/3226389
+
+- Grayscale darkmode support removed:
+ https://chromium-review.googlesource.com/c/chromium/src/+/3238985
+
+Qt 6.5
+------
+
+- IncreaseTextContrast removed:
+ https://chromium-review.googlesource.com/c/chromium/src/+/3821841
+
+Qt 6.6
+------
+
+- New alternative image classifier:
+ https://chromium-review.googlesource.com/c/chromium/src/+/3987823
"""
import os
@@ -109,7 +136,8 @@ class Variant(enum.Enum):
qt_515_2 = enum.auto()
qt_515_3 = enum.auto()
- qt_63 = enum.auto()
+ qt_64 = enum.auto()
+ qt_66 = enum.auto()
# Mapping from a colors.webpage.darkmode.algorithm setting value to
@@ -136,6 +164,15 @@ _IMAGE_POLICIES = {
'always': 0, # kFilterAll
'never': 1, # kFilterNone
'smart': 2, # kFilterSmart
+ 'smart-simple': 2, # kFilterSmart
+}
+
+# Using the colors.webpage.darkmode.policy.images setting, shared with _IMAGE_POLICIES
+_IMAGE_CLASSIFIERS = {
+ 'always': None,
+ 'never': None,
+ 'smart': 0, # kNumColorsWithMlFallback
+ 'smart-simple': 1, # kTransparencyAndNumColors
}
# Mapping from a colors.webpage.darkmode.policy.page setting value to
@@ -163,14 +200,16 @@ class _Setting:
option: str
chromium_key: str
- mapping: Optional[Mapping[Any, Union[str, int]]] = None
+ mapping: Optional[Mapping[Any, Union[str, int, None]]] = None
def _value_str(self, value: Any) -> str:
if self.mapping is None:
return str(value)
return str(self.mapping[value])
- def chromium_tuple(self, value: Any) -> Tuple[str, str]:
+ def chromium_tuple(self, value: Any) -> Optional[Tuple[str, str]]:
+ if self.mapping is not None and self.mapping[value] is None:
+ return None
return self.chromium_key, self._value_str(value)
def with_prefix(self, prefix: str) -> '_Setting':
@@ -236,6 +275,20 @@ class _Definition:
new._settings = self._settings + (setting,) # pylint: disable=protected-access
return new
+ def copy_replace_setting(self, option: str, chromium_key: str) -> '_Definition':
+ """Get a new _Definition object with `old` replaced by `new`.
+
+ If `old` is not in the settings list, return the old _Definition object.
+ """
+ new = copy.deepcopy(self)
+
+ for setting in new._settings: # pylint: disable=protected-access
+ if setting.option == option:
+ setting.chromium_key = chromium_key
+ return new
+
+ raise ValueError(f"Setting {option} not found in {self}")
+
# Our defaults for policy.images are different from Chromium's, so we mark it as
# mandatory setting.
@@ -247,12 +300,10 @@ _DEFINITIONS: MutableMapping[Variant, _Definition] = {
_Setting('policy.images', 'ImagePolicy', _IMAGE_POLICIES),
_Setting('contrast', 'Contrast'),
- _Setting('grayscale.all', 'Grayscale', _BOOLS),
_Setting('policy.page', 'PagePolicy', _PAGE_POLICIES),
- _Setting('threshold.text', 'TextBrightnessThreshold'),
+ _Setting('threshold.foreground', 'TextBrightnessThreshold'),
_Setting('threshold.background', 'BackgroundBrightnessThreshold'),
- _Setting('grayscale.images', 'ImageGrayscale'),
mandatory={'enabled', 'policy.images'},
prefix='forceDarkMode',
@@ -265,19 +316,20 @@ _DEFINITIONS: MutableMapping[Variant, _Definition] = {
_Setting('policy.images', 'ImagePolicy', _IMAGE_POLICIES),
_Setting('contrast', 'ContrastPercent'),
- _Setting('grayscale.all', 'IsGrayScale', _BOOLS),
- _Setting('threshold.text', 'TextBrightnessThreshold'),
+ _Setting('threshold.foreground', 'TextBrightnessThreshold'),
_Setting('threshold.background', 'BackgroundBrightnessThreshold'),
- _Setting('grayscale.images', 'ImageGrayScalePercent'),
mandatory={'enabled', 'policy.images'},
prefix='',
switch_names={'enabled': _BLINK_SETTINGS, None: 'dark-mode-settings'},
),
}
-_DEFINITIONS[Variant.qt_63] = _DEFINITIONS[Variant.qt_515_3].copy_add_setting(
- _Setting('increase_text_contrast', 'IncreaseTextContrast', _INT_BOOLS),
+_DEFINITIONS[Variant.qt_64] = _DEFINITIONS[Variant.qt_515_3].copy_replace_setting(
+ 'threshold.foreground', 'ForegroundBrightnessThreshold',
+)
+_DEFINITIONS[Variant.qt_66] = _DEFINITIONS[Variant.qt_64].copy_add_setting(
+ _Setting('policy.images', 'ImageClassifierPolicy', _IMAGE_CLASSIFIERS),
)
@@ -298,12 +350,11 @@ _PREFERRED_COLOR_SCHEME_DEFINITIONS: Mapping[Variant, Mapping[_SettingValType, s
"dark": "0",
"light": "1",
},
-
- Variant.qt_63: {
- "dark": "0",
- "light": "1",
- }
}
+for variant in Variant:
+ if variant not in _PREFERRED_COLOR_SCHEME_DEFINITIONS:
+ _PREFERRED_COLOR_SCHEME_DEFINITIONS[variant] = \
+ _PREFERRED_COLOR_SCHEME_DEFINITIONS[Variant.qt_515_3]
def _variant(versions: version.WebEngineVersions) -> Variant:
@@ -315,8 +366,10 @@ def _variant(versions: version.WebEngineVersions) -> Variant:
except KeyError:
log.init.warning(f"Ignoring invalid QUTE_DARKMODE_VARIANT={env_var}")
- if versions.webengine >= utils.VersionNumber(6, 3):
- return Variant.qt_63
+ if versions.webengine >= utils.VersionNumber(6, 6):
+ return Variant.qt_66
+ elif versions.webengine >= utils.VersionNumber(6, 4):
+ return Variant.qt_64
elif (versions.webengine == utils.VersionNumber(5, 15, 2) and
versions.chromium_major == 87):
# WORKAROUND for Gentoo packaging something newer as 5.15.2...
@@ -378,6 +431,8 @@ def settings(
if isinstance(value, usertypes.Unset):
continue
- result[switch_name].append(setting.chromium_tuple(value))
+ chromium_tuple = setting.chromium_tuple(value)
+ if chromium_tuple is not None:
+ result[switch_name].append(chromium_tuple)
return result
diff --git a/qutebrowser/browser/webengine/webenginesettings.py b/qutebrowser/browser/webengine/webenginesettings.py
index 1275edf0b..808e75c30 100644
--- a/qutebrowser/browser/webengine/webenginesettings.py
+++ b/qutebrowser/browser/webengine/webenginesettings.py
@@ -148,6 +148,12 @@ class WebEngineSettings(websettings.AbstractSettings):
Attr(QWebEngineSettings.WebAttribute.AutoLoadIconsForPage,
converter=lambda val: val != 'never'),
}
+ try:
+ _ATTRIBUTES['content.canvas_reading'] = Attr(
+ QWebEngineSettings.WebAttribute.ReadingFromCanvasEnabled)
+ except AttributeError:
+ # Added in QtWebEngine 6.6
+ pass
_FONT_SIZES = {
'fonts.web.size.minimum':
diff --git a/qutebrowser/config/configdata.yml b/qutebrowser/config/configdata.yml
index c3a46e0bb..cddac7353 100644
--- a/qutebrowser/config/configdata.yml
+++ b/qutebrowser/config/configdata.yml
@@ -454,12 +454,15 @@ content.canvas_reading:
default: true
type: Bool
backend: QtWebEngine
- restart: true
+ supports_pattern: true
desc: >-
Allow websites to read canvas elements.
Note this is needed for some websites to work properly.
+ On QtWebEngine < 6.6, this setting requires a restart and does not support
+ URL patterns, only the global setting is applied.
+
# Defaults from QWebSettings::QWebSettings() in
# qtwebkit/Source/WebKit/qt/Api/qwebsettings.cpp
@@ -3245,22 +3248,11 @@ colors.webpage.darkmode.enabled:
Example configurations from Chromium's `chrome://flags`:
-
- "With simple HSL/CIELAB/RGB-based inversion": Set
- `colors.webpage.darkmode.algorithm` accordingly.
-
- - "With selective image inversion": Set
- `colors.webpage.darkmode.policy.images` to `smart`.
+ `colors.webpage.darkmode.algorithm` accordingly, and
+ set `colors.webpage.darkmode.policy.images` to `never`.
- - "With selective inversion of non-image elements": Set
- `colors.webpage.darkmode.threshold.text` to 150 and
- `colors.webpage.darkmode.threshold.background` to 205.
-
- - "With selective inversion of everything": Combines the two variants
- above.
-
- - "With increased text contrast": Set
- `colors.webpage.darkmode.increase_text_contrast` (QtWebEngine 6.3+)
+ - "With selective image inversion": qutebrowser default settings.
restart: true
backend: QtWebEngine
@@ -3309,13 +3301,11 @@ colors.webpage.darkmode.policy.images:
- never: Never apply dark mode filter to any images.
- smart: "Apply dark mode based on image content. Not available with Qt
5.15.0."
+ - smart-simple: "On QtWebEngine 6.6, use a simpler algorithm for smart mode (based
+ on numbers of colors and transparency), rather than an ML-based model.
+ Same as 'smart' on older QtWebEnigne versions."
desc: >-
Which images to apply dark mode to.
-
- With QtWebEngine 5.15.0, this setting can cause frequent renderer process
- crashes due to a
- https://codereview.qt-project.org/c/qt/qtwebengine-chromium/+/304211[bug
- in Qt].
restart: true
backend: QtWebEngine
@@ -3335,6 +3325,9 @@ colors.webpage.darkmode.policy.page:
backend: QtWebEngine
colors.webpage.darkmode.threshold.text:
+ renamed: colors.webpage.darkmode.threshold.foreground
+
+colors.webpage.darkmode.threshold.foreground:
default: 256
type:
name: Int
@@ -3363,45 +3356,10 @@ colors.webpage.darkmode.threshold.background:
256 to never invert the color or to 0 to always invert it.
Note: This behavior is the opposite of
- `colors.webpage.darkmode.threshold.text`!
+ `colors.webpage.darkmode.threshold.foreground`!
restart: true
backend: QtWebEngine
-colors.webpage.darkmode.grayscale.all:
- default: false
- type: Bool
- desc: >-
- Render all colors as grayscale.
-
- This only has an effect when `colors.webpage.darkmode.algorithm` is set to
- `lightness-hsl` or `brightness-rgb`.
- restart: true
- backend: QtWebEngine
-
-colors.webpage.darkmode.grayscale.images:
- default: 0.0
- type:
- name: Float
- minval: 0.0
- maxval: 1.0
- desc: >-
- Desaturation factor for images in dark mode.
-
- If set to 0, images are left as-is. If set to 1, images are completely
- grayscale. Values between 0 and 1 desaturate the colors accordingly.
- restart: true
- backend: QtWebEngine
-
-colors.webpage.darkmode.increase_text_contrast:
- default: false
- type: Bool
- desc: >-
- Increase text contrast by drawing an outline of the uninverted color.
- restart: true
- backend:
- QtWebEngine: Qt 6.3
- QtWebKit: false
-
# emacs: '
## fonts
diff --git a/qutebrowser/config/qtargs.py b/qutebrowser/config/qtargs.py
index 4fa6aa43f..4358a0ece 100644
--- a/qutebrowser/config/qtargs.py
+++ b/qutebrowser/config/qtargs.py
@@ -282,7 +282,7 @@ _SettingValueType = Union[
[
version.WebEngineVersions,
],
- str,
+ Optional[str],
],
]
_WEBENGINE_SETTINGS: Dict[str, Dict[Any, Optional[_SettingValueType]]] = {
@@ -294,6 +294,7 @@ _WEBENGINE_SETTINGS: Dict[str, Dict[Any, Optional[_SettingValueType]]] = {
},
'content.canvas_reading': {
True: None,
+ # might be overridden in webenginesettings.py
False: '--disable-reading-from-canvas',
},
'content.webrtc_ip_handling_policy': {
@@ -336,9 +337,7 @@ _WEBENGINE_SETTINGS: Dict[str, Dict[Any, Optional[_SettingValueType]]] = {
'qt.workarounds.disable_accelerated_2d_canvas': {
'always': '--disable-accelerated-2d-canvas',
'never': None,
- 'auto': lambda _versions: 'always'
- if machinery.IS_QT6
- else 'never',
+ 'auto': '--disable-accelerated-2d-canvas' if machinery.IS_QT5 else None,
},
}
@@ -347,11 +346,7 @@ def _qtwebengine_settings_args(versions: version.WebEngineVersions) -> Iterator[
for setting, args in sorted(_WEBENGINE_SETTINGS.items()):
arg = args[config.instance.get(setting)]
if callable(arg):
- new_value = arg(versions)
- assert (
- new_value in args
- ), f"qt.settings feature detection returned an unrecognized value: {new_value} for {setting}"
- result = args[new_value]
+ result = arg(versions)
if result is not None:
assert isinstance(
result, str
diff --git a/tests/unit/browser/webengine/test_darkmode.py b/tests/unit/browser/webengine/test_darkmode.py
index 53d3246d6..bda05feb8 100644
--- a/tests/unit/browser/webengine/test_darkmode.py
+++ b/tests/unit/browser/webengine/test_darkmode.py
@@ -4,6 +4,7 @@
import logging
+from typing import List, Tuple
import pytest
@@ -103,7 +104,7 @@ QT_515_2_SETTINGS = {'blink-settings': [
('forceDarkModeEnabled', 'true'),
('forceDarkModeInversionAlgorithm', '2'),
('forceDarkModeImagePolicy', '2'),
- ('forceDarkModeGrayscale', 'true'),
+ ('forceDarkModeTextBrightnessThreshold', '100'),
]}
@@ -112,7 +113,16 @@ QT_515_3_SETTINGS = {
'dark-mode-settings': [
('InversionAlgorithm', '1'),
('ImagePolicy', '2'),
- ('IsGrayScale', 'true'),
+ ('TextBrightnessThreshold', '100'),
+ ],
+}
+
+QT_64_SETTINGS = {
+ 'blink-settings': [('forceDarkModeEnabled', 'true')],
+ 'dark-mode-settings': [
+ ('InversionAlgorithm', '1'),
+ ('ImagePolicy', '2'),
+ ('ForegroundBrightnessThreshold', '100'),
],
}
@@ -120,12 +130,13 @@ QT_515_3_SETTINGS = {
@pytest.mark.parametrize('qversion, expected', [
('5.15.2', QT_515_2_SETTINGS),
('5.15.3', QT_515_3_SETTINGS),
+ ('6.4', QT_64_SETTINGS),
])
def test_qt_version_differences(config_stub, qversion, expected):
settings = {
'enabled': True,
'algorithm': 'brightness-rgb',
- 'grayscale.all': True,
+ 'threshold.foreground': 100,
}
for k, v in settings.items():
config_stub.set_obj('colors.webpage.darkmode.' + k, v)
@@ -142,14 +153,10 @@ def test_qt_version_differences(config_stub, qversion, expected):
'PagePolicy', '1'),
('policy.images', 'smart',
'ImagePolicy', '2'),
- ('threshold.text', 100,
+ ('threshold.foreground', 100,
'TextBrightnessThreshold', '100'),
('threshold.background', 100,
'BackgroundBrightnessThreshold', '100'),
- ('grayscale.all', True,
- 'Grayscale', 'true'),
- ('grayscale.images', 0.5,
- 'ImageGrayscale', '0.5'),
])
def test_customization(config_stub, setting, value, exp_key, exp_val):
config_stub.val.colors.webpage.darkmode.enabled = True
@@ -163,15 +170,43 @@ def test_customization(config_stub, setting, value, exp_key, exp_val):
expected.append(('forceDarkModeImagePolicy', '2'))
expected.append(('forceDarkMode' + exp_key, exp_val))
- versions = version.WebEngineVersions.from_pyqt('5.15.2')
+ versions = version.WebEngineVersions.from_api(
+ qtwe_version='5.15.2',
+ chromium_version=None,
+ )
darkmode_settings = darkmode.settings(versions=versions, special_flags=[])
assert darkmode_settings['blink-settings'] == expected
+@pytest.mark.parametrize('qtwe_version, setting, value, expected', [
+ ('6.6.1', 'policy.images', 'always', [('ImagePolicy', '0')]),
+ ('6.6.1', 'policy.images', 'never', [('ImagePolicy', '1')]),
+ ('6.6.1', 'policy.images', 'smart', [('ImagePolicy', '2'), ('ImageClassifierPolicy', '0')]),
+ ('6.6.1', 'policy.images', 'smart-simple', [('ImagePolicy', '2'), ('ImageClassifierPolicy', '1')]),
+
+ ('6.5.3', 'policy.images', 'smart', [('ImagePolicy', '2')]),
+ ('6.5.3', 'policy.images', 'smart-simple', [('ImagePolicy', '2')]),
+])
+def test_image_policy(config_stub, qtwe_version: str, setting: str, value: str, expected: List[Tuple[str, str]]):
+ config_stub.val.colors.webpage.darkmode.enabled = True
+ config_stub.set_obj('colors.webpage.darkmode.' + setting, value)
+
+ versions = version.WebEngineVersions.from_api(
+ qtwe_version=qtwe_version,
+ chromium_version=None,
+ )
+ darkmode_settings = darkmode.settings(versions=versions, special_flags=[])
+ assert darkmode_settings['dark-mode-settings'] == expected
+
+
@pytest.mark.parametrize('webengine_version, expected', [
('5.15.2', darkmode.Variant.qt_515_2),
('5.15.3', darkmode.Variant.qt_515_3),
('6.2.0', darkmode.Variant.qt_515_3),
+ ('6.3.0', darkmode.Variant.qt_515_3),
+ ('6.4.0', darkmode.Variant.qt_64),
+ ('6.5.0', darkmode.Variant.qt_64),
+ ('6.6.0', darkmode.Variant.qt_66),
])
def test_variant(webengine_version, expected):
versions = version.WebEngineVersions.from_pyqt(webengine_version)