Commit 62be85f4 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧
Browse files

battery: Improve the brightness responsiveness

Summary:
Use QQC2.Slider, so that we have a moved signal. This way we can only
issue new brightnesses when the user actually interacts with it.
Don't adapt to the system brightness until we have finished interacting
with it.

Test Plan:
Manual testing, flickering is very much reduced both when scrolling over the
compact plasmoid as well as the slider.

Reviewers: #plasma, broulik

Reviewed By: #plasma, broulik

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D26035
parent 500192a7
......@@ -23,12 +23,16 @@ import QtQuick.Layouts 1.1
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as Components
import org.kde.plasma.components 3.0 as Components3
RowLayout {
id: item
property alias icon: brightnessIcon.source
property alias label: brightnessLabel.text
property alias value: brightnessSlider.value
property alias maximumValue: brightnessSlider.maximumValue
property alias maximumValue: brightnessSlider.to
property alias stepSize: brightnessSlider.stepSize
signal moved()
spacing: units.gridUnit
......@@ -51,13 +55,14 @@ RowLayout {
height: paintedHeight
}
Components.Slider {
Components3.Slider {
id: brightnessSlider
width: parent.width
// Don't allow the slider to turn off the screen
// Please see https://git.reviewboard.kde.org/r/122505/ for more information
minimumValue: maximumValue > 100 ? 1 : 0
from: to > 100 ? 1 : 0
stepSize: 1
onMoved: item.moved()
}
}
}
......@@ -38,18 +38,6 @@ FocusScope {
signal powermanagementChanged(bool checked)
Component.onCompleted: {
// setup handler on slider value manually to avoid change on creation
brightnessSlider.valueChanged.connect(function() {
batterymonitor.screenBrightness = brightnessSlider.value
})
keyboardBrightnessSlider.valueChanged.connect(function() {
batterymonitor.keyboardBrightness = keyboardBrightnessSlider.value
})
}
Column {
id: settingsColumn
anchors.horizontalCenter: parent.horizontalCenter
......@@ -82,6 +70,9 @@ FocusScope {
maximumValue: batterymonitor.maximumScreenBrightness
KeyNavigation.tab: keyboardBrightnessSlider
KeyNavigation.backtab: batteryList
stepSize: batterymonitor.maximumScreenBrightness/100
onMoved: batterymonitor.screenBrightness = value
// Manually dragging the slider around breaks the binding
Connections {
......@@ -102,6 +93,8 @@ FocusScope {
KeyNavigation.tab: pmSwitch
KeyNavigation.backtab: brightnessSlider
onMoved: batterymonitor.keyboardBrightness = value
// Manually dragging the slider around breaks the binding
Connections {
target: batterymonitor
......
......@@ -105,6 +105,7 @@ Item {
readonly property var kcm_energyinfo: ["kcm_energyinfo.desktop"]
readonly property bool kcmEnergyInformationAuthorized: KCMShell.authorize(kcm_energyinfo).length > 0
property QtObject updateScreenBrightnessJob
onScreenBrightnessChanged: {
if (disableBrightnessUpdate) {
return;
......@@ -114,8 +115,13 @@ Item {
operation.brightness = screenBrightness;
// show OSD only when the plasmoid isn't expanded since the moving slider is feedback enough
operation.silent = plasmoid.expanded
service.startOperationCall(operation);
updateScreenBrightnessJob = service.startOperationCall(operation);
updateScreenBrightnessJob.finished.connect(function(job) {
Logic.updateBrightness(batterymonitor, pmSource);
});
}
property QtObject updateKeyboardBrightnessJob
onKeyboardBrightnessChanged: {
if (disableBrightnessUpdate) {
return;
......@@ -124,7 +130,10 @@ Item {
var operation = service.operationDescription("setKeyboardBrightness");
operation.brightness = keyboardBrightness;
operation.silent = plasmoid.expanded
service.startOperationCall(operation);
updateKeyboardBrightnessJob = service.startOperationCall(operation);
updateKeyboardBrightnessJob.finished.connect(function(job) {
Logic.updateBrightness(batterymonitor, pmSource);
});
}
function action_powerdevilkcm() {
......
......@@ -50,6 +50,9 @@ function batteryDetails(batteryData, remainingTime) {
}
function updateBrightness(rootItem, source) {
if (rootItem.updateScreenBrightnessJob || rootItem.updateKeyboardBrightnessJob)
return;
if (!source.data["PowerDevil"]) {
return;
}
......
......@@ -41,6 +41,16 @@ PowerManagementJob::~PowerManagementJob()
{
}
static void callWhenFinished(const QDBusPendingCall& pending, std::function<void()> func, QObject* parent)
{
QDBusPendingCallWatcher* watcher = new QDBusPendingCallWatcher(pending, parent);
QObject::connect(watcher, &QDBusPendingCallWatcher::finished,
parent, [func](QDBusPendingCallWatcher* watcher) {
watcher->deleteLater();
func();
});
}
void PowerManagementJob::start()
{
const QString operation = operationName();
......@@ -92,12 +102,12 @@ void PowerManagementJob::start()
setResult(Solid::PowerManagement::stopSuppressingScreenPowerManagement(parameters().value(QStringLiteral("cookie")).toInt()));
return;
} else if (operation == QLatin1String("setBrightness")) {
setScreenBrightness(parameters().value(QStringLiteral("brightness")).toInt(), parameters().value(QStringLiteral("silent")).toBool());
setResult(true);
auto pending = setScreenBrightness(parameters().value(QStringLiteral("brightness")).toInt(), parameters().value(QStringLiteral("silent")).toBool());
callWhenFinished(pending, [this] { setResult(true); }, this);
return;
} else if (operation == QLatin1String("setKeyboardBrightness")) {
setKeyboardBrightness(parameters().value(QStringLiteral("brightness")).toInt(), parameters().value(QStringLiteral("silent")).toBool());
setResult(true);
auto pending = setKeyboardBrightness(parameters().value(QStringLiteral("brightness")).toInt(), parameters().value(QStringLiteral("silent")).toBool());
callWhenFinished(pending, [this] { setResult(true); }, this);
return;
}
......@@ -105,24 +115,24 @@ void PowerManagementJob::start()
setResult(false);
}
void PowerManagementJob::setScreenBrightness(int value, bool silent)
QDBusPendingCall PowerManagementJob::setScreenBrightness(int value, bool silent)
{
QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.Solid.PowerManagement"),
QStringLiteral("/org/kde/Solid/PowerManagement/Actions/BrightnessControl"),
QStringLiteral("org.kde.Solid.PowerManagement.Actions.BrightnessControl"),
silent ? "setBrightnessSilent" : "setBrightness");
msg << value;
QDBusConnection::sessionBus().asyncCall(msg);
return QDBusConnection::sessionBus().asyncCall(msg);
}
void PowerManagementJob::setKeyboardBrightness(int value, bool silent)
QDBusPendingCall PowerManagementJob::setKeyboardBrightness(int value, bool silent)
{
QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.Solid.PowerManagement"),
QStringLiteral("/org/kde/Solid/PowerManagement/Actions/KeyboardBrightnessControl"),
QStringLiteral("org.kde.Solid.PowerManagement.Actions.KeyboardBrightnessControl"),
silent ? "setKeyboardBrightnessSilent" : "setKeyboardBrightness");
msg << value;
QDBusConnection::sessionBus().asyncCall(msg);
return QDBusConnection::sessionBus().asyncCall(msg);
}
void PowerManagementJob::requestShutDown()
......
......@@ -22,9 +22,10 @@
// plasma
#include <Plasma/ServiceJob>
class QDBusPendingCall;
class PowerManagementJob : public Plasma::ServiceJob
{
Q_OBJECT
public:
......@@ -37,8 +38,8 @@ class PowerManagementJob : public Plasma::ServiceJob
private:
void requestShutDown();
void setScreenBrightness(int value, bool silent);
void setKeyboardBrightness(int value, bool silent);
QDBusPendingCall setScreenBrightness(int value, bool silent);
QDBusPendingCall setKeyboardBrightness(int value, bool silent);
};
#endif // POWERMANAGEMENTJOB_H
Markdown is supported
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