File indexing completed on 2024-04-28 16:48:43

0001 /*
0002     KWin - the KDE window manager
0003     This file is part of the KDE project.
0004 
0005     SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org>
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 #pragma once
0010 
0011 #include "input.h"
0012 #include "input_event_spy.h"
0013 #include <config-kwin.h>
0014 #include <kwin_export.h>
0015 
0016 #include <QAbstractItemModel>
0017 #include <QStyledItemDelegate>
0018 #include <QVector>
0019 #include <functional>
0020 #include <memory>
0021 
0022 class QTextEdit;
0023 
0024 namespace KWaylandServer
0025 {
0026 class AbstractDataSource;
0027 }
0028 
0029 namespace Ui
0030 {
0031 class DebugConsole;
0032 }
0033 
0034 namespace KWin
0035 {
0036 
0037 class Window;
0038 class X11Window;
0039 class InternalWindow;
0040 class Unmanaged;
0041 class DebugConsoleFilter;
0042 class WaylandWindow;
0043 
0044 class KWIN_EXPORT DebugConsoleModel : public QAbstractItemModel
0045 {
0046     Q_OBJECT
0047 public:
0048     explicit DebugConsoleModel(QObject *parent = nullptr);
0049     ~DebugConsoleModel() override;
0050 
0051     int columnCount(const QModelIndex &parent) const override;
0052     QVariant data(const QModelIndex &index, int role) const override;
0053     QModelIndex index(int row, int column, const QModelIndex &parent) const override;
0054     int rowCount(const QModelIndex &parent) const override;
0055     QModelIndex parent(const QModelIndex &child) const override;
0056 
0057 private Q_SLOTS:
0058     void handleWindowAdded(Window *window);
0059     void handleWindowRemoved(Window *window);
0060 
0061 private:
0062     template<class T>
0063     QModelIndex indexForWindow(int row, int column, const QVector<T *> &windows, int id) const;
0064     template<class T>
0065     QModelIndex indexForProperty(int row, int column, const QModelIndex &parent, T *(DebugConsoleModel::*filter)(const QModelIndex &) const) const;
0066     template<class T>
0067     int propertyCount(const QModelIndex &parent, T *(DebugConsoleModel::*filter)(const QModelIndex &) const) const;
0068     QVariant propertyData(QObject *object, const QModelIndex &index, int role) const;
0069     template<class T>
0070     QVariant windowData(const QModelIndex &index, int role, const QVector<T *> windows, const std::function<QString(T *)> &toString) const;
0071     template<class T>
0072     void add(int parentRow, QVector<T *> &windows, T *window);
0073     template<class T>
0074     void remove(int parentRow, QVector<T *> &windows, T *window);
0075     WaylandWindow *waylandWindow(const QModelIndex &index) const;
0076     InternalWindow *internalWindow(const QModelIndex &index) const;
0077     X11Window *x11Window(const QModelIndex &index) const;
0078     Unmanaged *unmanaged(const QModelIndex &index) const;
0079     int topLevelRowCount() const;
0080 
0081     QVector<WaylandWindow *> m_waylandWindows;
0082     QVector<InternalWindow *> m_internalWindows;
0083     QVector<X11Window *> m_x11Windows;
0084     QVector<Unmanaged *> m_unmanageds;
0085 };
0086 
0087 class DebugConsoleDelegate : public QStyledItemDelegate
0088 {
0089     Q_OBJECT
0090 public:
0091     explicit DebugConsoleDelegate(QObject *parent = nullptr);
0092     ~DebugConsoleDelegate() override;
0093 
0094     QString displayText(const QVariant &value, const QLocale &locale) const override;
0095 };
0096 
0097 class KWIN_EXPORT DebugConsole : public QWidget
0098 {
0099     Q_OBJECT
0100 public:
0101     DebugConsole();
0102     ~DebugConsole() override;
0103 
0104 protected:
0105     void showEvent(QShowEvent *event) override;
0106 
0107 private:
0108     void initGLTab();
0109     void updateKeyboardTab();
0110 
0111     std::unique_ptr<Ui::DebugConsole> m_ui;
0112     std::unique_ptr<DebugConsoleFilter> m_inputFilter;
0113 };
0114 
0115 class SurfaceTreeModel : public QAbstractItemModel
0116 {
0117     Q_OBJECT
0118 public:
0119     explicit SurfaceTreeModel(QObject *parent = nullptr);
0120     ~SurfaceTreeModel() override;
0121 
0122     int columnCount(const QModelIndex &parent) const override;
0123     QVariant data(const QModelIndex &index, int role) const override;
0124     QModelIndex index(int row, int column, const QModelIndex &parent) const override;
0125     int rowCount(const QModelIndex &parent) const override;
0126     QModelIndex parent(const QModelIndex &child) const override;
0127 };
0128 
0129 class DebugConsoleFilter : public InputEventSpy
0130 {
0131 public:
0132     explicit DebugConsoleFilter(QTextEdit *textEdit);
0133     ~DebugConsoleFilter() override;
0134 
0135     void pointerEvent(MouseEvent *event) override;
0136     void wheelEvent(WheelEvent *event) override;
0137     void keyEvent(KeyEvent *event) override;
0138     void touchDown(qint32 id, const QPointF &pos, std::chrono::microseconds time) override;
0139     void touchMotion(qint32 id, const QPointF &pos, std::chrono::microseconds time) override;
0140     void touchUp(qint32 id, std::chrono::microseconds time) override;
0141 
0142     void pinchGestureBegin(int fingerCount, std::chrono::microseconds time) override;
0143     void pinchGestureUpdate(qreal scale, qreal angleDelta, const QPointF &delta, std::chrono::microseconds time) override;
0144     void pinchGestureEnd(std::chrono::microseconds time) override;
0145     void pinchGestureCancelled(std::chrono::microseconds time) override;
0146 
0147     void swipeGestureBegin(int fingerCount, std::chrono::microseconds time) override;
0148     void swipeGestureUpdate(const QPointF &delta, std::chrono::microseconds time) override;
0149     void swipeGestureEnd(std::chrono::microseconds time) override;
0150     void swipeGestureCancelled(std::chrono::microseconds time) override;
0151 
0152     void switchEvent(SwitchEvent *event) override;
0153 
0154     void tabletToolEvent(TabletEvent *event) override;
0155     void tabletToolButtonEvent(uint button, bool pressed, const TabletToolId &tabletToolId, std::chrono::microseconds time) override;
0156     void tabletPadButtonEvent(uint button, bool pressed, const TabletPadId &tabletPadId, std::chrono::microseconds time) override;
0157     void tabletPadStripEvent(int number, int position, bool isFinger, const TabletPadId &tabletPadId, std::chrono::microseconds time) override;
0158     void tabletPadRingEvent(int number, int position, bool isFinger, const TabletPadId &tabletPadId, std::chrono::microseconds time) override;
0159 
0160 private:
0161     QTextEdit *m_textEdit;
0162 };
0163 
0164 class InputDeviceModel : public QAbstractItemModel
0165 {
0166     Q_OBJECT
0167 public:
0168     explicit InputDeviceModel(QObject *parent = nullptr);
0169     ~InputDeviceModel() override;
0170 
0171     int columnCount(const QModelIndex &parent) const override;
0172     QVariant data(const QModelIndex &index, int role) const override;
0173     QModelIndex index(int row, int column, const QModelIndex &parent) const override;
0174     int rowCount(const QModelIndex &parent) const override;
0175     QModelIndex parent(const QModelIndex &child) const override;
0176 
0177 private Q_SLOTS:
0178     void slotPropertyChanged();
0179 
0180 private:
0181     void setupDeviceConnections(InputDevice *device);
0182     QList<InputDevice *> m_devices;
0183 };
0184 
0185 class DataSourceModel : public QAbstractItemModel
0186 {
0187 public:
0188     using QAbstractItemModel::QAbstractItemModel;
0189 
0190     QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
0191     QModelIndex parent(const QModelIndex &child) const override;
0192     int rowCount(const QModelIndex &parent) const override;
0193     int columnCount(const QModelIndex &parent) const override
0194     {
0195         return parent.isValid() ? 0 : 2;
0196     }
0197     QVariant data(const QModelIndex &index, int role) const override;
0198     QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
0199 
0200     void setSource(KWaylandServer::AbstractDataSource *source);
0201 
0202 private:
0203     KWaylandServer::AbstractDataSource *m_source = nullptr;
0204     QVector<QByteArray> m_data;
0205 };
0206 }