7292af3d04
With fractional scaling integer based logical geometry may not match device pixels. Once we have a floating point base we can fix that. This also is important for our X11 scale override, with a scale of 2 we could get logical sizes with halves. We already have all input being floating point, this doubles down on it for all remaining geometry. - Outputs remain integer to ensure that any screen on the right remains aligned. - Placement also remains integer based for now. - Repainting is untouched as we always expand outwards (QRectF::toAdjustedRect(). - Decoration is untouched for now - Rules are integer in the config, but floating in the adjusting/API This should also be fine. At some point we'll add a method to snap to the device pixel grid. Effectively `round(value * dpr) / dpr` though right now things mostly work. This also gets rid of a lot of hacks for QRect right and bottom which are very confusing. Parts to watch out in the port are: QRectF::contains now includes edges QRectF::right and bottom are now sane so previous hacks have to be removed QRectF(QPoint, QPoint) behaves differently for the same reason QRectF::center too In test results some adjusted values which are the result of QRect.center because using QRectF's center should behave the same to the user.
155 lines
3.9 KiB
C++
155 lines
3.9 KiB
C++
/*
|
|
SPDX-FileCopyrightText: 2021 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
|
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "kwineffects.h"
|
|
#include "kwinglobals.h"
|
|
|
|
#include <QMatrix4x4>
|
|
#include <QObject>
|
|
|
|
#include <optional>
|
|
|
|
namespace KWin
|
|
{
|
|
|
|
class Output;
|
|
|
|
/**
|
|
* The Item class is the base class for items in the scene.
|
|
*/
|
|
class KWIN_EXPORT Item : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
explicit Item(Item *parent = nullptr);
|
|
~Item() override;
|
|
|
|
qreal opacity() const;
|
|
void setOpacity(qreal opacity);
|
|
|
|
QPointF position() const;
|
|
void setPosition(const QPointF &point);
|
|
|
|
QSizeF size() const;
|
|
void setSize(const QSizeF &size);
|
|
|
|
int z() const;
|
|
void setZ(int z);
|
|
|
|
/**
|
|
* Returns the enclosing rectangle of the item. The rect equals QRect(0, 0, width(), height()).
|
|
*/
|
|
QRectF rect() const;
|
|
/**
|
|
* Returns the enclosing rectangle of the item and all of its descendants.
|
|
*/
|
|
QRectF boundingRect() const;
|
|
|
|
virtual QRegion shape() const;
|
|
virtual QRegion opaque() const;
|
|
|
|
/**
|
|
* Returns the visual parent of the item. Note that the visual parent differs from
|
|
* the QObject parent.
|
|
*/
|
|
Item *parentItem() const;
|
|
void setParentItem(Item *parent);
|
|
QList<Item *> childItems() const;
|
|
QList<Item *> sortedChildItems() const;
|
|
|
|
QPointF rootPosition() const;
|
|
|
|
QMatrix4x4 transform() const;
|
|
void setTransform(const QMatrix4x4 &transform);
|
|
|
|
/**
|
|
* Maps the given @a region from the item's coordinate system to the scene's coordinate
|
|
* system.
|
|
*/
|
|
QRegion mapToGlobal(const QRegion ®ion) const;
|
|
/**
|
|
* Maps the given @a rect from the item's coordinate system to the scene's coordinate
|
|
* system.
|
|
*/
|
|
QRectF mapToGlobal(const QRectF &rect) const;
|
|
/**
|
|
* Maps the given @a rect from the scene's coordinate system to the item's coordinate
|
|
* system.
|
|
*/
|
|
QRectF mapFromGlobal(const QRectF &rect) const;
|
|
|
|
/**
|
|
* Moves this item right before the specified @a sibling in the parent's children list.
|
|
*/
|
|
void stackBefore(Item *sibling);
|
|
/**
|
|
* Moves this item right after the specified @a sibling in the parent's children list.
|
|
*/
|
|
void stackAfter(Item *sibling);
|
|
|
|
bool explicitVisible() const;
|
|
bool isVisible() const;
|
|
void setVisible(bool visible);
|
|
|
|
void scheduleRepaint(const QRectF ®ion);
|
|
void scheduleRepaint(const QRegion ®ion);
|
|
void scheduleFrame();
|
|
QRegion repaints(Output *output) const;
|
|
void resetRepaints(Output *output);
|
|
|
|
WindowQuadList quads() const;
|
|
virtual void preprocess();
|
|
|
|
Q_SIGNALS:
|
|
/**
|
|
* This signal is emitted when the position of this item has changed.
|
|
*/
|
|
void positionChanged();
|
|
/**
|
|
* This signal is emitted when the size of this item has changed.
|
|
*/
|
|
void sizeChanged();
|
|
|
|
/**
|
|
* This signal is emitted when the rectangle that encloses this item and all of its children
|
|
* has changed.
|
|
*/
|
|
void boundingRectChanged();
|
|
|
|
protected:
|
|
virtual WindowQuadList buildQuads() const;
|
|
void discardQuads();
|
|
|
|
private:
|
|
void addChild(Item *item);
|
|
void removeChild(Item *item);
|
|
void updateBoundingRect();
|
|
void scheduleRepaintInternal(const QRegion ®ion);
|
|
void markSortedChildItemsDirty();
|
|
|
|
bool computeEffectiveVisibility() const;
|
|
void updateEffectiveVisibility();
|
|
void removeRepaints(Output *output);
|
|
|
|
QPointer<Item> m_parentItem;
|
|
QList<Item *> m_childItems;
|
|
QMatrix4x4 m_transform;
|
|
QRectF m_boundingRect;
|
|
QPointF m_position;
|
|
QSizeF m_size = QSize(0, 0);
|
|
qreal m_opacity = 1;
|
|
int m_z = 0;
|
|
bool m_explicitVisible = true;
|
|
bool m_effectiveVisible = true;
|
|
QMap<Output *, QRegion> m_repaints;
|
|
mutable std::optional<WindowQuadList> m_quads;
|
|
mutable std::optional<QList<Item *>> m_sortedChildItems;
|
|
};
|
|
|
|
} // namespace KWin
|