OLD | NEW |
(Empty) | |
| 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 <string> |
| 12 #include <vector> |
| 13 |
| 14 #include "base/basictypes.h" |
| 15 #include "ui/events/ozone/evdev/event_device_util.h" |
| 16 #include "ui/events/ozone/evdev/events_ozone_evdev_export.h" |
| 17 |
| 18 #if !defined(ABS_MT_TOOL_Y) |
| 19 #define ABS_MT_TOOL_Y 0x3d |
| 20 #endif |
| 21 |
| 22 // ABS_MT_SLOT isn't valid options for EVIOCGMTSLOTS ioctl. |
| 23 #define EVDEV_ABS_MT_FIRST ABS_MT_TOUCH_MAJOR |
| 24 #define EVDEV_ABS_MT_LAST ABS_MT_TOOL_Y |
| 25 #define EVDEV_ABS_MT_COUNT (EVDEV_ABS_MT_LAST - EVDEV_ABS_MT_FIRST + 1) |
| 26 |
| 27 namespace ui { |
| 28 |
| 29 // Input device types. |
| 30 enum EVENTS_OZONE_EVDEV_EXPORT EventDeviceType { |
| 31 DT_KEYBOARD, |
| 32 DT_MOUSE, |
| 33 DT_TOUCHPAD, |
| 34 DT_TOUCHSCREEN, |
| 35 DT_MULTITOUCH, |
| 36 DT_MULTITOUCH_MOUSE, |
| 37 DT_ALL, |
| 38 }; |
| 39 |
| 40 // Device information for Linux input devices |
| 41 // |
| 42 // This stores and queries information about input devices; in |
| 43 // particular it knows which events the device can generate. |
| 44 class EVENTS_OZONE_EVDEV_EXPORT EventDeviceInfo { |
| 45 public: |
| 46 EventDeviceInfo(); |
| 47 ~EventDeviceInfo(); |
| 48 |
| 49 // Initialize device information from an open device. |
| 50 bool Initialize(int fd); |
| 51 |
| 52 // Manual initialization. |
| 53 void SetEventTypes(const unsigned long* ev_bits, size_t len); |
| 54 void SetKeyEvents(const unsigned long* key_bits, size_t len); |
| 55 void SetRelEvents(const unsigned long* rel_bits, size_t len); |
| 56 void SetAbsEvents(const unsigned long* abs_bits, size_t len); |
| 57 void SetMscEvents(const unsigned long* msc_bits, size_t len); |
| 58 void SetSwEvents(const unsigned long* sw_bits, size_t len); |
| 59 void SetLedEvents(const unsigned long* led_bits, size_t len); |
| 60 void SetProps(const unsigned long* prop_bits, size_t len); |
| 61 void SetAbsInfo(unsigned int code, const input_absinfo& absinfo); |
| 62 void SetAbsMtSlots(unsigned int code, const std::vector<int32_t>& values); |
| 63 void SetAbsMtSlot(unsigned int code, unsigned int slot, uint32_t value); |
| 64 |
| 65 // Check events this device can generate. |
| 66 bool HasEventType(unsigned int type) const; |
| 67 bool HasKeyEvent(unsigned int code) const; |
| 68 bool HasRelEvent(unsigned int code) const; |
| 69 bool HasAbsEvent(unsigned int code) const; |
| 70 bool HasMscEvent(unsigned int code) const; |
| 71 bool HasSwEvent(unsigned int code) const; |
| 72 bool HasLedEvent(unsigned int code) const; |
| 73 |
| 74 // Properties of absolute axes. |
| 75 int32_t GetAbsMinimum(unsigned int code) const; |
| 76 int32_t GetAbsMaximum(unsigned int code) const; |
| 77 int32_t GetAbsValue(unsigned int code) const; |
| 78 uint32_t GetAbsMtSlotCount() const; |
| 79 int32_t GetAbsMtSlotValue(unsigned int code, unsigned int slot) const; |
| 80 int32_t GetAbsMtSlotValueWithDefault(unsigned int code, |
| 81 unsigned int slot, |
| 82 int32_t default_value) const; |
| 83 |
| 84 // Device identification. |
| 85 const std::string& name() const { return name_; } |
| 86 uint16_t vendor_id() const { return vendor_id_; } |
| 87 uint16_t product_id() const { return product_id_; } |
| 88 |
| 89 // Check input device properties. |
| 90 bool HasProp(unsigned int code) const; |
| 91 |
| 92 // Has absolute X & Y axes (excludes MT) |
| 93 bool HasAbsXY() const; |
| 94 |
| 95 // Has MT absolute X & Y events. |
| 96 bool HasMTAbsXY() const; |
| 97 |
| 98 // Has relative X & Y axes. |
| 99 bool HasRelXY() const; |
| 100 |
| 101 // Has multitouch protocol "B". |
| 102 bool HasMultitouch() const; |
| 103 |
| 104 // Determine whether this is a "Direct Touch" device e.g. touchscreen. |
| 105 // Corresponds to INPUT_PROP_DIRECT but may be inferred. |
| 106 // NB: The Linux documentation says tablets would be direct, but they are |
| 107 // not (and drivers do not actually set INPUT_PROP_DIRECT for them). |
| 108 bool HasDirect() const; |
| 109 |
| 110 // Determine whether device moves the cursor. This is the case for touchpads |
| 111 // and tablets but not touchscreens. |
| 112 // Corresponds to INPUT_PROP_POINTER but may be inferred. |
| 113 bool HasPointer() const; |
| 114 |
| 115 // Has stylus EV_KEY events. |
| 116 bool HasStylus() const; |
| 117 |
| 118 // Determine whether there's a keyboard on this device. |
| 119 bool HasKeyboard() const; |
| 120 |
| 121 // Determine whether there's a mouse on this device. |
| 122 bool HasMouse() const; |
| 123 |
| 124 // Determine whether there's a touchpad on this device. |
| 125 bool HasTouchpad() const; |
| 126 |
| 127 // Determine whether there's a tablet on this device. |
| 128 bool HasTablet() const; |
| 129 |
| 130 // Determine whether there's a touchscreen on this device. |
| 131 bool HasTouchscreen() const; |
| 132 |
| 133 private: |
| 134 enum class LegacyAbsoluteDeviceType { |
| 135 LADT_TOUCHPAD, |
| 136 LADT_TOUCHSCREEN, |
| 137 LADT_TABLET, |
| 138 LADT_NONE, |
| 139 }; |
| 140 |
| 141 // Probe absolute X & Y axis behavior. This is for legacy drivers that |
| 142 // do not tell us what the axes mean. |
| 143 LegacyAbsoluteDeviceType ProbeLegacyAbsoluteDevice() const; |
| 144 |
| 145 unsigned long ev_bits_[EVDEV_BITS_TO_LONGS(EV_CNT)]; |
| 146 unsigned long key_bits_[EVDEV_BITS_TO_LONGS(KEY_CNT)]; |
| 147 unsigned long rel_bits_[EVDEV_BITS_TO_LONGS(REL_CNT)]; |
| 148 unsigned long abs_bits_[EVDEV_BITS_TO_LONGS(ABS_CNT)]; |
| 149 unsigned long msc_bits_[EVDEV_BITS_TO_LONGS(MSC_CNT)]; |
| 150 unsigned long sw_bits_[EVDEV_BITS_TO_LONGS(SW_CNT)]; |
| 151 unsigned long led_bits_[EVDEV_BITS_TO_LONGS(LED_CNT)]; |
| 152 unsigned long prop_bits_[EVDEV_BITS_TO_LONGS(INPUT_PROP_CNT)]; |
| 153 |
| 154 struct input_absinfo abs_info_[ABS_CNT]; |
| 155 |
| 156 // Store the values for the multi-touch properties for each slot. |
| 157 std::vector<int32_t> slot_values_[EVDEV_ABS_MT_COUNT]; |
| 158 |
| 159 // Device identification. |
| 160 std::string name_; |
| 161 uint16_t vendor_id_; |
| 162 uint16_t product_id_; |
| 163 |
| 164 DISALLOW_COPY_AND_ASSIGN(EventDeviceInfo); |
| 165 }; |
| 166 |
| 167 } // namspace ui |
| 168 |
| 169 #endif // UI_EVENTS_OZONE_EVDEV_EVENT_DEVICE_INFO_H_ |
OLD | NEW |