1
0
Fork
You've already forked dvui-sokol
0
Sokol backend for DVUI.
  • Zig 95.5%
  • Objective-C 2.6%
  • GLSL 1.9%
Mikael Säker 3203367d52 deps: bump sokey — carries the repinned (reachable) sokol
Aligns the whole graph on sokol#8bed105f so consumers get ONE sokol module (two instances gave 'expected app.Event, found app.Event').
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026年07月06日 22:15:26 +02:00
src sokol: route macOS clipboard through NSPasteboard (fix 8 KB truncation) 2026年07月04日 09:46:34 +02:00
.gitignore Initial commit: shared sokol backend for DVUI 2026年05月06日 15:33:36 +02:00
build.zig macOS: install application:openURLs: + openFiles: at +load time 2026年05月15日 11:45:55 +02:00
build.zig.zon deps: bump sokey — carries the repinned (reachable) sokol 2026年07月06日 22:15:26 +02:00
README.md README: document file-open paths + macOS extras 2026年05月15日 11:55:54 +02:00

dvui-sokol

Shared sokol backend for DVUI, used by cue, quote, and wordandkey.

Modules

  • dvui_sokol — the DVUI backend itself (kind = .custom).
  • runtime — small std-shim helpers (clock, getenv, fs, sleep, mutex) for code that does not want to thread std.Io through every call.
  • shader — generated GLSL → backend-specific shader bytecode (compiled by sokol-shdc at build time).

Consuming this package

In your build.zig.zon, declare both this package and dvui (matching the pinned version below — Zig's package manager deduplicates by hash):

.dependencies=.{.dvui_sokol=.{.url="git+https://codeberg.org/sicher/dvui-sokol#<rev>",.hash="...",},.dvui=.{.url="git+https://github.com/david-vanderson/dvui#2459d676a26c11627593aad5e9ad4cbda42e2f1e",.hash="dvui-0.5.0-dev-AQFJmT4I3wAC_MQuAnjx7tZe7iRao6cN7E7vcdOlItYa",},},

In build.zig:

constds_dep=b.dependency("dvui_sokol",.{.target=target,.optimize=optimize});constbackend_mod=ds_dep.module("dvui_sokol");construntime_mod=ds_dep.module("runtime");constdvui_dep=b.dependency("dvui",.{.target=target,.optimize=optimize,.backend=.custom,.libc=true,.@"stb-image"=true,});constdvui_mod=dvui_dep.module("dvui");@import("dvui").linkBackend(dvui_mod,backend_mod);// Use dvui_mod and runtime_mod from your app modules.

In your main.zig:

constdvui=@import("dvui");constsokol=@import("sokol");constdvui_sokol=@import("dvui_sokol");pubconstdvui_app:dvui.App=.{.config=.{.startFn=&startOptions},.frameFn=frame,.initFn=init,.deinitFn=deinit,};pubconstmain=dvui.App.main;

File-open handling (macOS)

The backend wires three file-delivery paths into a single per-frame drain so consumers don't have to think about which event a file arrived on:

  • Window drag-and-drop — sokol's FILES_DROPPED event.
  • Dock-icon drops / "Open With" — macOS's application:openFiles: delegate method (legacy).
  • Terminal open -a App -- file and modern open flows — macOS's application:openURLs: delegate method.

The two delegate methods are installed at dyld static-init phase by a tiny companion src/load_hook.m (a DvuiSokolDelegateGraft class with a +load method). This timing is mandatory: macOS dispatches the launch-time kAEOpenDocuments Apple Event before applicationDidFinishLaunching: runs, so any later injection loses the race and AppKit shows its "cannot open files in the X format" fallback dialog. +load is the earliest hook the Obj-C runtime exposes, and that's how this implementation wins.

In your frame loop, call drainDroppedFiles once per frame:

for(dvui_sokol.drainDroppedFiles())|path|{tryeditor.openFile(path);}

Returned slices live in static buffers — valid until the next event of the same type replaces them, which in practice means valid for the rest of the current frame. Copy if you need to keep them.

CFBundleDocumentTypes in your Info.plist is not required — open -a App is explicit about the target. (It is still useful if you want Finder's "Open With..." menu to list your app, but it's orthogonal to whether files actually open.)

Other macOS extras

  • Press-and-hold suppression — macOS's accent-picker popup is disabled at startup so holding a printable key delivers repeated keyDown events (what text editors want). Same flag Terminal.app, VS Code, and Sublime set.
  • Glass / blur compositing — opt-in via the -Dglass=true build option. Off by default; consumers that don't render frosted popups pay zero overhead.

License

MIT