Fix rounding error when setting brightness by percentage

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
(cherry picked from commit c3b2fad5e6)
r14.1.x
Michele Calgaro 1 year ago
parent a4e984b1af
commit 96562b80ba
Signed by: MicheleC
GPG Key ID: 2A75B7CA8ADED5CF

@ -78,9 +78,9 @@ ConfigureDialog::ConfigureDialog( TDEConfig *_config, HardwareInfo *_hwinfo, Set
scheme_changed = false;
displayed_WARN_autosuspend = false;
// check if brightness is supporte
// check if brightness is supported
if(hwinfo->supportBrightness()) {
brightnessLevels = hwinfo->getMaxBrightnessLevel() -1;
brightnessLevels = hwinfo->getMaxBrightnessLevel();
brightness_last = hwinfo->getCurrentBrightnessLevel();
} else {
brightnessLevels = -1;

@ -30,6 +30,7 @@
// include global header
#include <fcntl.h>
#include <math.h>
// include QT header
#include <tqtimer.h>
@ -956,7 +957,6 @@ bool HardwareInfo::setBrightnessPercentage(int percent)
if (trace) kdDebug() << funcinfo << "IN: " << " percent: " << percent << endl;
bool retval = false;
int maxBrightness = getMaxBrightnessLevel();
// Use the first backlight in the list
TDEGenericHardwareList hwlist = m_hwdevices->listByDeviceClass(TDEGenericDeviceType::Backlight);
@ -969,22 +969,24 @@ bool HardwareInfo::setBrightnessPercentage(int percent)
checkBrightness();
}
// Make sure percentage is within valid range
if (percent < 0) {
percent = 0;
}
else if (percent > 100) {
percent = 100;
}
int level = (int)(maxBrightness * percent / 100.0);
if (!brightness) {
kdError() << "Change brightness not supported " << endl;
} else {
}
else {
// Make sure percentage is within valid range
if (percent < 0) {
percent = 0;
}
else if (percent > 100) {
percent = 100;
}
int level = (int)round(getMaxBrightnessLevel() * percent / 100.0);
if (currentBrightnessLevel == level) {
kdDebug() << "Brightness level not changed, requested level == current level" << endl;
retval = true;
} else {
}
else {
backlightdevice->setRawBrightness(level);
retval = true;
}
@ -1181,10 +1183,9 @@ bool HardwareInfo::setBrightnessUp(int percentageStep) {
checkCurrentBrightness();
if (supportBrightness() && getCurrentBrightnessLevel() < getMaxBrightnessLevel() &&
percentageStep > 0)
if (supportBrightness() && percentageStep > 0)
{
int currentPerc = (int)(100.0 * getCurrentBrightnessLevel() / getMaxBrightnessLevel());
int currentPerc = (int)round(100.0 * getCurrentBrightnessLevel() / getMaxBrightnessLevel());
retval = setBrightnessPercentage(currentPerc + percentageStep);
}
@ -1206,8 +1207,8 @@ bool HardwareInfo::setBrightnessDown(int percentageStep) {
checkCurrentBrightness();
if (supportBrightness() && getCurrentBrightnessLevel() > 0 && percentageStep > 0) {
int currentPerc = (int)(100.0 * getCurrentBrightnessLevel() / getMaxBrightnessLevel());
if (supportBrightness() && percentageStep > 0) {
int currentPerc = (int)round(100.0 * getCurrentBrightnessLevel() / getMaxBrightnessLevel());
retval = setBrightnessPercentage(currentPerc - percentageStep);
}
@ -1245,7 +1246,7 @@ bool HardwareInfo::getLidclose() const {
*/
int HardwareInfo::getMaxBrightnessLevel() const {
if (brightness)
return availableBrightnessLevels;
return availableBrightnessLevels - 1;
else
return -1;
}

@ -23,6 +23,8 @@
#include <config.h>
#endif
#include <math.h>
// KDE headers:
#include <tdeaboutapplication.h>
#include <tdeapplication.h>
@ -1073,7 +1075,7 @@ void tdepowersave::do_downDimm() {
if (hwinfo->supportBrightness()) {
if (!AUTODIMM_Timer->isActive()) {
int dimmToLevel = (int)((float)hwinfo->getMaxBrightnessLevel()*((float)settings->autoDimmTo/100.0));
int dimmToLevel = (int)round(hwinfo->getMaxBrightnessLevel() * settings->autoDimmTo / 100.0);
// check if we really need to dimm down
if (dimmToLevel < hwinfo->getCurrentBrightnessLevel()) {
@ -1112,7 +1114,7 @@ void tdepowersave::do_upDimm() {
if (hwinfo->supportBrightness()) {
if (!AUTODIMM_Timer->isActive()) {
int dimmToLevel = (int)((float)hwinfo->getMaxBrightnessLevel()*((float)settings->brightnessValue/100.0));
int dimmToLevel = (int)round(hwinfo->getMaxBrightnessLevel() * settings->autoDimmTo / 100.0);
// check if we really need to dimm up
if (dimmToLevel > hwinfo->getCurrentBrightnessLevel()) {
@ -1153,8 +1155,7 @@ void tdepowersave::do_dimm() {
if (autoDimmDown) {
// dimm the display down
if (current > 0 &&
current > ((int)((float)hwinfo->getMaxBrightnessLevel()*((float)settings->autoDimmTo/100.0))-1)) {
if (current > (int)round(hwinfo->getMaxBrightnessLevel() * settings->autoDimmTo / 100.0)) {
hwinfo->setBrightnessLevel(current -1);
} else {
AUTODIMM_Timer->stop();
@ -1166,7 +1167,7 @@ void tdepowersave::do_dimm() {
}
} else {
// dimm the display up
if (current < ((int)((float)hwinfo->getMaxBrightnessLevel()*((float)settings->brightnessValue/100.0))-1)) {
if (current < (int)round(hwinfo->getMaxBrightnessLevel() * settings->autoDimmTo / 100.0)) {
hwinfo->setBrightnessLevel(current +1);
} else {
AUTODIMM_Timer->stop();
@ -2938,7 +2939,7 @@ int tdepowersave::brightnessGet() {
int retval = -1;
if (hwinfo->supportBrightness()) {
retval = (int)(100.0 * hwinfo->getCurrentBrightnessLevel() / hwinfo->getMaxBrightnessLevel());
retval = (int)round(100.0 * hwinfo->getCurrentBrightnessLevel() / hwinfo->getMaxBrightnessLevel());
}
kdDebugFuncOut(trace);
@ -2951,10 +2952,7 @@ void tdepowersave::brightnessSet(int percentage)
{
kdDebugFuncIn(trace);
if (hwinfo->supportBrightness() && percentage >= 0 && percentage <= 100)
{
hwinfo->setBrightnessPercentage(percentage);
}
hwinfo->setBrightnessPercentage(percentage);
kdDebugFuncOut(trace);
}

@ -440,8 +440,8 @@ k_dcop:
//! dcop function to open the configure dialog
bool openConfigureDialog();
//! dcop function to find out if tdepowersave manages DPMS
bool currentSchemeManagesDPMS();
//! dcop function to find out if tdepowersave manages DPMS
bool currentSchemeManagesDPMS();
//! dcop funtion to get the current brightness level
int brightnessGet();
//! dcop funtion to set the brightness level

Loading…
Cancel
Save