#pragma once #include #include #include #include #include #include "xutil.h" class SeqMatcher { public: using Callback = std::function; struct SymSequence { std::vector syms; Callback callback; }; SeqMatcher(Display *dpy); // Initialise with an initial list of sequences. SeqMatcher(Display *dpy, std::vector seqs); // Register a key sequence void addSequence(const std::vector &syms, Callback callback); // Returns bel()-running callback if unrecognised sequence is given std::optional observe(const XKeyEvent &ev); // Cancel any running sequence and restart from the beginning void reset(); private: struct Node; using NodeMap = std::unordered_map>; struct Node { std::variant v; }; Display *const dpy; Node rootNode; Node *curNode = &rootNode; };