File indexing completed on 2024-06-16 14:04:38

0001 /*
0002 *  Copyright 2018 Michail Vourlakos <mvourlakos@gmail.com>
0003 *
0004 *  This file is part of Latte-Dock
0005 *
0006 *  Latte-Dock is free software; you can redistribute it and/or
0007 *  modify it under the terms of the GNU General Public License as
0008 *  published by the Free Software Foundation; either version 2 of
0009 *  the License, or (at your option) any later version.
0010 *
0011 *  Latte-Dock is distributed in the hope that it will be useful,
0012 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0013 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014 *  GNU General Public License for more details.
0015 *
0016 *  You should have received a copy of the GNU General Public License
0017 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
0018 */
0019 
0020 #ifndef SCREENEDGEGHOSTWINDOW_H
0021 #define SCREENEDGEGHOSTWINDOW_H
0022 
0023 // local
0024 #include "../lattecorona.h"
0025 #include "../wm/windowinfowrap.h"
0026 
0027 // Qt
0028 #include <QObject>
0029 #include <QQuickView>
0030 #include <QTimer>
0031 
0032 namespace KWayland {
0033 namespace Client {
0034 class PlasmaShellSurface;
0035 }
0036 }
0037 
0038 namespace Latte {
0039 class Corona;
0040 class View;
0041 }
0042 
0043 namespace Latte {
0044 namespace ViewPart {
0045 
0046 //! What is the importance of this class?
0047 //!
0048 //! Plasma is activating the screen edges for the main panel window
0049 //! unfortunately this isn't possible for the Latte case.
0050 //! When a window is hidden at an edge it becomes NOT visible
0051 //! unfortunately that means that all the animations are
0052 //! stopped (Qt behaviour) and that creates confusion to the user after the window
0053 //! reappears because various animations are played (adding-removing tasks/launchers)
0054 //! that aren't relevant any more.
0055 //!
0056 //! In order to workaround the above behaviour Latte is using a
0057 //! fake window to communicate with KWin and the MAIN Latte::View window
0058 //! continues to use only mask technique to hide
0059 //!
0060 //! KDE BUGS: https://bugs.kde.org/show_bug.cgi?id=382219
0061 //!           https://bugs.kde.org/show_bug.cgi?id=392464
0062 
0063 class ScreenEdgeGhostWindow : public QQuickView
0064 {
0065     Q_OBJECT
0066 
0067 public:
0068     ScreenEdgeGhostWindow(Latte::View *view);
0069     ~ScreenEdgeGhostWindow() override;
0070 
0071     bool containsMouse() const;
0072 
0073     int location();
0074 
0075     void hideWithMask();
0076     void showWithMask();
0077 
0078     Latte::View *parentView();
0079 
0080     KWayland::Client::PlasmaShellSurface *surface();
0081 
0082 signals:
0083     void containsMouseChanged(bool contains);
0084     void dragEntered();
0085     void forcedShown(); //[workaround] forced shown to avoid a KWin issue that hides windows when activities are stopped
0086 
0087 protected:
0088     bool event(QEvent *ev) override;
0089 
0090 private slots:
0091     void startGeometryTimer();
0092     void updateGeometry();
0093     void fixGeometry();
0094 
0095 private:
0096     void setContainsMouse(bool contains);
0097     void setupWaylandIntegration();
0098 
0099 private:
0100     bool m_delayedContainsMouse{false};
0101     bool m_containsMouse{false};
0102     bool m_inDelete{false};
0103     QRect m_calculatedGeometry;
0104 
0105     QTimer m_delayedMouseTimer;
0106     QTimer m_fixGeometryTimer;
0107 
0108     //! HACK: Timers in order to handle KWin faulty
0109     //! behavior that hides Views when closing Activities
0110     //! with no actual reason
0111     QTimer m_visibleHackTimer1;
0112     QTimer m_visibleHackTimer2;
0113     //! Connections for the KWin visibility hack
0114     QList<QMetaObject::Connection> connectionsHack;
0115 
0116     Latte::View *m_latteView{nullptr};
0117 
0118     QPointer<Latte::Corona> m_corona;
0119 
0120     Latte::WindowSystem::WindowId m_trackedWindowId;
0121     KWayland::Client::PlasmaShellSurface *m_shellSurface{nullptr};
0122 };
0123 
0124 }
0125 }
0126 #endif