Shortcut.h 1016 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Traits.h>
  8. #include <Kernel/API/KeyCode.h>
  9. namespace GUI {
  10. class Shortcut {
  11. public:
  12. Shortcut() { }
  13. Shortcut(u8 modifiers, KeyCode key)
  14. : m_modifiers(modifiers)
  15. , m_key(key)
  16. {
  17. }
  18. bool is_valid() const { return m_key != KeyCode::Key_Invalid; }
  19. u8 modifiers() const { return m_modifiers; }
  20. KeyCode key() const { return m_key; }
  21. String to_string() const;
  22. bool operator==(const Shortcut& other) const
  23. {
  24. return m_modifiers == other.m_modifiers
  25. && m_key == other.m_key;
  26. }
  27. private:
  28. u8 m_modifiers { 0 };
  29. KeyCode m_key { KeyCode::Key_Invalid };
  30. };
  31. }
  32. namespace AK {
  33. template<>
  34. struct Traits<GUI::Shortcut> : public GenericTraits<GUI::Shortcut> {
  35. static unsigned hash(const GUI::Shortcut& shortcut)
  36. {
  37. return pair_int_hash(shortcut.modifiers(), shortcut.key());
  38. }
  39. };
  40. }