summaryrefslogtreecommitdiffstats
path: root/src/tdepowersave.cpp
diff options
context:
space:
mode:
authorMichele Calgaro <[email protected]>2023-08-30 14:27:52 +0900
committerMichele Calgaro <[email protected]>2023-09-04 09:54:27 +0900
commitc3b2fad5e680e600fdee13981c43d342483d5635 (patch)
tree027de3e0c7ebd643db327f35321fb89d7eeb70fa /src/tdepowersave.cpp
parentaee72d11d40febd7cf65634f7569e091edbc26f7 (diff)
downloadtdepowersave-c3b2fad5e680e600fdee13981c43d342483d5635.tar.gz
tdepowersave-c3b2fad5e680e600fdee13981c43d342483d5635.zip
Fix rounding error when setting brightness by percentage
Signed-off-by: Michele Calgaro <[email protected]>
Diffstat (limited to 'src/tdepowersave.cpp')
-rw-r--r--src/tdepowersave.cpp18
1 files changed, 8 insertions, 10 deletions
diff --git a/src/tdepowersave.cpp b/src/tdepowersave.cpp
index b57bfef..41ade35 100644
--- a/src/tdepowersave.cpp
+++ b/src/tdepowersave.cpp
@@ -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);
}