app.dhover×286 error×44all
// X11 F09 demo — output enumeration & hotplug (../../../features/f09-outputs.md).
// Built on the scaffold (../scaffold/app.d): same ImportC binding style, same
// poll(2)-driven readiness loop, same instrument.d event log. Rendering is a
// plain background-pixel window — pixels are irrelevant to this row.
//
// The deliverable is the DISTINCTION between RandR's two enumeration APIs:
//
//   * `XRRGetMonitors` (RandR >= 1.5) — the "modern" per-monitor view: logical
//     rectangles a desktop is tiled into (name atom, geometry, primary flag,
//     physical mm). No modes, no refresh — that lives a level below.
//   * `XRRGetScreenResources` + `XRRGetOutputInfo`/`XRRGetCrtcInfo` (1.2) —
//     the wiring-level object model: outputs (connectors) -> crtcs (scanout
//     engines) -> modes (timing blocks). Refresh is not a stored field; it is
//     COMPUTED from the mode timings: refresh = dotClock / (hTotal * vTotal),
//     and the demo logs that math term by term.
//
// Window<->output occupancy is DERIVED (X11 has no equivalent of Wayland's
// `wl_surface.enter/leave`): on every ConfigureNotify the demo translates its
// origin to root coordinates (XTranslateCoordinates) and intersects its rect
// with each monitor rect, emitting `surface_output enter/leave` on changes.
// Under WSI_AUTO_EXIT it proves the derivation with an XMoveWindow storm that
// slides the window half off, fully off, and back onto the only monitor.
//
// Hotplug: XRRSelectInput(RRScreenChangeNotifyMask | RRCrtcChangeNotifyMask |
// RROutputChangeNotifyMask | RROutputPropertyNotifyMask) on the root; every
// RRScreenChangeNotify / RRNotify is logged and answered by a re-enumeration
// that diffs the output set (`output_added`/`output_removed`). Xvfb's output
// set is static, so the run.sh driver exercises what IS reachable (xrandr
// --dpi, output property writes / non-desktop soft-unplug, and real pixel-size
// switches on a nested Xephyr); a true connector unplug is a Tier C item —
// see ../../f09-outputs.md.
//
// WSI_AUTO_EXIT=1 bounds the run (WSI_DURATION_MS, default 6 s). Headless-
// safe: no X server -> prints `SKIP:` and exits 0.
module 
(module) app
app
;
import
(module) c
c
; // ImportC: Xlib + Xrandr + poll
C preprocess command `cpp` failed for file `/home/runner/work/sparkles/sparkles/docs/research/window-system-integration/os-apis/x11/examples/f09-outputs/c.c`, exit status 1
import
(module) instrument
instrument
;
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, c_ulong;
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
,
(alias) app.snprintf = int core.stdc.stdio.snprintf(scope char* s, ulong n, scope const(char*) format, scope const ...) nothrow @nogc
snprintf
;
import
(package) core
core
.
(package) core.stdc
stdc
.
(module) core.stdc.stdlib

D header file for C99.

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

Source

core/stdc/stdlib.d

