forked from ThreadR-r/animwall
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathanimwall
More file actions
executable file
·186 lines (165 loc) · 5.14 KB
/
animwall
File metadata and controls
executable file
·186 lines (165 loc) · 5.14 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/bin/sh
#
# The GPLv2 License
#
# Copyright (C) 2020 Peter Kenji Yamanaka
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# Lowest priority, super nice (make this number smaller to increase priority, cannot go below 0)
__nice_value=19
# $1 wallpaper
# $2 geometry
# $3 screen
start_wallpaper()
{
printf -- '[ANIMWALL]: Launching...\n'
printf -- ' Wallpaper: "%s"\n' "$1"
printf -- ' Geometry: "%s"\n' "$2"
printf -- ' Screen: "%s"\n' "$3"
# Options "-un" only used by xwinwrap-git
# Will not work with shantz-xwinwrap-git
# Uses deprecated -wid option instead of --wid because
# xwinwrap will only interpret the WID as window id if it is
# on its own, attaching it with equals breaks it.
exec nice -n "${__nice_value}" xwinwrap \
-g "$2" \
-ni \
-st \
-sp \
-nf \
-b \
-un \
-ov \
-- nice -n "${__nice_value}" mpv \
-wid WID "$1" \
--no-osc \
--no-osd-bar \
--loop-file \
--player-operation-mode=cplayer \
--no-audio \
--panscan=1.0 \
--no-keepaspect \
--no-input-default-bindings \
--hwdec \
--stop-screensaver=no \
&
}
stop()
{
local prompt="$1"
echo "This subcommand kills all mpv processes, do you want to proceed?"
if [ $# -eq 0 ] || [ $prompt == "true"]; then
read -p "[Y]es/[N]o: " yn
case $yn in
[Yy]*) pkill mpv ; echo "Stopped" ; return 0 ;;
[Nn]*) echo "Aborted" ; return 1 ;;
esac
elif [ $prompt == "false" ]; then
pkill mpv
return 0
else
return 1
fi
}
restart()
{
stop false
start
}
start()
{
if ! command -v mpv > /dev/null; then
printf -- 'You must have "mpv" installed.\n'
return 1
fi
if ! command -v xwinwrap > /dev/null; then
printf -- 'You must have "xwinwrap" installed.\n'
return 1
fi
if ! command -v nice > /dev/null; then
printf -- 'You must have "nice" installed.\n'
return 1
fi
# Check for config file
animwall_configs=""
config_dir="${XDG_CONFIG_DIR:-"${HOME}/.config"}/animwall"
config_location="${config_dir}/animwall.conf"
if [ -f "${config_location}" ] && [ -r "${config_location}" ]; then
# printf -- 'Reading animwall.conf from %s\n' "${config_location}"
animwall_configs="$(cat -- "${config_location}")"
else
printf -- 'Could not find animwall.conf file at %s\n' "${config_location}"
printf -- 'Creating example file...\n'
# Make directory
mkdir -p "${config_dir}" || {
printf -- 'Failed to make configuration directory at: %s' "${config_dir}"
return 1
}
# Make config file
printf -- '%s\n' "$(cat << EOF
# This is the configuration file for animwall
#
# Entries are expected one per line in the format
# <FILE>:<WIDTHxHEIGHT+X+Y>:<SCREEN>
#
# Lines beginning with # are ignored
~/Pictures/wallpapers/example.mp4:1920x1080+0+0:0
~/Pictures/wallpapers/example.mp4:1920x1080+1920+0:1
EOF
)" > "${config_location}"
return 1
fi
if [ -z "${animwall_configs}" ]; then
printf -- 'Animwall config was empty!\n'
return 1
fi
# Parse config file
for config in ${animwall_configs}; do
case "${config}" in
\#*)
# printf -- 'Ignore line with comment: %s\n' "${config}"
continue
;;
*)
;;
esac
split_config="$(printf -- "%s" "${config}" | tr ':' ' ')"
wallpaper="$(printf -- "%s" "${split_config}" | awk '{ print $1 }')"
geometry="$(printf -- "%s" "${split_config}" | awk '{ print $2 }')"
screen="$(printf -- "%s" "${split_config}" | awk '{ print $3 }')"
# In case the wallpaper path has ~ as HOME, we replace it
# Replace all $HOME with literal HOME
wallpaper="$(printf -- "%s" "${wallpaper}" | sed "s|^\~|\$HOME|g" | sed "s|^\$HOME|${HOME}|g" )"
if [ -n "${wallpaper}" ] && [ -n "${geometry}" ] && [ -n "${screen}" ]; then
start_wallpaper "${wallpaper}" "${geometry}" "${screen}"
# else
# if [ -z "${wallpaper}" ]; then
# printf -- 'Missing wallpaper path in config: %s\n' "${config}"
# fi
# if [ -z "${geometry}" ]; then
# printf -- 'Missing geometry in config: %s\n' "${config}"
# fi
# if [ -z "${screen}" ]; then
# printf -- 'Missing screen in config: %s\n' "${config}"
# fi
fi
unset split_config
unset wallpaper
unset geometry
unset screen
unset config
done
}
"$@"