diff --git a/debug_console.cpp b/debug_console.cpp index 7151784c29..726cd459d3 100644 --- a/debug_console.cpp +++ b/debug_console.cpp @@ -1127,14 +1127,31 @@ QVariant SurfaceTreeModel::data(const QModelIndex &index, int role) const #if HAVE_INPUT InputDeviceModel::InputDeviceModel(QObject *parent) : QAbstractItemModel(parent) + , m_devices(LibInput::Connection::self()->devices()) { + for (auto it = m_devices.constBegin(); it != m_devices.constEnd(); ++it) { + setupDeviceConnections(*it); + } auto c = LibInput::Connection::self(); - auto resetModel = [this] { - beginResetModel(); - endResetModel(); - }; - connect(c, &LibInput::Connection::deviceAdded, this, resetModel); - connect(c, &LibInput::Connection::deviceRemoved, this, resetModel); + connect(c, &LibInput::Connection::deviceAdded, this, + [this] (LibInput::Device *d) { + beginInsertRows(QModelIndex(), m_devices.count(), m_devices.count()); + m_devices << d; + setupDeviceConnections(d); + endInsertRows(); + } + ); + connect(c, &LibInput::Connection::deviceRemoved, this, + [this] (LibInput::Device *d) { + const int index = m_devices.indexOf(d); + if (index == -1) { + return; + } + beginRemoveRows(QModelIndex(), index, index); + m_devices.removeAt(index); + endRemoveRows(); + } + ); } InputDeviceModel::~InputDeviceModel() = default; @@ -1215,6 +1232,31 @@ QModelIndex InputDeviceModel::parent(const QModelIndex &child) const return QModelIndex(); } +void InputDeviceModel::setupDeviceConnections(LibInput::Device *device) +{ + connect(device, &LibInput::Device::enabledChanged, this, + [this, device] { + const QModelIndex parent = index(m_devices.indexOf(device), 0, QModelIndex()); + const QModelIndex child = index(device->metaObject()->indexOfProperty("enabled"), 1, parent); + emit dataChanged(child, child, QVector{Qt::DisplayRole}); + } + ); + connect(device, &LibInput::Device::leftHandedChanged, this, + [this, device] { + const QModelIndex parent = index(m_devices.indexOf(device), 0, QModelIndex()); + const QModelIndex child = index(device->metaObject()->indexOfProperty("leftHanded"), 1, parent); + emit dataChanged(child, child, QVector{Qt::DisplayRole}); + } + ); + connect(device, &LibInput::Device::pointerAccelerationChanged, this, + [this, device] { + const QModelIndex parent = index(m_devices.indexOf(device), 0, QModelIndex()); + const QModelIndex child = index(device->metaObject()->indexOfProperty("pointerAcceleration"), 1, parent); + emit dataChanged(child, child, QVector{Qt::DisplayRole}); + } + ); +} + #endif } diff --git a/debug_console.h b/debug_console.h index 8309a463ff..f76699a215 100644 --- a/debug_console.h +++ b/debug_console.h @@ -138,6 +138,12 @@ private: }; #if HAVE_INPUT + +namespace LibInput +{ +class Device; +} + class InputDeviceModel : public QAbstractItemModel { Q_OBJECT @@ -150,6 +156,10 @@ public: QModelIndex index(int row, int column, const QModelIndex & parent) const override; int rowCount(const QModelIndex &parent) const override; QModelIndex parent(const QModelIndex &child) const override; + +private: + void setupDeviceConnections(LibInput::Device *device); + QVector m_devices; }; #endif