Commit 0f548c53 authored by Louis Moureaux's avatar Louis Moureaux Committed by Nate Graham
Browse files

Fix profile switching in the brightness actions

The current code assumes that the action is notified of every profile change,
which is only the case when the action is configured to run in all profiles.
The code that prevents brightness from being raised when switching to a more
conservative profile gets confused if the action didn't run in the "previous"
profile. Make it more robust by always querying the core for the previous
profile, which it luckily hasn't updated yet when the action gets executed.

BUG: 394945
FIXED-IN: 5.25


(cherry picked from commit 6220db1b)
parent 3b07690b
Pipeline #225929 passed with stage
in 2 minutes and 19 seconds
......@@ -79,10 +79,14 @@ void BrightnessControl::onProfileLoad()
{
const int absoluteBrightnessValue = qRound(m_defaultValue / 100.0 * brightnessMax());
// The core switches its profile after all actions have been updated, so here core()->currentProfile() is still the old one
const auto previousProfile = core()->currentProfile();
qCDebug(POWERDEVIL) << "Profiles: " << m_currentProfile << previousProfile;
// if the current profile is more conservative than the previous one and the
// current brightness is lower than the new profile
if (((m_currentProfile == QLatin1String("Battery") && m_lastProfile == QLatin1String("AC")) ||
(m_currentProfile == QLatin1String("LowBattery") && (m_lastProfile == QLatin1String("AC") || m_lastProfile == QLatin1String("Battery")))) &&
if (((m_currentProfile == QLatin1String("Battery") && previousProfile == QLatin1String("AC")) ||
(m_currentProfile == QLatin1String("LowBattery") && (previousProfile == QLatin1String("AC") || previousProfile == QLatin1String("Battery")))) &&
absoluteBrightnessValue > brightness()) {
// We don't want to change anything here
......@@ -93,8 +97,8 @@ void BrightnessControl::onProfileLoad()
};
// plugging in/out the AC is always explicit
if ((m_currentProfile == QLatin1String("AC") && m_lastProfile != QLatin1String("AC")) ||
(m_currentProfile != QLatin1String("AC") && m_lastProfile == QLatin1String("AC"))) {
if ((previousProfile == QLatin1String("AC") && m_currentProfile != QLatin1String("AC")) ||
(previousProfile != QLatin1String("AC") && m_currentProfile == QLatin1String("AC"))) {
args["Explicit"] = true;
args["Silent"] = true; // but we still don't want to show the OSD then
}
......@@ -126,11 +130,8 @@ bool BrightnessControl::isSupported()
bool BrightnessControl::loadAction(const KConfigGroup& config)
{
// Handle profile changes
m_lastProfile = m_currentProfile;
m_currentProfile = config.parent().name();
qCDebug(POWERDEVIL) << "Profiles: " << m_currentProfile << m_lastProfile;
if (config.hasKey("value")) {
m_defaultValue = config.readEntry<int>("value", 50);
}
......
......@@ -70,7 +70,6 @@ private:
int brightnessPercent(float value) const;
int m_defaultValue = -1;
QString m_lastProfile;
QString m_currentProfile;
};
......
......@@ -96,10 +96,15 @@ void KeyboardBrightnessControl::onIdleTimeout(int msec)
void KeyboardBrightnessControl::onProfileLoad()
{
const int absoluteKeyboardBrightnessValue = qRound(m_defaultValue / 100.0 * keyboardBrightnessMax());
// The core switches its profile after all actions have been updated, so here core()->currentProfile() is still the old one
const auto previousProfile = core()->currentProfile();
qCDebug(POWERDEVIL) << "Profiles: " << m_currentProfile << previousProfile;
// if the current profile is more conservative than the previous one and the
// current brightness is lower than the new profile
if (((m_currentProfile == QLatin1String("Battery") && m_lastProfile == QLatin1String("AC")) ||
(m_currentProfile == QLatin1String("LowBattery") && (m_lastProfile == QLatin1String("AC") || m_lastProfile == QLatin1String("Battery")))) &&
if (((m_currentProfile == QLatin1String("Battery") && previousProfile == QLatin1String("AC")) ||
(m_currentProfile == QLatin1String("LowBattery") && (previousProfile == QLatin1String("AC") || previousProfile == QLatin1String("Battery")))) &&
absoluteKeyboardBrightnessValue > keyboardBrightness()) {
// We don't want to change anything here
......@@ -110,8 +115,8 @@ void KeyboardBrightnessControl::onProfileLoad()
};
// plugging in/out the AC is always explicit
if ((m_currentProfile == QLatin1String("AC") && m_lastProfile != QLatin1String("AC")) ||
(m_currentProfile != QLatin1String("AC") && m_lastProfile == QLatin1String("AC"))) {
if ((m_currentProfile == QLatin1String("AC") && previousProfile != QLatin1String("AC")) ||
(m_currentProfile != QLatin1String("AC") && previousProfile == QLatin1String("AC"))) {
args["Explicit"] = true;
args["Silent"] = true; // but we still don't want to show the OSD then
}
......@@ -142,11 +147,8 @@ bool KeyboardBrightnessControl::isSupported()
bool KeyboardBrightnessControl::loadAction(const KConfigGroup& config)
{
// Handle profile changes
m_lastProfile = m_currentProfile;
m_currentProfile = config.parent().name();
qCDebug(POWERDEVIL) << "Profiles: " << m_currentProfile << m_lastProfile;
if (config.hasKey("value")) {
m_defaultValue = config.readEntry<int>("value", 50);
}
......
......@@ -72,7 +72,6 @@ private:
int m_defaultValue = -1;
int m_lastKeyboardBrightness = -1;
QString m_lastProfile;
QString m_currentProfile;
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment