diff --git a/src/kde_material_you_colors/apply_themes.py b/src/kde_material_you_colors/apply_themes.py index a7a8939..a99880d 100644 --- a/src/kde_material_you_colors/apply_themes.py +++ b/src/kde_material_you_colors/apply_themes.py @@ -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 ( @@ -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"), @@ -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( ( @@ -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"), diff --git a/src/kde_material_you_colors/config.py b/src/kde_material_you_colors/config.py index d0a28b2..67d24af 100644 --- a/src/kde_material_you_colors/config.py +++ b/src/kde_material_you_colors/config.py @@ -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): diff --git a/src/kde_material_you_colors/main.py b/src/kde_material_you_colors/main.py index 5b9dc0a..481b397 100755 --- a/src/kde_material_you_colors/main.py +++ b/src/kde_material_you_colors/main.py @@ -334,6 +334,14 @@ def main(): metavar="", ) + 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="", + ) + # Get commandline arguments args = parser.parse_args() # Check for one shot arguments diff --git a/src/kde_material_you_colors/utils/konsole_utils.py b/src/kde_material_you_colors/utils/konsole_utils.py index 2d2eeab..e15d076 100644 --- a/src/kde_material_you_colors/utils/konsole_utils.py +++ b/src/kde_material_you_colors/utils/konsole_utils.py @@ -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" @@ -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: @@ -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, diff --git a/src/kde_material_you_colors/utils/kwin_utils.py b/src/kde_material_you_colors/utils/kwin_utils.py index 01bbd89..6d651cb 100644 --- a/src/kde_material_you_colors/utils/kwin_utils.py +++ b/src/kde_material_you_colors/utils/kwin_utils.py @@ -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, @@ -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: @@ -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", @@ -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_ @@ -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 diff --git a/src/kde_material_you_colors/utils/wallpaper_utils.py b/src/kde_material_you_colors/utils/wallpaper_utils.py index b77eb77..3cfd30d 100644 --- a/src/kde_material_you_colors/utils/wallpaper_utils.py +++ b/src/kde_material_you_colors/utils/wallpaper_utils.py @@ -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 @@ -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) @@ -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 diff --git a/src/plasmoid/package/contents/ui/FullRepresentation.qml b/src/plasmoid/package/contents/ui/FullRepresentation.qml index 108f82d..2574d52 100644 --- a/src/plasmoid/package/contents/ui/FullRepresentation.qml +++ b/src/plasmoid/package/contents/ui/FullRepresentation.qml @@ -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"); @@ -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" @@ -2029,6 +2079,13 @@ ColumnLayout { } } + FileDialog { + id: fileDialogQdbusExec + onAccepted: { + mainLayout.settings.qdbus_executable = fileDialogQdbusExec.fileUrl.toString().substring(7) + } + } + FileDialog { id: fileDialogBackendExec onAccepted: {