• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 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.
4 
5 #ifndef UI_EVENTS_OZONE_EVDEV_EVENT_DEVICE_INFO_H_
6 #define UI_EVENTS_OZONE_EVDEV_EVENT_DEVICE_INFO_H_
7 
8 #include <limits.h>
9 #include <linux/input.h>
10 
11 #include "base/basictypes.h"
12 
13 #define EVDEV_LONG_BITS (CHAR_BIT * sizeof(long))
14 #define EVDEV_BITS_TO_LONGS(x) (((x) + EVDEV_LONG_BITS - 1) / EVDEV_LONG_BITS)
15 
16 namespace ui {
17 
18 // Device information for Linux input devices
19 //
20 // This stores and queries information about input devices; in
21 // particular it knows which events the device can generate.
22 class EventDeviceInfo {
23  public:
24   EventDeviceInfo();
25   ~EventDeviceInfo();
26 
27   // Initialize device information from an open device.
28   bool Initialize(int fd);
29 
30   // Check events this device can generate.
31   bool HasEventType(unsigned int type) const;
32   bool HasKeyEvent(unsigned int code) const;
33   bool HasRelEvent(unsigned int code) const;
34   bool HasAbsEvent(unsigned int code) const;
35   bool HasMscEvent(unsigned int code) const;
36   bool HasSwEvent(unsigned int code) const;
37   bool HasLedEvent(unsigned int code) const;
38 
39   // Check input device properties.
40   bool HasProp(unsigned int code) const;
41 
42  private:
43   unsigned long ev_bits_[EVDEV_BITS_TO_LONGS(EV_CNT)];
44   unsigned long key_bits_[EVDEV_BITS_TO_LONGS(KEY_CNT)];
45   unsigned long rel_bits_[EVDEV_BITS_TO_LONGS(REL_CNT)];
46   unsigned long abs_bits_[EVDEV_BITS_TO_LONGS(ABS_CNT)];
47   unsigned long msc_bits_[EVDEV_BITS_TO_LONGS(MSC_CNT)];
48   unsigned long sw_bits_[EVDEV_BITS_TO_LONGS(SW_CNT)];
49   unsigned long led_bits_[EVDEV_BITS_TO_LONGS(LED_CNT)];
50   unsigned long prop_bits_[EVDEV_BITS_TO_LONGS(INPUT_PROP_CNT)];
51 
52   DISALLOW_COPY_AND_ASSIGN(EventDeviceInfo);
53 };
54 
55 }  // namspace ui
56 
57 #endif  // UI_EVENTS_OZONE_EVDEV_EVENT_DEVICE_INFO_H_
58