-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathwl-present
More file actions
executable file
·235 lines (206 loc) · 6.28 KB
/
wl-present
File metadata and controls
executable file
·235 lines (206 loc) · 6.28 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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#!/bin/bash
usage() {
echo "usage: wl-present [options] <command> [argument]"
echo
echo "start wl-mirror and control the mirrored output and region in a convenient way"
echo
echo "commands:"
echo " help show this help"
echo " mirror [output] [options] start wl-mirror on output [output] (default asks via slurp)"
echo " set-output [output] set the recorded output (default asks via slurp)"
echo " set-region [region] set the recorded region (default asks via slurp)"
echo " unset-region unset the recorded region"
echo " set-scaling [scale] set the scaling mode (default asks via rofi)"
echo " freeze freeze the screen"
echo " unfreeze resume the screen capture after freeze"
echo " toggle-freeze toggle freeze state of screen capture"
echo " fullscreen fullscreen the wl-mirror window"
echo " unfullscreen unfullscreen the wl-mirror window"
echo " fullscreen-output [output] set fullscreen target output, implies fullscreen (default asks via slurp)"
echo " no-fullscreen-output unset fullscreen target output, implies unfullscreen"
echo " custom [options] send custom options to wl-mirror (default asks via rofi)"
echo
echo "options:"
echo " -n, --name use an alternative pipe name (default is wl-present)"
echo " this allows multiple instances of wl-present to run"
echo " at the same time."
echo "dependencies:"
echo " wl-mirror, bash, slurp, pipectl (optional), and either wofi, wmenu, rofi, fuzzel, or dmenu"
echo
echo "environment variables":
echo " WL_PRESENT_DMENU overrides the used dmenu implementation"
echo " WL_PRESENT_PIPECTL overrides the used pipectl implementation"
echo " WL_PRESENT_SLURP overrides the used slurp implementation"
echo " WL_PRESENT_PIPE_NAME overrides the default pipe name (default is wl-present)"
exit 0
}
if [[ -n "$WL_PRESENT_DMENU" ]]; then
DMENU="$WL_PRESENT_DMENU"
elif type -p wofi >/dev/null; then
DMENU="wofi -d"
elif type -p wmenu >/dev/null; then
DMENU=wmenu
elif type -p fuzzel >/dev/null; then
DMENU="fuzzel -d"
elif type -p rofi >/dev/null; then
DMENU="rofi -dmenu"
else
DMENU=dmenu
fi
if [[ -n "$WL_PRESENT_PIPECTL" ]]; then
PIPECTL="$WL_PRESENT_PIPECTL"
elif type -p pipectl >/dev/null; then
PIPECTL=pipectl
else
PIPECTL=pipectl-shim
fi
if [[ -n "$WL_PRESENT_SLURP" ]]; then
SLURP="$WL_PRESENT_SLURP"
else
SLURP=slurp
fi
if [[ -n "$WL_PRESENT_PIPE_NAME" ]]; then
PRESENT_PIPE_NAME="$WL_PRESENT_PIPE_NAME"
else
PRESENT_PIPE_NAME=wl-present
fi
pipectl-shim() {
PIPEPATH="${XDG_RUNTIME_DIR:-"${TMPDIR:-/tmp}"}"
PIPENAME="pipectl.$(id -u).pipe"
MODE=
FORCE=0
while [[ $# -gt 0 && "${1:0:1}" == "-" ]]; do
opt="$1"
shift
case "$opt" in
-n|--name) arg="$1"; shift; PIPENAME="pipectl.$(id -u).$arg.pipe";;
-i|--in) MODE=in;;
-o|--out) MODE=out;;
-f|--force) FORCE=1;;
--) break;;
esac
done
PIPE="$PIPEPATH/$PIPENAME"
case "$MODE" in
"in") if [[ ! -p "$PIPE" ]]; then
echo "error: could not open pipe at '$PIPE': No such file or directory" >&2
return 1
else
cat > "$PIPE"
fi;;
"out") if [[ "$FORCE" -eq 0 && -p "$PIPE" ]]; then
echo "error: cannot create pipe at '$PIPE': File exists" >&2
return 1
else
[[ "$FORCE" -eq 1 ]] && rm -f "$PIPE"
mkfifo "$PIPE"; (tail -f "$PIPE" & echo > "$PIPE"; wait); rm -f "$PIPE"
fi;;
esac
}
slurp-output() {
$SLURP -or -f '%o' 2>/dev/null
}
slurp-region() {
$SLURP 2>/dev/null
}
slurp-output-or-region() {
$SLURP -o -f '%x,%y %wx%h %o' 2>/dev/null
}
mirror() {
if [[ "$#" -eq 0 || "$1" =~ ^- ]]; then
OUTPUT_REGION=$(ask-output-or-region)
ARGS=("-S" "-r" "$OUTPUT_REGION" "$@")
else
OUTPUT="$1"
shift
ARGS=("-S" "$@" "$OUTPUT")
fi
$PIPECTL -n "$PRESENT_PIPE_NAME" -o | wl-mirror "${ARGS[@]}"
}
mirror-cmd() {
$PIPECTL -n "$PRESENT_PIPE_NAME" -i <<< "$1"
}
set-output() {
mirror-cmd "$1"
}
set-region() {
mirror-cmd "-r '$1'"
}
set-scaling() {
mirror-cmd "-s $1"
}
set-fullscreen-output() {
mirror-cmd "--fullscreen-output $1"
}
ask-output() {
slurp-output
[[ $? -ne 0 ]] && exit 1
}
ask-region() {
slurp-region
[[ $? -ne 0 ]] && exit 1
}
ask-output-or-region() {
slurp-output-or-region
[[ $? -ne 0 ]] && exit 1
}
ask-scaling() {
(echo fit; echo cover; echo exact; echo linear; echo nearest) | $DMENU -p "wl-present scaling"
[[ $? -ne 0 ]] && exit 1
}
ask-custom() {
cat <<EOF | $DMENU -p "wl-present custom"
--verbose
--no-verbose
--show-cursor
--no-show-cursor
--invert-colors
--no-invert-colors
--freeze
--unfreeze
--toggle-freeze
--fullscreen
--no-fullscreen
--fullscreen-output
--no-fullscreen-output
--scaling fit
--scaling cover
--scaling exact
--scaling linear
--scaling nearest
--backend
--transform
--region
--no-region
EOF
[[ $? -ne 0 ]] && exit 1
}
while [[ $# -gt 0 && "${1:0:1}" == "-" ]]; do
opt="$1"
shift
case "$opt" in
-n|--name) arg="$1"; shift; PRESENT_PIPE_NAME="$arg";;
-h|--help) usage;;
--) break;;
esac
done
if [[ $# -eq 0 ]]; then
usage
fi
case "$1" in
help) usage;;
mirror) shift; mirror "$@";;
set-output) set-output "${2:-$(ask-output)}";;
set-region) set-region "${2:-$(ask-region)}";;
unset-region|no-region) mirror-cmd --no-region;;
set-scaling) set-scaling "${2:-$(ask-scaling)}";;
freeze) mirror-cmd --freeze;;
unfreeze) mirror-cmd --unfreeze;;
toggle-freeze) mirror-cmd --toggle-freeze;;
fullscreen) mirror-cmd --fullscreen;;
unfullscreen|no-fullscreen) mirror-cmd --no-fullscreen;;
fullscreen-output) set-fullscreen-output "${2:-$(ask-output)}";;
no-fullscreen-output) mirror-cmd --no-fullscreen-output;;
custom) mirror-cmd "${2:-$(ask-custom)}";;
*) usage;;
esac