Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new: added --freeze flag #21

Merged
merged 6 commits into from
Jun 1, 2024
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions hyprshot
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Options:
-m, --mode one of: output, window, region, active, OUTPUT_NAME
-o, --output-folder directory in which to save screenshot
-f, --filename the file name of the resulting screenshot
-F, --freeze freeze the screen on initialization
-d, --debug print debug information
-s, --silent don't send notification when screenshot is saved
-r, --raw output raw image data to stdout
Expand Down Expand Up @@ -124,7 +125,27 @@ function save_geometry() {
send_notification $output
}

function killHyprpicker() {
if [ ! $HYPRPICKER_PID -eq -1 ]; then
kill $HYPRPICKER_PID
fi
}

function checkRunning() {
while [[ 1 == 1 ]]; do
if [[ $(pgrep slurp | wc -m) == 0 ]]; then
pkill hyprpicker
exit
fi
done
}

function begin_grab() {
if [ $FREEZE -eq 1 ] && [ "$(command -v "hyprpicker")" ] >/dev/null 2>&1; then
hyprpicker -r -z &
sleep 0.2
HYPRPICKER_PID=$!
fi
local option=$1
case $option in
output)
Expand Down Expand Up @@ -211,7 +232,7 @@ function parse_mode() {
}

function args() {
local options=$(getopt -o hf:o:m:dsrt: --long help,filename:,output-folder:,mode:,clipboard-only,debug,silent,raw,notif-timeout: -- "$@")
local options=$(getopt -o hf:o:m:dsFr:t: --long help,filename:,output-folder:,mode:,clipboard-only,debug,silent,freeze,raw,notif-timeout: -- "$@")
eval set -- "$options"

while true; do
Expand All @@ -238,6 +259,9 @@ function args() {
-d | --debug)
DEBUG=1
;;
-F | --freeze)
FREEZE=1
;;
-s | --silent)
SILENT=1
;;
Expand Down Expand Up @@ -273,6 +297,7 @@ SILENT=0
RAW=0
NOTIF_TIMEOUT=5000
CURRENT=0
FREEZE=0
[ -z "$XDG_PICTURES_DIR" ] && type xdg-user-dir &> /dev/null && XDG_PICTURES_DIR=$(xdg-user-dir PICTURES)
FILENAME="$(date +'%Y-%m-%d-%H%M%S_hyprshot.png')"
[ -z "$HYPRSHOT_DIR" ] && SAVEDIR=${XDG_PICTURES_DIR:=~} || SAVEDIR=${HYPRSHOT_DIR}
Expand All @@ -281,4 +306,5 @@ args $0 "$@"

SAVE_FULLPATH="$SAVEDIR/$FILENAME"
[ $CLIPBOARD -eq 0 ] && Print "Saving in: %s\n" "$SAVE_FULLPATH"
begin_grab $OPTION
begin_grab $OPTION & checkRunning
killHyprpicker
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this call the killHyprpicker function at the end when checkRunning already serves that purpose?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great point actually