FreeBSD Bugzilla – Attachment 219854 Details for
Bug 251290
sysutils/plasma5-powerdevil: use /dev/backlight to control brightness
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
v1
plasma5-powerdevil.diff (text/plain), 8.80 KB, created by
Mikael Urankar
on 2020-11-21 13:33:09 UTC
(
hide
)
Description:
v1
Filename:
MIME Type:
Creator:
Mikael Urankar
Created:
2020-11-21 13:33:09 UTC
Size:
8.80 KB
patch
obsolete
>Index: sysutils/plasma5-powerdevil/files/patch-daemon_backends_upower_backlighthelper.cpp >=================================================================== >--- sysutils/plasma5-powerdevil/files/patch-daemon_backends_upower_backlighthelper.cpp (nonexistent) >+++ sysutils/plasma5-powerdevil/files/patch-daemon_backends_upower_backlighthelper.cpp (working copy) >@@ -0,0 +1,192 @@ >+--- daemon/backends/upower/backlighthelper.cpp.orig 2020-11-21 13:29:06 UTC >++++ daemon/backends/upower/backlighthelper.cpp >+@@ -32,11 +32,18 @@ >+ >+ #ifdef Q_OS_FREEBSD >+ #define USE_SYSCTL >++#if __FreeBSD_version >= 1300118 >++#define USE_FBSDBACKLIGHT >+ #endif >++#endif >+ >+ #ifdef USE_SYSCTL >+ #include <sys/types.h> >+ #include <sys/sysctl.h> >++#ifdef USE_FBSDBACKLIGHT >++#include <sys/ioctl.h> >++#include <sys/backlight.h> >++#endif >+ >+ #define HAS_SYSCTL(n) (sysctlbyname(n, nullptr, nullptr, nullptr, 0) == 0) >+ #endif >+@@ -44,6 +51,13 @@ >+ #define BACKLIGHT_SYSFS_PATH "/sys/class/backlight/" >+ #define LED_SYSFS_PATH "/sys/class/leds/" >+ >++#define BACKLIGHT_FREEBSD_PATH "/dev/backlight/backlight0" >++#define BACKLIGHT_QUERY 0x0001 >++#define BACKLIGHT_SET_BRIGHTNESS 0x0002 >++#define BACKLIGHT_INCR 0x0004 >++#define BACKLIGHT_DECR 0x0008 >++#define BACKLIGHT_INFO 0x0010 >++ >+ BacklightHelper::BacklightHelper(QObject *parent) : QObject(parent) >+ { >+ init(); >+@@ -53,6 +67,12 @@ void BacklightHelper::init() >+ { >+ initUsingBacklightType(); >+ >++ // try to use /dev/backlight/backlight0 on FreeBSD >++#ifdef USE_FBSDBACKLIGHT >++ initUsingFreeBSDBacklight(); >++#endif >++ >++ // fallback to sysctl >+ if (m_dirname.isEmpty()) { >+ initUsingSysctl(); >+ >+@@ -130,6 +150,20 @@ void BacklightHelper::initUsingBacklightType() >+ >+ } >+ >++void BacklightHelper::initUsingFreeBSDBacklight() >++{ >++#ifdef USE_FBSDBACKLIGHT >++ QFile file(BACKLIGHT_FREEBSD_PATH); >++ if (file.open(QIODevice::ReadWrite)) { >++ m_dirname = BACKLIGHT_FREEBSD_PATH; >++ m_useFreeBSDBacklight = true; >++ file.close(); >++ } else { >++ qCWarning(POWERDEVIL) << "BacklightHelper::initUsingFreeBSDBacklight no RW access on " << BACKLIGHT_FREEBSD_PATH; >++ } >++#endif >++} >++ >+ void BacklightHelper::initUsingSysctl() >+ { >+ #ifdef USE_SYSCTL >+@@ -205,11 +239,31 @@ int BacklightHelper::readBrightness() const >+ } >+ >+ int brightness; >+- >+-#ifdef USE_SYSCTL >+- size_t len = sizeof(int); >+- if (sysctlbyname(qPrintable(QStringLiteral("hw.acpi.video.%1.brightness").arg(m_sysctlDevice)), &brightness, &len, nullptr, 0) != 0) { >+- return -1; >++#ifdef Q_OS_FREEBSD >++ if (m_useFreeBSDBacklight == true) { >++#ifdef USE_FBSDBACKLIGHT >++ struct backlight_props props; >++ >++ QFile file(m_dirname); >++ if (!file.open(QIODevice::ReadWrite)) { >++ qCWarning(POWERDEVIL) << "BacklightHelper::readBrightness no RW access on " << BACKLIGHT_FREEBSD_PATH; >++ return -1; >++ } >++ if (ioctl(file.handle(), BACKLIGHTGETSTATUS, &props) == -1) { >++ qCWarning(POWERDEVIL) << "BacklightHelper::readBrightness Cannot query the backlight device"; >++ file.close(); >++ return -1; >++ } >++ file.close(); >++ >++ brightness = props.brightness; >++ return brightness; >++#endif >++ } else { >++ size_t len = sizeof(int); >++ if (sysctlbyname(qPrintable(QStringLiteral("hw.acpi.video.%1.brightness").arg(m_sysctlDevice)), &brightness, &len, nullptr, 0) != 0) { >++ return -1; >++ } >+ } >+ #else >+ QFile file(m_dirname + "/brightness"); >+@@ -252,27 +306,50 @@ ActionReply BacklightHelper::setbrightness(const QVari >+ >+ bool BacklightHelper::writeBrightness(int brightness) const >+ { >+-#ifdef USE_SYSCTL >+- int actual_level = -1; >+- int d1 = 101; >+- // Search for the nearest level. >+- for (int level : m_sysctlBrightnessLevels) { >+- int d2 = qAbs(level - 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; >++ >++#ifdef Q_OS_FREEBSD >++ if (m_useFreeBSDBacklight == true) { >++#ifdef USE_FBSDBACKLIGHT >++ struct backlight_props props; >++ >++ props.brightness = brightness; >++ >++ QFile file(m_dirname); >++ if (!file.open(QIODevice::ReadWrite)) { >++ qCWarning(POWERDEVIL) << "BacklightHelper::writeBrightness no RW access on " << BACKLIGHT_FREEBSD_PATH; >++ return false; >+ } >+- actual_level = level; >+- d1 = d2; >++ if (ioctl(file.handle(), BACKLIGHTUPDATESTATUS, &props) == -1) { >++ qCWarning(POWERDEVIL) << "BacklightHelper::writeBrightness Cannot query the backlight device"; >++ file.close(); >++ return false; >++ } >++ file.close(); >++ >++ return true; >++#endif >++ } else { >++ int actual_level = -1; >++ int d1 = 101; >++ // Search for the nearest level. >++ for (int level : m_sysctlBrightnessLevels) { >++ int d2 = qAbs(level - 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); >++ return sysctlbyname(qPrintable(QStringLiteral("hw.acpi.video.%1.brightness").arg(m_sysctlDevice)), nullptr, nullptr, &actual_level, len) == 0; >+ } >+- size_t len = sizeof(int); >+- return sysctlbyname(qPrintable(QStringLiteral("hw.acpi.video.%1.brightness").arg(m_sysctlDevice)), nullptr, nullptr, &actual_level, len) == 0; >+ #else >+ QFile file(m_dirname + QLatin1String("/brightness")); >+ if (!file.open(QIODevice::WriteOnly)) { >+@@ -321,9 +398,12 @@ ActionReply BacklightHelper::brightnessmax(const QVari >+ >+ // maximum brightness >+ int max_brightness; >+- >+-#ifdef USE_SYSCTL >+- max_brightness = m_sysctlBrightnessLevels.last(); >++#ifdef Q_OS_FREEBSD >++ if (m_useFreeBSDBacklight == true) { >++ max_brightness = 100; >++ } else { >++ max_brightness = m_sysctlBrightnessLevels.last(); >++ } >+ #else >+ QFile file(m_dirname + QLatin1String("/max_brightness")); >+ if (!file.open(QIODevice::ReadOnly)) { > >Property changes on: sysutils/plasma5-powerdevil/files/patch-daemon_backends_upower_backlighthelper.cpp >___________________________________________________________________ >Added: fbsd:nokeywords >## -0,0 +1 ## >+yes >\ No newline at end of property >Added: svn:eol-style >## -0,0 +1 ## >+native >\ No newline at end of property >Added: svn:keywords >## -0,0 +1 ## >+FreeBSD=%H >\ No newline at end of property >Added: svn:mime-type >## -0,0 +1 ## >+text/plain >\ No newline at end of property >Index: sysutils/plasma5-powerdevil/files/patch-daemon_backends_upower_backlighthelper.h >=================================================================== >--- sysutils/plasma5-powerdevil/files/patch-daemon_backends_upower_backlighthelper.h (nonexistent) >+++ sysutils/plasma5-powerdevil/files/patch-daemon_backends_upower_backlighthelper.h (working copy) >@@ -0,0 +1,15 @@ >+--- daemon/backends/upower/backlighthelper.h.orig 2020-11-21 13:29:19 UTC >++++ daemon/backends/upower/backlighthelper.h >+@@ -55,8 +55,12 @@ public Q_SLOTS: (private) >+ /** >+ * FreeBSD (and other BSDs) can control backlight via acpi_video(4) >+ */ >++#if defined(__FreeBSD__) >++ void initUsingFreeBSDBacklight(); >++#endif >+ void initUsingSysctl(); >+ >++ bool m_useFreeBSDBacklight = false; >+ bool m_isSupported = false; >+ QString m_dirname; >+ QString m_sysctlDevice; > >Property changes on: sysutils/plasma5-powerdevil/files/patch-daemon_backends_upower_backlighthelper.h >___________________________________________________________________ >Added: fbsd:nokeywords >## -0,0 +1 ## >+yes >\ No newline at end of property >Added: svn:eol-style >## -0,0 +1 ## >+native >\ No newline at end of property >Added: svn:keywords >## -0,0 +1 ## >+FreeBSD=%H >\ No newline at end of property >Added: svn:mime-type >## -0,0 +1 ## >+text/plain >\ No newline at end of property
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 251290
: 219854