Commit 61815ac

HPCesia <me@hpcesia.com>
2026-10-24 14:34:34
script-tools: add qrscanner
1 parent 20c549a
Changed files (2)
modules
desktop
app
script-tools
users
hpcesia
modules/desktop/app/script-tools/qrscanner.nix
@@ -0,0 +1,69 @@
+{
+  den.aspects.desktop.app.script-tools.qrscanner = {
+    hjem = {pkgs, ...}: let
+      ix-qrscanner-script = pkgs.writeShellApplication {
+        name = "ix-qrscanner";
+        runtimeInputs = [
+          pkgs.coreutils
+          pkgs.grim
+          pkgs.libnotify
+          pkgs.slurp
+          pkgs.zbar
+          pkgs.wl-clipboard-rs
+        ];
+        text = ''
+          geom="$(slurp -d)" || exit 0
+
+          img="$(mktemp --suffix=.png)"
+          trap 'rm -f "$img"' EXIT
+
+          grim -g "$geom" "$img" || {
+            notify-send -u critical "QR Scanner" "Screenshot failed (grim)"
+            exit 1
+          }
+
+          result="$(zbarimg -q --raw -1 "$img" 2>/dev/null)" || {
+            notify-send -u critical "QR Scanner" "QR Code recognition failed (zbar)"
+            exit 1
+          }
+
+          if [ -z "$(printf '%s' "$result" | tr -d '[:space:]')" ]; then
+            notify-send "QR Scanner" "No QR code recognized in the selection"
+            exit 0
+          fi
+
+          printf '%s' "$result" | wl-copy
+          printf '%s\n' "$result"
+        '';
+
+        meta.mainProgram = "ix-qrscanner";
+      };
+
+      ix-qrscanner-desktop-entry = pkgs.makeDesktopItem {
+        name = "ix-qrscanner";
+        exec = "ix-qrscanner";
+        icon = "scanner";
+        desktopName = "IX Tools - QR Scanner";
+        comment = "Select a screen region containing a QR code and scan it";
+        categories = ["Utility" "Graphics"];
+        keywords = ["qr" "barcode" "scan"];
+        terminal = false;
+        startupNotify = false;
+      };
+
+      ix-qrscanner = pkgs.stdenv.mkDerivation rec {
+        name = "ix-qrscanner";
+        buildCommand = ''
+          mkdir -p $out/bin
+          install -Dm755 ${ix-qrscanner-script}/bin/${name} $out/bin/${name}
+          mkdir -p $out/share/applications
+          install -Dm644 ${ix-qrscanner-desktop-entry}/share/applications/${name}.desktop \
+            $out/share/applications/${name}.desktop
+        '';
+        dontBuild = true;
+      };
+    in {
+      packages = [ix-qrscanner];
+    };
+  };
+}
modules/users/hpcesia/desktop.nix
@@ -30,6 +30,7 @@
         desktop.app.obs-studio
         desktop.app.picard
         desktop.app.script-tools.ocr
+        desktop.app.script-tools.qrscanner
         desktop.app.term.foot
         desktop.app.thunderbird
         desktop.ime.fcitx5