diff --git a/yin_yang/plugins/_plugin.py b/yin_yang/plugins/_plugin.py index 0568d08..05d43e5 100644 --- a/yin_yang/plugins/_plugin.py +++ b/yin_yang/plugins/_plugin.py @@ -118,7 +118,7 @@ def __str__(self): class PluginCommandline(Plugin): - def __init__(self, command: [str]): + def __init__(self, command: list[str]): """ :param command: list of arguments as passed to @subprocess.run, with the theme being inserted as {theme} """ @@ -174,7 +174,7 @@ def __init__(self, strategy_instance: Optional[Plugin]): logger.warning(f'Plugin {self.name} has no support for your desktop environment yet!') @property - def strategy(self) -> Plugin: + def strategy(self) -> Plugin | None: return self._strategy_instance @property diff --git a/yin_yang/plugins/gtk.py b/yin_yang/plugins/gtk.py index 7dad089..153e552 100755 --- a/yin_yang/plugins/gtk.py +++ b/yin_yang/plugins/gtk.py @@ -1,6 +1,7 @@ import logging from os import scandir, path from pathlib import Path +import subprocess from PySide6.QtDBus import QDBusConnection, QDBusMessage @@ -79,7 +80,23 @@ def set_theme(self, theme: str): 'setGtkTheme' ) message.setArguments([theme]) - connection.call(message) + response = connection.call(message) + if response.type() == QDBusMessage.MessageType.ErrorMessage: + logger.warning('kde-gtk-config not available, try xsettingsd') + xsettingsd_conf_path = Path.home() / '.config' / 'xsettingsd' / 'xsettingsd.conf' + if not xsettingsd_conf_path.exists(): + logger.warning('xsettingsd not available') + with open(xsettingsd_conf_path, 'r') as f: + lines = f.readlines() + for i, line in enumerate(lines): + if line.startswith('Net/ThemeName'): + lines[i] = f'Net/ThemeName "{theme}"\n' + break + with open(xsettingsd_conf_path, 'w') as f: + f.writelines(lines) + subprocess.run(['killall', '-HUP', 'xsettingsd']) + else: + logger.debug('Success by kde-gtk-config') class _Xfce(PluginCommandline): diff --git a/yin_yang/plugins/konsole.py b/yin_yang/plugins/konsole.py index 8f10d5d..ebe8a56 100644 --- a/yin_yang/plugins/konsole.py +++ b/yin_yang/plugins/konsole.py @@ -74,6 +74,7 @@ def set_mode(self, dark: bool) -> bool: logger.debug(f'Changing profile in konsole session {proc_id}') set_profile(f'org.kde.konsole-{proc_id}', profile) + set_profile('org.kde.konsole', profile) # konsole may don't have session dbus like above set_profile('org.kde.yakuake', profile) process_ids = [ @@ -174,8 +175,11 @@ def default_profile(self, value: str): # If a match is found, return the content of the wildcard '*' if match: + logger.debug(f'Changing default profile to {value}') lines[i] = f'DefaultProfile={value}\n' break + else: + logger.debug('No default profile found') with self.config_path.open('w') as file: file.writelines(lines) @@ -238,9 +242,16 @@ def set_profile(service: str, profile: str): try: sessions = subprocess.check_output(f'qdbus {service} | grep "Sessions/"', shell=True) except subprocess.CalledProcessError: - # happens when dolphins konsole is not opened - logger.debug(f'No Konsole sessions available in service {service}, skipping') - return + try: + sessions = subprocess.check_output( + f'qdbus org.kde.konsole | grep "Sessions/"', shell=True + ) + logger.debug(f'Found org.kde.konsole, use that instead') + service = "org.kde.konsole" + except subprocess.CalledProcessError: + # happens when dolphins konsole is not opened + logger.debug(f'No Konsole sessions available in service {service}, skipping') + return sessions = sessions.decode('utf-8').removesuffix('\n').split('\n') # loop: process sessions