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 InitializeXInput2() { | 56 bool InitializeXInput2Internal() { |
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 |
100 bool InitializeXkb() { | 105 bool InitializeXkb() { |
101 Display* display = MessagePumpX11::GetDefaultXDisplay(); | 106 Display* display = MessagePumpX11::GetDefaultXDisplay(); |
102 if (!display) | 107 if (!display) |
103 return false; | 108 return false; |
104 | 109 |
105 int opcode, event, error; | 110 int opcode, event, error; |
106 int major = XkbMajorVersion; | 111 int major = XkbMajorVersion; |
107 int minor = XkbMinorVersion; | 112 int minor = XkbMinorVersion; |
108 if (!XkbQueryExtension(display, &opcode, &event, &error, &major, &minor)) { | 113 if (!XkbQueryExtension(display, &opcode, &event, &error, &major, &minor)) { |
109 DVLOG(1) << "Xkb extension not available."; | 114 DVLOG(1) << "Xkb extension not available."; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 g_xdisplay = NULL; | 146 g_xdisplay = NULL; |
142 } | 147 } |
143 | 148 |
144 // static | 149 // static |
145 Display* MessagePumpX11::GetDefaultXDisplay() { | 150 Display* MessagePumpX11::GetDefaultXDisplay() { |
146 if (!g_xdisplay) | 151 if (!g_xdisplay) |
147 g_xdisplay = XOpenDisplay(NULL); | 152 g_xdisplay = XOpenDisplay(NULL); |
148 return g_xdisplay; | 153 return g_xdisplay; |
149 } | 154 } |
150 | 155 |
| 156 // static |
| 157 bool MessagePumpX11::HasXInput2() { |
| 158 return InitializeXInput2(); |
| 159 } |
| 160 |
151 #if defined(TOOLKIT_GTK) | 161 #if defined(TOOLKIT_GTK) |
152 // static | 162 // static |
153 MessagePumpX11* MessagePumpX11::Current() { | 163 MessagePumpX11* MessagePumpX11::Current() { |
154 MessageLoop* loop = MessageLoop::current(); | 164 MessageLoop* loop = MessageLoop::current(); |
155 return static_cast<MessagePumpX11*>(loop->pump_gpu()); | 165 return static_cast<MessagePumpX11*>(loop->pump_gpu()); |
156 } | 166 } |
157 #else | 167 #else |
158 // static | 168 // static |
159 MessagePumpX11* MessagePumpX11::Current() { | 169 MessagePumpX11* MessagePumpX11::Current() { |
160 MessageLoopForUI* loop = MessageLoopForUI::current(); | 170 MessageLoopForUI* loop = MessageLoopForUI::current(); |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 if (FindEventTarget(xev) == x_root_window_) { | 314 if (FindEventTarget(xev) == x_root_window_) { |
305 FOR_EACH_OBSERVER(MessagePumpDispatcher, root_window_dispatchers_, | 315 FOR_EACH_OBSERVER(MessagePumpDispatcher, root_window_dispatchers_, |
306 Dispatch(xev)); | 316 Dispatch(xev)); |
307 return true; | 317 return true; |
308 } | 318 } |
309 MessagePumpDispatcher* dispatcher = GetDispatcherForXEvent(xev); | 319 MessagePumpDispatcher* dispatcher = GetDispatcherForXEvent(xev); |
310 return dispatcher ? dispatcher->Dispatch(xev) : true; | 320 return dispatcher ? dispatcher->Dispatch(xev) : true; |
311 } | 321 } |
312 | 322 |
313 } // namespace base | 323 } // namespace base |
OLD | NEW |