app.dhover×28 error×21all
// Minimal X11 window — the irreducible Xlib sequence that GLFW/SDL/winit wrap on
// Linux: XOpenDisplay -> XCreateSimpleWindow -> XMapWindow -> XNextEvent. All
// types and functions come from the real <X11/Xlib.h> via the ImportC shim
// (`c.c`); nothing is hand-declared. See ../index.md (the X11 OS-API survey).
//
// Headless-safe: if no X server is reachable, XOpenDisplay returns null, we print
// `SKIP:` and exit 0. With a live $DISPLAY it opens a real window, draws on the
// first Expose, and exits (a real app loops until WM_DELETE_WINDOW).
module 
(module) app
app
;
import
(module) c
c
; // ImportC: <X11/Xlib.h>
C preprocess command `cpp` failed for file `/home/runner/work/sparkles/sparkles/docs/research/window-system-integration/os-apis/x11/example/c.c`, exit status 1
import
(package) core
core
.
(package) core.stdc
stdc
.
(module) core.stdc.config

D compatible types that correspond to various basic types in associated C and C++ compilers.

Source

core/stdc/config.d

@copyrightCopyright Sean Kelly 2005 - 2009.@licenseDistributed under the Boost Software License 1.0. (See accompanying file LICENSE)@authorsSean Kelly@standardsISO/IEC 9899:1999 (E)
config
: c_long;
import
(package) core
core
.
(package) core.stdc
stdc
.
(module) core.stdc.stdio

D header file for C99 <stdio.h>

pubs.opengroup.org/onlinepubs/009695399/basedefs/stdio.h.html, stdio.h

Source

core/stdc/stdio.d

@copyrightCopyright Sean Kelly 2005 - 2009.@licenseDistributed under the Boost Software License 1.0. (See accompanying file LICENSE)@authorsSean Kelly, Alex Rønne Petersen@standardsISO/IEC 9899:1999 (E)
stdio
:
(alias) app.printf = int core.stdc.stdio.printf(scope const(char*) format, scope const ...) nothrow @nogc
printf
;
// Xlib exposes these as expression/object-like macros (e.g. `(1L<<15)`), which // ImportC does not reliably import — re-declare the few we use, per the ImportC // guide. (Function macros DefaultScreen/RootWindow/BlackPixel are likewise // avoided in favour of their real function forms XDefaultScreen/XRootWindow/….) enum : c_long {
(enum value) app.ExposureMask = 32768L
ExposureMask
= 1L << 15,
(enum value) app.KeyPressMask = 1L
KeyPressMask
= 1L << 0,
(enum value) app.StructureNotifyMask = 131072L
StructureNotifyMask
= 1L << 17,
} enum {
(enum value) app.Expose = 12
Expose
= 12,
(enum value) app.KeyPress = 2
KeyPress
= 2,
(enum value) app.ClientMessage = 33
ClientMessage
= 33,
} int
int D main()
main
()
{ // 1. Connect to the X server named by $DISPLAY (null = default). Display*
(local variable) _error_ dpy
dpy
= XOpenDisplay(null);
undefined identifier `Display`
undefined identifier `XOpenDisplay`
if (dpy is null) {
int core.stdc.stdio.printf(scope const(char*) format, scope const ...) nothrow @nogc
printf
("SKIP: no X11 display (XOpenDisplay returned null)\n");
return 0; // green on a headless runner } scope (exit) XCloseDisplay(dpy);
undefined identifier `XCloseDisplay`
const
(local variable) const(_error_) screen
screen
= XDefaultScreen(dpy);
undefined identifier `XDefaultScreen`
const
(local variable) const(_error_) root
root
= XRootWindow(dpy, screen);
undefined identifier `XRootWindow`
// 2. Create a top-level window as a child of the root window. Window
(local variable) _error_ win
win
= XCreateSimpleWindow(dpy, root,
undefined identifier `Window`
undefined identifier `XCreateSimpleWindow`
0, 0, 480, 320, // x, y, width, height 1, // border width XBlackPixel(dpy, screen), XWhitePixel(dpy, screen)); XStoreName(dpy, win, "Sparkles · X11 (Xlib)");
undefined identifier `XStoreName`
// 3. Route the window-manager close button to us as a ClientMessage. Atom
(local variable) _error_ wmDelete
wmDelete
= XInternAtom(dpy, "WM_DELETE_WINDOW", False);
undefined identifier `Atom`
undefined identifier `XInternAtom`
XSetWMProtocols(dpy, win, &wmDelete, 1);
undefined identifier `XSetWMProtocols`
// 4. Subscribe to events, then map (show) the window. XSelectInput(dpy, win, ExposureMask | KeyPressMask | StructureNotifyMask);
undefined identifier `XSelectInput`
XMapWindow(dpy, win);
undefined identifier `XMapWindow`
// 5. Event loop. A real app loops until WM_DELETE_WINDOW / a key; here we draw // once on the first Expose and exit so CI never blocks. GC
(local variable) _error_ gc
gc
= XDefaultGC(dpy, screen);
undefined identifier `GC`
undefined identifier `XDefaultGC`
XEvent
(local variable) _error_ ev
ev
;
undefined identifier `XEvent`
while (true) { XNextEvent(dpy, &ev);
undefined identifier `XNextEvent`
if (ev.type ==
(enum value) app.Expose = 12
Expose
)
{ XSetForeground(dpy, gc, XBlackPixel(dpy, screen));
undefined identifier `XSetForeground`
XFillRectangle(dpy, win, gc, 190, 130, 100, 60);
undefined identifier `XFillRectangle`
XFlush(dpy);
undefined identifier `XFlush`
int core.stdc.stdio.printf(scope const(char*) format, scope const ...) nothrow @nogc
printf
("ok: mapped a 480x320 window and drew on Expose\n");
return 0; } if (ev.type ==
(enum value) app.KeyPress = 2
KeyPress
|| ev.type ==
(enum value) app.ClientMessage = 33
ClientMessage
)
return 0; } }