// gKeyMapper daemon - executes the mapping configured for a G key. #ifndef GKEYMAPPER_DAEMON_ACTION_H #define GKEYMAPPER_DAEMON_ACTION_H #include #include #include #include "keymap.h" #include "mapping.h" #include "uinput_keyboard.h" namespace gkeymapper::daemon { class ActionRunner { public: // Opens the virtual keyboard and the keyboard layout. Without the virtual // keyboard, "key" mappings are skipped but "command" mappings still work. bool init(); void run(const gkeymapper::Mapping& mapping); // "keyhold": presses the keys of the mapping and keeps them down until the G // key is released. Returns whether anything is being held; a sequence, an // unusable target or a missing virtual keyboard fall back to a tap (false), // so the caller does not have to special-case them. Releasing index 0..8 is // done by end_hold(), all of them at once by release_held(). bool begin_hold(int index, const gkeymapper::Mapping& mapping); void end_hold(int index); // Let go of every held key. Called on device loss, on shutdown and before a // new device is claimed: a virtual key that stayed down because its release // report never arrived would look like a stuck key to the whole session. void release_held(); // Replays one key press + release. Used by the media-key passthrough, which // is not a mapping: the keyboard reports mute/volume/play only on the // interface the daemon holds, so they are forwarded verbatim. void tap_key(unsigned short code); private: void run_command(const std::string& command); // Parses mapping.target through the active layout. Logs and returns false on // an invalid shortcut. bool resolve_shortcut(const std::string& target, std::vector& steps); UinputKeyboard keyboard_; gkeymapper::Keymap keymap_; // Codes each G key (0 = G1) currently keeps down, empty when not holding. std::array, gkeymapper::kNumKeys> held_{}; }; } // namespace gkeymapper::daemon #endif // GKEYMAPPER_DAEMON_ACTION_H