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
3 // found in the LICENSE file.
5 #include "ui/events/devices/x11/device_list_cache_x11.h"
9 #include "base/memory/singleton.h"
10 #include "base/message_loop/message_loop.h"
11 #include "ui/events/devices/x11/device_data_manager_x11.h"
15 bool IsXI2Available() {
17 return ui::DeviceDataManagerX11::GetInstance()->IsXInput2Available();
27 DeviceListCacheX11::DeviceListCacheX11() {
30 DeviceListCacheX11::~DeviceListCacheX11() {
33 DeviceListCacheX11
* DeviceListCacheX11::GetInstance() {
34 return base::Singleton
<DeviceListCacheX11
>::get();
37 void DeviceListCacheX11::UpdateDeviceList(Display
* display
) {
38 XDeviceList
& new_x_dev_list
= x_dev_list_
;
39 new_x_dev_list
.devices
.reset(
40 XListInputDevices(display
, &new_x_dev_list
.count
));
42 XIDeviceList
& new_xi_dev_list
= xi_dev_list_
;
43 new_xi_dev_list
.devices
.reset(
45 ? XIQueryDevice(display
, XIAllDevices
, &new_xi_dev_list
.count
)
49 const XDeviceList
& DeviceListCacheX11::GetXDeviceList(Display
* display
) {
50 XDeviceList
& x_dev_list
= x_dev_list_
;
51 // Note that the function can be called before any update has taken place.
52 if (!x_dev_list
.devices
&& !x_dev_list
.count
)
53 x_dev_list
.devices
.reset(XListInputDevices(display
, &x_dev_list
.count
));
57 const XIDeviceList
& DeviceListCacheX11::GetXI2DeviceList(Display
* display
) {
58 XIDeviceList
& xi_dev_list
= xi_dev_list_
;
59 if (!xi_dev_list
.devices
&& !xi_dev_list
.count
) {
60 xi_dev_list
.devices
.reset(
61 XIQueryDevice(display
, XIAllDevices
, &xi_dev_list
.count
));