From f30eb0df6e7f85c95bb200ea753dfd2d874149ab Mon Sep 17 00:00:00 2001 From: Riyyi Date: Tue, 9 Mar 2021 12:52:48 +0100 Subject: [PATCH] Move screenshot keybindings to rofi menu --- .config/sxhkd/sxhkdrc | 8 +++---- .local/bin/aliases | 7 +++++-- .local/bin/printscreen | 47 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 6 deletions(-) create mode 100755 .local/bin/printscreen diff --git a/.config/sxhkd/sxhkdrc b/.config/sxhkd/sxhkdrc index 763d890..6d25a54 100644 --- a/.config/sxhkd/sxhkdrc +++ b/.config/sxhkd/sxhkdrc @@ -28,13 +28,13 @@ super + shift + s super + {F2,F3} brictl {dec,inc} 10 -# Screenshot (fullscreen, selection, focused window) -{_,shift,super} + @Print - scrot {_,-s,-u} -e "mv \$f $CAPTURE" +# Screenshot (fullscreen, selection, active window) +@Print + printscreen # Screen record ctrl + @Print - aliases screencast "$CAPTURE/$(date '+%Y-%m-%d-%H%M%S_1280x720_screencast')" + aliases screencast # Volume XF86Audio{LowerVolume,RaiseVolume,Mute} diff --git a/.local/bin/aliases b/.local/bin/aliases index 591c783..7641c45 100755 --- a/.local/bin/aliases +++ b/.local/bin/aliases @@ -67,7 +67,10 @@ screencast() { # Kill with SIGKILL, just in case it is still running pkill -9 ffmpeg else - NAME=${1:-"output"} + width=1280 + height=720 + NAME=${1:-"$CAPTURE/$(date '+%Y-%m-%d-%H%M%S')_${width}x${height}_ffmpeg"} + [ -n "$2" ] && AUDIO_CODEC="-c:a aac" [ -n "$2" ] && AUDIO_SOURCE="-f pulse -ac 2 -i $2" # 1 = system, 2 = mic @@ -76,7 +79,7 @@ screencast() { -threads 8 \ -f x11grab \ -framerate 30 \ - -s 1280x720 \ + -s "${width}x${height}" \ -i "$DISPLAY.0+640,180" \ $AUDIO_SOURCE \ -r 30 \ diff --git a/.local/bin/printscreen b/.local/bin/printscreen new file mode 100755 index 0000000..f594534 --- /dev/null +++ b/.local/bin/printscreen @@ -0,0 +1,47 @@ +#!/bin/sh + +# Take a screenshot with the configured program +# Depends: scrot / maim / magick + +# User-config--------------------------- + +# scrot / maim / magick import +screenshotter="scrot" + +# -------------------------------------- + +if [ "$screenshotter" = "scrot" ]; then + fullscreen="" + selection="-s" + activeWindow="-u" + filename="-e 'mv \$f $CAPTURE'" + +elif [ "$screenshotter" = "maim" ]; then + fullscreen="" + selection="-s" + activeWindow="-i \$(xdotool getactivewindow)" + filename="$CAPTURE/$(date '+%Y-%m-%d-%H%M%S')_maim.png" +elif [ "$screenshotter" = "magick import" ] || [ "$screenshotter" = "import" ]; then + fullscreen="-window root" + selection="" + activeWindow="-window \$(xdotool getactivewindow)" + filename="$CAPTURE/$(date '+%Y-%m-%d-%H%M%S')_import.png" +else + echo "Printscreen configuration is invalid" + exit 1 +fi + +options="\ +Selection +Active Window +Fullscreen" + +choice=$(echo "$options" | rofi -no-fixed-num-lines -dmenu -i -p "Screenshot") || exit 0 + +command="$screenshotter" +[ "$choice" = "Selection" ] && command="$command $selection" +[ "$choice" = "Active Window" ] && command="$command $activeWindow" +[ "$choice" = "Fullscreen" ] && command="$command $fullscreen" +command="$command $filename" + +eval "$command"