rgb_keyboard_manager.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright 2022 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 ASH_RGB_KEYBOARD_RGB_KEYBOARD_MANAGER_H_
  5. #define ASH_RGB_KEYBOARD_RGB_KEYBOARD_MANAGER_H_
  6. #include <stdint.h>
  7. #include "ash/ash_export.h"
  8. #include "ash/ime/ime_controller_impl.h"
  9. #include "base/memory/raw_ptr.h"
  10. #include "chromeos/ash/components/dbus/rgbkbd/rgbkbd_client.h"
  11. #include "third_party/cros_system_api/dbus/rgbkbd/dbus-constants.h"
  12. namespace ash {
  13. // RgbKeyboardManager is singleton class that provides clients access to
  14. // RGB keyboard-related API's. Clients should interact with this class instead
  15. // of the rgbkbd DBus client.
  16. // This class is owned by ash/shell and should NOT be created by any other
  17. // means.
  18. class ASH_EXPORT RgbKeyboardManager : public ImeControllerImpl::Observer,
  19. public RgbkbdClient::Observer {
  20. public:
  21. explicit RgbKeyboardManager(ImeControllerImpl* ime_controller);
  22. RgbKeyboardManager(const RgbKeyboardManager&) = delete;
  23. RgbKeyboardManager& operator=(const RgbKeyboardManager&) = delete;
  24. ~RgbKeyboardManager() override;
  25. rgbkbd::RgbKeyboardCapabilities GetRgbKeyboardCapabilities() const;
  26. void SetStaticBackgroundColor(uint8_t r, uint8_t g, uint8_t b);
  27. void SetRainbowMode();
  28. void SetAnimationMode(rgbkbd::RgbAnimationMode mode);
  29. // Returns the global instance if initialized. May return null.
  30. static RgbKeyboardManager* Get();
  31. bool IsRgbKeyboardSupported() const {
  32. return capabilities_ != rgbkbd::RgbKeyboardCapabilities::kNone;
  33. }
  34. private:
  35. // ImeControllerImpl::Observer:
  36. void OnCapsLockChanged(bool enabled) override;
  37. void OnKeyboardLayoutNameChanged(const std::string&) override {}
  38. // RgbkbdClient::Observer:
  39. void OnCapabilityUpdatedForTesting(
  40. rgbkbd::RgbKeyboardCapabilities capability) override;
  41. void FetchRgbKeyboardSupport();
  42. void OnGetRgbKeyboardCapabilities(
  43. absl::optional<rgbkbd::RgbKeyboardCapabilities> reply);
  44. void InitializeRgbKeyboard();
  45. bool IsPerKeyKeyboard() const;
  46. rgbkbd::RgbKeyboardCapabilities capabilities_ =
  47. rgbkbd::RgbKeyboardCapabilities::kNone;
  48. raw_ptr<ImeControllerImpl> ime_controller_ptr_;
  49. // Note: This should remain the last member so it'll be destroyed and
  50. // invalidate its weak pointers before any other members are destroyed.
  51. base::WeakPtrFactory<RgbKeyboardManager> weak_ptr_factory_{this};
  52. };
  53. } // namespace ash
  54. #endif // ASH_RGB_KEYBOARD_RGB_KEYBOARD_MANAGER_H_