Skip to content

refactor(xcb): type-safe core event dispatch - #14

Merged
TheB1t merged 1 commit into
masterfrom
refactor/xcb-event-dispatch
Apr 16, 2026
Merged

refactor(xcb): type-safe core event dispatch#14
TheB1t merged 1 commit into
masterfrom
refactor/xcb-event-dispatch

Conversation

@TheB1t

@TheB1t TheB1t commented Apr 16, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add libxcb/include/xcb/event_dispatch.hpp: X-macro + EventTraits<T> + KnownEvent concept + dispatch_event(). Mirrors the MessageTraits pattern from libipc/message_dispatch.hpp.
  • Migrate X11Backend::handle_generic_event and XWindowManager::dispatch to use it; the big manual opcode switch is gone from both.
  • Release variants (KeyRelease/ButtonRelease/FocusOut/LeaveNotify) are routed to their press-struct handler via dedicated switch cases.
  • Add xcb::event_as<T> for typed casts from xcb_generic_event_t* in the motion/expose coalescer.

Notes

Each dispatch site uses a small adapter struct (X11EventHandler / XwmEventHandler) marked // TODO: temporary. The cleaner end state is to let the class itself satisfy the concept via on(xcb_*_t&), which is currently blocked by a name clash with Backend::on(event::...) virtuals (-Woverloaded-virtual).

Test plan

  • x11 build clean
  • wayland build clean (-DSIRENWM_BACKEND=wayland, wlserver target)
  • ctest green (core, runtime, modules)
  • Integration (Xephyr) — not run in this environment

🤖 Generated with Claude Code

Add libxcb/include/xcb/event_dispatch.hpp mirroring the
MessageTraits + X-macro pattern from libipc/message_dispatch.hpp:
one X-macro enumerates core X11 event structs and their opcodes,
EventTraits<T> exposes the opcode at compile time, and
dispatch_event() drives a single switch that routes to handler.on(T&)
overloads via a KnownEvent-constrained concept.

Migrate both consumers:
- X11Backend::handle_generic_event (backends/x11)
- XWindowManager::dispatch         (libwlserver/xwm)

Both use a thin adapter struct (X11EventHandler / XwmEventHandler)
that forwards typed events to existing handle_* methods, marked
TODO — the cleaner end state is to let the class itself satisfy
the dispatch concept, blocked by a name clash with
Backend::on(event::...) virtuals.

Also add event_as<T>() for intention-revealing casts from
xcb_generic_event_t* in loop.cpp's motion/expose coalescing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@TheB1t
TheB1t merged commit f205c92 into master Apr 16, 2026
31 of 34 checks passed
@TheB1t
TheB1t deleted the refactor/xcb-event-dispatch branch April 16, 2026 08:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant