Add ICU message format support
[chromium-blink-merge.git] / ui / events / devices / x11 / device_list_cache_x11.cc
blobffab2ea9a98f1b02d149cc27658c97308bbaefa1
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"
7 #include <algorithm>
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"
13 namespace {
15 bool IsXI2Available() {
16 #if defined(USE_AURA)
17 return ui::DeviceDataManagerX11::GetInstance()->IsXInput2Available();
18 #else
19 return false;
20 #endif
25 namespace ui {
27 DeviceListCacheX11::DeviceListCacheX11() {
30 DeviceListCacheX11::~DeviceListCacheX11() {
33 DeviceListCacheX11* DeviceListCacheX11::GetInstance() {
34 return 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(
44 IsXI2Available()
45 ? XIQueryDevice(display, XIAllDevices, &new_xi_dev_list.count)
46 : nullptr);
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));
54 return x_dev_list;
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));
63 return xi_dev_list;
66 } // namespace ui