GShortcut.h 889 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #pragma once
  2. #include <AK/String.h>
  3. #include <AK/Traits.h>
  4. #include <Kernel/KeyCode.h>
  5. class GShortcut {
  6. public:
  7. GShortcut() {}
  8. GShortcut(u8 modifiers, KeyCode key)
  9. : m_modifiers(modifiers)
  10. , m_key(key)
  11. {
  12. }
  13. bool is_valid() const { return m_key != KeyCode::Key_Invalid; }
  14. u8 modifiers() const { return m_modifiers; }
  15. KeyCode key() const { return m_key; }
  16. String to_string() const;
  17. bool operator==(const GShortcut& other) const
  18. {
  19. return m_modifiers == other.m_modifiers
  20. && m_key == other.m_key;
  21. }
  22. private:
  23. u8 m_modifiers { 0 };
  24. KeyCode m_key { KeyCode::Key_Invalid };
  25. };
  26. namespace AK {
  27. template<>
  28. struct Traits<GShortcut> : public GenericTraits<GShortcut> {
  29. static unsigned hash(const GShortcut& shortcut)
  30. {
  31. return pair_int_hash(shortcut.modifiers(), shortcut.key());
  32. }
  33. };
  34. }