aboutsummaryrefslogtreecommitdiffstats
path: root/bin/udt-accent
diff options
context:
space:
mode:
Diffstat (limited to 'bin/udt-accent')
-rwxr-xr-xbin/udt-accent66
1 files changed, 49 insertions, 17 deletions
diff --git a/bin/udt-accent b/bin/udt-accent
index 8f85b4c..5bb324b 100755
--- a/bin/udt-accent
+++ b/bin/udt-accent
@@ -7,6 +7,7 @@
Usage: udt-accent <wallpaper-path>
udt-accent --selftest
+ udt-accent --help
The extraction reads the image's pixels itself rather than running `wal -i`,
because `wal -i` rewrites the whole ~/.cache/wal directory (which this no
@@ -403,23 +404,29 @@ def write_firefox(image):
A file, not a link: Firefox's sandbox refuses to follow a symlink out of
the profile, and the new tab shows nothing. Every profile without FF
Ultima is skipped.
+
+ A failure is reported, not raised: the new tab is cosmetic, and main()
+ still has GRUB, the homepage and the helpers to do after it.
"""
from PIL import Image, ImageFilter
- blurred = None
- for walls in (Path.home() / ".mozilla" / "firefox").glob(f"*/{FIREFOX_WALLS}"):
- if blurred is None:
- with Image.open(image) as im:
- im = im.convert("RGB")
- # Detail is blurred away anyway, so 1920 wide is plenty and
- # keeps the blur fast on a 4K wallpaper.
- im.thumbnail((1920, 1920))
- blurred = im.filter(ImageFilter.GaussianBlur(FIREFOX_BLUR))
- dest = walls / "darknix.png"
- # A leftover link would make save write through it into the
- # wallpaper itself.
- dest.unlink(missing_ok=True)
- blurred.save(dest, "PNG")
+ try:
+ blurred = None
+ for walls in (Path.home() / ".mozilla" / "firefox").glob(f"*/{FIREFOX_WALLS}"):
+ if blurred is None:
+ with Image.open(image) as im:
+ im = im.convert("RGB")
+ # Detail is blurred away anyway, so 1920 wide is plenty
+ # and keeps the blur fast on a 4K wallpaper.
+ im.thumbnail((1920, 1920))
+ blurred = im.filter(ImageFilter.GaussianBlur(FIREFOX_BLUR))
+ dest = walls / "darknix.png"
+ # A leftover link would make save write through it into the
+ # wallpaper itself.
+ dest.unlink(missing_ok=True)
+ blurred.save(dest, "PNG")
+ except Exception as exc:
+ print(f"udt-accent: firefox new tab not updated: {exc}", file=sys.stderr)
def rewrite(path, pattern, value):
@@ -844,14 +851,39 @@ def selftest():
got = power_icons()
assert set(got) == {"powerIcon", "rebootIcon", "suspendIcon", "hibernateIcon"}
+ # write_firefox: a real image lands blurred and capped at 1920, and a
+ # broken one is reported rather than raised, so main() carries on.
+ from PIL import Image
+ with tempfile.TemporaryDirectory() as tmp:
+ home = os.environ.get("HOME")
+ os.environ["HOME"] = tmp
+ try:
+ walls = Path(tmp) / ".mozilla" / "firefox" / "p.default" / FIREFOX_WALLS
+ walls.mkdir(parents=True)
+ src = Path(tmp) / "wall.png"
+ Image.new("RGB", (3840, 2160), "#336699").save(src)
+ write_firefox(src)
+ with Image.open(walls / "darknix.png") as out:
+ assert out.size == (1920, 1080) and out.mode == "RGB", out
+ bad = Path(tmp) / "bad.jpg"
+ bad.write_text("not an image")
+ write_firefox(bad)
+ finally:
+ os.environ["HOME"] = home
+
print("selftest OK")
if __name__ == "__main__":
- if len(sys.argv) == 2 and sys.argv[1] == "--selftest":
+ args = sys.argv[1:]
+ if args == ["--selftest"]:
selftest()
- elif len(sys.argv) == 2:
- main(sys.argv[1])
+ elif args in (["-h"], ["--help"]):
+ print(__doc__)
+ elif len(args) == 1 and not args[0].startswith("-") and os.path.isfile(args[0]):
+ main(args[0])
else:
+ # An unknown option or a missing file would otherwise be taken as the
+ # wallpaper, and its path written into SDDM's config and colors.json.
print(__doc__, file=sys.stderr)
sys.exit(2)