File indexing completed on 2024-04-28 16:49:27

0001 /*
0002 *  Copyright 2016  Smith AR <audoban@openmailbox.org>
0003 *                  Michail Vourlakos <mvourlakos@gmail.com>
0004 *
0005 *  This file is part of Latte-Dock
0006 *
0007 *  Latte-Dock is free software; you can redistribute it and/or
0008 *  modify it under the terms of the GNU General Public License as
0009 *  published by the Free Software Foundation; either version 2 of
0010 *  the License, or (at your option) any later version.
0011 *
0012 *  Latte-Dock is distributed in the hope that it will be useful,
0013 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0014 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0015 *  GNU General Public License for more details.
0016 *
0017 *  You should have received a copy of the GNU General Public License
0018 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
0019 */
0020 
0021 #ifndef PRIMARYCONFIGVIEW_H
0022 #define PRIMARYCONFIGVIEW_H
0023 
0024 // local
0025 #include "../../plasma/quick/configview.h"
0026 #include "../../wm/windowinfowrap.h"
0027 #include "../../../liblatte2/types.h"
0028 
0029 //Qt
0030 #include <QObject>
0031 #include <QPointer>
0032 #include <QTimer>
0033 #include <QWindow>
0034 
0035 // Plasma
0036 #include <plasma/package.h>
0037 #include <Plasma/FrameSvg>
0038 
0039 namespace Plasma {
0040 class Applet;
0041 class Containment;
0042 class FrameSvg;
0043 class Types;
0044 }
0045 
0046 namespace KWayland {
0047 namespace Client {
0048 class PlasmaShellSurface;
0049 }
0050 }
0051 
0052 namespace Latte {
0053 class Corona;
0054 class View;
0055 }
0056 
0057 namespace Latte {
0058 namespace ViewPart {
0059 class SecondaryConfigView;
0060 }
0061 }
0062 
0063 namespace Latte {
0064 namespace ViewPart {
0065 
0066 class PrimaryConfigView : public PlasmaQuick::ConfigView
0067 {
0068     Q_OBJECT
0069     //! used when the secondary config window can not be shown
0070     Q_PROPERTY(bool showInlineProperties READ showInlineProperties NOTIFY showInlinePropertiesChanged)
0071 
0072     Q_PROPERTY(int complexity READ complexity WRITE setComplexity NOTIFY complexityChanged)
0073 
0074     Q_PROPERTY(QRect availableScreenGeometry READ availableScreenGeometry NOTIFY availableScreenGeometryChanged)
0075 
0076     Q_PROPERTY(Plasma::FrameSvg::EnabledBorders enabledBorders READ enabledBorders NOTIFY enabledBordersChanged)
0077 
0078 public:
0079     enum ConfigViewType
0080     {
0081         PrimaryConfig = 0,
0082         SecondaryConfig
0083     };
0084 
0085     PrimaryConfigView(Plasma::Containment *containment, Latte::View *view, QWindow *parent = nullptr);
0086     ~PrimaryConfigView() override;
0087 
0088     void init() override;
0089     void requestActivate();
0090 
0091     Qt::WindowFlags wFlags() const;
0092 
0093     bool showInlineProperties() const;
0094     bool sticker() const;
0095 
0096     int complexity() const;
0097     void setComplexity(int complexity);
0098 
0099     QRect availableScreenGeometry() const;
0100     QRect geometryWhenVisible() const;
0101 
0102     Plasma::FrameSvg::EnabledBorders enabledBorders() const;
0103 
0104     QQuickView *secondaryWindow();
0105 
0106 public slots:
0107     Q_INVOKABLE void hideConfigWindow();
0108     Q_INVOKABLE void setSticker(bool blockFocusLost);
0109     Q_INVOKABLE void syncGeometry();
0110     Q_INVOKABLE void updateLaunchersForGroup(int groupInt);
0111     Q_INVOKABLE void updateEffects();
0112 
0113 signals:
0114     void availableScreenGeometryChanged();
0115     void complexityChanged();
0116     void enabledBordersChanged();
0117     void raiseDocksTemporaryChanged();
0118     void showInlinePropertiesChanged();
0119     void showSignal();
0120 
0121 protected:
0122     void showEvent(QShowEvent *ev) override;
0123     void hideEvent(QHideEvent *ev) override;
0124     void focusOutEvent(QFocusEvent *ev) override;
0125     bool event(QEvent *e) override;
0126 
0127     void syncSlideEffect();
0128 
0129 private slots:
0130     void immutabilityChanged(Plasma::Types::ImmutabilityType type);
0131     void updateAvailableScreenGeometry(View *origin = nullptr);
0132     void updateEnabledBorders();
0133     void updateShowInlineProperties();
0134 
0135     void createSecondaryWindow();
0136     void deleteSecondaryWindow();
0137 
0138     void setShowInlineProperties(bool show);
0139 
0140     void loadConfig();
0141     void saveConfig();
0142 
0143 private:
0144     void setupWaylandIntegration();
0145 
0146     bool m_blockFocusLost{false};
0147     bool m_blockFocusLostOnStartup{true};
0148     bool m_originalByPassWM{false};
0149     bool m_inReverse{false};    //! it is used by the borders
0150     bool m_showInlineProperties{false};
0151 
0152     Latte::Types::Visibility m_originalMode{Latte::Types::DodgeActive};
0153     Latte::Types::SettingsComplexity m_complexity{Latte::Types::BasicSettings};
0154 
0155     QRect m_availableScreenGeometry;
0156     QRect m_geometryWhenVisible;
0157 
0158     QPointer<Latte::View> m_latteView;
0159     QPointer<SecondaryConfigView> m_secConfigView;
0160     QTimer m_screenSyncTimer;
0161     QTimer m_thicknessSyncTimer;
0162     QList<QMetaObject::Connection> connections;
0163 
0164     Plasma::FrameSvg::EnabledBorders m_enabledBorders{Plasma::FrameSvg::AllBorders};
0165 
0166     //only for the mask on disabled compositing, not to actually paint
0167     Plasma::FrameSvg *m_background{nullptr};
0168 
0169     Latte::Corona *m_corona{nullptr};
0170     Latte::WindowSystem::WindowId m_waylandWindowId;
0171     KWayland::Client::PlasmaShellSurface *m_shellSurface{nullptr};
0172 };
0173 
0174 }
0175 }
0176 #endif //PRIMARYCONFIGVIEW_H
0177