mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-25 22:08:59 +00:00
Userspace programs can now open /dev/gui_events and read a stream of GUI_Event structs one at a time. I was stuck on a stupid problem where we'd reenter Scheduler::yield() due to having one of the has_data_available_for_reading() implementations using locks.
84 lines
2.1 KiB
C++
84 lines
2.1 KiB
C++
#include "Process.h"
|
|
#include "MemoryManager.h"
|
|
#include <LibC/errno_numbers.h>
|
|
#include <Widgets/AbstractScreen.h>
|
|
#include <Widgets/FrameBuffer.h>
|
|
#include <Widgets/EventLoop.h>
|
|
#include <Widgets/Font.h>
|
|
#include <Widgets/Button.h>
|
|
#include <Widgets/Label.h>
|
|
#include <Widgets/Widget.h>
|
|
#include <Widgets/Window.h>
|
|
#include <Widgets/WindowManager.h>
|
|
|
|
void Process::initialize_gui_statics()
|
|
{
|
|
Font::initialize();
|
|
FrameBuffer::initialize();
|
|
EventLoop::initialize();
|
|
WindowManager::initialize();
|
|
AbstractScreen::initialize();
|
|
|
|
new EventLoop;
|
|
}
|
|
|
|
int Process::make_window_id()
|
|
{
|
|
int new_id = m_next_window_id++;
|
|
while (!new_id || m_windows.contains(new_id))
|
|
new_id = m_next_window_id++;
|
|
return new_id;
|
|
}
|
|
|
|
static void wait_for_gui_server()
|
|
{
|
|
// FIXME: Time out after a while and return an error.
|
|
while (!EventLoop::main().running())
|
|
sleep(10);
|
|
}
|
|
|
|
int Process::gui$create_window(const GUI_CreateWindowParameters* user_params)
|
|
{
|
|
wait_for_gui_server();
|
|
|
|
if (!validate_read_typed(user_params))
|
|
return -EFAULT;
|
|
|
|
auto params = *user_params;
|
|
Rect rect = params.rect;
|
|
|
|
if (rect.is_empty())
|
|
return -EINVAL;
|
|
|
|
ProcessPagingScope scope(EventLoop::main().server_process());
|
|
|
|
int window_id = make_window_id();
|
|
if (!window_id)
|
|
return -ENOMEM;
|
|
|
|
auto window = make<Window>(*this, window_id);
|
|
if (!window)
|
|
return -ENOMEM;
|
|
|
|
window->setTitle(params.title);
|
|
window->setRect(rect);
|
|
|
|
m_windows.set(window_id, move(window));
|
|
dbgprintf("%s<%u> gui$create_window: %d with rect {%d,%d %dx%d}\n", name().characters(), pid(), window_id, rect.x(), rect.y(), rect.width(), rect.height());
|
|
|
|
return window_id;
|
|
}
|
|
|
|
int Process::gui$destroy_window(int window_id)
|
|
{
|
|
dbgprintf("%s<%u> gui$destroy_window (window_id=%d)\n", name().characters(), pid(), window_id);
|
|
if (window_id < 0)
|
|
return -EINVAL;
|
|
if (window_id >= static_cast<int>(m_windows.size()))
|
|
return -EBADWINDOW;
|
|
auto it = m_windows.find(window_id);
|
|
if (it == m_windows.end())
|
|
return -EBADWINDOW;
|
|
m_windows.remove(window_id);
|
|
return 0;
|
|
}
|