From c04e7643699e3b22240741a3efcca98ad669ab8e Mon Sep 17 00:00:00 2001 From: Bhushan Shah Date: Wed, 17 Aug 2016 14:39:58 +0530 Subject: [PATCH] [platforms/hwcomposer] Reset old brightness when turning screen back on Summary: 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: https://phabricator.kde.org/D2468 --- plugins/platforms/hwcomposer/hwcomposer_backend.cpp | 10 +++++++++- plugins/platforms/hwcomposer/hwcomposer_backend.h | 4 ++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/plugins/platforms/hwcomposer/hwcomposer_backend.cpp b/plugins/platforms/hwcomposer/hwcomposer_backend.cpp index 9305d39613..0dc26b80b5 100644 --- a/plugins/platforms/hwcomposer/hwcomposer_backend.cpp +++ b/plugins/platforms/hwcomposer/hwcomposer_backend.cpp @@ -31,6 +31,7 @@ along with this program. If not, see . #include // Qt #include +#include // hybris/android #include #include @@ -143,6 +144,13 @@ void BacklightInputEventFilter::toggleBacklight() HwcomposerBackend::HwcomposerBackend(QObject *parent) : Platform(parent) { + if (!QDBusConnection::sessionBus().connect(QStringLiteral("org.kde.Solid.PowerManagement"), + QStringLiteral("/org/kde/Solid/PowerManagement/Actions/BrightnessControl"), + QStringLiteral("org.kde.Solid.PowerManagement.Actions.BrightnessControl"), + QStringLiteral("brightnessChanged"), this, + SLOT(screenBrightnessChanged(int)))) { + qCWarning(KWIN_HWCOMPOSER) << "Failed to connect to brightness control"; + } handleOutputs(); } @@ -321,7 +329,7 @@ void HwcomposerBackend::toggleScreenBrightness() if (!m_lights) { return; } - 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; diff --git a/plugins/platforms/hwcomposer/hwcomposer_backend.h b/plugins/platforms/hwcomposer/hwcomposer_backend.h index e7125adf79..acd5269efc 100644 --- a/plugins/platforms/hwcomposer/hwcomposer_backend.h +++ b/plugins/platforms/hwcomposer/hwcomposer_backend.h @@ -86,6 +86,9 @@ Q_SIGNALS: private Q_SLOTS: void toggleBlankOutput(); + void screenBrightnessChanged(int brightness) { + m_oldScreenBrightness = brightness; + } private: 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;