Skip to content

Commit

Permalink
Port wallpaper plugin to new dbus plugin
Browse files Browse the repository at this point in the history
Add dconf/gsettings as fallback method
  • Loading branch information
heddxh committed Apr 17, 2024
1 parent 5d14a9a commit 508a323
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions yin_yang/plugins/gtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 508a323

Please sign in to comment.