5#include <portals/input.hpp>
7#include <initializer_list>
158enum class ShortcutActions :
unsigned char {
175 KeySelection(std::expected<std::shared_ptr<const Shortcut>,
ShortcutError> shortcut, detail::ShortcutActions actions,
177 : shortcut_(std::move(shortcut)), actions_(actions), options_(options) {
180 std::expected<std::shared_ptr<const Shortcut>,
ShortcutError> shortcut_;
181 detail::ShortcutActions actions_;
190std::optional<KeyEvent> shortcutEvent(
const InputEvent &event, ShortcutActions actions)
noexcept;
202std::span<const key::Chord> shortcutAlternative(
const Shortcut &shortcut, std::size_t index)
noexcept;
209std::optional<KeyEvent> matchShortcutActions(
const Shortcut &shortcut,
const InputEvent &event,
210 ShortcutActions actions)
noexcept;
226 return selection.shortcut_;
233 return selection.actions_;
240 return selection.options_;
253std::expected<Shortcut, ShortcutError> prepareShortcut(std::initializer_list<key::Chord> chords,
254 ShortcutOptions options = {});
260inline std::expected<Shortcut, ShortcutError> prepareShortcut(std::string_view source, ShortcutOptions options = {}) {
268std::expected<Shortcut, ShortcutError> prepareShortcut(
const Shortcut &shortcut, ShortcutOptions options = {});
273std::expected<Shortcut, ShortcutError> prepareShortcut(Shortcut &&shortcut, ShortcutOptions options = {});
278std::expected<std::shared_ptr<Shortcut>, ShortcutError>
279retainShortcut(std::expected<Shortcut, ShortcutError> &&shortcut);
284template <
class Source>
285concept ShortcutSource =
requires(Source source) { prepareShortcut(std::move(source)); };
Copyable immutable owning shortcut selection, or a deferred typed construction error....
Definition shortcut.hpp:171
A shortcut value or string accepted by the checked owning normalizer.
Definition shortcut.hpp:285
Public Portals API.
Definition action.hpp:8
std::optional< KeyEvent > matchShortcut(const Shortcut &shortcut, const InputEvent &event, ShortcutBehavior behavior={}) noexcept
std::variant< KeyEvent, TextInputEvent, MouseInputEvent, PasteInputEvent, InputProbeCandidate, InputIssue > InputEvent
Independent owning result, usable beyond decoder reset/destruction.
Definition input.hpp:378
@ INVALID_OPTIONS
Runner options are invalid, or a native run was requested with an injected clock.
Definition application.hpp:31
@ NO_MEMORY
Allocation failed at a runner exception boundary.
Definition application.hpp:33
std::expected< void, ShortcutError > validateShortcut(const Shortcut &shortcut, ShortcutOptions options={}) noexcept
std::expected< Shortcut, ShortcutError > parseShortcut(std::string_view source, ShortcutOptions options={})
ShortcutErrorKind
Bounded shortcut syntax and value-validation failures, never borrowing source text.
Definition shortcut.hpp:15
@ INVALID_CHORD
Invalid semantic key/scalar combination.
Definition shortcut.hpp:26
@ STROKE_LIMIT
Too many key strokes in one alternative.
Definition shortcut.hpp:19
@ AMBIGUOUS_PREFIX
An alternative is a proper prefix of another in this registration.
Definition shortcut.hpp:29
@ ALTERNATIVE_LIMIT
Too many alternatives.
Definition shortcut.hpp:18
@ EMPTY_TOKEN
Missing token around a plus or comma separator.
Definition shortcut.hpp:21
@ DUPLICATE_MODIFIER
One semantic modifier occurs twice in a stroke.
Definition shortcut.hpp:23
@ EXPECTED_KEY
Modifiers were provided without a key.
Definition shortcut.hpp:24
@ UNKNOWN_KEY
Unsupported ASCII key/modifier name, including physical qualifiers.
Definition shortcut.hpp:22
@ INVALID_ACTION_SET
Empty action set or invalid action; offset identifies the action index.
Definition shortcut.hpp:28
@ RESERVED_CANCEL
Unmodified Escape is reserved for cancelling pending input.
Definition shortcut.hpp:30
@ EMPTY_ALTERNATIVE
Missing alternative before or after a separator.
Definition shortcut.hpp:20
@ UNSUPPORTED_SEQUENCE
Reserved legacy diagnostic; valid sequences are now supported.
Definition shortcut.hpp:25
@ SOURCE_LIMIT
Source bytes exceed the configured cap.
Definition scene_resource_error.hpp:16
Owning key value without an inferred physical keyboard scan code.
Definition input.hpp:213
Command admission independent of low-level KeyEvent binding behavior.
Definition shortcut.hpp:51
bool repeat
Explicitly admit native REPEAT events; PRESS is always admitted, RELEASE never is.
Definition shortcut.hpp:52
Allocation-free diagnostic independent of source and scene lifetime.
Definition shortcut.hpp:34
bool operator==(const ShortcutError &other) const =default
std::size_t offset
Zero-based byte offset; typed chord errors use their alternative index.
Definition shortcut.hpp:36
ShortcutErrorKind cause
Exact parser/value failure.
Definition shortcut.hpp:35
Configurable finite parser limits; every value must be positive.
Definition shortcut.hpp:44
std::size_t maxAlternatives
Maximum alternatives retained by one registration.
Definition shortcut.hpp:46
std::size_t maxSourceBytes
Maximum runtime source length in bytes.
Definition shortcut.hpp:45
std::size_t maxStrokes
Maximum strokes in one alternative.
Definition shortcut.hpp:47
ShortcutSequence & operator=(ShortcutSequence &&other) noexcept
Definition shortcut.hpp:81
ShortcutSequence(const ShortcutSequence &other)=default
ShortcutSequence(ShortcutSequence &&other)
Definition shortcut.hpp:69
std::vector< key::Chord > strokes
Owned ordered strokes with exact semantic modifiers.
Definition shortcut.hpp:87
ShortcutSequence()
Construct empty storage; debug iterator proxy allocation may throw.
Definition shortcut.hpp:58
ShortcutSequence & operator=(const ShortcutSequence &other)=default
ShortcutSequence(std::initializer_list< key::Chord > chords)
Definition shortcut.hpp:62
Owning shortcut alternatives; one registration invokes at most once per completed event.
Definition shortcut.hpp:91
std::vector< ShortcutSequence > sequences
Owned sequences sharing the alternative budget with single chords.
Definition shortcut.hpp:128
Shortcut()
Construct empty owning storage; debug-container allocation is allowed to throw.
Definition shortcut.hpp:93
std::vector< key::Chord > alternatives
Owned values, never views into a caller string or initializer list.
Definition shortcut.hpp:127
Shortcut(Shortcut &&other)
Definition shortcut.hpp:107
Shortcut(std::initializer_list< key::Chord > chords)
Definition shortcut.hpp:97
Shortcut(const Shortcut &other)=default
Shortcut & operator=(const Shortcut &other)=default
Shortcut & operator=(Shortcut &&other) noexcept
Definition shortcut.hpp:120
Internal bridge keeping selection payload immutable and checked.
Definition shortcut.hpp:213
static ShortcutActions actions(const KeySelection &selection) noexcept
Definition shortcut.hpp:232
static ShortcutOptions options(const KeySelection &selection) noexcept
Definition shortcut.hpp:239
static const auto & shortcut(const KeySelection &selection) noexcept
Definition shortcut.hpp:225
static KeySelection make(std::expected< Shortcut, ShortcutError > &&shortcut, std::initializer_list< KeyAction > actions, ShortcutOptions options)
Compile-time semantic shortcut; letters match ASCII case with exact modifiers.
Definition input.hpp:96