From d4d325eab01803ee8c0128be3803a6eb6098d86d Mon Sep 17 00:00:00 2001 From: hurlbutt <5818219+hurlbutt@users.noreply.github.com> Date: Mon, 1 Jun 2026 17:34:40 -0700 Subject: [PATCH] Support jpg, ppm file format preference for screenshots --- dotfiles/.config/hypr/scripts/screenshot.sh | 46 ++++++++++++++------- dotfiles/.config/ml4w/bin/ml4w-screenshot | 21 ++++++++-- 2 files changed, 47 insertions(+), 20 deletions(-) diff --git a/dotfiles/.config/hypr/scripts/screenshot.sh b/dotfiles/.config/hypr/scripts/screenshot.sh index 5bb81ce3f..010e33b60 100755 --- a/dotfiles/.config/hypr/scripts/screenshot.sh +++ b/dotfiles/.config/hypr/scripts/screenshot.sh @@ -11,17 +11,34 @@ # Screenshots will be stored in $HOME by default. # The screenshot will be moved into the screenshot directory -# Add this to ~/.config/user-dirs.dirs to save screenshots in a custom folder: -# XDG_SCREENSHOTS_DIR="$HOME/Screenshots" +# Defaults +SAVE_DIR="$HOME/Pictures" +SAVE_FILENAME="screenshot_$(date +%d%m%Y_%H%M%S).jpg" -prompt='Screenshot' -mesg="DIR: ~/Screenshots" +# Load Settings +if [ -f ~/.config/ml4w/settings/screenshot-folder ]; then + SAVE_DIR=$(cat ~/.config/ml4w/settings/screenshot-folder) +fi +if [ -f ~/.config/ml4w/settings/screenshot-filename ]; then + SAVE_FILENAME=$(cat ~/.config/ml4w/settings/screenshot-filename) +fi -SAVE_DIR=$(cat ~/.config/ml4w/settings/screenshot-folder) -SAVE_FILENAME=$(cat ~/.config/ml4w/settings/screenshot-filename) eval screenshot_folder="$SAVE_DIR" eval NAME="$SAVE_FILENAME" +# Get image format +image_format="png" +extension="${NAME##*.}" + +case $extension in + "jpg"|"jpeg") + image_format="jpeg" + ;; + "ppm") + image_format="ppm" + ;; +esac + # Notifications source "$HOME/.config/ml4w/scripts/ml4w-notification-handler" APP_NAME="Screen Capture" @@ -30,15 +47,9 @@ NOTIFICATION_ICON="camera-photo-symbolic" # Screenshot Editor export GRIMBLAST_EDITOR="$(cat ~/.config/ml4w/settings/screenshot-editor)" -# Example for keybindings -# bind = SUPER, p, exec, grimblast save active -# bind = SUPER SHIFT, p, exec, grimblast save area -# bind = SUPER ALT, p, exec, grimblast save output -# bind = SUPER CTRL, p, exec, grimblast save screen - # Quick instant mode: full screen take_instant_full() { - grim "$NAME" && notify_user \ + grim -t "$image_format" "$NAME" && notify_user \ --a "${APP_NAME}" \ --i "${NOTIFICATION_ICON}" \ --s "Screenshot saved" \ @@ -67,7 +78,7 @@ take_instant_area() { trap - EXIT # capture and notify - grim -g "$region" "$NAME" && notify_user \ + grim -g "$region" -t "$image_format" "$NAME" && notify_user \ --a "${APP_NAME}" \ --i "${NOTIFICATION_ICON}" \ --s "Screenshot saved" \ @@ -197,16 +208,19 @@ copy_save_editor_exit() { } # Confirm and execute +# Note: `grimblast` only supports png outpuut when copy is specified copy_save_editor_run() { selected_chosen="$(copy_save_editor_exit)" if [[ "$selected_chosen" == "$copy" ]]; then option_chosen=copy + image_format=png ${1} elif [[ "$selected_chosen" == "$save" ]]; then option_chosen=save ${1} elif [[ "$selected_chosen" == "$copy_save" ]]; then option_chosen=copysave + image_format=png ${1} elif [[ "$selected_chosen" == "$edit" ]]; then option_chosen=edit @@ -244,7 +258,7 @@ timer() { # take shots takescreenshot() { sleep 1 - grimblast --notify "$option_chosen" "$option_type_screenshot" $NAME + grimblast --notify "$option_chosen" --filetype "$image_format" "$option_type_screenshot" $NAME if [ -f $HOME/$NAME ]; then if [ -d $screenshot_folder ]; then mv $HOME/$NAME $screenshot_folder/ @@ -256,7 +270,7 @@ takescreenshot_timer() { sleep 1 timer sleep 1 - grimblast --notify "$option_chosen" "$option_type_screenshot" $NAME + grimblast --notify "$option_chosen" --filetype "$image_format" "$option_type_screenshot" $NAME if [ -f $HOME/$NAME ]; then if [ -d $screenshot_folder ]; then mv $HOME/$NAME $screenshot_folder/ diff --git a/dotfiles/.config/ml4w/bin/ml4w-screenshot b/dotfiles/.config/ml4w/bin/ml4w-screenshot index 500ae172e..0088f8a1d 100755 --- a/dotfiles/.config/ml4w/bin/ml4w-screenshot +++ b/dotfiles/.config/ml4w/bin/ml4w-screenshot @@ -23,6 +23,19 @@ eval screenshot_folder="$SAVE_DIR" eval filename="$SAVE_FILENAME" path="$screenshot_folder/$filename" +# Get image format +image_format="png" +extension="${filename##*.}" + +case $extension in + "jpg"|"jpeg") + image_format="jpeg" + ;; + "ppm") + image_format="ppm" + ;; +esac + # Create Screenshot folder mkdir -p "$SAVE_DIR" @@ -40,18 +53,18 @@ take_screenshot() { case $mode in "fullscreen") - grim "$path" + grim -t "$image_format" "$path" ;; "area") # slurp allows UI selection GEOM=$(slurp) [ -z "$GEOM" ] && exit 0 # Handle ESC/Cancel - grim -g "$GEOM" "$path" + grim -g "$GEOM" -t "$image_format" "$path" ;; "window") # Hyprland specific geometry GEOM=$(hyprctl activewindow -j | jq -r '"\(.at[0]),\(.at[1]) \(.size[0])x\(.size[1])"') - grim -g "$GEOM" "$path" + grim -g "$GEOM" -t "$image_format" "$path" ;; esac @@ -104,4 +117,4 @@ DELAY_CHOICE=$(echo -e "0s\n2s\n5s\n10s" | fzf \ # Strip the 's' from the delay choice (e.g., "5s" -> "5") CLEAN_DELAY=$(echo "$DELAY_CHOICE" | sed 's/s//') -take_screenshot "$MODE_CHOICE" "$CLEAN_DELAY" \ No newline at end of file +take_screenshot "$MODE_CHOICE" "$CLEAN_DELAY"