Skip to content

Commit

Permalink
grimblast: hide the grim cursor before taking a screenshot (#132)
Browse files Browse the repository at this point in the history
* grimblast: try hiding the grim cursor before taking a screenshot

* grimblast: do not hardcode the cursor's new position

* grimblast: use the monitor's height for the cursor's new position

* grimblast: avoid breaking 'hyprctl' when having multiple monitors

* grimblast: fix typo

* grimblast: create a temporary virtual display to hide the cursor

* grimblast: make sure that the virtual display is not included in a screenshot

* grimblast: update CHANGELOG.md

* grimblast: add '' around variables.
  • Loading branch information
DHDcc authored Mar 1, 2025
1 parent 50e1dcb commit 28185f2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

### 2025-03-01

grimblast: hide the grim cursor before taking a screenshot

### 2024-08-02

grimblast: changed method to check if another instance is running
Expand Down
19 changes: 17 additions & 2 deletions grimblast/grimblast
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,31 @@ check() {
echo " $COMMAND: $RESULT"
}

moveCursorPosition() {
initialCursorPosition=$(hyprctl cursorpos)
virtualDisplayName="grimblastVD"
focusedMonitorName=$(hyprctl -j monitors | jq -r '.[] | select( .focused == true ) | .name')

hyprctl output create headless "$virtualDisplayName" >/dev/null
hyprctl dispatch focusmonitor "$virtualDisplayName" >/dev/null
}

restoreCursorPosition() {
hyprctl dispatch focusmonitor "$focusedMonitorName" >/dev/null
hyprctl output remove "$virtualDisplayName" >/dev/null
hyprctl dispatch movecursor "${initialCursorPosition//,}" >/dev/null
}

takeScreenshot() {
FILE=$1
GEOM=$2
OUTPUT=$3
if [ -n "$OUTPUT" ]; then
grim ${CURSOR:+-c} ${SCALE:+-s "$SCALE"} -o "$OUTPUT" "$FILE" || die "Unable to invoke grim"
moveCursorPosition && grim ${CURSOR:+-c} ${SCALE:+-s "$SCALE"} -o "$OUTPUT" "$FILE" && restoreCursorPosition || die "Unable to invoke grim"
elif [ -z "$GEOM" ]; then
grim ${CURSOR:+-c} ${SCALE:+-s "$SCALE"} "$FILE" || die "Unable to invoke grim"
else
grim ${CURSOR:+-c} ${SCALE:+-s "$SCALE"} -g "$GEOM" "$FILE" || die "Unable to invoke grim"
moveCursorPosition && grim ${CURSOR:+-c} ${SCALE:+-s "$SCALE"} -g "$GEOM" "$FILE" && restoreCursorPosition || die "Unable to invoke grim"
resetFade
fi
}
Expand Down

2 comments on commit 28185f2

@DHDcc
Copy link
Contributor Author

@DHDcc DHDcc commented on 28185f2 Mar 2, 2025

Choose a reason for hiding this comment

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

@fufexan is this commit going into the main branch?

@fufexan
Copy link
Member

@fufexan fufexan commented on 28185f2 Mar 2, 2025

Choose a reason for hiding this comment

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

Oh I didn't even notice you didn't base the PR on master. Sure, I'll cherry-pick it.

Please sign in to comment.