Files

58 lines
2.1 KiB
C
Raw Permalink Normal View History

2026-10-17 03:53:51 +02:00
// gKeyMapper daemon - executes the mapping configured for a G key.
#ifndef GKEYMAPPER_DAEMON_ACTION_H
#define GKEYMAPPER_DAEMON_ACTION_H
2026-10-18 16:59:51 +02:00
#include <array>
2026-10-17 03:53:51 +02:00
#include <string>
2026-10-18 16:59:51 +02:00
#include <vector>
2026-10-17 03:53:51 +02:00
#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);
2026-10-18 16:59:51 +02:00
// "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();
2026-10-18 03:50:33 +02:00
// 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);
2026-10-17 03:53:51 +02:00
private:
void run_command(const std::string& command);
2026-10-18 16:59:51 +02:00
// Parses mapping.target through the active layout. Logs and returns false on
// an invalid shortcut.
bool resolve_shortcut(const std::string& target,
std::vector<gkeymapper::ShortcutStep>& steps);
2026-10-17 03:53:51 +02:00
UinputKeyboard keyboard_;
gkeymapper::Keymap keymap_;
2026-10-18 16:59:51 +02:00
// Codes each G key (0 = G1) currently keeps down, empty when not holding.
std::array<std::vector<unsigned short>, gkeymapper::kNumKeys> held_{};
2026-10-17 03:53:51 +02:00
};
} // namespace gkeymapper::daemon
#endif // GKEYMAPPER_DAEMON_ACTION_H