app.dhover×206 error×43all
// X11 F06 demo — keyboard & keymap (../../../features/f06-keyboard.md).
// Built on the scaffold (../scaffold/app.d): same ImportC binding style, same
// poll(2)-driven readiness loop, same instrument.d event log.
//
// What it demonstrates (F06 requirements 1, 3, 6):
//
//   * The xkbcommon-x11 path: XGetXCBConnection exposes the Xlib connection's
//     xcb_connection_t, xkb_x11_setup_xkb_extension negotiates XKB >= 1.0,
//     xkb_x11_keymap_new_from_device + xkb_x11_state_new_from_device build the
//     keymap/state for the core keyboard — the app then owns the same
//     scancode -> keysym -> text state machine a Wayland client owns.
//   * Modifier/group state is synced from the server's XkbStateNotify events
//     via xkb_state_update_mask (NOT from xkb_state_update_key — the demo is
//     a pure observer, so the server's state is authoritative and a second
//     client's modifier presses are tracked too; see the findings doc for the
//     drift trade-off).
//   * Live keymap replacement: XkbNewKeyboardNotify / XkbMapNotify (broadcast
//     by the server when e.g. `setxkbmap de` runs) trigger a full
//     keymap+state rebuild, logged as `keymap_event`.
//   * Server-side auto-repeat with the detectable opt-in
//     (XkbSetDetectableAutoRepeat): a repeat arrives as KeyPress-without-
//     KeyRelease, detected via a keycode-is-already-down bitset -> repeat=1.
//   * Dead-key compose via xkb_compose (the de-layout `´` + `e` -> `é`);
//     XIM/X compose-of-the-input-method is F07's territory, not touched here.
//
// Every press/release logs `key code=… sym=… text=… state=down|up repeat=…`.
// Input is injected by the run.sh driver (xdotool + setxkbmap under Xvfb);
// without a driver the demo just times out cleanly (WSI_AUTO_EXIT=1, exit 0).
// Headless-safe: no X server -> prints `SKIP:` and exits 0. Findings:
// ../../f06-keyboard.md.
module 
(module) app
app
;
import
(module) c
c
; // ImportC: Xlib + Xlib-xcb + XKBlib + xkbcommon{,-x11,-compose} + poll
C preprocess command `cpp` failed for file `/home/runner/work/sparkles/sparkles/docs/research/window-system-integration/os-apis/x11/examples/f06-keyboard/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.locale

D header file for C99.

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

Source

core/stdc/locale.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)
locale
:
(alias constant) app.LC_ALL = int core.stdc.locale.LC_ALL = 6
LC_ALL
,
(alias) app.setlocale = char* core.stdc.locale.setlocale(int category, scope const(char*) locale) nothrow @nogc @system
setlocale
;
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
;
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
;
import
(package) core
core
.
(package) core.stdc
stdc
.
(module) core.stdc.string

D header file for C99.

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

Source

core/stdc/string.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)
string
:
(alias) app.strcmp = int core.stdc.string.strcmp(scope const(char*) s1, scope const(char*) s2) pure nothrow @nogc
strcmp
;
// --------------------------------------------------------------------------- // Constants Xlib/XKB.h expose as macros that ImportC cannot import; // re-declared per the scaffold gotcha. enum : c_long {
(enum value) app.KeyPressMask = 1L
KeyPressMask
= 1L << 0,
(enum value) app.KeyReleaseMask = 2L
KeyReleaseMask
= 1L << 1,
(enum value) app.ExposureMask = 32768L
ExposureMask
= 1L << 15,
(enum value) app.StructureNotifyMask = 131072L
StructureNotifyMask
= 1L << 17,
(enum value) app.FocusChangeMask = 2097152L
FocusChangeMask
= 1L << 21,
} enum // XEvent.type discriminators {
(enum value) app.KeyPress = 2
KeyPress
= 2,
(enum value) app.KeyRelease = 3
KeyRelease
= 3,
(enum value) app.FocusIn = 9
FocusIn
= 9,
(enum value) app.FocusOut = 10
FocusOut
= 10,
(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 value) app.MappingNotify = 34
MappingNotify
= 34,
} 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.RevertToParent = 2
RevertToParent
= 2;
enum
(constant) int app.CurrentTime = 0
CurrentTime
= 0;
enum
(constant) int app.XkbUseCoreKbd = 256
XkbUseCoreKbd
= 0x0100; // XKB.h device spec
enum // XkbEvent.any.xkb_type discriminators (XKB.h) {
(enum value) app.XkbNewKeyboardNotify = 0
XkbNewKeyboardNotify
= 0,
(enum value) app.XkbMapNotify = 1
XkbMapNotify
= 1,
(enum value) app.XkbStateNotify = 2
XkbStateNotify
= 2,
} enum : c_ulong // XkbSelectEvents masks (XKB.h) {
(enum value) app.XkbNewKeyboardNotifyMask = 1LU
XkbNewKeyboardNotifyMask
= 1L << 0,
(enum value) app.XkbMapNotifyMask = 2LU
XkbMapNotifyMask
= 1L << 1,
(enum value) app.XkbStateNotifyMask = 4LU
XkbStateNotifyMask
= 1L << 2,
} // --------------------------------------------------------------------------- // The xkbcommon trio (context/keymap/state) + compose, rebuilt on demand. struct
(struct) app.Kbd
Kbd
{ xkb_context*
(field) _error_ app.Kbd.ctx
ctx
;
undefined identifier `xkb_context`
xkb_keymap*
(field) _error_ app.Kbd.keymap
keymap
;
undefined identifier `xkb_keymap`
xkb_state*
(field) _error_ app.Kbd.state
state
;
undefined identifier `xkb_state`
xcb_connection_t*
(field) _error_ app.Kbd.xcb
xcb
;
undefined identifier `xcb_connection_t`
int
(field) int app.Kbd.deviceId
deviceId
;
} /// (Re)build keymap + state from the server's current map for the core /// keyboard — called at startup and again on every XkbNewKeyboardNotify / /// XkbMapNotify (e.g. after `setxkbmap de`). F06 requirement 3 + 6. bool
app.rebuildKeymap

(Re)build keymap + state from the server's current map for the core keyboard — called at startup and again on every XkbNewKeyboardNotify / XkbMapNotify (e.g. after setxkbmap de). F06 requirement 3 + 6.

rebuildKeymap
(ref
(struct) app.Kbd
Kbd
k, const(char)* reason)
{ if (k.
k.state
state
!is null)
xkb_state_unref(k.
k.state
state
);
if (k.
k.keymap
keymap
!is null)
xkb_keymap_unref(k.
k.keymap
keymap
);
k.
k.keymap
keymap
= xkb_x11_keymap_new_from_device(k.
k.ctx
ctx
, k.
k.xcb
xcb
, k.
k.deviceId
deviceId
,
XKB_KEYMAP_COMPILE_NO_FLAGS); if (k.
k.keymap
keymap
is null)
return false; k.
k.state
state
= xkb_x11_state_new_from_device(k.
k.keymap
keymap
, k.
k.xcb
xcb
, k.
k.deviceId
deviceId
);
if (k.
k.state
state
is null)
return false; emitf("keymap_event", "reason=%s layouts=%u layout0=%s", reason, xkb_keymap_num_layouts(k.
k.keymap
keymap
), xkb_keymap_layout_get_name(k.
k.keymap
keymap
, 0));
return true; } 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
("f06_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
) : 10_000;
// -- Connect; expose the xcb side of the same socket ---------------------- 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`
xcb_connection_t*
(local variable) _error_ xcb
xcb
= XGetXCBConnection(dpy);
undefined identifier `xcb_connection_t`
undefined identifier `XGetXCBConnection`
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=XGetXCBConnection ok=%d", cast(int)(xcb !is null));
// -- XKB extension, both faces of it -------------------------------------- // xcb side (for xkbcommon-x11's GetMap/GetState requests): ushort
(local variable) ushort xkbMajor
xkbMajor
,
(local variable) ushort xkbMinor
xkbMinor
;
ubyte
(local variable) ubyte xkbBaseEvent
xkbBaseEvent
,
(local variable) ubyte xkbBaseError
xkbBaseError
;
if (!xkb_x11_setup_xkb_extension(xcb, 1, 0,
undefined identifier `xkb_x11_setup_xkb_extension`
XKB_X11_SETUP_XKB_EXTENSION_NO_FLAGS, &xkbMajor, &xkbMinor, &xkbBaseEvent, &xkbBaseError)) {
int core.stdc.stdio.printf(scope const(char*) format, scope const ...) nothrow @nogc
printf
("SKIP: server lacks the XKB extension\n");
XCloseDisplay(dpy);
undefined identifier `XCloseDisplay`
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=xkb_x11_setup_xkb_extension version=%u.%u base_event=%u",
(local variable) ushort xkbMajor
xkbMajor
,
(local variable) ushort xkbMinor
xkbMinor
,
(local variable) ubyte xkbBaseEvent
xkbBaseEvent
);
// Xlib side (so XKBlib cooks wire events into XkbEvent and XkbSelectEvents // & XkbSetDetectableAutoRepeat work). Same extension on the same socket — // the event base it reports matches the xcb one. int
(local variable) int xkbOpcode
xkbOpcode
,
(local variable) int xkbEventBase
xkbEventBase
,
(local variable) int xkbErrorBase
xkbErrorBase
,
(local variable) int libMajor
libMajor
= 1,
(local variable) int libMinor
libMinor
= 0;
XkbQueryExtension(dpy, &xkbOpcode, &xkbEventBase, &xkbErrorBase, &libMajor, &libMinor);
undefined identifier `XkbQueryExtension`
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=XkbQueryExtension event_base=%d",
(local variable) int xkbEventBase
xkbEventBase
);
// Detectable auto-repeat opt-in: repeats become KeyPress-only (F06 req 3). int
(local variable) int darSupported
darSupported
= 0;
XkbSetDetectableAutoRepeat(dpy, True, &darSupported);
undefined identifier `XkbSetDetectableAutoRepeat`
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=XkbSetDetectableAutoRepeat supported=%d",
(local variable) int darSupported
darSupported
);
// Subscribe to the keymap/state broadcasts. enum c_ulong
(constant) ulong app.main.xkbMask = 7LU
xkbMask
=
(enum value) app.XkbNewKeyboardNotifyMask = 1LU
XkbNewKeyboardNotifyMask
|
(enum value) app.XkbMapNotifyMask = 2LU
XkbMapNotifyMask
|
(enum value) app.XkbStateNotifyMask = 4LU
XkbStateNotifyMask
;
XkbSelectEvents(dpy, XkbUseCoreKbd, xkbMask, xkbMask);
undefined identifier `XkbSelectEvents`
void instrument.emit(scope const(char)* kind) nothrow @nogc

