This source file includes following definitions.
- IsXI2Available
- GetInstance
- UpdateDeviceList
- GetXDeviceList
- GetXI2DeviceList
#include "ui/events/x/device_list_cache_x.h"
#include <algorithm>
#include "base/memory/singleton.h"
#include "base/message_loop/message_loop.h"
#include "ui/events/x/device_data_manager.h"
namespace {
bool IsXI2Available() {
#if defined(USE_AURA)
return ui::DeviceDataManager::GetInstance()->IsXInput2Available();
#else
return false;
#endif
}
}
namespace ui {
DeviceListCacheX::DeviceListCacheX() {
}
DeviceListCacheX::~DeviceListCacheX() {
std::map<Display*, XDeviceList>::iterator xp;
for (xp = x_dev_list_map_.begin(); xp != x_dev_list_map_.end(); xp++) {
if (xp->second.devices)
XFreeDeviceList(xp->second.devices);
}
std::map<Display*, XIDeviceList>::iterator xip;
for (xip = xi_dev_list_map_.begin(); xip != xi_dev_list_map_.end(); xip++) {
if (xip->second.devices)
XIFreeDeviceInfo(xip->second.devices);
}
}
DeviceListCacheX* DeviceListCacheX::GetInstance() {
return Singleton<DeviceListCacheX>::get();
}
void DeviceListCacheX::UpdateDeviceList(Display* display) {
XDeviceList& new_x_dev_list = x_dev_list_map_[display];
if (new_x_dev_list.devices)
XFreeDeviceList(new_x_dev_list.devices);
new_x_dev_list.devices = XListInputDevices(display, &new_x_dev_list.count);
XIDeviceList& new_xi_dev_list = xi_dev_list_map_[display];
if (new_xi_dev_list.devices)
XIFreeDeviceInfo(new_xi_dev_list.devices);
new_xi_dev_list.devices = IsXI2Available() ?
XIQueryDevice(display, XIAllDevices, &new_xi_dev_list.count) : NULL;
}
const XDeviceList& DeviceListCacheX::GetXDeviceList(Display* display) {
XDeviceList& x_dev_list = x_dev_list_map_[display];
if (!x_dev_list.devices && !x_dev_list.count)
x_dev_list.devices = XListInputDevices(display, &x_dev_list.count);
return x_dev_list;
}
const XIDeviceList& DeviceListCacheX::GetXI2DeviceList(Display* display) {
XIDeviceList& xi_dev_list = xi_dev_list_map_[display];
if (!xi_dev_list.devices && !xi_dev_list.count) {
xi_dev_list.devices = XIQueryDevice(display, XIAllDevices,
&xi_dev_list.count);
}
return xi_dev_list;
}
}