Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(135)

Side by Side Diff: ui/events/platform/x11/x11_event_source.h

Issue 1602173005: Add PlatformWindow/Event related code for Ozone X11. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes for comments. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
14 #include "ui/gfx/x/x11_types.h" 13 #include "ui/gfx/x/x11_types.h"
15 14
16 typedef struct _GPollFD GPollFD;
17 typedef struct _GSource GSource;
18 typedef union _XEvent XEvent; 15 typedef union _XEvent XEvent;
19 typedef unsigned long XID; 16 typedef unsigned long XID;
20 17
21 namespace ui { 18 namespace ui {
22 19
23 class X11HotplugEventHandler; 20 class X11HotplugEventHandler;
24 21
25 // A PlatformEventSource implementation for reading events from X11 server and 22 // Responsible for notifying X11EventSource when new XEvents are available and
26 // dispatching the events to the appropriate dispatcher. 23 // processing/dispatching XEvents. Implementations will likely be a
27 class EVENTS_EXPORT X11EventSource : public PlatformEventSource { 24 // PlatformEventSource as well.
25 class X11EventSourceDelegate {
28 public: 26 public:
29 explicit X11EventSource(XDisplay* display); 27 X11EventSourceDelegate() = default;
30 ~X11EventSource() override; 28
29 // Processes (if necessary) and handles dispatching XEvents.
30 virtual void ProcessXEvent(XEvent* xevent) = 0;
31
32 private:
33 DISALLOW_COPY_AND_ASSIGN(X11EventSourceDelegate);
34 };
35
36 // Implementation of X11 event handling without actually being a
37 // PlatformEventSource. Handles getting, pre-process and post-processing
38 // XEvents.
sadrul 2016/02/08 17:28:32 This doesn't need to refer to PlatformEventSource.
kylechar 2016/02/08 19:08:09 Done.
39 class EVENTS_EXPORT X11EventSource {
40 public:
41 X11EventSource(X11EventSourceDelegate* delegate, XDisplay* display);
42 ~X11EventSource();
31 43
32 static X11EventSource* GetInstance(); 44 static X11EventSource* GetInstance();
33 45
34 // Called by the glib source dispatch function. Processes all (if any) 46 // Called when there is a new XEvent available. Processes all (if any)
35 // available X events. 47 // available X events.
36 void DispatchXEvents(); 48 void DispatchXEvents();
37 49
38 // Blocks on the X11 event queue until we receive notification from the 50 // Blocks on the X11 event queue until we receive notification from the
39 // xserver that |w| has been mapped; StructureNotifyMask events on |w| are 51 // xserver that |w| has been mapped; StructureNotifyMask events on |w| are
40 // pulled out from the queue and dispatched out of order. 52 // pulled out from the queue and dispatched out of order.
41 // 53 //
42 // For those that know X11, this is really a wrapper around XWindowEvent 54 // For those that know X11, this is really a wrapper around XWindowEvent
43 // which still makes sure the preempted event is dispatched instead of 55 // which still makes sure the preempted event is dispatched instead of
44 // dropped on the floor. This method exists because mapping a window is 56 // 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 57 // asynchronous (and we receive an XEvent when mapped), while there are also
46 // functions which require a mapped window. 58 // functions which require a mapped window.
47 void BlockUntilWindowMapped(XID window); 59 void BlockUntilWindowMapped(XID window);
48 60
49 protected:
50 XDisplay* display() { return display_; } 61 XDisplay* display() { return display_; }
51 62
52 private: 63 void StopCurrentEventStream();
64 void OnDispatcherListChanged();
65
66 protected:
53 // Extracts cookie data from |xevent| if it's of GenericType, and dispatches 67 // 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 68 // the event. This function also frees up the cookie data after dispatch is
55 // complete. 69 // complete.
56 uint32_t ExtractCookieDataDispatchEvent(XEvent* xevent); 70 void ExtractCookieDataDispatchEvent(XEvent* xevent);
57 71
58 // PlatformEventSource: 72 // Handles updates after event has been dispatched.
59 uint32_t DispatchEvent(XEvent* xevent) override; 73 void PostDispatchEvent(XEvent* xevent);
60 void StopCurrentEventStream() override; 74
61 void OnDispatcherListChanged() override; 75 private:
76 static X11EventSource* instance_;
77
78 X11EventSourceDelegate* delegate_;
62 79
63 // The connection to the X11 server used to receive the events. 80 // The connection to the X11 server used to receive the events.
64 XDisplay* display_; 81 XDisplay* display_;
65 82
66 // Keeps track of whether this source should continue to dispatch all the 83 // Keeps track of whether this source should continue to dispatch all the
67 // available events. 84 // available events.
68 bool continue_stream_; 85 bool continue_stream_ = true;
69 86
70 scoped_ptr<X11HotplugEventHandler> hotplug_event_handler_; 87 scoped_ptr<X11HotplugEventHandler> hotplug_event_handler_;
71 88
72 DISALLOW_COPY_AND_ASSIGN(X11EventSource); 89 DISALLOW_COPY_AND_ASSIGN(X11EventSource);
73 }; 90 };
74 91
75 } // namespace ui 92 } // namespace ui
76 93
77 #endif // UI_EVENTS_PLATFORM_X11_X11_EVENT_SOURCE_H_ 94 #endif // UI_EVENTS_PLATFORM_X11_X11_EVENT_SOURCE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698