Compare commits

..

1 Commits

Author SHA1 Message Date
b52434339f Rework rendering 2026-06-07 20:39:23 +03:00
4 changed files with 126 additions and 181 deletions

View File

@@ -1,20 +1,20 @@
From e71364497354b511159bf3d883b0e6168f430187 Mon Sep 17 00:00:00 2001
From c9dd87198ce5262e6ddf6bf3b0c18eb84784d35e Mon Sep 17 00:00:00 2001
From: Oskari Alaranta <oskari.alaranta@bananymous.com>
Date: Tue, 7 Jul 2026 05:04:45 +0300
Date: Wed, 15 Apr 2026 17:52:54 +0300
Subject: [PATCH] linux-window-server-sdl2
---
userspace/libraries/LibGUI/Widget/Widget.cpp | 2 +-
userspace/libraries/LibGUI/Window.cpp | 11 +-
userspace/libraries/LibGUI/Window.cpp | 9 +-
userspace/programs/ProgramLauncher/main.cpp | 2 +-
userspace/programs/Terminal/Terminal.cpp | 10 +-
userspace/programs/Terminal/Terminal.cpp | 4 +-
.../programs/WindowServer/CMakeLists.txt | 3 +
.../programs/WindowServer/Framebuffer.cpp | 52 +--
userspace/programs/WindowServer/Window.cpp | 29 +-
.../programs/WindowServer/WindowServer.cpp | 47 ++-
.../programs/WindowServer/WindowServer.h | 1 +
userspace/programs/WindowServer/main.cpp | 357 ++++++++++++------
10 files changed, 345 insertions(+), 169 deletions(-)
10 files changed, 340 insertions(+), 166 deletions(-)
diff --git a/userspace/libraries/LibGUI/Widget/Widget.cpp b/userspace/libraries/LibGUI/Widget/Widget.cpp
index d6489d87..c532fb04 100644
@@ -30,7 +30,7 @@ index d6489d87..c532fb04 100644
}
diff --git a/userspace/libraries/LibGUI/Window.cpp b/userspace/libraries/LibGUI/Window.cpp
index 607421eb..d8aeee7e 100644
index b4172f70..3a0e9cca 100644
--- a/userspace/libraries/LibGUI/Window.cpp
+++ b/userspace/libraries/LibGUI/Window.cpp
@@ -4,9 +4,8 @@
@@ -44,7 +44,7 @@ index 607421eb..d8aeee7e 100644
#include <sys/socket.h>
#include <sys/un.h>
#include <time.h>
@@ -311,23 +310,23 @@ namespace LibGUI
@@ -271,7 +270,7 @@ namespace LibGUI
void Window::cleanup()
{
@@ -53,25 +53,24 @@ index 607421eb..d8aeee7e 100644
close(m_server_fd);
close(m_epoll_fd);
}
BAN::ErrorOr<bool> Window::handle_resize_event(const EventPacket::ResizeWindowEvent& event)
@@ -279,7 +278,7 @@ namespace LibGUI
BAN::ErrorOr<void> Window::handle_resize_event(const EventPacket::ResizeWindowEvent& event)
{
- void* framebuffer_addr = smo_map(event.smo_key);
+ void* framebuffer_addr = shmat(event.smo_key, nullptr, 0);
if (framebuffer_addr == nullptr)
{
- if (errno == ENOENT)
+ if (errno == EINVAL)
return false;
return BAN::Error::from_errno(errno);
}
if (m_framebuffer_smo)
- munmap(m_framebuffer_smo, m_width * m_height * 4);
+ shmdt(m_framebuffer_smo);
m_framebuffer_smo = nullptr;
TRY(m_texture.resize(event.width, event.height));
@@ -287,7 +286,7 @@ namespace LibGUI
if (m_root_widget)
TRY(m_root_widget->set_fixed_geometry({ 0, 0, event.width, event.height }));
- void* framebuffer_addr = smo_map(event.smo_key);
+ void* framebuffer_addr = shmat(event.smo_key, nullptr, 0);
if (framebuffer_addr == nullptr)
return BAN::Error::from_errno(errno);
diff --git a/userspace/programs/ProgramLauncher/main.cpp b/userspace/programs/ProgramLauncher/main.cpp
index c833c582..0e1cc460 100644
--- a/userspace/programs/ProgramLauncher/main.cpp
@@ -86,18 +85,10 @@ index c833c582..0e1cc460 100644
const auto full_program_list = get_program_list();
diff --git a/userspace/programs/Terminal/Terminal.cpp b/userspace/programs/Terminal/Terminal.cpp
index c470438d..709db432 100644
index e1bd317d..8a6b5bd0 100644
--- a/userspace/programs/Terminal/Terminal.cpp
+++ b/userspace/programs/Terminal/Terminal.cpp
@@ -9,6 +9,7 @@
#include <fcntl.h>
#include <signal.h>
#include <stdlib.h>
+#include <sys/ioctl.h>
#include <sys/select.h>
#include <termios.h>
#include <time.h>
@@ -92,7 +93,7 @@ void Terminal::start_shell()
@@ -92,7 +92,7 @@ void Terminal::start_shell()
close(pts_slave);
close(pts_master);
@@ -106,7 +97,7 @@ index c470438d..709db432 100644
exit(1);
}
@@ -127,7 +128,7 @@ void Terminal::run()
@@ -127,7 +127,7 @@ void Terminal::run()
m_window->texture().set_bg_color(m_bg_color);
m_window->invalidate();
@@ -115,25 +106,6 @@ index c470438d..709db432 100644
m_window->set_min_size(m_font.width() * 8, m_font.height() * 2);
@@ -147,7 +148,8 @@ void Terminal::run()
.ws_xpixel = static_cast<unsigned short>(m_window->width()),
.ws_ypixel = static_cast<unsigned short>(m_window->height()),
};
- if (tcsetwinsize(m_shell_info.pts_master, &winsize) == -1)
+
+ if (ioctl(m_shell_info.pts_master, TIOCSWINSZ, &winsize) == -1)
perror("tcsetwinsize");
}
@@ -212,7 +214,7 @@ void Terminal::run()
.ws_xpixel = static_cast<unsigned short>(m_window->width()),
.ws_ypixel = static_cast<unsigned short>(m_window->height()),
};
- if (tcsetwinsize(m_shell_info.pts_master, &winsize) == -1)
+ if (ioctl(m_shell_info.pts_master, TIOCSWINSZ, &winsize) == -1)
perror("tcsetwinsize");
});
diff --git a/userspace/programs/WindowServer/CMakeLists.txt b/userspace/programs/WindowServer/CMakeLists.txt
index 8fdf79f9..fcaf441d 100644
--- a/userspace/programs/WindowServer/CMakeLists.txt
@@ -227,7 +199,7 @@ index 0e727e8f..119f1451 100644
return framebuffer;
}
diff --git a/userspace/programs/WindowServer/Window.cpp b/userspace/programs/WindowServer/Window.cpp
index 78de89c9..c5405695 100644
index 1e66f522..9759eec9 100644
--- a/userspace/programs/WindowServer/Window.cpp
+++ b/userspace/programs/WindowServer/Window.cpp
@@ -5,15 +5,14 @@
@@ -249,7 +221,7 @@ index 78de89c9..c5405695 100644
LibGUI::EventPacket::DestroyWindowEvent packet;
@@ -45,16 +44,16 @@ BAN::ErrorOr<void> Window::resize(uint32_t width, uint32_t height)
@@ -47,16 +46,16 @@ BAN::ErrorOr<void> Window::resize(uint32_t width, uint32_t height)
{
const size_t fb_bytes = width * height * 4;
@@ -272,7 +244,7 @@ index 78de89c9..c5405695 100644
{
const auto old_area = m_client_area;
@@ -68,16 +67,14 @@ BAN::ErrorOr<void> Window::resize(uint32_t width, uint32_t height)
@@ -70,16 +69,14 @@ BAN::ErrorOr<void> Window::resize(uint32_t width, uint32_t height)
return title_bar_ret.release_error();
}
@@ -294,7 +266,7 @@ index 78de89c9..c5405695 100644
m_client_area.max_x = m_client_area.min_x + width;
m_client_area.max_y = m_client_area.min_y + height;
diff --git a/userspace/programs/WindowServer/WindowServer.cpp b/userspace/programs/WindowServer/WindowServer.cpp
index e6b01476..a14074c3 100644
index 2c67d6c0..600704fd 100644
--- a/userspace/programs/WindowServer/WindowServer.cpp
+++ b/userspace/programs/WindowServer/WindowServer.cpp
@@ -8,19 +8,20 @@
@@ -323,16 +295,16 @@ index e6b01476..a14074c3 100644
{
MUST(m_background_image.resize(m_framebuffer.width * m_framebuffer.height, 0xFF101010));
@@ -512,7 +513,7 @@ static void update_volume(const char* new_volume)
@@ -440,7 +441,7 @@ static void update_volume(const char* new_volume)
void WindowServer::on_key_event(LibInput::KeyEvent event)
{
- if (event.key == LibInput::Key::LeftSuper)
- if (event.key == LibInput::Key::Super)
+ if (event.key == LibInput::Key::RightCtrl)
m_is_mod_key_held = event.pressed();
if (event.pressed() && event.key == LibInput::Key::VolumeDown)
@@ -533,7 +534,7 @@ void WindowServer::on_key_event(LibInput::KeyEvent event)
@@ -461,7 +462,7 @@ void WindowServer::on_key_event(LibInput::KeyEvent event)
pid_t pid = fork();
if (pid == 0)
{
@@ -341,7 +313,7 @@ index e6b01476..a14074c3 100644
exit(1);
}
if (pid == -1)
@@ -547,7 +548,7 @@ void WindowServer::on_key_event(LibInput::KeyEvent event)
@@ -475,7 +476,7 @@ void WindowServer::on_key_event(LibInput::KeyEvent event)
pid_t pid = fork();
if (pid == 0)
{
@@ -350,7 +322,7 @@ index e6b01476..a14074c3 100644
exit(1);
}
if (pid == -1)
@@ -1664,16 +1665,34 @@ void WindowServer::sync()
@@ -1599,16 +1600,34 @@ void WindowServer::sync()
for (size_t i = 0; i < m_damaged_area_count; i++)
{
@@ -392,10 +364,10 @@ index e6b01476..a14074c3 100644
Rectangle WindowServer::cursor_area() const
diff --git a/userspace/programs/WindowServer/WindowServer.h b/userspace/programs/WindowServer/WindowServer.h
index 9e2dc70e..40813f2e 100644
index 94fbc774..bcd7a6b9 100644
--- a/userspace/programs/WindowServer/WindowServer.h
+++ b/userspace/programs/WindowServer/WindowServer.h
@@ -65,6 +65,7 @@ public:
@@ -62,6 +62,7 @@ public:
bool is_damaged() const { return m_damaged_area_count > 0 || m_is_bouncing_window; }
bool is_stopped() const { return m_is_stopped; }
@@ -404,7 +376,7 @@ index 9e2dc70e..40813f2e 100644
private:
void on_mouse_move_impl(int32_t new_x, int32_t new_y);
diff --git a/userspace/programs/WindowServer/main.cpp b/userspace/programs/WindowServer/main.cpp
index 61d10e97..e77e5d97 100644
index 46f2ba6d..520c8e7d 100644
--- a/userspace/programs/WindowServer/main.cpp
+++ b/userspace/programs/WindowServer/main.cpp
@@ -10,7 +10,6 @@
@@ -546,7 +518,7 @@ index 61d10e97..e77e5d97 100644
if (epoll_events == -1 && errno != EINTR)
{
dwarnln("epoll_pwait2: {}", strerror(errno));
@@ -334,48 +289,6 @@ int main()
@@ -333,48 +288,6 @@ int main()
continue;
}
@@ -595,7 +567,7 @@ index 61d10e97..e77e5d97 100644
const int client_fd = events[i].data.fd;
if (events[i].events & (EPOLLHUP | EPOLLERR))
{
@@ -507,3 +420,237 @@ int main()
@@ -500,3 +413,237 @@ int main()
}
}
}
@@ -834,5 +806,5 @@ index 61d10e97..e77e5d97 100644
+ }
+}
--
2.54.0
2.53.0

