OLD | NEW |
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_loop/message_pump_x11.h" | 5 #include "base/message_loop/message_pump_x11.h" |
6 | 6 |
7 #include <glib.h> | 7 #include <glib.h> |
8 #include <X11/X.h> | 8 #include <X11/X.h> |
9 #include <X11/extensions/XInput2.h> | 9 #include <X11/extensions/XInput2.h> |
10 #include <X11/XKBlib.h> | 10 #include <X11/XKBlib.h> |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 // method and destroyed whenever ~MessagePumpX11() is called. We do this | 46 // method and destroyed whenever ~MessagePumpX11() is called. We do this |
47 // for historical reasons so user code can call | 47 // for historical reasons so user code can call |
48 // MessagePumpForUI::GetDefaultXDisplay() where MessagePumpForUI is a typedef | 48 // MessagePumpForUI::GetDefaultXDisplay() where MessagePumpForUI is a typedef |
49 // to whatever type in the current build. | 49 // to whatever type in the current build. |
50 // | 50 // |
51 // TODO(erg): This can be changed to something more sane like | 51 // TODO(erg): This can be changed to something more sane like |
52 // MessagePumpX11::Current()->display() once MessagePumpGtk goes away. | 52 // MessagePumpX11::Current()->display() once MessagePumpGtk goes away. |
53 Display* g_xdisplay = NULL; | 53 Display* g_xdisplay = NULL; |
54 int g_xinput_opcode = -1; | 54 int g_xinput_opcode = -1; |
55 | 55 |
56 bool InitializeXInput2Internal() { | 56 bool InitializeXInput2() { |
57 Display* display = MessagePumpX11::GetDefaultXDisplay(); | 57 Display* display = MessagePumpX11::GetDefaultXDisplay(); |
58 if (!display) | 58 if (!display) |
59 return false; | 59 return false; |
60 | 60 |
61 int event, err; | 61 int event, err; |
62 | 62 |
63 int xiopcode; | 63 int xiopcode; |
64 if (!XQueryExtension(display, "XInputExtension", &xiopcode, &event, &err)) { | 64 if (!XQueryExtension(display, "XInputExtension", &xiopcode, &event, &err)) { |
65 DVLOG(1) << "X Input extension not available."; | 65 DVLOG(1) << "X Input extension not available."; |
66 return false; | 66 return false; |
(...skipping 23 matching lines...) Expand all Loading... |
90 | 90 |
91 Window FindEventTarget(const NativeEvent& xev) { | 91 Window FindEventTarget(const NativeEvent& xev) { |
92 Window target = xev->xany.window; | 92 Window target = xev->xany.window; |
93 if (xev->type == GenericEvent && | 93 if (xev->type == GenericEvent && |
94 static_cast<XIEvent*>(xev->xcookie.data)->extension == g_xinput_opcode) { | 94 static_cast<XIEvent*>(xev->xcookie.data)->extension == g_xinput_opcode) { |
95 target = static_cast<XIDeviceEvent*>(xev->xcookie.data)->event; | 95 target = static_cast<XIDeviceEvent*>(xev->xcookie.data)->event; |
96 } | 96 } |
97 return target; | 97 return target; |
98 } | 98 } |
99 | 99 |
100 bool InitializeXInput2() { | |
101 static bool xinput2_supported = InitializeXInput2Internal(); | |
102 return xinput2_supported; | |
103 } | |
104 | |
105 bool InitializeXkb() { | 100 bool InitializeXkb() { |
106 Display* display = MessagePumpX11::GetDefaultXDisplay(); | 101 Display* display = MessagePumpX11::GetDefaultXDisplay(); |
107 if (!display) | 102 if (!display) |
108 return false; | 103 return false; |
109 | 104 |
110 int opcode, event, error; | 105 int opcode, event, error; |
111 int major = XkbMajorVersion; | 106 int major = XkbMajorVersion; |
112 int minor = XkbMinorVersion; | 107 int minor = XkbMinorVersion; |
113 if (!XkbQueryExtension(display, &opcode, &event, &error, &major, &minor)) { | 108 if (!XkbQueryExtension(display, &opcode, &event, &error, &major, &minor)) { |
114 DVLOG(1) << "Xkb extension not available."; | 109 DVLOG(1) << "Xkb extension not available."; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 g_xdisplay = NULL; | 141 g_xdisplay = NULL; |
147 } | 142 } |
148 | 143 |
149 // static | 144 // static |
150 Display* MessagePumpX11::GetDefaultXDisplay() { | 145 Display* MessagePumpX11::GetDefaultXDisplay() { |
151 if (!g_xdisplay) | 146 if (!g_xdisplay) |
152 g_xdisplay = XOpenDisplay(NULL); | 147 g_xdisplay = XOpenDisplay(NULL); |
153 return g_xdisplay; | 148 return g_xdisplay; |
154 } | 149 } |
155 | 150 |
156 // static | |
157 bool MessagePumpX11::HasXInput2() { | |
158 return InitializeXInput2(); | |
159 } | |
160 | |
161 #if defined(TOOLKIT_GTK) | 151 #if defined(TOOLKIT_GTK) |
162 // static | 152 // static |
163 MessagePumpX11* MessagePumpX11::Current() { | 153 MessagePumpX11* MessagePumpX11::Current() { |
164 MessageLoop* loop = MessageLoop::current(); | 154 MessageLoop* loop = MessageLoop::current(); |
165 return static_cast<MessagePumpX11*>(loop->pump_gpu()); | 155 return static_cast<MessagePumpX11*>(loop->pump_gpu()); |
166 } | 156 } |
167 #else | 157 #else |
168 // static | 158 // static |
169 MessagePumpX11* MessagePumpX11::Current() { | 159 MessagePumpX11* MessagePumpX11::Current() { |
170 MessageLoopForUI* loop = MessageLoopForUI::current(); | 160 MessageLoopForUI* loop = MessageLoopForUI::current(); |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 if (FindEventTarget(xev) == x_root_window_) { | 304 if (FindEventTarget(xev) == x_root_window_) { |
315 FOR_EACH_OBSERVER(MessagePumpDispatcher, root_window_dispatchers_, | 305 FOR_EACH_OBSERVER(MessagePumpDispatcher, root_window_dispatchers_, |
316 Dispatch(xev)); | 306 Dispatch(xev)); |
317 return true; | 307 return true; |
318 } | 308 } |
319 MessagePumpDispatcher* dispatcher = GetDispatcherForXEvent(xev); | 309 MessagePumpDispatcher* dispatcher = GetDispatcherForXEvent(xev); |
320 return dispatcher ? dispatcher->Dispatch(xev) : true; | 310 return dispatcher ? dispatcher->Dispatch(xev) : true; |
321 } | 311 } |
322 | 312 |
323 } // namespace base | 313 } // namespace base |
OLD | NEW |