[backends/hwcompser] Toggle blank screen on power button press

Also blocks compositor while screen is turned off.
This commit is contained in:
Martin Gräßlin 2015-05-11 14:43:51 +02:00
parent 533a39bc3e
commit d5d304c2f6
2 changed files with 36 additions and 2 deletions

View file

@ -21,6 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "hwcomposer_backend.h"
#include "logging.h"
#include "screens_hwcomposer.h"
#include "composite.h"
#include "wayland_server.h"
// KWayland
#include <KWayland/Server/display.h>
@ -298,6 +299,12 @@ void HwcomposerBackend::inputEvent(Event *event, void *context)
if (key == KEY_RESERVED) {
break;
}
if (key == KEY_POWER) {
// this key is handled internally
// TODO: trigger timer to decide what should be done: short press/release (un)blank screen
// long press should emit the normal key pressed
break;
}
backend->keyboardKeyPressed(key, event->details.key.event_time);
break;
}
@ -306,6 +313,11 @@ void HwcomposerBackend::inputEvent(Event *event, void *context)
if (key == KEY_RESERVED) {
break;
}
if (key == KEY_POWER) {
// this key is handled internally
QMetaObject::invokeMethod(backend, "toggleBlankOutput", Qt::QueuedConnection);
break;
}
backend->keyboardKeyReleased(key, event->details.key.event_time);
break;
}
@ -405,7 +417,8 @@ void HwcomposerBackend::init()
}
// unblank, setPowerMode?
hwcDevice->blank(hwcDevice, 0, 0);
m_device = hwcDevice;
toggleBlankOutput();
// get display configuration
auto output = createOutput(hwcDevice);
@ -415,7 +428,6 @@ void HwcomposerBackend::init()
}
m_displaySize = output->pixelSize();
qCDebug(KWIN_HWCOMPOSER) << "Display size:" << m_displaySize;
m_device = hwcDevice;
initInput();
@ -447,6 +459,24 @@ void HwcomposerBackend::initInput()
waylandServer()->seat()->setHasTouch(true);
}
void HwcomposerBackend::toggleBlankOutput()
{
if (!m_device) {
return;
}
m_outputBlank = !m_outputBlank;
m_device->blank(m_device, 0, m_outputBlank ? 1 : 0);
// enable/disable compositor repainting when blanked
if (Compositor *compositor = Compositor::self()) {
if (m_outputBlank) {
compositor->aboutToSwapBuffers();
} else {
compositor->bufferSwapComplete();
compositor->addRepaintFull();
}
}
}
HwcomposerWindow *HwcomposerBackend::createSurface()
{
return new HwcomposerWindow(this);

View file

@ -60,12 +60,16 @@ public:
return m_device;
}
private Q_SLOTS:
void toggleBlankOutput();
private:
static void inputEvent(Event *event, void *context);
void initInput();
QSize m_displaySize;
hwc_composer_device_1_t *m_device = nullptr;
AndroidEventListener *m_inputListener = nullptr;
bool m_outputBlank = true;
};
class HwcomposerWindow : public HWComposerNativeWindow