From d081e70d78ec46a475b80e9d44c3d3c7219d3e2c Mon Sep 17 00:00:00 2001 From: oddlama Date: Mon, 16 Oct 2023 02:10:32 +0200 Subject: [PATCH] feat: use flameshot for screenshotting (twice as fast for fullscreen) --- pkgs/scripts/assets/qr-scan.svg | 13 +++++++++++++ pkgs/scripts/screenshot-area-scan-qr.nix | 19 +++++++++++-------- pkgs/scripts/screenshot-area.nix | 14 ++++++++++---- pkgs/scripts/screenshot-screen.nix | 10 +++++++--- users/myuser/graphical/i3.nix | 3 ++- 5 files changed, 43 insertions(+), 16 deletions(-) create mode 100644 pkgs/scripts/assets/qr-scan.svg diff --git a/pkgs/scripts/assets/qr-scan.svg b/pkgs/scripts/assets/qr-scan.svg new file mode 100644 index 0000000..75f6650 --- /dev/null +++ b/pkgs/scripts/assets/qr-scan.svg @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/pkgs/scripts/screenshot-area-scan-qr.nix b/pkgs/scripts/screenshot-area-scan-qr.nix index bb61fc4..2a0ed3c 100644 --- a/pkgs/scripts/screenshot-area-scan-qr.nix +++ b/pkgs/scripts/screenshot-area-scan-qr.nix @@ -1,10 +1,11 @@ { + lib, writeShellApplication, + flameshot, libnotify, xclip, - maim, - zbar, yq, + zbar, }: writeShellApplication { name = "screenshot-area-scan-qr"; @@ -19,10 +20,12 @@ writeShellApplication { TMPFILE=/dev/fd/3 date=$(date +"%Y-%m-%dT%H:%M:%S%:z") - out="''${XDG_PICTURES_DIR-$HOME/Pictures}/screenshots/$date-selection.png" - mkdir -p "$(dirname "$out")" - if ${maim}/bin/maim --color=.4,.7,1 --bordersize=1.0 --nodecorations=1 --hidecursor --format=png --quality=10 --noopengl --select \ + # 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") # Append codes Copy data separated by --- @@ -33,7 +36,7 @@ writeShellApplication { ${xclip}/bin/xclip -selection clipboard <<< "$DATA" ${libnotify}/bin/notify-send \ "šŸ” QR Code scan" "āœ… $N codes detected\nšŸ“‹ copied ''${#DATA} bytes" \ - --hint="string:image-path:$out" \ + --hint="string:image-path:"${./assets/qr-scan.svg} \ --hint="string:wired-tag:screenshot-$date" \ || true else @@ -41,14 +44,14 @@ writeShellApplication { "4") ${libnotify}/bin/notify-send \ "šŸ” QR Code scan" "āŒ 0 codes detected" \ - --hint="string:image-path:$out" \ + --hint="string:image-path:"${./assets/qr-scan.svg} \ --hint="string:wired-tag:screenshot-$date" \ || true ;; *) ${libnotify}/bin/notify-send \ "šŸ” QR Code scan" "āŒ Error while processing image: zbarimg exited with code $?" \ - --hint="string:image-path:$out" \ + --hint="string:image-path:"${./assets/qr-scan.svg} \ --hint="string:wired-tag:screenshot-$date" \ || true ;; diff --git a/pkgs/scripts/screenshot-area.nix b/pkgs/scripts/screenshot-area.nix index c30daaf..484f70b 100644 --- a/pkgs/scripts/screenshot-area.nix +++ b/pkgs/scripts/screenshot-area.nix @@ -1,9 +1,11 @@ { + lib, writeShellApplication, + flameshot, libnotify, - xclip, + moreutils, tesseract, - maim, + xclip, }: writeShellApplication { name = "screenshot-area"; @@ -15,8 +17,12 @@ writeShellApplication { out="''${XDG_PICTURES_DIR-$HOME/Pictures}/screenshots/$date-selection.png" mkdir -p "$(dirname "$out")" - ${maim}/bin/maim --color=.4,.7,1,0.2 --bordersize=1.0 --nodecorations=1 \ - --hidecursor --format=png --quality=10 --noopengl --select "$out" + # Always use native scaling to ensure flameshot is fullscreen across monitors + export QT_AUTO_SCREEN_SCALE_FACTOR=0 + export QT_SCREEN_SCALE_FACTORS="" + + # Use sponge to create the file on success only + ${lib.getExe flameshot} gui --raw | ${moreutils}/bin/sponge "$out" ${xclip}/bin/xclip -selection clipboard -t image/png < "$out" action=$(${libnotify}/bin/notify-send \ "šŸ“· Screenshot captured" "šŸ“‹ copied to clipboard" \ diff --git a/pkgs/scripts/screenshot-screen.nix b/pkgs/scripts/screenshot-screen.nix index d0bf7ca..82eaf47 100644 --- a/pkgs/scripts/screenshot-screen.nix +++ b/pkgs/scripts/screenshot-screen.nix @@ -1,7 +1,9 @@ { + lib, writeShellApplication, + flameshot, libnotify, - maim, + moreutils, }: writeShellApplication { name = "screenshot-screen"; @@ -9,12 +11,14 @@ writeShellApplication { set -euo pipefail umask 077 - out="''${XDG_PICTURES_DIR-$HOME/Pictures}/screenshots/$(date +"%Y-%m-%dT%H:%M:%S%:z")-fullscreen.png" + date=$(date +"%Y-%m-%dT%H:%M:%S%:z") + out="''${XDG_PICTURES_DIR-$HOME/Pictures}/screenshots/$date-fullscreen.png" mkdir -p "$(dirname "$out")" - ${maim}/bin/maim --hidecursor --format=png --quality=10 --noopengl "$out" + ${lib.getExe flameshot} full --raw | ${moreutils}/bin/sponge "$out" ${libnotify}/bin/notify-send \ "šŸ“· Screenshot captured" "šŸ’¾ Saved to $out" \ + --hint="string:wired-tag:screenshot-$date" \ || true ''; } diff --git a/users/myuser/graphical/i3.nix b/users/myuser/graphical/i3.nix index 762c14b..f96a6b6 100644 --- a/users/myuser/graphical/i3.nix +++ b/users/myuser/graphical/i3.nix @@ -90,7 +90,8 @@ in { "b" = "exec firefox"; # TODO ; exec signal-desktop; exec discord "Shift+s" = "exec --no-startup-id ${getExe pkgs.scripts.screenshot-area}"; "F11" = "exec --no-startup-id ${getExe pkgs.scripts.screenshot-area-scan-qr}"; - "F12" = "exec --no-startup-id ${getExe pkgs.scripts.screenshot-screen}"; + # Exlicitly without --no-startup-id to show the spinner + "F12" = "exec ${getExe pkgs.scripts.screenshot-screen}"; "Print" = "exec --no-startup-id env QT_AUTO_SCREEN_SCALE_FACTOR=0 QT_SCREEN_SCALE_FACTORS='' ${getExe pkgs.flameshot} gui"; "Shift+r" = "reload";