Generalize input module to mouse and joystick/gamepad events
Extend the input service beyond the keyboard so mouse and joystick/gamepad drivers can broadcast too, with per-device publish and subscribe methods. - protocol: KeyEvent joins MouseEvent (motion/buttons/scroll) and JoystickEvent (axes/buttons), all carried in a common InputEvent envelope tagged with a DeviceKind. A subscribe request carries a device_mask, so a subscriber names the classes it wants and the service routes each event only to interested subscribers (a mouse-only listener never wakes for keystrokes). - runtime: per-device publish methods (publishKeyboardEvent/publishMouseEvent/ publishJoystickEvent) and subscribe helpers (subscribeKeyboard/Mouse/Joystick, each typed, plus subscribe(mask)/subscribeAll returning the tagged envelope). - service: subscriber table gains a device_mask; broadcast routes by the event's device class. - mouse driver now publishes (synthetic) mouse events like the keyboard driver; input-source cycles all three classes; input-test subscribes to all and only emits its "ok" marker once it has received one of each class — so the passing test proves per-device routing, not just delivery. Real HID decoding stays a follow-up. No kernel changes: ipc_send is generic and the 36-byte InputEvent fits its 64-byte payload. Full QEMU suite 48/48; serial log confirms keyboard, mouse, and joystick all reach one subscription.
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
//! system/services/input-test — the input service's client and test oracle, the input
|
||||
//! counterpart of vfs-test. It `subscribe`s to the input service, then loops receiving the
|
||||
//! events a source broadcasts. Once it has received at least one event it heartbeats
|
||||
//! `"input-test: ok"` (repeatedly), which the in-kernel `input` test case watches for on
|
||||
//! the serial log: seeing it proves an event travelled source -> service -> subscriber
|
||||
//! over IPC and arrived intact.
|
||||
//! counterpart of vfs-test. It subscribes to *all* device classes and loops receiving the
|
||||
//! events a source broadcasts, logging each with its class. It emits the success marker
|
||||
//! `"input-test: ok"` only **after it has received at least one of each class** (keyboard,
|
||||
//! mouse, and joystick), then heartbeats it. So the in-kernel `input` test case seeing that
|
||||
//! marker proves not just that IPC delivery works but that the service *routed* all three
|
||||
//! device classes to one subscription — source -> service -> subscriber, per device.
|
||||
|
||||
const std = @import("std");
|
||||
const runtime = @import("runtime");
|
||||
@@ -16,20 +17,36 @@ fn writeLine(comptime fmt: []const u8, arguments: anytype) void {
|
||||
}
|
||||
|
||||
pub fn main() void {
|
||||
var listener = input.subscribe() orelse {
|
||||
var listener = input.subscribeAll() orelse {
|
||||
_ = system.write("input-test: could not subscribe\n");
|
||||
return;
|
||||
};
|
||||
_ = system.write("input-test: subscribed\n");
|
||||
|
||||
var received: usize = 0;
|
||||
var seen_keyboard = false;
|
||||
var seen_mouse = false;
|
||||
var seen_joystick = false;
|
||||
while (true) {
|
||||
const event = listener.next() orelse continue;
|
||||
received += 1;
|
||||
// Report the round trip. The kernel test matches the "input-test: ok" prefix and
|
||||
// requires it to recur, so the source staying up keeps this beating.
|
||||
const kind: input.EventKind = @enumFromInt(event.kind);
|
||||
writeLine("input-test: ok received {d} last kind={s} code={d} char={d}\n", .{ received, @tagName(kind), event.keycode, event.character });
|
||||
// Decode the class-specific payload from the tagged envelope and note the class.
|
||||
if (event.asKeyboard()) |key| {
|
||||
seen_keyboard = true;
|
||||
writeLine("input-test: got keyboard code={d} char={d}\n", .{ key.keycode, key.character });
|
||||
} else if (event.asMouse()) |mouse| {
|
||||
seen_mouse = true;
|
||||
writeLine("input-test: got mouse dx={d} dy={d} buttons={d}\n", .{ mouse.dx, mouse.dy, mouse.buttons });
|
||||
} else if (event.asJoystick()) |joystick| {
|
||||
seen_joystick = true;
|
||||
writeLine("input-test: got joystick control={d} value={d}\n", .{ joystick.control, joystick.value });
|
||||
} else {
|
||||
writeLine("input-test: got device={d}\n", .{event.device});
|
||||
}
|
||||
|
||||
// The success marker: only once every class has been routed here does this appear,
|
||||
// and then it heartbeats. Seeing "input-test: ok" proves per-device fan-out works.
|
||||
if (seen_keyboard and seen_mouse and seen_joystick) {
|
||||
_ = system.write("input-test: ok all classes received (keyboard, mouse, joystick)\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user