Commit c04e7643 authored by Bhushan Shah's avatar Bhushan Shah 📱
Browse files

[platforms/hwcomposer] Reset old brightness when turning screen back on

Now powerdevil can adjust brightness using leds subsystem, however, kwin
as well sets brightness to 0 for turning off screen and 0xff when
turning screen back on. This resets the brightness set by the powerdevil
to 100%.

As a solution now kwin listens to brightnessChanged dbus signal of
brightnesscontrol and book-keeps the changed brightness, if screen is
turned off it sets brightness to 0 and when turning screen on, it resets
to old brightness.

If powermanagement service doesn't appear on dbus by default it restores
100% brightness.

Test Plan:
Appearantly this still doesn't work as-it-is on phone, because powerdevil
doesn't emit brightnessChanged dbus signal because of bug in the driver of
backlight control, driver doesn't seem to trigger uevents for changes in
backlight. But with hack in powerdevil to emit brightnessChanged when setting
brightness, this works

Reviewers: broulik, #plasma_on_wayland, graesslin

Reviewed By: #plasma_on_wayland, graesslin

Subscribers: plasma-devel, kwin

Tags: #plasma_on_wayland, #kwin

Differential Revision:
parent e40344c6
......@@ -31,6 +31,7 @@ along with this program. If not, see <>.
#include <KWayland/Server/seat_interface.h>
// Qt
#include <QKeyEvent>
#include <QDBusConnection>
// hybris/android
#include <hardware/hardware.h>
#include <hardware/hwcomposer.h>
......@@ -143,6 +144,13 @@ void BacklightInputEventFilter::toggleBacklight()
HwcomposerBackend::HwcomposerBackend(QObject *parent)
: Platform(parent)
if (!QDBusConnection::sessionBus().connect(QStringLiteral("org.kde.Solid.PowerManagement"),
QStringLiteral("brightnessChanged"), this,
SLOT(screenBrightnessChanged(int)))) {
qCWarning(KWIN_HWCOMPOSER) << "Failed to connect to brightness control";
......@@ -321,7 +329,7 @@ void HwcomposerBackend::toggleScreenBrightness()
if (!m_lights) {
const int brightness = m_outputBlank ? 0 : 0xFF;
const int brightness = m_outputBlank ? 0 : m_oldScreenBrightness;
struct light_state_t state;
state.flashMode = LIGHT_FLASH_NONE;
state.brightnessMode = BRIGHTNESS_MODE_USER;
......@@ -86,6 +86,9 @@ Q_SIGNALS:
private Q_SLOTS:
void toggleBlankOutput();
void screenBrightnessChanged(int brightness) {
m_oldScreenBrightness = brightness;
void initLights();
......@@ -96,6 +99,7 @@ private:
bool m_outputBlank = true;
int m_refreshRate = 60000;
int m_vsyncInterval = 16;
int m_oldScreenBrightness = 0xff;
bool m_hasVsync = false;
QMutex m_vsyncMutex;
QWaitCondition m_vsyncWaitCondition;
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