Skip to content

Commit

Permalink
Allow custom qdbus executable name
Browse files Browse the repository at this point in the history
Also raise kwin log level to default KWin scripting debug level
  • Loading branch information
luisbocanegra committed May 20, 2024
1 parent 0939a52 commit e06de47
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 18 deletions.
15 changes: 11 additions & 4 deletions src/kde_material_you_colors/apply_themes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import json
import logging
from kde_material_you_colors import schemeconfigs
from kde_material_you_colors import settings
from kde_material_you_colors.config import Configs
from kde_material_you_colors.utils.wallpaper_utils import WallpaperReader
from kde_material_you_colors.utils import (
Expand All @@ -17,6 +16,14 @@

def apply(config: Configs, wallpaper: WallpaperReader, dark_light):
needs_kwin_reload = False
qdbus_executable = config.read("qdbus_executable")
if qdbus_executable is None:
qdbus_executable = "qdbus6"
if utils.find_executable(qdbus_executable) is None:
logging.error(
f"QDbus executable '{qdbus_executable}' wasn't found, there will be errors. Please set the correct one in the configuration"
)

material_colors = m3_scheme_utils.get_color_schemes(
wallpaper,
config.read("ncolor"),
Expand Down Expand Up @@ -71,7 +78,7 @@ def apply(config: Configs, wallpaper: WallpaperReader, dark_light):
dark_light=dark_light,
)
if config.read("disable_konsole") is not True:
konsole_utils.apply_color_scheme()
konsole_utils.apply_color_scheme(qdbus_executable)
if config.read("darker_window_list"):
titlebar_utils.kwin_rule_darker_titlebar(
(
Expand All @@ -90,7 +97,7 @@ def apply(config: Configs, wallpaper: WallpaperReader, dark_light):
dark_light=dark_light,
)
if needs_kwin_reload is True:
kwin_utils.reload()
kwin_utils.reload(qdbus_executable)
pywal_utils.print_color_palette(
light=config.read("light"),
pywal_light=config.read("pywal_light"),
Expand Down
1 change: 1 addition & 0 deletions src/kde_material_you_colors/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ def defaults(self):
"scheme_variant": [args.scheme_variant, 5, 1],
"chroma_multiplier": [args.chroma_multiplier, 1, 2],
"tone_multiplier": [args.tone_multiplier, 1, 2],
"qdbus_executable": [args.qdbus_executable, None, 3],
}

def parse_conf(self):
Expand Down
8 changes: 8 additions & 0 deletions src/kde_material_you_colors/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,14 @@ def main():
metavar="<float>",
)

parser.add_argument(
"--qdbus-executable",
type=str,
help="Name or location of the QDbus executable e.g qdbus6, qdbus-qt6... (default is qdbus6)",
default=None,
metavar="<string>",
)

# Get commandline arguments
args = parser.parse_args()
# Check for one shot arguments
Expand Down
8 changes: 4 additions & 4 deletions src/kde_material_you_colors/utils/konsole_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def export_scheme(
config.write(configfile, space_around_delimiters=False)


def apply_color_scheme():
def apply_color_scheme(qdbus_executable: str):
"""Applies the color scheme to the existing default profile or a new one"""
profile_name = set_default_profile(settings.KONSOLE_DEFAULT_THEMED_PROFILE)
profile_path = settings.KONSOLE_DIR + profile_name + ".profile"
Expand Down Expand Up @@ -157,10 +157,10 @@ def apply_color_scheme():
except Exception as e:
logging.exception(f"Error applying Konsole profile:\n{e}")

reload_profile(profile_name)
reload_profile(profile_name, qdbus_executable)


def reload_profile(profile: str):
def reload_profile(profile: str, qdbus_executable: str):
"""Reload the konsole profile for all running konsole sessions
Args:
Expand All @@ -180,7 +180,7 @@ def reload_profile(profile: str):
for service in konsole_dbus_services:
try:
# get open sessions (tabs and splits)
cmd = ["qdbus", service]
cmd = [qdbus_executable, service]
result = subprocess.run(
cmd,
stdout=subprocess.PIPE,
Expand Down
17 changes: 10 additions & 7 deletions src/kde_material_you_colors/utils/kwin_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
from kde_material_you_colors import settings


def reload():
def reload(qdbus_executable: str):
logging.info(f"Reloading KWin")
subprocess.Popen(
"qdbus org.kde.KWin /KWin reconfigure",
qdbus_executable + " org.kde.KWin /KWin reconfigure",
shell=True,
stderr=subprocess.DEVNULL,
stdout=subprocess.DEVNULL,
Expand All @@ -29,7 +29,7 @@ def blend_changes():
)


def load_desktop_window_id_script():
def load_desktop_window_id_script(qdbus_executable: str):
# based on https://github.com/jinliu/kdotool/blob/master/src/main.rs 7eebebe
is_loaded = False
try:
Expand Down Expand Up @@ -65,7 +65,7 @@ def load_desktop_window_id_script():
try:
# Construct the command with the necessary arguments
command = [
"qdbus",
qdbus_executable,
"org.kde.KWin",
"/Scripting",
"org.kde.kwin.Scripting.loadScript",
Expand Down Expand Up @@ -93,7 +93,9 @@ def load_desktop_window_id_script():
raise


def get_desktop_window_id(screen: int = 0) -> str | None:
def get_desktop_window_id(
screen: int = 0, qdbus_executable: str = "qdbus6"
) -> str | None:
# based on https://github.com/jinliu/kdotool/blob/master/src/main.rs 7eebebe
"""_summary_
Expand Down Expand Up @@ -124,14 +126,15 @@ def get_desktop_window_id(screen: int = 0) -> str | None:
// it seems the list of windows is sorted by the screens positions(?)
// and (at least on my machine) this works for any arrangement
//desktopWindows.sort((b,a) => (a.pos.x - b.pos.x))
print("KMYC-desktop-window-id:", desktopWindows[{screen}].id)
// FIXME: Use callDBus + dbus service instead
console.error("KMYC-desktop-window-id:", desktopWindows[{screen}].id)
"""
with open(settings.KWIN_DESKTOP_ID_JSCRIPT, "w", encoding="utf-8") as js:
js.write(script_str)

# Load the script using qdbus
try:
script_id = load_desktop_window_id_script()
script_id = load_desktop_window_id_script(qdbus_executable)
except Exception as error:
logging.error(error)
raise
Expand Down
9 changes: 6 additions & 3 deletions src/kde_material_you_colors/utils/wallpaper_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def __init__(self, config: Configs):
self._file = config.read("file")
self._color = config.read("color")
self._light = config.read("light")
self._qdbus_executable = config.read("qdbus_executable") or "qdbus6"
self._plugin = None
self._type = None
self._source = None
Expand Down Expand Up @@ -96,7 +97,9 @@ def screenshot(self, skip_screenshot):
self._error = "Screenshot helper is not installed. Use another wallpaper plugin or install the helper"
return
try:
screenshot_taken = get_desktop_screenshot(self._monitor)
screenshot_taken = get_desktop_screenshot(
self._monitor, self._qdbus_executable
)
except Exception as e:
logging.exception(e)
self._error = str(e)
Expand Down Expand Up @@ -222,10 +225,10 @@ def evaluate_script(script: str):
return script_output


def get_desktop_screenshot(screen=0):
def get_desktop_screenshot(screen=0, qdbus_executable="qdbus6"):
# take screenshot of desktop
try:
window_handle = kwin_utils.get_desktop_window_id(screen)
window_handle = kwin_utils.get_desktop_window_id(screen, qdbus_executable)
except Exception as e:
logging.exception(e)
raise
Expand Down
57 changes: 57 additions & 0 deletions src/plasmoid/package/contents/ui/FullRepresentation.qml
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,7 @@ ColumnLayout {
property int scheme_variant: 5; \
property real chroma_multiplier: 1.0; \
property real tone_multiplier: 1.0; \
property string qdbus_executable; \
}';

settings = Qt.createQmlObject(settingsString, mainLayout, "settingsObject");
Expand Down Expand Up @@ -1795,6 +1796,55 @@ ColumnLayout {
opacity: dividerOpacity
}

RowLayout {
Layout.alignment: Qt.AlignHCenter
PlasmaExtras.Heading {
level: 1
text: "QDbus executable"
}
PlasmaComponents3.ToolButton {
id: qdbusInfoBtn
icon.name: "help-hint"
opacity: 0.7
hoverEnabled: true
onClicked: qdbusInfoPopup.open()

PlasmaComponents3.ToolTip {
id: qdbusInfoPopup
x: qdbusInfoBtn.width / 2
y: qdbusInfoBtn.height
text: "Name or location of the QDbus executable e.g qdbus6, qdbus-qt6... (default is qdbus6)"
}
}
}

RowLayout {
PlasmaComponents3.Label {
text: "Executable"
}
PlasmaComponents3.TextField {
placeholderText: qsTr("e.g qdbus6, qdbus-qt6... (default is qdbus6)")
Layout.fillWidth: true
text: settings.qdbus_executable
onAccepted: {
settings.qdbus_executable = text
}
}
PlasmaComponents3.Button {
icon.name: "document-open"
onClicked: {
fileDialogQdbusExec.open()
}
}
}

Rectangle {
Layout.preferredWidth: mainLayout.width
height: 1
color: dividerColor
opacity: dividerOpacity
}

PlasmaExtras.Heading {
level: 1
text: "Delay & screenshot options"
Expand Down Expand Up @@ -2029,6 +2079,13 @@ ColumnLayout {
}
}

FileDialog {
id: fileDialogQdbusExec
onAccepted: {
mainLayout.settings.qdbus_executable = fileDialogQdbusExec.fileUrl.toString().substring(7)
}
}

FileDialog {
id: fileDialogBackendExec
onAccepted: {
Expand Down

0 comments on commit e06de47

Please sign in to comment.