File indexing completed on 2024-04-28 16:54:58

0001 /*
0002     SPDX-FileCopyrightText: 2013 Marco Martin <mart@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include <optional>
0010 
0011 #include <PlasmaQuick/ConfigView>
0012 #include <PlasmaQuick/ContainmentView>
0013 #include <QPointer>
0014 
0015 #include <KConfigWatcher>
0016 
0017 namespace KWayland
0018 {
0019 namespace Client
0020 {
0021 class PlasmaShellSurface;
0022 }
0023 }
0024 
0025 class DesktopView : public PlasmaQuick::ContainmentView
0026 {
0027     Q_OBJECT
0028 
0029     Q_PROPERTY(WindowType windowType READ windowType WRITE setWindowType NOTIFY windowTypeChanged)
0030 
0031     // What kind of plasma session we're in: are we in a full workspace, an application?...
0032     Q_PROPERTY(SessionType sessionType READ sessionType CONSTANT)
0033 
0034     Q_PROPERTY(QVariantMap candidateContainments READ candidateContainmentsGraphicItems NOTIFY candidateContainmentsChanged)
0035 
0036     /**
0037      * Whether the desktop is used in accent color extraction
0038      *
0039      * @note When usedInAccentColor becomes @c true, \Kirigami.ImageColors
0040      * will be loaded and update the accent color, and \setAccentColor will
0041      * be called
0042      */
0043     Q_PROPERTY(bool usedInAccentColor READ usedInAccentColor NOTIFY usedInAccentColorChanged)
0044 
0045     Q_PROPERTY(QColor accentColor READ accentColor WRITE setAccentColor RESET resetAccentColor NOTIFY accentColorChanged)
0046 
0047 public:
0048     enum WindowType {
0049         Window, /** The window is a normal resizable window with titlebar and appears in the taskbar */
0050         FullScreen, /** The window is fullscreen and goes over all the other windows */
0051         Desktop, /** The window is the desktop layer, under everything else, doesn't appear in the taskbar */
0052         WindowedDesktop, /** full screen and borderless as Desktop, but can be brought in front and appears in the taskbar */
0053     };
0054     Q_ENUM(WindowType)
0055 
0056     enum SessionType {
0057         ApplicationSession, /** our session is a normal application */
0058         ShellSession, /** We are running as the primary user interface of this machine */
0059     };
0060     Q_ENUM(SessionType)
0061 
0062     explicit DesktopView(Plasma::Corona *corona, QScreen *targetScreen = nullptr);
0063     ~DesktopView() override;
0064 
0065     /*This is different from screen() as is always there, even if the window is
0066       temporarily outside the screen or if is hidden: only plasmashell will ever
0067       change this property, unlike QWindow::screen()*/
0068     void setScreenToFollow(QScreen *screen);
0069     QScreen *screenToFollow() const;
0070 
0071     void adaptToScreen();
0072     void showEvent(QShowEvent *) override;
0073 
0074     bool usedInAccentColor() const;
0075 
0076     QColor accentColor() const;
0077     void setAccentColor(const QColor &);
0078     void resetAccentColor();
0079 
0080     WindowType windowType() const;
0081     void setWindowType(WindowType type);
0082 
0083     SessionType sessionType() const;
0084 
0085     QVariantMap candidateContainmentsGraphicItems() const;
0086 
0087     Q_INVOKABLE QString fileFromPackage(const QString &key, const QString &fileName);
0088 
0089 protected:
0090     bool event(QEvent *e) override;
0091     void keyPressEvent(QKeyEvent *e) override;
0092 
0093 protected Q_SLOTS:
0094     /**
0095      * It will be called when the configuration is requested
0096      */
0097     void showConfigurationInterface(Plasma::Applet *applet) override;
0098 
0099 private Q_SLOTS:
0100     void slotContainmentChanged();
0101     void slotScreenChanged(int newId);
0102     void screenGeometryChanged();
0103 
0104 Q_SIGNALS:
0105     void stayBehindChanged();
0106     void windowTypeChanged();
0107     void candidateContainmentsChanged();
0108     void geometryChanged();
0109     void usedInAccentColorChanged();
0110     void accentColorChanged(const QColor &accentColor);
0111 
0112 private:
0113     void coronaPackageChanged(const KPackage::Package &package);
0114     void ensureWindowType();
0115     void setupWaylandIntegration();
0116     void setAccentColorFromWallpaper(const QColor &accentColor);
0117     bool handleKRunnerTextInput(QKeyEvent *e);
0118 
0119     std::optional<QColor> m_accentColor;
0120     QPointer<PlasmaQuick::ConfigView> m_configView;
0121     QPointer<QScreen> m_screenToFollow;
0122     WindowType m_windowType;
0123     KWayland::Client::PlasmaShellSurface *m_shellSurface;
0124     QString m_krunnerText;
0125 
0126     // KRunner config
0127     KConfigWatcher::Ptr m_configWatcher;
0128     bool m_activateKRunnerWhenTypingOnDesktop;
0129 
0130     // Accent color config
0131     Plasma::Containment *m_containment = nullptr;
0132     int m_containmentScreenId = -1;
0133 };