wind: Generate random windows on keypresses

This commit is contained in:
apio 2023-08-06 12:45:13 +02:00
parent 11e0025a5b
commit 3fefb74710
Signed by: apio
GPG Key ID: B8A7D06E42258954

View File

@ -11,10 +11,13 @@
#include <string.h> #include <string.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/poll.h> #include <sys/poll.h>
#include <time.h>
#include <unistd.h> #include <unistd.h>
Result<int> luna_main(int argc, char** argv) Result<int> luna_main(int argc, char** argv)
{ {
srand((unsigned)time(NULL));
StringView socket_path = "/tmp/wind.sock"; StringView socket_path = "/tmp/wind.sock";
StringView user; StringView user;
@ -105,7 +108,14 @@ Result<int> luna_main(int argc, char** argv)
{ {
moon::KeyboardPacket packet; moon::KeyboardPacket packet;
TRY(keyboard->read_typed(packet)); TRY(keyboard->read_typed(packet));
background = ui::Color::from_rgb(0x00, 0x00, packet.key * 2); if (!packet.released)
{
TRY(make<Window>(ui::Rect { rand() % screen.canvas().width, rand() % screen.canvas().height,
rand() % screen.canvas().width, rand() % screen.canvas().height },
ui::Color::from_rgb(static_cast<u8>(rand() % 256), static_cast<u8>(rand() % 256),
static_cast<u8>(rand() % 256)),
strerror(packet.key)));
}
} }
if (fds[2].revents & POLLIN) if (fds[2].revents & POLLIN)
{ {