@copyrightCopyright Sean Kelly 2005 - 2014.@licenseDistributed under the Boost Software License 1.0. (See accompanying file LICENSE)@authorsSean Kelly@standardsISO/IEC 9899:1999 (E)
stdlib
:
(alias) app.atoi = int core.stdc.stdlib.atoi(scope const(char*) nptr) nothrow @nogc
atoi
,
(alias) app.getenv = char* core.stdc.stdlib.getenv(scope const(char*) name) nothrow @nogc
getenv
;
// --------------------------------------------------------------------------- // Constants Xlib/Xrandr expose as macros that ImportC cannot import; // re-declared per the scaffold gotcha (../../scaffold.md). enum : c_long {
(enum value) app.KeyPressMask = 1L
KeyPressMask
= 1L << 0,
(enum value) app.ExposureMask = 32768L
ExposureMask
= 1L << 15,
(enum value) app.StructureNotifyMask = 131072L
StructureNotifyMask
= 1L << 17,
} enum // XEvent.type discriminators {
(enum value) app.KeyPress = 2
KeyPress
= 2,
(enum value) app.Expose = 12
Expose
= 12,
(enum value) app.MapNotify = 19
MapNotify
= 19,
(enum value) app.ConfigureNotify = 22
ConfigureNotify
= 22,
(enum value) app.ClientMessage = 33
ClientMessage
= 33,
} enum
(constant) int app.False = 0
False
= 0;
enum
(constant) int app.True = 1
True
= 1;
enum
(constant) int app.POLLIN = 1
POLLIN
= 0x001;
enum // Xrandr.h: event codes (offsets from the extension event base) ... {
(enum value) app.RRScreenChangeNotify = 0
RRScreenChangeNotify
= 0,
(enum value) app.RRNotify = 1
RRNotify
= 1,
(enum value) app.RRNotify_CrtcChange = 0
RRNotify_CrtcChange
= 0, // ... XRRNotifyEvent.subtype values ...
(enum value) app.RRNotify_OutputChange = 1
RRNotify_OutputChange
= 1,
(enum value) app.RRNotify_OutputProperty = 2
RRNotify_OutputProperty
= 2,
} enum : c_long // ... XRRSelectInput masks ... {
(enum value) app.RRScreenChangeNotifyMask = 1L
RRScreenChangeNotifyMask
= 1L << 0,
(enum value) app.RRCrtcChangeNotifyMask = 2L
RRCrtcChangeNotifyMask
= 1L << 1,
(enum value) app.RROutputChangeNotifyMask = 4L
RROutputChangeNotifyMask
= 1L << 2,
(enum value) app.RROutputPropertyNotifyMask = 8L
RROutputPropertyNotifyMask
= 1L << 3,
} enum // ... and Connection states. {
(enum value) app.RR_Connected = 0
RR_Connected
= 0,
(enum value) app.RR_Disconnected = 1
RR_Disconnected
= 1,
(enum value) app.RR_UnknownConnection = 2
RR_UnknownConnection
= 2,
} // --------------------------------------------------------------------------- // Modern view: XRRGetMonitors. Monitors are kept in a fixed table so the // occupancy derivation can intersect against them on every ConfigureNotify. struct
(struct) app.MonitorRect
MonitorRect
{ char[64]
(field) char[64] app.MonitorRect.name
name
;
int
(field) int app.MonitorRect.x
x
,
(field) int app.MonitorRect.y
y
,
(field) int app.MonitorRect.w
w
,
(field) int app.MonitorRect.h
h
;
int
(field) int app.MonitorRect.primary
primary
;
} __gshared
(struct) app.MonitorRect
MonitorRect
[16]
(__gshared global) app.MonitorRect[16] app.g_monitors
g_monitors
;
__gshared int
(__gshared global) int app.g_nMonitors
g_nMonitors
= 0;
/// Enumerate via XRRGetMonitors (RandR >= 1.5): the per-monitor logical view. /// Note what is and is NOT here: name/geometry/primary/physical-mm — but no /// mode and no refresh; those belong to the object model below. void
app.enumerateMonitors

Enumerate via XRRGetMonitors (RandR >= 1.5): the per-monitor logical view. Note what is and is NOT here: name/geometry/primary/physical-mm — but no mode and no refresh; those belong to the object model below.

