File indexing completed on 2024-06-09 05:26:10

0001 /*
0002     KWin - the KDE window manager
0003     This file is part of the KDE project.
0004 
0005     SPDX-FileCopyrightText: 2010 Martin Gräßlin <mgraesslin@kde.org>
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 
0010 #pragma once
0011 #include "effect/effect.h"
0012 #include <KConfigWatcher>
0013 #include <KStartupInfo>
0014 #include <QObject>
0015 
0016 #include <chrono>
0017 
0018 class KSelectionOwner;
0019 namespace KWin
0020 {
0021 
0022 class GLShader;
0023 class GLTexture;
0024 
0025 class StartupFeedbackEffect
0026     : public Effect
0027 {
0028     Q_OBJECT
0029     Q_PROPERTY(int type READ type)
0030 public:
0031     StartupFeedbackEffect();
0032     ~StartupFeedbackEffect() override;
0033 
0034     void reconfigure(ReconfigureFlags flags) override;
0035     void prePaintScreen(ScreenPrePaintData &data, std::chrono::milliseconds presentTime) override;
0036     void paintScreen(const RenderTarget &renderTarget, const RenderViewport &viewport, int mask, const QRegion &region, Output *screen) override;
0037     void postPaintScreen() override;
0038     bool isActive() const override;
0039 
0040     int requestedEffectChainPosition() const override
0041     {
0042         return 90;
0043     }
0044 
0045     int type() const
0046     {
0047         return int(m_type);
0048     }
0049 
0050     static bool supported();
0051 
0052 private Q_SLOTS:
0053     void gotNewStartup(const QString &id, const QIcon &icon);
0054     void gotRemoveStartup(const QString &id);
0055     void gotStartupChange(const QString &id, const QIcon &icon);
0056     void slotMouseChanged(const QPointF &pos, const QPointF &oldpos, Qt::MouseButtons buttons, Qt::MouseButtons oldbuttons, Qt::KeyboardModifiers modifiers, Qt::KeyboardModifiers oldmodifiers);
0057 
0058 private:
0059     enum FeedbackType {
0060         NoFeedback,
0061         BouncingFeedback,
0062         BlinkingFeedback,
0063         PassiveFeedback
0064     };
0065 
0066     struct Startup
0067     {
0068         QIcon icon;
0069         std::shared_ptr<QTimer> expiredTimer;
0070     };
0071 
0072     void start(const Startup &startup);
0073     void stop();
0074     QImage scalePixmap(const QPixmap &pm, const QSize &size, qreal devicePixelRatio) const;
0075     void prepareTextures(const QPixmap &pix, qreal devicePixelRatio);
0076     QRect feedbackRect() const;
0077     QSize feedbackIconSize() const;
0078 
0079     qreal m_bounceSizesRatio;
0080     KStartupInfo *m_startupInfo;
0081     KSelectionOwner *m_selection;
0082     QString m_currentStartup;
0083     QMap<QString, Startup> m_startups;
0084     bool m_active;
0085     int m_frame;
0086     int m_progress;
0087     std::chrono::milliseconds m_lastPresentTime;
0088     std::unique_ptr<GLTexture> m_bouncingTextures[5];
0089     std::unique_ptr<GLTexture> m_texture; // for passive and blinking
0090     FeedbackType m_type;
0091     QRect m_currentGeometry, m_dirtyRect;
0092     std::unique_ptr<GLShader> m_blinkingShader;
0093     int m_cursorSize;
0094     KConfigWatcher::Ptr m_configWatcher;
0095     bool m_splashVisible;
0096     std::chrono::seconds m_timeout;
0097 };
0098 } // namespace