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