initial commit

This commit is contained in:
alterNERDtive 2023-11-02 17:16:32 +01:00
commit 06dc4f8e5a
Signed by: alterNERDtive
GPG key ID: 547787A4FE6533F1
6 changed files with 90 additions and 0 deletions

8
Makefile Normal file
View file

@ -0,0 +1,8 @@
all: install
install:
mkdir -p ~/.local/bin
cp swaybg-swapper.py ~/.local/bin
cp systemd/swaybg-swapper.{service,timer} ~/.config/systemd/user/
systemctl --user daemon-reload
systemctl --user enable --now swaybg-swapper.timer

17
backgrounds.example.json Normal file
View file

@ -0,0 +1,17 @@
{
"DP-0": [
{
"file": "test.png",
"transform": "fill",
"colour": "#000000"
},
{ "file": "empty.png" }
],
"DP-1": [
{ "file": "foo.png" },
{
"file": "bar.jpg",
"transform": "fit"
}
]
}

43
swaybg-swapper.py Executable file
View file

@ -0,0 +1,43 @@
#!/usr/bin/env python
import json
import random
import subprocess
import time
import os.path
pidof = subprocess.run(["pidof", "swaybg"], capture_output=True)
pids = None
if pidof.returncode == 0:
pids = pidof.stdout[:-1]
file = "~/.config/sway/backgrounds.json"
if not os.path.isfile(os.path.expanduser(file)):
print("Config file “{}” not found".format(file))
exit(1)
with open(os.path.expanduser(file)) as config_file:
config = json.load(config_file)
cmd=["swaybg"]
for item in config:
output = config[item]
background = output[random.randrange(len(output))]
cmd.extend(["-o", item, "-i", os.path.expanduser(background["file"])])
if "transform" in background:
cmd.extend(["-m", background["transform"]])
else:
cmd.extend(["-m", "center"])
if "colour" in background:
cmd.extend(["-c", background["colour"]])
else: cmd.extend(["-c", "#000000"])
# avoid ugly flickering by
# 1. running new `swaybg`
# 2. waiting!
# 3. killing old `swaybg`(s)
subprocess.Popen(cmd)
time.sleep(1)
if pids is not None:
for pid in pids.split():
subprocess.run(["kill", pid])

View file

@ -0,0 +1,14 @@
[Unit]
Description=Background swapper for sway/swaybg
PartOf=sway-session.target
[Service]
Type=oneshot
ExecStart=python %h/.local/bin/swaybg-swapper.py
Restart=on-failure
RestartSec=1
TimeoutStopSec=10
KillMode=process
[Install]
WantedBy=sway-session.target

View file

@ -0,0 +1,6 @@
[Unit]
Description=Executes swaybg-swapper.service
[Timer]
OnUnitInactiveSec=60m
[Install]
WantedBy=timers.target

2
timer.example.conf Normal file
View file

@ -0,0 +1,2 @@
[Timer]
OnUnitInactiveSec=60m