1
0
mirror of https://github.com/KDE/latte-dock.git synced 2024-12-23 01:33:50 +03:00
latte-dock/app/view/positioner.h

201 lines
5.8 KiB
C
Raw Normal View History

/*
* 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
//local
#include <coretypes.h>
#include "../wm/windowinfowrap.h"
2018-12-02 03:05:52 +03:00
// Qt
#include <QObject>
#include <QPointer>
#include <QScreen>
#include <QTimer>
2018-12-02 03:05:52 +03:00
// Plasma
#include <Plasma/Containment>
namespace Plasma {
class Types;
}
namespace Latte {
class Corona;
class View;
}
namespace Latte {
namespace ViewPart {
class Positioner: public QObject
{
Q_OBJECT
Q_PROPERTY(bool inRelocationAnimation READ inRelocationAnimation NOTIFY inRelocationAnimationChanged)
Q_PROPERTY(bool inSlideAnimation READ inSlideAnimation WRITE setInSlideAnimation NOTIFY inSlideAnimationChanged)
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)
Q_PROPERTY(QRect canvasGeometry READ canvasGeometry NOTIFY canvasGeometryChanged)
//! animating window slide
Q_PROPERTY(int slideOffset READ slideOffset WRITE setSlideOffset NOTIFY slideOffsetChanged)
Q_PROPERTY(QString currentScreenName READ currentScreenName NOTIFY currentScreenChanged)
public:
Positioner(Latte::View *parent);
virtual ~Positioner();
2018-12-01 17:13:35 +03:00
int currentScreenId() const;
QString currentScreenName() const;
int slideOffset() const;
void setSlideOffset(int offset);
bool inLayoutUnloading();
bool inRelocationAnimation();
bool inSlideAnimation() const;
void setInSlideAnimation(bool active);
bool isCursorInsideView() const;
bool isStickedOnTopEdge() const;
void setIsStickedOnTopEdge(bool sticked);
bool isStickedOnBottomEdge() const;
void setIsStickedOnBottomEdge(bool sticked);
QRect canvasGeometry();
void setScreenToFollow(QScreen *scr, bool updateScreenId = true);
2018-12-01 17:13:35 +03:00
void reconsiderScreen();
2019-12-26 18:21:03 +03:00
Latte::WindowSystem::WindowId trackedWindowId();
public slots:
Q_INVOKABLE void setNextLocation(const QString layoutName, const QString screenId, int edge, int alignment);
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();
void initDelayedSignals();
void updateWaylandId();
signals:
void canvasGeometryChanged();
void currentScreenChanged();
void edgeChanged();
void screenGeometryChanged();
void slideOffsetChanged();
2019-04-12 18:55:45 +03:00
void windowSizeChanged();
//! 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 hidingForRelocationStarted();
void hidingForRelocationFinished();
void showingAfterRelocationFinished();
void onHideWindowsForSlidingOut();
void inRelocationAnimationChanged();
void inSlideAnimationChanged();
void isStickedOnTopEdgeChanged();
void isStickedOnBottomEdgeChanged();
private slots:
void onScreenChanged(QScreen *screen);
void onCurrentLayoutIsSwitching(const QString &layoutName);
void validateDockGeometry();
void updateInRelocationAnimation();
void syncLatteViews();
void updateContainmentScreen();
private:
void init();
void initSignalingForLocationChangeSliding();
void updateFormFactor();
void resizeWindow(QRect availableScreenRect = QRect());
void updatePosition(QRect availableScreenRect = QRect());
void updateCanvasGeometry(QRect availableScreenRect = QRect());
void validateTopBottomBorders(QRect availableScreenRect, QRegion availableScreenRegion);
void setCanvasGeometry(const QRect &geometry);
bool isLastHidingRelocationEvent() const;
QRect maximumNormalGeometry();
private:
bool m_inDelete{false};
bool m_inLayoutUnloading{false};
bool m_inRelocationAnimation{false};
bool m_inSlideAnimation{false};
bool m_isStickedOnTopEdge{false};
bool m_isStickedOnBottomEdge{false};
int m_slideOffset{0};
QRect m_canvasGeometry;
//! it is used in order to enforce X11 to never miss window geometry
QRect m_validGeometry;
//! it is used to update geometry calculations without requesting no needed Corona calculations
QRect m_lastAvailableScreenRect;
QRegion m_lastAvailableScreenRegion;
QPointer<Latte::View> m_view;
QPointer<Latte::Corona> m_corona;
2021-03-13 18:28:19 +03:00
QString m_screenNameToFollow;
QPointer<QScreen> m_screenToFollow;
QTimer m_screenSyncTimer;
2020-07-12 15:02:54 +03:00
QTimer m_syncGeometryTimer;
QTimer m_validateGeometryTimer;
//!used for relocation properties group
bool m_repositionFromViewSettingsWindow{false};
bool m_repositionIsAnimated{false};
QString m_nextLayoutName;
2021-04-12 00:14:42 +03:00
QString m_nextScreenName;
QScreen *m_nextScreen{nullptr};
2021-04-12 00:14:42 +03:00
Plasma::Types::Location m_nextScreenEdge{Plasma::Types::Floating};
Latte::Types::Alignment m_nextAlignment{Latte::Types::NoneAlignment};
Latte::WindowSystem::WindowId m_trackedWindowId;
};
}
}
#endif