2020-01-18 11:38:21 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 11:38:21 +03:00
|
|
|
*/
|
|
|
|
|
2019-03-02 12:04:49 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/Traits.h>
|
2020-07-04 18:22:23 +03:00
|
|
|
#include <Kernel/API/KeyCode.h>
|
2019-03-02 12:04:49 +03:00
|
|
|
|
2020-02-02 17:07:41 +03:00
|
|
|
namespace GUI {
|
|
|
|
|
|
|
|
class Shortcut {
|
2019-03-02 12:04:49 +03:00
|
|
|
public:
|
2021-09-16 09:57:01 +03:00
|
|
|
Shortcut() = default;
|
2020-02-02 17:07:41 +03:00
|
|
|
Shortcut(u8 modifiers, KeyCode key)
|
2019-03-02 12:04:49 +03:00
|
|
|
: m_modifiers(modifiers)
|
|
|
|
, m_key(key)
|
|
|
|
{
|
|
|
|
}
|
2021-06-24 18:09:41 +03:00
|
|
|
Shortcut(KeyCode key)
|
|
|
|
: m_modifiers(0)
|
|
|
|
, m_key(key)
|
|
|
|
{
|
|
|
|
}
|
2019-03-02 12:04:49 +03:00
|
|
|
|
|
|
|
bool is_valid() const { return m_key != KeyCode::Key_Invalid; }
|
2019-07-03 22:17:35 +03:00
|
|
|
u8 modifiers() const { return m_modifiers; }
|
2019-03-02 12:04:49 +03:00
|
|
|
KeyCode key() const { return m_key; }
|
|
|
|
String to_string() const;
|
|
|
|
|
2020-02-02 17:07:41 +03:00
|
|
|
bool operator==(const Shortcut& other) const
|
2019-03-02 12:04:49 +03:00
|
|
|
{
|
|
|
|
return m_modifiers == other.m_modifiers
|
|
|
|
&& m_key == other.m_key;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2019-07-03 22:17:35 +03:00
|
|
|
u8 m_modifiers { 0 };
|
2019-03-02 12:04:49 +03:00
|
|
|
KeyCode m_key { KeyCode::Key_Invalid };
|
|
|
|
};
|
|
|
|
|
2020-02-02 17:07:41 +03:00
|
|
|
}
|
|
|
|
|
2019-03-02 12:04:49 +03:00
|
|
|
namespace AK {
|
|
|
|
|
|
|
|
template<>
|
2020-02-02 17:07:41 +03:00
|
|
|
struct Traits<GUI::Shortcut> : public GenericTraits<GUI::Shortcut> {
|
|
|
|
static unsigned hash(const GUI::Shortcut& shortcut)
|
2019-03-02 12:04:49 +03:00
|
|
|
{
|
|
|
|
return pair_int_hash(shortcut.modifiers(), shortcut.key());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|