2024-10-15 02:40:43 -04:00
|
|
|
{ pkgs, config, ... }:
|
2024-10-09 03:36:08 -04:00
|
|
|
{
|
2024-11-24 20:02:09 -05:00
|
|
|
imports = [ ./swappy ];
|
2024-10-07 11:42:34 -04:00
|
|
|
|
2024-11-05 16:09:49 -05:00
|
|
|
home.packages = with pkgs; [
|
|
|
|
(pkgs.writeScriptBin "swayshot" ''
|
2024-08-24 22:16:51 -04:00
|
|
|
# Swappy
|
|
|
|
handle_swappy() {
|
|
|
|
# Create an imv window to act as a static screen
|
2024-10-01 18:18:26 -04:00
|
|
|
grim -t jpeg -q 90 - | imv -w "GlobalShot" - & imv_pid=$!
|
2024-08-24 22:16:51 -04:00
|
|
|
|
|
|
|
# Capture the screenshot of the selected area and save to a temporary file
|
|
|
|
selected_area=$(swaymsg -t get_tree | jq -r '.. | select(.pid? and .visible?) | .rect | "\(.x),\(.y) \(.width)x\(.height)"'\
|
2024-10-15 02:40:43 -04:00
|
|
|
| XCURSOR_SIZE=40 slurp -w ${config.look.border.string} -c ${config.look.colors.prime} -B 00000066 -b 00000099)
|
2024-08-24 22:16:51 -04:00
|
|
|
temp_file=$(mktemp -u).png
|
|
|
|
grim -g "$selected_area" "$temp_file"
|
|
|
|
|
|
|
|
# Kill the imv window
|
|
|
|
kill $imv_pid
|
|
|
|
|
|
|
|
# Copy the screenshot to the clipboard
|
|
|
|
swappy -f - < "$temp_file"
|
|
|
|
|
|
|
|
# Clean up the temporary file
|
|
|
|
rm "$temp_file"
|
|
|
|
}
|
|
|
|
|
2024-10-01 18:18:26 -04:00
|
|
|
# Screen
|
|
|
|
handle_screen() {
|
2024-08-24 22:16:51 -04:00
|
|
|
# Take a screenshot and save it to the temporary file
|
|
|
|
temp_file=$(mktemp -u).png
|
2024-10-15 13:48:33 -04:00
|
|
|
grim -o $(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .name') "$temp_file"
|
2024-08-24 22:16:51 -04:00
|
|
|
|
|
|
|
# Check if the screenshot was successfully taken
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
# Copy the screenshot to the clipboard
|
|
|
|
wl-copy < "$temp_file"
|
|
|
|
|
|
|
|
# Show a notification with the screenshot
|
|
|
|
notify-send -i "$temp_file" "Current screen copied."
|
|
|
|
|
|
|
|
# Remove the temporary file
|
|
|
|
rm "$temp_file"
|
|
|
|
else
|
|
|
|
# If the screenshot capture failed, show an error notification
|
|
|
|
notify-send "Error: Unable to capture screenshot."
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Check for command-line arguments
|
|
|
|
if [ "$1" == "--swappy" ]; then
|
|
|
|
handle_swappy
|
2024-10-01 18:18:26 -04:00
|
|
|
elif [ "$1" == "--screen" ]; then
|
|
|
|
handle_screen
|
2024-08-24 22:16:51 -04:00
|
|
|
else
|
2024-10-01 18:18:26 -04:00
|
|
|
echo "Please use the arguments --swappy or --screen."
|
2024-08-24 22:16:51 -04:00
|
|
|
fi
|
2024-11-05 16:09:49 -05:00
|
|
|
'')
|
2024-08-24 22:16:51 -04:00
|
|
|
];
|
|
|
|
}
|