1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-16 20:05:07 +00:00

Port Terminal to LibGUI.

To facilitate listening for action on arbitrary file descriptors,
I've added a GNotifier class. It's quite simple but very useful:

GNotifier notifier(fd, GNotifier::Read);
notifier.on_ready_to_read = [this] (GNotifier& fd) {
    // read from fd or whatever else you like :^)
};

The callback will get invoked by GEventLoop when select() says we
have something to read on the fd.
This commit is contained in:
Andreas Kling 2019-02-10 14:28:39 +01:00
parent ae4811fbae
commit 53d34a0885
15 changed files with 268 additions and 151 deletions

View file

@ -163,13 +163,17 @@ void GWindow::event(GEvent& event)
}
if (event.is_key_event()) {
if (!m_focused_widget)
return;
return m_focused_widget->event(event);
if (m_focused_widget)
return m_focused_widget->event(event);
if (m_main_widget)
return m_main_widget->event(event);
return;
}
if (event.type() == GEvent::WindowBecameActive || event.type() == GEvent::WindowBecameInactive) {
m_is_active = event.type() == GEvent::WindowBecameActive;
if (m_main_widget)
m_main_widget->event(event);
if (m_focused_widget)
m_focused_widget->update();
return;
@ -202,9 +206,18 @@ void GWindow::set_main_widget(GWidget* widget)
if (m_main_widget == widget)
return;
m_main_widget = widget;
m_main_widget->set_relative_rect({ 0, 0, width(), height() });
if (widget)
widget->set_window(this);
if (m_main_widget) {
auto new_window_rect = rect();
if (m_main_widget->horizontal_size_policy() == SizePolicy::Fixed)
new_window_rect.set_width(m_main_widget->preferred_size().width());
if (m_main_widget->vertical_size_policy() == SizePolicy::Fixed)
new_window_rect.set_height(m_main_widget->preferred_size().height());
set_rect(new_window_rect);
m_main_widget->set_relative_rect({ { }, new_window_rect.size() });
m_main_widget->set_window(this);
if (m_main_widget->accepts_focus())
m_main_widget->set_focus(true);
}
update();
}