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() {} }