2018-11-29 22:30:00 +03:00
/*
* Copyright 2018 Michail Vourlakos < mvourlakos @ gmail . com >
*
* This file is part of Latte - Dock
*
* Latte - Dock is free software ; you can redistribute it and / or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation ; either version 2 of
* the License , or ( at your option ) any later version .
*
* Latte - Dock is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < http : //www.gnu.org/licenses/>.
*/
# ifndef POSITIONER_H
# define POSITIONER_H
2019-07-15 14:53:40 +03:00
//local
# include "../wm/windowinfowrap.h"
2018-12-02 03:05:52 +03:00
// Qt
2018-11-29 22:30:00 +03:00
# include <QObject>
# include <QPointer>
# include <QScreen>
# include <QTimer>
2018-12-02 03:05:52 +03:00
// Plasma
2018-11-29 22:30:00 +03:00
# include <Plasma/Containment>
namespace Plasma {
class Types ;
}
namespace Latte {
2019-07-15 14:53:40 +03:00
class Corona ;
2018-12-06 13:15:58 +03:00
class View ;
2018-11-29 22:30:00 +03:00
}
namespace Latte {
2018-12-06 12:37:14 +03:00
namespace ViewPart {
2018-11-29 22:30:00 +03:00
class Positioner : public QObject
{
Q_OBJECT
2021-01-19 22:14:09 +03:00
Q_PROPERTY ( bool inRelocationAnimation READ inRelocationAnimation NOTIFY inRelocationAnimationChanged )
2020-01-03 22:14:07 +03:00
Q_PROPERTY ( bool inSlideAnimation READ inSlideAnimation WRITE setInSlideAnimation NOTIFY inSlideAnimationChanged )
2020-01-03 17:17:02 +03:00
2020-03-01 00:28:22 +03:00
Q_PROPERTY ( bool isStickedOnTopEdge READ isStickedOnTopEdge WRITE setIsStickedOnTopEdge NOTIFY isStickedOnTopEdgeChanged )
Q_PROPERTY ( bool isStickedOnBottomEdge READ isStickedOnBottomEdge WRITE setIsStickedOnBottomEdge NOTIFY isStickedOnBottomEdgeChanged )
2018-12-01 17:13:35 +03:00
Q_PROPERTY ( int currentScreenId READ currentScreenId NOTIFY currentScreenChanged )
2021-02-27 21:00:00 +03:00
Q_PROPERTY ( QRect canvasGeometry READ canvasGeometry NOTIFY canvasGeometryChanged )
2020-01-02 18:06:50 +03:00
//! animating window slide
Q_PROPERTY ( int slideOffset READ slideOffset WRITE setSlideOffset NOTIFY slideOffsetChanged )
2018-12-01 16:22:33 +03:00
Q_PROPERTY ( QString currentScreenName READ currentScreenName NOTIFY currentScreenChanged )
2018-11-29 22:30:00 +03:00
public :
2018-12-06 13:15:58 +03:00
Positioner ( Latte : : View * parent ) ;
2018-11-29 22:30:00 +03:00
virtual ~ Positioner ( ) ;
2018-12-01 17:13:35 +03:00
int currentScreenId ( ) const ;
QString currentScreenName ( ) const ;
2018-11-29 22:30:00 +03:00
2020-01-02 18:06:50 +03:00
int slideOffset ( ) const ;
void setSlideOffset ( int offset ) ;
2020-08-30 14:34:56 +03:00
bool inLayoutUnloading ( ) ;
2021-01-19 22:14:09 +03:00
bool inRelocationAnimation ( ) ;
2020-01-03 17:17:02 +03:00
2020-01-03 22:14:07 +03:00
bool inSlideAnimation ( ) const ;
void setInSlideAnimation ( bool active ) ;
2020-12-24 20:27:11 +03:00
bool isCursorInsideView ( ) const ;
2020-03-01 00:28:22 +03:00
bool isStickedOnTopEdge ( ) const ;
void setIsStickedOnTopEdge ( bool sticked ) ;
bool isStickedOnBottomEdge ( ) const ;
void setIsStickedOnBottomEdge ( bool sticked ) ;
2020-07-09 09:20:33 +03:00
QRect canvasGeometry ( ) ;
2018-11-29 22:30:00 +03:00
void setScreenToFollow ( QScreen * scr , bool updateScreenId = true ) ;
2018-12-01 17:13:35 +03:00
void reconsiderScreen ( ) ;
2018-11-29 22:30:00 +03:00
2019-12-26 18:21:03 +03:00
Latte : : WindowSystem : : WindowId trackedWindowId ( ) ;
2018-11-29 22:30:00 +03:00
public slots :
Q_INVOKABLE void hideDockDuringLocationChange ( int goToLocation ) ;
Q_INVOKABLE void hideDockDuringMovingToLayout ( QString layoutName ) ;
Q_INVOKABLE bool setCurrentScreen ( const QString id ) ;
void syncGeometry ( ) ;
2020-07-12 15:22:01 +03:00
//! direct geometry calculations without any protections or checks
//! that might prevent them. It must be called with care.
void immediateSyncGeometry ( ) ;
2020-03-19 23:12:59 +03:00
void initDelayedSignals ( ) ;
2020-07-11 19:00:05 +03:00
void updateWaylandId ( ) ;
2020-03-19 23:12:59 +03:00
2018-11-29 22:30:00 +03:00
signals :
2020-07-09 09:20:33 +03:00
void canvasGeometryChanged ( ) ;
2018-11-29 22:30:00 +03:00
void currentScreenChanged ( ) ;
2019-05-09 23:45:52 +03:00
void edgeChanged ( ) ;
2018-11-29 22:30:00 +03:00
void screenGeometryChanged ( ) ;
2020-01-02 18:06:50 +03:00
void slideOffsetChanged ( ) ;
2019-04-12 18:55:45 +03:00
void windowSizeChanged ( ) ;
2018-11-29 22:30:00 +03:00
//! these two signals are used from config ui and containment ui
//! in order to orchestrate an animated hiding/showing of dock
//! during changing location
void hideDockDuringLocationChangeStarted ( ) ;
void hideDockDuringLocationChangeFinished ( ) ;
void hideDockDuringScreenChangeStarted ( ) ;
void hideDockDuringScreenChangeFinished ( ) ;
void hideDockDuringMovingToLayoutStarted ( ) ;
void hideDockDuringMovingToLayoutFinished ( ) ;
void showDockAfterLocationChangeFinished ( ) ;
void showDockAfterScreenChangeFinished ( ) ;
void showDockAfterMovingToLayoutFinished ( ) ;
2020-01-03 17:17:02 +03:00
void onHideWindowsForSlidingOut ( ) ;
2021-01-19 22:14:09 +03:00
void inRelocationAnimationChanged ( ) ;
2020-01-03 22:14:07 +03:00
void inSlideAnimationChanged ( ) ;
2020-03-01 00:28:22 +03:00
void isStickedOnTopEdgeChanged ( ) ;
void isStickedOnBottomEdgeChanged ( ) ;
2020-01-03 17:17:02 +03:00
2018-11-29 22:30:00 +03:00
private slots :
void screenChanged ( QScreen * screen ) ;
2020-08-03 00:29:59 +03:00
void onCurrentLayoutIsSwitching ( const QString & layoutName ) ;
2018-11-29 22:30:00 +03:00
void validateDockGeometry ( ) ;
2021-01-19 22:14:09 +03:00
void updateInRelocationAnimation ( ) ;
2020-03-07 19:30:22 +03:00
void syncLatteViews ( ) ;
void updateContainmentScreen ( ) ;
2018-11-29 22:30:00 +03:00
private :
void init ( ) ;
void initSignalingForLocationChangeSliding ( ) ;
2018-12-01 01:13:11 +03:00
void updateFormFactor ( ) ;
2020-07-09 09:20:33 +03:00
void resizeWindow ( QRect availableScreenRect = QRect ( ) ) ;
2018-11-29 22:30:00 +03:00
void updatePosition ( QRect availableScreenRect = QRect ( ) ) ;
2020-07-09 09:20:33 +03:00
void updateCanvasGeometry ( QRect availableScreenRect = QRect ( ) ) ;
2018-11-29 22:30:00 +03:00
2020-03-02 19:44:40 +03:00
void validateTopBottomBorders ( QRect availableScreenRect , QRegion availableScreenRegion ) ;
2020-07-09 09:20:33 +03:00
void setCanvasGeometry ( const QRect & geometry ) ;
2018-11-29 22:30:00 +03:00
QRect maximumNormalGeometry ( ) ;
private :
bool m_inDelete { false } ;
2020-08-30 14:34:56 +03:00
bool m_inLayoutUnloading { false } ;
2021-01-19 22:14:09 +03:00
bool m_inRelocationAnimation { false } ;
2020-01-03 22:14:07 +03:00
bool m_inSlideAnimation { false } ;
2018-11-29 22:30:00 +03:00
2020-03-01 00:28:22 +03:00
bool m_isStickedOnTopEdge { false } ;
bool m_isStickedOnBottomEdge { false } ;
2020-01-02 18:06:50 +03:00
int m_slideOffset { 0 } ;
2020-07-09 09:20:33 +03:00
QRect m_canvasGeometry ;
2018-11-29 22:30:00 +03:00
//! it is used in order to enforce X11 to never miss window geometry
QRect m_validGeometry ;
2020-07-11 17:13:16 +03:00
//! it is used to update geometry calculations without requesting no needed Corona calculations
QRect m_lastAvailableScreenRect ;
QRegion m_lastAvailableScreenRegion ;
2018-11-29 22:30:00 +03:00
2018-12-06 13:15:58 +03:00
QPointer < Latte : : View > m_view ;
2019-07-15 14:53:40 +03:00
QPointer < Latte : : Corona > m_corona ;
2018-11-29 22:30:00 +03:00
QString m_screenToFollowId ;
QPointer < QScreen > m_screenToFollow ;
QTimer m_screenSyncTimer ;
2020-07-12 15:02:54 +03:00
QTimer m_syncGeometryTimer ;
2018-11-29 22:30:00 +03:00
QTimer m_validateGeometryTimer ;
//!used at sliding out/in animation
QString m_moveToLayout ;
Plasma : : Types : : Location m_goToLocation { Plasma : : Types : : Floating } ;
QScreen * m_goToScreen { nullptr } ;
2019-07-15 14:53:40 +03:00
2019-07-16 13:23:20 +03:00
Latte : : WindowSystem : : WindowId m_trackedWindowId ;
2018-11-29 22:30:00 +03:00
} ;
2018-12-01 01:13:11 +03:00
}
2018-11-29 22:30:00 +03:00
}
# endif