| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 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_GAMEPAD_EVENT_CONVERTER_EVDEV_H_ |
| 6 #define UI_EVENTS_OZONE_GAMEPAD_EVENT_CONVERTER_EVDEV_H_ |
| 7 |
| 8 #include <vector> |
| 9 |
| 10 #include "base/files/file_path.h" |
| 11 #include "base/macros.h" |
| 12 #include "ui/events/devices/input_device.h" |
| 13 #include "ui/events/event.h" |
| 14 #include "ui/events/ozone/evdev/event_converter_evdev.h" |
| 15 #include "ui/events/ozone/evdev/event_device_info.h" |
| 16 #include "ui/events/ozone/evdev/events_ozone_evdev_export.h" |
| 17 #include "ui/events/ozone/evdev/scoped_input_device.h" |
| 18 #include "ui/events/ozone/gamepad/gamepad_mapping.h" |
| 19 |
| 20 struct input_event; |
| 21 |
| 22 namespace ui { |
| 23 |
| 24 class DeviceEventDispatcherEvdev; |
| 25 |
| 26 class EVENTS_OZONE_EVDEV_EXPORT GamepadEventConverterEvdev |
| 27 : public EventConverterEvdev { |
| 28 public: |
| 29 GamepadEventConverterEvdev(ScopedInputDevice fd, |
| 30 base::FilePath path, |
| 31 int id, |
| 32 const EventDeviceInfo& info, |
| 33 DeviceEventDispatcherEvdev* dispatcher); |
| 34 |
| 35 ~GamepadEventConverterEvdev() override; |
| 36 |
| 37 // EventConverterEvdev: |
| 38 void OnFileCanReadWithoutBlocking(int fd) override; |
| 39 bool HasGamepad() const override; |
| 40 void OnDisabled() override; |
| 41 |
| 42 // This function processes one input_event from evdev. |
| 43 void ProcessEvent(const struct input_event& input); |
| 44 |
| 45 private: |
| 46 // This function releases all the keys and resets all the axises. |
| 47 void ResetGamepad(); |
| 48 |
| 49 // This function reads current gamepad status and resyncs the gamepad. |
| 50 void ResyncGamepad(); |
| 51 |
| 52 void OnButtonChange(unsigned int code, |
| 53 double value, |
| 54 const base::TimeTicks& timestamp); |
| 55 void OnAbsChange(unsigned int code, |
| 56 double value, |
| 57 const base::TimeTicks& timestamp); |
| 58 void OnSync(const base::TimeTicks& timestamp); |
| 59 |
| 60 // Sometimes, we want to drop abs values, when we do so, we no longer want to |
| 61 // send gamepad frame event when we see next sync. This flag is set to false |
| 62 // when each frame is sent. It is set to true when Btn or Abs event is sent. |
| 63 bool will_send_frame_; |
| 64 |
| 65 // This is the abs_info for this gamepad. It will be used to map abs values. |
| 66 struct input_absinfo abs_info_[ABS_CNT]; |
| 67 |
| 68 GamepadMapper mapper_; |
| 69 |
| 70 // Input device file descriptor. |
| 71 ScopedInputDevice input_device_fd_; |
| 72 |
| 73 // Callbacks for dispatching events. |
| 74 DeviceEventDispatcherEvdev* dispatcher_; |
| 75 |
| 76 DISALLOW_COPY_AND_ASSIGN(GamepadEventConverterEvdev); |
| 77 }; |
| 78 |
| 79 } // namespace ui |
| 80 |
| 81 #endif // UI_EVENTS_OZONE_GAMEPAD_EVENT_CONVERTER_EVDEV_H_ |
| OLD | NEW |