| 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 | 11 |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "ui/events/events_export.h" | 13 #include "ui/events/events_export.h" |
| 14 #include "ui/gfx/x/x11_types.h" | 14 #include "ui/gfx/x/x11_types.h" |
| 15 | 15 |
| 16 typedef union _XEvent XEvent; | 16 using Time = unsigned long; |
| 17 typedef unsigned long XID; | 17 using XEvent = union _XEvent; |
| 18 using XID = unsigned long; |
| 18 | 19 |
| 19 namespace ui { | 20 namespace ui { |
| 20 | 21 |
| 21 class X11HotplugEventHandler; | 22 class X11HotplugEventHandler; |
| 22 | 23 |
| 23 // Responsible for notifying X11EventSource when new XEvents are available and | 24 // Responsible for notifying X11EventSource when new XEvents are available and |
| 24 // processing/dispatching XEvents. Implementations will likely be a | 25 // processing/dispatching XEvents. Implementations will likely be a |
| 25 // PlatformEventSource. | 26 // PlatformEventSource. |
| 26 class X11EventSourceDelegate { | 27 class X11EventSourceDelegate { |
| 27 public: | 28 public: |
| (...skipping 24 matching lines...) Expand all Loading... |
| 52 // pulled out from the queue and dispatched out of order. | 53 // pulled out from the queue and dispatched out of order. |
| 53 // | 54 // |
| 54 // For those that know X11, this is really a wrapper around XWindowEvent | 55 // For those that know X11, this is really a wrapper around XWindowEvent |
| 55 // which still makes sure the preempted event is dispatched instead of | 56 // which still makes sure the preempted event is dispatched instead of |
| 56 // dropped on the floor. This method exists because mapping a window is | 57 // dropped on the floor. This method exists because mapping a window is |
| 57 // asynchronous (and we receive an XEvent when mapped), while there are also | 58 // asynchronous (and we receive an XEvent when mapped), while there are also |
| 58 // functions which require a mapped window. | 59 // functions which require a mapped window. |
| 59 void BlockUntilWindowMapped(XID window); | 60 void BlockUntilWindowMapped(XID window); |
| 60 | 61 |
| 61 XDisplay* display() { return display_; } | 62 XDisplay* display() { return display_; } |
| 63 Time last_seen_server_time() const { return last_seen_server_time_; } |
| 62 | 64 |
| 63 void StopCurrentEventStream(); | 65 void StopCurrentEventStream(); |
| 64 void OnDispatcherListChanged(); | 66 void OnDispatcherListChanged(); |
| 65 | 67 |
| 66 protected: | 68 protected: |
| 67 // Extracts cookie data from |xevent| if it's of GenericType, and dispatches | 69 // Extracts cookie data from |xevent| if it's of GenericType, and dispatches |
| 68 // the event. This function also frees up the cookie data after dispatch is | 70 // the event. This function also frees up the cookie data after dispatch is |
| 69 // complete. | 71 // complete. |
| 70 void ExtractCookieDataDispatchEvent(XEvent* xevent); | 72 void ExtractCookieDataDispatchEvent(XEvent* xevent); |
| 71 | 73 |
| 72 // Handles updates after event has been dispatched. | 74 // Handles updates after event has been dispatched. |
| 73 void PostDispatchEvent(XEvent* xevent); | 75 void PostDispatchEvent(XEvent* xevent); |
| 74 | 76 |
| 75 private: | 77 private: |
| 78 void ExtractTimeFromXEvent(const XEvent& xevent); |
| 79 |
| 76 static X11EventSource* instance_; | 80 static X11EventSource* instance_; |
| 77 | 81 |
| 78 X11EventSourceDelegate* delegate_; | 82 X11EventSourceDelegate* delegate_; |
| 79 | 83 |
| 80 // The connection to the X11 server used to receive the events. | 84 // The connection to the X11 server used to receive the events. |
| 81 XDisplay* display_; | 85 XDisplay* display_; |
| 82 | 86 |
| 87 // The last timestamp seen in an XEvent. |
| 88 Time last_seen_server_time_; |
| 89 |
| 83 // Keeps track of whether this source should continue to dispatch all the | 90 // Keeps track of whether this source should continue to dispatch all the |
| 84 // available events. | 91 // available events. |
| 85 bool continue_stream_ = true; | 92 bool continue_stream_ = true; |
| 86 | 93 |
| 87 std::unique_ptr<X11HotplugEventHandler> hotplug_event_handler_; | 94 std::unique_ptr<X11HotplugEventHandler> hotplug_event_handler_; |
| 88 | 95 |
| 89 DISALLOW_COPY_AND_ASSIGN(X11EventSource); | 96 DISALLOW_COPY_AND_ASSIGN(X11EventSource); |
| 90 }; | 97 }; |
| 91 | 98 |
| 92 } // namespace ui | 99 } // namespace ui |
| 93 | 100 |
| 94 #endif // UI_EVENTS_PLATFORM_X11_X11_EVENT_SOURCE_H_ | 101 #endif // UI_EVENTS_PLATFORM_X11_X11_EVENT_SOURCE_H_ |
| OLD | NEW |