mirror of
https://github.com/oddlama/nix-config.git
synced 2025-10-10 23:00:39 +02:00
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,
|
writeShellApplication,
|
||||||
flameshot,
|
grimblast,
|
||||||
libnotify,
|
libnotify,
|
||||||
xclip,
|
tesseract,
|
||||||
|
wl-clipboard,
|
||||||
yq,
|
yq,
|
||||||
zbar,
|
zbar,
|
||||||
}:
|
}:
|
||||||
writeShellApplication {
|
writeShellApplication {
|
||||||
name = "screenshot-area-scan-qr";
|
name = "screenshot-area-scan-qr";
|
||||||
|
runtimeInputs = [
|
||||||
|
grimblast
|
||||||
|
libnotify
|
||||||
|
tesseract
|
||||||
|
wl-clipboard
|
||||||
|
yq
|
||||||
|
zbar
|
||||||
|
];
|
||||||
text = ''
|
text = ''
|
||||||
set -euo pipefail
|
|
||||||
umask 077
|
umask 077
|
||||||
|
|
||||||
# Create in-memory tmpfile
|
# Create in-memory tmpfile
|
||||||
|
@ -19,40 +26,31 @@ writeShellApplication {
|
||||||
rm "$TMPFILE" # still open in-memory as /dev/fd/3
|
rm "$TMPFILE" # still open in-memory as /dev/fd/3
|
||||||
TMPFILE=/dev/fd/3
|
TMPFILE=/dev/fd/3
|
||||||
|
|
||||||
date=$(date +"%Y-%m-%dT%H:%M:%S%:z")
|
if grimblast --freeze save area - \
|
||||||
|
| zbarimg --xml - > "$TMPFILE"; then
|
||||||
# Always use native scaling to ensure flameshot is fullscreen across monitors
|
N=$(xq -r '.barcodes.source.index.symbol | if type == "array" then length else 1 end' < "$TMPFILE")
|
||||||
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")
|
|
||||||
# Append codes Copy data separated by ---
|
# 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
|
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
|
done
|
||||||
${xclip}/bin/xclip -selection clipboard <<< "$DATA"
|
wl-copy <<< "$DATA"
|
||||||
${libnotify}/bin/notify-send \
|
notify-send \
|
||||||
"🔍 QR Code scan" "✅ $N codes detected\n📋 copied ''${#DATA} bytes" \
|
"🔍 QR Code scan" "✅ $N codes detected\n📋 copied ''${#DATA} bytes" \
|
||||||
--hint="string:image-path:"${./assets}/qr-scan.png \
|
--hint="string:image-path:"${./assets}/qr-scan.png \
|
||||||
--hint="string:wired-tag:screenshot-$date" \
|
|
||||||
|| true
|
|| true
|
||||||
else
|
else
|
||||||
case "$?" in
|
case "$?" in
|
||||||
"4")
|
"4")
|
||||||
${libnotify}/bin/notify-send \
|
notify-send \
|
||||||
"🔍 QR Code scan" "❌ 0 codes detected" \
|
"🔍 QR Code scan" "❌ 0 codes detected" \
|
||||||
--hint="string:image-path:"${./assets}/qr-scan.png \
|
--hint="string:image-path:"${./assets}/qr-scan.png \
|
||||||
--hint="string:wired-tag:screenshot-$date" \
|
|
||||||
|| true
|
|| true
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
${libnotify}/bin/notify-send \
|
notify-send \
|
||||||
"🔍 QR Code scan" "❌ Error while processing image: zbarimg exited with code $?" \
|
"🔍 QR Code scan" "❌ Error while processing image: zbarimg exited with code $?" \
|
||||||
--hint="string:image-path:"${./assets}/qr-scan.png \
|
--hint="string:image-path:"${./assets}/qr-scan.png \
|
||||||
--hint="string:wired-tag:screenshot-$date" \
|
|
||||||
|| true
|
|| true
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
|
@ -1,55 +1,84 @@
|
||||||
{
|
{
|
||||||
lib,
|
|
||||||
writeShellApplication,
|
writeShellApplication,
|
||||||
flameshot,
|
grimblast,
|
||||||
libnotify,
|
libnotify,
|
||||||
moreutils,
|
|
||||||
tesseract,
|
tesseract,
|
||||||
xclip,
|
wl-clipboard,
|
||||||
}:
|
}:
|
||||||
writeShellApplication {
|
writeShellApplication {
|
||||||
name = "screenshot-area";
|
name = "screenshot-area";
|
||||||
|
runtimeInputs = [
|
||||||
|
grimblast
|
||||||
|
libnotify
|
||||||
|
tesseract
|
||||||
|
wl-clipboard
|
||||||
|
];
|
||||||
text = ''
|
text = ''
|
||||||
set -euo pipefail
|
|
||||||
umask 077
|
umask 077
|
||||||
|
|
||||||
date=$(date +"%Y-%m-%dT%H:%M:%S%:z")
|
date=$(date +"%Y-%m-%dT%H:%M:%S%:z")
|
||||||
out="''${XDG_PICTURES_DIR-$HOME/Pictures}/screenshots/$date-selection.png"
|
out="''${XDG_PICTURES_DIR-$HOME/Pictures}/screenshots/$date-selection.png"
|
||||||
mkdir -p "$(dirname "$out")"
|
mkdir -p "$(dirname "$out")"
|
||||||
|
|
||||||
# Always use native scaling to ensure flameshot is fullscreen across monitors
|
grimblast --freeze save area "$out" || exit 2
|
||||||
export QT_AUTO_SCREEN_SCALE_FACTOR=0
|
wl-copy -t image/png < "$out"
|
||||||
export QT_SCREEN_SCALE_FACTORS=""
|
|
||||||
|
|
||||||
# Use sponge to create the file on success only
|
declare -A NOTIFICATION_IDS
|
||||||
if ${lib.getExe flameshot} gui --raw 2>&1 1> >(${moreutils}/bin/sponge "$out") | grep -q "flameshot: info:.*aborted."; then
|
function notify_wait_action() {
|
||||||
exit 1
|
id="$1"
|
||||||
fi
|
shift 1
|
||||||
|
|
||||||
${xclip}/bin/xclip -selection clipboard -t image/png < "$out"
|
args=("--print-id")
|
||||||
action=$(${libnotify}/bin/notify-send \
|
if [[ -v "NOTIFICATION_IDS[$id]" ]]; then
|
||||||
"📷 Screenshot captured" "📋 copied to clipboard" \
|
args+=("--replace-id=''${NOTIFICATION_IDS[$id]}")
|
||||||
--hint="string:wired-tag:screenshot-$date" \
|
|
||||||
--action=ocr=OCR) \
|
|
||||||
|| true
|
|
||||||
|
|
||||||
if [[ "$action" == "ocr" ]]; then
|
|
||||||
${libnotify}/bin/notify-send \
|
|
||||||
"📷 Screenshot captured" "⏳ Running OCR ..." \
|
|
||||||
--hint="string:wired-tag:screenshot-$date" \
|
|
||||||
|| true
|
|
||||||
|
|
||||||
if ${tesseract}/bin/tesseract "$out" - -l eng+deu | ${xclip}/bin/xclip -selection clipboard; then
|
|
||||||
${libnotify}/bin/notify-send \
|
|
||||||
"📷 Screenshot captured" "🔠 OCR copied to clipboard" \
|
|
||||||
--hint="string:wired-tag:screenshot-$date" \
|
|
||||||
|| true
|
|
||||||
else
|
|
||||||
${libnotify}/bin/notify-send \
|
|
||||||
"📷 Screenshot captured" "❌ Error while running OCR" \
|
|
||||||
--hint="string:wired-tag:screenshot-$date" \
|
|
||||||
|| true
|
|
||||||
fi
|
fi
|
||||||
fi
|
args+=("$@")
|
||||||
|
|
||||||
|
readarray -t __notify_output < <(notify-send "''${args[@]}" || true)
|
||||||
|
NOTIFICATION_IDS["$id"]="''${__notify_output[0]-}"
|
||||||
|
echo "''${__notify_output[1]-}"
|
||||||
|
}
|
||||||
|
|
||||||
|
function notify_nowait() {
|
||||||
|
id="$1"
|
||||||
|
shift 1
|
||||||
|
|
||||||
|
args=("--print-id")
|
||||||
|
if [[ -v "NOTIFICATION_IDS[$id]" ]]; then
|
||||||
|
args+=("--replace-id=''${NOTIFICATION_IDS[$id]}")
|
||||||
|
fi
|
||||||
|
args+=("$@")
|
||||||
|
|
||||||
|
readarray -t __notify_output < <(notify-send "''${args[@]}" || true)
|
||||||
|
NOTIFICATION_IDS["$id"]="''${__notify_output[0]-}"
|
||||||
|
unset __notify_output
|
||||||
|
}
|
||||||
|
|
||||||
|
title="📷 Screenshot captured"
|
||||||
|
body="📋 image copied to clipboard"
|
||||||
|
while true; do
|
||||||
|
action=$(notify_wait_action main "$title" "$body" \
|
||||||
|
--action=ocr="Run OCR" \
|
||||||
|
--action=copy="Copy Image")
|
||||||
|
|
||||||
|
case "$action" in
|
||||||
|
ocr)
|
||||||
|
notify_nowait main "$title" "⏳ Running OCR ..."
|
||||||
|
|
||||||
|
if tesseract "$out" - -l eng+deu | wl-copy; then
|
||||||
|
body="🔠 OCR copied to clipboard"
|
||||||
|
else
|
||||||
|
body="❌ Error while running OCR"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
|
||||||
|
copy)
|
||||||
|
wl-copy -t image/png < "$out"
|
||||||
|
body="📋 image copied to clipboard"
|
||||||
|
;;
|
||||||
|
|
||||||
|
*) exit 0 ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,24 +1,23 @@
|
||||||
{
|
{
|
||||||
lib,
|
|
||||||
writeShellApplication,
|
writeShellApplication,
|
||||||
flameshot,
|
grimblast,
|
||||||
libnotify,
|
libnotify,
|
||||||
moreutils,
|
|
||||||
}:
|
}:
|
||||||
writeShellApplication {
|
writeShellApplication {
|
||||||
name = "screenshot-screen";
|
name = "screenshot-screen";
|
||||||
|
runtimeInputs = [
|
||||||
|
grimblast
|
||||||
|
libnotify
|
||||||
|
];
|
||||||
text = ''
|
text = ''
|
||||||
set -euo pipefail
|
|
||||||
umask 077
|
umask 077
|
||||||
|
|
||||||
date=$(date +"%Y-%m-%dT%H:%M:%S%:z")
|
date=$(date +"%Y-%m-%dT%H:%M:%S%:z")
|
||||||
out="''${XDG_PICTURES_DIR-$HOME/Pictures}/screenshots/$date-fullscreen.png"
|
out="''${XDG_PICTURES_DIR-$HOME/Pictures}/screenshots/$date-fullscreen.png"
|
||||||
mkdir -p "$(dirname "$out")"
|
mkdir -p "$(dirname "$out")"
|
||||||
|
|
||||||
if ${lib.getExe flameshot} full --raw 2>&1 1> >(${moreutils}/bin/sponge "$out") | grep -q "flameshot: info:.*aborted."; then
|
grimblast --freeze save screen "$out" || exit 2
|
||||||
exit 1
|
notify-send \
|
||||||
fi
|
|
||||||
${libnotify}/bin/notify-send \
|
|
||||||
"📷 Screenshot captured" "💾 Saved to $out" \
|
"📷 Screenshot captured" "💾 Saved to $out" \
|
||||||
--hint="string:wired-tag:screenshot-$date" \
|
--hint="string:wired-tag:screenshot-$date" \
|
||||||
|| true
|
|| true
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
# TODO: waybar qr scan button
|
# TODO: waybar qr scan button
|
||||||
# TODO: waybar color picker button
|
# TODO: waybar color picker button
|
||||||
# TODO: notification center toggle
|
# TODO: notification center toggle
|
||||||
|
# TODO: screencast button with notification
|
||||||
# TODO ai speech indicator / toggle
|
# TODO ai speech indicator / toggle
|
||||||
{
|
{
|
||||||
lib,
|
lib,
|
||||||
|
@ -13,6 +14,7 @@
|
||||||
concatMap
|
concatMap
|
||||||
elem
|
elem
|
||||||
flip
|
flip
|
||||||
|
getExe
|
||||||
mkIf
|
mkIf
|
||||||
mkMerge
|
mkMerge
|
||||||
optionals
|
optionals
|
||||||
|
@ -58,10 +60,9 @@ in {
|
||||||
"SUPER,b,exec,firefox"
|
"SUPER,b,exec,firefox"
|
||||||
|
|
||||||
# Shortcuts & Actions
|
# Shortcuts & Actions
|
||||||
#"SUPER + SHIFT,s,exec ${getExe pkgs.scripts.screenshot-area}"
|
"SUPER + SHIFT,s,exec,${getExe pkgs.scripts.screenshot-area}"
|
||||||
#"SUPER,F11,exec ${getExe pkgs.scripts.screenshot-area-scan-qr}"
|
"SUPER,F11,exec,${getExe pkgs.scripts.screenshot-area-scan-qr}"
|
||||||
#"SUPER,F12,exec ${getExe pkgs.scripts.screenshot-screen}"
|
"SUPER,F12,exec,${getExe pkgs.scripts.screenshot-screen}"
|
||||||
#"SUPER,Print,exec ${getExe pkgs.flameshot} gui"
|
|
||||||
|
|
||||||
# Per-window actions
|
# Per-window actions
|
||||||
"SUPER,q,killactive,"
|
"SUPER,q,killactive,"
|
||||||
|
@ -115,7 +116,6 @@ in {
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
cursor.no_warps = true;
|
|
||||||
decoration.rounding = 4;
|
decoration.rounding = 4;
|
||||||
|
|
||||||
input = {
|
input = {
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
enable = true;
|
enable = true;
|
||||||
package = pkgs.rofi-wayland;
|
package = pkgs.rofi-wayland;
|
||||||
extraConfig = {
|
extraConfig = {
|
||||||
matching = "fuzzy";
|
|
||||||
terminal = "kitty";
|
terminal = "kitty";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue