Explorar el Código

LibCore: Add a hook for custom construction of EventLoopImplementation

Andreas Kling hace 2 años
padre
commit
31289a8d57

+ 3 - 1
Userland/Libraries/LibCore/EventLoop.cpp

@@ -30,8 +30,10 @@ bool has_event_loop()
 }
 }
 
+Function<NonnullOwnPtr<EventLoopImplementation>()> EventLoop::make_implementation = EventLoopImplementationUnix::create;
+
 EventLoop::EventLoop()
-    : m_impl(make<EventLoopImplementationUnix>())
+    : m_impl(make_implementation())
 {
     if (event_loop_stack().is_empty()) {
         event_loop_stack().append(*this);

+ 2 - 0
Userland/Libraries/LibCore/EventLoop.h

@@ -93,6 +93,8 @@ public:
 
     static EventLoop& current();
 
+    static Function<NonnullOwnPtr<EventLoopImplementation>()> make_implementation;
+
 private:
     void wait_for_event(WaitMode);
     Optional<Time> get_next_timer_expiration();

+ 2 - 0
Userland/Libraries/LibCore/EventLoopImplementationUnix.h

@@ -12,6 +12,8 @@ namespace Core {
 
 class EventLoopImplementationUnix final : public EventLoopImplementation {
 public:
+    static NonnullOwnPtr<EventLoopImplementationUnix> create() { return make<EventLoopImplementationUnix>(); }
+
     EventLoopImplementationUnix();
     virtual ~EventLoopImplementationUnix();