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/XKBlib.h> |
8 #include <X11/X.h> | |
9 #include <X11/Xlib.h> | 8 #include <X11/Xlib.h> |
10 #include <X11/XKBlib.h> | |
11 | 9 |
12 #include "base/logging.h" | 10 #include "base/logging.h" |
13 #include "ui/events/devices/x11/device_data_manager_x11.h" | 11 #include "ui/events/devices/x11/device_data_manager_x11.h" |
14 #include "ui/events/event_utils.h" | 12 #include "ui/events/event_utils.h" |
15 #include "ui/events/platform/platform_event_dispatcher.h" | 13 #include "ui/events/platform/platform_event_dispatcher.h" |
16 #include "ui/events/platform/x11/x11_hotplug_event_handler.h" | 14 #include "ui/events/platform/x11/x11_hotplug_event_handler.h" |
17 #include "ui/gfx/x/x11_types.h" | |
18 | 15 |
19 namespace ui { | 16 namespace ui { |
20 | 17 |
21 namespace { | 18 namespace { |
22 | 19 |
23 int g_xinput_opcode = -1; | |
24 | |
25 bool InitializeXInput2(XDisplay* display) { | |
26 if (!display) | |
27 return false; | |
28 | |
29 int event, err; | |
30 | |
31 int xiopcode; | |
32 if (!XQueryExtension(display, "XInputExtension", &xiopcode, &event, &err)) { | |
33 DVLOG(1) << "X Input extension not available."; | |
34 return false; | |
35 } | |
36 g_xinput_opcode = xiopcode; | |
37 | |
38 int major = 2, minor = 2; | |
39 if (XIQueryVersion(display, &major, &minor) == BadRequest) { | |
40 DVLOG(1) << "XInput2 not supported in the server."; | |
41 return false; | |
42 } | |
43 if (major < 2 || (major == 2 && minor < 2)) { | |
44 DVLOG(1) << "XI version on server is " << major << "." << minor << ". " | |
45 << "But 2.2 is required."; | |
46 return false; | |
47 } | |
48 | |
49 return true; | |
50 } | |
51 | |
52 bool InitializeXkb(XDisplay* display) { | 20 bool InitializeXkb(XDisplay* display) { |
53 if (!display) | 21 if (!display) |
54 return false; | 22 return false; |
55 | 23 |
56 int opcode, event, error; | 24 int opcode, event, error; |
57 int major = XkbMajorVersion; | 25 int major = XkbMajorVersion; |
58 int minor = XkbMinorVersion; | 26 int minor = XkbMinorVersion; |
59 if (!XkbQueryExtension(display, &opcode, &event, &error, &major, &minor)) { | 27 if (!XkbQueryExtension(display, &opcode, &event, &error, &major, &minor)) { |
60 DVLOG(1) << "Xkb extension not available."; | 28 DVLOG(1) << "Xkb extension not available."; |
61 return false; | 29 return false; |
(...skipping 10 matching lines...) Expand all Loading... | |
72 return true; | 40 return true; |
73 } | 41 } |
74 | 42 |
75 } // namespace | 43 } // namespace |
76 | 44 |
77 X11EventSource::X11EventSource(XDisplay* display) | 45 X11EventSource::X11EventSource(XDisplay* display) |
78 : display_(display), | 46 : display_(display), |
79 continue_stream_(true) { | 47 continue_stream_(true) { |
80 CHECK(display_); | 48 CHECK(display_); |
81 DeviceDataManagerX11::CreateInstance(); | 49 DeviceDataManagerX11::CreateInstance(); |
82 InitializeXInput2(display_); | |
83 InitializeXkb(display_); | 50 InitializeXkb(display_); |
84 } | 51 } |
85 | 52 |
86 X11EventSource::~X11EventSource() { | 53 X11EventSource::~X11EventSource() {} |
87 } | |
88 | 54 |
89 // static | |
sadrul
2016/02/04 22:29:32
keep this
kylechar
2016/02/05 18:21:46
Done.
| |
90 X11EventSource* X11EventSource::GetInstance() { | 55 X11EventSource* X11EventSource::GetInstance() { |
91 return static_cast<X11EventSource*>(PlatformEventSource::GetInstance()); | 56 return static_cast<X11EventSource*>(PlatformEventSource::GetInstance()); |
92 } | 57 } |
93 | 58 |
94 //////////////////////////////////////////////////////////////////////////////// | 59 //////////////////////////////////////////////////////////////////////////////// |
95 // X11EventSource, public | 60 // X11EventSource, public |
96 | 61 |
97 void X11EventSource::DispatchXEvents() { | 62 void X11EventSource::DispatchXEvents() { |
98 DCHECK(display_); | 63 DCHECK(display_); |
99 // Handle all pending events. | 64 // Handle all pending events. |
(...skipping 11 matching lines...) Expand all Loading... | |
111 XEvent event; | 76 XEvent event; |
112 do { | 77 do { |
113 // Block until there's a message of |event_mask| type on |w|. Then remove | 78 // Block until there's a message of |event_mask| type on |w|. Then remove |
114 // it from the queue and stuff it in |event|. | 79 // it from the queue and stuff it in |event|. |
115 XWindowEvent(display_, window, StructureNotifyMask, &event); | 80 XWindowEvent(display_, window, StructureNotifyMask, &event); |
116 ExtractCookieDataDispatchEvent(&event); | 81 ExtractCookieDataDispatchEvent(&event); |
117 } while (event.type != MapNotify); | 82 } while (event.type != MapNotify); |
118 } | 83 } |
119 | 84 |
120 //////////////////////////////////////////////////////////////////////////////// | 85 //////////////////////////////////////////////////////////////////////////////// |
121 // X11EventSource, private | 86 // X11EventSource, protected |
122 | 87 |
123 uint32_t X11EventSource::ExtractCookieDataDispatchEvent(XEvent* xevent) { | 88 void X11EventSource::ExtractCookieDataDispatchEvent(XEvent* xevent) { |
124 bool have_cookie = false; | 89 bool have_cookie = false; |
125 if (xevent->type == GenericEvent && | 90 if (xevent->type == GenericEvent && |
126 XGetEventData(xevent->xgeneric.display, &xevent->xcookie)) { | 91 XGetEventData(xevent->xgeneric.display, &xevent->xcookie)) { |
127 have_cookie = true; | 92 have_cookie = true; |
128 } | 93 } |
129 uint32_t action = DispatchEvent(xevent); | 94 DispatchEvent(xevent); |
130 if (have_cookie) | 95 if (have_cookie) |
131 XFreeEventData(xevent->xgeneric.display, &xevent->xcookie); | 96 XFreeEventData(xevent->xgeneric.display, &xevent->xcookie); |
132 return action; | |
133 } | 97 } |
134 | 98 |
135 uint32_t X11EventSource::DispatchEvent(XEvent* xevent) { | 99 void X11EventSource::PostDispatchEvent(XEvent* xevent) { |
136 uint32_t action = PlatformEventSource::DispatchEvent(xevent); | |
137 if (xevent->type == GenericEvent && | 100 if (xevent->type == GenericEvent && |
138 (xevent->xgeneric.evtype == XI_HierarchyChanged || | 101 (xevent->xgeneric.evtype == XI_HierarchyChanged || |
139 xevent->xgeneric.evtype == XI_DeviceChanged)) { | 102 xevent->xgeneric.evtype == XI_DeviceChanged)) { |
140 ui::UpdateDeviceList(); | 103 ui::UpdateDeviceList(); |
141 hotplug_event_handler_->OnHotplugEvent(); | 104 hotplug_event_handler_->OnHotplugEvent(); |
142 } | 105 } |
143 | 106 |
144 if (xevent->type == EnterNotify && | 107 if (xevent->type == EnterNotify && |
145 xevent->xcrossing.detail != NotifyInferior && | 108 xevent->xcrossing.detail != NotifyInferior && |
146 xevent->xcrossing.mode != NotifyUngrab) { | 109 xevent->xcrossing.mode != NotifyUngrab) { |
147 // Clear stored scroll data | 110 // Clear stored scroll data |
148 ui::DeviceDataManagerX11::GetInstance()->InvalidateScrollClasses(); | 111 ui::DeviceDataManagerX11::GetInstance()->InvalidateScrollClasses(); |
149 } | 112 } |
150 return action; | |
151 } | 113 } |
152 | 114 |
153 void X11EventSource::StopCurrentEventStream() { | 115 void X11EventSource::StopCurrentEventStream() { |
154 continue_stream_ = false; | 116 continue_stream_ = false; |
155 } | 117 } |
156 | 118 |
157 void X11EventSource::OnDispatcherListChanged() { | 119 void X11EventSource::OnDispatcherListChanged() { |
158 if (!hotplug_event_handler_) { | 120 if (!hotplug_event_handler_) { |
159 hotplug_event_handler_.reset(new X11HotplugEventHandler()); | 121 hotplug_event_handler_.reset(new X11HotplugEventHandler()); |
160 // Force the initial device query to have an update list of active devices. | 122 // Force the initial device query to have an update list of active devices. |
161 hotplug_event_handler_->OnHotplugEvent(); | 123 hotplug_event_handler_->OnHotplugEvent(); |
162 } | 124 } |
163 } | 125 } |
164 | 126 |
165 } // namespace ui | 127 } // namespace ui |
OLD | NEW |