app.dhover×306 error×32all
// X11 F14 demo — window state & vetoable close (../../f14-window-state.md,
// spec ../../../features/f14-window-state.md). Evolves the scaffold
// (../scaffold/app.d) event loop; presentation is reduced to a server-side
// XFillRectangle (state events, not pixels, are the subject here).
//
// What it exercises:
//   * maximize toggle / fullscreen toggle via _NET_WM_STATE ClientMessages to
//     the root window (EWMH: _NET_WM_STATE_MAXIMIZED_HORZ+VERT,
//     _NET_WM_STATE_FULLSCREEN, action _NET_WM_STATE_TOGGLE)
//   * minimize via XIconifyWindow (ICCCM WM_CHANGE_STATE -> IconicState),
//     restore via XMapWindow + _NET_ACTIVE_WINDOW
//   * every resulting event is logged until the dust settles: PropertyNotify
//     on _NET_WM_STATE / WM_STATE (the atom list is re-read and decoded each
//     change), ConfigureNotify sizes, Map/Unmap/ReparentNotify,
//     VisibilityNotify, and FocusIn/FocusOut with the full mode/detail decode
//   * vetoable close: a "dirty" flag vetoes the first WM_DELETE_WINDOW
//     ClientMessage (the request is purely advisory — there is nothing to
//     "return" to the WM); the second request closes
//   * WSI_NO_WM_DELETE=1 omits WM_DELETE_WINDOW from WM_PROTOCOLS: a WM-side
//     close then falls back to XKillClient and the connection dies (XIO error
//     handler logs `connection_lost` and exits 0 — that *is* the finding)
//
// Modes: WSI_AUTO_EXIT=1 self-drives the whole transition schedule (the same
// handlers the keys call) and exits 0 — works on bare Xvfb (no WM: requests
// vanish; the silence is logged) and under a WM. WSI_DRIVEN=1 instead waits
// ~12 s for externally injected keys (xdotool; see run.sh):
//   m maximize-toggle   i iconify   r restore   f fullscreen-toggle
//   d dirty-toggle      c self-send a WM_DELETE_WINDOW request   q quit
// Headless-safe: no display -> prints `SKIP:` and exits 0.
module 
(module) app
app
;
import
(module) c
c
; // ImportC: Xlib + Xutil + Xatom (+ unused XShm) + poll
C preprocess command `cpp` failed for file `/home/runner/work/sparkles/sparkles/docs/research/window-system-integration/os-apis/x11/examples/f14-window-state/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.exit = noreturn core.stdc.stdlib.exit(int status) nothrow @nogc
exit
,
(alias) app.getenv = char* core.stdc.stdlib.getenv(scope const(char*) name) nothrow @nogc
getenv
;
// Macros ImportC cannot export, re-declared (see ../scaffold/app.d): enum : c_long {
(enum value) app.KeyPressMask = 1L
KeyPressMask
= 1L << 0,
(enum value) app.ExposureMask = 32768L
ExposureMask
= 1L << 15,
(enum value) app.VisibilityChangeMask = 65536L
VisibilityChangeMask
= 1L << 16,
(enum value) app.StructureNotifyMask = 131072L
StructureNotifyMask
= 1L << 17,
(enum value) app.SubstructureNotifyMask = 524288L
SubstructureNotifyMask
= 1L << 19,
(enum value) app.SubstructureRedirectMask = 1048576L
SubstructureRedirectMask
= 1L << 20,
(enum value) app.FocusChangeMask = 2097152L
FocusChangeMask
= 1L << 21,
(enum value) app.PropertyChangeMask = 4194304L
PropertyChangeMask
= 1L << 22,
} enum // XEvent.type discriminators {
(enum value) app.KeyPress = 2
KeyPress
= 2,
(enum value) app.FocusIn = 9
FocusIn
= 9,
(enum value) app.FocusOut = 10
FocusOut
= 10,
(enum value) app.Expose = 12
Expose
= 12,
(enum value) app.VisibilityNotify = 15
VisibilityNotify
= 15,
(enum value) app.UnmapNotify = 18
UnmapNotify
= 18,
(enum value) app.MapNotify = 19
MapNotify
= 19,
(enum value) app.ReparentNotify = 21
ReparentNotify
= 21,
(enum value) app.ConfigureNotify = 22
ConfigureNotify
= 22,
(enum value) app.PropertyNotify = 28
PropertyNotify
= 28,
(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
(constant) int app.XA_ATOM = 4
XA_ATOM
= 4; // Xatom.h: #define XA_ATOM ((Atom) 4) — a cast macro
enum
(constant) int app.AnyPropertyType = 0
AnyPropertyType
= 0;
enum
(constant) int app.NoEventMask = 0
NoEventMask
= 0;
// EWMH _NET_WM_STATE ClientMessage actions (EWMH spec, _NET_WM_STATE): enum : c_long {
(enum value) app._NET_WM_STATE_REMOVE = 0L
_NET_WM_STATE_REMOVE
= 0,
(enum value) app._NET_WM_STATE_ADD = 1L
_NET_WM_STATE_ADD
= 1,
(enum value) app._NET_WM_STATE_TOGGLE = 2L
_NET_WM_STATE_TOGGLE
= 2,
} // ICCCM WM_STATE / WM_CHANGE_STATE state values: enum {
(enum value) app.WithdrawnState = 0
WithdrawnState
= 0,
(enum value) app.NormalState = 1
NormalState
= 1,
(enum value) app.IconicState = 3
IconicState
= 3 }
// The FocusIn/FocusOut "Notify* zoo" (Xlib ch. 10.8, <X11/X.h>): static immutable
(alias) object.string = string
string
[4]
(immutable global) immutable(string[4]) app.focusModes
focusModes
=
["NotifyNormal", "NotifyGrab", "NotifyUngrab", "NotifyWhileGrabbed"]; static immutable
(alias) object.string = string
string
[8]
(immutable global) immutable(string[8]) app.focusDetails
focusDetails
= [
"NotifyAncestor", "NotifyVirtual", "NotifyInferior", "NotifyNonlinear", "NotifyNonlinearVirtual", "NotifyPointer", "NotifyPointerRoot", "NotifyDetailNone", ]; struct
(struct) app.Demo
Demo
{ Display*
(field) _error_ app.Demo.dpy
dpy
;
undefined identifier `Display`
Window
(field) _error_ app.Demo.root
root
,
(field) _error_ app.Demo.win
win
;
undefined identifier `Window`
undefined identifier `Window`
int
(field) int app.Demo.screen
screen
;
Atom
(field) _error_ app.Demo.netWmState
netWmState
,
(field) _error_ app.Demo.netMaxH
netMaxH
,
(field) _error_ app.Demo.netMaxV
netMaxV
,
(field) _error_ app.Demo.netFullscreen
netFullscreen
,
(field) _error_ app.Demo.netActive
netActive
;
undefined identifier `Atom`
undefined identifier `Atom`
undefined identifier `Atom`
undefined identifier `Atom`
undefined identifier `Atom`
Atom
(field) _error_ app.Demo.wmProtocols
wmProtocols
,
(field) _error_ app.Demo.wmDelete
wmDelete
,
(field) _error_ app.Demo.wmState
wmState
;
undefined identifier `Atom`
undefined identifier `Atom`
undefined identifier `Atom`
bool
(field) bool app.Demo.dirty
dirty
,
(field) bool app.Demo.running
running
= true;
int
(field) int app.Demo.requests
requests
,
(field) int app.Demo.stateChanges
stateChanges
,
(field) int app.Demo.configures
configures
,
(field) int app.Demo.unmapsMaps
unmapsMaps
,
(field) int app.Demo.focusEvents
focusEvents
;
} __gshared int
(__gshared global) int app.g_xerrors
g_xerrors
;
extern (C) int
app.onXError
onXError
(Display*
(parameter) Display* dpy
dpy
, XErrorEvent*
(parameter) XErrorEvent* e
e
) @nogc nothrow
undefined identifier `Display`
undefined identifier `XErrorEvent`
{ ++g_xerrors; emitf("x_error", "code=%d request=%d", e.error_code, e.request_code); return 0; } // Fires when the server severs the connection (the XKillClient probe). The // handler must not return; exiting 0 keeps the probe pass green — losing the // connection is the documented outcome, not a demo failure. extern (C) int
app.onXIOError
onXIOError
(Display*
(parameter) Display* dpy
dpy
) @nogc nothrow
undefined identifier `Display`
{ emit("connection_lost via=XIOError likely=XKillClient"); exit(0); } /// EWMH state change: a ClientMessage *to the root window* with /// SubstructureRedirect|SubstructureNotify in the event mask — only a WM /// (the client that selected SubstructureRedirect on the root) receives it. void
app.sendNetWmState

EWMH state change: a ClientMessage to the root window with SubstructureRedirect|SubstructureNotify in the event mask — only a WM (the client that selected SubstructureRedirect on the root) receives it.

sendNetWmState
(ref
(struct) app.Demo
Demo
(parameter) Demo d
d
, c_long action, Atom a1, Atom a2,
undefined identifier `Atom`
undefined identifier `Atom`
const(char)* kind) @nogc nothrow { XEvent
_error_ e
e
;
e.xclient.
e.xclient.type
type
= ClientMessage;
e.xclient.window = d.
d.win
win
;
e.xclient.message_type = d.
d.netWmState
netWmState
;
e.xclient.
e.xclient.format
format
= 32;
e.xclient.data.l[0] = action; e.xclient.data.l[1] = cast(c_long) a1; e.xclient.data.l[2] = cast(c_long) a2; e.xclient.data.l[3] = 1; // source indication: normal application XSendEvent(d.
d.dpy
dpy
, d.
d.root
root
, False,
SubstructureRedirectMask | SubstructureNotifyMask, &e); XFlush(d.
d.dpy
dpy
);
++d.
d.requests
requests
;
emitf("state_request", "kind=%s action=%ld target=root", kind, action); } void
app.requestActivate
requestActivate
(ref
(struct) app.Demo
Demo
(parameter) Demo d
d
) @nogc nothrow
{ XEvent
_error_ e
e
;
e.xclient.
e.xclient.type
type
= ClientMessage;
e.xclient.window = d.
d.win
win
;
e.xclient.message_type = d.
d.netActive
netActive
;
e.xclient.
e.xclient.format
format
= 32;
e.xclient.data.l[0] = 1; // source: application XSendEvent(d.
d.dpy
dpy
, d.
d.root
root
, False,
SubstructureRedirectMask | SubstructureNotifyMask, &e); XFlush(d.
d.dpy
dpy
);
++d.
d.requests
requests
;
emit("state_request kind=activate target=root"); } /// Self-deliver the WM_PROTOCOLS/WM_DELETE_WINDOW ClientMessage — the close /// request is just an event any client may send; the WM sends exactly this. void
app.sendCloseRequest

Self-deliver the WM_PROTOCOLS/WM_DELETE_WINDOW ClientMessage — the close request is just an event any client may send; the WM sends exactly this.

sendCloseRequest
(ref
(struct) app.Demo
Demo
(parameter) Demo d
d
) @nogc nothrow
{ XEvent
_error_ e
e
;
e.xclient.
e.xclient.type
type
= ClientMessage;
e.xclient.window = d.
d.win
win
;
e.xclient.message_type = d.
d.wmProtocols
wmProtocols
;
e.xclient.
e.xclient.format
format
= 32;
e.xclient.data.l[0] = cast(c_long) d.
d.wmDelete
wmDelete
;
XSendEvent(d.
d.dpy
dpy
, d.
d.win
win
, False, NoEventMask, &e);
XFlush(d.
d.dpy
dpy
);
emit("step name=XSendEvent msg=WM_DELETE_WINDOW to=self"); } /// Re-read and decode the _NET_WM_STATE atom list (PropertyNotify carries no /// payload — the new value must be fetched with XGetWindowProperty). void
app.logNetWmState

Re-read and decode the NET_WM_STATE atom list (PropertyNotify carries no payload — the new value must be fetched with XGetWindowProperty).

logNetWmState
(ref
(struct) app.Demo
Demo
(parameter) Demo d
d
) nothrow
{ Atom
_error_ type
type
;
int
_error_ format
format
;
c_ulong
_error_ nitems
nitems
,
_error_ after
after
;
ubyte*
_error_ prop
prop
;
XGetWindowProperty(d.
d.dpy
dpy
, d.
d.win
win
, d.
d.netWmState
netWmState
, 0, 32, False, XA_ATOM,
&type, &format, &nitems, &after, &prop); char[256]
_error_ buf
buf
= '\0';
(unresolved type) size_t
size_t
_error_ off
off
;
foreach (
(parameter) i
i
; 0 .. cast(
(unresolved type) size_t
size_t
) nitems)
{ const
_error_ a
a
= (cast(Atom*) prop)[i];
char*
_error_ name
name
= XGetAtomName(d.
d.dpy
dpy
, a);
off += snprintf(buf.ptr + off, buf.
buf.length
length
- off, "%s%s",
i ? ",".ptr : "".ptr, name); XFree(name); } if (prop !is null) XFree(prop); ++d.
d.stateChanges
stateChanges
;
emitf("state_changed", "states=[%s]", buf.ptr); } /// Decode the ICCCM WM_STATE property (set by the WM): the first CARD32 is /// Withdrawn/Normal/Iconic — the only reliable iconified-or-not signal. void
app.logWmState

Decode the ICCCM WM_STATE property (set by the WM): the first CARD32 is Withdrawn/Normal/Iconic — the only reliable iconified-or-not signal.

logWmState
(ref
(struct) app.Demo
Demo
(parameter) Demo d
d
) nothrow
{ Atom
_error_ type
type
;
int
_error_ format
format
;
c_ulong
_error_ nitems
nitems
,
_error_ after
after
;
ubyte*
_error_ prop
prop
;
XGetWindowProperty(d.
d.dpy
dpy
, d.
d.win
win
, d.
d.wmState
wmState
, 0, 2, False, AnyPropertyType,
&type, &format, &nitems, &after, &prop); if (prop !is null && nitems >= 1) { const
_error_ v
v
= *cast(c_ulong*) prop;
emitf("state_changed", "wm_state=%s", v == IconicState ? "iconic".ptr : v == NormalState ? "normal".ptr : "withdrawn".ptr); ++d.
d.stateChanges
stateChanges
;
} if (prop !is null) XFree(prop); } void
app.redraw
redraw
(ref
(struct) app.Demo
Demo
(parameter) Demo d
d
, int w, int h) @nogc nothrow
{ GC
_error_ gc
gc
= XDefaultGC(d.
d.dpy
dpy
, d.
d.screen
screen
);
XSetForeground(d.
d.dpy
dpy
, gc, d.
d.dirty
dirty
? 0xc04040 : 0x4070b0);
XFillRectangle(d.
d.dpy
dpy
, d.
d.win
win
, gc, 0, 0, cast(uint) w, cast(uint) h);
} // One named action per key; the auto schedule calls the same handler. void
app.act
act
(ref
(struct) app.Demo
Demo
(parameter) Demo d
d
, char
(parameter) char key
key
) nothrow
{ switch (key) { case 'm': sendNetWmState(d, _NET_WM_STATE_TOGGLE, d.
d.netMaxH
netMaxH
, d.
d.netMaxV
netMaxV
, "maximize_toggle");
break; case 'f': sendNetWmState(d, _NET_WM_STATE_TOGGLE, d.
d.netFullscreen
netFullscreen
, 0, "fullscreen_toggle");
break; case 'i': // Xutil convenience: sends the ICCCM WM_CHANGE_STATE ClientMessage // (IconicState) to the root — again, only a WM listens. const
_error_ st
st
= XIconifyWindow(d.
d.dpy
dpy
, d.
d.win
win
, d.
d.screen
screen
);
XFlush(d.
d.dpy
dpy
);
++d.
d.requests
requests
;
emitf("state_request", "kind=minimize via=XIconifyWindow sent=%d", st); break; case 'r': sendNetWmState(d, _NET_WM_STATE_REMOVE, d.
d.netMaxH
netMaxH
, d.
d.netMaxV
netMaxV
, "restore_maximize");
sendNetWmState(d, _NET_WM_STATE_REMOVE, d.
d.netFullscreen
netFullscreen
, 0, "restore_fullscreen");
XMapWindow(d.
d.dpy
dpy
, d.
d.win
win
); // de-iconify (ICCCM: map the window)
emit("state_request kind=restore via=XMapWindow"); requestActivate(d); break; case 'd': d.
d.dirty
dirty
= !d.
d.dirty
dirty
;
emitf("dirty", "flag=%d", cast(int) d.
d.dirty
dirty
);
break; case 'c': sendCloseRequest(d); break; case 'q': d.
d.running
running
= false;
break; default: break; } } 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
("f14_x11");
const
(local variable) const(bool) autoExit
autoExit
=
char* core.stdc.stdlib.getenv(scope const(char*) name) nothrow @nogc
getenv
("WSI_AUTO_EXIT") !is null;
const
(local variable) const(bool) driven
driven
=
char* core.stdc.stdlib.getenv(scope const(char*) name) nothrow @nogc
getenv
("WSI_DRIVEN") !is null;
const
(local variable) const(bool) noWmDelete
noWmDelete
=
char* core.stdc.stdlib.getenv(scope const(char*) name) nothrow @nogc
getenv
("WSI_NO_WM_DELETE") !is null;
(struct) app.Demo
Demo
(local variable) _error_ d
d
;
d.
d.dpy
dpy
= XOpenDisplay(null);
if (d.
(field) _error_ d.dpy
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; } XSetErrorHandler(&onXError);
undefined identifier `XSetErrorHandler`
XSetIOErrorHandler(&onXIOError);
undefined identifier `XSetIOErrorHandler`
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(d.
d.dpy
dpy
));
undefined identifier `XConnectionNumber`
d.
d.screen
screen
= XDefaultScreen(d.
d.dpy
dpy
);
d.
d.root
root
= XRootWindow(d.
d.dpy
dpy
, d.
d.screen
screen
);
int
(local variable) int width
width
= 480,
(local variable) int height
height
= 320;
d.
d.win
win
= XCreateSimpleWindow(d.
d.dpy
dpy
, d.
d.root
root
, 20, 20, width, height, 1,
XBlackPixel(d.
d.dpy
dpy
, d.
d.screen
screen
), XWhitePixel(d.
d.dpy
dpy
, d.
d.screen
screen
));
XStoreName(d.
d.dpy
dpy
, d.
d.win
win
, "Sparkles \xc2\xb7 X11 F14 window state");
undefined identifier `XStoreName`
d.
d.netWmState
netWmState
= XInternAtom(d.
d.dpy
dpy
, "_NET_WM_STATE", False);
d.
d.netMaxH
netMaxH
= XInternAtom(d.
d.dpy
dpy
, "_NET_WM_STATE_MAXIMIZED_HORZ", False);
d.
d.netMaxV
netMaxV
= XInternAtom(d.
d.dpy
dpy
, "_NET_WM_STATE_MAXIMIZED_VERT", False);
d.
d.netFullscreen
netFullscreen
= XInternAtom(d.
d.dpy
dpy
, "_NET_WM_STATE_FULLSCREEN", False);
d.
d.netActive
netActive
= XInternAtom(d.
d.dpy
dpy
, "_NET_ACTIVE_WINDOW", False);
d.
d.wmProtocols
wmProtocols
= XInternAtom(d.
d.dpy
dpy
, "WM_PROTOCOLS", False);
d.
d.wmDelete
wmDelete
= XInternAtom(d.
d.dpy
dpy
, "WM_DELETE_WINDOW", False);
d.
d.wmState
wmState
= XInternAtom(d.
d.dpy
dpy
, "WM_STATE", False);
if (
(local variable) const(bool) noWmDelete
noWmDelete
)
void instrument.emit(scope const(char)* kind) nothrow @nogc

Emit an event with no key=value payload.

emit
("step name=XSetWMProtocols skipped=WSI_NO_WM_DELETE");
else XSetWMProtocols(d.
d.dpy
dpy
, d.
d.win
win
, &d.
d.wmDelete
wmDelete
, 1);
undefined identifier `XSetWMProtocols`
XSelectInput(d.
d.dpy
dpy
, d.
d.win
win
, ExposureMask | KeyPressMask | StructureNotifyMask
undefined identifier `XSelectInput`
| PropertyChangeMask | FocusChangeMask | VisibilityChangeMask); XMapWindow(d.
d.dpy
dpy
, d.
d.win
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", d.
(field) _error_ d.win
win
,
(local variable) int width
width
,
(local variable) int height
height
);
// The self-driven schedule (µs since init) — same handlers as the keys. static immutable struct
(struct) app.main.Step
Step
{ long
(field) immutable(long) app.main.Step.t
t
; char
(field) immutable(char) app.main.Step.key
key
; }
static immutable
(struct) app.main.Step
Step
[9]
(immutable global) immutable(app.main.Step[9]) app.main.schedule
schedule
= [
{400_000, 'm'}, {900_000, 'm'}, {1_400_000, 'i'}, {1_900_000, 'r'}, {2_400_000, 'f'}, {2_900_000, 'f'}, {3_400_000, 'd'}, {3_500_000, 'c'}, /* dirty -> vetoed */ {3_900_000, 'c'}, /* closes */ ];
(alias) object.size_t = ulong
size_t
(local variable) ulong nextStep
nextStep
;
const
(local variable) const(int) deadline
deadline
=
(local variable) const(bool) driven
driven
? 12_000_000 : 5_000_000;
const
(local variable) const(_error_) fd
fd
= XConnectionNumber(d.
d.dpy
dpy
);
undefined identifier `XConnectionNumber`
while (d.
(field) _error_ d.running
running
)
{ while (XPending(d.
d.dpy
dpy
) > 0)
undefined identifier `XPending`
{ XEvent
(local variable) _error_ ev
ev
;
undefined identifier `XEvent`
XNextEvent(d.
d.dpy
dpy
, &ev);
undefined identifier `XNextEvent`
switch (ev.
(field) _error_ ev.type
type
)
{ case ConfigureNotify: ++d.
d.configures
configures
;
emitf("configure", "size=%dx%d pos=%d+%d send_event=%d", ev.xconfigure.
ev.xconfigure.width
width
, ev.xconfigure.
ev.xconfigure.height
height
,
ev.xconfigure.x, ev.xconfigure.y, cast(int) ev.xany.send_event); width = ev.xconfigure.
ev.xconfigure.width
width
;
height = ev.xconfigure.
ev.xconfigure.height
height
;
break; case MapNotify: ++d.
d.unmapsMaps
unmapsMaps
;
emit("map_notify"); break; case UnmapNotify: ++d.
d.unmapsMaps
unmapsMaps
;
emitf("unmap_notify", "send_event=%d", cast(int) ev.xany.send_event); break; case ReparentNotify: emitf("reparent_notify", "parent=0x%lx", ev.xreparent.parent); break; case VisibilityNotify: emitf("visibility", "state=%d", ev.xvisibility.state); break; case PropertyNotify: char*
_error_ name
name
= XGetAtomName(d.
d.dpy
dpy
, ev.xproperty.atom);
emitf("property_notify", "atom=%s state=%s", name, ev.xproperty.state == 0 ? "NewValue".ptr : "Deleted".ptr); XFree(name); if (ev.xproperty.atom == d.
d.netWmState
netWmState
&& ev.xproperty.state == 0)
logNetWmState(d); else if (ev.xproperty.atom == d.
d.wmState
wmState
&& ev.xproperty.state == 0)
logWmState(d); break; case FocusIn: case FocusOut: ++d.
d.focusEvents
focusEvents
;
emitf("focus", "state=%s mode=%s detail=%s", ev.
ev.type
type
== FocusIn ? "in".ptr : "out".ptr,
focusModes[ev.xfocus.mode].ptr, focusDetails[ev.xfocus.detail].ptr); break; case Expose: if (ev.xexpose.count == 0) redraw(d, width, height); break; case ClientMessage: if (ev.xclient.message_type == d.
d.wmProtocols
wmProtocols
&& cast(Atom) ev.xclient.data.l[0] == d.
d.wmDelete
wmDelete
)
{ if (d.
d.dirty
dirty
)
{ // The veto: simply do nothing. WM_DELETE_WINDOW is // advisory (ICCCM §4.2.8.1) — there is no reply, no // return value, nothing to send back. Ignoring it IS // the veto; the WM cannot tell refusal from sloth. d.
d.dirty
dirty
= false;
emit("close_requested veto=1 action=ignored_dirty_cleared"); redraw(d, width, height); } else { emit("close_requested veto=0 action=quit"); d.
d.running
running
= false;
} } break; case KeyPress: const
_error_ sym
sym
= XLookupKeysym(&ev.xkey, 0);
emitf("key", "sym=0x%lx", sym); if (sym >= 'a' && sym <= 'z') act(d, cast(char) sym); break; default: break; } } if (
(local variable) const(bool) autoExit
autoExit
&& !
(local variable) const(bool) driven
driven
&&
(local variable) ulong nextStep
nextStep
<
(immutable global) immutable(app.main.Step[9]) app.main.schedule
schedule
.
(constant) ulong immutable(app.main.Step[9]).length = 9LU
length
&&
long instrument.nowUs() nothrow @nogc

Microseconds elapsed since initInstrument.

nowUs
() >=
(immutable global) immutable(app.main.Step[9]) app.main.schedule
schedule
[
(local variable) ulong nextStep
nextStep
].
(field) immutable(long) app.main.Step.t
t
)
{ act(d, schedule[nextStep].
schedule[nextStep].key
key
);
++
(local variable) ulong nextStep
nextStep
;
} if ((
(local variable) const(bool) autoExit
autoExit
||
(local variable) const(bool) driven
driven
) &&
long instrument.nowUs() nothrow @nogc

Microseconds elapsed since initInstrument.

nowUs
() >
(local variable) const(int) deadline
deadline
)
{
void instrument.emit(scope const(char)* kind) nothrow @nogc

Emit an event with no key=value payload.

emit
("auto_exit reason=deadline");
break; } if (!
(local variable) const(bool) autoExit
autoExit
&& !
(local variable) const(bool) driven
driven
&&
(local variable) ulong nextStep
nextStep
== 0)
(local variable) ulong nextStep
nextStep
= 1; // interactive: no schedule, keys only
pollfd
(local variable) _error_ pfd
pfd
;
undefined identifier `pollfd`
pfd.
pfd.fd
fd
= fd;
pfd.events = POLLIN; pfd.revents = 0; poll(&pfd, 1, (autoExit || driven) ? 20 : -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", "requests=%d state_changes=%d configures=%d map_unmap=%d "
~ "focus=%d x_errors=%d", d.
(field) _error_ d.requests
requests
, d.
(field) _error_ d.stateChanges
stateChanges
, d.
(field) _error_ d.configures
configures
,
d.
(field) _error_ d.unmapsMaps
unmapsMaps
, d.
(field) _error_ d.focusEvents
focusEvents
,
(__gshared global) int app.g_xerrors
g_xerrors
);
XDestroyWindow(d.
d.dpy
dpy
, d.
d.win
win
);
undefined identifier `XDestroyWindow`
XCloseDisplay(d.
d.dpy
dpy
);
undefined identifier `XCloseDisplay`
return 0; }