mirror of
https://github.com/RGBCube/serenity
synced 2025-07-06 04:27:35 +00:00
Start refactoring the windowing system to use an event loop.
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.
This commit is contained in:
parent
b4da4e8fbd
commit
b0e3f73375
46 changed files with 283 additions and 292 deletions
|
@ -22,6 +22,14 @@ void Process::initialize_gui_statics()
|
|||
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.
|
||||
|
@ -37,28 +45,26 @@ int Process::gui$create_window(const GUI_CreateWindowParameters* user_params)
|
|||
return -EFAULT;
|
||||
|
||||
auto params = *user_params;
|
||||
Rect rect = params.rect;
|
||||
|
||||
if (params.rect.is_empty())
|
||||
if (rect.is_empty())
|
||||
return -EINVAL;
|
||||
|
||||
ProcessPagingScope scope(EventLoop::main().server_process());
|
||||
|
||||
auto* window = new Window;
|
||||
int window_id = make_window_id();
|
||||
if (!window_id)
|
||||
return -ENOMEM;
|
||||
|
||||
auto window = make<Window>(*this, window_id);
|
||||
if (!window)
|
||||
return -ENOMEM;
|
||||
|
||||
int window_id = m_windows.size();
|
||||
m_windows.append(window->makeWeakPtr());
|
||||
|
||||
window->setTitle(params.title);
|
||||
window->setRect(params.rect);
|
||||
window->setRect(rect);
|
||||
|
||||
auto* main_widget = new Widget;
|
||||
window->setMainWidget(main_widget);
|
||||
main_widget->setWindowRelativeRect({ 0, 0, params.rect.width(), params.rect.height() });
|
||||
main_widget->setBackgroundColor(params.background_color);
|
||||
main_widget->setFillWithBackgroundColor(true);
|
||||
dbgprintf("%s<%u> gui$create_window: %d with rect {%d,%d %dx%d}\n", name().characters(), pid(), window_id, params.rect.x(), params.rect.y(), params.rect.width(), params.rect.height());
|
||||
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;
|
||||
}
|
||||
|
@ -70,65 +76,9 @@ int Process::gui$destroy_window(int window_id)
|
|||
return -EINVAL;
|
||||
if (window_id >= static_cast<int>(m_windows.size()))
|
||||
return -EBADWINDOW;
|
||||
auto* window = m_windows[window_id].ptr();
|
||||
if (!window)
|
||||
auto it = m_windows.find(window_id);
|
||||
if (it == m_windows.end())
|
||||
return -EBADWINDOW;
|
||||
window->deleteLater();
|
||||
m_windows.remove(window_id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Process::gui$create_widget(int window_id, const GUI_CreateWidgetParameters* user_params)
|
||||
{
|
||||
if (!validate_read_typed(user_params))
|
||||
return -EFAULT;
|
||||
|
||||
if (window_id < 0)
|
||||
return -EINVAL;
|
||||
if (window_id >= static_cast<int>(m_windows.size()))
|
||||
return -EINVAL;
|
||||
if (!m_windows[window_id])
|
||||
return -EINVAL;
|
||||
auto& window = *m_windows[window_id];
|
||||
|
||||
auto params = *user_params;
|
||||
|
||||
if (params.rect.is_empty())
|
||||
return -EINVAL;
|
||||
|
||||
Widget* widget = nullptr;
|
||||
switch (params.type) {
|
||||
case GUI_WidgetType::Label:
|
||||
widget = new Label(window.mainWidget());
|
||||
static_cast<Label*>(widget)->setText(params.text);
|
||||
widget->setFillWithBackgroundColor(params.opaque);
|
||||
break;
|
||||
case GUI_WidgetType::Button:
|
||||
widget = new Button(window.mainWidget());
|
||||
static_cast<Button*>(widget)->setCaption(params.text);
|
||||
break;
|
||||
}
|
||||
|
||||
int widget_id = m_widgets.size();
|
||||
m_widgets.append(widget->makeWeakPtr());
|
||||
|
||||
widget->setWindowRelativeRect(params.rect);
|
||||
widget->setBackgroundColor(params.background_color);
|
||||
dbgprintf("%s<%u> gui$create_widget: %d with rect {%d,%d %dx%d}\n", name().characters(), pid(), widget_id, params.rect.x(), params.rect.y(), params.rect.width(), params.rect.height());
|
||||
|
||||
return window_id;
|
||||
}
|
||||
|
||||
int Process::gui$destroy_widget(int widget_id)
|
||||
{
|
||||
dbgprintf("%s<%u> gui$destroy_widget (widget_id=%d)\n", name().characters(), pid(), widget_id);
|
||||
if (widget_id < 0)
|
||||
return -EINVAL;
|
||||
if (widget_id >= static_cast<int>(m_widgets.size()))
|
||||
return -EBADWINDOW;
|
||||
auto* widget = m_widgets[widget_id].ptr();
|
||||
if (!widget)
|
||||
return -EBADWIDGET;
|
||||
widget->deleteLater();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue