Index: base/message_pump_x.cc |
diff --git a/base/message_pump_x.cc b/base/message_pump_x.cc |
index e7deff0f602316625093be29971493743f3acf22..c19e3cbb931063231eb8a09947b65e5a1014853d 100644 |
--- a/base/message_pump_x.cc |
+++ b/base/message_pump_x.cc |
@@ -37,8 +37,9 @@ GSourceFuncs XSourceFuncs = { |
NULL |
}; |
-// The opcode used for checking events. |
-int xiopcode = -1; |
+// The status of XInput2 initialization. |
+bool xInput2Initialized = false; |
sadrul
2012/05/16 21:47:12
xinput2_initialized
xinput2_supported
camelCase i
Rick Byers
2012/05/17 14:06:56
Done.
|
+bool xInput2Supported = false; |
// The message-pump opens a connection to the display and owns it. |
Display* g_xdisplay = NULL; |
@@ -47,16 +48,20 @@ Display* g_xdisplay = NULL; |
// is specified. |
base::MessagePumpDispatcher* g_default_dispatcher = NULL; |
-void InitializeXInput2(void) { |
+void InitializeXInput2IfNeeded(void) { |
+ if (xInput2Initialized) |
+ return; |
+ xInput2Initialized = true; |
+ |
Display* display = base::MessagePumpX::GetDefaultXDisplay(); |
if (!display) |
return; |
int event, err; |
+ int xiopcode; |
if (!XQueryExtension(display, "XInputExtension", &xiopcode, &event, &err)) { |
DVLOG(1) << "X Input extension not available."; |
- xiopcode = -1; |
return; |
} |
@@ -68,17 +73,17 @@ void InitializeXInput2(void) { |
#endif |
if (XIQueryVersion(display, &major, &minor) == BadRequest) { |
DVLOG(1) << "XInput2 not supported in the server."; |
- xiopcode = -1; |
return; |
} |
#if defined(USE_XI2_MT) |
if (major < 2 || (major == 2 && minor < USE_XI2_MT)) { |
DVLOG(1) << "XI version on server is " << major << "." << minor << ". " |
<< "But 2." << USE_XI2_MT << " is required."; |
- xiopcode = -1; |
return; |
} |
#endif |
+ |
+ xInput2Supported = true; |
} |
} // namespace |
@@ -87,7 +92,7 @@ namespace base { |
MessagePumpX::MessagePumpX() : MessagePumpGlib(), |
x_source_(NULL) { |
- InitializeXInput2(); |
+ InitializeXInput2IfNeeded(); |
InitXSource(); |
} |
@@ -107,7 +112,8 @@ Display* MessagePumpX::GetDefaultXDisplay() { |
// static |
bool MessagePumpX::HasXInput2() { |
- return xiopcode != -1; |
+ InitializeXInput2IfNeeded(); |
+ return xInput2Supported; |
} |
// static |