Luna/libui/include/ui/App.h

71 lines
1.4 KiB
C
Raw Normal View History

/**
* @file App.h
* @author apio (cloudapio.eu)
* @brief UI application event loop.
*
* @copyright Copyright (c) 2023, the Luna authors.
*
*/
#pragma once
#include <luna/HashMap.h>
2023-10-06 20:06:34 +00:00
#include <os/EventLoop.h>
#include <os/LocalClient.h>
#include <ui/Window.h>
namespace ui
{
class App
{
public:
App();
~App();
Result<void> init(int, char**);
Result<int> run();
Rect screen_rect();
os::LocalClient& client()
{
return *m_client;
}
void set_should_close(bool b)
{
m_should_close = b;
2023-10-06 20:06:34 +00:00
if (b) m_loop.quit();
}
void set_main_window(Window* window)
{
check(!m_main_window);
m_main_window = window;
}
Window* main_window()
{
return m_main_window;
}
Result<void> register_window(OwnedPtr<Window>&& window, Badge<Window>);
void unregister_window(Window* window, Badge<Window>);
Result<void> handle_ipc_event(u8 id);
bool process_events();
static App& the();
private:
static App* s_app;
OwnedPtr<os::LocalClient> m_client;
Window* m_main_window { nullptr };
HashMap<int, OwnedPtr<Window>> m_windows;
bool m_should_close { false };
2023-10-06 20:06:34 +00:00
os::EventLoop m_loop;
Window* find_window(int id);
};
}