|
MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
|
Cross-platform tablet and stylus backend over raw HID. More...
#include <TabletBackend.hpp>
Inheritance diagram for MayaFlux::Core::TabletBackend:
Collaboration diagram for MayaFlux::Core::TabletBackend:Classes | |
| struct | Config |
| Configuration for the tablet backend. More... | |
| struct | TabletDevice |
| One physical HID device and the tools it presents. More... | |
Public Member Functions | |
| void | close_device (uint32_t device_id) override |
| Close a previously opened device. | |
| std::vector< InputDeviceInfo > | get_devices () const override |
| Get list of available devices. | |
| std::optional< TabletLayout > | get_layout (uint32_t device_id) const |
| Parsed report layout for the device backing a tool. | |
| std::string | get_name () const override |
| Get backend name/identifier string. | |
| std::vector< uint32_t > | get_open_devices () const override |
| Get list of currently open device IDs. | |
| std::optional< TabletToolInfo > | get_tool_info (uint32_t device_id) const |
| Extended information for a tool. | |
| InputType | get_type () const override |
| Get backend type. | |
| std::string | get_version () const override |
| Get backend version string. | |
| bool | initialize () override |
| Initialize the input backend. | |
| bool | is_device_open (uint32_t device_id) const override |
| Check if a device is currently open. | |
| bool | is_initialized () const override |
| Check if backend is initialized. | |
| bool | is_running () const override |
| Check if backend is actively listening. | |
| bool | open_device (uint32_t device_id) override |
| Open a device for input. | |
| TabletBackend & | operator= (const TabletBackend &)=delete |
| TabletBackend & | operator= (TabletBackend &&)=delete |
| size_t | refresh_devices () override |
| Refresh the device list. | |
| void | set_device_callback (DeviceCallback callback) override |
| Register callback for device connect/disconnect events. | |
| void | set_input_callback (InputCallback callback) override |
| Register callback for input values. | |
| void | shutdown () override |
| Shutdown and release all resources. | |
| void | start () override |
| Start listening for input events. | |
| void | stop () override |
| Stop listening for input events. | |
| TabletBackend () | |
| TabletBackend (Config config) | |
| TabletBackend (const TabletBackend &)=delete | |
| TabletBackend (TabletBackend &&)=delete | |
| ~TabletBackend () override | |
Public Member Functions inherited from MayaFlux::Core::IInputBackend | |
| virtual | ~IInputBackend ()=default |
Static Public Member Functions | |
| static TabletLayout | parse_descriptor (std::span< const uint8_t > descriptor) |
| Parse a HID report descriptor into a tablet layout. | |
Private Member Functions | |
| bool | adopt_device (const std::string &path, uint16_t vid, uint16_t pid, std::string name) |
| void | emit_frame (TabletDevice &device) |
| void | notify_device_change (const InputDeviceInfo &info, bool connected) |
| void | notify_input (const InputValue &value) |
| void | poll_device (TabletDevice &device) |
| void | poll_thread_func () |
| void | unpack_report (TabletDevice &device, std::span< const uint8_t > report) |
Private Attributes | |
| std::mutex | m_callback_mutex |
| Config | m_config |
| DeviceCallback | m_device_callback |
| std::unordered_map< std::string, std::shared_ptr< TabletDevice > > | m_devices |
| std::mutex | m_devices_mutex |
| std::atomic< bool > | m_initialized { false } |
| InputCallback | m_input_callback |
| uint32_t | m_next_device_id { 1 } |
| std::thread | m_poll_thread |
| std::atomic< bool > | m_running { false } |
| std::atomic< bool > | m_stop_requested { false } |
| std::unordered_map< uint32_t, std::string > | m_tool_paths |
| std::unordered_map< uint32_t, TabletToolInfo > | m_tools |
Cross-platform tablet and stylus backend over raw HID.
Opens digitizer devices through HIDAPI on every supported platform, retrieves each device's HID report descriptor, parses it, and unpacks incoming reports into a fixed slot layout. There is no platform-specific code, no window, no message loop, no run loop and no thread affinity. Tablet data flows in a process that never creates a window.
Devices are selected by HID usage page 0x0D, usages Digitizer (0x01) and Pen (0x02). Where HIDAPI does not report a usage page during enumeration, the descriptor is fetched and inspected instead.
A device carrying an Invert usage presents two tools and therefore two device ids, one pen and one eraser. Reports route to whichever the Invert bit selects.
Each input report produces one InputValue of Type::VECTOR laid out per TabletFrame. Fields absent from a report retain their previous value, since a report carries only what the device chose to send. Wheel clears after each emission because it is a delta.
timestamp_ns is the time the report was read. HIDAPI carries no device timestamp on any platform, so poll jitter is present in the value.
Threading follows HIDBackend: a dedicated thread polls open devices and invokes the input callback from that thread.
Requires read access to the HID device nodes. On Linux that is a udev rule for /dev/hidraw*, on macOS the Input Monitoring permission.
Definition at line 80 of file TabletBackend.hpp.