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 #ifndef UI_EVENTS_DEVICES_X11_DEVICE_LIST_CACHE_X11_H_
6 #define UI_EVENTS_DEVICES_X11_DEVICE_LIST_CACHE_X11_H_
8 #include <X11/extensions/XInput.h>
9 #include <X11/extensions/XInput2.h>
13 #include "base/basictypes.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "ui/events/devices/events_devices_export.h"
16 #include "ui/gfx/x/x11_types.h"
19 template <typename T
> struct DefaultSingletonTraits
;
22 typedef struct _XDisplay Display
;
24 template <typename T
, void (*D
)(T
*)>
26 DeviceList() : count(0) {}
27 T
& operator[](int x
) { return devices
[x
]; }
28 const T
& operator[](int x
) const { return devices
[x
]; }
29 scoped_ptr
<T
[], gfx::XObjectDeleter
<T
, void, D
>> devices
;
33 typedef struct DeviceList
<XDeviceInfo
, XFreeDeviceList
> XDeviceList
;
34 typedef struct DeviceList
<XIDeviceInfo
, XIFreeDeviceInfo
> XIDeviceList
;
38 // A class to cache the current XInput device list. This minimized the
39 // round-trip time to the X server whenever such a device list is needed. The
40 // update function will be called on each incoming XI_HierarchyChanged event.
41 class EVENTS_DEVICES_EXPORT DeviceListCacheX11
{
43 static DeviceListCacheX11
* GetInstance();
45 void UpdateDeviceList(Display
* display
);
47 // Returns the list of devices associated with |display|. Uses the old X11
48 // protocol to get the list of the devices.
49 const XDeviceList
& GetXDeviceList(Display
* display
);
51 // Returns the list of devices associated with |display|. Uses the newer
52 // XINPUT2 protocol to get the list of devices. Before making this call, make
53 // sure that XInput2 support is available (e.g. by calling
54 // IsXInput2Available()).
55 const XIDeviceList
& GetXI2DeviceList(Display
* display
);
58 friend struct base::DefaultSingletonTraits
<DeviceListCacheX11
>;
61 ~DeviceListCacheX11();
63 XDeviceList x_dev_list_
;
64 XIDeviceList xi_dev_list_
;
66 DISALLOW_COPY_AND_ASSIGN(DeviceListCacheX11
);
71 #endif // UI_EVENTS_DEVICES_X11_DEVICE_LIST_CACHE_X11_H_