Capture screenshots in the compositor instead of grim

This commit is contained in:
Samuel Onoja committed 2026-09-29 15:51:56 +01:00
1 parent 4b70cb40e0
commit eda453dabd
15 files changed
+2770 -171

No files matched your search

+23 -11
View File
@@ -25,7 +25,7 @@ case ${1:-} in
esac
(($# == 0)) || fail 'Usage: ferese-screenshot [--full | --all]'
for tool in grim satty wl-copy flock; do
for tool in feresectl satty wl-copy flock python3; do
command -v "$tool" >/dev/null || fail "Required command not found: $tool"
done
: "${XDG_RUNTIME_DIR:?A Wayland login session is required}"
@@ -40,21 +40,18 @@ if [[ $mode == area ]]; then
[[ -n $geometry ]] || exit 0
capture_args=(-g "$geometry")
elif [[ $mode == full ]]; then
for tool in feresectl python3; do
command -v "$tool" >/dev/null || fail "Required command not found: $tool"
done
# Resolve the active monitor before Satty can change keyboard focus.
# Never fall back to grim's all-monitor capture when IPC is unavailable.
output=$(feresectl get-outputs | python3 -c '
# Never fall back to an all-monitor capture when IPC is unavailable.
geometry=$(feresectl get-outputs | python3 -c '
import json, sys
outputs = [output for output in json.load(sys.stdin) if output.get("enabled")]
focused = [output for output in outputs if output.get("focused")]
selected = focused if len(focused) == 1 else outputs if len(outputs) == 1 else []
if len(selected) != 1 or not selected[0].get("name"):
if len(selected) != 1 or any(selected[0].get(k) is None for k in ("x", "y", "width", "height")):
sys.exit(1)
print(selected[0]["name"])
print("%d,%d %dx%d" % (selected[0]["x"], selected[0]["y"], selected[0]["width"], selected[0]["height"]))
') || fail 'Could not determine the active monitor. Use area selection or --all.'
capture_args=(-o "$output")
capture_args=(-g "$geometry")
fi
pictures=$(xdg-user-dir PICTURES 2>/dev/null) || pictures="$HOME/Pictures"
directory=${pictures:-$HOME/Pictures}/Screenshots
@@ -63,12 +60,27 @@ file=$(mktemp "$directory/Screenshot-$(date +%Y-%m-%d_%H-%M-%S)-XXXXXX.png") ||
input=''
trap '[[ -z $input ]] || rm -f -- "$input"; [[ -s $file ]] || rm -f -- "$file"' EXIT
input=$(mktemp "$XDG_RUNTIME_DIR/ferese-screenshot-XXXXXX.png") || fail 'Could not create the temporary capture.'
grim "${capture_args[@]}" "$input" || fail 'Could not capture the screen. Log back into Ferese after enabling screen capture.'
feresectl screenshot "${capture_args[@]}" >"$input" || fail 'Could not capture the screen. Ferese must be running, unlocked, and reachable over its socket.'
editor_size=$(feresectl get-outputs | python3 -c '
import json, sys
outputs = [output for output in json.load(sys.stdin) if output.get("enabled")]
focused = [output for output in outputs if output.get("focused")]
selected = focused if len(focused) == 1 else outputs if len(outputs) == 1 else []
if len(selected) != 1 or any(selected[0].get(key) is None for key in ("width", "height")):
sys.exit(1)
width = max(1, min(1500, round(selected[0]["width"] * 0.8)))
height = max(1, min(920, round(selected[0]["height"] * 0.8), round(width * 0.68)))
print(f"{width}x{height}")
') || editor_size=1000x700
# Enter saves the annotated image and copies it; Escape discards the capture.
# Keep the parent lock through editing. Close it only in Satty so clipboard
# helpers cannot inherit the lock and keep later screenshots blocked.
satty --filename "$input" --output-filename "$file" \
--fullscreen current-screen \
--app-id dev.ferese.Screenshot \
--resize "$editor_size" \
--no-window-decoration \
--copy-command 'wl-copy --type image/png' \
--save-after-copy \
--actions-on-enter save-to-file,save-to-clipboard,exit \