1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 22:27:42 +00:00

Add a simple close button ("X") to windows.

Clicking the button generates a WindowCloseRequest event which the client app
then has to deal with. The default behavior for GWindow is to close() itself.

I also added a flag, GWindow::should_exit_event_loop_on_close() which does
what it sounds like it does.

This patch exposed some bugs in GWindow and GWidget teardown.
This commit is contained in:
Andreas Kling 2019-02-05 10:31:37 +01:00
parent d0078b6574
commit 11db8c1697
14 changed files with 103 additions and 1 deletions

View file

@ -35,6 +35,12 @@ GEventLoop& GEventLoop::main()
return *s_mainGEventLoop;
}
void GEventLoop::exit(int code)
{
m_exit_requested = true;
m_exit_code = code;
}
int GEventLoop::exec()
{
m_event_fd = open("/dev/gui_events", O_RDONLY | O_NONBLOCK | O_CLOEXEC);
@ -45,6 +51,8 @@ int GEventLoop::exec()
m_running = true;
for (;;) {
if (m_exit_requested)
return m_exit_code;
if (m_queued_events.is_empty())
wait_for_event();
Vector<QueuedEvent> events = move(m_queued_events);
@ -69,6 +77,7 @@ int GEventLoop::exec()
}
}
}
ASSERT_NOT_REACHED();
}
void GEventLoop::post_event(GObject* receiver, OwnPtr<GEvent>&& event)
@ -95,6 +104,11 @@ void GEventLoop::handle_window_activation_event(const GUI_Event& event, GWindow&
post_event(&window, make<GEvent>(event.type == GUI_Event::Type::WindowActivated ? GEvent::WindowBecameActive : GEvent::WindowBecameInactive));
}
void GEventLoop::handle_window_close_request_event(const GUI_Event&, GWindow& window)
{
post_event(&window, make<GEvent>(GEvent::WindowCloseRequest));
}
void GEventLoop::handle_key_event(const GUI_Event& event, GWindow& window)
{
#ifdef GEVENTLOOP_DEBUG
@ -192,6 +206,9 @@ void GEventLoop::wait_for_event()
case GUI_Event::Type::WindowDeactivated:
handle_window_activation_event(event, *window);
break;
case GUI_Event::Type::WindowCloseRequest:
handle_window_close_request_event(event, *window);
break;
case GUI_Event::Type::KeyDown:
case GUI_Event::Type::KeyUp:
handle_key_event(event, *window);