Skip to content

Commit

Permalink
grimblast: allow opening file folder when clicking notification (#126)
Browse files Browse the repository at this point in the history
* grimblast opens the file directory when notification is clicked when --openfile is set

* change CHANGELOG to reflect previous commit

* added notification for users without dbus-send

* add --openfile documentation in manpage
  • Loading branch information
PacificViking authored Jan 29, 2025
1 parent 2967407 commit f4bea56
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

grimblast: allow decimals for --wait

### 2025-01-21

grimblast: allow opening file directory when clicking on notification when --openfile is set

### 2024-12-01

grimblast: fix window selection on fullscreen
Expand Down
27 changes: 25 additions & 2 deletions grimblast/grimblast
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ env_editor_confirm() {
}

NOTIFY=no
OPENFILE_NOTIFICATION=no
CURSOR=
FREEZE=
WAIT=no
Expand All @@ -64,6 +65,10 @@ while [ $# -gt 0 ]; do
NOTIFY=yes
shift # past argument
;;
-o | --openfile)
OPENFILE_NOTIFICATION=yes
shift # past argument
;;
-c | --cursor)
CURSOR=yes
shift # past argument
Expand Down Expand Up @@ -104,7 +109,7 @@ FILE_EDITOR=${3:-$(tmp_editor_directory)/$(date -Ins).png}

if [ "$ACTION" != "save" ] && [ "$ACTION" != "copy" ] && [ "$ACTION" != "edit" ] && [ "$ACTION" != "copysave" ] && [ "$ACTION" != "check" ]; then
echo "Usage:"
echo " grimblast [--notify] [--cursor] [--freeze] [--wait N] [--scale <scale>] (copy|save|copysave|edit) [active|screen|output|area] [FILE|-]"
echo " grimblast [--notify] [--openfile] [--cursor] [--freeze] [--wait N] [--scale <scale>] (copy|save|copysave|edit) [active|screen|output|area] [FILE|-]"
echo " grimblast check"
echo " grimblast usage"
echo ""
Expand Down Expand Up @@ -134,6 +139,23 @@ notifyOk() {
notify "$@"
}

notifyOpen() {
if [ "$OPENFILE_NOTIFICATION" = "no" ]; then
notifyOk
else
outt=$(notify-send -A "default=open_folder" -a grimblast "$@")
if [ "$outt" == "default" ]; then
# this does not work for filenames with commas in them
if dbus-send --session --print-reply --dest=org.freedesktop.FileManager1 --type=method_call /org/freedesktop/FileManager1 org.freedesktop.FileManager1.ShowItems array:string:"$4" string:""; then
:
else
notify-send -t 3000 -a grimblast "Error displaying folder with dbus-send";
echo "Displayed: Error displaying folder with dbus-send";
fi
fi
fi
}

notifyError() {
if [ $NOTIFY = "yes" ]; then
TITLE=${2:-"Screenshot"}
Expand Down Expand Up @@ -248,7 +270,8 @@ elif [ "$ACTION" = "save" ]; then
if takeScreenshot "$FILE" "$GEOM" "$OUTPUT"; then
TITLE="Screenshot of $SUBJECT"
MESSAGE=$(basename "$FILE")
notifyOk "$TITLE" "$MESSAGE" -i "$FILE"
killHyprpicker
notifyOpen "$TITLE" "$MESSAGE" -i "$FILE"
echo "$FILE"
else
notifyError "Error taking screenshot with grim"
Expand Down
4 changes: 4 additions & 0 deletions grimblast/grimblast.1.scd
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ grimblast - a helper for screenshots within hyprland
*--notify*
Show notifications to the user that a screenshot has been taken.

*--openfile*
Uses dbus to display the folder containing the file when interacting with the
notification, only works with --notify

*--cursor*
Include cursors in the screenshot.

Expand Down

0 comments on commit f4bea56

Please sign in to comment.