wf-recorder: Add swayrecorder script

This commit is contained in:
Johannes Loher 2021-08-17 08:24:43 +02:00
parent 9daee83daa
commit ba41ba23cc

79
.local/bin/swayrecorder Executable file
View file

@ -0,0 +1,79 @@
#! /bin/sh
# Copyright (c) 2021 Johannes Loher
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
print_usage() {
echo "Usage: swayrecorder [command]"
echo
echo "Commands:"
echo " -a, --all Capture all outputs. This is the default if no option is given."
echo " -m, --manual Select a region manually and capture it."
echo " -o, --output Select an output and capture it."
echo " -O, --focused-output Capture the currently focused output"
echo " -w, --window Select a window and capture it."
echo " -W, --focused-window Capture the currently focused window"
echo " -h, --help Show help message and quit."
echo
}
all() {
grim
}
select_manual() {
DIMENSIONS=$(slurp)
wf-recorder -g "$DIMENSIONS"
}
select_output() {
DIMENSIONS=$(swaymsg -t get_outputs | jq -r '.[] | select(.active) | .rect | "\(.x),\(.y) \(.width)x\(.height)"' | slurp)
wf-recorder -g "$DIMENSIONS"
}
focused_output() {
wf-recorder -o $(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .name')
}
select_window() {
DIMENSIONS=$(swaymsg -t get_tree | jq -r '.. | select(.pid? and .visible?) | .rect | "\(.x),\(.y) \(.width)x\(.height)"' | slurp)
wf-recorder -g "$DIMENSIONS"
}
focused_window() {
DIMENSIONS=$(swaymsg -t get_tree | jq -r '.. | select(.pid? and .visible?) | select(.focused) | .rect | "\(.x),\(.y) \(.width)x\(.height)"')
wf-recorder -g "$DIMENSIONS"
}
case $1 in
-a|--all|"")
all
;;
-m|--manual)
select_manual
;;
-o|--output)
select_output
;;
-O|--focused-output)
focused_output
;;
-w|--window)
select_window
;;
-W|--focused-window)
focused_window
;;
-h|--help)
print_usage
;;
*)
print_usage
exit 1
;;
esac