From 4bd4743f954fd3195c73be19381d3749e08328a1 Mon Sep 17 00:00:00 2001 From: Siina Mashek Date: Sun, 13 Mar 2022 08:27:19 +0200 Subject: [PATCH] Refactored scrot.sh and added secondary display capture --- common/scrot.sh | 63 +++++++++++++++++++++++++++--------------------- scrotsh.khotkeys | 34 +++++++++++++++++++++++--- 2 files changed, 66 insertions(+), 31 deletions(-) diff --git a/common/scrot.sh b/common/scrot.sh index 482b606..5d6e49f 100755 --- a/common/scrot.sh +++ b/common/scrot.sh @@ -7,54 +7,63 @@ # - imagemagick: for custom resolution sizes # - mpv: plays audio file upon completion # - boop.sh: uploads screenshot to boop.icu +# - Checks for SCREENSHOT_DIR environment variable # # Example global keybinds: # -# TYPE CMD KEYBIND +# TYPE CMD KEYBIND # -# Fullscreen scrot.sh Print -# Main monitor scrot.sh -m Meta+Ctrl+Print -# Active window/Selct scrot.sh -s Meta+Print +# Fullscreen scrot.sh Print +# Main monitor scrot.sh --main Meta+Ctrl+Print +# Active window/Select scrot.sh --select Meta+Print # -# TODO: Autodetect mpv and boop.sh to make them optional # TODO: Figure out how to capture a specific monitor, not just main +# TODO: Remove hardcoded shutter sound path -source ~/.profile # Workaround +source ~/.profile # Workaround to avoid using /bin/bash -# Checks for SCREENSHOT_DIR environment variable -#screendir="$HOME/Screenshots" +# Edit these to fit setup sound="$HOME/Projects/local-bin/sounds/shutter.ogg" filename="$(date +'%Y%m%d_%H%M%S').png" -resolution="1920x1080" - -# For desktop multi-monitor -if [[ ${1} == "-d" ]]; then - resolution="1920x1590" -fi - -args="-m 9 -u" - +main_res="1920x1080+0+510" +secondary_res="1080x1920+1920+0" +# Ensure screenshot directory is there so the script will work if [[ ! -d $SCREENSHOT_DIR ]]; then mkdir -p $SCREENSHOT_DIR fi - -echo "Entering $SCREENSHOT_DIR" cd $SCREENSHOT_DIR -if [[ ${1} == "-m" ]]; then - args="${args} -g ${resolution}+0+510" # for standard 1080p single monitor -else - args="${args}" +# Setup is 1920x1590: main = 1920x1080; secondary = 1080x1920 +if [[ ${1} == "--main" ]]; then + resolution=$main_res +elif [[ ${1} == "--secondary" ]]; then + resolution=$secondary_res fi +# Set maim arguments based on command arguments +args="-m 9 -u" +if [[ ${1} == "--select" ]]; then + args="$args ${1}" +elif [[ ${1} == "--main" || ${1} == "--secondary" ]]; then + args="$args -g $resolution" + +fi + +# Take the screenshot with maim maim -B $args $filename > /dev/null 2>&1 -# cleanup for my dual-monitor setup -if [[ ${1} == "-d" ]]; then +# cleanup for main monitor +if [[ ${1} == "--main" ]]; then magick convert $filename -trim +repage $SCREENSHOT_DIR/$filename fi -mpv $sound -$HOME/.local/bin/boop.sh "$SCREENSHOT_DIR/$filename" +# Play sound if mpv is available +if [[ -n "$(which mpv)" ]]; then + mpv $sound +fi +# Upload to boop if boop.sh is available +if [[ -n "$(which boop.sh)" ]]; then + boop.sh "$SCREENSHOT_DIR/$filename" +fi diff --git a/scrotsh.khotkeys b/scrotsh.khotkeys index 9f7b348..5f97cd4 100644 --- a/scrotsh.khotkeys +++ b/scrotsh.khotkeys @@ -3,7 +3,7 @@ DataCount=1 [Data_1] Comment=Comment -DataCount=3 +DataCount=4 Enabled=true Name=Scrot.sh SystemGroup=0 @@ -49,7 +49,7 @@ Type=SIMPLE_ACTION_DATA ActionsCount=1 [Data_1_2Actions0] -CommandURL=/home/siina/.local/bin/scrot.sh -m +CommandURL=/home/siina/.local/bin/scrot.sh --main Type=COMMAND_URL [Data_1_2Conditions] @@ -61,7 +61,7 @@ Comment=Simple_action TriggersCount=1 [Data_1_2Triggers0] -Key= +Key=Meta+Ctrl+Print Type=SHORTCUT Uuid={c339b929-b41c-4c59-928e-2fafe008b001} @@ -75,7 +75,7 @@ Type=SIMPLE_ACTION_DATA ActionsCount=1 [Data_1_3Actions0] -CommandURL=/home/siina/.local/bin/scrot.sh -s +CommandURL=/home/siina/.local/bin/scrot.sh --select Type=COMMAND_URL [Data_1_3Conditions] @@ -91,6 +91,32 @@ Key=Meta+Print Type=SHORTCUT Uuid={205c92eb-bb7b-47a2-8309-b9ebf3f655e2} +[Data_1_4] +Comment=Comment +Enabled=true +Name=Secondary Display +Type=SIMPLE_ACTION_DATA + +[Data_1_4Actions] +ActionsCount=1 + +[Data_1_4Actions0] +CommandURL=/home/siina/.local/bin/scrot.sh --secondary +Type=COMMAND_URL + +[Data_1_4Conditions] +Comment= +ConditionsCount=0 + +[Data_1_4Triggers] +Comment=Simple_action +TriggersCount=1 + +[Data_1_4Triggers0] +Key= +Type=SHORTCUT +Uuid={3069937f-c0f2-4741-96a0-ca47d3f123f0} + [Main] AllowMerge=false Version=2