mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-24 10:52:49 +00:00
solid: use UDev device properties for button type detection
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
34c5d4ae82
commit
52d07efe02
6 changed files with 6 additions and 134 deletions
|
@ -131,7 +131,6 @@ if(UDEV_FOUND AND CMAKE_SYSTEM_NAME MATCHES Linux)
|
||||||
include_directories(${UDEV_INCLUDES})
|
include_directories(${UDEV_INCLUDES})
|
||||||
message(STATUS "Building Solid UDev backend.")
|
message(STATUS "Building Solid UDev backend.")
|
||||||
set(solid_LIB_SRCS ${solid_LIB_SRCS}
|
set(solid_LIB_SRCS ${solid_LIB_SRCS}
|
||||||
backends/udev/utils.cpp
|
|
||||||
backends/udev/udevdevice.cpp
|
backends/udev/udevdevice.cpp
|
||||||
backends/udev/udevmanager.cpp
|
backends/udev/udevmanager.cpp
|
||||||
backends/udev/udevdeviceinterface.cpp
|
backends/udev/udevdeviceinterface.cpp
|
||||||
|
|
|
@ -18,21 +18,17 @@
|
||||||
*************************************************************************************/
|
*************************************************************************************/
|
||||||
|
|
||||||
#include "udevbutton.h"
|
#include "udevbutton.h"
|
||||||
#include "utils.h"
|
|
||||||
|
|
||||||
using namespace Solid::Backends::UDev;
|
using namespace Solid::Backends::UDev;
|
||||||
|
|
||||||
Button::Button(UDevDevice* device)
|
Button::Button(UDevDevice* device)
|
||||||
: DeviceInterface(device)
|
: DeviceInterface(device),
|
||||||
|
m_type(Solid::Button::UnknownButtonType)
|
||||||
{
|
{
|
||||||
if (m_device->propertyExists("KEY")) {
|
if (m_device->propertyExists("KEY")) {
|
||||||
m_type = Solid::Button::PowerButton;
|
m_type = Solid::Button::PowerButton;
|
||||||
return;
|
} else if (m_device->propertyExists("SW")) {
|
||||||
}
|
|
||||||
|
|
||||||
if (m_device->propertyExists("SW")) {
|
|
||||||
m_type = Solid::Button::LidButton;
|
m_type = Solid::Button::LidButton;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -504,7 +504,7 @@ bool UDevDevice::queryDeviceInterface(const Solid::DeviceInterface::Type &type)
|
||||||
return m_device.subsystem() == QLatin1String("tty");
|
return m_device.subsystem() == QLatin1String("tty");
|
||||||
|
|
||||||
case Solid::DeviceInterface::Button:
|
case Solid::DeviceInterface::Button:
|
||||||
return m_device.subsystem() == QLatin1String("input");
|
return property("ID_INPUT_KEY").toInt() == 1;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "udevmanager.h"
|
#include "udevmanager.h"
|
||||||
#include "utils.h"
|
|
||||||
|
|
||||||
#include "udev.h"
|
#include "udev.h"
|
||||||
#include "udevdevice.h"
|
#include "udevdevice.h"
|
||||||
|
@ -42,8 +41,6 @@ public:
|
||||||
|
|
||||||
bool isOfInterest(const QString &udi, const UdevQt::Device &device);
|
bool isOfInterest(const QString &udi, const UdevQt::Device &device);
|
||||||
bool checkOfInterest(const UdevQt::Device &device);
|
bool checkOfInterest(const UdevQt::Device &device);
|
||||||
bool isPowerBubtton(const UdevQt::Device &device);
|
|
||||||
bool isLidBubtton(const UdevQt::Device &device);
|
|
||||||
|
|
||||||
UdevQt::Client *m_client;
|
UdevQt::Client *m_client;
|
||||||
QStringList m_devicesOfInterest;
|
QStringList m_devicesOfInterest;
|
||||||
|
@ -130,12 +127,8 @@ bool UDevManager::Private::checkOfInterest(const UdevQt::Device &device)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (device.subsystem() == QLatin1String("input")) {
|
if (device.subsystem() == QLatin1String("input")) {
|
||||||
if (device.deviceProperties().contains("KEY")) {
|
const QStringList deviceProperties = device.deviceProperties();
|
||||||
return isPowerBubtton(device);
|
return (device.deviceProperty("ID_INPUT_KEY").toInt() == 1 && (deviceProperties.contains("KEY") || deviceProperties.contains("SW")));
|
||||||
}
|
|
||||||
if (device.deviceProperties().contains("SW")) {
|
|
||||||
return isLidBubtton(device);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return device.subsystem() == QLatin1String("dvb") ||
|
return device.subsystem() == QLatin1String("dvb") ||
|
||||||
|
@ -145,34 +138,6 @@ bool UDevManager::Private::checkOfInterest(const UdevQt::Device &device)
|
||||||
(device.deviceProperty("ID_GPHOTO2").toInt() == 1 && device.parent().deviceProperty("ID_GPHOTO2").toInt() != 1); // GPhoto2 cameras
|
(device.deviceProperty("ID_GPHOTO2").toInt() == 1 && device.parent().deviceProperty("ID_GPHOTO2").toInt() != 1); // GPhoto2 cameras
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UDevManager::Private::isLidBubtton(const UdevQt::Device& device)
|
|
||||||
{
|
|
||||||
long bitmask[NBITS(SW_MAX)];
|
|
||||||
int nbits = input_str_to_bitmask(device.deviceProperty("SW").toByteArray(), bitmask, sizeof(bitmask), NBITS(SW_MAX));
|
|
||||||
if (nbits == 1) {
|
|
||||||
if (test_bit (SW_LID, bitmask)) {
|
|
||||||
// qDebug() << "Lid button detected";
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool UDevManager::Private::isPowerBubtton(const UdevQt::Device& device)
|
|
||||||
{
|
|
||||||
long bitmask[NBITS(KEY_MAX)];
|
|
||||||
int nbits = input_str_to_bitmask(device.deviceProperty("KEY").toByteArray(), bitmask, sizeof(bitmask), NBITS(KEY_MAX));
|
|
||||||
if (nbits == 1) {
|
|
||||||
if (test_bit (KEY_POWER, bitmask)) {
|
|
||||||
// qDebug() << "Power button detected";
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
UDevManager::UDevManager(QObject *parent)
|
UDevManager::UDevManager(QObject *parent)
|
||||||
: Solid::Ifaces::DeviceManager(parent),
|
: Solid::Ifaces::DeviceManager(parent),
|
||||||
d(new Private)
|
d(new Private)
|
||||||
|
|
|
@ -1,49 +0,0 @@
|
||||||
/*************************************************************************************
|
|
||||||
* Copyright (C) 2013 by Alejandro Fiestas Olivares <afiestas@kde.org> *
|
|
||||||
* *
|
|
||||||
* This library is free software; you can redistribute it and/or *
|
|
||||||
* modify it under the terms of the GNU Library General Public *
|
|
||||||
* License as published by the Free Software Foundation; either *
|
|
||||||
* version 2 of the License, or (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* This library is distributed in the hope that it will be useful, *
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
|
||||||
* Library General Public License for more details. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU Library General Public License *
|
|
||||||
* along with this library; see the file COPYING.LIB. If not, write to *
|
|
||||||
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
|
|
||||||
* Boston, MA 02110-1301, USA. *
|
|
||||||
*************************************************************************************/
|
|
||||||
|
|
||||||
#include "utils.h"
|
|
||||||
|
|
||||||
#include <QtCore/QList>
|
|
||||||
#include <QDebug>
|
|
||||||
|
|
||||||
int Solid::Backends::UDev::input_str_to_bitmask(const QByteArray& value, long int* bitmask, size_t max_size, int max_bits)
|
|
||||||
{
|
|
||||||
int i, j;
|
|
||||||
int num_bits_set = 0;
|
|
||||||
|
|
||||||
memset (bitmask, 0, max_size);
|
|
||||||
QList<QByteArray> bits = value.split(' ');
|
|
||||||
for (i = bits.length() - 1, j = 0; i >= 0; i--, j++) {
|
|
||||||
if (j >= max_bits) {
|
|
||||||
qWarning() << "Solid::Backends::UDev::input_str_to_bitmask can't handle some bits" << bits;
|
|
||||||
return num_bits_set;
|
|
||||||
}
|
|
||||||
unsigned long val;
|
|
||||||
|
|
||||||
val = bits[i].toLong(0, 16);
|
|
||||||
bitmask[j] = val;
|
|
||||||
|
|
||||||
while (val != 0) {
|
|
||||||
num_bits_set++;
|
|
||||||
val &= (val - 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return num_bits_set;
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
/*************************************************************************************
|
|
||||||
* Copyright (C) 2013 by Alejandro Fiestas Olivares <afiestas@kde.org> *
|
|
||||||
* *
|
|
||||||
* This library is free software; you can redistribute it and/or *
|
|
||||||
* modify it under the terms of the GNU Library General Public *
|
|
||||||
* License as published by the Free Software Foundation; either *
|
|
||||||
* version 2 of the License, or (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* This library is distributed in the hope that it will be useful, *
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
|
||||||
* Library General Public License for more details. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU Library General Public License *
|
|
||||||
* along with this library; see the file COPYING.LIB. If not, write to *
|
|
||||||
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
|
|
||||||
* Boston, MA 02110-1301, USA. *
|
|
||||||
*************************************************************************************/
|
|
||||||
|
|
||||||
#include <linux/input.h>
|
|
||||||
|
|
||||||
#include <QtCore/QByteArray>
|
|
||||||
|
|
||||||
#define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1)
|
|
||||||
#define BITS_PER_LONG (sizeof(long) * 8)
|
|
||||||
#define OFF(x) ((x)%BITS_PER_LONG)
|
|
||||||
#define LONG(x) ((x)/BITS_PER_LONG)
|
|
||||||
#define test_bit(bit, array) ((array[LONG(bit)] >> OFF(bit)) & 1)
|
|
||||||
|
|
||||||
namespace Solid
|
|
||||||
{
|
|
||||||
namespace Backends
|
|
||||||
{
|
|
||||||
namespace UDev
|
|
||||||
{
|
|
||||||
int input_str_to_bitmask(const QByteArray &value, long int* bitmask, size_t max_size, int max_bits);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Add table
Reference in a new issue