OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/events/platform/x11/x11_event_source.h" | 5 #include "ui/events/platform/x11/x11_event_source.h" |
6 | 6 |
7 #include <X11/extensions/XInput2.h> | 7 #include <X11/extensions/XInput2.h> |
8 #include <X11/X.h> | 8 #include <X11/X.h> |
| 9 #include <X11/Xlib.h> |
9 #include <X11/XKBlib.h> | 10 #include <X11/XKBlib.h> |
10 #include <X11/Xlib.h> | |
11 | 11 |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "ui/events/devices/x11/device_data_manager_x11.h" |
| 14 #include "ui/events/event_utils.h" |
13 #include "ui/events/platform/platform_event_dispatcher.h" | 15 #include "ui/events/platform/platform_event_dispatcher.h" |
14 #include "ui/events/platform/platform_event_utils.h" | 16 #include "ui/events/platform/x11/x11_hotplug_event_handler.h" |
15 #include "ui/events/platform/x11/device_data_manager_x11.h" | |
16 #include "ui/events/platform/x11/hotplug_event_handler_x11.h" | |
17 #include "ui/gfx/x/x11_types.h" | 17 #include "ui/gfx/x/x11_types.h" |
18 | 18 |
19 namespace ui { | 19 namespace ui { |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 int g_xinput_opcode = -1; | 23 int g_xinput_opcode = -1; |
24 | 24 |
25 bool InitializeXInput2(XDisplay* display) { | 25 bool InitializeXInput2(XDisplay* display) { |
26 if (!display) | 26 if (!display) |
27 return false; | 27 return false; |
28 | 28 |
29 int event, err; | 29 int event, err; |
30 | 30 |
31 int xiopcode; | 31 int xiopcode; |
32 if (!XQueryExtension(display, "XInputExtension", &xiopcode, &event, &err)) { | 32 if (!XQueryExtension(display, "XInputExtension", &xiopcode, &event, &err)) { |
33 DVLOG(1) << "X Input extension not available."; | 33 DVLOG(1) << "X Input extension not available."; |
34 return false; | 34 return false; |
35 } | 35 } |
36 g_xinput_opcode = xiopcode; | 36 g_xinput_opcode = xiopcode; |
37 | 37 |
38 #if defined(USE_XI2_MT) | 38 int major = 2, minor = 2; |
39 // USE_XI2_MT also defines the required XI2 minor minimum version. | |
40 int major = 2, minor = USE_XI2_MT; | |
41 #else | |
42 int major = 2, minor = 0; | |
43 #endif | |
44 if (XIQueryVersion(display, &major, &minor) == BadRequest) { | 39 if (XIQueryVersion(display, &major, &minor) == BadRequest) { |
45 DVLOG(1) << "XInput2 not supported in the server."; | 40 DVLOG(1) << "XInput2 not supported in the server."; |
46 return false; | 41 return false; |
47 } | 42 } |
48 #if defined(USE_XI2_MT) | 43 if (major < 2 || (major == 2 && minor < 2)) { |
49 if (major < 2 || (major == 2 && minor < USE_XI2_MT)) { | |
50 DVLOG(1) << "XI version on server is " << major << "." << minor << ". " | 44 DVLOG(1) << "XI version on server is " << major << "." << minor << ". " |
51 << "But 2." << USE_XI2_MT << " is required."; | 45 << "But 2.2 is required."; |
52 return false; | 46 return false; |
53 } | 47 } |
54 #endif | |
55 | 48 |
56 return true; | 49 return true; |
57 } | 50 } |
58 | 51 |
59 bool InitializeXkb(XDisplay* display) { | 52 bool InitializeXkb(XDisplay* display) { |
60 if (!display) | 53 if (!display) |
61 return false; | 54 return false; |
62 | 55 |
63 int opcode, event, error; | 56 int opcode, event, error; |
64 int major = XkbMajorVersion; | 57 int major = XkbMajorVersion; |
(...skipping 14 matching lines...) Expand all Loading... |
79 return true; | 72 return true; |
80 } | 73 } |
81 | 74 |
82 } // namespace | 75 } // namespace |
83 | 76 |
84 X11EventSource::X11EventSource(XDisplay* display) | 77 X11EventSource::X11EventSource(XDisplay* display) |
85 : display_(display), | 78 : display_(display), |
86 continue_stream_(true) { | 79 continue_stream_(true) { |
87 CHECK(display_); | 80 CHECK(display_); |
88 DeviceDataManagerX11::CreateInstance(); | 81 DeviceDataManagerX11::CreateInstance(); |
89 hotplug_event_handler_.reset( | |
90 new HotplugEventHandlerX11(DeviceDataManager::GetInstance())); | |
91 InitializeXInput2(display_); | 82 InitializeXInput2(display_); |
92 InitializeXkb(display_); | 83 InitializeXkb(display_); |
93 | |
94 // Force the initial device query to have an update list of active devices. | |
95 hotplug_event_handler_->OnHotplugEvent(); | |
96 } | 84 } |
97 | 85 |
98 X11EventSource::~X11EventSource() { | 86 X11EventSource::~X11EventSource() { |
99 } | 87 } |
100 | 88 |
101 // static | 89 // static |
102 X11EventSource* X11EventSource::GetInstance() { | 90 X11EventSource* X11EventSource::GetInstance() { |
103 return static_cast<X11EventSource*>(PlatformEventSource::GetInstance()); | 91 return static_cast<X11EventSource*>(PlatformEventSource::GetInstance()); |
104 } | 92 } |
105 | 93 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 | 136 |
149 if (have_cookie) | 137 if (have_cookie) |
150 XFreeEventData(xevent->xgeneric.display, &xevent->xcookie); | 138 XFreeEventData(xevent->xgeneric.display, &xevent->xcookie); |
151 return action; | 139 return action; |
152 } | 140 } |
153 | 141 |
154 void X11EventSource::StopCurrentEventStream() { | 142 void X11EventSource::StopCurrentEventStream() { |
155 continue_stream_ = false; | 143 continue_stream_ = false; |
156 } | 144 } |
157 | 145 |
| 146 void X11EventSource::OnDispatcherListChanged() { |
| 147 if (!hotplug_event_handler_) { |
| 148 hotplug_event_handler_.reset(new X11HotplugEventHandler()); |
| 149 // Force the initial device query to have an update list of active devices. |
| 150 hotplug_event_handler_->OnHotplugEvent(); |
| 151 } |
| 152 } |
| 153 |
158 } // namespace ui | 154 } // namespace ui |
OLD | NEW |