// gKeyMapper daemon - raw HID access to the keyboard's vendor interface. // // Uses the kernel's hidraw interface instead of libusb: hidraw provides // non-exclusive access, so other tools (OpenRGB, etc.) can talk to the same // device at the same time. The kernel driver (usbhid) stays attached. #ifndef GKEYMAPPER_DAEMON_GKEY_DEVICE_H #define GKEYMAPPER_DAEMON_GKEY_DEVICE_H #include #include "device_tables.h" namespace gkeymapper::daemon { class GKeyDevice { public: GKeyDevice() = default; ~GKeyDevice(); GKeyDevice(const GKeyDevice&) = delete; GKeyDevice& operator=(const GKeyDevice&) = delete; // Finds a supported keyboard and opens its hidraw node. Returns false (and // logs) if none is found. // // `quiet` silences the "cannot use the keyboard" lines only, which the // hot-plug retry uses so an unplugged keyboard does not flood the journal // with one line every retry. bool open(bool quiet = false); void close(); bool is_open() const { return fd_ >= 0; } // Sends the "stop mapping G-keys to F-keys" command if the model needs it. bool disable_binding(); // Reads one interrupt report. Returns the number of bytes (>0), 0 on // timeout, or a negative value on error. int read_report(uint8_t* buffer, int length, int timeoutMs); const DeviceProfile* profile() const { return profile_; } private: int find_hidraw_node(uint16_t vendor, uint16_t product); int fd_ = -1; const DeviceProfile* profile_ = nullptr; }; } // namespace gkeymapper::daemon #endif // GKEYMAPPER_DAEMON_GKEY_DEVICE_H