LibGUI: Add API to block until window events are available

This commit is contained in:
Bananymous 2025-05-05 22:33:00 +03:00
parent 96496da0ab
commit f78c7e7926
2 changed files with 11 additions and 1 deletions

View File

@ -387,10 +387,17 @@ namespace LibGUI
return {}; return {};
} }
#define TRY_OR_BREAK(...) ({ auto&& e = (__VA_ARGS__); if (e.is_error()) break; e.release_value(); }) void Window::wait_events()
{
fd_set fds;
FD_ZERO(&fds);
FD_SET(m_server_fd, &fds);
select(m_server_fd + 1, &fds, nullptr, nullptr, nullptr);
}
void Window::poll_events() void Window::poll_events()
{ {
#define TRY_OR_BREAK(...) ({ auto&& e = (__VA_ARGS__); if (e.is_error()) break; e.release_value(); })
for (;;) for (;;)
{ {
fd_set fds; fd_set fds;
@ -444,6 +451,7 @@ namespace LibGUI
break; break;
} }
} }
#undef TRY_OR_BREAK
} }
} }

View File

@ -88,7 +88,9 @@ namespace LibGUI
// used on resize to fill empty space // used on resize to fill empty space
void set_bg_color(uint32_t bg_color) { m_bg_color = bg_color; } void set_bg_color(uint32_t bg_color) { m_bg_color = bg_color; }
void wait_events();
void poll_events(); void poll_events();
void set_socket_error_callback(BAN::Function<void()> callback) { m_socket_error_callback = callback; } void set_socket_error_callback(BAN::Function<void()> callback) { m_socket_error_callback = callback; }
void set_close_window_event_callback(BAN::Function<void()> callback) { m_close_window_event_callback = callback; } void set_close_window_event_callback(BAN::Function<void()> callback) { m_close_window_event_callback = callback; }
void set_resize_window_event_callback(BAN::Function<void()> callback) { m_resize_window_event_callback = callback; } void set_resize_window_event_callback(BAN::Function<void()> callback) { m_resize_window_event_callback = callback; }