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 <memory> | 10 #include <memory> |
| 11 #include <stack> |
11 | 12 |
12 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/optional.h" |
13 #include "ui/events/events_export.h" | 15 #include "ui/events/events_export.h" |
14 #include "ui/gfx/x/x11_types.h" | 16 #include "ui/gfx/x/x11_types.h" |
15 | 17 |
16 using Time = unsigned long; | 18 using Time = unsigned long; |
17 using XEvent = union _XEvent; | 19 using XEvent = union _XEvent; |
18 using XID = unsigned long; | 20 using XID = unsigned long; |
19 using XWindow = unsigned long; | 21 using XWindow = unsigned long; |
20 | 22 |
| 23 namespace gfx { |
| 24 class Point; |
| 25 } |
| 26 |
21 namespace ui { | 27 namespace ui { |
22 | 28 |
23 class X11HotplugEventHandler; | 29 class X11HotplugEventHandler; |
24 class XScopedEventSelector; | 30 class XScopedEventSelector; |
25 | 31 |
26 // Responsible for notifying X11EventSource when new XEvents are available and | 32 // Responsible for notifying X11EventSource when new XEvents are available and |
27 // processing/dispatching XEvents. Implementations will likely be a | 33 // processing/dispatching XEvents. Implementations will likely be a |
28 // PlatformEventSource. | 34 // PlatformEventSource. |
29 class X11EventSourceDelegate { | 35 class X11EventSourceDelegate { |
30 public: | 36 public: |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 | 76 |
71 void BlockUntilWindowUnmapped(XID window); | 77 void BlockUntilWindowUnmapped(XID window); |
72 | 78 |
73 XDisplay* display() { return display_; } | 79 XDisplay* display() { return display_; } |
74 | 80 |
75 // Returns the timestamp of the event currently being dispatched. Falls back | 81 // Returns the timestamp of the event currently being dispatched. Falls back |
76 // on GetCurrentServerTime() if there's no event being dispatched, or if the | 82 // on GetCurrentServerTime() if there's no event being dispatched, or if the |
77 // current event does not have a timestamp. | 83 // current event does not have a timestamp. |
78 Time GetTimestamp(); | 84 Time GetTimestamp(); |
79 | 85 |
| 86 // Returns the root pointer location only if there is an event being |
| 87 // dispatched that contains that information. |
| 88 base::Optional<gfx::Point> GetRootCursorLocationFromCurrentEvent() const; |
| 89 |
80 void StopCurrentEventStream(); | 90 void StopCurrentEventStream(); |
81 void OnDispatcherListChanged(); | 91 void OnDispatcherListChanged(); |
82 | 92 |
83 protected: | 93 protected: |
84 // Extracts cookie data from |xevent| if it's of GenericType, and dispatches | 94 // Extracts cookie data from |xevent| if it's of GenericType, and dispatches |
85 // the event. This function also frees up the cookie data after dispatch is | 95 // the event. This function also frees up the cookie data after dispatch is |
86 // complete. | 96 // complete. |
87 void ExtractCookieDataDispatchEvent(XEvent* xevent); | 97 void ExtractCookieDataDispatchEvent(XEvent* xevent); |
88 | 98 |
89 // Handles updates after event has been dispatched. | 99 // Handles updates after event has been dispatched. |
90 void PostDispatchEvent(XEvent* xevent); | 100 void PostDispatchEvent(XEvent* xevent); |
91 | 101 |
92 // Block until receiving a structure notify event of |type| on |window|. | 102 // Block until receiving a structure notify event of |type| on |window|. |
93 // Dispatch all encountered events prior to the one we're blocking on. | 103 // Dispatch all encountered events prior to the one we're blocking on. |
94 void BlockOnWindowStructureEvent(XID window, int type); | 104 void BlockOnWindowStructureEvent(XID window, int type); |
95 | 105 |
96 // Explicitly asks the X11 server for the current timestamp, and updates | 106 // Explicitly asks the X11 server for the current timestamp, and updates |
97 // |last_seen_server_time_| with this value. | 107 // |last_seen_server_time_| with this value. |
98 Time GetCurrentServerTime(); | 108 Time GetCurrentServerTime(); |
99 | 109 |
100 private: | 110 private: |
101 static X11EventSource* instance_; | 111 static X11EventSource* instance_; |
102 | 112 |
103 X11EventSourceDelegate* delegate_; | 113 X11EventSourceDelegate* delegate_; |
104 | 114 |
105 // The connection to the X11 server used to receive the events. | 115 // The connection to the X11 server used to receive the events. |
106 XDisplay* display_; | 116 XDisplay* display_; |
107 | 117 |
108 // The timestamp of the event being dispatched. | 118 // Events currently being dispatched. The topmost event in this stack |
109 Time event_timestamp_; | 119 // corresponds to the deepest-nested message loop. |
| 120 std::stack<XEvent*> dispatching_events_; |
110 | 121 |
111 // State necessary for UpdateLastSeenServerTime | 122 // State necessary for UpdateLastSeenServerTime |
112 bool dummy_initialized_; | 123 bool dummy_initialized_; |
113 XWindow dummy_window_; | 124 XWindow dummy_window_; |
114 XAtom dummy_atom_; | 125 XAtom dummy_atom_; |
115 std::unique_ptr<XScopedEventSelector> dummy_window_events_; | 126 std::unique_ptr<XScopedEventSelector> dummy_window_events_; |
116 | 127 |
117 // Keeps track of whether this source should continue to dispatch all the | 128 // Keeps track of whether this source should continue to dispatch all the |
118 // available events. | 129 // available events. |
119 bool continue_stream_ = true; | 130 bool continue_stream_ = true; |
120 | 131 |
121 std::unique_ptr<X11HotplugEventHandler> hotplug_event_handler_; | 132 std::unique_ptr<X11HotplugEventHandler> hotplug_event_handler_; |
122 | 133 |
123 DISALLOW_COPY_AND_ASSIGN(X11EventSource); | 134 DISALLOW_COPY_AND_ASSIGN(X11EventSource); |
124 }; | 135 }; |
125 | 136 |
126 } // namespace ui | 137 } // namespace ui |
127 | 138 |
128 #endif // UI_EVENTS_PLATFORM_X11_X11_EVENT_SOURCE_H_ | 139 #endif // UI_EVENTS_PLATFORM_X11_X11_EVENT_SOURCE_H_ |
OLD | NEW |