File indexing completed on 2025-02-16 14:20:28
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 VIEW_H 0022 #define VIEW_H 0023 0024 // local 0025 #include "containmentinterface.h" 0026 #include "effects.h" 0027 #include "positioner.h" 0028 #include "visibilitymanager.h" 0029 #include "indicator/indicator.h" 0030 #include "settings/primaryconfigview.h" 0031 #include "windowstracker/windowstracker.h" 0032 #include "../shortcuts/globalshortcuts.h" 0033 #include "../layout/genericlayout.h" 0034 #include "../plasma/quick/containmentview.h" 0035 #include "../plasma/quick/configview.h" 0036 #include "../../liblatte2/types.h" 0037 0038 // C++ 0039 #include <array> 0040 0041 // Qt 0042 #include <QQuickView> 0043 #include <QMenu> 0044 #include <QMimeData> 0045 #include <QScreen> 0046 #include <QPointer> 0047 #include <QTimer> 0048 0049 namespace Plasma { 0050 class Types; 0051 class Corona; 0052 class Containment; 0053 } 0054 0055 namespace KWayland { 0056 namespace Client { 0057 class PlasmaShellSurface; 0058 } 0059 } 0060 0061 namespace Latte { 0062 class Corona; 0063 class GenericLayout; 0064 0065 namespace ViewPart { 0066 class ContextMenu; 0067 } 0068 } 0069 0070 namespace Latte { 0071 0072 class View : public PlasmaQuick::ContainmentView 0073 { 0074 Q_OBJECT 0075 0076 Q_PROPERTY(Latte::Types::ViewType type READ type WRITE setType NOTIFY typeChanged) 0077 0078 Q_PROPERTY(bool alternativesIsShown READ alternativesIsShown NOTIFY alternativesIsShownChanged) 0079 Q_PROPERTY(bool behaveAsPlasmaPanel READ behaveAsPlasmaPanel WRITE setBehaveAsPlasmaPanel NOTIFY behaveAsPlasmaPanelChanged) 0080 Q_PROPERTY(bool byPassWM READ byPassWM WRITE setByPassWM NOTIFY byPassWMChanged) 0081 Q_PROPERTY(bool containsDrag READ containsDrag NOTIFY containsDragChanged) 0082 Q_PROPERTY(bool contextMenuIsShown READ contextMenuIsShown NOTIFY contextMenuIsShownChanged) 0083 //! Because Latte uses animations, changing to edit mode it may be different than 0084 //! when the isUserConfiguring changes value 0085 Q_PROPERTY(bool inEditMode READ inEditMode WRITE setInEditMode NOTIFY inEditModeChanged) 0086 Q_PROPERTY(bool isPreferredForShortcuts READ isPreferredForShortcuts WRITE setIsPreferredForShortcuts NOTIFY isPreferredForShortcutsChanged) 0087 Q_PROPERTY(bool latteTasksArePresent READ latteTasksArePresent WRITE setLatteTasksArePresent NOTIFY latteTasksArePresentChanged) 0088 Q_PROPERTY(bool onPrimary READ onPrimary WRITE setOnPrimary NOTIFY onPrimaryChanged) 0089 0090 //! values to be used from Smart surrounding Views 0091 Q_PROPERTY(bool isTouchingBottomViewAndIsBusy READ isTouchingBottomViewAndIsBusy WRITE setIsTouchingBottomViewAndIsBusy NOTIFY isTouchingBottomViewAndIsBusyChanged) 0092 Q_PROPERTY(bool isTouchingTopViewAndIsBusy READ isTouchingTopViewAndIsBusy WRITE setIsTouchingTopViewAndIsBusy NOTIFY isTouchingTopViewAndIsBusyChanged) 0093 0094 Q_PROPERTY(int alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged) 0095 Q_PROPERTY(int fontPixelSize READ fontPixelSize WRITE setFontPixelSize NOTIFY fontPixelSizeChanged) 0096 Q_PROPERTY(int x READ x NOTIFY xChanged) 0097 Q_PROPERTY(int y READ y NOTIFY yChanged) 0098 Q_PROPERTY(int width READ width NOTIFY widthChanged) 0099 Q_PROPERTY(int height READ height NOTIFY heightChanged) 0100 Q_PROPERTY(int editThickness READ editThickness WRITE setEditThickness NOTIFY editThicknessChanged) 0101 Q_PROPERTY(int maxThickness READ maxThickness WRITE setMaxThickness NOTIFY maxThicknessChanged) 0102 Q_PROPERTY(int normalThickness READ normalThickness WRITE setNormalThickness NOTIFY normalThicknessChanged) 0103 Q_PROPERTY(int offset READ offset WRITE setOffset NOTIFY offsetChanged) 0104 0105 Q_PROPERTY(float maxLength READ maxLength WRITE setMaxLength NOTIFY maxLengthChanged) 0106 0107 Q_PROPERTY(Latte::Layout::GenericLayout *layout READ layout WRITE setLayout NOTIFY layoutChanged) 0108 Q_PROPERTY(Latte::ViewPart::Effects *effects READ effects NOTIFY effectsChanged) 0109 Q_PROPERTY(Latte::ViewPart::Indicator *indicator READ indicator NOTIFY indicatorChanged) 0110 Q_PROPERTY(Latte::ViewPart::Positioner *positioner READ positioner NOTIFY positionerChanged) 0111 Q_PROPERTY(Latte::ViewPart::VisibilityManager *visibility READ visibility NOTIFY visibilityChanged) 0112 Q_PROPERTY(Latte::ViewPart::WindowsTracker *windowsTracker READ windowsTracker NOTIFY windowsTrackerChanged) 0113 0114 Q_PROPERTY(QRect absoluteGeometry READ absoluteGeometry NOTIFY absoluteGeometryChanged) 0115 Q_PROPERTY(QRect localGeometry READ localGeometry WRITE setLocalGeometry NOTIFY localGeometryChanged) 0116 Q_PROPERTY(QRect screenGeometry READ screenGeometry NOTIFY screenGeometryChanged) 0117 0118 public: 0119 View(Plasma::Corona *corona, QScreen *targetScreen = nullptr, bool byPassWM = false); 0120 virtual ~View(); 0121 0122 void init(); 0123 0124 Types::ViewType type() const; 0125 void setType(Types::ViewType type); 0126 0127 bool alternativesIsShown() const; 0128 void setAlternativesIsShown(bool show); 0129 0130 bool inDelete() const; 0131 0132 bool onPrimary() const; 0133 void setOnPrimary(bool flag); 0134 0135 int currentThickness() const; 0136 0137 bool behaveAsPlasmaPanel() const; 0138 void setBehaveAsPlasmaPanel(bool behavior); 0139 0140 bool containsDrag() const; 0141 bool containsMouse() const; 0142 0143 bool contextMenuIsShown() const; 0144 0145 bool byPassWM() const; 0146 void setByPassWM(bool bypass); 0147 0148 bool inEditMode() const; 0149 void setInEditMode(bool edit); 0150 0151 bool isPreferredForShortcuts() const; 0152 void setIsPreferredForShortcuts(bool preferred); 0153 0154 bool latteTasksArePresent() const; 0155 void setLatteTasksArePresent(bool present); 0156 0157 bool isTouchingBottomViewAndIsBusy() const; 0158 void setIsTouchingBottomViewAndIsBusy(bool touchAndBusy); 0159 0160 bool isTouchingTopViewAndIsBusy() const; 0161 void setIsTouchingTopViewAndIsBusy(bool touchAndBusy); 0162 0163 float maxLength() const; 0164 void setMaxLength(float length); 0165 0166 int fontPixelSize() const; 0167 void setFontPixelSize(int size); 0168 0169 int editThickness() const; 0170 void setEditThickness(int thickness); 0171 0172 int maxThickness() const; 0173 void setMaxThickness(int thickness); 0174 0175 int normalThickness() const; 0176 void setNormalThickness(int thickness); 0177 0178 int offset() const; 0179 void setOffset(int offset); 0180 0181 int alignment() const; 0182 void setAlignment(int alignment); 0183 0184 QRect absoluteGeometry() const; 0185 QRect screenGeometry() const; 0186 0187 QRect localGeometry() const; 0188 void setLocalGeometry(const QRect &geometry); 0189 0190 bool isOnActivity(const QString &activity) const; 0191 bool isOnAllActivities() const; 0192 QStringList activities() const; 0193 0194 bool settingsWindowIsShown(); 0195 void showSettingsWindow(); 0196 0197 PlasmaQuick::ConfigView *configView(); 0198 0199 ViewPart::Effects *effects() const; 0200 ViewPart::Indicator *indicator() const; 0201 ViewPart::ContainmentInterface *interface() const; 0202 ViewPart::Positioner *positioner() const; 0203 ViewPart::VisibilityManager *visibility() const; 0204 ViewPart::WindowsTracker *windowsTracker() const; 0205 0206 Layout::GenericLayout *layout() const; 0207 void setLayout(Layout::GenericLayout *layout); 0208 0209 KWayland::Client::PlasmaShellSurface *surface(); 0210 0211 //! release grab and restore mouse state 0212 void unblockMouse(int x, int y); 0213 0214 void reconsiderScreen(); 0215 0216 //! these are signals that create crashes, such a example is the availableScreenRectChanged from corona 0217 //! when its containment is destroyed 0218 void disconnectSensitiveSignals(); 0219 0220 public slots: 0221 Q_INVOKABLE void copyView(); 0222 Q_INVOKABLE void removeView(); 0223 0224 Q_INVOKABLE QVariantList containmentActions(); 0225 0226 Q_INVOKABLE void deactivateApplets(); 0227 Q_INVOKABLE void moveToLayout(QString layoutName); 0228 Q_INVOKABLE void removeTasksPlasmoid(); 0229 Q_INVOKABLE void setBlockHiding(bool block); 0230 Q_INVOKABLE void toggleAppletExpanded(const int id); 0231 0232 Q_INVOKABLE bool appletIsExpandable(const int id); 0233 Q_INVOKABLE bool mimeContainsPlasmoid(QMimeData *mimeData, QString name); 0234 Q_INVOKABLE bool tasksPresent(); 0235 0236 void updateAbsoluteGeometry(bool bypassChecks = false); 0237 0238 Q_INVOKABLE bool isHighestPriorityView(); 0239 0240 protected slots: 0241 void showConfigurationInterface(Plasma::Applet *applet) override; 0242 0243 protected: 0244 bool event(QEvent *ev) override; 0245 void mousePressEvent(QMouseEvent *event) override; 0246 0247 signals: 0248 void eventTriggered(QEvent *ev); 0249 void mousePressed(const QPoint pos, const int button); 0250 void mouseReleased(const QPoint pos, const int button); 0251 0252 void activitiesChanged(); 0253 void alternativesIsShownChanged(); 0254 void alignmentChanged(); 0255 void behaveAsPlasmaPanelChanged(); 0256 void byPassWMChanged(); 0257 void configWindowGeometryChanged(); // is called from config windows 0258 void containsDragChanged(); 0259 void contextMenuIsShownChanged(); 0260 void dockLocationChanged(); 0261 void editThicknessChanged(); 0262 void effectsChanged(); 0263 void fontPixelSizeChanged(); 0264 void forcedShown(); //[workaround] forced shown to avoid a KWin issue that hides windows when closing activities 0265 void widthChanged(); 0266 void heightChanged(); 0267 void inEditModeChanged(); 0268 void indicatorChanged(); 0269 void isPreferredForShortcutsChanged(); 0270 void isTouchingBottomViewAndIsBusyChanged(); 0271 void isTouchingTopViewAndIsBusyChanged(); 0272 void latteTasksArePresentChanged(); 0273 void layoutChanged(); 0274 void localGeometryChanged(); 0275 void maxLengthChanged(); 0276 void maxThicknessChanged(); 0277 void normalThicknessChanged(); 0278 void offsetChanged(); 0279 void onPrimaryChanged(); 0280 void positionerChanged(); 0281 void screenGeometryChanged(); 0282 void typeChanged(); 0283 void visibilityChanged(); 0284 void windowsTrackerChanged(); 0285 void xChanged(); 0286 void yChanged(); 0287 0288 void absoluteGeometryChanged(const QRect &geometry); 0289 0290 void customPluginsChanged(); 0291 0292 //! are used to trigger the Corona relevant signals and in that 0293 //! way we can disable any such signaling all together, e.g. through disconnectSensitiveSignals() 0294 void availableScreenRectChangedFrom(Latte::View *origin); 0295 void availableScreenRegionChangedFrom(Latte::View *origin); 0296 0297 private slots: 0298 void availableScreenRectChangedFromSlot(View *origin); 0299 void configViewCreatedFor(Latte::View *view); 0300 void hideWindowsForSlidingOut(); 0301 void preferredViewForShortcutsChangedSlot(Latte::View *view); 0302 void releaseGrab(); 0303 void reloadSource(); 0304 void statusChanged(Plasma::Types::ItemStatus); 0305 0306 void restoreConfig(); 0307 void saveConfig(); 0308 0309 private: 0310 void applyActivitiesToWindows(); 0311 void initSignalingForLocationChangeSliding(); 0312 void setupWaylandIntegration(); 0313 void updateAppletContainsMethod(); 0314 0315 void setContainsDrag(bool contains); 0316 0317 private: 0318 Plasma::Containment *containmentById(uint id); 0319 0320 bool m_alternativesIsShown{false}; 0321 bool m_behaveAsPlasmaPanel{false}; 0322 bool m_byPassWM{true}; 0323 bool m_containsDrag{false}; 0324 bool m_containsMouse{false}; 0325 bool m_inDelete{false}; 0326 bool m_inEditMode{false}; 0327 bool m_isPreferredForShortcuts{false}; 0328 bool m_latteTasksArePresent{false}; 0329 bool m_onPrimary{true}; 0330 0331 bool m_isTouchingBottomViewAndIsBusy{false}; 0332 bool m_isTouchingTopViewAndIsBusy{false}; 0333 0334 int m_fontPixelSize{ -1}; 0335 int m_editThickness{24}; 0336 int m_maxThickness{24}; 0337 int m_normalThickness{24}; 0338 int m_offset{0}; 0339 float m_maxLength{1}; 0340 0341 Types::Alignment m_alignment{Types::Center}; 0342 Types::ViewType m_type{Types::DockView}; 0343 0344 QRect m_localGeometry; 0345 QRect m_absoluteGeometry; 0346 0347 QStringList m_activities; 0348 0349 //! HACK: Timers in order to handle KWin faulty 0350 //! behavior that hides Views when closing Activities 0351 //! with no actual reason 0352 QTimer m_visibleHackTimer1; 0353 QTimer m_visibleHackTimer2; 0354 0355 QTimer m_releaseGrabTimer; 0356 int m_releaseGrab_x; 0357 int m_releaseGrab_y; 0358 0359 Layout::GenericLayout *m_layout{nullptr}; 0360 QPointer<PlasmaQuick::ConfigView> m_configView; 0361 0362 QPointer<ViewPart::ContextMenu> m_contextMenu; 0363 QPointer<ViewPart::Effects> m_effects; 0364 QPointer<ViewPart::Indicator> m_indicator; 0365 QPointer<ViewPart::ContainmentInterface> m_interface; 0366 QPointer<ViewPart::Positioner> m_positioner; 0367 QPointer<ViewPart::VisibilityManager> m_visibility; 0368 QPointer<ViewPart::WindowsTracker> m_windowsTracker; 0369 0370 //! Connections to release and bound for the assigned layout 0371 QList<QMetaObject::Connection> connectionsLayout; 0372 0373 QPointer<Latte::Corona> m_corona; 0374 0375 KWayland::Client::PlasmaShellSurface *m_shellSurface{nullptr}; 0376 }; 0377 0378 } 0379 0380 #endif