Skip to content

Commit

Permalink
Merge branch 'imnofox-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
boramalper committed Aug 5, 2016
2 parents d7ed5a6 + 0f2bf76 commit be626be
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ near-realtime picture of Earth.
* OS X
* GNOME 3
* Cinnamon 2.8.8

### Not Tested

* KDE

### Not Supported
Expand Down Expand Up @@ -91,6 +88,13 @@ If you use nitrogen for setting your wallpaper, you have to enter this in your
systemctl --user enable --now himawaripy.timer

### For KDE Users
#### KDE 5.7+
To change the wallpaper in KDE 5.7+, desktop widgets must be unlocked. If you dom't want to leave them unlocked, the pre-KDE 5.7 method can still be used.

To unlock desktop widgets ([from the KDE userbase](https://userbase.kde.org/Plasma#Widgets)):
> Open the Desktop Toolbox or the Panel Toolbox or right click on the Desktop - if you see an item labeled Unlock Widgets then select that, and then proceed to add widgets to your Desktop or your Panel.
#### Before KDE 5.7
> So the issue here is that KDE does not support changing the desktop wallpaper
> from the commandline, but it does support polling a directory for file changes
> through the "Slideshow" desktop background option, whereby you can point KDE
Expand Down
38 changes: 38 additions & 0 deletions himawaripy/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os
import re
import sys
import subprocess
from distutils.version import LooseVersion

from .config import xfce_displays

Expand Down Expand Up @@ -30,6 +32,32 @@ def set_background(file_path):
'repeat with aDesktop in theDesktops\n'
'set the picture of aDesktop to \"' + file_path + '"\nend repeat\nend tell'])
subprocess.call(["killall", "Dock"])
elif de == "kde":
if plasma_version() > LooseVersion("5.7"):
''' Command per https://github.com/boramalper/himawaripy/issues/57
Sets 'FillMode' to 1, which is "Scaled, Keep Proportions"
Forces 'Color' to black, which sets the background colour.
'''
script = 'var a = desktops();' \
'for (i = 0; i < a.length; i++) {{' \
'd = a[i];d.wallpaperPlugin = "org.kde.image";' \
'd.currentConfigGroup = Array("Wallpaper", "org.kde.image", "General");' \
'd.writeConfig("Image", "file://{}");' \
'd.writeConfig("FillMode", 1);' \
'd.writeConfig("Color", "#000");' \
'}}'
try:
subprocess.check_output(["qdbus", "org.kde.plasmashell", "/PlasmaShell",
"org.kde.PlasmaShell.evaluateScript", script.format(file_path)])
except subprocess.CalledProcessError as e:
if "Widgets are locked" in e.output.decode("utf-8"):
print("!! Cannot change the wallpaper while widgets are locked.")
print("!! Please unlock widgets to allow wallpaper changing.\n")
else:
print(e)
else:
print("\nCouldn't detect plasmashell 5.7 or higher.")
elif has_program("feh"):
print("\nCouldn't detect your desktop environment ('{}'), but you have"
"'feh' installed so we will use it.".format(de))
Expand Down Expand Up @@ -114,6 +142,16 @@ def has_program(program):
return False


def plasma_version():
try:
output = subprocess.Popen(["plasmashell", "-v"], stdout=subprocess.PIPE).communicate()[0].decode("utf-8")
print("\nRunning", output)
version = re.match(r"plasmashell (.*)", output).group(1)
return LooseVersion(version)
except (subprocess.CalledProcessError, IndexError):
return LooseVersion("")


def is_running(process):
try:
subprocess.check_output(["pidof", "--", process])
Expand Down

0 comments on commit be626be

Please sign in to comment.