forked from mirrors_public/oddlama_nix-config
feat: convert screenshot scripts to wayland
This commit is contained in:
parent
3a0cec46f3
commit
3b602b322a
5 changed files with 97 additions and 72 deletions
|
@ -1,16 +1,23 @@
|
|||
{
|
||||
lib,
|
||||
writeShellApplication,
|
||||
flameshot,
|
||||
grimblast,
|
||||
libnotify,
|
||||
xclip,
|
||||
tesseract,
|
||||
wl-clipboard,
|
||||
yq,
|
||||
zbar,
|
||||
}:
|
||||
writeShellApplication {
|
||||
name = "screenshot-area-scan-qr";
|
||||
runtimeInputs = [
|
||||
grimblast
|
||||
libnotify
|
||||
tesseract
|
||||
wl-clipboard
|
||||
yq
|
||||
zbar
|
||||
];
|
||||
text = ''
|
||||
set -euo pipefail
|
||||
umask 077
|
||||
|
||||
# Create in-memory tmpfile
|
||||
|
@ -19,40 +26,31 @@ writeShellApplication {
|
|||
rm "$TMPFILE" # still open in-memory as /dev/fd/3
|
||||
TMPFILE=/dev/fd/3
|
||||
|
||||
date=$(date +"%Y-%m-%dT%H:%M:%S%:z")
|
||||
|
||||
# Always use native scaling to ensure flameshot is fullscreen across monitors
|
||||
export QT_AUTO_SCREEN_SCALE_FACTOR=0
|
||||
export QT_SCREEN_SCALE_FACTORS=""
|
||||
|
||||
if ${lib.getExe flameshot} gui --raw \
|
||||
| ${zbar}/bin/zbarimg --xml - > "$TMPFILE"; then
|
||||
N=$(${yq}/bin/xq -r '.barcodes.source.index.symbol | if type == "array" then length else 1 end' < "$TMPFILE")
|
||||
if grimblast --freeze save area - \
|
||||
| zbarimg --xml - > "$TMPFILE"; then
|
||||
N=$(xq -r '.barcodes.source.index.symbol | if type == "array" then length else 1 end' < "$TMPFILE")
|
||||
# Append codes Copy data separated by ---
|
||||
DATA=$(${yq}/bin/xq -r '.barcodes.source.index.symbol | if type == "array" then .[0].data else .data end' < "$TMPFILE")
|
||||
DATA=$(xq -r '.barcodes.source.index.symbol | if type == "array" then .[0].data else .data end' < "$TMPFILE")
|
||||
for ((i=1;i<N;++i)); do
|
||||
DATA="$DATA"$'\n'"---"$'\n'"$(${yq}/bin/xq -r ".barcodes.source.index.symbol[$i].data" < "$TMPFILE")"
|
||||
DATA="$DATA"$'\n'"---"$'\n'"$(xq -r ".barcodes.source.index.symbol[$i].data" < "$TMPFILE")"
|
||||
done
|
||||
${xclip}/bin/xclip -selection clipboard <<< "$DATA"
|
||||
${libnotify}/bin/notify-send \
|
||||
wl-copy <<< "$DATA"
|
||||
notify-send \
|
||||
"🔍 QR Code scan" "✅ $N codes detected\n📋 copied ''${#DATA} bytes" \
|
||||
--hint="string:image-path:"${./assets}/qr-scan.png \
|
||||
--hint="string:wired-tag:screenshot-$date" \
|
||||
|| true
|
||||
else
|
||||
case "$?" in
|
||||
"4")
|
||||
${libnotify}/bin/notify-send \
|
||||
notify-send \
|
||||
"🔍 QR Code scan" "❌ 0 codes detected" \
|
||||
--hint="string:image-path:"${./assets}/qr-scan.png \
|
||||
--hint="string:wired-tag:screenshot-$date" \
|
||||
|| true
|
||||
;;
|
||||
*)
|
||||
${libnotify}/bin/notify-send \
|
||||
notify-send \
|
||||
"🔍 QR Code scan" "❌ Error while processing image: zbarimg exited with code $?" \
|
||||
--hint="string:image-path:"${./assets}/qr-scan.png \
|
||||
--hint="string:wired-tag:screenshot-$date" \
|
||||
|| true
|
||||
;;
|
||||
esac
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue