| 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/devices/x11/device_data_manager_x11.h" | 5 #include "ui/events/devices/x11/device_data_manager_x11.h" |
| 6 | 6 |
| 7 #include <X11/extensions/XInput.h> | 7 #include <X11/extensions/XInput.h> |
| 8 #include <X11/extensions/XInput2.h> | 8 #include <X11/extensions/XInput2.h> |
| 9 #include <X11/Xlib.h> | 9 #include <X11/Xlib.h> |
| 10 | 10 |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 valuator_count_[i] = 0; | 207 valuator_count_[i] = 0; |
| 208 valuator_lookup_[i].clear(); | 208 valuator_lookup_[i].clear(); |
| 209 data_type_lookup_[i].clear(); | 209 data_type_lookup_[i].clear(); |
| 210 valuator_min_[i].clear(); | 210 valuator_min_[i].clear(); |
| 211 valuator_max_[i].clear(); | 211 valuator_max_[i].clear(); |
| 212 for (int j = 0; j < kMaxSlotNum; j++) | 212 for (int j = 0; j < kMaxSlotNum; j++) |
| 213 last_seen_valuator_[i][j].clear(); | 213 last_seen_valuator_[i][j].clear(); |
| 214 } | 214 } |
| 215 | 215 |
| 216 // Find all the touchpad devices. | 216 // Find all the touchpad devices. |
| 217 XDeviceList dev_list = | 217 const XDeviceList& dev_list = |
| 218 ui::DeviceListCacheX11::GetInstance()->GetXDeviceList(display); | 218 ui::DeviceListCacheX11::GetInstance()->GetXDeviceList(display); |
| 219 Atom xi_touchpad = XInternAtom(display, XI_TOUCHPAD, false); | 219 Atom xi_touchpad = XInternAtom(display, XI_TOUCHPAD, false); |
| 220 for (int i = 0; i < dev_list.count; ++i) | 220 for (int i = 0; i < dev_list.count; ++i) |
| 221 if (dev_list[i].type == xi_touchpad) | 221 if (dev_list[i].type == xi_touchpad) |
| 222 touchpads_[dev_list[i].id] = true; | 222 touchpads_[dev_list[i].id] = true; |
| 223 | 223 |
| 224 if (!IsXInput2Available()) | 224 if (!IsXInput2Available()) |
| 225 return; | 225 return; |
| 226 | 226 |
| 227 // Update the structs with new valuator information | 227 // Update the structs with new valuator information |
| 228 XIDeviceList info_list = | 228 const XIDeviceList& info_list = |
| 229 ui::DeviceListCacheX11::GetInstance()->GetXI2DeviceList(display); | 229 ui::DeviceListCacheX11::GetInstance()->GetXI2DeviceList(display); |
| 230 Atom atoms[DT_LAST_ENTRY]; | 230 Atom atoms[DT_LAST_ENTRY]; |
| 231 for (int data_type = 0; data_type < DT_LAST_ENTRY; ++data_type) | 231 for (int data_type = 0; data_type < DT_LAST_ENTRY; ++data_type) |
| 232 atoms[data_type] = atom_cache_.GetAtom(kCachedAtoms[data_type]); | 232 atoms[data_type] = atom_cache_.GetAtom(kCachedAtoms[data_type]); |
| 233 | 233 |
| 234 for (int i = 0; i < info_list.count; ++i) { | 234 for (int i = 0; i < info_list.count; ++i) { |
| 235 XIDeviceInfo* info = info_list.devices + i; | 235 const XIDeviceInfo& info = info_list[i]; |
| 236 | 236 |
| 237 if (info->use == XIMasterPointer) | 237 if (info.use == XIMasterPointer) |
| 238 master_pointers_.push_back(info->deviceid); | 238 master_pointers_.push_back(info.deviceid); |
| 239 | 239 |
| 240 // We currently handle only slave, non-keyboard devices | 240 // We currently handle only slave, non-keyboard devices |
| 241 if (info->use != XISlavePointer && info->use != XIFloatingSlave) | 241 if (info.use != XISlavePointer && info.use != XIFloatingSlave) |
| 242 continue; | 242 continue; |
| 243 | 243 |
| 244 bool possible_cmt = false; | 244 bool possible_cmt = false; |
| 245 bool not_cmt = false; | 245 bool not_cmt = false; |
| 246 const int deviceid = info->deviceid; | 246 const int deviceid = info.deviceid; |
| 247 | 247 |
| 248 for (int j = 0; j < info->num_classes; ++j) { | 248 for (int j = 0; j < info.num_classes; ++j) { |
| 249 if (info->classes[j]->type == XIValuatorClass) | 249 if (info.classes[j]->type == XIValuatorClass) |
| 250 ++valuator_count_[deviceid]; | 250 ++valuator_count_[deviceid]; |
| 251 else if (info->classes[j]->type == XIScrollClass) | 251 else if (info.classes[j]->type == XIScrollClass) |
| 252 not_cmt = true; | 252 not_cmt = true; |
| 253 } | 253 } |
| 254 | 254 |
| 255 // Skip devices that don't use any valuator | 255 // Skip devices that don't use any valuator |
| 256 if (!valuator_count_[deviceid]) | 256 if (!valuator_count_[deviceid]) |
| 257 continue; | 257 continue; |
| 258 | 258 |
| 259 valuator_lookup_[deviceid].resize(DT_LAST_ENTRY, -1); | 259 valuator_lookup_[deviceid].resize(DT_LAST_ENTRY, -1); |
| 260 data_type_lookup_[deviceid].resize( | 260 data_type_lookup_[deviceid].resize( |
| 261 valuator_count_[deviceid], DT_LAST_ENTRY); | 261 valuator_count_[deviceid], DT_LAST_ENTRY); |
| 262 valuator_min_[deviceid].resize(DT_LAST_ENTRY, 0); | 262 valuator_min_[deviceid].resize(DT_LAST_ENTRY, 0); |
| 263 valuator_max_[deviceid].resize(DT_LAST_ENTRY, 0); | 263 valuator_max_[deviceid].resize(DT_LAST_ENTRY, 0); |
| 264 for (int j = 0; j < kMaxSlotNum; j++) | 264 for (int j = 0; j < kMaxSlotNum; j++) |
| 265 last_seen_valuator_[deviceid][j].resize(DT_LAST_ENTRY, 0); | 265 last_seen_valuator_[deviceid][j].resize(DT_LAST_ENTRY, 0); |
| 266 for (int j = 0; j < info->num_classes; ++j) { | 266 for (int j = 0; j < info.num_classes; ++j) { |
| 267 if (info->classes[j]->type != XIValuatorClass) | 267 if (info.classes[j]->type != XIValuatorClass) |
| 268 continue; | 268 continue; |
| 269 | 269 |
| 270 XIValuatorClassInfo* v = | 270 XIValuatorClassInfo* v = |
| 271 reinterpret_cast<XIValuatorClassInfo*>(info->classes[j]); | 271 reinterpret_cast<XIValuatorClassInfo*>(info.classes[j]); |
| 272 for (int data_type = 0; data_type < DT_LAST_ENTRY; ++data_type) { | 272 for (int data_type = 0; data_type < DT_LAST_ENTRY; ++data_type) { |
| 273 if (v->label == atoms[data_type]) { | 273 if (v->label == atoms[data_type]) { |
| 274 valuator_lookup_[deviceid][data_type] = v->number; | 274 valuator_lookup_[deviceid][data_type] = v->number; |
| 275 data_type_lookup_[deviceid][v->number] = data_type; | 275 data_type_lookup_[deviceid][v->number] = data_type; |
| 276 valuator_min_[deviceid][data_type] = v->min; | 276 valuator_min_[deviceid][data_type] = v->min; |
| 277 valuator_max_[deviceid][data_type] = v->max; | 277 valuator_max_[deviceid][data_type] = v->max; |
| 278 if (IsCMTDataType(data_type)) | 278 if (IsCMTDataType(data_type)) |
| 279 possible_cmt = true; | 279 possible_cmt = true; |
| 280 break; | 280 break; |
| 281 } | 281 } |
| (...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 753 } else { | 753 } else { |
| 754 keyboards.erase(it); | 754 keyboards.erase(it); |
| 755 ++blocked_iter; | 755 ++blocked_iter; |
| 756 } | 756 } |
| 757 } | 757 } |
| 758 // Notify base class of updated list. | 758 // Notify base class of updated list. |
| 759 DeviceDataManager::OnKeyboardDevicesUpdated(keyboards); | 759 DeviceDataManager::OnKeyboardDevicesUpdated(keyboards); |
| 760 } | 760 } |
| 761 | 761 |
| 762 } // namespace ui | 762 } // namespace ui |
| OLD | NEW |