gaming_seat.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright 2016 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. #ifndef COMPONENTS_EXO_GAMING_SEAT_H_
  5. #define COMPONENTS_EXO_GAMING_SEAT_H_
  6. #include <memory>
  7. #include "base/containers/flat_map.h"
  8. #include "base/memory/weak_ptr.h"
  9. #include "base/synchronization/lock.h"
  10. #include "base/task/sequenced_task_runner.h"
  11. #include "components/exo/gamepad.h"
  12. #include "components/exo/wm_helper.h"
  13. #include "ui/aura/client/focus_change_observer.h"
  14. #include "ui/events/ozone/gamepad/gamepad_observer.h"
  15. namespace exo {
  16. class GamingSeatDelegate;
  17. class GamepadDelegate;
  18. // This class represents one gaming seat. It uses /device/gamepad or
  19. // ozone/gamepad as backend and notifies corresponding GamepadDelegate of any
  20. // gamepad changes.
  21. class GamingSeat : public aura::client::FocusChangeObserver,
  22. public ui::GamepadObserver {
  23. public:
  24. // This class will monitor gamepad connection changes and manage gamepads.
  25. GamingSeat(GamingSeatDelegate* gaming_seat_delegate);
  26. GamingSeat(const GamingSeat&) = delete;
  27. GamingSeat& operator=(const GamingSeat&) = delete;
  28. ~GamingSeat() override;
  29. // Overridden from ui::aura::client::FocusChangeObserver:
  30. void OnWindowFocused(aura::Window* gained_focus,
  31. aura::Window* lost_focus) override;
  32. // Overridden from ui::GamepadObserver:
  33. void OnGamepadDevicesUpdated() override;
  34. void OnGamepadEvent(const ui::GamepadEvent& event) override;
  35. private:
  36. // The delegate that handles gamepad_added.
  37. GamingSeatDelegate* const delegate_;
  38. // Contains the delegate for each gamepad device.
  39. base::flat_map<int, std::unique_ptr<Gamepad>> gamepads_;
  40. // The flag if a valid target for gaming seat is focused. In other words, if
  41. // it's true, this class is observing gamepad events.
  42. bool focused_ = false;
  43. };
  44. } // namespace exo
  45. #endif // COMPONENTS_EXO_GAMING_SEAT_H_