wind: Create a local server object
This commit is contained in:
parent
b6fe96e364
commit
335911c287
@ -7,18 +7,16 @@
|
|||||||
|
|
||||||
Result<Screen> Screen::open()
|
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);
|
if (fd < 0) return err(errno);
|
||||||
|
|
||||||
int width = ioctl(fd, FB_GET_WIDTH);
|
int width = ioctl(fd, FB_GET_WIDTH);
|
||||||
int height = ioctl(fd, FB_GET_HEIGHT);
|
int height = ioctl(fd, FB_GET_HEIGHT);
|
||||||
|
|
||||||
void* p = mmap(nullptr, width * height * BYTES_PER_PIXEL, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
void* p = mmap(nullptr, width * height * BYTES_PER_PIXEL, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||||
if (p == MAP_FAILED)
|
close(fd);
|
||||||
{
|
|
||||||
close(fd);
|
if (p == MAP_FAILED) { return err(errno); }
|
||||||
return err(errno);
|
|
||||||
}
|
|
||||||
|
|
||||||
Screen screen;
|
Screen screen;
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include <moon/Keyboard.h>
|
#include <moon/Keyboard.h>
|
||||||
#include <os/ArgumentParser.h>
|
#include <os/ArgumentParser.h>
|
||||||
#include <os/File.h>
|
#include <os/File.h>
|
||||||
|
#include <os/LocalServer.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -40,6 +41,9 @@ Result<int> luna_main(int argc, char** argv)
|
|||||||
|
|
||||||
auto screen = TRY(Screen::open());
|
auto screen = TRY(Screen::open());
|
||||||
|
|
||||||
|
auto server = TRY(os::LocalServer::create(socket_path, false));
|
||||||
|
TRY(server->listen(20));
|
||||||
|
|
||||||
Mouse mouse_pointer { screen.canvas() };
|
Mouse mouse_pointer { screen.canvas() };
|
||||||
|
|
||||||
ioctl(STDIN_FILENO, TTYSETGFX, 1);
|
ioctl(STDIN_FILENO, TTYSETGFX, 1);
|
||||||
@ -67,14 +71,17 @@ Result<int> luna_main(int argc, char** argv)
|
|||||||
|
|
||||||
ui::Color background = ui::BLACK;
|
ui::Color background = ui::BLACK;
|
||||||
|
|
||||||
|
Vector<SharedPtr<os::LocalServer::Client>> clients;
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
struct pollfd fds[] = {
|
struct pollfd fds[] = {
|
||||||
{ .fd = mouse->fd(), .events = POLLIN, .revents = 0 },
|
{ .fd = mouse->fd(), .events = POLLIN, .revents = 0 },
|
||||||
{ .fd = keyboard->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) continue;
|
||||||
if (rc < 0) { os::println("poll: error: %s", strerror(errno)); }
|
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));
|
TRY(keyboard->read_typed(packet));
|
||||||
background = ui::Color::from_rgb(0x00, 0x00, packet.key * 2);
|
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);
|
screen.canvas().fill(background);
|
||||||
mouse_pointer.draw(screen.canvas());
|
mouse_pointer.draw(screen.canvas());
|
||||||
|
Loading…
Reference in New Issue
Block a user