initial commit
This commit is contained in:
commit
06dc4f8e5a
6 changed files with 90 additions and 0 deletions
8
Makefile
Normal file
8
Makefile
Normal 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
17
backgrounds.example.json
Normal 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
43
swaybg-swapper.py
Executable 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])
|
14
systemd/swaybg-swapper.service
Normal file
14
systemd/swaybg-swapper.service
Normal 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
|
6
systemd/swaybg-swapper.timer
Normal file
6
systemd/swaybg-swapper.timer
Normal file
|
@ -0,0 +1,6 @@
|
|||
[Unit]
|
||||
Description=Executes swaybg-swapper.service
|
||||
[Timer]
|
||||
OnUnitInactiveSec=60m
|
||||
[Install]
|
||||
WantedBy=timers.target
|
2
timer.example.conf
Normal file
2
timer.example.conf
Normal file
|
@ -0,0 +1,2 @@
|
|||
[Timer]
|
||||
OnUnitInactiveSec=60m
|
Loading…
Reference in a new issue