File indexing completed on 2024-12-01 05:02:29

0001 /*
0002     SPDX-FileCopyrightText: 2016 Smith AR <audoban@openmailbox.org>
0003     SPDX-FileCopyrightText: 2016 Michail Vourlakos <mvourlakos@gmail.com>
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef VIEW_H
0008 #define VIEW_H
0009 
0010 // local
0011 #include <coretypes.h>
0012 #include "containmentinterface.h"
0013 #include "effects.h"
0014 #include "parabolic.h"
0015 #include "positioner.h"
0016 #include "eventssink.h"
0017 #include "visibilitymanager.h"
0018 #include "indicator/indicator.h"
0019 #include "settings/primaryconfigview.h"
0020 #include "windowstracker/windowstracker.h"
0021 #include "../data/viewdata.h"
0022 #include "../shortcuts/globalshortcuts.h"
0023 #include "../layout/genericlayout.h"
0024 #include "../plasma/quick/containmentview.h"
0025 #include "../plasma/quick/configview.h"
0026 
0027 // C++
0028 #include <array>
0029 
0030 // Qt
0031 #include <QQuickView>
0032 #include <QMenu>
0033 #include <QMetaObject>
0034 #include <QMimeData>
0035 #include <QScreen>
0036 #include <QPointer>
0037 #include <QTimer>
0038 
0039 
0040 namespace Plasma {
0041 class Types;
0042 class Corona;
0043 class Containment;
0044 }
0045 
0046 namespace PlasmaQuick {
0047 class AppletQuickItem;
0048 }
0049 
0050 
0051 namespace KWayland {
0052 namespace Client {
0053 class PlasmaShellSurface;
0054 }
0055 }
0056 
0057 namespace Latte {
0058 class Corona;
0059 class Interfaces;
0060 class GenericLayout;
0061 }
0062 
0063 namespace Latte {
0064 
0065 class View : public PlasmaQuick::ContainmentView
0066 {
0067     Q_OBJECT
0068 
0069     Q_PROPERTY(int groupId READ groupId NOTIFY groupIdChanged)
0070     Q_PROPERTY(Latte::Types::ViewType type READ type WRITE setType NOTIFY typeChanged)
0071 
0072     Q_PROPERTY(bool alternativesIsShown READ alternativesIsShown NOTIFY alternativesIsShownChanged)
0073     Q_PROPERTY(bool behaveAsPlasmaPanel READ behaveAsPlasmaPanel WRITE setBehaveAsPlasmaPanel NOTIFY behaveAsPlasmaPanelChanged)
0074     Q_PROPERTY(bool byPassWM READ byPassWM WRITE setByPassWM NOTIFY byPassWMChanged)
0075     Q_PROPERTY(bool containsDrag READ containsDrag NOTIFY containsDragChanged)
0076     Q_PROPERTY(bool inSettingsAdvancedMode READ inSettingsAdvancedMode NOTIFY inSettingsAdvancedModeChanged)
0077 
0078     Q_PROPERTY(bool inEditMode READ inEditMode NOTIFY inEditModeChanged)
0079     Q_PROPERTY(bool isPreferredForShortcuts READ isPreferredForShortcuts WRITE setIsPreferredForShortcuts NOTIFY isPreferredForShortcutsChanged)
0080     Q_PROPERTY(bool onPrimary READ onPrimary WRITE setOnPrimary NOTIFY onPrimaryChanged)
0081     Q_PROPERTY(bool screenEdgeMarginEnabled READ screenEdgeMarginEnabled WRITE setScreenEdgeMarginEnabled NOTIFY screenEdgeMarginEnabledChanged)
0082 
0083     //! values to be used from Smart surrounding Views
0084     Q_PROPERTY(bool isTouchingBottomViewAndIsBusy READ isTouchingBottomViewAndIsBusy WRITE setIsTouchingBottomViewAndIsBusy NOTIFY isTouchingBottomViewAndIsBusyChanged)
0085     Q_PROPERTY(bool isTouchingTopViewAndIsBusy READ isTouchingTopViewAndIsBusy WRITE setIsTouchingTopViewAndIsBusy NOTIFY isTouchingTopViewAndIsBusyChanged)
0086 
0087     Q_PROPERTY(int alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged)
0088     Q_PROPERTY(int fontPixelSize READ fontPixelSize WRITE setFontPixelSize NOTIFY fontPixelSizeChanged)
0089     Q_PROPERTY(int x READ x NOTIFY xChanged)
0090     Q_PROPERTY(int y READ y NOTIFY yChanged)
0091     Q_PROPERTY(int width READ width NOTIFY widthChanged)
0092     Q_PROPERTY(int height READ height NOTIFY heightChanged)
0093     Q_PROPERTY(int editThickness READ editThickness NOTIFY editThicknessChanged)
0094     Q_PROPERTY(int maxThickness READ maxThickness WRITE setMaxThickness NOTIFY maxThicknessChanged)
0095     Q_PROPERTY(int normalThickness READ normalThickness WRITE setNormalThickness NOTIFY normalThicknessChanged)
0096     Q_PROPERTY(int maxNormalThickness READ maxNormalThickness WRITE setMaxNormalThickness NOTIFY maxNormalThicknessChanged)
0097     Q_PROPERTY(int headThicknessGap READ headThicknessGap WRITE setHeadThicknessGap NOTIFY headThicknessGapChanged)
0098     Q_PROPERTY(int screenEdgeMargin READ screenEdgeMargin WRITE setScreenEdgeMargin NOTIFY screenEdgeMarginChanged)
0099 
0100     Q_PROPERTY(float maxLength READ maxLength WRITE setMaxLength NOTIFY maxLengthChanged)
0101     Q_PROPERTY(float offset READ offset WRITE setOffset NOTIFY offsetChanged)
0102 
0103     Q_PROPERTY(QString name READ name NOTIFY nameChanged)
0104 
0105     Q_PROPERTY(QQuickItem *colorizer READ colorizer WRITE setColorizer NOTIFY colorizerChanged)
0106     Q_PROPERTY(QQuickItem *metrics READ metrics WRITE setMetrics NOTIFY metricsChanged)
0107 
0108     Q_PROPERTY(QVariantList containmentActions READ containmentActions NOTIFY containmentActionsChanged)
0109 
0110     Q_PROPERTY(Latte::Layout::GenericLayout *layout READ layout WRITE setLayout NOTIFY layoutChanged)
0111     Q_PROPERTY(Latte::ViewPart::Effects *effects READ effects NOTIFY effectsChanged)
0112     Q_PROPERTY(Latte::ViewPart::ContainmentInterface *extendedInterface READ extendedInterface NOTIFY extendedInterfaceChanged)
0113     Q_PROPERTY(Latte::ViewPart::Indicator *indicator READ indicator NOTIFY indicatorChanged)
0114     Q_PROPERTY(Latte::ViewPart::Parabolic *parabolic READ parabolic NOTIFY parabolicChanged)
0115     Q_PROPERTY(Latte::ViewPart::Positioner *positioner READ positioner NOTIFY positionerChanged)
0116     Q_PROPERTY(Latte::ViewPart::EventsSink *sink READ sink NOTIFY sinkChanged)
0117     Q_PROPERTY(Latte::ViewPart::VisibilityManager *visibility READ visibility NOTIFY visibilityChanged)
0118     Q_PROPERTY(Latte::ViewPart::WindowsTracker *windowsTracker READ windowsTracker NOTIFY windowsTrackerChanged)
0119 
0120     Q_PROPERTY(Latte::Interfaces *interfacesGraphicObj READ interfacesGraphicObj WRITE setInterfacesGraphicObj NOTIFY interfacesGraphicObjChanged)
0121 
0122     Q_PROPERTY(QRect absoluteGeometry READ absoluteGeometry NOTIFY absoluteGeometryChanged)
0123     Q_PROPERTY(QRect localGeometry READ localGeometry WRITE setLocalGeometry NOTIFY localGeometryChanged)
0124     Q_PROPERTY(QRect screenGeometry READ screenGeometry NOTIFY screenGeometryChanged)
0125 
0126 public:
0127     View(Plasma::Corona *corona, QScreen *targetScreen = nullptr, bool byPassX11WM = false);
0128     virtual ~View();
0129 
0130     void init(Plasma::Containment *plasma_containment = nullptr);
0131 
0132     Types::ViewType type() const;
0133     void setType(Types::ViewType type);
0134 
0135     bool alternativesIsShown() const;
0136     void setAlternativesIsShown(bool show);
0137 
0138     bool inDelete() const;
0139     bool inReadyState() const;
0140 
0141     bool onPrimary() const;
0142     void setOnPrimary(bool flag);
0143 
0144     bool behaveAsPlasmaPanel() const;
0145     void setBehaveAsPlasmaPanel(bool behavior);
0146 
0147     bool containsDrag() const;
0148     bool containsMouse() const;
0149 
0150     bool byPassWM() const;
0151     void setByPassWM(bool bypass);
0152 
0153     bool inEditMode() const;
0154 
0155     bool isFloatingPanel() const;
0156 
0157     virtual bool isPreferredForShortcuts() const;
0158     void setIsPreferredForShortcuts(bool preferred);
0159 
0160     bool inSettingsAdvancedMode() const;
0161 
0162     bool isTouchingBottomViewAndIsBusy() const;
0163     void setIsTouchingBottomViewAndIsBusy(bool touchAndBusy);
0164 
0165     bool isTouchingTopViewAndIsBusy() const;
0166     void setIsTouchingTopViewAndIsBusy(bool touchAndBusy);
0167 
0168     bool screenEdgeMarginEnabled() const;
0169     void setScreenEdgeMarginEnabled(bool enabled); 
0170 
0171     virtual int groupId() const;
0172 
0173     int fontPixelSize() const;
0174     void setFontPixelSize(int size);
0175 
0176     int editThickness() const;
0177 
0178     int maxThickness() const;
0179     void setMaxThickness(int thickness);
0180 
0181     int normalThickness() const;
0182     void setNormalThickness(int thickness);
0183 
0184     int maxNormalThickness() const;
0185     void setMaxNormalThickness(int thickness);
0186 
0187     int headThicknessGap() const;
0188     void setHeadThicknessGap(int thickness);
0189 
0190     int screenEdgeMargin() const;
0191     void setScreenEdgeMargin(int margin);
0192 
0193     int alignment() const;
0194     void setAlignment(int alignment);
0195 
0196     float maxLength() const;
0197     void setMaxLength(float length);
0198 
0199     float offset() const;
0200     void setOffset(float offset);
0201 
0202     QRect absoluteGeometry() const;
0203     QRect screenGeometry() const;
0204 
0205     QRect localGeometry() const;
0206     void setLocalGeometry(const QRect &geometry);
0207 
0208     QString validTitle() const;
0209 
0210     QString name() const;
0211     void setName(const QString &newname);
0212 
0213     bool isOnActivity(const QString &activity) const;
0214     bool isOnAllActivities() const;
0215 
0216     QStringList activities() const;
0217     void setActivities(const QStringList &ids);
0218 
0219     bool settingsWindowIsShown();
0220     void showSettingsWindow();
0221 
0222     QQuickItem *colorizer() const;
0223     void setColorizer(QQuickItem *colorizer);
0224 
0225     QQuickItem *metrics() const;
0226     void setMetrics(QQuickItem *metrics);
0227 
0228     virtual bool isCloned() const = 0; //means that this view is a clone of an original view
0229     virtual bool isOriginal() const = 0; //means that this view is an original view that can be autocloned to other screens
0230     virtual bool isSingle() const = 0; //means that this view is not related to clones and screen groups in any way
0231     virtual Latte::Types::ScreensGroup screensGroup() const = 0;
0232 
0233     QVariantList containmentActions() const;
0234 
0235     QQuickView *configView();
0236 
0237     virtual Latte::Data::View data() const;
0238 
0239     ViewPart::Effects *effects() const;   
0240     ViewPart::ContainmentInterface *extendedInterface() const;
0241     virtual ViewPart::Indicator *indicator() const;
0242     ViewPart::Parabolic *parabolic() const;
0243     ViewPart::Positioner *positioner() const;
0244     ViewPart::EventsSink *sink() const;
0245     ViewPart::VisibilityManager *visibility() const;
0246     ViewPart::WindowsTracker *windowsTracker() const;
0247 
0248     Latte::Interfaces *interfacesGraphicObj() const;
0249     void setInterfacesGraphicObj(Latte::Interfaces *ifaces);
0250 
0251     Layout::GenericLayout *layout() const;
0252     void setLayout(Layout::GenericLayout *layout);
0253 
0254     KWayland::Client::PlasmaShellSurface *surface();
0255 
0256     //! release grab and restore mouse state
0257     void unblockMouse(int x, int y);
0258 
0259     virtual void reconsiderScreen();
0260 
0261     //! these are signals that create crashes, such a example is the availableScreenRectChanged from corona
0262     //! when its containment is destroyed
0263     void disconnectSensitiveSignals();
0264 
0265     //! used from ViewSettingsFactory in order to move Configuration Windows to different View
0266     void releaseConfigView();
0267 
0268 public slots:
0269     Q_INVOKABLE void newView(const QString &templateFile);
0270     Q_INVOKABLE void removeView();
0271     Q_INVOKABLE void duplicateView();
0272     Q_INVOKABLE void exportTemplate();
0273 
0274     Q_INVOKABLE bool mimeContainsPlasmoid(QMimeData *mimeData, QString name);
0275 
0276     void updateAbsoluteGeometry(bool bypassChecks = false);
0277 
0278     Q_INVOKABLE bool isHighestPriorityView();
0279     Q_INVOKABLE QAction *action(const QString &name);
0280 
0281 protected slots:
0282     void showConfigurationInterface(Plasma::Applet *applet) override;
0283     void showWidgetExplorer(const QPointF &point);
0284 
0285 protected:
0286     bool event(QEvent *ev) override;
0287 
0288 signals:
0289     void eventTriggered(QEvent *ev);
0290     void mousePressed(const QPoint pos, const int button);
0291     void mouseReleased(const QPoint pos, const int button);
0292     void wheelScrolled(const QPoint pos, const QPoint angleDelta, const int buttons);
0293 
0294     void activitiesChanged();
0295     void alternativesIsShownChanged();
0296     void alignmentChanged();
0297     void behaveAsPlasmaPanelChanged();
0298     void byPassWMChanged();
0299     void colorizerChanged();
0300     void configWindowGeometryChanged(); // is called from config windows
0301     void containmentActionsChanged();
0302     void containsDragChanged();
0303     void dockLocationChanged();
0304     void editThicknessChanged();
0305     void effectsChanged();
0306     void extendedInterfaceChanged();
0307     void fontPixelSizeChanged();
0308     void forcedShown(); //[workaround] forced shown to avoid a KWin issue that hides windows when closing activities
0309     void geometryChanged();
0310     void groupIdChanged();
0311     void widthChanged();
0312     void headThicknessGapChanged();
0313     void heightChanged();
0314     void inEditModeChanged();
0315     void indicatorChanged();
0316     void inSettingsAdvancedModeChanged();
0317     void interfacesGraphicObjChanged();
0318     void isPreferredForShortcutsChanged();
0319     void isTouchingBottomViewAndIsBusyChanged();
0320     void isTouchingTopViewAndIsBusyChanged();
0321     void layoutChanged();
0322     void localGeometryChanged();
0323     void maxLengthChanged();
0324     void maxThicknessChanged();
0325     void metricsChanged();
0326     void normalThicknessChanged();
0327     void maxNormalThicknessChanged();
0328     void nameChanged();
0329     void offsetChanged();
0330     void onPrimaryChanged();
0331     void parabolicChanged();
0332     void positionerChanged();
0333     void screenEdgeMarginChanged();
0334     void screenEdgeMarginEnabledChanged();
0335     void screenGeometryChanged();
0336 
0337     void sinkChanged();
0338     void typeChanged();
0339     void visibilityChanged();
0340     void windowsTrackerChanged();
0341     void xChanged();
0342     void yChanged();
0343 
0344     void absoluteGeometryChanged(const QRect &geometry);
0345 
0346     void indicatorPluginChanged(const QString &indicatorId);
0347     void indicatorPluginRemoved(const QString &indicatorId);
0348     void userRequestedViewType(const int &type);
0349 
0350     //! are used to trigger the Corona relevant signals and in that
0351     //! way we can disable any such signaling all together, e.g. through disconnectSensitiveSignals()
0352     void availableScreenRectChangedFrom(Latte::View *origin);
0353     void availableScreenRegionChangedFrom(Latte::View *origin);
0354 
0355 protected:
0356     QPointer<Latte::Corona> m_corona;
0357 
0358 private slots:
0359     void applyActivitiesToWindows();
0360     void availableScreenRectChangedFromSlot(View *origin);
0361     void hideWindowsForSlidingOut();
0362     void preferredViewForShortcutsChangedSlot(Latte::View *view);
0363     void releaseGrab();
0364     void reloadSource();
0365     void updateTransientWindowsTracking();
0366     void statusChanged(Plasma::Types::ItemStatus);
0367 
0368     void addTransientWindow(QWindow *window);
0369     void removeTransientWindow(const bool &visible);
0370 
0371     //! workaround in order for top panels to be always on top
0372     void topViewAlwaysOnTop();
0373     void verticalUnityViewHasFocus();
0374 
0375     //!workround for when kwin hides view when an activity is closing
0376     void showHiddenViewFromActivityStopping();
0377 
0378     void restoreConfig();
0379     void saveConfig();
0380 
0381 private:
0382     void initSignalingForLocationChangeSliding();
0383     void setupWaylandIntegration();
0384     void updateAppletContainsMethod();
0385 
0386     void setContainsDrag(bool contains);
0387 
0388 private:
0389     Plasma::Containment *containmentById(uint id);
0390 
0391     bool m_alternativesIsShown{false};
0392     bool m_behaveAsPlasmaPanel{false};
0393     bool m_byPassWM{true};
0394     bool m_containsDrag{false};
0395     bool m_containsMouse{false};
0396     bool m_inDelete{false};
0397     bool m_isPreferredForShortcuts{false};
0398     bool m_onPrimary{true};
0399     bool m_screenEdgeMarginEnabled{false};
0400 
0401     bool m_isTouchingBottomViewAndIsBusy{false};
0402     bool m_isTouchingTopViewAndIsBusy{false};
0403 
0404     int m_fontPixelSize{ -1};
0405     int m_maxThickness{256};
0406     int m_normalThickness{256};
0407     int m_maxNormalThickness{256};
0408     int m_headThicknessGap{0};
0409     int m_screenEdgeMargin{-1};
0410     float m_maxLength{1};
0411     float m_offset{0};
0412 
0413     Types::Alignment m_alignment{Types::Center};
0414     Types::ViewType m_type{Types::DockView};
0415 
0416     QRect m_localGeometry;
0417     QRect m_absoluteGeometry;
0418 
0419     QString m_name;
0420 
0421     QStringList m_activities;
0422 
0423     //! HACK: In order to avoid crashes when the View is added and removed
0424     //! immediately during startup
0425     QTimer m_initLayoutTimer;
0426 
0427     //! HACK: Timers in order to handle KWin faulty
0428     //! behavior that hides Views when closing Activities
0429     //! with no actual reason
0430     QTimer m_visibleHackTimer1;
0431     QTimer m_visibleHackTimer2;
0432 
0433     QTimer m_releaseGrabTimer;
0434     int m_releaseGrab_x;
0435     int m_releaseGrab_y;
0436 
0437     Layout::GenericLayout *m_layout{nullptr};
0438 
0439     QQuickItem *m_colorizer{nullptr};
0440     QQuickItem *m_metrics{nullptr};
0441 
0442     QPointer<PlasmaQuick::ConfigView> m_appletConfigView;
0443     QPointer<ViewPart::PrimaryConfigView> m_primaryConfigView;
0444 
0445     QPointer<ViewPart::Effects> m_effects;
0446     QPointer<ViewPart::Indicator> m_indicator;
0447     QPointer<ViewPart::ContainmentInterface> m_interface;
0448     QPointer<ViewPart::Parabolic> m_parabolic;
0449     QPointer<ViewPart::Positioner> m_positioner;
0450     QPointer<ViewPart::EventsSink> m_sink;
0451     QPointer<ViewPart::VisibilityManager> m_visibility;
0452     QPointer<ViewPart::WindowsTracker> m_windowsTracker;
0453 
0454     QPointer<Latte::Interfaces> m_interfacesGraphicObj;
0455 
0456     //! Connections to release and bound for the assigned layout
0457     QList<QMetaObject::Connection> connectionsLayout;
0458 
0459     //! track transientWindows
0460     QList<QWindow *> m_transientWindows;
0461 
0462     KWayland::Client::PlasmaShellSurface *m_shellSurface{nullptr};
0463 };
0464 
0465 }
0466 
0467 #endif