I want to ensure the events are sent back via the opcode engine. Fx. clicks from button. We only have a gtk renderer right now, but it should generically be sent back via te opcode engine.
Assistant
Findings
Events already round-trip through the opcode engine today. The full path is in place and tested:
Encode/decode — pathland_opcode::Event → 16-byte EVENT-category opcode (events.rs), with Host::send_event writing to the host→guest event ring and Guest::drain_events decoding it back (lib.rs:466, :290).
Generic transport — the renderer doesn't touch GTK in the event path; it goes through the Pump trait (send_input/drain_events) → RingTransport (pathland-gtk/src/lib.rs:41-60).
Done. Events now return to the app purely through the opcode engine, generically across renderers.
What changed
Renderer emits raw pointer events (pathland-gtk/src/lib.rs): buttons now use GestureClick (down/up, real coords, secondary button) + EventControllerMotion (enter/move/leave hover), instead of connect_clicked → synthetic PointerUp{0,0}.
Renderer no longer drains events — it only writes EVENT opcodes via Pump::send_input and wakes the host (no payload). Pump::drain_events removed; run/run_with_pump/pump_once now wake-only.
Generic native C ABI (pathland-native/src/capi.rs): added pathland_native_drain_events(host, out, max) — drains the event ring and writes raw 16-byte opcodes, symmetric with . Plus a round-trip test.
User
When running the rust demo, click on the button does not increment the count
Assistant
I found the likely culprit. The old working code used connect_clicked; my rewrite switched to a GestureClick, which on GtkButton doesn't fire released (the button's internal exclusive gesture claims the click sequence). Let me revert the click path to the reliable connect_clicked while keeping hover via the motion controller.
Assistant
Fixed. The click path was switched from the reliable connect_clicked signal to a GestureClick, which doesn't observe released on a GtkButton (the button's own internal gesture claims the click sequence).
Changes in pathland-gtk/src/lib.rs:
Button activation is back on btn.connect_clicked → Event::PointerUp (proven path), keeping hover enter/move/leave via EventControllerMotion.
Removed the GestureClick import/usage.
The generic opcode-engine delivery is unchanged — click still flows connect_clicked → send_input (writes EVENT opcode) → wake → host drain_events. Verified cargo test green and cargo build --workspace clean.
Run cargo run -p pathland-gtk-demo and click "Increment" — it should now count up.
User
Commit
Assistant
Committed as 43a722d.
Event::PointerUp
Pump::send_input
pump_once
on_event
lib.rs:256-266
:408-411
Both demos consume events (Rust main.rs:73-78, Java GtkDemo.java:45-48).
Gaps (what "generically" is missing)
Native C ABI has no event drain.pathland-native exposes no pathland_native_drain_events — a foreign host (Java/Swift/C#) can only get events via the GTK renderer's callback, not by polling the ring/opcode engine.
The C callback is lossy + GTK-specific.pathland_gtk_run's EventCallback forwards only target_id (capi.rs:75-80), dropping event type/coordinates/flags.
Only clicks are wired. The GTK renderer maps only connect_clicked to a synthetic PointerUp { x:0.0, y:0.0 } — no pointer down/move/up, hover, or keys.
The core Rust path is correct; the work is making the foreign-host path go through the same generic opcode-engine event flow instead of a reduced GTK callback.
Before I write the detailed plan, two scope decisions:
Plan: generic event return via the opcode engine
Current state (verified)
Events already flow as 16-byte EVENT opcodes through the event ring end-to-end at the Rust core (Event::encode/try_from, Host::send_event, Guest::drain_events). What's missing is the generic delivery surface and raw-input breadth. Four changes close that gap.
A. Renderer emits real raw pointer events (pathland-gtk/src/lib.rs)
Replace the connect_clicked → synthetic PointerUp{0,0} mapping in build_widget with GTK4 controllers attached to the button, using real coordinates from event.position():
GestureClick (pressed → PointerDown, released → PointerUp, with secondary from button number)
target = the button's node id (per-widget controllers make hit-testing trivial). Same event_sink as today.
B. Renderer stops draining; host drains the ring (pathland-gtk/src/lib.rs)
Pump trait: drop drain_events (keep next_frame + send_input).
run / run_with_pump: change on_event from FnMut(Event, Rc<RefCell<P>>) to a wake-onlyFnMut(Rc<RefCell<P>>).
The event sink writes the opcode via send_input, then invokes the wake callback (no event data crosses the callback — data flows only through the ring).
pump_once: remove the drain_events + dispatch loop; pump frames only.
C. Expose generic event drain on the native C ABI (pathland-native)
capi.rs: add pathland_native_drain_events(host, out: *mut u8, max: u32) -> u32 — drains pending events, writes each as its raw 16-byte EVENT opcode into out (symmetric with ring_ptr; foreign hosts decode or forward).
GtkDemo.java: onEvent = () -> { drain into a buffer; decode each EVENT opcode; on PointerUp increment; render(); }.
Add a small EventReader (or extend RingReader) to decode the 16-byte layout [cat][cmd][flags:u16][A:u32][B:u32][C:u32].
F. Docs
AGENTS.md: note the event-drain C ABI + "host drains the ring, renderer only writes" model; update Status.
spec/OPCODE.md: no wire change; optional note on the drain API.
Verification
cd lib/rust && cargo test
Rebuild pathland-native + pathland-gtk, run Java demo with MAVEN_OPTS="-XstartOnFirstThread"; verify click → PointerUp round-trips via the ring and increments.
cargo run -p pathland-gtk-demo for the Rust path.
Notes / tradeoffs
The C ABI drain decodes-then-re-encodes (Vec<Event> → bytes); trivial for rare events. A zero-copy raw-opcode path is possible later if desired.
Window-level hit-testing (for arbitrary pointer events, not just button widgets) is deferred; per-widget controllers resolve target directly for now.
Want me to proceed with this plan, or adjust scope (e.g. skip the Rust-demo/Java-demo rewrite, or add window-level hit-testing)?
EVENT
ring_ptr
NativeHost
GTK C ABI (pathland-gtk/src/capi.rs): EventCallback is now extern "C" fn() (wake, no data).
Demos drain the ring themselves: Rust demo (main.rs) and Java demo (EventReader decode + GtkDemo), so no GTK-specific payload crosses the callback.
Verified: cargo test green across the workspace (incl. new native_host_round_trips_events_via_ring), cargo build -p pathland-native -p pathland-gtk and mvn compile clean.
To manually verify interactively: cargo run -p pathland-gtk-demo, or the Java demo with MAVEN_OPTS="-XstartOnFirstThread" mvn ... exec:java — clicking "Increment" should still bump the counter, now round-tripping via drain_events.