wind: Create a local server object
All checks were successful
continuous-integration/drone/pr Build is passing

This commit is contained in:
apio 2023-08-03 16:40:17 +02:00
parent c779ef84ef
commit 7a2acce8fd
Signed by: apio
GPG Key ID: B8A7D06E42258954
2 changed files with 18 additions and 7 deletions

View File

@ -7,18 +7,16 @@
Result<Screen> Screen::open()
{
int fd = ::open("/dev/fb0", O_RDWR | O_CLOEXEC);
int fd = ::open("/dev/fb0", O_RDWR);
if (fd < 0) return err(errno);
int width = ioctl(fd, FB_GET_WIDTH);
int height = ioctl(fd, FB_GET_HEIGHT);
void* p = mmap(nullptr, width * height * BYTES_PER_PIXEL, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (p == MAP_FAILED)
{
close(fd);
return err(errno);
}
if (p == MAP_FAILED) { return err(errno); }
Screen screen;

View File

@ -4,6 +4,7 @@
#include <moon/Keyboard.h>
#include <os/ArgumentParser.h>
#include <os/File.h>
#include <os/LocalServer.h>
#include <pwd.h>
#include <stdlib.h>
#include <string.h>
@ -40,6 +41,9 @@ Result<int> luna_main(int argc, char** argv)
auto screen = TRY(Screen::open());
auto server = TRY(os::LocalServer::create(socket_path, false));
TRY(server->listen(20));
Mouse mouse_pointer { screen.canvas() };
ioctl(STDIN_FILENO, TTYSETGFX, 1);
@ -67,14 +71,17 @@ Result<int> luna_main(int argc, char** argv)
ui::Color background = ui::BLACK;
Vector<SharedPtr<os::LocalServer::Client>> clients;
while (1)
{
struct pollfd fds[] = {
{ .fd = mouse->fd(), .events = POLLIN, .revents = 0 },
{ .fd = keyboard->fd(), .events = POLLIN, .revents = 0 },
{ .fd = server->fd(), .events = POLLIN, .revents = 0 },
};
int rc = poll(fds, 2, 1000);
int rc = poll(fds, 3, 1000);
if (!rc) continue;
if (rc < 0) { os::println("poll: error: %s", strerror(errno)); }
@ -90,6 +97,12 @@ Result<int> luna_main(int argc, char** argv)
TRY(keyboard->read_typed(packet));
background = ui::Color::from_rgb(0x00, 0x00, packet.key * 2);
}
if (fds[2].revents & POLLIN)
{
auto client = TRY(server->accept());
os::println("wind: New client connected!");
TRY(clients.try_append(client));
}
screen.canvas().fill(background);
mouse_pointer.draw(screen.canvas());