enumerateMonitors
(Display*
(parameter) Display* dpy
dpy
, Window
(parameter) Window root
root
) @nogc nothrow
undefined identifier `Display`
undefined identifier `Window`
{ int
_error_ n
n
= 0;
XRRMonitorInfo*
_error_ mons
mons
= XRRGetMonitors(dpy, root, True, &n);
g_nMonitors = 0; if (mons is null) { emit("monitors api=XRRGetMonitors result=null"); return; } foreach (
(parameter) i
i
; 0 .. n)
{ auto
_error_ m
m
= &mons[i];
char*
_error_ name
name
= XGetAtomName(dpy, m.
m.name
name
);
emitf("output", "api=XRRGetMonitors id=%s geom=%dx%d+%d+%d mm=%dx%d " ~ "primary=%d automatic=%d noutput=%d refresh=NOT_EXPOSED_HERE", name, m.
m.width
width
, m.
m.height
height
, m.
m.x
x
, m.
m.y
y
, m.mwidth, m.mheight,
cast(int) m.
m.primary
primary
, cast(int) m.automatic, m.noutput);
if (g_nMonitors < g_monitors.
g_monitors.length
length
)
{ auto
_error_ slot
slot
= &g_monitors[g_nMonitors++];
snprintf(slot.
slot.name
name
.ptr, slot.
slot.name
name
.
slot.name.length
length
, "%s", name);
slot.
slot.x
x
= m.
m.x
x
;
slot.
slot.y
y
= m.
m.y
y
;
slot.
slot.w
w
= m.
m.width
width
;
slot.
slot.h
h
= m.
m.height
height
;
slot.
slot.primary
primary
= cast(int) m.
m.primary
primary
;
} XFree(name); } XRRFreeMonitors(mons); } /// Fallback monitor table when the server has no RandR 1.5 (e.g. Xephyr, /// RandR 1.1): treat the whole core screen as one monitor rect, so the /// occupancy derivation still works. The log says which source was used. void
app.coreScreenAsMonitor

Fallback monitor table when the server has no RandR 1.5 (e.g. Xephyr, RandR 1.1): treat the whole core screen as one monitor rect, so the occupancy derivation still works. The log says which source was used.

coreScreenAsMonitor
(Display*
(parameter) Display* dpy
dpy
, int
(parameter) int screen
screen
) @nogc nothrow
undefined identifier `Display`
{ g_nMonitors = 1; auto
_error_ slot
slot
= &g_monitors[0];
snprintf(slot.
slot.name
name
.ptr, slot.
slot.name
name
.
slot.name.length
length
, "core-screen");
slot.
slot.x
x
= 0;
slot.
slot.y
y
= 0;
slot.
slot.w
w
= XDisplayWidth(dpy, screen);
slot.
slot.h
h
= XDisplayHeight(dpy, screen);
slot.
slot.primary
primary
= 1;
emitf("output", "api=core_screen_fallback id=core-screen geom=%dx%d+0+0", slot.
slot.w
w
, slot.
slot.h
h
);
} // --------------------------------------------------------------------------- // Wiring-level view: screen resources -> outputs -> crtcs -> modes. // The hotplug diff state is the OUTPUT set (connector list + connection). struct
(struct) app.OutputState
OutputState
{ c_ulong
(field) ulong app.OutputState.xid
xid
; // RROutput
int
(field) int app.OutputState.connected
connected
;
char[64]
(field) char[64] app.OutputState.name
name
;
} __gshared
(struct) app.OutputState
OutputState
[32]
(__gshared global) app.OutputState[32] app.g_outputs
g_outputs
;
__gshared int
(__gshared global) int app.g_nOutputs
g_nOutputs
= 0;
/// refresh = dotClock / (hTotal * vTotal) — the field RandR does NOT store. double
app.modeRefresh

refresh = dotClock / (hTotal * vTotal) — the field RandR does NOT store.

modeRefresh
(const(XRRModeInfo)*
(parameter) const(XRRModeInfo)* m
m
) @nogc nothrow
undefined identifier `XRRModeInfo`
{ if (m is null || m.hTotal == 0 || m.vTotal == 0) return 0; return cast(double) m.dotClock / (cast(double) m.hTotal * m.vTotal); } /// Enumerate via the RandR 1.2 object model and rebuild the output table. /// `diff=true` compares against the previous table and emits /// `output_added` / `output_removed` / `output_connection` events. void
app.enumerateResources

Enumerate via the RandR 1.2 object model and rebuild the output table. ``diff=true compares against the previous table and emits output_added / output_removed / output_connection events.

