Separate logic to set brightness by absolute level or percentage

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
pull/17/head
Michele Calgaro 1 year ago
parent e7c760c9c0
commit fa1f792e61
Signed by: MicheleC
GPG Key ID: 2A75B7CA8ADED5CF

@ -1652,7 +1652,7 @@ void ConfigureDialog::brightnessSlider_sliderMoved( int new_value ) {
if (cB_Brightness->isEnabled() && cB_Brightness->isChecked()) {
scheme_valueChanged();
tL_valueBrightness->setText(TQString::number(new_value) + " %");
hwinfo->setBrightness(-1, new_value);
hwinfo->setBrightnessPercentage(new_value);
pB_resetBrightness->setEnabled(true);
brightness_changed = true;
}
@ -1664,7 +1664,7 @@ void ConfigureDialog::brightnessSlider_sliderMoved( int new_value ) {
void ConfigureDialog::pB_resetBrightness_clicked( ) {
kdDebugFuncIn(trace);
hwinfo->setBrightness(brightness_last, -1);
hwinfo->setBrightnessLevel(brightness_last);
brightnessSlider->setValue(brightness_last);
pB_resetBrightness->setEnabled(false);
brightness_changed = false;

@ -898,31 +898,71 @@ bool HardwareInfo::suspend( suspend_type suspend ) {
}
/*!
* Function to set brightness via TDE hardware library (if supported by hardware)
* Function to set brightness level via TDE hardware library (if supported by hardware)
* \param level Integer with the level to set, (range: 0 - \ref availableBrightnessLevels )
* \param percent Integer with the brightness percentage to set
* \return boolean with result of the operation
* \retval true if successful
* \retval false else, if a error occurs
*/
bool HardwareInfo::setBrightness ( int level, int percent ){
if (trace) kdDebug() << funcinfo << "IN: " << "level: " << level << " percent: " << percent << endl;
bool HardwareInfo::setBrightnessLevel(int level)
{
if (trace) kdDebug() << funcinfo << "IN: " << "level: " << level << endl;
bool retval = false;
int maxBrightness = getMaxBrightnessLevel();
// Use the first backlight in the list
TDEGenericHardwareList hwlist = m_hwdevices->listByDeviceClass(TDEGenericDeviceType::Backlight);
TDEGenericDevice *hwdevice;
hwdevice = hwlist.first();
TDEBacklightDevice *backlightdevice = static_cast<TDEBacklightDevice*>(hwdevice);
if ((level == -1) && (percent >= 0)) {
if (percent == 0) {
if (backlightdevice) {
if (!brightness) {
checkBrightness();
}
// Make sure level is within valid range
if (level < 0) {
level = 0;
} else if (percent >= 98) {
level = (availableBrightnessLevels - 1);
}
else if (level > maxBrightness) {
level = maxBrightness;
}
if (!brightness) {
kdError() << "Change brightness not supported " << endl;
} else {
if (currentBrightnessLevel == level) {
kdDebug() << "Brightness level not changed, requested level == current level" << endl;
retval = true;
} else {
level = (int)((float)availableBrightnessLevels * ((float)percent/100.0));
if (level > (availableBrightnessLevels -1))
level = availableBrightnessLevels -1;
kdDebug() << "percentage mapped to new level: " << level << endl;
backlightdevice->setRawBrightness(level);
retval = true;
}
}
}
// check for actual brightness level to be sure everything was set correct
checkCurrentBrightness();
kdDebugFuncOut(trace);
return retval;
}
/*!
* Function to set brightness percentage via TDE hardware library (if supported by hardware)
* \param percent Integer with the brightness percentage to set
* \return boolean with result of the operation
* \retval true if successful
* \retval false else, if a error occurs
*/
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);
TDEGenericDevice *hwdevice;
@ -934,8 +974,17 @@ bool HardwareInfo::setBrightness ( int level, int percent ){
checkBrightness();
}
if (!brightness || (level < 0 ) || (level >= availableBrightnessLevels)) {
kdError() << "Change brightness or requested level not supported " << endl;
// 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 {
if (currentBrightnessLevel == level) {
kdDebug() << "Brightness level not changed, requested level == current level" << endl;
@ -1137,35 +1186,11 @@ bool HardwareInfo::setBrightnessUp(int percentageStep) {
checkCurrentBrightness();
if (supportBrightness() && (getCurrentBrightnessLevel() >= 0) &&
(getCurrentBrightnessLevel() != (getMaxBrightnessLevel()-1))) {
int setTo = 0;
int minPercStep = 10;
int currentPerc = (int)(((float)getCurrentBrightnessLevel()/(float)(getMaxBrightnessLevel()-1))*100.0);
if (percentageStep > 0 && (percentageStep <= (100-currentPerc))) {
minPercStep = percentageStep;
}
if ((currentPerc + minPercStep) > 100) {
// set to 100 %
setTo = getMaxBrightnessLevel() -1;
} else {
setTo = (int)(((float)(getMaxBrightnessLevel()-1))*(((float)(currentPerc + minPercStep))/100.0));
if ((setTo == getCurrentBrightnessLevel()) && (setTo < (getMaxBrightnessLevel() -1))) {
setTo++;
}
}
if (trace) {
kdDebug() << "Max: " << getMaxBrightnessLevel()
<< " Current: " << getCurrentBrightnessLevel()
<< " minPercStep: " << minPercStep
<< " currentPerc: " << currentPerc
<< " setTo: " << setTo << endl;
}
retval = setBrightness(setTo, -1);
if (supportBrightness() && getCurrentBrightnessLevel() < getMaxBrightnessLevel() &&
percentageStep > 0)
{
int currentPerc = (int)(100.0 * getCurrentBrightnessLevel() / getMaxBrightnessLevel());
retval = setBrightnessPercentage(currentPerc + percentageStep);
}
kdDebugFuncOut(trace);
@ -1186,33 +1211,9 @@ bool HardwareInfo::setBrightnessDown(int percentageStep) {
checkCurrentBrightness();
if (supportBrightness() && (getCurrentBrightnessLevel() > 0)) {
int setTo = 0;
int minPercStep = 10;
int currentPerc = (int)(((float)getCurrentBrightnessLevel()/(float)(getMaxBrightnessLevel()-1))*100.0);
if (percentageStep > 0 && (percentageStep < currentPerc)) {
minPercStep = percentageStep;
}
if ((currentPerc - minPercStep) < 0) {
setTo = 0;
} else {
setTo = (int)(((float)(getMaxBrightnessLevel()-1))*(((float)(currentPerc - minPercStep))/100.0));
if ((setTo == getCurrentBrightnessLevel()) && (setTo > 0)) {
setTo--;
}
}
if (trace) {
kdDebug() << "Max: " << getMaxBrightnessLevel()
<< " Current: " << getCurrentBrightnessLevel()
<< " minPercStep: " << minPercStep
<< " currentPerc: " << currentPerc
<< " setTo: " << setTo << endl;
}
retval = setBrightness(setTo, -1);
if (supportBrightness() && getCurrentBrightnessLevel() > 0 && percentageStep > 0) {
int currentPerc = (int)(100.0 * getCurrentBrightnessLevel() / getMaxBrightnessLevel());
retval = setBrightnessPercentage(currentPerc - percentageStep);
}
kdDebugFuncOut(trace);

@ -459,8 +459,10 @@ public:
// --> functions to call a TDE hardware library and trigger an action
//! execute/trigger a suspend via the TDE hardware library
bool suspend ( suspend_type suspend );
//! set the brightness via TDE hardware library
bool setBrightness ( int level, int percent = -1);
//! set the brightness level via TDE hardware library
bool setBrightnessLevel(int level);
//! set the brightness percentage via TDE hardware library
bool setBrightnessPercentage(int percent);
//! to set the brightness down
bool setBrightnessDown(int percentageStep = -1);
//! to set the brightness up

@ -1155,7 +1155,7 @@ void tdepowersave::do_dimm() {
// dimm the display down
if (current > 0 &&
current > ((int)((float)hwinfo->getMaxBrightnessLevel()*((float)settings->autoDimmTo/100.0))-1)) {
hwinfo->setBrightness((current -1) , -1);
hwinfo->setBrightnessLevel(current -1);
} else {
AUTODIMM_Timer->stop();
@ -1167,7 +1167,7 @@ void tdepowersave::do_dimm() {
} else {
// dimm the display up
if (current < ((int)((float)hwinfo->getMaxBrightnessLevel()*((float)settings->brightnessValue/100.0))-1)) {
hwinfo->setBrightness((current +1) , -1);
hwinfo->setBrightnessLevel(current +1);
} else {
AUTODIMM_Timer->stop();
}
@ -1925,7 +1925,7 @@ void tdepowersave::setSchemeSettings(){
// --> set brightness settings
if(settings->brightness && hwinfo->supportBrightness()) {
// set to given values
hwinfo->setBrightness (-1, settings->brightnessValue);
hwinfo->setBrightnessPercentage(settings->brightnessValue);
}
// --> set CPU Freq settings
@ -2205,7 +2205,7 @@ void tdepowersave::handleActionCall ( action action, int value , bool checkAC, b
TQTimer::singleShot(100, this, TQT_SLOT(do_freeze()));
break;
case BRIGHTNESS:
hwinfo->setBrightness( -1, value );
hwinfo->setBrightnessPercentage(value);
break;
case CPUFREQ_POWERSAVE:
hwinfo->setCPUFreq( POWERSAVE );
@ -2953,7 +2953,7 @@ void tdepowersave::brightnessSet(int percentage)
if (hwinfo->supportBrightness() && percentage >= 0 && percentage <= 100)
{
hwinfo->setBrightness(-1, percentage);
hwinfo->setBrightnessPercentage(percentage);
}
kdDebugFuncOut(trace);

Loading…
Cancel
Save