From 59511ca6b236c69a5dcc3242efdcb78549a7d3c1 Mon Sep 17 00:00:00 2001 From: diviocity Date: Sun, 1 Nov 2026 13:30:36 +0100 Subject: [PATCH] fix untracked src files --- src/window_class.v | 43 +++++++++++++++++++++++++++++++++++++++++++ src/window_title.v | 15 +++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 src/window_class.v create mode 100644 src/window_title.v diff --git a/src/window_class.v b/src/window_class.v new file mode 100644 index 0000000..a92b3cc --- /dev/null +++ b/src/window_class.v @@ -0,0 +1,43 @@ +import sokol.sapp + +// Names the window for the desktop. On X11 — also what an XWayland session's +// X11 property query sees — launchers, taskbars and the .desktop file's +// StartupWMClass match a window against its WM_CLASS resource pair +// (instance, class). sokol's own title call goes through Xutf8SetWMProperties +// with nil class hints, so the window comes up anonymous and the toolkit +// guesses; this writes the vendetta pair instead. The property is exactly +// what XSetClassHint itself writes — two null-terminated STRING atoms, +// instance then class — against the static atoms XA_WM_CLASS (20) and +// XA_STRING (31), so nothing of the XClassHint plumbing is needed. It must +// run once sokol has its X11 connection, which is registered inside sokol's +// own loop — the first frame is the earliest point vendetta can answer +// that. Only the desktop machines sokol runs through X11 are addressed; +// macOS and Windows have nothing a .desktop-style file matches, and Android +// nothing at all. +$if linux || freebsd || openbsd || netbsd || dragonfly || solaris { + #include + + fn set_window_class() { + display := sapp.x11_get_display() + window := sapp.x11_get_window() + if display == unsafe { nil } || u64(window) == 0 { + return + } + // The class atom is one of XSetClassHint's own interned atoms, not + // one of the root's predefined set; the server interns the property + // contents synchronously, so the byte copy's storage only has to + // outlive this call. + name := 'vendetta'.bytes() + mut data := []u8{len: 2 * (name.len + 1)} + atom := C.XInternAtom(display, c'WM_CLASS', 0) + unsafe { + C.memcpy(&data[0], name.data, name.len) + C.memcpy(&data[name.len + 1], name.data, name.len) + // XA_STRING (31), 8-bit format: the property XSetClassHint + // itself writes, instance then class. + C.XChangeProperty(display, u64(window), atom, 31, 8, 0, &data[0], data.len) + } + } +} $else { + fn set_window_class() {} +} diff --git a/src/window_title.v b/src/window_title.v new file mode 100644 index 0000000..5efa492 --- /dev/null +++ b/src/window_title.v @@ -0,0 +1,15 @@ +// The window-title plumbing, kept apart because the import rule pins it to a +// file head: apply_window_title pushes a title onto the OS window, and every +// vendetta desktop build renders through ui2's custom GL renderer (the macOS +// compile_error guard in main.v leans on it too), whose window is sokol's, so +// the title goes through gg's sapp wrapper; android has no title bar and +// ignores the call harmlessly. +import gg + +$if android || linux || ((macos || windows) && ui2_custom_rendering ?) { + fn apply_window_title(title string) { + gg.set_window_title(title) + } +} $else { + fn apply_window_title(_ string) {} +} -- 2.56.1