enumerateResources
(Display*
(parameter) Display* dpy
dpy
, Window
(parameter) Window root
root
, bool diff) @nogc nothrow
undefined identifier `Display`
undefined identifier `Window`
{ XRRScreenResources*
_error_ res
res
= XRRGetScreenResources(dpy, root);
if (res is null) { emit("resources api=XRRGetScreenResources result=null"); return; } emitf("resources", "api=XRRGetScreenResources noutput=%d ncrtc=%d nmode=%d", res.noutput, res.ncrtc, res.nmode);
(unresolved type) OutputState
OutputState
[32]
_error_ prev
prev
= g_outputs;
const
_error_ nPrev
nPrev
= g_nOutputs;
g_nOutputs = 0; foreach (
(parameter) i
i
; 0 .. res.noutput)
{ XRROutputInfo*
_error_ oi
oi
= XRRGetOutputInfo(dpy, res, res.outputs[i]);
if (oi is null) continue; if (oi.crtc != 0) { XRRCrtcInfo*
_error_ ci
ci
= XRRGetCrtcInfo(dpy, res, oi.crtc);
// Find the XRRModeInfo the crtc's mode XID names, for the timings. const(XRRModeInfo)*
_error_ mi
mi
= null;
if (ci !is null) foreach (
(parameter) k
k
; 0 .. res.nmode)
if (res.modes[k].id == ci.mode) mi = &res.modes[k]; if (ci !is null && mi !is null) emitf("output", "api=resources id=%s output=0x%lx crtc=0x%lx " ~ "geom=%ux%u+%d+%d mm=%lux%lu mode=%s " ~ "refresh=dotClock/(hTotal*vTotal)=%lu/(%u*%u)=%.2fHz", oi.
oi.name
name
, cast(c_ulong) res.outputs[i], cast(c_ulong) oi.crtc,
ci.
ci.width
width
, ci.
ci.height
height
, ci.
ci.x
x
, ci.
ci.y
y
, oi.mm_width, oi.mm_height,
mi.
mi.name
name
, cast(c_ulong) mi.dotClock, mi.hTotal, mi.vTotal,
modeRefresh(mi)); else emitf("output", "api=resources id=%s output=0x%lx crtc=0x%lx mode=unresolved", oi.
oi.name
name
, cast(c_ulong) res.outputs[i], cast(c_ulong) oi.crtc);
if (ci !is null) XRRFreeCrtcInfo(ci); } else emitf("output", "api=resources id=%s output=0x%lx crtc=none connection=%d " ~ "(connected-but-off or disconnected connector)", oi.
oi.name
name
, cast(c_ulong) res.outputs[i], cast(int) oi.connection);
if (g_nOutputs < g_outputs.
g_outputs.length
length
)
{ auto
_error_ slot
slot
= &g_outputs[g_nOutputs++];
slot.
slot.xid
xid
= cast(c_ulong) res.outputs[i];
slot.
slot.connected
connected
= oi.connection == RR_Connected;
snprintf(slot.
slot.name
name
.ptr, slot.
slot.name
name
.
slot.name.length
length
, "%s", oi.
oi.name
name
);
} XRRFreeOutputInfo(oi); } XRRFreeScreenResources(res); if (!diff) return; foreach (
(parameter) i
i
; 0 .. g_nOutputs) // added / reconnected
{ bool
_error_ found
found
= false;
foreach (
(parameter) j
j
; 0 .. nPrev)
if (prev[j].
prev[j].xid
xid
== g_outputs[i].
g_outputs[i].xid
xid
)
{ found = true; if (prev[j].
prev[j].connected
connected
!= g_outputs[i].
g_outputs[i].connected
connected
)
emitf("output_connection", "id=%s connected=%d", g_outputs[i].
g_outputs[i].name
name
.ptr, g_outputs[i].
g_outputs[i].connected
connected
);
} if (!found) emitf("output_added", "id=%s output=0x%lx", g_outputs[i].
g_outputs[i].name
name
.ptr, g_outputs[i].
g_outputs[i].xid
xid
);
} foreach (
(parameter) j
j
; 0 .. nPrev) // removed
{ bool
_error_ found
found
= false;
foreach (
(parameter) i
i
; 0 .. g_nOutputs)
if (g_outputs[i].
g_outputs[i].xid
xid
== prev[j].
prev[j].xid
xid
)
found = true; if (!found) emitf("output_removed", "id=%s output=0x%lx", prev[j].
prev[j].name
name
.ptr, prev[j].
prev[j].xid
xid
);
} } // --------------------------------------------------------------------------- // Occupancy: which monitor rect(s) does the window's root-space rect overlap? // X11 never tells a window this — it is derived geometry, recomputed on every // ConfigureNotify and after every monitor-layout change. (Wayland instead // delivers `wl_surface.enter/leave` to the surface directly.) __gshared uint
(__gshared global) uint app.g_occupied
g_occupied
= 0; // bitmask over g_monitors
void
app.computeOccupancy
computeOccupancy
(Display*
(parameter) Display* dpy
dpy
, Window
(parameter) Window win
win
, Window
(parameter) Window root
root
, int
(parameter) int w
w
, int
(parameter) int h
h
) @nogc nothrow
undefined identifier `Display`
undefined identifier `Window`
undefined identifier `Window`
{ // ConfigureNotify's x/y are relative to the parent; translate to root // coordinates so the rect lives in the same space as the monitor rects. int
_error_ rx
rx
,
_error_ ry
ry
;
Window
_error_ child
child
;
XTranslateCoordinates(dpy, win, root, 0, 0, &rx, &ry, &child); uint
_error_ now
now
= 0;
foreach (
(parameter) i
i
; 0 .. g_nMonitors)
{ const
_error_ m
m
= &g_monitors[i];
const
_error_ ix
ix
= (rx + w < m.
m.x
x
+ m.
m.w
w
? rx + w : m.
m.x
x
+ m.
m.w
w
) - (rx > m.
m.x
x
? rx : m.
m.x
x
);
const
_error_ iy
iy
= (ry + h < m.
m.y
y
+ m.
m.h
h
? ry + h : m.
m.y
y
+ m.
m.h
h
) - (ry > m.
m.y
y
? ry : m.
m.y
y
);
if (ix > 0 && iy > 0) { now |= 1u << i; if (!(g_occupied & (1u << i))) emitf("surface_output", "enter id=%s overlap=%dx%d of=%dx%d " ~ "derived=window_rect(%d,%d,%dx%d)_vs_monitor_rect", m.
m.name
name
.ptr, ix, iy, w, h, rx, ry, w, h);
} } foreach (
(parameter) i
i
; 0 .. g_nMonitors)
if ((g_occupied & (1u << i)) && !(now & (1u << i))) emitf("surface_output", "leave id=%s", g_monitors[i].
g_monitors[i].name
name
.ptr);
if (now == 0 && g_occupied != 0) emitf("surface_output", "none window=(%d,%d,%dx%d) outside all monitors " ~ "(window keeps running; nothing tells it)", rx, ry, w, h); g_occupied = now; } // --------------------------------------------------------------------------- int
int D main()
main
()
{
void instrument.initInstrument(const(char)* demoName) nothrow @nogc

Names the demo, starts the monotonic clock, and emits init_start. Call this first, before any platform API call.

initInstrument
("f09_x11");
const
(local variable) const(char*) envAuto
envAuto
=
char* core.stdc.stdlib.getenv(scope const(char*) name) nothrow @nogc
getenv
("WSI_AUTO_EXIT");
const
(local variable) const(bool) autoExit
autoExit
=
(local variable) const(char*) envAuto
envAuto
!is null &&
(local variable) const(char*) envAuto
envAuto
[0] == '1';
const
(local variable) const(char*) envDur
envDur
=
char* core.stdc.stdlib.getenv(scope const(char*) name) nothrow @nogc
getenv
("WSI_DURATION_MS");
const
(local variable) const(int) durationMs
durationMs
=
(local variable) const(char*) envDur
envDur
!is null ?
int core.stdc.stdlib.atoi(scope const(char*) nptr) nothrow @nogc
atoi
(
(local variable) const(char*) envDur
envDur
) : 6_000;
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; }
void instrument.emitf(scope const(char)* kind, scope const(char)* fmt, ...) nothrow @nogc

