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 #ifndef UI_EVENTS_PLATFORM_X11_DEVICE_LIST_CACHE_X_H_ | 5 #ifndef UI_EVENTS_DEVICES_X11_DEVICE_LIST_CACHE_X11_H_ |
6 #define UI_EVENTS_PLATFORM_X11_DEVICE_LIST_CACHE_X_H_ | 6 #define UI_EVENTS_DEVICES_X11_DEVICE_LIST_CACHE_X11_H_ |
7 | 7 |
8 #include <X11/extensions/XInput.h> | 8 #include <X11/extensions/XInput.h> |
9 #include <X11/extensions/XInput2.h> | 9 #include <X11/extensions/XInput2.h> |
10 | 10 |
11 #include <map> | 11 #include <map> |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "ui/events/events_base_export.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" |
15 | 17 |
16 template <typename T> | 18 template <typename T> struct DefaultSingletonTraits; |
17 struct DefaultSingletonTraits; | |
18 | 19 |
19 typedef struct _XDisplay Display; | 20 typedef struct _XDisplay Display; |
20 | 21 |
21 template <typename T> | 22 template <typename T, void (*D)(T*)> |
22 struct DeviceList { | 23 struct DeviceList { |
23 DeviceList() : devices(NULL), count(0) {} | 24 DeviceList() : count(0) {} |
24 T& operator[](int x) { return devices[x]; } | 25 T& operator[](int x) { return devices[x]; } |
25 const T& operator[](int x) const { return devices[x]; } | 26 const T& operator[](int x) const { return devices[x]; } |
26 T* devices; | 27 scoped_ptr<T[], gfx::XObjectDeleter<T, void, D>> devices; |
27 int count; | 28 int count; |
28 }; | 29 }; |
29 | 30 |
30 typedef struct DeviceList<XDeviceInfo> XDeviceList; | 31 typedef struct DeviceList<XDeviceInfo, XFreeDeviceList> XDeviceList; |
31 typedef struct DeviceList<XIDeviceInfo> XIDeviceList; | 32 typedef struct DeviceList<XIDeviceInfo, XIFreeDeviceInfo> XIDeviceList; |
32 | 33 |
33 namespace ui { | 34 namespace ui { |
34 | 35 |
35 // A class to cache the current XInput device list. This minimized the | 36 // A class to cache the current XInput device list. This minimized the |
36 // round-trip time to the X server whenever such a device list is needed. The | 37 // round-trip time to the X server whenever such a device list is needed. The |
37 // update function will be called on each incoming XI_HierarchyChanged event. | 38 // update function will be called on each incoming XI_HierarchyChanged event. |
38 class EVENTS_BASE_EXPORT DeviceListCacheX { | 39 class EVENTS_DEVICES_EXPORT DeviceListCacheX11 { |
39 public: | 40 public: |
40 static DeviceListCacheX* GetInstance(); | 41 static DeviceListCacheX11* GetInstance(); |
41 | 42 |
42 void UpdateDeviceList(Display* display); | 43 void UpdateDeviceList(Display* display); |
43 | 44 |
44 // Returns the list of devices associated with |display|. Uses the old X11 | 45 // Returns the list of devices associated with |display|. Uses the old X11 |
45 // protocol to get the list of the devices. | 46 // protocol to get the list of the devices. |
46 const XDeviceList& GetXDeviceList(Display* display); | 47 const XDeviceList& GetXDeviceList(Display* display); |
47 | 48 |
48 // Returns the list of devices associated with |display|. Uses the newer | 49 // Returns the list of devices associated with |display|. Uses the newer |
49 // XINPUT2 protocol to get the list of devices. Before making this call, make | 50 // XINPUT2 protocol to get the list of devices. Before making this call, make |
50 // sure that XInput2 support is available (e.g. by calling | 51 // sure that XInput2 support is available (e.g. by calling |
51 // IsXInput2Available()). | 52 // IsXInput2Available()). |
52 const XIDeviceList& GetXI2DeviceList(Display* display); | 53 const XIDeviceList& GetXI2DeviceList(Display* display); |
53 | 54 |
54 private: | 55 private: |
55 friend struct DefaultSingletonTraits<DeviceListCacheX>; | 56 friend struct DefaultSingletonTraits<DeviceListCacheX11>; |
56 | 57 |
57 DeviceListCacheX(); | 58 DeviceListCacheX11(); |
58 ~DeviceListCacheX(); | 59 ~DeviceListCacheX11(); |
59 | 60 |
60 std::map<Display*, XDeviceList> x_dev_list_map_; | 61 XDeviceList x_dev_list_; |
61 std::map<Display*, XIDeviceList> xi_dev_list_map_; | 62 XIDeviceList xi_dev_list_; |
62 | 63 |
63 DISALLOW_COPY_AND_ASSIGN(DeviceListCacheX); | 64 DISALLOW_COPY_AND_ASSIGN(DeviceListCacheX11); |
64 }; | 65 }; |
65 | 66 |
66 } // namespace ui | 67 } // namespace ui |
67 | 68 |
68 #endif // UI_EVENTS_PLATFORM_X11_DEVICE_LIST_CACHE_X_H_ | 69 #endif // UI_EVENTS_DEVICES_X11_DEVICE_LIST_CACHE_X11_H_ |
| 70 |
OLD | NEW |