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()) { if (cB_Brightness->isEnabled() && cB_Brightness->isChecked()) {
scheme_valueChanged(); scheme_valueChanged();
tL_valueBrightness->setText(TQString::number(new_value) + " %"); tL_valueBrightness->setText(TQString::number(new_value) + " %");
hwinfo->setBrightness(-1, new_value); hwinfo->setBrightnessPercentage(new_value);
pB_resetBrightness->setEnabled(true); pB_resetBrightness->setEnabled(true);
brightness_changed = true; brightness_changed = true;
} }
@ -1664,7 +1664,7 @@ void ConfigureDialog::brightnessSlider_sliderMoved( int new_value ) {
void ConfigureDialog::pB_resetBrightness_clicked( ) { void ConfigureDialog::pB_resetBrightness_clicked( ) {
kdDebugFuncIn(trace); kdDebugFuncIn(trace);
hwinfo->setBrightness(brightness_last, -1); hwinfo->setBrightnessLevel(brightness_last);
brightnessSlider->setValue(brightness_last); brightnessSlider->setValue(brightness_last);
pB_resetBrightness->setEnabled(false); pB_resetBrightness->setEnabled(false);
brightness_changed = 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 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 * \return boolean with result of the operation
* \retval true if successful * \retval true if successful
* \retval false else, if a error occurs * \retval false else, if a error occurs
*/ */
bool HardwareInfo::setBrightness ( int level, int percent ){ bool HardwareInfo::setBrightnessLevel(int level)
if (trace) kdDebug() << funcinfo << "IN: " << "level: " << level << " percent: " << percent << endl; {
if (trace) kdDebug() << funcinfo << "IN: " << "level: " << level << endl;
bool retval = false; 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 (backlightdevice) {
if (percent == 0) { if (!brightness) {
checkBrightness();
}
// Make sure level is within valid range
if (level < 0) {
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 { } else {
level = (int)((float)availableBrightnessLevels * ((float)percent/100.0)); backlightdevice->setRawBrightness(level);
if (level > (availableBrightnessLevels -1)) retval = true;
level = availableBrightnessLevels -1; }
kdDebug() << "percentage mapped to new level: " << level << endl;
} }
} }
// 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 // Use the first backlight in the list
TDEGenericHardwareList hwlist = m_hwdevices->listByDeviceClass(TDEGenericDeviceType::Backlight); TDEGenericHardwareList hwlist = m_hwdevices->listByDeviceClass(TDEGenericDeviceType::Backlight);
TDEGenericDevice *hwdevice; TDEGenericDevice *hwdevice;
@ -934,8 +974,17 @@ bool HardwareInfo::setBrightness ( int level, int percent ){
checkBrightness(); checkBrightness();
} }
if (!brightness || (level < 0 ) || (level >= availableBrightnessLevels)) { // Make sure percentage is within valid range
kdError() << "Change brightness or requested level not supported " << endl; 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 {
if (currentBrightnessLevel == level) { if (currentBrightnessLevel == level) {
kdDebug() << "Brightness level not changed, requested level == current level" << endl; kdDebug() << "Brightness level not changed, requested level == current level" << endl;
@ -1137,35 +1186,11 @@ bool HardwareInfo::setBrightnessUp(int percentageStep) {
checkCurrentBrightness(); checkCurrentBrightness();
if (supportBrightness() && (getCurrentBrightnessLevel() >= 0) && if (supportBrightness() && getCurrentBrightnessLevel() < getMaxBrightnessLevel() &&
(getCurrentBrightnessLevel() != (getMaxBrightnessLevel()-1))) { percentageStep > 0)
int setTo = 0; {
int minPercStep = 10; int currentPerc = (int)(100.0 * getCurrentBrightnessLevel() / getMaxBrightnessLevel());
int currentPerc = (int)(((float)getCurrentBrightnessLevel()/(float)(getMaxBrightnessLevel()-1))*100.0); retval = setBrightnessPercentage(currentPerc + percentageStep);
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);
} }
kdDebugFuncOut(trace); kdDebugFuncOut(trace);
@ -1186,33 +1211,9 @@ bool HardwareInfo::setBrightnessDown(int percentageStep) {
checkCurrentBrightness(); checkCurrentBrightness();
if (supportBrightness() && (getCurrentBrightnessLevel() > 0)) { if (supportBrightness() && getCurrentBrightnessLevel() > 0 && percentageStep > 0) {
int setTo = 0; int currentPerc = (int)(100.0 * getCurrentBrightnessLevel() / getMaxBrightnessLevel());
int minPercStep = 10; retval = setBrightnessPercentage(currentPerc - percentageStep);
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);
} }
kdDebugFuncOut(trace); kdDebugFuncOut(trace);

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

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

Loading…
Cancel
Save