- C 93.7%
- Makefile 6.3%
| include | ||
| src | ||
| vendor | ||
| .clang-format | ||
| .gitignore | ||
| compile_flags.txt | ||
| LICENSE | ||
| Makefile | ||
| manifest.toml | ||
| README.md | ||
grabit-qr
a grabit plugin: select a region, read the QR codes in it, copy the text and show it in a notification.
grabit plugin install https://heliopolis.live/creations/grabit-qr.git
grabit qr # pick a region
grabit qr --open # also open the first http(s) link
grabit qr -w # the active window
grabit qr --fullscreen=all # every monitor
grabit qr --delay 3 # wait, then pick
grabit qr photo.jpg # an existing png or jpeg
grabit qr --no-copy --no-notify | xargs -r echo # stdout only
each decoded code goes to stdout on its own line, duplicates dropped, up to 32 per scan. the clipboard gets all of them joined by newlines; the notification shows the first 300 characters.
exits 0 when at least one code is found, 1 when none are or the image can't be read, and 2 on bad arguments. when the capture itself fails, grabit's exit code is passed through: 3 when the selection is cancelled, 4 with no usable wayland session, 2 for a bad capture value like --delay abc.
| option | |
|---|---|
--open |
open the first http(s) link with xdg-open |
--no-copy |
leave the clipboard alone |
--no-notify |
no desktop notification |
-h, --help |
print usage |
-F, --fullscreen[=<n|name|all>], -w, -L, --no-last, --delay <s>, --delay=<s>, --cursor, -e |
passed to grabit's capture |
capture options don't combine with an image path: grabit qr -w photo.jpg exits 2.
runtime: wl-copy (clipboard), notify-send (notifications), xdg-open (--open). each is optional; without it, that step is skipped.
decoding is QR only (no 1D barcodes). light-on-dark codes are retried inverted, and transparent pixels are treated as white.
the cache dir (~/.cache/grabit/plugins/qr/) keeps the last scan as last.png, so it holds whatever was on screen. grabit plugin remove qr leaves it behind; delete it yourself.
using this as a template
this repo is meant to be copied. what each part shows:
| file | what it demonstrates |
|---|---|
manifest.toml |
the minimum for a build-from-source plugin: name, [build], [update], [capture] |
Makefile |
builds with make and a C compiler; every dependency is vendored |
include/grabit-plugin.h |
grabit's helper header, copied from grabit's include/ |
src/stb_image.c |
compiles the stb_image implementation once, with warnings off |
src/main.c capture() |
calling back into grabit with $GRABIT_BIN and custom flags |
src/main.c main() |
stdout for results, stderr for logs, exit codes |
the plugin captures through grabit itself instead of capture.auto = true, for three reasons:
- format:
capture.autosaves in the user'sformat(png, jpeg or webp). asking for--format pngmeans the decoder only has to read png. - history: a scan is not something the user wants in their history. the plugin writes a small overlay config to
$GRABIT_CACHE_DIR/capture.toml(history.enabled = false,preview.enabled = false) and appends it toGRABIT_CONFIG, which grabit applies last. this is how to change any setting for one capture without touching the user's config. - flag values: with
capture.auto, the value of any non-grabit flag counts as a positional and turns auto-capture off. owning the capture avoids that.
for a plugin that should just get the screenshot as argv[1], set capture.auto = true and skip all of that.
the last scan is kept as $GRABIT_CACHE_DIR/last.png (overwritten each run) for debugging a code that won't read.
things to know
[build]plugins are never updated automatically. grabit prints a hint and the user runsgrabit plugin update qr;check_every_hoursonly sets how often that hint appears. use[prebuilt]with a pinnedsha256if you want automatic updates.- installing needs
git, and a[build]plugin also needs whatevercmdruns (makeandcchere) on the user's machine. - grabit strips
--captureand--no-capturebefore running the plugin, even withcapture.auto = false.grabit qr --capturemakes grabit capture with the user's full config and pass the path in, which skips the overlay: the scan lands in history, and a webpformatwon't decode. grabit plugin removeleaves the cache dir in place. if your plugin caches anything sensitive, say so in your readme.grabit qr --pinpins the last stdout line as a file path, which makes no sense for text output. plugins that write an image should print its path last so--pinworks.- any helper you spawn that can outlive you (
wl-copykeeps serving the clipboard in the background) must not inherit your stdout. otherwise$(grabit qr)or--pinwaits until the clipboard changes.copy_to_clipboard()points it at/dev/null.
license
AGPL-3.0-or-later (see LICENSE). a copy of this repo inherits that license; the vendored code below keeps its own.