Skip to content

Commit

Permalink
Use screen number instead of panel index
Browse files Browse the repository at this point in the history
Now wallpaper plugins and their desktop window are in sync
  • Loading branch information
luisbocanegra committed Dec 5, 2023
1 parent 7dfda28 commit b05da94
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 30 deletions.
4 changes: 3 additions & 1 deletion src/kde_material_you_colors/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,9 @@ def main():
if wallpaper_data[1] is not None:
wallpaper_watcher.set_value(wallpaper_data)
else:
screenshot = wallpaper_utils.get_desktop_screenshot()
screenshot = wallpaper_utils.get_desktop_screenshot(
config_watcher.get_new_value()["monitor"]
)
# if screenshot is not None:
wallpaper_watcher.set_value(screenshot)

Expand Down
57 changes: 28 additions & 29 deletions src/kde_material_you_colors/utils/wallpaper_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,39 +46,39 @@ def get_wallpaper_data(monitor=0, file=None, color=None, light=None):
return (f"color:{color}", None, None, error)

else:
# Get current wallpaper plugin id
script = """
var desktops = desktops();
d = desktops[%s];
print(d.wallpaperPlugin)
"""
plugin = evaluate_script(script, monitor)

# Get wallpaper data
script = """
function getConfig(desktop, keys) {
for (const key of keys) {
script = f"""
function getConfig(desktop, keys) {{
for (const key of keys) {{
const value = desktop.readConfig(key);
if (value !== "") {
if (key == "Provider") {
if (value !== "") {{
if (key == "Provider") {{
return key + "," + value + "," + desktop.readConfig("Category");
}
}}
return key + "," + value;
}
}
}
}}
}}
}}
var desktops = desktops();
var desktop = desktops[%s];
var screen = {monitor}
if (screen > desktops.length) {{
screen = 0
}}
for (let i=0; i<desktops.length; i++) {{
if (desktops[i].screen == screen) {{
desktop = desktops[i];
break
}}
}}
var plugin = desktop.wallpaperPlugin
desktop.currentConfigGroup = Array("Wallpaper", plugin, "General");
const keys = ["Image", "Color","color","Provider"];
var config = getConfig(desktop, keys);
print(config);
print(plugin+","+config);
"""
# split type and wallpaper data, this allows commas in wallpaper data
script_output = evaluate_script(script, monitor).split(",", 1)
# wallpaper_data = script_output.split(",", 1)
# print(script_output)
# split type and wallpaper data, this allows commas in wallpaper name
plugin, script_output = evaluate_script(script).split(",", 1)
script_output = script_output.split(",", 1)

# special case for picture of the day plugin that requires a
# directory, provider and sometimes a category
Expand Down Expand Up @@ -169,10 +169,11 @@ def get_wallpaper_data(monitor=0, file=None, color=None, light=None):
)
return (plugin, "image", wallpaper)

# nothing matches
return (f"plugin:{plugin}", None, None, "Plugin unsupported")


def evaluate_script(script, monitor):
def evaluate_script(script):
"""Make a dbus call to org.kde.PlasmaShell.evaluateScript to get wallpaper data
Args:
Expand All @@ -188,9 +189,7 @@ def evaluate_script(script, monitor):
bus.get_object("org.kde.plasmashell", "/PlasmaShell"),
dbus_interface="org.kde.PlasmaShell",
)
wallpaper_data = str(plasma.evaluateScript(script % (monitor,))).replace(
"file://", ""
)
wallpaper_data = str(plasma.evaluateScript(script)).replace("file://", "")
return wallpaper_data
except Exception as e:
error = f"Error getting wallpaper from dbus:\n{e}"
Expand All @@ -199,9 +198,9 @@ def evaluate_script(script, monitor):
return ""


def get_desktop_screenshot():
def get_desktop_screenshot(screen=0):
# take screenshot of desktop
window_handle = kwin_utils.get_desktop_window_id(0) # TODO: make configurable
window_handle = kwin_utils.get_desktop_window_id(screen)
if window_handle is not None:
screenshot_taken = kwin_utils.screenshot_window(
window_handle, settings.SCREENSHOT_PATH
Expand Down

0 comments on commit b05da94

Please sign in to comment.