simple plugin example for grabit
  • C 93.7%
  • Makefile 6.3%
Find a file Use this template
2026-12-02 08:14:59 -05:00
include add grabit plugin header 2026-11-28 16:35:36 -05:00
src scan a region for qr codes 2026-12-01 20:45:28 -05:00
vendor vendor stb_image 2.34 2026-11-28 14:50:40 -05:00
.clang-format license, gitignore and format config 2026-11-25 10:13:00 -05:00
.gitignore license, gitignore and format config 2026-11-25 10:13:00 -05:00
compile_flags.txt license, gitignore and format config 2026-11-25 10:13:00 -05:00
LICENSE license, gitignore and format config 2026-11-25 10:13:00 -05:00
Makefile makefile and plugin manifest 2026-11-29 10:41:00 -05:00
manifest.toml last 2 tings? 2026-12-02 08:14:59 -05:00
README.md last 2 tings? 2026-12-02 08:14:59 -05:00

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.auto saves in the user's format (png, jpeg or webp). asking for --format png means 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 to GRABIT_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 runs grabit plugin update qr; check_every_hours only sets how often that hint appears. use [prebuilt] with a pinned sha256 if you want automatic updates.
  • installing needs git, and a [build] plugin also needs whatever cmd runs (make and cc here) on the user's machine.
  • grabit strips --capture and --no-capture before running the plugin, even with capture.auto = false. grabit qr --capture makes grabit capture with the user's full config and pass the path in, which skips the overlay: the scan lands in history, and a webp format won't decode.
  • grabit plugin remove leaves the cache dir in place. if your plugin caches anything sensitive, say so in your readme.
  • grabit qr --pin pins 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 --pin works.
  • any helper you spawn that can outlive you (wl-copy keeps serving the clipboard in the background) must not inherit your stdout. otherwise $(grabit qr) or --pin waits 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.

vendored code

  • vendor/quirc: quirc v1.2, ISC (see vendor/quirc/LICENSE)
  • vendor/stb/stb_image.h: stb_image v2.34, public domain / MIT