OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_OZONE_PLATFORM_X11_X11_EVENT_FACTORY_H_ |
6 #define UI_EVENTS_PLATFORM_X11_X11_EVENT_SOURCE_H_ | 6 #define UI_OZONE_PLATFORM_X11_X11_EVENT_FACTORY_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 "base/message_loop/message_loop.h" | |
13 #include "base/message_loop/message_pump_libevent.h" | |
12 #include "ui/events/events_export.h" | 14 #include "ui/events/events_export.h" |
13 #include "ui/events/platform/platform_event_source.h" | 15 #include "ui/events/platform/platform_event_source.h" |
14 #include "ui/gfx/x/x11_types.h" | 16 #include "ui/gfx/x/x11_types.h" |
17 #include "ui/ozone/platform/x11/x11_window_manager_ozone.h" | |
15 | 18 |
16 typedef struct _GPollFD GPollFD; | 19 typedef struct _GPollFD GPollFD; |
17 typedef struct _GSource GSource; | 20 typedef struct _GSource GSource; |
18 typedef union _XEvent XEvent; | 21 typedef union _XEvent XEvent; |
19 typedef unsigned long XID; | 22 typedef unsigned long XID; |
20 | 23 |
21 namespace ui { | 24 namespace ui { |
22 | 25 |
23 class X11HotplugEventHandler; | |
24 | |
25 // A PlatformEventSource implementation for reading events from X11 server and | 26 // A PlatformEventSource implementation for reading events from X11 server and |
26 // dispatching the events to the appropriate dispatcher. | 27 // dispatching the events to the appropriate dispatcher. |
27 class EVENTS_EXPORT X11EventSource : public PlatformEventSource { | 28 class EVENTS_EXPORT X11EventFactory |
sadrul
2016/01/21 14:53:01
Why can't we use X11EventSourceLibevent instead?
kylechar
2016/01/21 15:13:35
Similar X11Window the existing X11EventSourceLibev
| |
29 : public PlatformEventSource, | |
30 public base::MessagePumpLibevent::Watcher { | |
28 public: | 31 public: |
29 explicit X11EventSource(XDisplay* display); | 32 explicit X11EventFactory(XDisplay* display, |
30 ~X11EventSource() override; | 33 scoped_refptr<X11WindowManagerOzone> window_manager); |
34 ~X11EventFactory() override; | |
31 | 35 |
32 static X11EventSource* GetInstance(); | 36 static X11EventFactory* GetInstance(); |
33 | 37 |
34 // Called by the glib source dispatch function. Processes all (if any) | 38 // Called by the glib source dispatch function. Processes all (if any) |
35 // available X events. | 39 // available X events. |
36 void DispatchXEvents(); | 40 void DispatchXEvents(); |
37 | 41 |
38 // Blocks on the X11 event queue until we receive notification from the | 42 // Blocks on the X11 event queue until we receive notification from the |
39 // xserver that |w| has been mapped; StructureNotifyMask events on |w| are | 43 // xserver that |w| has been mapped; StructureNotifyMask events on |w| are |
40 // pulled out from the queue and dispatched out of order. | 44 // pulled out from the queue and dispatched out of order. |
41 // | 45 // |
42 // For those that know X11, this is really a wrapper around XWindowEvent | 46 // For those that know X11, this is really a wrapper around XWindowEvent |
43 // which still makes sure the preempted event is dispatched instead of | 47 // which still makes sure the preempted event is dispatched instead of |
44 // dropped on the floor. This method exists because mapping a window is | 48 // 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 | 49 // asynchronous (and we receive an XEvent when mapped), while there are also |
46 // functions which require a mapped window. | 50 // functions which require a mapped window. |
47 void BlockUntilWindowMapped(XID window); | 51 void BlockUntilWindowMapped(XID window); |
48 | 52 |
49 protected: | 53 private: |
50 XDisplay* display() { return display_; } | 54 void AddEventWatcher(); |
51 | 55 |
52 private: | |
53 // Extracts cookie data from |xevent| if it's of GenericType, and dispatches | 56 // 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 | 57 // the event. This function also frees up the cookie data after dispatch is |
55 // complete. | 58 // complete. |
56 uint32_t ExtractCookieDataDispatchEvent(XEvent* xevent); | 59 uint32_t ExtractCookieDataDispatchEvent(XEvent* xevent); |
57 | 60 |
58 // PlatformEventSource: | 61 // PlatformEventSource: |
59 uint32_t DispatchEvent(XEvent* xevent) override; | 62 uint32_t DispatchEvent(base::NativeEvent event) override; |
60 void StopCurrentEventStream() override; | 63 void StopCurrentEventStream() override; |
61 void OnDispatcherListChanged() override; | 64 void OnDispatcherListChanged() override; |
62 | 65 |
66 // base::MessagePumpLibevent::Watcher: | |
67 void OnFileCanReadWithoutBlocking(int fd) override; | |
68 void OnFileCanWriteWithoutBlocking(int fd) override; | |
69 | |
70 // Dispatches a XEvent for a XWindow that can't be translated to a ui::Event. | |
71 void DispatchXEventToXWindow(const XEvent& xevent); | |
72 | |
63 // The connection to the X11 server used to receive the events. | 73 // The connection to the X11 server used to receive the events. |
64 XDisplay* display_; | 74 XDisplay* display_; |
65 | 75 |
66 // Keeps track of whether this source should continue to dispatch all the | 76 // Keeps track of whether this source should continue to dispatch all the |
67 // available events. | 77 // available events. |
68 bool continue_stream_; | 78 bool continue_stream_ = true; |
69 | 79 |
70 scoped_ptr<X11HotplugEventHandler> hotplug_event_handler_; | 80 scoped_refptr<X11WindowManagerOzone> window_manager_; |
81 base::MessagePumpLibevent::FileDescriptorWatcher watcher_controller_; | |
82 bool initialized_ = false; | |
71 | 83 |
72 DISALLOW_COPY_AND_ASSIGN(X11EventSource); | 84 DISALLOW_COPY_AND_ASSIGN(X11EventFactory); |
73 }; | 85 }; |
74 | 86 |
75 } // namespace ui | 87 } // namespace ui |
76 | 88 |
77 #endif // UI_EVENTS_PLATFORM_X11_X11_EVENT_SOURCE_H_ | 89 #endif // UI_OZONE_PLATFORM_X11_X11_EVENT_FACTORY_H_ |
OLD | NEW |