Emit an event with a printf-formatted key=value ... payload.

emitf
("step", "name=XOpenDisplay fd=%d", XConnectionNumber(dpy));
undefined identifier `XConnectionNumber`
const
(local variable) const(_error_) screen
screen
= XDefaultScreen(dpy);
undefined identifier `XDefaultScreen`
Window
(local variable) _error_ root
root
= XRootWindow(dpy, screen);
undefined identifier `Window`
undefined identifier `XRootWindow`
// -- RandR availability gates which of the two APIs exist ---------------- int
(local variable) int rrEventBase
rrEventBase
= -1,
(local variable) int rrErrorBase
rrErrorBase
= -1,
(local variable) int rrMajor
rrMajor
= 0,
(local variable) int rrMinor
rrMinor
= 0;
const
(local variable) const(_error_) haveRandr
haveRandr
= XRRQueryExtension(dpy, &rrEventBase, &rrErrorBase) != 0;
undefined identifier `XRRQueryExtension`
if (haveRandr) XRRQueryVersion(dpy, &rrMajor, &rrMinor);
undefined identifier `XRRQueryVersion`
void instrument.emitf(scope const(char)* kind, scope const(char)* fmt, ...) nothrow @nogc

Emit an event with a printf-formatted key=value ... payload.

emitf
("step", "name=XRRQueryExtension available=%d version=%d.%d event_base=%d",
cast(int) haveRandr,
(local variable) int rrMajor
rrMajor
,
(local variable) int rrMinor
rrMinor
,
(local variable) int rrEventBase
rrEventBase
);
const
(local variable) const(_error_) haveResources
haveResources
= haveRandr && (
(local variable) int rrMajor
rrMajor
> 1 ||
(local variable) int rrMinor
rrMinor
>= 2);
const
(local variable) const(_error_) haveMonitors
haveMonitors
= haveRandr && (
(local variable) int rrMajor
rrMajor
> 1 ||
(local variable) int rrMinor
rrMinor
>= 5);
// -- Enumeration, both ways (no window needed — only the connection) ----- if (haveMonitors) enumerateMonitors(dpy, root); else coreScreenAsMonitor(dpy, screen); if (haveResources) enumerateResources(dpy, root, false); else
void instrument.emitf(scope const(char)* kind, scope const(char)* fmt, ...) nothrow @nogc