View File

@@ -309,16 +309,25 @@ static void invalidate_window_recursive(Object::Window& dst_window, int32_t dst_
ASSERT(dst_x + w <= dst_window.width);
ASSERT(dst_y + h <= dst_window.height);
for (int32_t y = 0; y < h; y++)
if (&dst_window == &src_window)
{
uint32_t* dst_u32 = &dst_window.double_buffer[(dst_y + y) * dst_window.width + dst_x];
const uint32_t* src_u32 = &src_window. pixels[(src_y + y) * src_window.width + src_x];
for (int32_t x = 0; x < w; x++)
for (int32_t y = 0; y < h; y++)
{
if (src_u32[x] != COLOR_INVISIBLE)
dst_u32[x] = 0xFF000000 | src_u32[x];
else if (&dst_window == &src_window)
dst_u32[x] = 0x00000000;
uint32_t* dst_u32 = &dst_window.double_buffer[(dst_y + y) * dst_window.width + dst_x];
const uint32_t* src_u32 = &src_window. pixels[(src_y + y) * src_window.width + src_x];
for (int32_t x = 0; x < w; x++)
dst_u32[x] = (src_u32[x] != COLOR_INVISIBLE) ? src_u32[x] : 0x00000000;
}
}
else
{
for (int32_t y = 0; y < h; y++)
{
uint32_t* dst_u32 = &dst_window.double_buffer[(dst_y + y) * dst_window.width + dst_x];
const uint32_t* src_u32 = &src_window. pixels[(src_y + y) * src_window.width + src_x];
for (int32_t x = 0; x < w; x++)
if (src_u32[x] != COLOR_INVISIBLE)
dst_u32[x] = 0xFF000000 | src_u32[x];
}
}
}
@@ -750,7 +759,7 @@ void update_cursor(WINDOW wid, int32_t x, int32_t y)
if (wid == None)
return;
const CURSOR cid = [](WINDOW wid) -> CURSOR {
const CURSOR cid = [&wid]() -> CURSOR {
for (;;)
{
const auto& window = g_objects[wid]->object.get<Object::Window>();
@@ -758,7 +767,7 @@ void update_cursor(WINDOW wid, int32_t x, int32_t y)
return window.cursor;
wid = window.parent;
}
}(wid);
}();
static CURSOR active_cid = None;
if (cid == active_cid)
@@ -856,8 +865,8 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
dprintln("CreateWindow");
dprintln(" depth: {}", request.depth);
dprintln(" wid: {h}", request.wid);
dprintln(" parent: {h}", request.parent);
dprintln(" wid: {}", request.wid);
dprintln(" parent: {}", request.parent);
dprintln(" x: {}", request.x);
dprintln(" y: {}", request.y);
dprintln(" width: {}", request.width);
@@ -983,7 +992,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
auto request = decode<xChangeWindowAttributesReq>(packet).value();
dprintln("ChangeWindowAttributes");
dprintln(" window: {h}", request.window);
dprintln(" window: {}", request.window);
dprintln(" valueMask: {8h}", request.valueMask);
auto& window = TRY_REF(get_window(client_info, request.window, opcode));
@@ -1042,7 +1051,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
const CARD32 wid = packet.as_span<const uint32_t>()[1];
dprintln("GetWindowAttributes");
dprintln(" window: {h}", wid);
dprintln(" window: {}", wid);
const auto& window = TRY_REF(get_window(client_info, wid, opcode));
@@ -1079,7 +1088,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
const CARD32 wid = packet.as_span<const uint32_t>()[1];
dprintln("DestroyWinow");
dprintln(" window: {h}", wid);
dprintln(" window: {}", wid);
(void)TRY_REF(get_window(client_info, wid, opcode));
TRY(destroy_window(client_info, wid));
@@ -1091,8 +1100,8 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
auto request = decode<xReparentWindowReq>(packet).value();
dprintln("ReparentWinow");
dprintln(" window: {h}", request.window);
dprintln(" parent: {h}", request.parent);
dprintln(" window: {}", request.window);
dprintln(" parent: {}", request.parent);
dprintln(" x: {}", request.x);
dprintln(" y: {}", request.y);
@@ -1162,7 +1171,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
const CARD32 wid = packet.as_span<const uint32_t>()[1];
dprintln("MapWindow");
dprintln(" window: {h}", wid);
dprintln(" window: {}", wid);
(void)TRY_REF(get_window(client_info, wid, opcode));
TRY(map_window(client_info, wid));
@@ -1174,7 +1183,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
const CARD32 wid = packet.as_span<const uint32_t>()[1];
dprintln("MapSubwindows");
dprintln(" window: {h}", wid);
dprintln(" window: {}", wid);
const auto& window = TRY_REF(get_window(client_info, wid, opcode));
for (auto child_wid : window.children)
@@ -1187,7 +1196,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
const CARD32 wid = packet.as_span<const uint32_t>()[1];
dprintln("UnmapWindow");
dprintln(" window: {h}", wid);
dprintln(" window: {}", wid);
(void)TRY_REF(get_window(client_info, wid, opcode));
TRY(unmap_window(client_info, wid));
@@ -1199,7 +1208,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
const CARD32 wid = packet.as_span<const uint32_t>()[1];
dprintln("UnmapSubwindows");
dprintln(" window: {h}", wid);
dprintln(" window: {}", wid);
const auto& window = TRY_REF(get_window(client_info, wid, opcode));
for (auto child_wid : window.children)
@@ -1212,7 +1221,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
auto request = decode<xConfigureWindowReq>(packet).value();
dprintln("ConfigureWindow");
dprintln(" window: {h}", request.window);
dprintln(" window: {}", request.window);
dprintln(" mask: {4h}", request.mask);
auto& window = TRY_REF(get_window(client_info, request.window, opcode));
@@ -1304,7 +1313,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
const CARD32 drawable_id = packet.as_span<const uint32_t>()[1];
dprintln("GetGeometry");
dprintln(" drawable: {h}", drawable_id);
dprintln(" drawable: {}", drawable_id);
auto it = g_objects.find(drawable_id);
if (it == g_objects.end() || (it->value->type != Object::Type::Window && it->value->type != Object::Type::Pixmap))
@@ -1371,7 +1380,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
const auto wid = packet.as_span<const CARD32>()[1];
dprintln("QueryTree");
dprintln(" window: {h}", wid);
dprintln(" window: {}", wid);
const auto& window = TRY_REF(get_window(client_info, wid, opcode));
@@ -1455,7 +1464,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
dprintln("ChangeProperty");
dprintln(" mode: {}", request.mode);
dprintln(" window: {h}", request.window);
dprintln(" window: {}", request.window);
dprintln(" property: {}", g_atoms_id_to_name[request.property]);
dprintln(" type: {}", g_atoms_id_to_name[request.type]);
dprintln(" format: {}", request.format);
@@ -1520,7 +1529,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
auto request = decode<xDeletePropertyReq>(packet).value();
dprintln("DeleteProperty");
dprintln(" window: {h}", request.window);
dprintln(" window: {}", request.window);
dprintln(" property: {}", g_atoms_id_to_name[request.property]);
auto& window = TRY_REF(get_window(client_info, request.window, opcode));
@@ -1550,7 +1559,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
dprintln("GetProperty");
dprintln(" c_delete: {}", request.c_delete);
dprintln(" window: {h}", request.window);
dprintln(" window: {}", request.window);
dprintln(" property: {}", g_atoms_id_to_name[request.property]);
dprintln(" type: {}", request.type);
dprintln(" longOffset: {}", request.longOffset);
@@ -1633,7 +1642,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
const CARD32 wid = packet.as_span<const uint32_t>()[1];
dprintln("ListProperties");
dprintln(" window: {h}", wid);
dprintln(" window: {}", wid);
const auto& window = TRY_REF(get_window(client_info, wid, opcode));
@@ -1657,7 +1666,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
auto request = decode<xSetSelectionOwnerReq>(packet).value();
dprintln("SetSelectionOwner");
dprintln(" window: {h}", request.window);
dprintln(" window: {}", request.window);
dprintln(" selection: {}", g_atoms_id_to_name[request.selection]);
dprintln(" time: {}", request.time);
@@ -1713,7 +1722,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
auto request = decode<xConvertSelectionReq>(packet).value();
dprintln("ConvertSelection");
dprintln(" requestor: {h}", request.requestor);
dprintln(" requestor: {}", request.requestor);
dprintln(" selection: {}", get_atom_name_safe(request.selection));
dprintln(" target: {}", get_atom_name_safe(request.target));
dprintln(" property: {}", get_atom_name_safe(request.property));
@@ -1800,8 +1809,8 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
dprintln("GrabPointer");
dprintln(" ownerEvents: {}", request.ownerEvents);
dprintln(" grabWindow: {h}", request.grabWindow);
dprintln(" eventMask: {h}", request.eventMask);
dprintln(" grabWindow: {}", request.grabWindow);
dprintln(" eventMask: {}", request.eventMask);
dprintln(" pointerMode: {}", request.pointerMode);
dprintln(" keyboardMode: {}", request.keyboardMode);
dprintln(" confineTo: {}", request.confineTo);
@@ -1867,7 +1876,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
dprintln("GrabKeyboard");
dprintln(" ownerEvents: {}", request.ownerEvents);
dprintln(" grabWindow: {h}", request.grabWindow);
dprintln(" grabWindow: {}", request.grabWindow);
dprintln(" pointerMode: {}", request.pointerMode);
dprintln(" keyboardMode: {}", request.keyboardMode);
dprintln(" time: {}", request.time);
@@ -1942,7 +1951,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
const CARD32 wid = packet.as_span<const uint32_t>()[1];
dprintln("QueryPointer");
dprintln(" window: {h}", wid);
dprintln(" window: {}", wid);
const auto& window = TRY_REF(get_window(client_info, wid, opcode));
@@ -1989,8 +1998,8 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
auto request = decode<xTranslateCoordsReq>(packet).value();
dprintln("TranslateCoords");
dprintln(" src_wid: {h}", request.srcWid);
dprintln(" dst_wid: {h}", request.dstWid);
dprintln(" src_wid: {}", request.srcWid);
dprintln(" dst_wid: {}", request.dstWid);
dprintln(" src_x: {}", request.srcX);
dprintln(" src_y: {}", request.srcY);
@@ -2018,12 +2027,12 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
auto request = decode<xWarpPointerReq>(packet).value();
dprintln("WarpPointer");
dprintln(" src_wid: {h}", request.srcWid);
dprintln(" src_wid: {}", request.srcWid);
dprintln(" src_x: {}", request.srcX);
dprintln(" src_y: {}", request.srcY);
dprintln(" src_w: {}", request.srcWidth);
dprintln(" src_h: {}", request.srcHeight);
dprintln(" dst_wid: {h}", request.dstWid);
dprintln(" dst_wid: {}", request.dstWid);
dprintln(" dst_x: {}", request.dstX);
dprintln(" dst_y: {}", request.dstY);
@@ -2093,8 +2102,8 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
dprintln("CreatePixmap");
dprintln(" depth: {}", request.depth);
dprintln(" pid: {h}", request.pid);
dprintln(" drawable: {h}", request.drawable);
dprintln(" pid: {}", request.pid);
dprintln(" drawable: {}", request.drawable);
dprintln(" width: {}", request.width);
dprintln(" height: {}", request.height);
@@ -2128,7 +2137,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
const CARD32 pid = packet.as_span<const uint32_t>()[1];
dprintln("FreePixmap");
dprintln(" pixmap: {h}", pid);
dprintln(" pixmap: {}", pid);
(void)TRY_REF(get_pixmap(client_info, pid, opcode));
client_info.objects.remove(pid);
@@ -2141,7 +2150,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
auto request = decode<xCreateGCReq>(packet).value();
dprintln("CreateGC");
dprintln(" drawable {h}", request.drawable);
dprintln(" drawable {}", request.drawable);
dprintln(" gc {}", request.gc);
dprintln(" mask {8h}", request.mask);
@@ -2223,7 +2232,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
auto request = decode<xChangeGCReq>(packet).value();
dprintln("ChangeGC");
dprintln(" gc: {h}", request.gc);
dprintln(" gc: {}", request.gc);
dprintln(" mask: {8h}", request.mask);
auto& object = *g_objects[request.gc];
@@ -2287,7 +2296,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
auto request = decode<xSetClipRectanglesReq>(packet).value();
dprintln("SetClipRectangles");
dprintln(" gc: {h}", request.gc);
dprintln(" gc: {}", request.gc);
dprintln(" ordering: {}", request.ordering);
dprintln(" xOrigin: {}", request.xOrigin);
dprintln(" yOrigin: {}", request.yOrigin);
@@ -2315,7 +2324,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
const CARD32 gc = packet.as_span<const uint32_t>()[1];
dprintln("FreeGC");
dprintln(" gc: {h}", gc);
dprintln(" gc: {}", gc);
(void)TRY_REF(get_gc(client_info, gc, opcode));
client_info.objects.remove(gc);
@@ -2329,7 +2338,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
dprintln("ClearArea");
dprintln(" exposures: {}", request.exposures);
dprintln(" window: {h}", request.window);
dprintln(" window: {}", request.window);
dprintln(" x: {}", request.x);
dprintln(" y: {}", request.y);
dprintln(" width: {}", request.width);
@@ -2363,9 +2372,9 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
auto request = decode<xCopyAreaReq>(packet).value();
dprintln("CopyArea");
dprintln(" srcDrawable: {h}", request.srcDrawable);
dprintln(" dstDrawable: {h}", request.dstDrawable);
dprintln(" gc: {h}", request.gc);
dprintln(" srcDrawable: {}", request.srcDrawable);
dprintln(" dstDrawable: {}", request.dstDrawable);
dprintln(" gc: {}", request.gc);
dprintln(" srcX: {}", request.srcX);
dprintln(" srcY: {}", request.srcY);
dprintln(" dstX: {}", request.dstX);
@@ -2458,8 +2467,8 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
auto request = decode<xPutImageReq>(packet).value();
dprintln("PutImage");
dprintln(" drawable: {h}", request.drawable);
dprintln(" gc: {h}", request.gc);
dprintln(" drawable: {}", request.drawable);
dprintln(" gc: {}", request.gc);
dprintln(" format: {}", request.format);
dprintln(" depth: {}", request.depth);
dprintln(" dstX: {}", request.dstX);
@@ -2507,7 +2516,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
auto request = decode<xGetImageReq>(packet).value();
dprintln("GetImage");
dprintln(" drawable: {h}", request.drawable);
dprintln(" drawable: {}", request.drawable);
dprintln(" format: {}", request.format);
dprintln(" x: {}", request.x);
dprintln(" y: {}", request.y);
@@ -2678,7 +2687,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
auto request = decode<xCreateCursorReq>(packet).value();
dprintln("CreateCursor");
dprintln(" cid: {h}", request.cid);
dprintln(" cid: {}", request.cid);
dprintln(" source: {}", request.source);
dprintln(" mask: {}", request.mask);
dprintln(" foreRed: {}", request.foreRed);
@@ -2749,7 +2758,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
const auto cid = packet.as_span<const uint32_t>()[1];
dprintln("FreeCursor");
dprintln(" cid: {h}", cid);
dprintln(" cid: {}", cid);
client_info.objects.remove(cid);
g_objects.remove(cid);
@@ -2762,7 +2771,7 @@ BAN::ErrorOr<void> handle_packet(Client& client_info, BAN::ConstByteSpan packet)
dprintln("QueryBestSize");
dprintln(" class: {}", request.c_class);
dprintln(" drawable: {h}", request.drawable);
dprintln(" drawable: {}", request.drawable);
dprintln(" width: {}", request.width);
dprintln(" height: {}", request.height);

View File

@@ -26,8 +26,6 @@ struct BananCursor final : public PlatformCursor
int32_t origin_y;
};
static BAN::UniqPtr<LibGUI::Window> s_dummy_window;
static BAN::ErrorOr<void> bananos_initialize_keymap();
static bool bananos_initialize()
@@ -42,9 +40,7 @@ static bool bananos_initialize()
return false;
}
s_dummy_window = dummy_or_error.release_value();
register_display(0, 0, s_dummy_window->width(), s_dummy_window->height());
register_display(0, 0, dummy_or_error.value()->width(), dummy_or_error.value()->height());
if (auto ret = bananos_initialize_keymap(); ret.is_error())
{
@@ -76,9 +72,6 @@ static BAN::ErrorOr<BAN::UniqPtr<PlatformWindow>> bananos_create_window(WindowTy
auto gui_window = TRY(LibGUI::Window::create(width, height, ""_sv, attributes));
auto* winp = gui_window.ptr();
if (x != 0 || y != 0)
gui_window->set_position(x, y);
gui_window->set_close_window_event_callback([wid] {
on_window_close_event(wid);
});
@@ -91,9 +84,6 @@ static BAN::ErrorOr<BAN::UniqPtr<PlatformWindow>> bananos_create_window(WindowTy
gui_window->set_window_fullscreen_event_callback([wid](auto event) {
on_window_fullscreen_event(wid, event.fullscreen);
});
gui_window->set_window_move_event_callback([wid](auto event) {
on_window_move_event(wid, event.x, event.y);
});
gui_window->set_mouse_move_event_callback([wid](auto event) {
on_mouse_move_event(wid, event.x, event.y);
});
@@ -140,12 +130,6 @@ static void bananos_request_resize(PlatformWindow* window, uint32_t width, uint3
banan_window.window->request_resize(width, height);
}
static void bananos_request_reposition(PlatformWindow* window, int32_t x, int32_t y)
{
auto& banan_window = *static_cast<BananWindow*>(window);
banan_window.window->set_position(x, y);
}
static void bananos_invalidate(PlatformWindow* window, const void* src_pixels, uint32_t src_pitch, uint32_t x, uint32_t y, uint32_t width, uint32_t height)
{
auto& banan_window = *static_cast<BananWindow*>(window);
@@ -176,26 +160,6 @@ static void bananos_request_fullscreen(PlatformWindow* window, bool fullscreen)
banan_window.window->set_fullscreen(fullscreen);
}
static void bananos_query_ponter(int32_t* x, int32_t* y)
{
s_dummy_window->query_cursor_position();
bool queried { false };
s_dummy_window->set_query_pointer_event_callback([&](auto event) {
*x = event.x;
*y = event.y;
queried = true;
});
while (!queried)
{
s_dummy_window->wait_events();
s_dummy_window->poll_events();
}
s_dummy_window->set_query_pointer_event_callback({});
}
static BAN::ErrorOr<BAN::UniqPtr<PlatformCursor>> bananos_create_bitmap_cursor(const uint32_t* pixels, uint32_t width, uint32_t height, int32_t origin_x, int32_t origin_y)
{
auto cursor = TRY(BAN::UniqPtr<BananCursor>::create());
@@ -233,10 +197,10 @@ PlatformOps g_platform_ops = {
.begin_frame = nullptr,
.end_frame = bananos_end_frame,
.request_resize = bananos_request_resize,
.request_reposition = bananos_request_reposition,
.request_reposition = nullptr,
.request_fullscreen = bananos_request_fullscreen,
.warp_pointer = nullptr,
.query_pointer = bananos_query_ponter,
.query_pointer = nullptr,
.set_pointer_grab = nullptr,
.create_system_cursor = nullptr,
.create_bitmap_cursor = bananos_create_bitmap_cursor,
@@ -246,27 +210,29 @@ PlatformOps g_platform_ops = {
#include <LibInput/KeyboardLayout.h>
#include <LibInput/KeyEvent.h>
static uint32_t bananos_keyevent_to_x_keysym(LibInput::KeyEvent event);
static uint32_t bananos_key_to_x_keysym(LibInput::Key, bool upper);
static BAN::ErrorOr<void> bananos_initialize_keymap()
{
static constexpr uint16_t modifier_map[] {
0,
LibInput::KeyEvent::LShift,
LibInput::KeyEvent::RAlt,
LibInput::KeyEvent::RAlt | LibInput::KeyEvent::LShift,
};
// FIXME: get this from somewhere (gui command? enviroment? tmp file?)
const auto keymap_path = "./us.keymap"_sv;
TRY(LibInput::KeyboardLayout::initialize());
auto& keyboard_layout = LibInput::KeyboardLayout::get();
TRY(keyboard_layout.load_from_file(keymap_path));
for (uint8_t scancode = 0; scancode < g_keymap_size; scancode++)
const BAN::Span<const LibInput::Key> banan_keymaps[] {
keyboard_layout.keymap_normal(),
keyboard_layout.keymap_shift(),
keyboard_layout.keymap_altgr(),
keyboard_layout.keymap_altgr(), // add shift+altgr map?
};
for (size_t scancode = 0; scancode < g_keymap_size; scancode++)
for (size_t layer = 0; layer < g_keymap_layers; layer++)
if (const auto event = keyboard_layout.key_event_from_raw({ .modifier = modifier_map[layer], .keycode = scancode }); event.key != LibInput::Key::None)
g_keymap[scancode][layer] = bananos_keyevent_to_x_keysym(event);
if (const auto banan_key = banan_keymaps[layer][scancode]; banan_key != LibInput::Key::None)
g_keymap[scancode][layer] = bananos_key_to_x_keysym(banan_key, layer % 2);
using LibInput::keycode_normal;
using LibInput::keycode_numpad;
@@ -301,22 +267,22 @@ static BAN::ErrorOr<void> bananos_initialize_keymap()
#include <wctype.h>
static uint32_t bananos_keyevent_to_x_keysym(LibInput::KeyEvent event)
static uint32_t bananos_key_to_x_keysym(LibInput::Key key, bool upper)
{
using namespace LibInput;
if (const char* utf8 = key_to_utf8(event.key, event.modifier))
if (const char* utf8 = key_to_utf8(key, upper ? KeyEvent::LShift : 0))
{
uint32_t codepoint = BAN::UTF8::to_codepoint(utf8);
const uint32_t codepoint = BAN::UTF8::to_codepoint(utf8);
if (codepoint != BAN::UTF8::invalid && iswprint(codepoint))
{
if (codepoint >= 0x100)
codepoint |= 0x01000000;
return codepoint;
if ((codepoint >= 0x20 && codepoint <= 0x7E) || (codepoint >= 0xA0 && codepoint <= 0xFF))
return codepoint;
return 0x01000000 | codepoint;
}
}
switch (event.key)
switch (key)
{
case Key::F1: return XK_F1;
case Key::F2: return XK_F2;
@@ -344,10 +310,9 @@ static uint32_t bananos_keyevent_to_x_keysym(LibInput::KeyEvent event)
case Key::CapsLock: return XK_Caps_Lock;
case Key::LeftShift: return XK_Shift_L;
case Key::LeftCtrl: return XK_Control_L;
case Key::LeftSuper: return XK_Super_L;
case Key::Super: return XK_Super_L;
case Key::LeftAlt: return XK_Alt_L;
case Key::RightAlt: return XK_Alt_R;
case Key::RightSuper: return XK_Super_R;
case Key::RightCtrl: return XK_Control_R;
case Key::RightShift: return XK_Shift_R;
case Key::ArrowUp: return XK_Up;
@@ -380,11 +345,10 @@ static uint32_t bananos_keyevent_to_x_keysym(LibInput::KeyEvent event)
case Key::MediaStop: return XF86XK_AudioStop;
case Key::MediaPrevious: return XF86XK_AudioPrev;
case Key::MediaNext: return XF86XK_AudioNext;
case Key::Application: return XF86XK_ApplicationRight;
default: break;
}
static_assert(static_cast<size_t>(Key::Count) == 147, "update keymap");
static_assert(static_cast<size_t>(Key::Count) == 145, "update keymap");
return 0;
}