| 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 "ui/events/x/device_list_cache_x.h" | 5 #include "ui/events/x/device_list_cache_x.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "ui/events/x/device_data_manager.h" | |
| 12 | 11 |
| 13 namespace { | 12 namespace { |
| 14 | 13 |
| 15 bool IsXI2Available() { | 14 bool IsXI2Available() { |
| 16 #if defined(USE_AURA) | 15 #if defined(USE_AURA) |
| 17 return ui::DeviceDataManager::GetInstance()->IsXInput2Available(); | 16 return base::MessagePumpForUI::HasXInput2(); |
| 18 #else | 17 #else |
| 19 return false; | 18 return false; |
| 20 #endif | 19 #endif |
| 21 } | 20 } |
| 22 | 21 |
| 23 } | 22 } |
| 24 | 23 |
| 25 namespace ui { | 24 namespace ui { |
| 26 | 25 |
| 27 DeviceListCacheX::DeviceListCacheX() { | 26 DeviceListCacheX::DeviceListCacheX() |
| 27 : xi2_(IsXI2Available()) { |
| 28 } | 28 } |
| 29 | 29 |
| 30 DeviceListCacheX::~DeviceListCacheX() { | 30 DeviceListCacheX::~DeviceListCacheX() { |
| 31 std::map<Display*, XDeviceList>::iterator xp; | 31 std::map<Display*, XDeviceList>::iterator xp; |
| 32 for (xp = x_dev_list_map_.begin(); xp != x_dev_list_map_.end(); xp++) { | 32 for (xp = x_dev_list_map_.begin(); xp != x_dev_list_map_.end(); xp++) { |
| 33 if (xp->second.devices) | 33 if (xp->second.devices) |
| 34 XFreeDeviceList(xp->second.devices); | 34 XFreeDeviceList(xp->second.devices); |
| 35 } | 35 } |
| 36 std::map<Display*, XIDeviceList>::iterator xip; | 36 std::map<Display*, XIDeviceList>::iterator xip; |
| 37 for (xip = xi_dev_list_map_.begin(); xip != xi_dev_list_map_.end(); xip++) { | 37 for (xip = xi_dev_list_map_.begin(); xip != xi_dev_list_map_.end(); xip++) { |
| 38 if (xip->second.devices) | 38 if (xip->second.devices) |
| 39 XIFreeDeviceInfo(xip->second.devices); | 39 XIFreeDeviceInfo(xip->second.devices); |
| 40 } | 40 } |
| 41 } | 41 } |
| 42 | 42 |
| 43 DeviceListCacheX* DeviceListCacheX::GetInstance() { | 43 DeviceListCacheX* DeviceListCacheX::GetInstance() { |
| 44 return Singleton<DeviceListCacheX>::get(); | 44 return Singleton<DeviceListCacheX>::get(); |
| 45 } | 45 } |
| 46 | 46 |
| 47 void DeviceListCacheX::UpdateDeviceList(Display* display) { | 47 void DeviceListCacheX::UpdateDeviceList(Display* display) { |
| 48 XDeviceList& new_x_dev_list = x_dev_list_map_[display]; | 48 XDeviceList& new_x_dev_list = x_dev_list_map_[display]; |
| 49 if (new_x_dev_list.devices) | 49 if (new_x_dev_list.devices) |
| 50 XFreeDeviceList(new_x_dev_list.devices); | 50 XFreeDeviceList(new_x_dev_list.devices); |
| 51 new_x_dev_list.devices = XListInputDevices(display, &new_x_dev_list.count); | 51 new_x_dev_list.devices = XListInputDevices(display, &new_x_dev_list.count); |
| 52 | 52 |
| 53 XIDeviceList& new_xi_dev_list = xi_dev_list_map_[display]; | 53 XIDeviceList& new_xi_dev_list = xi_dev_list_map_[display]; |
| 54 if (new_xi_dev_list.devices) | 54 if (new_xi_dev_list.devices) |
| 55 XIFreeDeviceInfo(new_xi_dev_list.devices); | 55 XIFreeDeviceInfo(new_xi_dev_list.devices); |
| 56 new_xi_dev_list.devices = IsXI2Available() ? | 56 new_xi_dev_list.devices = xi2_ ? XIQueryDevice(display, XIAllDevices, |
| 57 XIQueryDevice(display, XIAllDevices, &new_xi_dev_list.count) : NULL; | 57 &new_xi_dev_list.count) : NULL; |
| 58 } | 58 } |
| 59 | 59 |
| 60 const XDeviceList& DeviceListCacheX::GetXDeviceList(Display* display) { | 60 const XDeviceList& DeviceListCacheX::GetXDeviceList(Display* display) { |
| 61 XDeviceList& x_dev_list = x_dev_list_map_[display]; | 61 XDeviceList& x_dev_list = x_dev_list_map_[display]; |
| 62 // Note that the function can be called before any update has taken place. | 62 // Note that the function can be called before any update has taken place. |
| 63 if (!x_dev_list.devices && !x_dev_list.count) | 63 if (!x_dev_list.devices && !x_dev_list.count) |
| 64 x_dev_list.devices = XListInputDevices(display, &x_dev_list.count); | 64 x_dev_list.devices = XListInputDevices(display, &x_dev_list.count); |
| 65 return x_dev_list; | 65 return x_dev_list; |
| 66 } | 66 } |
| 67 | 67 |
| 68 const XIDeviceList& DeviceListCacheX::GetXI2DeviceList(Display* display) { | 68 const XIDeviceList& DeviceListCacheX::GetXI2DeviceList(Display* display) { |
| 69 XIDeviceList& xi_dev_list = xi_dev_list_map_[display]; | 69 XIDeviceList& xi_dev_list = xi_dev_list_map_[display]; |
| 70 if (!xi_dev_list.devices && !xi_dev_list.count) { | 70 if (xi2_ && !xi_dev_list.devices && !xi_dev_list.count) { |
| 71 xi_dev_list.devices = XIQueryDevice(display, XIAllDevices, | 71 xi_dev_list.devices = XIQueryDevice(display, XIAllDevices, |
| 72 &xi_dev_list.count); | 72 &xi_dev_list.count); |
| 73 } | 73 } |
| 74 return xi_dev_list; | 74 return xi_dev_list; |
| 75 } | 75 } |
| 76 | 76 |
| 77 } // namespace ui | 77 } // namespace ui |
| 78 | 78 |
| OLD | NEW |