apio
ac260d0397
All checks were successful
Build and test / build (push) Successful in 1m42s
This segments privileges more, making it so that any app connecting to wsys.sock can't just always access every single advanced feature in wind if they don't need to. Of course, apps have to restrict themselves, which is why only privileged apps have access to this feature in the first place. Normal apps' pledges are all empty and can't be changed. An example: taskbar uses the "ExtendedLayers" pledge to move its window to the background, but relinquishes it afterwards, and doesn't need any other advanced feature for now. If a pledge-capable app tries to use a pledge-protected function without having pledged anything, it can't. Pledges are mandatory if you want to access certain functionality, unlike the kernel's pledges which make every syscall available if you don't use pledge().
77 lines
1.6 KiB
C++
77 lines
1.6 KiB
C++
/**
|
|
* @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>
|
|
#include <luna/StringView.h>
|
|
#include <os/EventLoop.h>
|
|
#include <os/IPC.h>
|
|
#include <ui/Window.h>
|
|
|
|
namespace ui
|
|
{
|
|
class App
|
|
{
|
|
public:
|
|
App();
|
|
~App();
|
|
|
|
Result<void> init(StringView socket_path = "/tmp/wind.sock");
|
|
Result<int> run();
|
|
|
|
Rect screen_rect();
|
|
|
|
os::IPC::Client& client()
|
|
{
|
|
return *m_client;
|
|
}
|
|
|
|
void set_should_close(bool b)
|
|
{
|
|
m_should_close = b;
|
|
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;
|
|
}
|
|
|
|
void pledge(i16 pledges);
|
|
|
|
Result<void> register_window(OwnedPtr<Window>&& window, Badge<Window>);
|
|
void unregister_window(Window* window, Badge<Window>);
|
|
|
|
static App& the();
|
|
|
|
private:
|
|
static App* s_app;
|
|
OwnedPtr<os::IPC::Client> m_client;
|
|
Window* m_main_window { nullptr };
|
|
HashMap<int, OwnedPtr<Window>> m_windows;
|
|
bool m_should_close { false };
|
|
os::EventLoop m_loop;
|
|
Vector<int> m_window_clear_queue;
|
|
|
|
bool process_events();
|
|
|
|
Window* find_window(int id);
|
|
|
|
Result<void> handle_ipc_event(os::IPC::Client&, u8 id, void*);
|
|
|
|
friend void handle_socket_event(int, int);
|
|
};
|
|
}
|