Compare commits

...

3 Commits

4 changed files with 90 additions and 27 deletions

View File

@@ -1,20 +1,20 @@
From c9dd87198ce5262e6ddf6bf3b0c18eb84784d35e Mon Sep 17 00:00:00 2001 From 8b4747fe0dbc356ee1ff05a9bbc868472e188e2f Mon Sep 17 00:00:00 2001
From: Oskari Alaranta <oskari.alaranta@bananymous.com> From: Oskari Alaranta <oskari.alaranta@bananymous.com>
Date: Wed, 15 Apr 2026 17:52:54 +0300 Date: Tue, 23 Jun 2026 23:38:46 +0300
Subject: [PATCH] linux-window-server-sdl2 Subject: [PATCH] linux-window-server-sdl2
--- ---
userspace/libraries/LibGUI/Widget/Widget.cpp | 2 +- userspace/libraries/LibGUI/Widget/Widget.cpp | 2 +-
userspace/libraries/LibGUI/Window.cpp | 9 +- userspace/libraries/LibGUI/Window.cpp | 9 +-
userspace/programs/ProgramLauncher/main.cpp | 2 +- userspace/programs/ProgramLauncher/main.cpp | 2 +-
userspace/programs/Terminal/Terminal.cpp | 4 +- userspace/programs/Terminal/Terminal.cpp | 10 +-
.../programs/WindowServer/CMakeLists.txt | 3 + .../programs/WindowServer/CMakeLists.txt | 3 +
.../programs/WindowServer/Framebuffer.cpp | 52 +-- .../programs/WindowServer/Framebuffer.cpp | 52 +--
userspace/programs/WindowServer/Window.cpp | 29 +- userspace/programs/WindowServer/Window.cpp | 29 +-
.../programs/WindowServer/WindowServer.cpp | 47 ++- .../programs/WindowServer/WindowServer.cpp | 47 ++-
.../programs/WindowServer/WindowServer.h | 1 + .../programs/WindowServer/WindowServer.h | 1 +
userspace/programs/WindowServer/main.cpp | 357 ++++++++++++------ userspace/programs/WindowServer/main.cpp | 357 ++++++++++++------
10 files changed, 340 insertions(+), 166 deletions(-) 10 files changed, 344 insertions(+), 168 deletions(-)
diff --git a/userspace/libraries/LibGUI/Widget/Widget.cpp b/userspace/libraries/LibGUI/Widget/Widget.cpp diff --git a/userspace/libraries/LibGUI/Widget/Widget.cpp b/userspace/libraries/LibGUI/Widget/Widget.cpp
index d6489d87..c532fb04 100644 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 diff --git a/userspace/libraries/LibGUI/Window.cpp b/userspace/libraries/LibGUI/Window.cpp
index b4172f70..3a0e9cca 100644 index f0a11b64..f269594b 100644
--- a/userspace/libraries/LibGUI/Window.cpp --- a/userspace/libraries/LibGUI/Window.cpp
+++ b/userspace/libraries/LibGUI/Window.cpp +++ b/userspace/libraries/LibGUI/Window.cpp
@@ -4,9 +4,8 @@ @@ -4,9 +4,8 @@
@@ -44,7 +44,7 @@ index b4172f70..3a0e9cca 100644
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/un.h> #include <sys/un.h>
#include <time.h> #include <time.h>
@@ -271,7 +270,7 @@ namespace LibGUI @@ -297,7 +296,7 @@ namespace LibGUI
void Window::cleanup() void Window::cleanup()
{ {
@@ -53,7 +53,7 @@ index b4172f70..3a0e9cca 100644
close(m_server_fd); close(m_server_fd);
close(m_epoll_fd); close(m_epoll_fd);
} }
@@ -279,7 +278,7 @@ namespace LibGUI @@ -305,7 +304,7 @@ namespace LibGUI
BAN::ErrorOr<void> Window::handle_resize_event(const EventPacket::ResizeWindowEvent& event) BAN::ErrorOr<void> Window::handle_resize_event(const EventPacket::ResizeWindowEvent& event)
{ {
if (m_framebuffer_smo) if (m_framebuffer_smo)
@@ -62,7 +62,7 @@ index b4172f70..3a0e9cca 100644
m_framebuffer_smo = nullptr; m_framebuffer_smo = nullptr;
TRY(m_texture.resize(event.width, event.height)); TRY(m_texture.resize(event.width, event.height));
@@ -287,7 +286,7 @@ namespace LibGUI @@ -313,7 +312,7 @@ namespace LibGUI
if (m_root_widget) if (m_root_widget)
TRY(m_root_widget->set_fixed_geometry({ 0, 0, event.width, event.height })); TRY(m_root_widget->set_fixed_geometry({ 0, 0, event.width, event.height }));
@@ -85,10 +85,18 @@ index c833c582..0e1cc460 100644
const auto full_program_list = get_program_list(); const auto full_program_list = get_program_list();
diff --git a/userspace/programs/Terminal/Terminal.cpp b/userspace/programs/Terminal/Terminal.cpp diff --git a/userspace/programs/Terminal/Terminal.cpp b/userspace/programs/Terminal/Terminal.cpp
index e1bd317d..8a6b5bd0 100644 index 711d8eab..e334e338 100644
--- a/userspace/programs/Terminal/Terminal.cpp --- a/userspace/programs/Terminal/Terminal.cpp
+++ b/userspace/programs/Terminal/Terminal.cpp +++ b/userspace/programs/Terminal/Terminal.cpp
@@ -92,7 +92,7 @@ void Terminal::start_shell() @@ -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()
close(pts_slave); close(pts_slave);
close(pts_master); close(pts_master);
@@ -97,7 +105,7 @@ index e1bd317d..8a6b5bd0 100644
exit(1); exit(1);
} }
@@ -127,7 +127,7 @@ void Terminal::run() @@ -127,7 +128,7 @@ void Terminal::run()
m_window->texture().set_bg_color(m_bg_color); m_window->texture().set_bg_color(m_bg_color);
m_window->invalidate(); m_window->invalidate();
@@ -106,6 +114,25 @@ index e1bd317d..8a6b5bd0 100644
m_window->set_min_size(m_font.width() * 8, m_font.height() * 2); 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 diff --git a/userspace/programs/WindowServer/CMakeLists.txt b/userspace/programs/WindowServer/CMakeLists.txt
index 8fdf79f9..fcaf441d 100644 index 8fdf79f9..fcaf441d 100644
--- a/userspace/programs/WindowServer/CMakeLists.txt --- a/userspace/programs/WindowServer/CMakeLists.txt
@@ -266,7 +293,7 @@ index 1e66f522..9759eec9 100644
m_client_area.max_x = m_client_area.min_x + width; m_client_area.max_x = m_client_area.min_x + width;
m_client_area.max_y = m_client_area.min_y + height; 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 diff --git a/userspace/programs/WindowServer/WindowServer.cpp b/userspace/programs/WindowServer/WindowServer.cpp
index 2c67d6c0..600704fd 100644 index b29b5888..be5b2f76 100644
--- a/userspace/programs/WindowServer/WindowServer.cpp --- a/userspace/programs/WindowServer/WindowServer.cpp
+++ b/userspace/programs/WindowServer/WindowServer.cpp +++ b/userspace/programs/WindowServer/WindowServer.cpp
@@ -8,19 +8,20 @@ @@ -8,19 +8,20 @@
@@ -295,7 +322,7 @@ index 2c67d6c0..600704fd 100644
{ {
MUST(m_background_image.resize(m_framebuffer.width * m_framebuffer.height, 0xFF101010)); MUST(m_background_image.resize(m_framebuffer.width * m_framebuffer.height, 0xFF101010));
@@ -440,7 +441,7 @@ static void update_volume(const char* new_volume) @@ -451,7 +452,7 @@ static void update_volume(const char* new_volume)
void WindowServer::on_key_event(LibInput::KeyEvent event) void WindowServer::on_key_event(LibInput::KeyEvent event)
{ {
@@ -304,7 +331,7 @@ index 2c67d6c0..600704fd 100644
m_is_mod_key_held = event.pressed(); m_is_mod_key_held = event.pressed();
if (event.pressed() && event.key == LibInput::Key::VolumeDown) if (event.pressed() && event.key == LibInput::Key::VolumeDown)
@@ -461,7 +462,7 @@ void WindowServer::on_key_event(LibInput::KeyEvent event) @@ -472,7 +473,7 @@ void WindowServer::on_key_event(LibInput::KeyEvent event)
pid_t pid = fork(); pid_t pid = fork();
if (pid == 0) if (pid == 0)
{ {
@@ -313,7 +340,7 @@ index 2c67d6c0..600704fd 100644
exit(1); exit(1);
} }
if (pid == -1) if (pid == -1)
@@ -475,7 +476,7 @@ void WindowServer::on_key_event(LibInput::KeyEvent event) @@ -486,7 +487,7 @@ void WindowServer::on_key_event(LibInput::KeyEvent event)
pid_t pid = fork(); pid_t pid = fork();
if (pid == 0) if (pid == 0)
{ {
@@ -322,7 +349,7 @@ index 2c67d6c0..600704fd 100644
exit(1); exit(1);
} }
if (pid == -1) if (pid == -1)
@@ -1599,16 +1600,34 @@ void WindowServer::sync() @@ -1614,16 +1615,34 @@ void WindowServer::sync()
for (size_t i = 0; i < m_damaged_area_count; i++) for (size_t i = 0; i < m_damaged_area_count; i++)
{ {
@@ -364,10 +391,10 @@ index 2c67d6c0..600704fd 100644
Rectangle WindowServer::cursor_area() const Rectangle WindowServer::cursor_area() const
diff --git a/userspace/programs/WindowServer/WindowServer.h b/userspace/programs/WindowServer/WindowServer.h diff --git a/userspace/programs/WindowServer/WindowServer.h b/userspace/programs/WindowServer/WindowServer.h
index 94fbc774..bcd7a6b9 100644 index c31ea125..2d0676bc 100644
--- a/userspace/programs/WindowServer/WindowServer.h --- a/userspace/programs/WindowServer/WindowServer.h
+++ b/userspace/programs/WindowServer/WindowServer.h +++ b/userspace/programs/WindowServer/WindowServer.h
@@ -62,6 +62,7 @@ public: @@ -64,6 +64,7 @@ public:
bool is_damaged() const { return m_damaged_area_count > 0 || m_is_bouncing_window; } bool is_damaged() const { return m_damaged_area_count > 0 || m_is_bouncing_window; }
bool is_stopped() const { return m_is_stopped; } bool is_stopped() const { return m_is_stopped; }
@@ -376,7 +403,7 @@ index 94fbc774..bcd7a6b9 100644
private: private:
void on_mouse_move_impl(int32_t new_x, int32_t new_y); 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 diff --git a/userspace/programs/WindowServer/main.cpp b/userspace/programs/WindowServer/main.cpp
index 46f2ba6d..520c8e7d 100644 index 5b860dc7..4b174cce 100644
--- a/userspace/programs/WindowServer/main.cpp --- a/userspace/programs/WindowServer/main.cpp
+++ b/userspace/programs/WindowServer/main.cpp +++ b/userspace/programs/WindowServer/main.cpp
@@ -10,7 +10,6 @@ @@ -10,7 +10,6 @@
@@ -567,7 +594,7 @@ index 46f2ba6d..520c8e7d 100644
const int client_fd = events[i].data.fd; const int client_fd = events[i].data.fd;
if (events[i].events & (EPOLLHUP | EPOLLERR)) if (events[i].events & (EPOLLHUP | EPOLLERR))
{ {
@@ -500,3 +413,237 @@ int main() @@ -505,3 +418,237 @@ int main()
} }
} }
} }
@@ -806,5 +833,5 @@ index 46f2ba6d..520c8e7d 100644
+ } + }
+} +}
-- --
2.53.0 2.54.0

