diff --git a/daemon/backends/upower/backlighthelper.h b/daemon/backends/upower/backlighthelper.h --- a/daemon/backends/upower/backlighthelper.h +++ b/daemon/backends/upower/backlighthelper.h @@ -47,15 +47,8 @@ */ void initUsingBacklightType(); - /** - * FreeBSD (and other BSDs) can control backlight via acpi_video(4) - */ - void initUsingSysctl(); - bool m_isSupported = false; QString m_dirname; - QString m_sysctlDevice; - QList m_sysctlBrightnessLevels; }; #endif // BACKLIGHTHELPER_H diff --git a/daemon/backends/upower/backlighthelper.cpp b/daemon/backends/upower/backlighthelper.cpp --- a/daemon/backends/upower/backlighthelper.cpp +++ b/daemon/backends/upower/backlighthelper.cpp @@ -28,17 +28,6 @@ #include -#ifdef Q_OS_FREEBSD -#define USE_SYSCTL -#endif - -#ifdef USE_SYSCTL -#include -#include - -#define HAS_SYSCTL(n) (sysctlbyname(n, NULL, NULL, NULL, 0) == 0) -#endif - #define BACKLIGHT_SYSFS_PATH "/sys/class/backlight/" #define LED_SYSFS_PATH "/sys/class/leds/" @@ -52,12 +41,8 @@ initUsingBacklightType(); if (m_dirname.isEmpty()) { - initUsingSysctl(); - - if (m_sysctlDevice.isEmpty() || m_sysctlBrightnessLevels.isEmpty()) { - qCWarning(POWERDEVIL) << "no kernel backlight interface found"; - return; - } + qCWarning(POWERDEVIL) << "no kernel backlight interface found"; + return; } m_isSupported = true; @@ -134,60 +119,6 @@ } -void BacklightHelper::initUsingSysctl() -{ -#ifdef USE_SYSCTL - /* - * lcd0 is, in theory, the correct device, but some vendors have custom ACPI implementations - * which cannot be interpreted. In that case, devices should be reported as "out", but - * FreeBSD doesn't care (yet), so they can appear as any other type. Let's search for the first - * device with brightness management, then. - */ - QStringList types; - types << QStringLiteral("lcd") << QStringLiteral("out") << QStringLiteral("crt") << QStringLiteral("tv") << QStringLiteral("ext"); - Q_FOREACH (const QString &type, types) { - for (int i = 0; m_sysctlDevice.isEmpty(); i++) { - QString device = QStringLiteral("%1%2").arg(type, QString::number(i)); - // We don't care about the value, we only want the sysctl to be there. - if (!HAS_SYSCTL(qPrintable(QStringLiteral("hw.acpi.video.%1.active").arg(device)))) { - break; - } - if (HAS_SYSCTL(qPrintable(QStringLiteral("hw.acpi.video.%1.brightness").arg(device))) && - HAS_SYSCTL(qPrintable(QStringLiteral("hw.acpi.video.%1.levels").arg(device)))) { - m_sysctlDevice = device; - break; - } - } - } - - if (m_sysctlDevice.isEmpty()) { - return; - } - - size_t len; - if (sysctlbyname(qPrintable(QStringLiteral("hw.acpi.video.%1.levels").arg(m_sysctlDevice)), NULL, &len, NULL, 0) != 0 || - len == 0) { - return; - } - int *levels = (int *)malloc(len); - if (!levels) { - return; - } - if (sysctlbyname(qPrintable(QString("hw.acpi.video.%1.levels").arg(m_sysctlDevice)), levels, &len, NULL, 0) != 0) { - free(levels); - return; - } - // acpi_video(4) supports only some predefined brightness levels. - int nlevels = len / sizeof(int); - for (int i = 0; i < nlevels; i++) { - m_sysctlBrightnessLevels << levels[i]; - } - free(levels); - // Sorting helps when finding max value and when scanning for the nearest level in setbrightness(). - qSort(m_sysctlBrightnessLevels.begin(), m_sysctlBrightnessLevels.end()); -#endif -} - ActionReply BacklightHelper::brightness(const QVariantMap &args) { Q_UNUSED(args); @@ -202,13 +133,6 @@ // current brightness int brightness; -#ifdef USE_SYSCTL - size_t len = sizeof(int); - if (sysctlbyname(qPrintable(QStringLiteral("hw.acpi.video.%1.brightness").arg(m_sysctlDevice)), &brightness, &len, NULL, 0) != 0) { - reply = ActionReply::HelperErrorReply(); - return reply; - } -#else QFile file(m_dirname + "/brightness"); if (!file.open(QIODevice::ReadOnly)) { reply = ActionReply(ActionReply::HelperErrorType); @@ -220,7 +144,6 @@ QTextStream stream(&file); stream >> brightness; file.close(); -#endif //qCDebug(POWERDEVIL) << "brightness:" << brightness; reply.addData("brightness", brightness); @@ -242,31 +165,6 @@ //qCDebug(POWERDEVIL) << "setting brightness:" << actual_brightness; -#ifdef USE_SYSCTL - int actual_level = -1; - int d1 = 101; - // Search for the nearest level. - Q_FOREACH (int level, m_sysctlBrightnessLevels) { - int d2 = qAbs(level - actual_brightness); - /* - * The list is sorted, so we break when it starts diverging. There may be repeated values, - * so we keep going on equal gap (e.g., value = 7.5, levels = 0 0 10 ...: we don't break at - * the second '0' so we can get to the '10'). This also means that the value will always - * round off to the bigger level when in the middle (e.g., value = 5, levels = 0 10 ...: - * value rounds off to 10). - */ - if (d2 > d1) { - break; - } - actual_level = level; - d1 = d2; - } - size_t len = sizeof(int); - if (sysctlbyname(qPrintable(QStringLiteral("hw.acpi.video.%1.brightness").arg(m_sysctlDevice)), NULL, NULL, &actual_level, len) != 0) { - reply = ActionReply::HelperErrorReply(); - return reply; - } -#else QFile file(m_dirname + QLatin1String("/brightness")); if (!file.open(QIODevice::WriteOnly)) { reply = ActionReply::HelperErrorReply(); @@ -283,7 +181,6 @@ // reply.setErrorCode(file.error()); qCWarning(POWERDEVIL) << "writing brightness failed with error code " << file.error() << file.errorString(); } -#endif return reply; } @@ -317,9 +214,6 @@ // maximum brightness int max_brightness; -#ifdef USE_SYSCTL - max_brightness = m_sysctlBrightnessLevels.last(); -#else QFile file(m_dirname + QLatin1String("/max_brightness")); if (!file.open(QIODevice::ReadOnly)) { reply = ActionReply::HelperErrorReply(); @@ -331,7 +225,6 @@ QTextStream stream(&file); stream >> max_brightness; file.close(); -#endif //qCDebug(POWERDEVIL) << "max brightness:" << max_brightness;