File: powerdevilscreenbrightnesslogic.cpp

package info (click to toggle)
powerdevil 4%3A5.20.5-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 4,372 kB
  • sloc: cpp: 8,987; xml: 1,294; sh: 24; makefile: 12
file content (77 lines) | stat: -rw-r--r-- 3,090 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/***************************************************************************
 *   Copyright (C) 2014 by Nikita Skovoroda <chalkerx@gmail.com>            *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
 ***************************************************************************/

#include "powerdevilscreenbrightnesslogic.h"
#include "powerdevil_debug.h"
#include <QDebug>

namespace PowerDevil
{

int ScreenBrightnessLogic::toggled() const
{
    // ignore, we won't toggle the display off
    return -1;
}

int ScreenBrightnessLogic::calculateSteps(int maxValue) const
{
    // We assume that the preferred number of steps for screen brightness is 20, but we don't want more.

    if (maxValue <= 20) {
        // Too few steps, return the number of actual steps.
        // Those would be uniform, but not round in some cases.
        return maxValue;
    }

    if (maxValue >= 100 || maxValue % 20 == 0 || (maxValue >= 80 && maxValue % 4 == 0)) {
        // In this case all 20 steps are perfect.
        return 20;
    }

    // At this point we have maxValue in the range 21-79 which probably is a rare case.

    if (maxValue >= 34 || maxValue == 32 || maxValue == 28) {
        // In this case all 20 steps are matched +-1%, which is fine.
        return 20;
    }

    // At this point we have maxValue in the range 21-33.
    // Trying to make 20 steps from here will make them not uniform.

    if (maxValue % 5 == 0) {
        // For maxValue == 30 there are 10 even and round steps.
        // For maxValue == 25 steps are shown as
        //  0% 12% 20% 32% 40% 52% 60% 72% 80% 92% 100%, which is also fine.
        return 10;
    }

    // Trying hard to find an uniform steps set
    for (int steps = 9; steps <= 14; steps++) {
        if (maxValue % steps == 0) {
            return steps;
        }
    }

    // 4 different maxValue values left: 21, 23, 29, 31.
    // Those produce +-2% on 10 steps, there is nothing better we can do here.
    return 10;
}

};