File: random-wallpaper

package info (click to toggle)
fvwm-crystal 3.3.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 19,748 kB
  • ctags: 793
  • sloc: sh: 2,815; cs: 880; python: 875; makefile: 212
file content (60 lines) | stat: -rwxr-xr-x 1,443 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash

# set ramdom wallpapers from the ones in $FVWM_USERDIR/wallpapers/*
# it follow the symlinks; but all the pictures must be in child directories
# USAGE:
# 'Exec exec random-wallpaper' will set a randdom wallpaper and exit
# 'Êxec exec random-wallpaper loop <delay>' will loop and set wallpaper at <delay> in secondes interval

# PID to kill if fvwm is interrupted
TMPFILE="/tmp/crystal_wallpaper_$$"

cleanup() {
	rm "${TMPFILE}"
	FvwmCommand 'UnsetEnv LOOPWP'
	exit 0
}

trap cleanup INT QUIT TERM

# set random wallpaper
set_uniquewp() {
	WPS=""
	n=0
	for i in ${FVWM_USERDIR}/wallpapers/*; do
		WPS[${n}]="$i"
		let n++;
	done
	WPS=\'$(fvwm-crystal.wallpaper "${WPS[0]}" "${WPS[1]}" "${WPS[2]}" "${WPS[3]}" "${WPS[4]}" "${WPS[5]}" "${WPS[6]}" "${WPS[7]}" "${WPS[8]}" "${WPS[9]}" "${WPS[10]}")\'
	FvwmCommand "SavePreferences LastChoosenWallpaper \"Wallpaper-Set ${WPS}\""
	echo $WPS
	sleep 0.1
	FvwmCommand 'LoadPreferences LastChoosenWallpaper'
}

# loop random wallpaper
set_loopwp() {
	touch "${TMPFILE}"
	while :; do
		set_uniquewp
		sleep $1
		# fvwm is started with exec, be sure it is running
		pidof fvwm 1>/dev/null || cleanup
	done
}

# main program
SCRIPTID="$$"

if [[ "$1" = "loop" ]]; then
	if [[ "${LOOPWP}" = "" ]]; then
		FvwmCommand "SetEnv LOOPWP ${SCRIPTID}"
		set_loopwp $2
	else	kill "${LOOPWP}" 2>/dev/null
		sleep 0.5
		FvwmCommand "SetEnv LOOPWP ${SCRIPTID}"
		set_loopwp $2
	fi
else
	set_uniquewp
fi