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_pump_x.h" | 5 #include "base/message_pump_x.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" |
(...skipping 19 matching lines...) Expand all Loading... |
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 opcode used for checking events. | |
41 int xiopcode = -1; | |
42 | |
43 // 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. |
44 Display* g_xdisplay = NULL; | 41 Display* g_xdisplay = NULL; |
45 | 42 |
46 // The default dispatcher to process native events when no dispatcher | 43 // The default dispatcher to process native events when no dispatcher |
47 // is specified. | 44 // is specified. |
48 base::MessagePumpDispatcher* g_default_dispatcher = NULL; | 45 base::MessagePumpDispatcher* g_default_dispatcher = NULL; |
49 | 46 |
50 void InitializeXInput2(void) { | 47 bool InitializeXInput2Internal() { |
51 Display* display = base::MessagePumpX::GetDefaultXDisplay(); | 48 Display* display = base::MessagePumpX::GetDefaultXDisplay(); |
52 if (!display) | 49 if (!display) |
53 return; | 50 return false; |
54 | 51 |
55 int event, err; | 52 int event, err; |
56 | 53 |
| 54 int xiopcode; |
57 if (!XQueryExtension(display, "XInputExtension", &xiopcode, &event, &err)) { | 55 if (!XQueryExtension(display, "XInputExtension", &xiopcode, &event, &err)) { |
58 DVLOG(1) << "X Input extension not available."; | 56 DVLOG(1) << "X Input extension not available."; |
59 xiopcode = -1; | 57 return false; |
60 return; | |
61 } | 58 } |
62 | 59 |
63 #if defined(USE_XI2_MT) | 60 #if defined(USE_XI2_MT) |
64 // USE_XI2_MT also defines the required XI2 minor minimum version. | 61 // USE_XI2_MT also defines the required XI2 minor minimum version. |
65 int major = 2, minor = USE_XI2_MT; | 62 int major = 2, minor = USE_XI2_MT; |
66 #else | 63 #else |
67 int major = 2, minor = 0; | 64 int major = 2, minor = 0; |
68 #endif | 65 #endif |
69 if (XIQueryVersion(display, &major, &minor) == BadRequest) { | 66 if (XIQueryVersion(display, &major, &minor) == BadRequest) { |
70 DVLOG(1) << "XInput2 not supported in the server."; | 67 DVLOG(1) << "XInput2 not supported in the server."; |
71 xiopcode = -1; | 68 return false; |
72 return; | |
73 } | 69 } |
74 #if defined(USE_XI2_MT) | 70 #if defined(USE_XI2_MT) |
75 if (major < 2 || (major == 2 && minor < USE_XI2_MT)) { | 71 if (major < 2 || (major == 2 && minor < USE_XI2_MT)) { |
76 DVLOG(1) << "XI version on server is " << major << "." << minor << ". " | 72 DVLOG(1) << "XI version on server is " << major << "." << minor << ". " |
77 << "But 2." << USE_XI2_MT << " is required."; | 73 << "But 2." << USE_XI2_MT << " is required."; |
78 xiopcode = -1; | 74 return false; |
79 return; | |
80 } | 75 } |
81 #endif | 76 #endif |
| 77 |
| 78 return true; |
| 79 } |
| 80 |
| 81 bool InitializeXInput2() { |
| 82 static bool xinput2_supported = InitializeXInput2Internal(); |
| 83 return xinput2_supported; |
82 } | 84 } |
83 | 85 |
84 } // namespace | 86 } // namespace |
85 | 87 |
86 namespace base { | 88 namespace base { |
87 | 89 |
88 MessagePumpX::MessagePumpX() : MessagePumpGlib(), | 90 MessagePumpX::MessagePumpX() : MessagePumpGlib(), |
89 x_source_(NULL) { | 91 x_source_(NULL) { |
90 InitializeXInput2(); | 92 InitializeXInput2(); |
91 InitXSource(); | 93 InitXSource(); |
92 } | 94 } |
93 | 95 |
94 MessagePumpX::~MessagePumpX() { | 96 MessagePumpX::~MessagePumpX() { |
95 g_source_destroy(x_source_); | 97 g_source_destroy(x_source_); |
96 g_source_unref(x_source_); | 98 g_source_unref(x_source_); |
97 XCloseDisplay(g_xdisplay); | 99 XCloseDisplay(g_xdisplay); |
98 g_xdisplay = NULL; | 100 g_xdisplay = NULL; |
99 } | 101 } |
100 | 102 |
101 // static | 103 // static |
102 Display* MessagePumpX::GetDefaultXDisplay() { | 104 Display* MessagePumpX::GetDefaultXDisplay() { |
103 if (!g_xdisplay) | 105 if (!g_xdisplay) |
104 g_xdisplay = XOpenDisplay(NULL); | 106 g_xdisplay = XOpenDisplay(NULL); |
105 return g_xdisplay; | 107 return g_xdisplay; |
106 } | 108 } |
107 | 109 |
108 // static | 110 // static |
109 bool MessagePumpX::HasXInput2() { | 111 bool MessagePumpX::HasXInput2() { |
110 return xiopcode != -1; | 112 return InitializeXInput2(); |
111 } | 113 } |
112 | 114 |
113 // static | 115 // static |
114 void MessagePumpX::SetDefaultDispatcher(MessagePumpDispatcher* dispatcher) { | 116 void MessagePumpX::SetDefaultDispatcher(MessagePumpDispatcher* dispatcher) { |
115 DCHECK(!g_default_dispatcher || !dispatcher); | 117 DCHECK(!g_default_dispatcher || !dispatcher); |
116 g_default_dispatcher = dispatcher; | 118 g_default_dispatcher = dispatcher; |
117 } | 119 } |
118 | 120 |
119 void MessagePumpX::InitXSource() { | 121 void MessagePumpX::InitXSource() { |
120 // CHECKs are to help track down crbug.com/113106. | 122 // CHECKs are to help track down crbug.com/113106. |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 return true; | 187 return true; |
186 } | 188 } |
187 return false; | 189 return false; |
188 } | 190 } |
189 | 191 |
190 void MessagePumpX::DidProcessXEvent(XEvent* xevent) { | 192 void MessagePumpX::DidProcessXEvent(XEvent* xevent) { |
191 FOR_EACH_OBSERVER(MessagePumpObserver, observers(), DidProcessEvent(xevent)); | 193 FOR_EACH_OBSERVER(MessagePumpObserver, observers(), DidProcessEvent(xevent)); |
192 } | 194 } |
193 | 195 |
194 } // namespace base | 196 } // namespace base |
OLD | NEW |