Skip to content

Commit

Permalink
Do not use QQuickItemPrivate
Browse files Browse the repository at this point in the history
We don't want to depend on Qt private APIs.

Issue: #11
  • Loading branch information
plfiorini committed May 15, 2022
1 parent 783657b commit 82db3d5
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 33 deletions.
21 changes: 16 additions & 5 deletions src/compositor/compositor_api/aurorawaylandmousetracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,22 @@
**
****************************************************************************/

#include "aurorawaylandmousetracker_p.h"
#include <QCursor>
#include <QImage>
#include <QPixmap>

#include <QtQuick/private/qquickitem_p.h>
#include "aurorawaylandmousetracker_p.h"

namespace Aurora {

namespace Compositor {

class WaylandMouseTrackerPrivate : public QQuickItemPrivate
class WaylandMouseTrackerPrivate
{
Q_DECLARE_PUBLIC(WaylandMouseTracker)
public:
WaylandMouseTrackerPrivate()
WaylandMouseTrackerPrivate(WaylandMouseTracker *self)
: q_ptr(self)
{
QImage cursorImage(64,64,QImage::Format_ARGB32);
cursorImage.fill(Qt::transparent);
Expand Down Expand Up @@ -72,10 +75,14 @@ class WaylandMouseTrackerPrivate : public QQuickItemPrivate
bool windowSystemCursorEnabled = false;
QPixmap cursorPixmap;
bool hovered = false;

private:
WaylandMouseTracker *q_ptr = nullptr;
};

WaylandMouseTracker::WaylandMouseTracker(QQuickItem *parent)
: QQuickItem(*(new WaylandMouseTrackerPrivate), parent)
: QQuickItem(parent)
, d_ptr(new WaylandMouseTrackerPrivate(this))
{
Q_D(WaylandMouseTracker);
setFiltersChildMouseEvents(true);
Expand All @@ -86,6 +93,10 @@ WaylandMouseTracker::WaylandMouseTracker(QQuickItem *parent)
#endif
}

WaylandMouseTracker::~WaylandMouseTracker()
{
}

qreal WaylandMouseTracker::mouseX() const
{
Q_D(const WaylandMouseTracker);
Expand Down
4 changes: 4 additions & 0 deletions src/compositor/compositor_api/aurorawaylandmousetracker_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class LIRIAURORACOMPOSITOR_EXPORT WaylandMouseTracker : public QQuickItem
#endif
public:
WaylandMouseTracker(QQuickItem *parent = nullptr);
~WaylandMouseTracker();

qreal mouseX() const;
qreal mouseY() const;
Expand All @@ -85,6 +86,9 @@ class LIRIAURORACOMPOSITOR_EXPORT WaylandMouseTracker : public QQuickItem
void hoverMoveEvent(QHoverEvent *event) override;
void hoverEnterEvent(QHoverEvent *event) override;
void hoverLeaveEvent(QHoverEvent *event) override;

private:
QScopedPointer<WaylandMouseTrackerPrivate> const d_ptr;
};

} // namespace Compositor
Expand Down
19 changes: 7 additions & 12 deletions src/compositor/compositor_api/aurorawaylandquickitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@

#include <QtGui/QKeyEvent>
#include <QtGui/QGuiApplication>
#include <QtGui/QWindow>
#include <QtGui/QScreen>

#include <QtQuick/QSGSimpleTextureNode>
Expand Down Expand Up @@ -735,16 +736,8 @@ class WaylandSurfaceTextureProvider : public QSGTextureProvider
* Constructs a WaylandQuickItem with the given \a parent.
*/
WaylandQuickItem::WaylandQuickItem(QQuickItem *parent)
: QQuickItem(*new WaylandQuickItemPrivate(), parent)
{
d_func()->init();
}

/*!
* \internal
*/
WaylandQuickItem::WaylandQuickItem(WaylandQuickItemPrivate &dd, QQuickItem *parent)
: QQuickItem(dd, parent)
: QQuickItem(parent)
, d_ptr(new WaylandQuickItemPrivate(this))
{
d_func()->init();
}
Expand Down Expand Up @@ -2097,10 +2090,12 @@ void WaylandQuickItem::handleDragStarted(WaylandDrag *drag)

qreal WaylandQuickItemPrivate::scaleFactor() const
{
Q_Q(const WaylandQuickItem);

qreal f = view->output() ? view->output()->scaleFactor() : 1;
#if !defined(Q_OS_MACOS)
if (window)
f /= window->devicePixelRatio();
if (q->window())
f /= q->window()->devicePixelRatio();
#endif
return f;
}
Expand Down
3 changes: 2 additions & 1 deletion src/compositor/compositor_api/aurorawaylandquickitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ private Q_SLOTS:
protected:
QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data) override;

WaylandQuickItem(WaylandQuickItemPrivate &dd, QQuickItem *parent = nullptr);
private:
QScopedPointer<WaylandQuickItemPrivate> const d_ptr;
};

} // namespace Compositor
Expand Down
10 changes: 8 additions & 2 deletions src/compositor/compositor_api/aurorawaylandquickitem_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,14 @@ class WaylandBufferMaterial : public QSGMaterial
#endif
#endif // QT_CONFIG(opengl)

