diff --git a/yin_yang/plugins/gtk.py b/yin_yang/plugins/gtk.py index 1a5eb20..c24ee2f 100755 --- a/yin_yang/plugins/gtk.py +++ b/yin_yang/plugins/gtk.py @@ -79,48 +79,52 @@ def available(self) -> bool: class _Kde(DBusPlugin): - name = 'GTK' + @property + def name(self): + return 'GTK' def __init__(self): super().__init__() self.theme_light = 'Breeze' self.theme_dark = 'Breeze' + self.message_data = ['org.kde.GtkConfig', '/GtkConfig', 'org.kde.GtkConfig', 'setGtkTheme'] - def create_message(self, theme: str) -> QDBusMessage: - message = QDBusMessage.createMethodCall( - 'org.kde.GtkConfig', - '/GtkConfig', - 'org.kde.GtkConfig', - 'setGtkTheme' - ) - message.setArguments([theme]) - return message + def create_message(self, theme: str): + self.message = QDBusMessage.createMethodCall(*self.message_data) + self.message.setArguments([theme]) def set_theme(self, theme: str): - response = self.call(self.create_message(theme)) + """Call DBus interface of kde-ftk-config if installed. + Otherwise try changing xsettingsd's conf and dconf""" - if response.type() != QDBusMessage.MessageType.ErrorMessage: + if self.connection.interface().isServiceRegistered('org.kde.GtkConfig'): + super().set_theme(theme) return - logger.warning('kde-gtk-config not available, trying xsettingsd') + # User don't have kde-gtk-config installed, try xsettingsd and dconf + logger.warning('kde-gtk-config not available, trying xsettingsd and dconf') + + # xsettingsd xsettingsd_conf_path = Path.home() / '.config/xsettingsd/xsettingsd.conf' if not xsettingsd_conf_path.exists(): logger.warning('xsettingsd not available') return - 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) - # send signal to read new config subprocess.run(['killall', '-HUP', 'xsettingsd']) + # change dconf db. since dconf sending data as GVariant, use gsettings instead + subprocess.run(['gsettings', 'set', 'org.gnome.desktop.interface', 'gtk-theme', '{theme}']) + color_scheme = 'prefer-dark' if theme == self.theme_dark else 'prefer-light' + subprocess.run(['gsettings', 'set', 'org.gnome.desktop.interface', 'color-scheme', f'{color_scheme}']) + class _Xfce(PluginCommandline): def __init__(self):