diff --git a/qutebrowser/config/configinit.py b/qutebrowser/config/configinit.py index 1b4157ece..c76efba00 100644 --- a/qutebrowser/config/configinit.py +++ b/qutebrowser/config/configinit.py @@ -75,6 +75,7 @@ def early_init(args): message.error("set: {} - {}".format(e.__class__.__name__, e)) configtypes.Font.monospace_fonts = config.val.fonts.monospace + config.instance.changed.connect(_update_monospace_fonts) _init_envvars() @@ -94,6 +95,21 @@ def _init_envvars(): os.environ.pop('QT_WAYLAND_DISABLE_WINDOWDECORATION', None) +@config.change_filter('fonts.monospace', function=True) +def _update_monospace_fonts(): + """Update all fonts if fonts.monospace was set.""" + configtypes.Font.monospace_fonts = config.val.fonts.monospace + for name, opt in configdata.DATA.items(): + if name == 'fonts.monospace': + continue + elif not isinstance(opt.typ, configtypes.Font): + continue + elif not config.instance.get_obj(name).endswith(' monospace'): + continue + + config.instance.changed.emit(name) + + def get_backend(args): """Find out what backend to use based on available libraries.""" str_to_backend = { diff --git a/tests/unit/config/test_configinit.py b/tests/unit/config/test_configinit.py index 912ded304..9ece48bdb 100644 --- a/tests/unit/config/test_configinit.py +++ b/tests/unit/config/test_configinit.py @@ -211,6 +211,22 @@ class TestEarlyInit: assert config.instance.get('fonts.keyhint') == '8pt "Comic Sans MS"' assert config.instance.get('fonts.tabs').family() == 'Comic Sans MS' + def test_monospace_fonts_later(self, init_patch, args): + """Ensure setting fonts.monospace after init works properly. + + See https://github.com/qutebrowser/qutebrowser/issues/2973 + """ + configinit.early_init(args) + changed_options = [] + config.instance.changed.connect(changed_options.append) + + config.instance.set_obj('fonts.monospace', '"Comic Sans MS"') + + assert 'fonts.keyhint' in changed_options + assert config.instance.get('fonts.keyhint') == '8pt "Comic Sans MS"' + assert 'fonts.tabs' in changed_options + assert config.instance.get('fonts.tabs').family() == 'Comic Sans MS' + def test_force_software_rendering(self, monkeypatch, config_stub): """Setting force_software_rendering should set the environment var.""" envvar = 'QT_XCB_FORCE_SOFTWARE_OPENGL'