1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 23:07:35 +00:00

LibGUI: Implement nested event loops to support dialog boxes.

This patch adds a simple GMessageBox that can run in a nested event loop.
Here's how you use it:

    GMessageBox box("Message text here", "Message window title");
    int result = box.exec();

The next step is to make the WindowServer respect the modality flag of
these windows and prevent interaction with other windows in the same
process until the modal window has been closed.
This commit is contained in:
Andreas Kling 2019-03-19 00:01:02 +01:00
parent 55aa819077
commit 57ff293a51
29 changed files with 275 additions and 79 deletions

View file

@ -23,14 +23,15 @@ public:
void post_event(GObject& receiver, OwnPtr<GEvent>&&);
static GEventLoop& main();
static GEventLoop& current();
bool running() const { return m_running; }
int register_timer(GObject&, int milliseconds, bool should_reload);
bool unregister_timer(int timer_id);
static int register_timer(GObject&, int milliseconds, bool should_reload);
static bool unregister_timer(int timer_id);
void register_notifier(Badge<GNotifier>, GNotifier&);
void unregister_notifier(Badge<GNotifier>, GNotifier&);
static void register_notifier(Badge<GNotifier>, GNotifier&);
static void unregister_notifier(Badge<GNotifier>, GNotifier&);
void quit(int);
@ -41,6 +42,12 @@ public:
static pid_t server_pid() { return s_server_pid; }
void take_pending_events_from(GEventLoop& other)
{
m_queued_events.append(move(other.m_queued_events));
m_unprocessed_messages.append(move(other.m_unprocessed_messages));
}
private:
void wait_for_event();
bool drain_messages_from_server();
@ -67,7 +74,6 @@ private:
bool m_running { false };
bool m_exit_requested { false };
int m_exit_code { 0 };
int m_next_timer_id { 1 };
static pid_t s_server_pid;
static pid_t s_event_fd;
@ -83,6 +89,8 @@ private:
bool has_expired() const;
};
HashMap<int, OwnPtr<EventLoopTimer>> m_timers;
HashTable<GNotifier*> m_notifiers;
static HashMap<int, OwnPtr<EventLoopTimer>>* s_timers;
static int s_next_timer_id;
static HashTable<GNotifier*>* s_notifiers;
};