7#include "keyboard_key.hpp"
9#include "../utility/utility.hpp"
10#include "../codec/codec.hpp"
11#include "../coroutine/module.hpp"
12#include "../macros.hpp"
13#include <unordered_map>
17namespace hi {
inline namespace v1 {
27 bindings[key].add_system_command(
command);
32 bindings[key].add_ignored_command(
command);
37 bindings[key].add_user_command(
command);
47 if (
event == gui_event_type::keyboard_down) {
48 hilet i = bindings.
find(keyboard_key{
event.keyboard_modifiers,
event.key()});
49 if (i != bindings.
cend()) {
50 for (
auto &e : i->second.get_events()) {
71 hilet data = parse_JSON(path);
74 hi_check(data.contains(
"bindings"),
"Missing key 'bindings' at top level.");
85 "Expecting required 'key' and 'command' for a binding, got {}",
101 if (
command == gui_event_type::none) {
106 add_ignored_binding(key,
command);
108 add_system_binding(key,
command);
110 add_user_binding(key,
command);
115 throw io_error(std::format(
"{}: Could not load keyboard bindings.\n{}", path.string(), e.
what()));
155 if (i == ignored.
cend()) {
164 if (i == user.
cend()) {
176 if (i == cache.
cend()) {
181 for (hilet
cmd : ignored) {
183 if (i != cache.
cend()) {
188 for (hilet
cmd : user) {
190 if (i == cache.
cend()) {
204inline keyboard_bindings& keyboard_bindings::global()
noexcept
207 _global = std::make_unique<keyboard_bindings>();
212inline void load_user_keyboard_bindings(std::filesystem::path
const& path)
214 return keyboard_bindings::global().load_bindings(path,
false);
217inline void load_system_keyboard_bindings(std::filesystem::path
const& path)
219 return keyboard_bindings::global().load_bindings(path,
true);
224 for (
auto &e : keyboard_bindings::global().translate(
event)) {
Definition of GUI event types.
gui_event_type
GUI event type.
Definition gui_event_type.hpp:24
DOXYGEN BUG.
Definition algorithm.hpp:16
geometry/margins.hpp
Definition lookahead_iterator.hpp:5
constexpr gui_event_type to_gui_event_type(std::string_view name) noexcept
Convert a name to a GUI event type.
Definition gui_event_type.hpp:202
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
A user interface event.
Definition gui_event.hpp:75
Definition keyboard_bindings.hpp:19
void clear() noexcept
Clear all bindings.
Definition keyboard_bindings.hpp:62
void load_bindings(std::filesystem::path const &path, bool system_binding=false)
Load bindings from a JSON file.
Definition keyboard_bindings.hpp:69
generator< gui_event > translate(gui_event event) const noexcept
translate a key press in the empty-context to a command.
Definition keyboard_bindings.hpp:45
Exception thrown during parsing on an error.
Definition exception_intf.hpp:47
Exception thrown during I/O on an error.
Definition exception_intf.hpp:172
T emplace_back(T... args)