55 lines
1.6 KiB
C++
55 lines
1.6 KiB
C++
// gKeyMapper daemon - raw USB HID access to the keyboard's vendor interface.
|
|
#ifndef GKEYMAPPER_DAEMON_GKEY_DEVICE_H
|
|
#define GKEYMAPPER_DAEMON_GKEY_DEVICE_H
|
|
|
|
#include <cstdint>
|
|
|
|
#include "device_tables.h"
|
|
|
|
struct libusb_context;
|
|
struct libusb_device_handle;
|
|
|
|
namespace gkeymapper::daemon {
|
|
|
|
class GKeyDevice {
|
|
public:
|
|
GKeyDevice() = default;
|
|
~GKeyDevice();
|
|
|
|
GKeyDevice(const GKeyDevice&) = delete;
|
|
GKeyDevice& operator=(const GKeyDevice&) = delete;
|
|
|
|
// Finds a supported keyboard, opens it and detaches the kernel driver from
|
|
// the vendor interface. 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; libusb-level failures always log.
|
|
bool open(bool quiet = false);
|
|
void close();
|
|
bool is_open() const { return handle_ != nullptr; }
|
|
|
|
// 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:
|
|
bool find_endpoint();
|
|
|
|
libusb_context* context_ = nullptr;
|
|
libusb_device_handle* handle_ = nullptr;
|
|
const DeviceProfile* profile_ = nullptr;
|
|
uint8_t endpoint_ = 0;
|
|
int claimed_interface_ = -1;
|
|
bool detached_kernel_driver_ = false;
|
|
};
|
|
|
|
} // namespace gkeymapper::daemon
|
|
|
|
#endif // GKEYMAPPER_DAEMON_GKEY_DEVICE_H
|