File indexing completed on 2024-05-05 05:38:21

0001 /*
0002     SPDX-FileCopyrightText: 2023 David Edmundson <davidedmundson@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef X11WINDOWSCREENRELATIVEPOSITIONER_H
0008 #define X11WINDOWSCREENRELATIVEPOSITIONER_H
0009 
0010 #include <QMargins>
0011 #include <QObject>
0012 #include <QPointer>
0013 #include <QWindow>
0014 
0015 /**
0016  * This class positions a window relative to screen edges, keeping the position
0017  * in sync with screen and window size changes.
0018  *
0019  * Position changes will apply just before the next frame
0020  *
0021  */
0022 class X11WindowScreenRelativePositioner : public QObject
0023 {
0024     Q_OBJECT
0025 public:
0026     /**
0027      * Construct a new X11WindowScreenRelativePositioner for the window
0028      * The created object is parented to the window
0029      */
0030     explicit X11WindowScreenRelativePositioner(QWindow *window);
0031 
0032     /**
0033      * @brief setAnchors
0034      * @param anchors
0035      */
0036     void setAnchors(Qt::Edges anchors);
0037     void setMargins(const QMargins &margins);
0038 
0039     bool eventFilter(QObject *watched, QEvent *event) override;
0040 
0041 Q_SIGNALS:
0042     void anchorsChanged();
0043     void marginsChanged();
0044 
0045 private:
0046     void polish();
0047     void updatePolish();
0048     void reposition();
0049     void handleScreenChanged();
0050 
0051     Qt::Edges m_anchors;
0052     QMargins m_margins;
0053 
0054     bool m_needsRepositioning;
0055     QWindow *m_window;
0056     QPointer<QScreen> m_screen;
0057 };
0058 
0059 #endif // X11WINDOWSCREENRELATIVEPOSITIONER_H