OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UI_EVENTS_PLATFORM_X11_X11_EVENT_SOURCE_H_ | 5 #ifndef UI_EVENTS_PLATFORM_X11_X11_EVENT_SOURCE_H_ |
6 #define UI_EVENTS_PLATFORM_X11_X11_EVENT_SOURCE_H_ | 6 #define UI_EVENTS_PLATFORM_X11_X11_EVENT_SOURCE_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "ui/events/events_export.h" | 12 #include "ui/events/events_export.h" |
13 #include "ui/events/platform/platform_event_source.h" | |
14 #include "ui/gfx/x/x11_types.h" | 13 #include "ui/gfx/x/x11_types.h" |
15 | 14 |
16 typedef struct _GPollFD GPollFD; | |
17 typedef struct _GSource GSource; | |
18 typedef union _XEvent XEvent; | 15 typedef union _XEvent XEvent; |
19 typedef unsigned long XID; | 16 typedef unsigned long XID; |
20 | 17 |
21 namespace ui { | 18 namespace ui { |
22 | 19 |
23 class X11HotplugEventHandler; | 20 class X11HotplugEventHandler; |
24 | 21 |
25 // A PlatformEventSource implementation for reading events from X11 server and | 22 // Responsible for notifying X11EventSource when new XEvents are available and |
26 // dispatching the events to the appropriate dispatcher. | 23 // processing/dispatching XEvents. Implementations will likely be a |
27 class EVENTS_EXPORT X11EventSource : public PlatformEventSource { | 24 // PlatformEventSource. |
| 25 class X11EventSourceDelegate { |
28 public: | 26 public: |
29 explicit X11EventSource(XDisplay* display); | 27 X11EventSourceDelegate() = default; |
30 ~X11EventSource() override; | 28 |
| 29 // Processes (if necessary) and handles dispatching XEvents. |
| 30 virtual void ProcessXEvent(XEvent* xevent) = 0; |
| 31 |
| 32 private: |
| 33 DISALLOW_COPY_AND_ASSIGN(X11EventSourceDelegate); |
| 34 }; |
| 35 |
| 36 // Receives X11 events and sends them to X11EventSourceDelegate. Handles |
| 37 // receiving, pre-process and post-processing XEvents. |
| 38 class EVENTS_EXPORT X11EventSource { |
| 39 public: |
| 40 X11EventSource(X11EventSourceDelegate* delegate, XDisplay* display); |
| 41 ~X11EventSource(); |
31 | 42 |
32 static X11EventSource* GetInstance(); | 43 static X11EventSource* GetInstance(); |
33 | 44 |
34 // Called by the glib source dispatch function. Processes all (if any) | 45 // Called when there is a new XEvent available. Processes all (if any) |
35 // available X events. | 46 // available X events. |
36 void DispatchXEvents(); | 47 void DispatchXEvents(); |
37 | 48 |
38 // Blocks on the X11 event queue until we receive notification from the | 49 // Blocks on the X11 event queue until we receive notification from the |
39 // xserver that |w| has been mapped; StructureNotifyMask events on |w| are | 50 // xserver that |w| has been mapped; StructureNotifyMask events on |w| are |
40 // pulled out from the queue and dispatched out of order. | 51 // pulled out from the queue and dispatched out of order. |
41 // | 52 // |
42 // For those that know X11, this is really a wrapper around XWindowEvent | 53 // For those that know X11, this is really a wrapper around XWindowEvent |
43 // which still makes sure the preempted event is dispatched instead of | 54 // which still makes sure the preempted event is dispatched instead of |
44 // dropped on the floor. This method exists because mapping a window is | 55 // dropped on the floor. This method exists because mapping a window is |
45 // asynchronous (and we receive an XEvent when mapped), while there are also | 56 // asynchronous (and we receive an XEvent when mapped), while there are also |
46 // functions which require a mapped window. | 57 // functions which require a mapped window. |
47 void BlockUntilWindowMapped(XID window); | 58 void BlockUntilWindowMapped(XID window); |
48 | 59 |
49 protected: | |
50 XDisplay* display() { return display_; } | 60 XDisplay* display() { return display_; } |
51 | 61 |
52 private: | 62 void StopCurrentEventStream(); |
| 63 void OnDispatcherListChanged(); |
| 64 |
| 65 protected: |
53 // Extracts cookie data from |xevent| if it's of GenericType, and dispatches | 66 // Extracts cookie data from |xevent| if it's of GenericType, and dispatches |
54 // the event. This function also frees up the cookie data after dispatch is | 67 // the event. This function also frees up the cookie data after dispatch is |
55 // complete. | 68 // complete. |
56 uint32_t ExtractCookieDataDispatchEvent(XEvent* xevent); | 69 void ExtractCookieDataDispatchEvent(XEvent* xevent); |
57 | 70 |
58 // PlatformEventSource: | 71 // Handles updates after event has been dispatched. |
59 uint32_t DispatchEvent(XEvent* xevent) override; | 72 void PostDispatchEvent(XEvent* xevent); |
60 void StopCurrentEventStream() override; | 73 |
61 void OnDispatcherListChanged() override; | 74 private: |
| 75 static X11EventSource* instance_; |
| 76 |
| 77 X11EventSourceDelegate* delegate_; |
62 | 78 |
63 // The connection to the X11 server used to receive the events. | 79 // The connection to the X11 server used to receive the events. |
64 XDisplay* display_; | 80 XDisplay* display_; |
65 | 81 |
66 // Keeps track of whether this source should continue to dispatch all the | 82 // Keeps track of whether this source should continue to dispatch all the |
67 // available events. | 83 // available events. |
68 bool continue_stream_; | 84 bool continue_stream_ = true; |
69 | 85 |
70 scoped_ptr<X11HotplugEventHandler> hotplug_event_handler_; | 86 scoped_ptr<X11HotplugEventHandler> hotplug_event_handler_; |
71 | 87 |
72 DISALLOW_COPY_AND_ASSIGN(X11EventSource); | 88 DISALLOW_COPY_AND_ASSIGN(X11EventSource); |
73 }; | 89 }; |
74 | 90 |
75 } // namespace ui | 91 } // namespace ui |
76 | 92 |
77 #endif // UI_EVENTS_PLATFORM_X11_X11_EVENT_SOURCE_H_ | 93 #endif // UI_EVENTS_PLATFORM_X11_X11_EVENT_SOURCE_H_ |
OLD | NEW |