From 07f2b5dbb79f9914d2b6d646f2a64c6f430762e1 Mon Sep 17 00:00:00 2001 From: Oskari Alaranta Date: Wed, 15 Apr 2026 18:18:24 +0300 Subject: [PATCH] Add hacky way to die when WindowServer dies We keep a dummy window around which will receive a close event that exits once WindowServer dies :^) --- xbanan/main.cpp | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/xbanan/main.cpp b/xbanan/main.cpp index 213f479..79c0bfa 100644 --- a/xbanan/main.cpp +++ b/xbanan/main.cpp @@ -18,19 +18,20 @@ #include #endif -static const xRectangle s_screen_bounds = +static BAN::UniqPtr s_dummy_window = []() { auto attributes = LibGUI::Window::default_attributes; attributes.shown = false; - auto window = MUST(LibGUI::Window::create(0, 0, ""_sv, attributes)); - return xRectangle { - .x = 0, - .y = 0, - .width = static_cast(window->width()), - .height = static_cast(window->height()), - }; + return MUST(LibGUI::Window::create(0, 0, ""_sv, attributes)); }(); +static const xRectangle s_screen_bounds = { + .x = 0, + .y = 0, + .width = static_cast(s_dummy_window->width()), + .height = static_cast(s_dummy_window->height()), +}; + const xPixmapFormat g_formats[6] { { .depth = 1, @@ -172,11 +173,24 @@ int main() return 1; } - epoll_event event { .events = EPOLLIN, .data = { .ptr = nullptr } }; - if (epoll_ctl(g_epoll_fd, EPOLL_CTL_ADD, server_sock, &event) == -1) { - perror("xbanan: epoll_ctl"); - return 1; + epoll_event event { .events = EPOLLIN, .data = { .ptr = nullptr } }; + if (epoll_ctl(g_epoll_fd, EPOLL_CTL_ADD, server_sock, &event) == -1) + { + perror("xbanan: epoll_ctl"); + return 1; + } + } + + { + epoll_event event { .events = EPOLLIN, .data = { .ptr = (void*)1 } }; + if (epoll_ctl(g_epoll_fd, EPOLL_CTL_ADD, s_dummy_window->server_fd(), &event) == -1) + { + perror("xbanan: epoll_ctl"); + return 1; + } + + s_dummy_window->request_resize(1, 1); } #define APPEND_ATOM(name) do { \ @@ -397,6 +411,12 @@ int main() continue; } + if (events[i].data.ptr == (void*)1) + { + s_dummy_window->poll_events(); + continue; + } + auto it = g_epoll_thingies.find(events[i].data.fd); if (it == g_epoll_thingies.end()) continue;