Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
46 changes: 30 additions & 16 deletions dotfiles/.config/hypr/scripts/screenshot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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" \
Expand Down Expand Up @@ -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" \
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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/
Expand All @@ -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/
Expand Down
21 changes: 17 additions & 4 deletions dotfiles/.config/ml4w/bin/ml4w-screenshot
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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

Expand Down Expand Up @@ -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"
take_screenshot "$MODE_CHOICE" "$CLEAN_DELAY"