class WaylandQuickItemPrivate : public QQuickItemPrivate
class WaylandQuickItemPrivate
{
Q_DECLARE_PUBLIC(WaylandQuickItem)
public:
WaylandQuickItemPrivate() = default;
WaylandQuickItemPrivate(WaylandQuickItem *self)
: q_ptr(self)
{
}

void init()
{
Expand Down Expand Up @@ -221,6 +224,9 @@ class WaylandQuickItemPrivate : public QQuickItemPrivate
WaylandSurface::Origin origin = WaylandSurface::OriginTopLeft;
QPointer<QObject> subsurfaceHandler;
QList<WaylandSeat *> touchingSeats;

private:
WaylandQuickItem *q_ptr = nullptr;
};

} // namespace Compositor
Expand Down
29 changes: 28 additions & 1 deletion src/compositor/compositor_api/aurorawaylandquickoutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,39 @@ void WaylandQuickOutput::setAutomaticFrameCallback(bool automatic)
emit automaticFrameCallbackChanged();
}

static bool itemZOrder_sort(QQuickItem *lhs, QQuickItem *rhs)
{
return lhs->z() < rhs->z();
}

static QList<QQuickItem *> paintOrderChildItems(QQuickItem *rootItem)
{
const auto childItems = rootItem->childItems();

// If none of the items have set Z then the paint order list is the same as
// the childItems list. This is by far the most common case.
bool haveZ = false;
for (int i = 0; i < childItems.count(); ++i) {
if (childItems.at(i)->z() != 0.) {
haveZ = true;
break;
}
}
if (haveZ) {
const auto sortedChildItems = new QList<QQuickItem*>(childItems);
std::stable_sort(sortedChildItems->begin(), sortedChildItems->end(), itemZOrder_sort);
return *sortedChildItems;
}

return childItems;
}

static QQuickItem* clickableItemAtPosition(QQuickItem *rootItem, const QPointF &position)
{
if (!rootItem->isEnabled() || !rootItem->isVisible())
return nullptr;

QList<QQuickItem *> paintOrderItems = QQuickItemPrivate::get(rootItem)->paintOrderChildItems();
QList<QQuickItem *> paintOrderItems = paintOrderChildItems(rootItem);
auto negativeZStart = paintOrderItems.crend();
for (auto it = paintOrderItems.crbegin(); it != paintOrderItems.crend(); ++it) {
if ((*it)->z() < 0) {
Expand Down
11 changes: 2 additions & 9 deletions src/compositor/extensions/aurorawaylandquickshellsurfaceitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ WaylandQuickShellSurfaceItem *WaylandQuickShellSurfaceItemPrivate::maybeCreateAu
* Constructs a WaylandQuickWlShellSurfaceItem with the given \a parent.
*/
WaylandQuickShellSurfaceItem::WaylandQuickShellSurfaceItem(QQuickItem *parent)
: WaylandQuickItem(*new WaylandQuickShellSurfaceItemPrivate(), parent)
: WaylandQuickItem(parent)
, d_ptr(new WaylandQuickShellSurfaceItemPrivate(this))
{
}

Expand All @@ -96,14 +97,6 @@ WaylandQuickShellSurfaceItem::~WaylandQuickShellSurfaceItem()
}
}

/*!
* \internal
*/
WaylandQuickShellSurfaceItem::WaylandQuickShellSurfaceItem(WaylandQuickShellSurfaceItemPrivate &dd, QQuickItem *parent)
: WaylandQuickItem(dd, parent)
{
}

/*!
* \qmlproperty ShellSurface AuroraCompositor::ShellSurfaceItem::shellSurface
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ class LIRIAURORACOMPOSITOR_EXPORT WaylandQuickShellSurfaceItem : public WaylandQ
void staysOnTopChanged();
void staysOnBottomChanged();

protected:
WaylandQuickShellSurfaceItem(WaylandQuickShellSurfaceItemPrivate &dd, QQuickItem *parent);
private:
QScopedPointer<WaylandQuickShellSurfaceItemPrivate> const d_ptr;
};

} // namespace Compositor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ class LIRIAURORACOMPOSITOR_EXPORT WaylandQuickShellSurfaceItemPrivate : public W
{
Q_DECLARE_PUBLIC(WaylandQuickShellSurfaceItem)
public:
WaylandQuickShellSurfaceItemPrivate() {}
WaylandQuickShellSurfaceItemPrivate(WaylandQuickShellSurfaceItem *self)
: WaylandQuickItemPrivate(self)
, q_ptr(self)
{
}

WaylandQuickShellSurfaceItem *maybeCreateAutoPopup(WaylandShellSurface* shellSurface);
static WaylandQuickShellSurfaceItemPrivate *get(WaylandQuickShellSurfaceItem *item) { return item->d_func(); }

Expand All @@ -72,6 +77,9 @@ class LIRIAURORACOMPOSITOR_EXPORT WaylandQuickShellSurfaceItemPrivate : public W
bool m_autoCreatePopupItems = true;
bool staysOnTop = false;
bool staysOnBottom = false;

private:
WaylandQuickShellSurfaceItem *q_ptr = nullptr;
};

class LIRIAURORACOMPOSITOR_EXPORT WaylandQuickShellEventFilter : public QObject
Expand Down

0 comments on commit 82db3d5

Please sign in to comment.