View File

@@ -750,7 +750,7 @@ void update_cursor(WINDOW wid, int32_t x, int32_t y)
if (wid == None) if (wid == None)
return; return;
const CURSOR cid = [&wid]() -> CURSOR { const CURSOR cid = [](WINDOW wid) -> CURSOR {
for (;;) for (;;)
{ {
const auto& window = g_objects[wid]->object.get<Object::Window>(); const auto& window = g_objects[wid]->object.get<Object::Window>();
@@ -758,7 +758,7 @@ void update_cursor(WINDOW wid, int32_t x, int32_t y)
return window.cursor; return window.cursor;
wid = window.parent; wid = window.parent;
} }
}(); }(wid);
static CURSOR active_cid = None; static CURSOR active_cid = None;
if (cid == active_cid) if (cid == active_cid)

View File

@@ -26,6 +26,8 @@ struct BananCursor final : public PlatformCursor
int32_t origin_y; int32_t origin_y;
}; };
static BAN::UniqPtr<LibGUI::Window> s_dummy_window;
static BAN::ErrorOr<void> bananos_initialize_keymap(); static BAN::ErrorOr<void> bananos_initialize_keymap();
static bool bananos_initialize() static bool bananos_initialize()
@@ -40,7 +42,9 @@ static bool bananos_initialize()
return false; return false;
} }
register_display(0, 0, dummy_or_error.value()->width(), dummy_or_error.value()->height()); s_dummy_window = dummy_or_error.release_value();
register_display(0, 0, s_dummy_window->width(), s_dummy_window->height());
if (auto ret = bananos_initialize_keymap(); ret.is_error()) if (auto ret = bananos_initialize_keymap(); ret.is_error())
{ {
@@ -72,6 +76,9 @@ static BAN::ErrorOr<BAN::UniqPtr<PlatformWindow>> bananos_create_window(WindowTy
auto gui_window = TRY(LibGUI::Window::create(width, height, ""_sv, attributes)); auto gui_window = TRY(LibGUI::Window::create(width, height, ""_sv, attributes));
auto* winp = gui_window.ptr(); auto* winp = gui_window.ptr();
if (x != 0 || y != 0)
gui_window->set_position(x, y);
gui_window->set_close_window_event_callback([wid] { gui_window->set_close_window_event_callback([wid] {
on_window_close_event(wid); on_window_close_event(wid);
}); });
@@ -84,6 +91,9 @@ static BAN::ErrorOr<BAN::UniqPtr<PlatformWindow>> bananos_create_window(WindowTy
gui_window->set_window_fullscreen_event_callback([wid](auto event) { gui_window->set_window_fullscreen_event_callback([wid](auto event) {
on_window_fullscreen_event(wid, event.fullscreen); 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) { gui_window->set_mouse_move_event_callback([wid](auto event) {
on_mouse_move_event(wid, event.x, event.y); on_mouse_move_event(wid, event.x, event.y);
}); });
@@ -130,6 +140,12 @@ static void bananos_request_resize(PlatformWindow* window, uint32_t width, uint3
banan_window.window->request_resize(width, height); 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) 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); auto& banan_window = *static_cast<BananWindow*>(window);
@@ -160,6 +176,26 @@ static void bananos_request_fullscreen(PlatformWindow* window, bool fullscreen)
banan_window.window->set_fullscreen(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) 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()); auto cursor = TRY(BAN::UniqPtr<BananCursor>::create());
@@ -197,10 +233,10 @@ PlatformOps g_platform_ops = {
.begin_frame = nullptr, .begin_frame = nullptr,
.end_frame = bananos_end_frame, .end_frame = bananos_end_frame,
.request_resize = bananos_request_resize, .request_resize = bananos_request_resize,
.request_reposition = nullptr, .request_reposition = bananos_request_reposition,
.request_fullscreen = bananos_request_fullscreen, .request_fullscreen = bananos_request_fullscreen,
.warp_pointer = nullptr, .warp_pointer = nullptr,
.query_pointer = nullptr, .query_pointer = bananos_query_ponter,
.set_pointer_grab = nullptr, .set_pointer_grab = nullptr,
.create_system_cursor = nullptr, .create_system_cursor = nullptr,
.create_bitmap_cursor = bananos_create_bitmap_cursor, .create_bitmap_cursor = bananos_create_bitmap_cursor,