mouse: Show textual description of buttons
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
7983d63b8e
commit
d0ceec6952
@ -1,3 +1,4 @@
|
||||
#include <luna/String.h>
|
||||
#include <moon/Mouse.h>
|
||||
#include <os/File.h>
|
||||
|
||||
@ -11,6 +12,21 @@ Result<int> 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<StringView> 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());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user