Sokol backend for DVUI.
  • Zig 82.6%
  • Objective-C 15.7%
  • GLSL 1%
  • Shell 0.7%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Mikael Säker b2ddf9af8f platform: fullScreenTitlebar says whether the system draws a shadow under the bar
With a 15.5 SDK stamp the full-screen title bar's window is taller than
the bar (44pt around 28pt) and the system draws a shadow in the room
below it; a binary with a newer stamp gets a 32pt window and none.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 13:58:53 +02:00
scripts Migrate to Zig 0.17 and sokol's new buffer-update API 2026-10-06 15:49:20 +02:00
src platform: fullScreenTitlebar says whether the system draws a shadow under the bar 2026-10-21 13:58:53 +02:00
.gitignore scripts: setup-tools, the one every repo shares 2026-09-22 21:06:15 +02:00
build.zig glass: widen the overlay vertex count before the multiply 2026-10-06 21:39:49 +02:00
build.zig.zon deps: track sokol 261ddd4 and sokey f709b87 2026-10-07 09:23:47 +02:00
LICENSE Add MIT license 2026-07-25 12:00:17 +02:00
README.md docs: repoint links to git.urverk.org 2026-07-25 11:41:27 +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://git.urverk.org/urverk/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:

const ds_dep = b.dependency("dvui_sokol", .{ .target = target, .optimize = optimize });
const backend_mod = ds_dep.module("dvui_sokol");
const runtime_mod = ds_dep.module("runtime");

const dvui_dep = b.dependency("dvui", .{
    .target = target,
    .optimize = optimize,
    .backend = .custom,
    .libc = true,
    .@"stb-image" = true,
});
const dvui_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:

const dvui = @import("dvui");
const sokol = @import("sokol");
const dvui_sokol = @import("dvui_sokol");

pub const dvui_app: dvui.App = .{
    .config = .{ .startFn = &startOptions },
    .frameFn = frame,
    .initFn = init,
    .deinitFn = deinit,
};
pub const main = 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| {
    try editor.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