Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix konsole dbus call and modify xsettingsd on kde as a fallback method #260

Merged
merged 5 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'])
l0drex marked this conversation as resolved.
Show resolved Hide resolved
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
heddxh marked this conversation as resolved.
Show resolved Hide resolved
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