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

Side by Side Diff: base/message_loop/message_pump_x11.h

Issue 219743002: x11: Move X event handling out of the message-pump. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: tot-merge-r261267 Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « base/message_loop/message_loop.cc ('k') | base/message_loop/message_pump_x11.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 BASE_MESSAGE_LOOP_MESSAGE_PUMP_X11_H 5 #ifndef BASE_MESSAGE_LOOP_MESSAGE_PUMP_X11_H
6 #define BASE_MESSAGE_LOOP_MESSAGE_PUMP_X11_H 6 #define BASE_MESSAGE_LOOP_MESSAGE_PUMP_X11_H
7 7
8 #include <bitset> 8 #include <bitset>
9 #include <map> 9 #include <map>
10 10
(...skipping 13 matching lines...) Expand all
24 typedef struct _GSource GSource; 24 typedef struct _GSource GSource;
25 typedef struct _XDisplay Display; 25 typedef struct _XDisplay Display;
26 26
27 namespace base { 27 namespace base {
28 28
29 // This class implements a message-pump for dispatching X events. 29 // This class implements a message-pump for dispatching X events.
30 // 30 //
31 // If there's a current dispatcher given through RunWithDispatcher(), that 31 // If there's a current dispatcher given through RunWithDispatcher(), that
32 // dispatcher receives events. Otherwise, we route to messages to dispatchers 32 // dispatcher receives events. Otherwise, we route to messages to dispatchers
33 // who have subscribed to messages from a specific X11 window. 33 // who have subscribed to messages from a specific X11 window.
34 class BASE_EXPORT MessagePumpX11 : public MessagePumpGlib, 34 class BASE_EXPORT MessagePumpX11 : public MessagePumpGlib {
35 public MessagePumpDispatcher {
36 public: 35 public:
37 MessagePumpX11(); 36 MessagePumpX11();
38 virtual ~MessagePumpX11(); 37 virtual ~MessagePumpX11();
39 38
40 // Returns default X Display. 39 // Returns default X Display.
41 static Display* GetDefaultXDisplay(); 40 static Display* GetDefaultXDisplay();
42 41
43 // Returns the UI or GPU message pump. 42 // Returns the UI or GPU message pump.
44 static MessagePumpX11* Current(); 43 static MessagePumpX11* Current();
45 44
46 // Adds/Removes |dispatcher| for the |xid|. This will route all messages from
47 // the window |xid| to |dispatcher.
48 void AddDispatcherForWindow(MessagePumpDispatcher* dispatcher,
49 unsigned long xid);
50 void RemoveDispatcherForWindow(unsigned long xid);
51
52 // Adds/Removes |dispatcher| to receive all events sent to the X root
53 // window. A root window can have multiple dispatchers, and events on root
54 // windows will be dispatched to all.
55 void AddDispatcherForRootWindow(MessagePumpDispatcher* dispatcher);
56 void RemoveDispatcherForRootWindow(MessagePumpDispatcher* dispatcher);
57
58 // Adds an Observer, which will start receiving notifications immediately. 45 // Adds an Observer, which will start receiving notifications immediately.
59 void AddObserver(MessagePumpObserver* observer); 46 void AddObserver(MessagePumpObserver* observer);
60 47
61 // Removes an Observer. It is safe to call this method while an Observer is 48 // Removes an Observer. It is safe to call this method while an Observer is
62 // receiving a notification callback. 49 // receiving a notification callback.
63 void RemoveObserver(MessagePumpObserver* observer); 50 void RemoveObserver(MessagePumpObserver* observer);
64 51
65 // Internal function. Called by the glib source dispatch function. Processes
66 // all available X events.
67 void DispatchXEvents();
68
69 // Blocks on the X11 event queue until we receive notification from the
70 // xserver that |w| has been mapped; StructureNotifyMask events on |w| are
71 // pulled out from the queue and dispatched out of order.
72 //
73 // For those that know X11, this is really a wrapper around XWindowEvent
74 // which still makes sure the preempted event is dispatched instead of
75 // dropped on the floor. This method exists because mapping a window is
76 // asynchronous (and we receive an XEvent when mapped), while there are also
77 // functions which require a mapped window.
78 void BlockUntilWindowMapped(unsigned long xid);
79
80 private:
81 typedef std::map<unsigned long, MessagePumpDispatcher*> DispatchersMap;
82
83 // Initializes the glib event source for X.
84 void InitXSource();
85
86 // Dispatches the event to the specified dispatcher.
87 void ProcessXEvent(MessagePumpDispatcher* dispatcher, XEvent* event);
88
89 // Sends the event to the observers. If an observer returns true, then it does 52 // Sends the event to the observers. If an observer returns true, then it does
90 // not send the event to any other observers and returns true. Returns false 53 // not send the event to any other observers and returns true. Returns false
91 // if no observer returns true. 54 // if no observer returns true.
92 bool WillProcessXEvent(XEvent* xevent); 55 bool WillProcessXEvent(XEvent* xevent);
93 void DidProcessXEvent(XEvent* xevent); 56 void DidProcessXEvent(XEvent* xevent);
94 57
95 // Returns the Dispatcher based on the event's target window. 58 private:
96 MessagePumpDispatcher* GetDispatcherForXEvent(const NativeEvent& xev) const;
97
98 ObserverList<MessagePumpObserver>& observers() { return observers_; }
99
100 // Overridden from MessagePumpDispatcher:
101 virtual uint32_t Dispatch(const NativeEvent& event) OVERRIDE;
102
103 // The event source for X events.
104 GSource* x_source_;
105
106 // The poll attached to |x_source_|.
107 scoped_ptr<GPollFD> x_poll_;
108
109 DispatchersMap dispatchers_;
110
111 // Dispatch calls can cause addition of new dispatchers as we iterate
112 // through them. Use ObserverList to ensure the iterator remains valid across
113 // additions.
114 ObserverList<MessagePumpDispatcher> root_window_dispatchers_;
115
116 // List of observers. 59 // List of observers.
117 ObserverList<MessagePumpObserver> observers_; 60 ObserverList<MessagePumpObserver> observers_;
118 61
119 unsigned long x_root_window_;
120
121 DISALLOW_COPY_AND_ASSIGN(MessagePumpX11); 62 DISALLOW_COPY_AND_ASSIGN(MessagePumpX11);
122 }; 63 };
123 64
124 #if !defined(TOOLKIT_GTK) 65 #if !defined(TOOLKIT_GTK)
125 typedef MessagePumpX11 MessagePumpForUI; 66 typedef MessagePumpX11 MessagePumpForUI;
126 #endif 67 #endif
127 68
128 } // namespace base 69 } // namespace base
129 70
130 #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_X11_H 71 #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_X11_H
OLDNEW
« no previous file with comments | « base/message_loop/message_loop.cc ('k') | base/message_loop/message_pump_x11.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698