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

Side by Side Diff: base/message_pump_aurax11.cc

Issue 10441028: aura/cros: Rename MessagePump{X => AuraX11} and move the atom cache into it. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix compile error in file added in the interim Created 8 years, 6 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_pump_aurax11.h ('k') | base/message_pump_observer.h » ('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 #include "base/message_pump_x.h" 5 #include "base/message_pump_aurax11.h"
6 6
7 #include <X11/extensions/XInput2.h> 7 #include <X11/extensions/XInput2.h>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
11 11
12 namespace { 12 namespace {
13 13
14 gboolean XSourcePrepare(GSource* source, gint* timeout_ms) { 14 gboolean XSourcePrepare(GSource* source, gint* timeout_ms) {
15 if (XPending(base::MessagePumpX::GetDefaultXDisplay())) 15 if (XPending(base::MessagePumpAuraX11::GetDefaultXDisplay()))
16 *timeout_ms = 0; 16 *timeout_ms = 0;
17 else 17 else
18 *timeout_ms = -1; 18 *timeout_ms = -1;
19 return FALSE; 19 return FALSE;
20 } 20 }
21 21
22 gboolean XSourceCheck(GSource* source) { 22 gboolean XSourceCheck(GSource* source) {
23 return XPending(base::MessagePumpX::GetDefaultXDisplay()); 23 return XPending(base::MessagePumpAuraX11::GetDefaultXDisplay());
24 } 24 }
25 25
26 gboolean XSourceDispatch(GSource* source, 26 gboolean XSourceDispatch(GSource* source,
27 GSourceFunc unused_func, 27 GSourceFunc unused_func,
28 gpointer data) { 28 gpointer data) {
29 base::MessagePumpX* pump = static_cast<base::MessagePumpX*>(data); 29 base::MessagePumpAuraX11* pump = static_cast<base::MessagePumpAuraX11*>(data);
30 return pump->DispatchXEvents(); 30 return pump->DispatchXEvents();
31 } 31 }
32 32
33 GSourceFuncs XSourceFuncs = { 33 GSourceFuncs XSourceFuncs = {
34 XSourcePrepare, 34 XSourcePrepare,
35 XSourceCheck, 35 XSourceCheck,
36 XSourceDispatch, 36 XSourceDispatch,
37 NULL 37 NULL
38 }; 38 };
39 39
40 // The message-pump opens a connection to the display and owns it. 40 // The message-pump opens a connection to the display and owns it.
41 Display* g_xdisplay = NULL; 41 Display* g_xdisplay = NULL;
42 42
43 // The default dispatcher to process native events when no dispatcher 43 // The default dispatcher to process native events when no dispatcher
44 // is specified. 44 // is specified.
45 base::MessagePumpDispatcher* g_default_dispatcher = NULL; 45 base::MessagePumpDispatcher* g_default_dispatcher = NULL;
46 46
47 bool InitializeXInput2Internal() { 47 bool InitializeXInput2Internal() {
48 Display* display = base::MessagePumpX::GetDefaultXDisplay(); 48 Display* display = base::MessagePumpAuraX11::GetDefaultXDisplay();
49 if (!display) 49 if (!display)
50 return false; 50 return false;
51 51
52 int event, err; 52 int event, err;
53 53
54 int xiopcode; 54 int xiopcode;
55 if (!XQueryExtension(display, "XInputExtension", &xiopcode, &event, &err)) { 55 if (!XQueryExtension(display, "XInputExtension", &xiopcode, &event, &err)) {
56 DVLOG(1) << "X Input extension not available."; 56 DVLOG(1) << "X Input extension not available.";
57 return false; 57 return false;
58 } 58 }
(...skipping 21 matching lines...) Expand all
80 80
81 bool InitializeXInput2() { 81 bool InitializeXInput2() {
82 static bool xinput2_supported = InitializeXInput2Internal(); 82 static bool xinput2_supported = InitializeXInput2Internal();
83 return xinput2_supported; 83 return xinput2_supported;
84 } 84 }
85 85
86 } // namespace 86 } // namespace
87 87
88 namespace base { 88 namespace base {
89 89
90 MessagePumpX::MessagePumpX() : MessagePumpGlib(), 90 MessagePumpAuraX11::MessagePumpAuraX11() : MessagePumpGlib(),
91 x_source_(NULL) { 91 x_source_(NULL) {
92 InitializeXInput2(); 92 InitializeXInput2();
93 InitXSource(); 93 InitXSource();
94 } 94 }
95 95
96 // static 96 // static
97 Display* MessagePumpX::GetDefaultXDisplay() { 97 Display* MessagePumpAuraX11::GetDefaultXDisplay() {
98 if (!g_xdisplay) 98 if (!g_xdisplay)
99 g_xdisplay = XOpenDisplay(NULL); 99 g_xdisplay = XOpenDisplay(NULL);
100 return g_xdisplay; 100 return g_xdisplay;
101 } 101 }
102 102
103 // static 103 // static
104 bool MessagePumpX::HasXInput2() { 104 bool MessagePumpAuraX11::HasXInput2() {
105 return InitializeXInput2(); 105 return InitializeXInput2();
106 } 106 }
107 107
108 // static 108 // static
109 void MessagePumpX::SetDefaultDispatcher(MessagePumpDispatcher* dispatcher) { 109 void MessagePumpAuraX11::SetDefaultDispatcher(
110 MessagePumpDispatcher* dispatcher) {
110 DCHECK(!g_default_dispatcher || !dispatcher); 111 DCHECK(!g_default_dispatcher || !dispatcher);
111 g_default_dispatcher = dispatcher; 112 g_default_dispatcher = dispatcher;
112 } 113 }
113 114
114 gboolean MessagePumpX::DispatchXEvents() { 115 gboolean MessagePumpAuraX11::DispatchXEvents() {
115 Display* display = GetDefaultXDisplay(); 116 Display* display = GetDefaultXDisplay();
116 DCHECK(display); 117 DCHECK(display);
117 MessagePumpDispatcher* dispatcher = 118 MessagePumpDispatcher* dispatcher =
118 GetDispatcher() ? GetDispatcher() : g_default_dispatcher; 119 GetDispatcher() ? GetDispatcher() : g_default_dispatcher;
119 120
120 // In the general case, we want to handle all pending events before running 121 // In the general case, we want to handle all pending events before running
121 // the tasks. This is what happens in the message_pump_glib case. 122 // the tasks. This is what happens in the message_pump_glib case.
122 while (XPending(display)) { 123 while (XPending(display)) {
123 XEvent xev; 124 XEvent xev;
124 XNextEvent(display, &xev); 125 XNextEvent(display, &xev);
125 if (dispatcher && ProcessXEvent(dispatcher, &xev)) 126 if (dispatcher && ProcessXEvent(dispatcher, &xev))
126 return TRUE; 127 return TRUE;
127 } 128 }
128 return TRUE; 129 return TRUE;
129 } 130 }
130 131
131 MessagePumpX::~MessagePumpX() { 132 MessagePumpAuraX11::~MessagePumpAuraX11() {
132 g_source_destroy(x_source_); 133 g_source_destroy(x_source_);
133 g_source_unref(x_source_); 134 g_source_unref(x_source_);
134 XCloseDisplay(g_xdisplay); 135 XCloseDisplay(g_xdisplay);
135 g_xdisplay = NULL; 136 g_xdisplay = NULL;
136 } 137 }
137 138
138 void MessagePumpX::InitXSource() { 139 void MessagePumpAuraX11::InitXSource() {
139 // CHECKs are to help track down crbug.com/113106. 140 // CHECKs are to help track down crbug.com/113106.
140 CHECK(!x_source_); 141 CHECK(!x_source_);
141 Display* display = GetDefaultXDisplay(); 142 Display* display = GetDefaultXDisplay();
142 CHECK(display) << "Unable to get connection to X server"; 143 CHECK(display) << "Unable to get connection to X server";
143 x_poll_.reset(new GPollFD()); 144 x_poll_.reset(new GPollFD());
144 CHECK(x_poll_.get()); 145 CHECK(x_poll_.get());
145 x_poll_->fd = ConnectionNumber(display); 146 x_poll_->fd = ConnectionNumber(display);
146 x_poll_->events = G_IO_IN; 147 x_poll_->events = G_IO_IN;
147 148
148 x_source_ = g_source_new(&XSourceFuncs, sizeof(GSource)); 149 x_source_ = g_source_new(&XSourceFuncs, sizeof(GSource));
149 g_source_add_poll(x_source_, x_poll_.get()); 150 g_source_add_poll(x_source_, x_poll_.get());
150 g_source_set_can_recurse(x_source_, TRUE); 151 g_source_set_can_recurse(x_source_, TRUE);
151 g_source_set_callback(x_source_, NULL, this, NULL); 152 g_source_set_callback(x_source_, NULL, this, NULL);
152 g_source_attach(x_source_, g_main_context_default()); 153 g_source_attach(x_source_, g_main_context_default());
153 } 154 }
154 155
155 bool MessagePumpX::ProcessXEvent(MessagePumpDispatcher* dispatcher, 156 bool MessagePumpAuraX11::ProcessXEvent(MessagePumpDispatcher* dispatcher,
156 XEvent* xev) { 157 XEvent* xev) {
157 bool should_quit = false; 158 bool should_quit = false;
158 159
159 bool have_cookie = false; 160 bool have_cookie = false;
160 if (xev->type == GenericEvent && 161 if (xev->type == GenericEvent &&
161 XGetEventData(xev->xgeneric.display, &xev->xcookie)) { 162 XGetEventData(xev->xgeneric.display, &xev->xcookie)) {
162 have_cookie = true; 163 have_cookie = true;
163 } 164 }
164 165
165 if (!WillProcessXEvent(xev)) { 166 if (!WillProcessXEvent(xev)) {
166 if (!dispatcher->Dispatch(xev)) { 167 if (!dispatcher->Dispatch(xev)) {
167 should_quit = true; 168 should_quit = true;
168 Quit(); 169 Quit();
169 } 170 }
170 DidProcessXEvent(xev); 171 DidProcessXEvent(xev);
171 } 172 }
172 173
173 if (have_cookie) { 174 if (have_cookie) {
174 XFreeEventData(xev->xgeneric.display, &xev->xcookie); 175 XFreeEventData(xev->xgeneric.display, &xev->xcookie);
175 } 176 }
176 177
177 return should_quit; 178 return should_quit;
178 } 179 }
179 180
180 bool MessagePumpX::WillProcessXEvent(XEvent* xevent) { 181 bool MessagePumpAuraX11::WillProcessXEvent(XEvent* xevent) {
181 if (!observers().might_have_observers()) 182 if (!observers().might_have_observers())
182 return false; 183 return false;
183 ObserverListBase<MessagePumpObserver>::Iterator it(observers()); 184 ObserverListBase<MessagePumpObserver>::Iterator it(observers());
184 MessagePumpObserver* obs; 185 MessagePumpObserver* obs;
185 while ((obs = it.GetNext()) != NULL) { 186 while ((obs = it.GetNext()) != NULL) {
186 if (obs->WillProcessEvent(xevent)) 187 if (obs->WillProcessEvent(xevent))
187 return true; 188 return true;
188 } 189 }
189 return false; 190 return false;
190 } 191 }
191 192
192 void MessagePumpX::DidProcessXEvent(XEvent* xevent) { 193 void MessagePumpAuraX11::DidProcessXEvent(XEvent* xevent) {
193 FOR_EACH_OBSERVER(MessagePumpObserver, observers(), DidProcessEvent(xevent)); 194 FOR_EACH_OBSERVER(MessagePumpObserver, observers(), DidProcessEvent(xevent));
194 } 195 }
195 196
196 } // namespace base 197 } // namespace base
OLDNEW
« no previous file with comments | « base/message_pump_aurax11.h ('k') | base/message_pump_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698