File indexing completed on 2024-02-18 16:19:56

0001 /*
0002     KWin - the KDE window manager
0003     This file is part of the KDE project.
0004 
0005     SPDX-FileCopyrightText: 2015 Martin Gräßlin <mgraesslin@kde.org>
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 #include "dpmsinputeventfilter.h"
0010 #include "core/output.h"
0011 #include "input_event.h"
0012 #include "main.h"
0013 #include "wayland/seat_interface.h"
0014 #include "wayland_server.h"
0015 #include "workspace.h"
0016 
0017 #include <QGuiApplication>
0018 #include <QKeyEvent>
0019 
0020 namespace KWin
0021 {
0022 
0023 DpmsInputEventFilter::DpmsInputEventFilter()
0024     : InputEventFilter()
0025 {
0026     KSharedConfig::Ptr kwinSettings = kwinApp()->config();
0027     m_enableDoubleTap = kwinSettings->group("Wayland").readEntry<bool>("DoubleTapWakeup", true);
0028 }
0029 
0030 DpmsInputEventFilter::~DpmsInputEventFilter() = default;
0031 
0032 bool DpmsInputEventFilter::pointerEvent(MouseEvent *event, quint32 nativeButton)
0033 {
0034     notify();
0035     return true;
0036 }
0037 
0038 bool DpmsInputEventFilter::wheelEvent(WheelEvent *event)
0039 {
0040     notify();
0041     return true;
0042 }
0043 
0044 bool DpmsInputEventFilter::keyEvent(KeyEvent *event)
0045 {
0046     if (event->type() == QKeyEvent::KeyPress) {
0047         notify();
0048     }
0049     return true;
0050 }
0051 
0052 bool DpmsInputEventFilter::touchDown(qint32 id, const QPointF &pos, std::chrono::microseconds time)
0053 {
0054     if (m_enableDoubleTap) {
0055         if (m_touchPoints.isEmpty()) {
0056             if (!m_doubleTapTimer.isValid()) {
0057                 // this is the first tap
0058                 m_doubleTapTimer.start();
0059             } else {
0060                 if (m_doubleTapTimer.elapsed() < qApp->doubleClickInterval()) {
0061                     m_secondTap = true;
0062                 } else {
0063                     // took too long. Let's consider it a new click
0064                     m_doubleTapTimer.restart();
0065                 }
0066             }
0067         } else {
0068             // not a double tap
0069             m_doubleTapTimer.invalidate();
0070             m_secondTap = false;
0071         }
0072         m_touchPoints << id;
0073     }
0074     return true;
0075 }
0076 
0077 bool DpmsInputEventFilter::touchUp(qint32 id, std::chrono::microseconds time)
0078 {
0079     if (m_enableDoubleTap) {
0080         m_touchPoints.removeAll(id);
0081         if (m_touchPoints.isEmpty() && m_doubleTapTimer.isValid() && m_secondTap) {
0082             if (m_doubleTapTimer.elapsed() < qApp->doubleClickInterval()) {
0083                 waylandServer()->seat()->setTimestamp(std::chrono::duration_cast<std::chrono::milliseconds>(time));
0084                 notify();
0085             }
0086             m_doubleTapTimer.invalidate();
0087             m_secondTap = false;
0088         }
0089     }
0090     return true;
0091 }
0092 
0093 bool DpmsInputEventFilter::touchMotion(qint32 id, const QPointF &pos, std::chrono::microseconds time)
0094 {
0095     // ignore the event
0096     return true;
0097 }
0098 
0099 void DpmsInputEventFilter::notify()
0100 {
0101     const QList<Output *> outputs = workspace()->outputs();
0102     for (Output *output : outputs) {
0103         output->setDpmsMode(Output::DpmsMode::On);
0104     }
0105 }
0106 
0107 }