Emit an event with no key=value payload.

emit
("step name=XkbSelectEvents masks=new_keyboard|map|state");
// -- xkbcommon: keymap + state for the core keyboard ----------------------
(struct) app.Kbd
Kbd
(local variable) _error_ kbd
kbd
;
kbd.
kbd.xcb
xcb
= xcb;
kbd.
kbd.ctx
ctx
= xkb_context_new(XKB_CONTEXT_NO_FLAGS);
kbd.
kbd.deviceId
deviceId
= xkb_x11_get_core_keyboard_device_id(xcb);
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=xkb_x11_get_core_keyboard_device_id id=%d", kbd.
(field) _error_ kbd.deviceId
deviceId
);
if (kbd.
(field) _error_ kbd.deviceId
deviceId
< 0 || !rebuildKeymap(kbd, "startup"))
{
int core.stdc.stdio.printf(scope const(char*) format, scope const ...) nothrow @nogc
printf
("SKIP: could not build an xkb keymap from the device\n");
XCloseDisplay(dpy);
undefined identifier `XCloseDisplay`
return 0; } // -- Compose (dead keys): xkbcommon's compose table, locale-driven -------- // XIM-style input-method compose is F07's territory; this is the pure // client-side xkb_compose state machine. Under a bare CI env the locale is // "C", whose compose table is empty — fall back to en_US.UTF-8 (the // canonical X11 Compose set, which carries <dead_acute><e> -> é).
char* core.stdc.locale.setlocale(int category, scope const(char*) locale) nothrow @nogc @system
setlocale
(
(constant) int core.stdc.locale.LC_ALL = 6
LC_ALL
, "");
const(char)*
(local variable) const(char)* locale
locale
=
char* core.stdc.stdlib.getenv(scope const(char*) name) nothrow @nogc
getenv
("LC_ALL");
if (
(local variable) const(char)* locale
locale
is null ||
(local variable) const(char)* locale
locale
[0] == '\0')
(local variable) const(char)* locale
locale
=
char* core.stdc.stdlib.getenv(scope const(char*) name) nothrow @nogc
getenv
("LC_CTYPE");
if (
(local variable) const(char)* locale
locale
is null ||
(local variable) const(char)* locale
locale
[0] == '\0')
(local variable) const(char)* locale
locale
=
char* core.stdc.stdlib.getenv(scope const(char*) name) nothrow @nogc
getenv
("LANG");
if (
(local variable) const(char)* locale
locale
is null ||
(local variable) const(char)* locale
locale
[0] == '\0'
||
int core.stdc.string.strcmp(scope const(char*) s1, scope const(char*) s2) pure nothrow @nogc
strcmp
(
(local variable) const(char)* locale
locale
, "C") == 0 ||
int core.stdc.string.strcmp(scope const(char*) s1, scope const(char*) s2) pure nothrow @nogc
strcmp
(
(local variable) const(char)* locale
locale
, "POSIX") == 0)
(local variable) const(char)* locale
locale
= "en_US.UTF-8";
xkb_compose_table*
(local variable) _error_ composeTable
composeTable
= xkb_compose_table_new_from_locale(
undefined identifier `xkb_compose_table`
undefined identifier `xkb_compose_table_new_from_locale`
kbd.
kbd.ctx
ctx
, locale, XKB_COMPOSE_COMPILE_NO_FLAGS);
xkb_compose_state*
(local variable) _error_ compose
compose
= composeTable !is null
undefined identifier `xkb_compose_state`
? xkb_compose_state_new(composeTable, XKB_COMPOSE_STATE_NO_FLAGS) : null;
undefined identifier `xkb_compose_state_new`
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=xkb_compose_table_new_from_locale locale=%s ok=%d",
(local variable) const(char)* locale
locale
, cast(int)(compose !is null));
// -- Window; self-focus so xdotool/XTEST input lands here under bare Xvfb - const
(local variable) const(_error_) screen
screen
= XDefaultScreen(dpy);
undefined identifier `XDefaultScreen`
Window
(local variable) _error_ win
win
= XCreateSimpleWindow(dpy, XRootWindow(dpy, screen), 0, 0,
undefined identifier `Window`
undefined identifier `XCreateSimpleWindow`
480, 320, 1, XBlackPixel(dpy, screen), XWhitePixel(dpy, screen)); XStoreName(dpy, win, "Sparkles · X11 F06 keyboard");
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, KeyPressMask | KeyReleaseMask | ExposureMask
undefined identifier `XSelectInput`
| StructureNotifyMask | FocusChangeMask); 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=480x320", win);
// -- State for the loop ---------------------------------------------------- ubyte[32]
(local variable) ubyte[32] downBits
downBits
; // keycode bitset: a KeyPress for an already-down key is a repeat
bool
(local variable) bool running
running
= true,
(local variable) bool focused
focused
= false;
int
(local variable) int presses
presses
= 0,
(local variable) int releases
releases
= 0,
(local variable) int repeats
repeats
= 0,
(local variable) int composed
composed
= 0,
(local variable) int rebuilds
rebuilds
= 0;
char[64]
(local variable) char[64] symName
symName
,
(local variable) char[64] keyText
keyText
,
(local variable) char[64] composeText
composeText
;
const
(local variable) const(_error_) fd
fd
= XConnectionNumber(dpy);
undefined identifier `XConnectionNumber`
while (
(local variable) bool running
running
)
{ while (XPending(dpy) > 0) // also flushes the output buffer
undefined identifier `XPending`
{ XEvent
(local variable) _error_ ev
ev
;
undefined identifier `XEvent`
XNextEvent(dpy, &ev);
undefined identifier `XNextEvent`
if (ev.type ==
(local variable) int xkbEventBase
xkbEventBase
) // all XKB events share one type code
{ auto
(local variable) _error_ xkbEv
xkbEv
= cast(XkbEvent*)&ev;
undefined identifier `XkbEvent`
switch (xkbEv.any.xkb_type) { case XkbStateNotify: // Server-authoritative modifier/group sync (F06 req 3). xkb_state_update_mask(kbd.
kbd.state
state
,
xkbEv.
xkbEv.state
state
.base_mods, xkbEv.
xkbEv.state
state
.latched_mods,
xkbEv.
xkbEv.state
state
.locked_mods, xkbEv.
xkbEv.state
state
.base_group,
xkbEv.
xkbEv.state
state
.latched_group, xkbEv.
xkbEv.state
state
.locked_group);
emitf("xkb_state", "base_mods=0x%x locked_mods=0x%x group=%d", xkbEv.
xkbEv.state
state
.base_mods, xkbEv.
xkbEv.state
state
.locked_mods,
xkbEv.
xkbEv.state
state
.group);
break; case XkbNewKeyboardNotify: // e.g. setxkbmap replaced the keymap emitf("xkb_new_keyboard", "device=%d old_device=%d changed=0x%x", xkbEv.new_kbd.device, xkbEv.new_kbd.old_device, xkbEv.new_kbd.changed); if (rebuildKeymap(kbd, "XkbNewKeyboardNotify")) ++rebuilds; break; case XkbMapNotify: if (rebuildKeymap(kbd, "XkbMapNotify")) ++rebuilds; break; default: break; } continue; } switch (ev.type) { case KeyPress, KeyRelease: const
_error_ keycode
keycode
= ev.xkey.
ev.xkey.keycode
keycode
; // X keycode == xkb keycode
const
_error_ down
down
= ev.type == KeyPress;
const
_error_ idx
idx
= keycode >> 3,
_error_ bit
bit
= cast(ubyte)(1 << (keycode & 7));
// With detectable auto-repeat a repeat is a KeyPress while // the key is still down (no interleaved KeyRelease). const
_error_ repeat
repeat
= down && (downBits[idx] & bit) != 0;
if (down) downBits[idx] |= bit; else downBits[idx] &= cast(ubyte) ~cast(int) bit; const
_error_ sym
sym
= xkb_state_key_get_one_sym(kbd.
kbd.state
state
, keycode);
if (xkb_keysym_get_name(sym, symName.ptr, symName.length) < 0) symName[0] = '\0'; keyText[0] = '\0'; xkb_state_key_get_utf8(kbd.
kbd.state
state
, keycode, keyText.ptr, keyText.length);
const(char)*
_error_ text
text
= keyText.ptr;
if (down && compose !is null && sym != 0) { // Dead-key state machine (F06 req 6): feed every pressed // keysym; while composing, suppress the raw text. if (xkb_compose_state_feed(compose, sym) == XKB_COMPOSE_FEED_ACCEPTED) { final switch (xkb_compose_state_get_status(compose)) { case XKB_COMPOSE_COMPOSING: emit("compose state=composing"); text = ""; break; case XKB_COMPOSE_COMPOSED: composeText[0] = '\0'; xkb_compose_state_get_utf8(compose, composeText.ptr, composeText.length); emitf("compose", "state=composed text=%s", composeText.ptr); text = composeText.ptr; ++composed; xkb_compose_state_reset(compose); break; case XKB_COMPOSE_CANCELLED: emit("compose state=cancelled"); text = ""; xkb_compose_state_reset(compose); break; case XKB_COMPOSE_NOTHING: break; } } } emitf("key", "code=%u sym=%s text=%s state=%s repeat=%d", keycode, symName.ptr, text, down ? "down".ptr : "up".ptr, cast(int) repeat); if (down) { ++presses; repeats += repeat; } else ++releases; break; case MapNotify: // Bare Xvfb has no WM: focus stays PointerRoot unless someone // sets it. Self-focus so injected XTEST events land here. XSetInputFocus(dpy, win, RevertToParent, CurrentTime); XFlush(dpy); emit("step name=XSetInputFocus revert_to=parent"); break; case FocusIn: focused = true; emit("focus state=in"); break; case FocusOut: focused = false; emit("focus state=out"); break; case MappingNotify: // Legacy core-protocol keymap change; the XKB events above // supersede it for XKB-aware clients. Logged if it appears. emit("legacy_mapping_notify"); break; case ClientMessage: if (cast(Atom) ev.xclient.data.l[0] == wmDelete) { emit("close_requested via=WM_DELETE_WINDOW"); running = false; } break; default: break; } } if (
(local variable) const(bool) autoExit
autoExit
&&
long instrument.nowUs() nothrow @nogc

Microseconds elapsed since initInstrument.

nowUs
() > cast(long)
(local variable) const(int) durationMs
durationMs
* 1000)
{
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", "presses=%d releases=%d repeats=%d composed=%d "
~ "keymap_rebuilds=%d focused=%d",
(local variable) int presses
presses
,
(local variable) int releases
releases
,
(local variable) int repeats
repeats
,
(local variable) int composed
composed
,
(local variable) int rebuilds
rebuilds
, cast(int)
(local variable) bool focused
focused
);
if (compose !is null) xkb_compose_state_unref(compose);
undefined identifier `xkb_compose_state_unref`
if (composeTable !is null) xkb_compose_table_unref(composeTable);
undefined identifier `xkb_compose_table_unref`
xkb_state_unref(kbd.
kbd.state
state
);
undefined identifier `xkb_state_unref`
xkb_keymap_unref(kbd.
kbd.keymap
keymap
);
undefined identifier `xkb_keymap_unref`
xkb_context_unref(kbd.
kbd.ctx
ctx
);
undefined identifier `xkb_context_unref`
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; }