#include #include #include Result luna_main(int, char**) { auto mouse = TRY(os::File::open("/dev/mouse", os::File::ReadOnly)); mouse->set_buffer(os::File::NotBuffered); while (1) { moon::MousePacket packet; TRY(mouse->read_typed(packet)); bool right = packet.buttons & moon::MouseButton::Right; bool left = packet.buttons & moon::MouseButton::Left; bool middle = packet.buttons & moon::MouseButton::Middle; Vector buttons; if (right) TRY(buttons.try_append("RIGHT"_sv)); if (left) TRY(buttons.try_append("LEFT"_sv)); if (middle) TRY(buttons.try_append("MIDDLE"_sv)); String button_string; if (!buttons.size()) button_string = TRY(String::from_cstring("NONE")); else button_string = TRY(String::join(buttons, " | "_sv)); os::println("Mouse packet: xdelta=%d, ydelta=%d, buttons=(%s)", packet.xdelta, packet.ydelta, button_string.chars()); } }