2011-12-20 20:21:11 +01:00
|
|
|
#ifndef keys_hh_INCLUDED
|
|
|
|
#define keys_hh_INCLUDED
|
|
|
|
|
2015-08-18 01:19:14 +02:00
|
|
|
#include "coord.hh"
|
2014-11-12 22:27:07 +01:00
|
|
|
#include "flags.hh"
|
2014-12-16 19:57:19 +01:00
|
|
|
#include "hash.hh"
|
2017-03-17 00:08:10 +01:00
|
|
|
#include "meta.hh"
|
2015-08-18 01:19:14 +02:00
|
|
|
#include "optional.hh"
|
|
|
|
#include "unicode.hh"
|
2015-01-12 14:45:44 +01:00
|
|
|
#include "vector.hh"
|
2011-12-20 20:21:11 +01:00
|
|
|
|
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
|
|
|
struct Key
|
|
|
|
{
|
2014-12-16 19:57:19 +01:00
|
|
|
enum class Modifiers : int
|
2011-12-20 20:21:11 +01:00
|
|
|
{
|
|
|
|
None = 0,
|
2014-10-15 20:13:51 +02:00
|
|
|
Control = 1 << 0,
|
|
|
|
Alt = 1 << 1,
|
2015-03-22 11:08:44 +01:00
|
|
|
ControlAlt = Control | Alt,
|
|
|
|
|
|
|
|
MousePress = 1 << 2,
|
|
|
|
MouseRelease = 1 << 3,
|
|
|
|
MousePos = 1 << 4,
|
2015-03-22 13:17:01 +01:00
|
|
|
MouseWheelDown = 1 << 5,
|
|
|
|
MouseWheelUp = 1 << 6,
|
2015-03-28 19:18:28 +01:00
|
|
|
MouseEvent = MousePress | MouseRelease | MousePos |
|
|
|
|
MouseWheelDown | MouseWheelUp,
|
2015-08-23 16:18:18 +02:00
|
|
|
|
|
|
|
Resize = 1 << 7,
|
2011-12-20 20:21:11 +01:00
|
|
|
};
|
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,
|
2014-05-25 18:41:28 +02:00
|
|
|
Delete,
|
2012-09-07 20:22:19 +02:00
|
|
|
Escape,
|
2016-07-05 20:21:15 +02:00
|
|
|
Return,
|
2012-09-07 20:22:19 +02:00
|
|
|
Up,
|
|
|
|
Down,
|
|
|
|
Left,
|
|
|
|
Right,
|
2012-09-07 21:09:23 +02:00
|
|
|
PageUp,
|
|
|
|
PageDown,
|
2013-02-19 13:50:27 +01:00
|
|
|
Home,
|
|
|
|
End,
|
2016-07-05 20:21:15 +02:00
|
|
|
Tab,
|
2012-09-11 14:27:21 +02:00
|
|
|
BackTab,
|
2013-11-09 12:12:55 +01:00
|
|
|
F1,
|
|
|
|
F2,
|
|
|
|
F3,
|
|
|
|
F4,
|
|
|
|
F5,
|
|
|
|
F6,
|
|
|
|
F7,
|
|
|
|
F8,
|
|
|
|
F9,
|
|
|
|
F10,
|
|
|
|
F11,
|
|
|
|
F12,
|
2015-07-15 14:56:31 +02:00
|
|
|
FocusIn,
|
|
|
|
FocusOut,
|
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
|
|
|
|
2017-10-20 06:16:58 +02:00
|
|
|
Modifiers modifiers = {};
|
|
|
|
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) {}
|
|
|
|
|
2017-10-20 06:16:58 +02:00
|
|
|
constexpr Key() = default;
|
|
|
|
|
2015-03-07 16:29:21 +01:00
|
|
|
constexpr uint64_t val() const { return (uint64_t)modifiers << 32 | key; }
|
2012-10-18 19:56:57 +02:00
|
|
|
|
2015-03-07 16:29:21 +01:00
|
|
|
constexpr bool operator==(Key other) const { return val() == other.val(); }
|
|
|
|
constexpr bool operator!=(Key other) const { return val() != other.val(); }
|
|
|
|
constexpr bool operator<(Key other) const { return val() < other.val(); }
|
2015-03-22 11:08:44 +01:00
|
|
|
|
2016-09-22 21:36:26 +02:00
|
|
|
constexpr DisplayCoord coord() const { return {(int)((key & 0xFFFF0000) >> 16), (int)(key & 0x0000FFFF)}; }
|
2015-08-18 01:19:14 +02:00
|
|
|
|
|
|
|
Optional<Codepoint> codepoint() const;
|
2011-12-20 20:21:11 +01:00
|
|
|
};
|
|
|
|
|
2017-03-15 18:55:34 +01:00
|
|
|
constexpr bool with_bit_ops(Meta::Type<Key::Modifiers>) { return true; }
|
2014-11-12 22:27:07 +01:00
|
|
|
|
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
|
|
|
|
2017-01-30 14:38:56 +01:00
|
|
|
constexpr Key alt(Key key)
|
|
|
|
{
|
|
|
|
return { key.modifiers | Key::Modifiers::Alt, key.key };
|
|
|
|
}
|
|
|
|
constexpr Key ctrl(Key key)
|
|
|
|
{
|
|
|
|
return { key.modifiers | Key::Modifiers::Control, key.key };
|
|
|
|
}
|
|
|
|
constexpr Key ctrlalt(Key key)
|
|
|
|
{
|
|
|
|
return { key.modifiers | Key::Modifiers::ControlAlt, key.key };
|
|
|
|
}
|
2013-10-26 19:42:36 +02:00
|
|
|
|
2016-09-22 21:36:26 +02:00
|
|
|
constexpr Codepoint encode_coord(DisplayCoord coord) { return (Codepoint)(((int)coord.line << 16) | ((int)coord.column & 0x0000FFFF)); }
|
2015-08-23 16:18:18 +02:00
|
|
|
|
2016-09-22 21:36:26 +02:00
|
|
|
constexpr Key resize(DisplayCoord dim) { return { Key::Modifiers::Resize, encode_coord(dim) }; }
|
2015-03-22 11:08:44 +01:00
|
|
|
|
2017-10-17 16:45:17 +02:00
|
|
|
constexpr 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
|