File indexing completed on 2024-04-28 05:30:15

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