mirror-kde-plasma-desktop/kcms/touchscreen/touchscreenmoduledata.cpp
Kai Uwe Broulik 0339c53fe2 kcms/libkwindevices: Use new device-specific List methods
Instead of getting all devices and filtering them, we can now ask
KWin for a list of devices of a certain kind.

This reduces DBus traffic to a single call on creation of the model.
A custom filter can still be provided to e.g. narrow down pointer
to touchpad only.

We still have to introspect the device when it gets added to see whether
it is relevant but that's just a single additional call compared to
the ones we did initially.

Also puts it in a namespace to avoid future clashes of "InputDevice"
in the KCMs.
2026-03-25 19:11:39 +01:00

27 lines
898 B
C++

/**
* SPDX-FileCopyrightText: 2025 Nicolas Fella <nicolas.fella@gmx.de>
*
* SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "touchscreenmoduledata.h"
#include "devicesmodel.h"
TouchscreenModuleData::TouchscreenModuleData(QObject *parent)
: KCModuleData(parent)
, m_devices(new KWinDevices::DevicesModel(KWinDevices::DevicesModel::Kind::Touch, {}, this))
{
connect(m_devices, &QAbstractItemModel::rowsInserted, this, &TouchscreenModuleData::updateRelevance);
connect(m_devices, &QAbstractItemModel::rowsRemoved, this, &TouchscreenModuleData::updateRelevance);
connect(m_devices, &QAbstractItemModel::modelReset, this, &TouchscreenModuleData::updateRelevance);
updateRelevance();
}
void TouchscreenModuleData::updateRelevance()
{
bool relevant = m_devices->rowCount(QModelIndex()) > 0;
setRelevant(relevant);
}
#include "moc_touchscreenmoduledata.cpp"