diff --git a/solid/solid/CMakeLists.txt b/solid/solid/CMakeLists.txt index 6a996934..0d67a0c2 100644 --- a/solid/solid/CMakeLists.txt +++ b/solid/solid/CMakeLists.txt @@ -131,7 +131,6 @@ if(UDEV_FOUND AND CMAKE_SYSTEM_NAME MATCHES Linux) include_directories(${UDEV_INCLUDES}) message(STATUS "Building Solid UDev backend.") set(solid_LIB_SRCS ${solid_LIB_SRCS} - backends/udev/utils.cpp backends/udev/udevdevice.cpp backends/udev/udevmanager.cpp backends/udev/udevdeviceinterface.cpp diff --git a/solid/solid/backends/udev/udevbutton.cpp b/solid/solid/backends/udev/udevbutton.cpp index b6faa6b7..16dca6ab 100644 --- a/solid/solid/backends/udev/udevbutton.cpp +++ b/solid/solid/backends/udev/udevbutton.cpp @@ -18,21 +18,17 @@ *************************************************************************************/ #include "udevbutton.h" -#include "utils.h" using namespace Solid::Backends::UDev; Button::Button(UDevDevice* device) - : DeviceInterface(device) + : DeviceInterface(device), + m_type(Solid::Button::UnknownButtonType) { if (m_device->propertyExists("KEY")) { m_type = Solid::Button::PowerButton; - return; - } - - if (m_device->propertyExists("SW")) { + } else if (m_device->propertyExists("SW")) { m_type = Solid::Button::LidButton; - return; } } diff --git a/solid/solid/backends/udev/udevdevice.cpp b/solid/solid/backends/udev/udevdevice.cpp index 8751876d..4164f077 100644 --- a/solid/solid/backends/udev/udevdevice.cpp +++ b/solid/solid/backends/udev/udevdevice.cpp @@ -504,7 +504,7 @@ bool UDevDevice::queryDeviceInterface(const Solid::DeviceInterface::Type &type) return m_device.subsystem() == QLatin1String("tty"); case Solid::DeviceInterface::Button: - return m_device.subsystem() == QLatin1String("input"); + return property("ID_INPUT_KEY").toInt() == 1; default: return false; diff --git a/solid/solid/backends/udev/udevmanager.cpp b/solid/solid/backends/udev/udevmanager.cpp index 0d8d9af4..cf0e3efd 100644 --- a/solid/solid/backends/udev/udevmanager.cpp +++ b/solid/solid/backends/udev/udevmanager.cpp @@ -19,7 +19,6 @@ */ #include "udevmanager.h" -#include "utils.h" #include "udev.h" #include "udevdevice.h" @@ -42,8 +41,6 @@ public: bool isOfInterest(const QString &udi, 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; QStringList m_devicesOfInterest; @@ -130,12 +127,8 @@ bool UDevManager::Private::checkOfInterest(const UdevQt::Device &device) } if (device.subsystem() == QLatin1String("input")) { - if (device.deviceProperties().contains("KEY")) { - return isPowerBubtton(device); - } - if (device.deviceProperties().contains("SW")) { - return isLidBubtton(device); - } + const QStringList deviceProperties = device.deviceProperties(); + return (device.deviceProperty("ID_INPUT_KEY").toInt() == 1 && (deviceProperties.contains("KEY") || deviceProperties.contains("SW"))); } 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 } -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) : Solid::Ifaces::DeviceManager(parent), d(new Private) diff --git a/solid/solid/backends/udev/utils.cpp b/solid/solid/backends/udev/utils.cpp deleted file mode 100644 index d3731693..00000000 --- a/solid/solid/backends/udev/utils.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/************************************************************************************* - * Copyright (C) 2013 by Alejandro Fiestas Olivares * - * * - * 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 -#include - -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 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; -} diff --git a/solid/solid/backends/udev/utils.h b/solid/solid/backends/udev/utils.h deleted file mode 100644 index 45e8f0bd..00000000 --- a/solid/solid/backends/udev/utils.h +++ /dev/null @@ -1,39 +0,0 @@ -/************************************************************************************* - * Copyright (C) 2013 by Alejandro Fiestas Olivares * - * * - * 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 - -#include - -#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); -} -} -}