From dce7b92c9511f38c836f7e702c02afd17e514470 Mon Sep 17 00:00:00 2001 From: apio Date: Thu, 14 Sep 2023 21:29:48 +0200 Subject: [PATCH] libui: Add option to run event processing in a loop instead of in app.run() --- libui/include/ui/App.h | 4 ++++ libui/src/App.cpp | 16 ++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/libui/include/ui/App.h b/libui/include/ui/App.h index 231c9af3..b297c14b 100644 --- a/libui/include/ui/App.h +++ b/libui/include/ui/App.h @@ -35,6 +35,8 @@ namespace ui m_should_close = b; } + void set_nonblocking(); + void set_main_window(Window* window) { check(!m_main_window); @@ -51,6 +53,8 @@ namespace ui Result handle_ipc_event(u8 id); + bool process_events(); + static App& the(); private: diff --git a/libui/src/App.cpp b/libui/src/App.cpp index 886d9b46..43fe9b9b 100644 --- a/libui/src/App.cpp +++ b/libui/src/App.cpp @@ -50,8 +50,8 @@ namespace ui Result App::run() { - check(m_main_window); - while (!m_should_close) { TRY(os::IPC::check_for_messages(*m_client)); } + while (process_events()) + ; return 0; } @@ -135,4 +135,16 @@ namespace ui default: fail("Unexpected IPC request from server!"); } } + + void App::set_nonblocking() + { + fcntl(m_client->fd(), F_SETFL, O_NONBLOCK); + } + + bool App::process_events() + { + check(m_main_window); + os::IPC::check_for_messages(*m_client).release_value(); + return !m_should_close; + } }