Skip to content

Commit

Permalink
Merge pull request #260 from heddxh/master
Browse files Browse the repository at this point in the history
Fix konsole dbus call and  modify xsettingsd on kde as a fallback method
  • Loading branch information
l0drex authored Jan 16, 2024
2 parents 4e62e54 + ebb016b commit 1d5c01c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
4 changes: 2 additions & 2 deletions yin_yang/plugins/_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
"""
Expand Down Expand Up @@ -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
Expand Down
19 changes: 18 additions & 1 deletion yin_yang/plugins/gtk.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
from os import scandir, path
from pathlib import Path
import subprocess

from PySide6.QtDBus import QDBusConnection, QDBusMessage

Expand Down Expand Up @@ -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):
Expand Down
17 changes: 14 additions & 3 deletions yin_yang/plugins/konsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1d5c01c

Please sign in to comment.