2011-12-20 20:21:11 +01:00
|
|
|
#ifndef keys_hh_INCLUDED
|
|
|
|
#define keys_hh_INCLUDED
|
|
|
|
|
2012-04-14 03:17:09 +02:00
|
|
|
#include "string.hh"
|
2013-04-09 20:05:40 +02:00
|
|
|
#include "unicode.hh"
|
|
|
|
|
|
|
|
#include <vector>
|
2011-12-20 20:21:11 +01:00
|
|
|
|
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
|
|
|
struct Key
|
|
|
|
{
|
|
|
|
enum class Modifiers
|
|
|
|
{
|
|
|
|
None = 0,
|
|
|
|
Control = 1,
|
|
|
|
Alt = 2,
|
|
|
|
ControlAlt = 3
|
|
|
|
};
|
2012-10-09 19:15:05 +02:00
|
|
|
enum NamedKey : Codepoint
|
2012-09-07 20:22:19 +02:00
|
|
|
{
|
2012-10-08 19:33:53 +02:00
|
|
|
// use UTF-16 surrogate pairs range
|
|
|
|
Backspace = 0xD800,
|
2012-09-07 20:22:19 +02:00
|
|
|
Escape,
|
|
|
|
Up,
|
|
|
|
Down,
|
|
|
|
Left,
|
|
|
|
Right,
|
2012-09-07 21:09:23 +02:00
|
|
|
PageUp,
|
|
|
|
PageDown,
|
2013-02-19 13:50:27 +01:00
|
|
|
Home,
|
|
|
|
End,
|
2012-09-11 14:27:21 +02:00
|
|
|
BackTab,
|
2012-10-18 19:56:57 +02:00
|
|
|
Invalid,
|
2012-09-07 20:22:19 +02:00
|
|
|
};
|
2011-12-20 20:21:11 +01:00
|
|
|
|
|
|
|
Modifiers modifiers;
|
2012-10-09 19:15:05 +02:00
|
|
|
Codepoint key;
|
2011-12-20 20:21:11 +01:00
|
|
|
|
2012-10-09 19:15:05 +02: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
|
|
|
|
2012-10-09 19:15:05 +02:00
|
|
|
constexpr Key(Codepoint key)
|
2012-09-07 20:22:19 +02:00
|
|
|
: 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; }
|
2012-10-18 19:56:57 +02:00
|
|
|
|
2013-07-26 01:44:25 +02:00
|
|
|
constexpr bool operator!=(Key other) const
|
2012-10-18 19:56:57 +02:00
|
|
|
{ return modifiers != other.modifiers or key != other.key; }
|
2011-12-20 20:21:11 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::vector<Key> KeyList;
|
|
|
|
|
2012-04-14 03:17:09 +02:00
|
|
|
KeyList parse_keys(const String& str);
|
2013-07-26 01:44:25 +02:00
|
|
|
String key_to_str(Key key);
|
2011-12-20 20:21:11 +01:00
|
|
|
|
2013-10-26 19:42:36 +02: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 }; }
|
|
|
|
|
2011-12-20 20:21:11 +01:00
|
|
|
}
|
|
|
|
|
2011-12-21 15:29:28 +01:00
|
|
|
namespace std
|
|
|
|
{
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct hash<Kakoune::Key> : unary_function<const Kakoune::Key&, size_t>
|
|
|
|
{
|
2013-07-26 01:44:25 +02:00
|
|
|
size_t operator()(Kakoune::Key key) const
|
2011-12-21 15:29:28 +01:00
|
|
|
{
|
|
|
|
return static_cast<size_t>(key.modifiers) * 1024 + key.key;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-20 20:21:11 +01:00
|
|
|
#endif // keys_hh_INCLUDED
|