KWin
Loading...
Searching...
No Matches
dpmsinputeventfilter.cpp
Go to the documentation of this file.
1/*
2 KWin - the KDE window manager
3 This file is part of the KDE project.
4
5 SPDX-FileCopyrightText: 2015 Martin Gräßlin <mgraesslin@kde.org>
6
7 SPDX-License-Identifier: GPL-2.0-or-later
8*/
10#include "core/output.h"
11#include "core/outputbackend.h"
12#include "core/session.h"
13#include "input_event.h"
14#include "main.h"
15#include "wayland/seat.h"
16#include "wayland_server.h"
17#include "workspace.h"
18
19#include <QGuiApplication>
20#include <QKeyEvent>
21
22namespace KWin
23{
24
27{
28 KSharedConfig::Ptr kwinSettings = kwinApp()->config();
29 m_enableDoubleTap = kwinSettings->group(QStringLiteral("Wayland")).readEntry<bool>("DoubleTapWakeup", true);
30 if (Session *session = kwinApp()->outputBackend()->session()) {
31 connect(session, &Session::awoke, this, &DpmsInputEventFilter::notify);
32 }
33}
34
39
40bool DpmsInputEventFilter::pointerEvent(MouseEvent *event, quint32 nativeButton)
41{
42 notify();
43 return true;
44}
45
47{
48 notify();
49 return true;
50}
51
53{
54 if (event->type() == QKeyEvent::KeyPress) {
55 notify();
56 } else if (event->type() == QKeyEvent::KeyRelease) {
57 return false;
58 }
59 return true;
60}
61
62bool DpmsInputEventFilter::touchDown(qint32 id, const QPointF &pos, std::chrono::microseconds time)
63{
64 if (m_enableDoubleTap) {
65 if (m_touchPoints.isEmpty()) {
66 if (!m_doubleTapTimer.isValid()) {
67 // this is the first tap
68 m_doubleTapTimer.start();
69 } else {
70 if (m_doubleTapTimer.elapsed() < qApp->doubleClickInterval()) {
71 m_secondTap = true;
72 } else {
73 // took too long. Let's consider it a new click
74 m_doubleTapTimer.restart();
75 }
76 }
77 } else {
78 // not a double tap
79 m_doubleTapTimer.invalidate();
80 m_secondTap = false;
81 }
82 m_touchPoints << id;
83 }
84 return true;
85}
86
87bool DpmsInputEventFilter::touchUp(qint32 id, std::chrono::microseconds time)
88{
89 if (m_enableDoubleTap) {
90 m_touchPoints.removeAll(id);
91 if (m_touchPoints.isEmpty() && m_doubleTapTimer.isValid() && m_secondTap) {
92 if (m_doubleTapTimer.elapsed() < qApp->doubleClickInterval()) {
93 waylandServer()->seat()->setTimestamp(std::chrono::duration_cast<std::chrono::milliseconds>(time));
94 notify();
95 }
96 m_doubleTapTimer.invalidate();
97 m_secondTap = false;
98 }
99 }
100 return true;
101}
102
103bool DpmsInputEventFilter::touchMotion(qint32 id, const QPointF &pos, std::chrono::microseconds time)
104{
105 // ignore the event
106 return true;
107}
108
109void DpmsInputEventFilter::notify()
110{
111 const QList<Output *> outputs = workspace()->outputs();
112 for (Output *output : outputs) {
113 output->setDpmsMode(Output::DpmsMode::On);
114 }
115}
116
117}
118#include "moc_dpmsinputeventfilter.cpp"
bool touchUp(qint32 id, std::chrono::microseconds time) override
bool keyEvent(KeyEvent *event) override
bool wheelEvent(WheelEvent *event) override
bool pointerEvent(MouseEvent *event, quint32 nativeButton) override
bool touchMotion(qint32 id, const QPointF &pos, std::chrono::microseconds time) override
bool touchDown(qint32 id, const QPointF &pos, std::chrono::microseconds time) override
void setTimestamp(std::chrono::microseconds time)
Definition seat.cpp:488
SeatInterface * seat() const
QList< Output * > outputs() const
Definition workspace.h:762
WaylandServer * waylandServer()
Workspace * workspace()
Definition workspace.h:830