Files
gKeyMapper/daemon/g910_device.h

52 lines
1.6 KiB
C
Raw Permalink Normal View History

2026-10-27 18:57:14 +01:00
// 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.
2026-10-17 03:53:51 +02:00
#ifndef GKEYMAPPER_DAEMON_GKEY_DEVICE_H
#define GKEYMAPPER_DAEMON_GKEY_DEVICE_H
#include <cstdint>
#include "device_tables.h"
namespace gkeymapper::daemon {
class GKeyDevice {
public:
GKeyDevice() = default;
~GKeyDevice();
GKeyDevice(const GKeyDevice&) = delete;
GKeyDevice& operator=(const GKeyDevice&) = delete;
2026-10-27 18:57:14 +01:00
// Finds a supported keyboard and opens its hidraw node. Returns false (and
// logs) if none is found.
2026-10-18 03:50:33 +02:00
//
// `quiet` silences the "cannot use the keyboard" lines only, which the
// hot-plug retry uses so an unplugged keyboard does not flood the journal
2026-10-27 18:57:14 +01:00
// with one line every retry.
2026-10-18 03:50:33 +02:00
bool open(bool quiet = false);
2026-10-17 03:53:51 +02:00
void close();
2026-10-27 18:57:14 +01:00
bool is_open() const { return fd_ >= 0; }
2026-10-17 03:53:51 +02:00
// 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:
2026-10-27 18:57:14 +01:00
int find_hidraw_node(uint16_t vendor, uint16_t product);
2026-10-17 03:53:51 +02:00
2026-10-27 18:57:14 +01:00
int fd_ = -1;
2026-10-17 03:53:51 +02:00
const DeviceProfile* profile_ = nullptr;
};
} // namespace gkeymapper::daemon
#endif // GKEYMAPPER_DAEMON_GKEY_DEVICE_H