diff --git a/apps/mouse.cpp b/apps/mouse.cpp index 695a8470..d41aef4b 100644 --- a/apps/mouse.cpp +++ b/apps/mouse.cpp @@ -1,3 +1,4 @@ +#include #include #include @@ -11,6 +12,21 @@ Result luna_main(int, char**) moon::MousePacket packet; TRY(mouse->read_typed(packet)); - os::println("Mouse packet: xdelta=%d, ydelta=%d, buttons=%d", packet.xdelta, packet.ydelta, packet.buttons); + 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()); } }