summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--home/wayland/pkgs/wayland-scripts/default.nix12
-rwxr-xr-xhome/wayland/pkgs/wayland-scripts/src/bin/cwall26
-rwxr-xr-xhome/wayland/pkgs/wayland-scripts/src/bin/freezshot57
3 files changed, 34 insertions, 61 deletions
diff --git a/home/wayland/pkgs/wayland-scripts/default.nix b/home/wayland/pkgs/wayland-scripts/default.nix
index 0e28487..e39907a 100644
--- a/home/wayland/pkgs/wayland-scripts/default.nix
+++ b/home/wayland/pkgs/wayland-scripts/default.nix
@@ -7,10 +7,9 @@
sway,
ffmpeg,
libnotify,
- imv,
- grim,
- slurp,
bemenu,
+ jq,
+ coreutils,
}:
stdenvNoCC.mkDerivation {
@@ -51,11 +50,10 @@ stdenvNoCC.mkDerivation {
wrapProgram $out/bin/freezshot \
--prefix PATH : ${
lib.makeBinPath [
- ffmpeg
+ libnotify
sway
- grim
- slurp
- imv
+ jq
+ coreutils
]
}
'';
diff --git a/home/wayland/pkgs/wayland-scripts/src/bin/cwall b/home/wayland/pkgs/wayland-scripts/src/bin/cwall
index 6268390..7bdb13c 100755
--- a/home/wayland/pkgs/wayland-scripts/src/bin/cwall
+++ b/home/wayland/pkgs/wayland-scripts/src/bin/cwall
@@ -5,27 +5,26 @@ bgdesk="$bgroot/desktop"
bglock="$bgroot/lockscreen"
walldir="$HOME/pix/wall"
-die()
-{
- command -v notify-send > /dev/null &&
- notify-send " cwall" "$1"
+info() {
+ notify-send " cwall" "$1"
+ printf "\033[32;1m%b\033[0m\n" "$1"
+}
+die() {
+ notify-send " cwall" "err: $1"
printf "\033[31;1merr: %b\033[0m\n" "$1" 1>&2
exit "${2:-1}"
}
-usage()
-{
- echo 'Usage: cwall [wallpaper.img|directory]'
+usage() {
+ info 'Usage: cwall [wallpaper.img|directory]'
}
-mimetype()
-{
+mimetype() {
file --brief --dereference --mime-type "$1"
}
-randimg()
-{
+randimg() {
# usage: randbg dir
: "${1:?}"
maxattempts=10
@@ -60,8 +59,7 @@ randimg()
done
}
-updatewall()
-{
+updatewall() {
: "${1:?}"
rm -f "$bgdesk" "$bglock"
@@ -98,7 +96,7 @@ case "$(mimetype "$input")" in
die "no image file in $input"
fi
- updatewall "$img"
+ updatewall "$img" && info "Wallpaper updated to $img"
;;
*)
die "invalid input $input"
diff --git a/home/wayland/pkgs/wayland-scripts/src/bin/freezshot b/home/wayland/pkgs/wayland-scripts/src/bin/freezshot
index a47e9c8..754064a 100755
--- a/home/wayland/pkgs/wayland-scripts/src/bin/freezshot
+++ b/home/wayland/pkgs/wayland-scripts/src/bin/freezshot
@@ -1,51 +1,28 @@
#!/usr/bin/env bash
-tmp="${XDG_RUNTIME_DIR:-${TMPDIR:-/tmp}}"
-tmp="$(mktemp -d "${tmp}/freezhot.XXXX")"
-out="${GRIM_DEFAULT_DIR:-${XDG_PICTURES_DIR:-.}}"
+out_dir="${GRIM_DEFAULT_DIR:-${XDG_PICTURES_DIR:-.}}"
-wl_res()
-{
- swaymsg -pt get_outputs | while read -r line; do
- case "$line" in
- "Current mode"*)
- line="${line#*Current mode: }"
- echo "${line%% *}"
- return
- esac
- done
+info() {
+ notify-send " freezhot" "$1"
+ printf "\033[32;1merr: %b\032[0m\n" "$1"
+}
+
+focused_clinet_name() {
+ name="$(swaymsg -t get_tree | jq -r '.. | select(.focused? == true) | .name')"
+ if [ -z "$name" ]; then
+ echo "screenshot"
+ else
+ echo "$name"
+ fi
}
########
# MAIN #
########
-if [ ! -d "$out" ]; then
- mkdir -p "$out"
+if [ ! -d "$out_dir" ]; then
+ mkdir -p "$out_dir"
fi
-GRIM_DEFAULT_DIR="$tmp" grim
-trap 'rm -r "$tmp"' EXIT
-imv -f "$tmp"/* &
-view_pid=$!
+out="$out_dir/$(date +'%Y%m%d-%Hh%Mm%Ss')-$(focused_clinet_name).png"
-region=$(slurp -f '%wx%h %x:%y') > /dev/null 2>&1
-r=$?
-kill $view_pid
-if [ $r != 0 ]; then
- exit 1
-fi
-
-img="$(ls "$tmp")"
-res="${region% *}"
-if [ "$res" = "$(wl_res)" ]; then
- cp "$tmp/$img" "$out"
-else
- width=${res%x*}
- hight="${res#*x}"
- position="${region#* }"
- ffmpeg \
- -loglevel quiet \
- -i "$tmp/$img" \
- -vf "crop=$width:$hight:$position" \
- "$out/$img"
-fi
+grim "$out" && info "Screenshot saved to $out"