| 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" | 13 #include "ui/events/platform/platform_event_source.h" |
| 14 #include "ui/gfx/x/x11_types.h" | 14 #include "ui/gfx/x/x11_types.h" |
| 15 | 15 |
| 16 typedef struct _GPollFD GPollFD; | |
| 17 typedef struct _GSource GSource; | |
| 18 typedef union _XEvent XEvent; | 16 typedef union _XEvent XEvent; |
| 19 typedef unsigned long XID; | 17 typedef unsigned long XID; |
| 20 | 18 |
| 21 namespace ui { | 19 namespace ui { |
| 22 | 20 |
| 23 class X11HotplugEventHandler; | 21 class X11HotplugEventHandler; |
| 24 | 22 |
| 25 // A PlatformEventSource implementation for reading events from X11 server and | 23 // Abstract PlatformEventSource implementation for reading events from X11 |
| 26 // dispatching the events to the appropriate dispatcher. | 24 // server. |
| 27 class EVENTS_EXPORT X11EventSource : public PlatformEventSource { | 25 class EVENTS_EXPORT X11EventSource : public PlatformEventSource { |
| 28 public: | 26 public: |
| 29 explicit X11EventSource(XDisplay* display); | 27 explicit X11EventSource(XDisplay* display); |
| 30 ~X11EventSource() override; | 28 ~X11EventSource() override; |
| 31 | 29 |
| 32 static X11EventSource* GetInstance(); | 30 static X11EventSource* GetInstance(); |
| 33 | 31 |
| 34 // Called by the glib source dispatch function. Processes all (if any) | 32 // Called when there is a new XEvent available. Processes all (if any) |
| 35 // available X events. | 33 // available X events. |
| 36 void DispatchXEvents(); | 34 void DispatchXEvents(); |
| 37 | 35 |
| 38 // Blocks on the X11 event queue until we receive notification from the | 36 // Blocks on the X11 event queue until we receive notification from the |
| 39 // xserver that |w| has been mapped; StructureNotifyMask events on |w| are | 37 // xserver that |w| has been mapped; StructureNotifyMask events on |w| are |
| 40 // pulled out from the queue and dispatched out of order. | 38 // pulled out from the queue and dispatched out of order. |
| 41 // | 39 // |
| 42 // For those that know X11, this is really a wrapper around XWindowEvent | 40 // For those that know X11, this is really a wrapper around XWindowEvent |
| 43 // which still makes sure the preempted event is dispatched instead of | 41 // which still makes sure the preempted event is dispatched instead of |
| 44 // dropped on the floor. This method exists because mapping a window is | 42 // 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 | 43 // asynchronous (and we receive an XEvent when mapped), while there are also |
| 46 // functions which require a mapped window. | 44 // functions which require a mapped window. |
| 47 void BlockUntilWindowMapped(XID window); | 45 void BlockUntilWindowMapped(XID window); |
| 48 | 46 |
| 49 protected: | 47 protected: |
| 50 XDisplay* display() { return display_; } | |
| 51 | |
| 52 private: | |
| 53 // Extracts cookie data from |xevent| if it's of GenericType, and dispatches | 48 // 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 | 49 // the event. This function also frees up the cookie data after dispatch is |
| 55 // complete. | 50 // complete. |
| 56 uint32_t ExtractCookieDataDispatchEvent(XEvent* xevent); | 51 void ExtractCookieDataDispatchEvent(XEvent* xevent); |
| 52 |
| 53 // Handles updates after event has been dispatched. |
| 54 void PostDispatchEvent(XEvent* xevent); |
| 57 | 55 |
| 58 // PlatformEventSource: | 56 // PlatformEventSource: |
| 59 uint32_t DispatchEvent(XEvent* xevent) override; | |
| 60 void StopCurrentEventStream() override; | 57 void StopCurrentEventStream() override; |
| 61 void OnDispatcherListChanged() override; | 58 void OnDispatcherListChanged() override; |
| 62 | 59 |
| 63 // The connection to the X11 server used to receive the events. | 60 // The connection to the X11 server used to receive the events. |
| 64 XDisplay* display_; | 61 XDisplay* display_; |
| 65 | 62 |
| 66 // Keeps track of whether this source should continue to dispatch all the | 63 // Keeps track of whether this source should continue to dispatch all the |
| 67 // available events. | 64 // available events. |
| 68 bool continue_stream_; | 65 bool continue_stream_ = true; |
| 69 | 66 |
| 70 scoped_ptr<X11HotplugEventHandler> hotplug_event_handler_; | 67 scoped_ptr<X11HotplugEventHandler> hotplug_event_handler_; |
| 71 | 68 |
| 69 private: |
| 72 DISALLOW_COPY_AND_ASSIGN(X11EventSource); | 70 DISALLOW_COPY_AND_ASSIGN(X11EventSource); |
| 73 }; | 71 }; |
| 74 | 72 |
| 75 } // namespace ui | 73 } // namespace ui |
| 76 | 74 |
| 77 #endif // UI_EVENTS_PLATFORM_X11_X11_EVENT_SOURCE_H_ | 75 #endif // UI_EVENTS_PLATFORM_X11_X11_EVENT_SOURCE_H_ |
| OLD | NEW |