-
Notifications
You must be signed in to change notification settings - Fork 1
/
cdmpvTempBgTasks.sh
executable file
·211 lines (186 loc) · 8.28 KB
/
cdmpvTempBgTasks.sh
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
#!/bin/bash
export DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
source "${DIR}"/config.sh
source "${DIR}"/vars.sh
trap "trap - SIGTERM && echo 'Caught SIGTERM, sending SIGTERM to process group' && kill -9 -- -$$" SIGINT SIGTERM EXIT
#trap "trap - SIGTERM && (/bin/kill --verbose --timeout 1000 TERM --timeout 1000 KILL --signal QUIT -- $$ || true) && sleep 0.2 && screen -xr mpv0 -X kill" SIGINT SIGTERM EXIT
#if [ "${BASH_SOURCE[0]}" -ef "$0" ]
if [ "$1" -ne "123456" ]
then
echo "This file is supposed to be executed by another script. Exiting."
exit 1
fi
sleep 2 # todo: do we need this line?
# cvt is better than gtf according to what I read;
# But gtf is better for virtual monitors because cvt outputs 59.86 Hz when asked for 60.00 Hz
modeline=`gtf ${GUEST_W} ${GUEST_H} ${GUEST_REFRESH_RATE} | grep Modeline | sed -r 's/^\s+//' |cut -d' ' -f2- | tr '"' ' '`
echo $modeline > /tmp/vncmodeline
XRANDR_RES=`echo -n ${modeline} | cut -d' ' -f1`
#XRANDR_RES=1280x720
# TODO: rg --pcre2 ..... ${GUEST_REFRESH_RATE}(?![0-9]) but Debian&Ubuntu's ripgrep is compiled without pcre2
# Fix resolution in the guest
function fixRes {
# if the guest is Sway:
#swaymsg output <name> --custom "${GUEST_W}x${GUEST_H}@${GUEST_REFRESH_RATE}Hz"
# Do we need to this?:
#swaymsg output <name> subpixel rgb|bgr|vrgb|vbgr|none
# else:
# Check if we already have the requested resolution at the requested refresh rate
if [[ "$GUEST_REFRESH_RATE" != "60" ]]
then
(xrandr | grep "${GUEST_RES}"'(\s+[0-9.]{4,6}\*?\+?)*\s+'"${GUEST_REFRESH_RATE}" >/dev/null) || (xrandr --newmode $modeline && xrandr --addmode VNC-0 "${XRANDR_RES}")
xrandr -s "${XRANDR_RES}" -r $GUEST_REFRESH_RATE
fi
xrandr --dpi 96
}
fixRes
# if we don't specify I3SOCK,
# then the child i3 will steal parent i3's sock;
# and when the child i3 would die,
# it would delete the sock so that both i3 had no sock.
# TODO: XCURSOR_SIZE=0?
mkfifo "${DIR}/i3-ipc-socket"
i3cfg="${DIR}/.i3-child-config.halfautogened_dontedit"
if [ ${SWAYSOCK}:+1 ]
then
# xset (TODO: maybe also Xmodmap and setxkbmap?) work with Xwayland
# pacman -S bemenu-wayland (wlroots-based compositors only)
cat "${DIR}/i3-child-config" | sed 's/i3-msg/swaymsg/g' | grep -v xrandr | grep -v 'Xmodmap|setxkbmap' > "${i3cfg}"
else
cat "${DIR}/i3-child-config" > "${i3cfg}"
fi
#echo 'exec "autocutsel -fork"' >> "${i3cfg}"
if [ "${PREFER_AUTOCUTSEL}" == "1" ]
then
if [ "${ALLOW_COPYOUTOF}" == "1" ]
then
#echo 'exec "'"${DIR}"'/autocutsel/autocutsel -s PRIMARY -rawhex | (while read line ; do echo -n $line | xxd -r -p | env DISPLAY="${HOST_DISPLAY}" WAYLAND_DISPLAY="${HOST_WAYLAND_DISPLAY}" xclip -sel primary -d $HOST_DISPLAY ; done )"' >> "${i3cfg}"
#echo 'exec "'"${DIR}"'/autocutsel/autocutsel -s CLIPBOARD -rawhex | (while read line ; do echo -n $line | xxd -r -p | env DISPLAY="${HOST_DISPLAY}" WAYLAND_DISPLAY="${HOST_WAYLAND_DISPLAY}" xclip -sel clipboard -d $HOST_DISPLAY ; done )"' >> "${i3cfg}"
#("${DIR}"/autocutsel/autocutsel -s PRIMARY -rawhex | (while read line ; do echo -n $line | xxd -r -p | env DISPLAY="${HOST_DISPLAY}" WAYLAND_DISPLAY="${HOST_WAYLAND_DISPLAY}" xclip -sel primary -d $HOST_DISPLAY ; done ) ) &
("${DIR}"/autocutsel/autocutsel -s CLIPBOARD -rawhex | (while read line ; do echo -n $line | xxd -r -p | env DISPLAY="${HOST_DISPLAY}" WAYLAND_DISPLAY="${HOST_WAYLAND_DISPLAY}" xclip -sel clipboard -d $HOST_DISPLAY ; done ) ) &
fi
ALLOW_COPYOUTOF=0
ALLOW_COPYINTO=0
fi
I3MSG="${I3MSG}" I3SOCK="${DIR}/i3-ipc-socket" i3 -c "${i3cfg}" &
sleep 3 &&
fixRes
sleep 0.2
echo -n > "${DIR}/.env-of-current-process"
echo "# This file was generated by cdmpvTempBgTasks.sh" >> "${DIR}/.env-of-current-process"
echo "# This file is generated every time you launch cdmpv.sh" >> "${DIR}/.env-of-current-process"
echo "# This file is used only by x11wid.sh" >> "${DIR}/.env-of-current-process"
echo HOST_DISPLAY=\"${HOST_DISPLAY}\" >> "${DIR}/.env-of-current-process"
echo GUEST_DISPLAY=\"${DISPLAY}\" >> "${DIR}/.env-of-current-process"
echo WAYLAND_DISPLAY=\"${HOST_WAYLAND_DISPLAY}\" >> "${DIR}/.env-of-current-process"
echo GUEST_RES=\"${GUEST_RES}\" >> "${DIR}/.env-of-current-process"
echo GUEST_REFRESH_RATE=\"${GUEST_REFRESH_RATE}\" >> "${DIR}/.env-of-current-process"
echo UPSCALED_FPS=\"${UPSCALED_FPS}\" >> "${DIR}/.env-of-current-process"
if [[ "${STUPIDI3ONLYMETHOD}" == "1" ]]
then
VNCVIEWER_AND_MPV_POS_X=`calc "floor((${HOST_W} - ${VNCVIEWER_AND_MPV_W}) / 2)"`
VNCVIEWER_AND_MPV_POS_Y=`calc "floor((${HOST_H} - ${VNCVIEWER_AND_MPV_H}) / 2)"`
#bash "${DIR}"/fixVncViewerAndMpvWindows.sh
echo "geometry=${VNCVIEWER_AND_MPV_RES}+${VNCVIEWER_AND_MPV_POS_X}+${VNCVIEWER_AND_MPV_POS_Y}\n\n"
sleep 0.1
# fourcc is BGR3, while yuv pixel format is BGR24. Or I don't the terminology
# beforce TsubaUp:
#--demuxer-rawvideo-format=BGR3 \
#--demuxer-rawvideo-mp-format=bgr24 \
# --speed=1.05 \
# --untimed \
# if the input is not created 0 (and/or 1?) frame durations ago, then remove --no-correct-pts
#DISPLAY="${HOST_DISPLAY}" WAYLAND_DISPLAY="${HOST_WAYLAND_DISPLAY}" screen -Dm -L -Logfile "/tmp/mpv0-$(date -Iseconds).log" -S mpv0 \
DISPLAY="${HOST_DISPLAY}" WAYLAND_DISPLAY="${HOST_WAYLAND_DISPLAY}" screen -Dm -S mpv0 \
mpv \
--no-fs \
--demuxer-rawvideo-w="${GUEST_W}" \
--demuxer-rawvideo-h="${GUEST_H}" \
--demuxer-rawvideo-format=BGR3 \
--demuxer-rawvideo-mp-format=bgr24 \
--demuxer-rawvideo-fps="${GUEST_REFRESH_RATE}" \
--geometry="${VNCVIEWER_AND_MPV_RES}+${VNCVIEWER_AND_MPV_POS_X}+${VNCVIEWER_AND_MPV_POS_Y}" \
\
--input-conf="${MPV__INPUT_CONF}" \
--af="" \
--untimed \
--vf-pre="mpdecimate" \
--vf-pre="fps=${UPSCALED_FPS}" \
--fps="${UPSCALED_FPS}" \
--input-ipc-server="${DIR}"/mpvsocket \
--correct-pts \
--vd-lavc-threads=1 \
--cache-pause=no \
--demuxer-lavf-o-add="fflags=+nobuffer+fastseek+flush_packets" \
--demuxer-lavf-probe-info=nostreams \
--demuxer-lavf-analyzeduration=0.1 \
--demuxer-readahead-secs=0 \
--demuxer-thread=yes \
--interpolation=no \
--deband=no \
--no-audio \
--vd-queue-max-samples=2 \
--ad-queue-max-samples=1 \
--video-latency-hacks=yes \
--profile=low-latency \
--no-pause \
--force-window=yes \
--network-timeout=0 \
"av://v4l2:${CAM}" &
# --demuxer-max-bytes=500MiB \
#FIXME: or demuxerthread=no?
rvncpath="${DIR}/realvnc-vnc-viewer/bin/vncviewer"
if [[ -f "${rvncpath}" ]]
then
# Possible values for MenuKey: /usr/include/X11/keysymdef.h (just remove XK_)
# But Super_L doesn't work. It seems only F1..F12 work
#what's faster: Full or rgb111?
DISPLAY="${HOST_DISPLAY}" WAYLAND_DISPLAY="${HOST_WAYLAND_DISPLAY}" nice -n -15 "${rvncpath}" :0 -GrabKeyboard=0 -FullScreen=1 -PreferredEncoding=Raw -Quality=Low -ColorLevel=Full -AutoReconnect=0 -MenuKey= -DotWhenNoCursor=0 -UpdateScreenshot=0 -EnableToolbar=0 -ServerCutText=0 -SendPrimary=0 -RelativePtr=1 -Encryption=PreferOff -WarnUnencrypted=0 -Scaling=FitHeight &
PICOM_ARGS="--opacity-rule='0:name *= \"cdmpv) - VNC Vie''wer\"'"
else
DISPLAY="${HOST_DISPLAY}" WAYLAND_DISPLAY="${HOST_WAYLAND_DISPLAY}" nice -n -15 gvncviewer :0 &
PICOM_ARGS="--opacity-rule='0:name *= \"GVncVie''wer\"'"
fi
unset rvncpath
#if you somehow manage TigerVNC to upscale, then use: -PreferredEncoding=Raw -CompressLevel=0 -NoJpeg=1 in order to avoid stutters
#ColorLevel
sleep 1
if ! pidof picom compton > /dev/null
then
PICOM_BIN=`( (whereis picom | grep -v ':$')>/dev/null && echo -n picom) || echo -n compton`
if [ "$isNvidia" == "1" ]; then
PICOM_ARGS="${PICOM_ARGS} --vsync --xrender-sync-fence"
else
PICOM_ARGS="${PICOM_ARGS} --vsync"
fi
#DISPLAY="${HOST_DISPLAY}" "$PICOM_BIN" $PICOM_ARGS &
(echo -n "$PICOM_BIN" $PICOM_ARGS | DISPLAY="${HOST_DISPLAY}" bash) &
unset PICOM_BIN
fi
unset PICOM_ARGS
sleep 3
DISPLAY="${HOST_DISPLAY}" WAYLAND_DISPLAY="${HOST_WAYLAND_DISPLAY}" source "${DIR}"/fixVncViewerAndMpvWindows.sh "${VNC_WILL_BE_AT_DESKTOP}"
fixRes
sleep 2
fixRes
else
set -x
DISPLAY="${HOST_DISPLAY}" WAYLAND_DISPLAY="${HOST_WAYLAND_DISPLAY}" \
vncviewer "${VNC_SOCKET_PATH}" -PreferredEncoding=Raw -CompressLevel=0 -NoJpeg=1 -MenuKey=F11 -AcceptClipboard="$ALLOW_COPYOUTOF" -SendClipboard="$ALLOW_COPYINTO" &
sleep 3
if [[ "$AUTOLAUNCH_X11WID_SH" != "0" ]]
then
GUEST_DISPLAY="${DISPLAY}" DISPLAY="${HOST_DISPLAY}" WAYLAND_DISPLAY="${HOST_WAYLAND_DISPLAY}" bash "${DIR}"/x11wid.sh &
fi
set +x
sleep 3
fixRes
sleep 2
fixRes
sleep 2
fixRes
sleep 2
fixRes
sleep 2
fixRes
fi