|
|
|
@ -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);
|
|
|
|
|