| 1 | import sokol.sapp |
| 2 | |
| 3 | // Names the window for the desktop. On X11 — also what an XWayland session's |
| 4 | // X11 property query sees — launchers, taskbars and the .desktop file's |
| 5 | // StartupWMClass match a window against its WM_CLASS resource pair |
| 6 | // (instance, class). sokol's own title call goes through Xutf8SetWMProperties |
| 7 | // with nil class hints, so the window comes up anonymous and the toolkit |
| 8 | // guesses; this writes the vendetta pair instead. The property is exactly |
| 9 | // what XSetClassHint itself writes — two null-terminated STRING atoms, |
| 10 | // instance then class — against the static atoms XA_WM_CLASS (20) and |
| 11 | // XA_STRING (31), so nothing of the XClassHint plumbing is needed. It must |
| 12 | // run once sokol has its X11 connection, which is registered inside sokol's |
| 13 | // own loop — the first frame is the earliest point vendetta can answer |
| 14 | // that. Only the desktop machines sokol runs through X11 are addressed; |
| 15 | // macOS and Windows have nothing a .desktop-style file matches, and Android |
| 16 | // nothing at all. |
| 17 | $if linux || freebsd || openbsd || netbsd || dragonfly || solaris { |
| 18 | #include <X11/Xlib.h> |
| 19 | |
| 20 | fn set_window_class() { |
| 21 | display := sapp.x11_get_display() |
| 22 | window := sapp.x11_get_window() |
| 23 | if display == unsafe { nil } || u64(window) == 0 { |
| 24 | return |
| 25 | } |
| 26 | // The class atom is one of XSetClassHint's own interned atoms, not |
| 27 | // one of the root's predefined set; the server interns the property |
| 28 | // contents synchronously, so the byte copy's storage only has to |
| 29 | // outlive this call. |
| 30 | name := 'vendetta'.bytes() |
| 31 | mut data := []u8{len: 2 * (name.len + 1)} |
| 32 | atom := C.XInternAtom(display, c'WM_CLASS', 0) |
| 33 | unsafe { |
| 34 | C.memcpy(&data[0], name.data, name.len) |
| 35 | C.memcpy(&data[name.len + 1], name.data, name.len) |
| 36 | // XA_STRING (31), 8-bit format: the property XSetClassHint |
| 37 | // itself writes, instance then class. |
| 38 | C.XChangeProperty(display, u64(window), atom, 31, 8, 0, &data[0], data.len) |
| 39 | } |
| 40 | } |
| 41 | } $else { |
| 42 | fn set_window_class() {} |
| 43 | } |
| 44 | |