| 1 | // LAF OS Library | 
|---|
| 2 | // Copyright (C) 2021  Igara Studio S.A. | 
|---|
| 3 | // Copyright (C) 2012-2018  David Capello | 
|---|
| 4 | // | 
|---|
| 5 | // This file is released under the terms of the MIT license. | 
|---|
| 6 | // Read LICENSE.txt for more information. | 
|---|
| 7 |  | 
|---|
| 8 | #ifndef OS_EVENT_QUEUE_H_INCLUDED | 
|---|
| 9 | #define OS_EVENT_QUEUE_H_INCLUDED | 
|---|
| 10 | #pragma once | 
|---|
| 11 |  | 
|---|
| 12 | namespace os { | 
|---|
| 13 |  | 
|---|
| 14 | class Event; | 
|---|
| 15 |  | 
|---|
| 16 | class EventQueue { | 
|---|
| 17 | public: | 
|---|
| 18 | static constexpr const double kWithoutTimeout = -1.0; | 
|---|
| 19 |  | 
|---|
| 20 | virtual ~EventQueue() { } | 
|---|
| 21 |  | 
|---|
| 22 | // Wait for a new event. We can specify a timeout in seconds to | 
|---|
| 23 | // limit the time of wait for the next event. | 
|---|
| 24 | virtual void getEvent(Event& ev, double timeout = kWithoutTimeout) = 0; | 
|---|
| 25 |  | 
|---|
| 26 | // Adds a new event in the queue to be processed by | 
|---|
| 27 | // getEvent(). It's used by each platform to convert | 
|---|
| 28 | // platform-specific messages into platform-independent events | 
|---|
| 29 | // (os::Event). | 
|---|
| 30 | virtual void queueEvent(const Event& ev) = 0; | 
|---|
| 31 |  | 
|---|
| 32 | // Clears all events in the queue. You shouldn't call this | 
|---|
| 33 | // function, it's used internally to clear all events before the | 
|---|
| 34 | // System instance is destroyed. Anyway you might want to use it | 
|---|
| 35 | // in case that you want to ensure that no more WindowRef is | 
|---|
| 36 | // alive. | 
|---|
| 37 | virtual void clearEvents() = 0; | 
|---|
| 38 |  | 
|---|
| 39 | // Deprecated old method. We should remove this line after some | 
|---|
| 40 | // releases. It's here to avoid calling getEvent(Event&, double) | 
|---|
| 41 | // even when we use a bool 2nd argument. | 
|---|
| 42 | void getEvent(Event& ev, bool) = delete; | 
|---|
| 43 |  | 
|---|
| 44 | // On macOS we need the EventQueue before the creation of the | 
|---|
| 45 | // System. E.g. when we double-click a file an Event to open that | 
|---|
| 46 | // file is queued in application:openFile:, code which is executed | 
|---|
| 47 | // before the user's main() code. | 
|---|
| 48 | static EventQueue* instance(); | 
|---|
| 49 | }; | 
|---|
| 50 |  | 
|---|
| 51 | inline void queue_event(const Event& ev) { | 
|---|
| 52 | EventQueue::instance()->queueEvent(ev); | 
|---|
| 53 | } | 
|---|
| 54 |  | 
|---|
| 55 | } // namespace os | 
|---|
| 56 |  | 
|---|
| 57 | #endif | 
|---|
| 58 |  | 
|---|