13#include "virtualdesktops.h"
22QSizeF Tile::s_minimumSize = QSizeF(0.15, 0.15);
26 , m_parentTile(parent)
30 m_padding = m_parentTile->
padding();
37 for (
auto *t : std::as_const(m_children)) {
39 t->m_parentTile =
nullptr;
44 for (
auto *w : std::as_const(m_windows)) {
58 return m_relativeGeometry.left() > 0.0;
60 return m_relativeGeometry.top() > 0.0;
62 return m_relativeGeometry.right() < 1.0;
64 return m_relativeGeometry.bottom() < 1.0;
66 return m_relativeGeometry.top() > 0.0 && m_relativeGeometry.left() > 0.0;
68 return m_relativeGeometry.top() > 0.0 && m_relativeGeometry.right() < 1.0;
70 return m_relativeGeometry.bottom() < 1.0 && m_relativeGeometry.left() > 0.0;
72 return m_relativeGeometry.bottom() < 1.0 && m_relativeGeometry.right() < 1.0;
87 const QRectF relGeom((geom.x() - outGeom.x()) / outGeom.width(),
88 (geom.y() - outGeom.y()) / outGeom.height(),
89 geom.width() / outGeom.width(),
90 geom.height() / outGeom.height());
97 QRectF constrainedGeom = geom;
98 constrainedGeom.setWidth(std::max(constrainedGeom.width(), s_minimumSize.width()));
99 constrainedGeom.setHeight(std::max(constrainedGeom.height(), s_minimumSize.height()));
101 if (m_relativeGeometry == constrainedGeom) {
105 m_relativeGeometry = constrainedGeom;
111 for (
auto *w : std::as_const(m_windows)) {
118 return m_relativeGeometry;
124 return QRectF(std::round(geom.x() + m_relativeGeometry.x() * geom.width()),
125 std::round(geom.y() + m_relativeGeometry.y() * geom.height()),
126 std::round(m_relativeGeometry.width() * geom.width()),
127 std::round(m_relativeGeometry.height() * geom.height()));
133 return QRectF(std::round(m_relativeGeometry.x() * geom.width()),
134 std::round(m_relativeGeometry.y() * geom.height()),
135 std::round(m_relativeGeometry.width() * geom.width()),
136 std::round(m_relativeGeometry.height() * geom.height()));
142 QMarginsF effectiveMargins;
143 effectiveMargins.setLeft(m_relativeGeometry.left() > 0.0 ? m_padding / 2.0 : m_padding);
144 effectiveMargins.setTop(m_relativeGeometry.top() > 0.0 ? m_padding / 2.0 : m_padding);
145 effectiveMargins.setRight(m_relativeGeometry.right() < 1.0 ? m_padding / 2.0 : m_padding);
146 effectiveMargins.setBottom(m_relativeGeometry.bottom() < 1.0 ? m_padding / 2.0 : m_padding);
149 return geom.intersected(
workspace()->clientArea(
MaximizeArea, m_tiling->
output(), VirtualDesktopManager::self()->currentDesktop())) - effectiveMargins;
155 return geom.intersected(
workspace()->clientArea(
MaximizeArea, m_tiling->
output(), VirtualDesktopManager::self()->currentDesktop()));
161 return m_children.count() > 0 || !m_parentTile;
184 for (
auto *t : std::as_const(m_children)) {
187 for (
auto *w : std::as_const(m_windows)) {
197 return m_quickTileMode;
202 m_quickTileMode = mode;
212 const QPointF relativePos = QPointF((x_root - outGeom.x()) / outGeom.width(), (y_root - outGeom.y()) / outGeom.height());
213 QRectF newGeom = m_relativeGeometry;
217 newGeom.setTopLeft(relativePos - QPointF(m_padding / outGeom.width(), m_padding / outGeom.height()));
220 newGeom.setBottomRight(relativePos + QPointF(m_padding / outGeom.width(), m_padding / outGeom.height()));
223 newGeom.setBottomLeft(relativePos + QPointF(-m_padding / outGeom.width(), m_padding / outGeom.height()));
226 newGeom.setTopRight(relativePos + QPointF(m_padding / outGeom.width(), -m_padding / outGeom.height()));
229 newGeom.setTop(relativePos.y() - m_padding / outGeom.height());
232 newGeom.setBottom(relativePos.y() + m_padding / outGeom.height());
235 newGeom.setLeft(relativePos.x() - m_padding / outGeom.width());
238 newGeom.setRight(relativePos.x() + m_padding / outGeom.width());
255 auto newGeom = m_relativeGeometry;
259 qreal relativeDelta = delta / outGeom.width();
260 newGeom.setLeft(newGeom.left() + relativeDelta);
264 qreal relativeDelta = delta / outGeom.height();
265 newGeom.setTop(newGeom.top() + relativeDelta);
268 case Qt::RightEdge: {
269 qreal relativeDelta = delta / outGeom.width();
270 newGeom.setRight(newGeom.right() + relativeDelta);
273 case Qt::BottomEdge: {
274 qreal relativeDelta = delta / outGeom.height();
275 newGeom.setBottom(newGeom.bottom() + relativeDelta);
284 if (!m_windows.contains(window)) {
286 m_windows.append(window);
296 if (m_windows.removeOne(window)) {
310 Q_ASSERT(position >= 0);
311 const bool wasEmpty = m_children.isEmpty();
312 item->setParent(
this);
314 m_children.insert(std::clamp<qsizetype>(position, 0, m_children.length()), item);
318 for (
auto *w : std::as_const(m_windows)) {
335 const bool wasEmpty = m_children.isEmpty();
336 const int idx = m_children.indexOf(child);
337 m_children.removeAll(child);
338 if (m_children.isEmpty() && !wasEmpty) {
342 for (
int i = idx; i < m_children.count(); ++i) {
343 Q_EMIT m_children[i]->rowChanged(i);
356 if (row < 0 || row >= m_children.size()) {
359 return m_children.value(
row);
364 return m_children.count();
370 for (
auto *t : std::as_const(m_children)) {
371 tiles << t << t->descendants();
384 for (
const Tile *child : m_children) {
397 return m_parentTile->m_children.indexOf(
this);
406 if (!m_parentTile ||
row() >= m_parentTile->
childCount() - 1) {
416 if (r <= 0 || !m_parentTile) {
425#include "moc_tile.cpp"
void resizeFromGravity(Gravity gravity, int x_root, int y_root)
Q_INVOKABLE void resizeByPixels(qreal delta, Qt::Edge edge)
void isLayoutChanged(bool isLayout)
void removeWindow(Window *window)
void paddingChanged(qreal padding)
QRectF absoluteGeometryInScreen
void setQuickTileMode(QuickTileMode mode)
QList< KWin::Tile * > tiles
void visitDescendants(std::function< void(const Tile *child)> callback) const
Tile * nextSibling() const
void relativeGeometryChanged()
QRectF maximizedWindowGeometry() const
TileManager * manager() const
void windowRemoved(Window *window)
void absoluteGeometryChanged()
Tile * childTile(int row)
void addWindow(Window *window)
QList< KWin::Window * > windows
void setGeometryFromAbsolute(const QRectF &geom)
virtual bool supportsResizeGravity(Gravity gravity)
QuickTileMode quickTileMode() const
Tile * parentTile() const
void destroyChild(Tile *tile)
void setGeometryFromWindow(const QRectF &geom)
Tile(TileManager *tiling, Tile *parentItem=nullptr)
Tile * previousSibling() const
virtual void setRelativeGeometry(const QRectF &geom)
QList< Tile * > descendants() const
QList< Tile * > childTiles() const
void windowAdded(Window *window)
QRectF windowGeometry() const
void windowGeometryChanged()
void setPadding(qreal padding)
void insertChild(int position, Tile *item)
void removeChild(Tile *child)
KWin::Tile * bestTileForPosition(const QPointF &pos)
void moveResize(const QRectF &rect)
static Workspace * self()