kakoune/src/keys.hh

86 lines
1.8 KiB
C++
Raw Normal View History

2011-12-20 20:21:11 +01:00
#ifndef keys_hh_INCLUDED
#define keys_hh_INCLUDED
2013-04-09 20:05:40 +02:00
#include "unicode.hh"
2014-11-12 22:27:07 +01:00
#include "flags.hh"
#include "hash.hh"
2015-01-12 14:45:44 +01:00
#include "vector.hh"
2011-12-20 20:21:11 +01:00
namespace Kakoune
{
struct Key
{
enum class Modifiers : int
2011-12-20 20:21:11 +01:00
{
None = 0,
Control = 1 << 0,
Alt = 1 << 1,
ControlAlt = Control | Alt
2011-12-20 20:21:11 +01:00
};
enum NamedKey : Codepoint
{
2012-10-08 19:33:53 +02:00
// use UTF-16 surrogate pairs range
Backspace = 0xD800,
Delete,
Escape,
Up,
Down,
Left,
Right,
2012-09-07 21:09:23 +02:00
PageUp,
PageDown,
Home,
End,
BackTab,
2013-11-09 12:12:55 +01:00
F1,
F2,
F3,
F4,
F5,
F6,
F7,
F8,
F9,
F10,
F11,
F12,
Invalid,
};
2011-12-20 20:21:11 +01:00
Modifiers modifiers;
Codepoint key;
2011-12-20 20:21:11 +01:00
constexpr Key(Modifiers modifiers, Codepoint key)
2011-12-20 20:21:11 +01:00
: modifiers(modifiers), key(key) {}
2011-12-21 15:29:28 +01:00
constexpr Key(Codepoint key)
: modifiers(Modifiers::None), key(key) {}
2013-07-26 01:44:25 +02:00
constexpr bool operator==(Key other) const
2011-12-21 15:29:28 +01:00
{ return modifiers == other.modifiers and key == other.key; }
2013-07-26 01:44:25 +02:00
constexpr bool operator!=(Key other) const
{ return modifiers != other.modifiers or key != other.key; }
2011-12-20 20:21:11 +01:00
};
2014-11-12 22:27:07 +01:00
template<> struct WithBitOps<Key::Modifiers> : std::true_type {};
2015-01-12 14:45:44 +01:00
using KeyList = Vector<Key, MemoryDomain::Mapping>;
2011-12-20 20:21:11 +01:00
2014-11-12 22:27:07 +01:00
class String;
class StringView;
2014-04-20 12:27:59 +02:00
KeyList parse_keys(StringView str);
2013-07-26 01:44:25 +02:00
String key_to_str(Key key);
2011-12-20 20:21:11 +01:00
constexpr Key alt(Codepoint key) { return { Key::Modifiers::Alt, key }; }
constexpr Key ctrl(Codepoint key) { return { Key::Modifiers::Control, key }; }
constexpr Key ctrlalt(Codepoint key) { return { Key::Modifiers::ControlAlt, key }; }
inline size_t hash_value(const Key& key) { return hash_values(key.modifiers, key.key); }
2011-12-21 15:29:28 +01:00
}
2011-12-20 20:21:11 +01:00
#endif // keys_hh_INCLUDED