summaryrefslogtreecommitdiff
path: root/private_dot_local/bin/executable_toggle-screen-capture
blob: 10dff96bbceb9a4eb4e281ffba4ea39fce4e5edb (plain)
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
#!/bin/sh

PID=`pgrep wf-recorder`
FILE="$HOME/multimedia/screencasts/`date '+%Y%m%d-%H%M%S'`.mkv"

if [ "$PID" ]; then
  kill -INT $PID
  for module in `pactl list short modules | grep wf-recorder | cut -f1`; do
    pactl unload-module $module
  done
  while `pgrep wf-recorder`; do sleep 0.01; done
  pkill -SIGRTMIN+8 waybar
  sleep 0.01
  pkill -SIGRTMIN+8 waybar
else
  TYPE=${1:-output}
  case $TYPE in
    output)
      GEOMETRY=`slurp -o -b "303030AA" -B "303030AA"`
      ;;
    window)
      GEOMETRY=`swaymsg -t get_tree | jq -r '.. | select(.pid? and .visible?) | "\(.rect.x+.window_rect.x),\(.rect.y+.window_rect.y) \(.window_rect.width)x\(.window_rect.height)"' | slurp -b "303030AA" -B "303030AA"`
      ;;
    *)
      echo "Usage: $0 [output|window]"
      exit 1
      ;;
  esac
  if [ -z "$GEOMETRY" ]; then exit; fi
  pactl load-module module-null-sink sink_name=wf-recorder
  pactl load-module module-loopback sink=wf-recorder source=alsa_output.pci-0000_00_1b.0.analog-stereo.monitor
  pactl load-module module-loopback sink=wf-recorder source=alsa_input.pci-0000_00_1b.0.analog-stereo
  wf-recorder --audio=wf-recorder.monitor \
              --geometry="$GEOMETRY" \
              --pixel-format=yuv420p \
              --file="$FILE" &
  disown $!
  pkill -SIGRTMIN+8 waybar
fi