Add a display server and graphical user interface #38
@ -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);
|
||||
}
|
||||
close(fd);
|
||||
|
||||
if (p == MAP_FAILED) { return err(errno); }
|
||||
|
||||
Screen screen;
|
||||
|
||||
|
@ -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());
|
||||
|
Loading…
Reference in New Issue
Block a user