2024-11-07 22:34:41 -05:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QtQml>
|
|
|
|
#include <libevdev/libevdev-uinput.h>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <linux/input.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
class DeviceManager : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
QML_ELEMENT
|
|
|
|
|
|
|
|
Q_PROPERTY(QString name WRITE setName READ name NOTIFY nameChanged)
|
|
|
|
Q_PROPERTY(bool direct WRITE setDirect READ direct NOTIFY directChanged)
|
|
|
|
Q_PROPERTY(bool pad WRITE setPad READ pad NOTIFY padChanged)
|
2025-04-12 16:42:00 -04:00
|
|
|
Q_PROPERTY(int penButtons WRITE setPenButtons READ penButtons NOTIFY penButtonsChanged)
|
2024-11-07 22:34:41 -05:00
|
|
|
|
|
|
|
public:
|
|
|
|
~DeviceManager() override;
|
|
|
|
|
|
|
|
QString name() const;
|
|
|
|
void setName(const QString &name);
|
|
|
|
|
|
|
|
bool direct() const;
|
|
|
|
void setDirect(bool direct);
|
|
|
|
|
|
|
|
bool pad() const;
|
|
|
|
void setPad(bool pad);
|
|
|
|
|
2025-04-12 16:42:00 -04:00
|
|
|
int penButtons() const;
|
|
|
|
void setPenButtons(int num);
|
|
|
|
|
2024-11-07 22:34:41 -05:00
|
|
|
public Q_SLOTS:
|
|
|
|
void recreateDevice();
|
|
|
|
void testButton();
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
void nameChanged();
|
|
|
|
void directChanged();
|
|
|
|
void padChanged();
|
2025-04-12 16:42:00 -04:00
|
|
|
void penButtonsChanged();
|
2024-11-07 22:34:41 -05:00
|
|
|
|
|
|
|
private:
|
|
|
|
void destroyDevice();
|
|
|
|
|
|
|
|
struct libevdev *dev = nullptr;
|
|
|
|
struct libevdev_uinput *uidev = nullptr;
|
|
|
|
int fd = 0, uinput_fd = 0;
|
|
|
|
unsigned int type = 0, code = 0;
|
|
|
|
int rc = 0;
|
|
|
|
const char *devnode = nullptr;
|
|
|
|
|
|
|
|
QString m_name;
|
|
|
|
bool m_direct = false;
|
|
|
|
bool m_pad = false;
|
2025-04-12 16:42:00 -04:00
|
|
|
int m_penButtons = 3;
|
2024-11-07 22:34:41 -05:00
|
|
|
};
|