Emit an event with a printf-formatted key=value ... payload.

emitf
("resources", "api=XRRGetScreenResources unavailable (server randr %d.%d < 1.2)",
(local variable) int rrMajor
rrMajor
,
(local variable) int rrMinor
rrMinor
);
// -- Subscribe to change events; only 1.0's screen-change bit is safe on // an old server, the 1.2+ bits would be a BadValue there. ------------- if (haveRandr) { c_long
(local variable) long mask
mask
=
(enum value) app.RRScreenChangeNotifyMask = 1L
RRScreenChangeNotifyMask
;
if (haveResources)
(local variable) long mask
mask
|=
(enum value) app.RRCrtcChangeNotifyMask = 2L
RRCrtcChangeNotifyMask
|
(enum value) app.RROutputChangeNotifyMask = 4L
RROutputChangeNotifyMask
|
(enum value) app.RROutputPropertyNotifyMask = 8L
RROutputPropertyNotifyMask
;
XRRSelectInput(dpy, root, cast(int) mask);
undefined identifier `XRRSelectInput`
void instrument.emitf(scope const(char)* kind, scope const(char)* fmt, ...) nothrow @nogc

Emit an event with a printf-formatted key=value ... payload.

emitf
("step", "name=XRRSelectInput mask=0x%lx",
(local variable) long mask
mask
);
} // -- Window (background-pixel rendering; pixels are not this row's job) -- int
(local variable) int width
width
= 320,
(local variable) int height
height
= 240;
Window
(local variable) _error_ win
win
= XCreateSimpleWindow(dpy, root, 40, 40, width, height, 1,
undefined identifier `Window`
undefined identifier `XCreateSimpleWindow`
XBlackPixel(dpy, screen), XWhitePixel(dpy, screen)); XStoreName(dpy, win, "Sparkles · X11 F09 outputs");
undefined identifier `XStoreName`
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`
XSelectInput(dpy, win, ExposureMask | KeyPressMask | StructureNotifyMask);
undefined identifier `XSelectInput`
XMapWindow(dpy, win);
undefined identifier `XMapWindow`
void instrument.emitf(scope const(char)* kind, scope const(char)* fmt, ...) nothrow @nogc

Emit an event with a printf-formatted key=value ... payload.

emitf
("window_created", "xid=0x%lx size=%dx%d pos=40,40", win,
(local variable) int width
width
,
(local variable) int height
height
);
const
(local variable) const(_error_) fd
fd
= XConnectionNumber(dpy);
undefined identifier `XConnectionNumber`
bool
(local variable) bool running
running
= true;
int
(local variable) int rrScreenChanges
rrScreenChanges
= 0,
(local variable) int rrNotifies
rrNotifies
= 0,
(local variable) int moveStep
moveStep
= 0;
// The auto-exit move storm: half off the monitor, fully off, back on. static immutable int[2][3]
(immutable global) immutable(int[2][3]) app.main.moves
moves
= [[-160, 40], [-1000, 40], [40, 40]];
while (
(local variable) bool running
running
)
{ while (XPending(dpy) > 0)
undefined identifier `XPending`
{ XEvent
(local variable) _error_ ev
ev
;
undefined identifier `XEvent`
XNextEvent(dpy, &ev);
undefined identifier `XNextEvent`
if (haveRandr && ev.type ==
(local variable) int rrEventBase
rrEventBase
+
(enum value) app.RRScreenChangeNotify = 0
RRScreenChangeNotify
)
{ ++
(local variable) int rrScreenChanges
rrScreenChanges
;
auto
(local variable) _error_ rr
rr
= cast(XRRScreenChangeNotifyEvent*)&ev;
undefined identifier `XRRScreenChangeNotifyEvent`
void instrument.emitf(scope const(char)* kind, scope const(char)* fmt, ...) nothrow @nogc

Emit an event with a printf-formatted key=value ... payload.

emitf
("randr_screen_change", "px=%dx%d mm=%dx%d size_index=%d rotation=%d",
rr.
(field) _error_ rr.width
width
, rr.
(field) _error_ rr.height
height
, rr.mwidth, rr.mheight,
cast(int) rr.size_index, cast(int) rr.rotation); XRRUpdateConfiguration(&ev); // refresh Xlib's cached screen size
undefined identifier `XRRUpdateConfiguration`
if (haveMonitors) enumerateMonitors(dpy, root); else coreScreenAsMonitor(dpy, screen); if (haveResources) enumerateResources(dpy, root, true); computeOccupancy(dpy, win, root, width, height); continue; } if (haveRandr && ev.type ==
(local variable) int rrEventBase
rrEventBase
+
(enum value) app.RRNotify = 1
RRNotify
)
{ ++
(local variable) int rrNotifies
rrNotifies
;
auto
(local variable) _error_ nev
nev
= cast(XRRNotifyEvent*)&ev;
undefined identifier `XRRNotifyEvent`
if (nev.subtype ==
(enum value) app.RRNotify_OutputChange = 1
RRNotify_OutputChange
)
{ auto
(local variable) _error_ oev
oev
= cast(XRROutputChangeNotifyEvent*)&ev;
undefined identifier `XRROutputChangeNotifyEvent`
void instrument.emitf(scope const(char)* kind, scope const(char)* fmt, ...) nothrow @nogc

Emit an event with a printf-formatted key=value ... payload.

emitf
("randr_notify", "subtype=OutputChange output=0x%lx crtc=0x%lx "
~ "mode=0x%lx connection=%d", cast(c_ulong) oev.output, cast(c_ulong) oev.crtc, cast(c_ulong) oev.mode, cast(int) oev.connection); } else if (nev.subtype ==
(enum value) app.RRNotify_OutputProperty = 2
RRNotify_OutputProperty
)
{ auto
(local variable) _error_ pev
pev
= cast(XRROutputPropertyNotifyEvent*)&ev;
undefined identifier `XRROutputPropertyNotifyEvent`
char*
(local variable) char* prop
prop
= XGetAtomName(dpy, pev.property);
undefined identifier `XGetAtomName`
void instrument.emitf(scope const(char)* kind, scope const(char)* fmt, ...) nothrow @nogc

Emit an event with a printf-formatted key=value ... payload.

emitf
("randr_notify", "subtype=OutputProperty output=0x%lx property=%s state=%d",
cast(c_ulong) pev.output,
(local variable) char* prop
prop
, pev.state);
XFree(prop);
undefined identifier `XFree`
} else
void instrument.emitf(scope const(char)* kind, scope const(char)* fmt, ...) nothrow @nogc

Emit an event with a printf-formatted key=value ... payload.

emitf
("randr_notify", "subtype=%d", nev.subtype);
if (haveMonitors) enumerateMonitors(dpy, root); if (haveResources) enumerateResources(dpy, root, true); computeOccupancy(dpy, win, root, width, height); continue; } switch (ev.type) { case MapNotify: computeOccupancy(dpy, win, root, width, height); break; case ConfigureNotify: width = ev.xconfigure.
ev.xconfigure.width
width
;
height = ev.xconfigure.
ev.xconfigure.height
height
;
emitf("configure", "pos=%d,%d size=%dx%d", ev.xconfigure.
ev.xconfigure.x
x
, ev.xconfigure.
ev.xconfigure.y
y
, width, height);
computeOccupancy(dpy, win, root, width, height); break; case ClientMessage: if (cast(Atom) ev.xclient.data.l[0] == wmDelete) { emit("close_requested via=WM_DELETE_WINDOW"); running = false; } break; case KeyPress: running = false; break; default: break; } } if (
(local variable) const(bool) autoExit
autoExit
)
{ const
(local variable) const(long) elapsedMs
elapsedMs
=
long instrument.nowUs() nothrow @nogc

Microseconds elapsed since initInstrument.

nowUs
() / 1000;
// One move per second starting at t=1s: exercises the occupancy // derivation against the (single) monitor without any driver. if (
(local variable) int moveStep
moveStep
<
(immutable global) immutable(int[2][3]) app.main.moves
moves
.
(constant) ulong immutable(int[2][3]).length = 3LU
length
&&
(local variable) const(long) elapsedMs
elapsedMs
> 1000 * (
(local variable) int moveStep
moveStep
+ 1))
{
void instrument.emitf(scope const(char)* kind, scope const(char)* fmt, ...) nothrow @nogc

Emit an event with a printf-formatted key=value ... payload.

emitf
("step", "name=XMoveWindow n=%d pos=%d,%d",
(local variable) int moveStep
moveStep
+ 1,
(immutable global) immutable(int[2][3]) app.main.moves
moves
[
(local variable) int moveStep
moveStep
][0],
(immutable global) immutable(int[2][3]) app.main.moves
moves
[
(local variable) int moveStep
moveStep
][1]);
XMoveWindow(dpy, win, moves[moveStep][0], moves[moveStep][1]);
undefined identifier `XMoveWindow`
XFlush(dpy); // push the request before sleeping in poll()
undefined identifier `XFlush`
++
(local variable) int moveStep
moveStep
;
} if (
(local variable) const(long) elapsedMs
elapsedMs
>
(local variable) const(int) durationMs
durationMs
)
{
void instrument.emit(scope const(char)* kind) nothrow @nogc

Emit an event with no key=value payload.

emit
("auto_exit");
break; } } pollfd
(local variable) _error_ pfd
pfd
;
undefined identifier `pollfd`
pfd.
pfd.fd
fd
= fd;
pfd.events = POLLIN; pfd.revents = 0; poll(&pfd, 1, autoExit ? 100 : -1);
undefined identifier `poll`
}
void instrument.emitf(scope const(char)* kind, scope const(char)* fmt, ...) nothrow @nogc

Emit an event with a printf-formatted key=value ... payload.

emitf
("summary", "monitors=%d outputs=%d randr_screen_changes=%d randr_notifies=%d",
(__gshared global) int app.g_nMonitors
g_nMonitors
,
(__gshared global) int app.g_nOutputs
g_nOutputs
,
(local variable) int rrScreenChanges
rrScreenChanges
,
(local variable) int rrNotifies
rrNotifies
);
XDestroyWindow(dpy, win);
undefined identifier `XDestroyWindow`
XCloseDisplay(dpy);
undefined identifier `XCloseDisplay`
void instrument.emit(scope const(char)* kind) nothrow @nogc

Emit an event with no key=value payload.

emit
("teardown");
return 0; }