diff --git a/wind/Screen.cpp b/wind/Screen.cpp index b44874ba..8d0e224c 100644 --- a/wind/Screen.cpp +++ b/wind/Screen.cpp @@ -7,18 +7,16 @@ Result 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); - } + close(fd); + + if (p == MAP_FAILED) { return err(errno); } Screen screen; diff --git a/wind/main.cpp b/wind/main.cpp index 318da9b9..bda0fa86 100644 --- a/wind/main.cpp +++ b/wind/main.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -40,6 +41,9 @@ Result 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 luna_main(int argc, char** argv) ui::Color background = ui::BLACK; + Vector> 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 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());