| 
									
										
										
										
											2023-04-24 14:51:19 +02:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2024-10-04 13:19:50 +02:00
										 |  |  |  * Copyright (c) 2022-2023, Andreas Kling <andreas@ladybird.org> | 
					
						
							| 
									
										
										
										
											2023-04-24 14:51:19 +02:00
										 |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-04 04:37:36 -05:00
										 |  |  | #include <AK/Badge.h>
 | 
					
						
							| 
									
										
										
										
											2023-04-24 14:51:19 +02:00
										 |  |  | #include <AK/NonnullOwnPtr.h>
 | 
					
						
							|  |  |  | #include <LibCore/EventLoopImplementation.h>
 | 
					
						
							| 
									
										
										
										
											2024-11-09 12:50:33 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-10 09:23:10 -05:00
										 |  |  | class QEvent; | 
					
						
							|  |  |  | class QEventLoop; | 
					
						
							|  |  |  | class QSocketNotifier; | 
					
						
							| 
									
										
										
										
											2023-04-24 14:51:19 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-10 09:23:10 -05:00
										 |  |  | namespace WebView { | 
					
						
							| 
									
										
										
										
											2023-04-24 14:51:19 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-01 11:49:07 -04:00
										 |  |  | class EventLoopImplementationQt; | 
					
						
							| 
									
										
										
										
											2023-07-04 04:37:36 -05:00
										 |  |  | class EventLoopImplementationQtEventTarget; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-25 17:38:48 +02:00
										 |  |  | class EventLoopManagerQt final : public Core::EventLoopManager { | 
					
						
							| 
									
										
										
										
											2023-04-24 14:51:19 +02:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2023-04-25 17:38:48 +02:00
										 |  |  |     EventLoopManagerQt(); | 
					
						
							|  |  |  |     virtual ~EventLoopManagerQt() override; | 
					
						
							|  |  |  |     virtual NonnullOwnPtr<Core::EventLoopImplementation> make_implementation() override; | 
					
						
							| 
									
										
										
										
											2023-04-24 14:51:19 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-11 11:45:39 +02:00
										 |  |  |     virtual intptr_t register_timer(Core::EventReceiver&, int milliseconds, bool should_reload) override; | 
					
						
							| 
									
										
										
										
											2024-02-18 00:11:38 -05:00
										 |  |  |     virtual void unregister_timer(intptr_t timer_id) override; | 
					
						
							| 
									
										
										
										
											2023-04-24 14:51:19 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     virtual void register_notifier(Core::Notifier&) override; | 
					
						
							|  |  |  |     virtual void unregister_notifier(Core::Notifier&) override; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-25 16:53:07 +02:00
										 |  |  |     virtual void did_post_event() override; | 
					
						
							| 
									
										
										
										
											2023-07-04 04:37:36 -05:00
										 |  |  |     static bool event_target_received_event(Badge<EventLoopImplementationQtEventTarget>, QEvent* event); | 
					
						
							| 
									
										
										
										
											2023-04-25 16:53:07 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-29 23:18:20 -06:00
										 |  |  |     virtual int register_signal(int, Function<void(int)>) override; | 
					
						
							|  |  |  |     virtual void unregister_signal(int) override; | 
					
						
							| 
									
										
										
										
											2023-04-25 17:38:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-01 11:49:07 -04:00
										 |  |  |     void set_main_loop_signal_notifiers(Badge<EventLoopImplementationQt>); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-25 17:38:48 +02:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2024-06-29 23:18:20 -06:00
										 |  |  |     static void handle_signal(int); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-04 04:37:36 -05:00
										 |  |  |     NonnullOwnPtr<EventLoopImplementationQtEventTarget> m_main_thread_event_target; | 
					
						
							| 
									
										
										
										
											2024-06-29 23:18:20 -06:00
										 |  |  |     QSocketNotifier* m_signal_socket_notifier { nullptr }; | 
					
						
							|  |  |  |     int m_signal_socket_fds[2] = { -1, -1 }; | 
					
						
							| 
									
										
										
										
											2023-07-04 04:37:36 -05:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-25 17:38:48 +02:00
										 |  |  | class EventLoopImplementationQt final : public Core::EventLoopImplementation { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  |     static NonnullOwnPtr<EventLoopImplementationQt> create() { return adopt_own(*new EventLoopImplementationQt); } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     virtual ~EventLoopImplementationQt() override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     virtual int exec() override; | 
					
						
							|  |  |  |     virtual size_t pump(PumpMode) override; | 
					
						
							|  |  |  |     virtual void quit(int) override; | 
					
						
							|  |  |  |     virtual void wake() override; | 
					
						
							| 
									
										
										
										
											2025-04-29 15:41:18 -06:00
										 |  |  |     virtual bool was_exit_requested() const override; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-06 18:09:39 +02:00
										 |  |  |     virtual void post_event(Core::EventReceiver& receiver, NonnullOwnPtr<Core::Event>&&) override; | 
					
						
							| 
									
										
										
										
											2023-04-25 17:38:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-01 11:49:07 -04:00
										 |  |  |     void set_main_loop(); | 
					
						
							| 
									
										
										
										
											2023-04-24 14:51:19 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							| 
									
										
										
										
											2023-04-25 17:38:48 +02:00
										 |  |  |     friend class EventLoopManagerQt; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-25 16:53:07 +02:00
										 |  |  |     EventLoopImplementationQt(); | 
					
						
							|  |  |  |     bool is_main_loop() const { return m_main_loop; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-10 09:23:10 -05:00
										 |  |  |     NonnullOwnPtr<QEventLoop> m_event_loop; | 
					
						
							| 
									
										
										
										
											2023-04-25 16:53:07 +02:00
										 |  |  |     bool m_main_loop { false }; | 
					
						
							| 
									
										
										
										
											2023-04-24 14:51:19 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |