WaylandSurface *surface = qobject_cast<WaylandSurface *>(sender());
QPoint pos;
if (!m_surfaces.contains(surface)) {
- uint px = 1 + (qrand() % (width() - surface->geometry().size().width() - 2));
- uint py = 1 + (qrand() % (height() - surface->geometry().size().height() - 2));
+ uint px = 1 + (qrand() % (width() - surface->size().width() - 2));
+ uint py = 1 + (qrand() % (height() - surface->size().height() - 2));
pos = QPoint(px, py);
- surface->setGeometry(QRect(pos, surface->geometry().size()));
+ surface->setPos(pos);
m_surfaces.append(surface);
}
QLinkedListIterator<WaylandSurface *> i(surface->subSurfaces());
while (i.hasNext()) {
WaylandSurface *subSurface = i.next();
- QPoint p = subSurface->mapTo(window,QPoint(0,0));
- QRect geo = subSurface->geometry();
- geo.moveTo(p);
- if (geo.isValid()) {
+ QPointF p = subSurface->mapTo(window,QPoint(0,0));
+ QSize size = subSurface->size();
+ if (size.isValid()) {
GLuint texture = 0;
if (subSurface->type() == WaylandSurface::Texture) {
texture = subSurface->texture(QOpenGLContext::currentContext());
} else if (surface->type() == WaylandSurface::Shm ) {
texture = m_textureCache->bindTexture(context()->contextHandle(), surface->image());
}
- m_textureBlitter->drawTexture(texture,geo,window->geometry().size(),0,window->isYInverted(),subSurface->isYInverted());
+ m_textureBlitter->drawTexture(texture,QRect(p.toPoint(),size),window->size(),0,window->isYInverted(),subSurface->isYInverted());
}
paintChildren(subSurface,window);
}
for (int i = 0; i < m_surfaces.size(); ++i) {
#ifdef QT_COMPOSITOR_WAYLAND_GL
GLuint texture = composeSurface(m_surfaces.at(i));
- m_textureBlitter->drawTexture(texture,m_surfaces.at(i)->geometry(),size(),0,false,m_surfaces.at(i)->isYInverted());
+ WaylandSurface *surface = m_surfaces.at(i);
+ QRect geo(surface->pos().toPoint(),surface->size());
+ m_textureBlitter->drawTexture(texture,geo,size(),0,false,m_surfaces.at(i)->isYInverted());
#else
QImage img = composeSurface(m_surfaces.at(i));
p.drawImage(m_surfaces.at(i)->geometry().topLeft(),img);
void raise(WaylandSurface *surface) {
setInputFocus(surface);
- surfaceDamaged(surface, QRect(QPoint(), surface->geometry().size()));
+ surfaceDamaged(surface, QRect(QPoint(), surface->size()));
m_surfaces.removeOne(surface);
m_surfaces.append(surface);
}
m_cursorPos = e->pos();
if (!m_cursor.isNull())
update();
- QPoint local;
+ QPointF local;
if (WaylandSurface *surface = surfaceAt(e->pos(), &local)) {
raise(surface);
if (e->modifiers() & Qt::ControlModifier) {
m_moveSurface = surface;
m_moveOffset = local;
} else {
- surface->sendMousePressEvent(local, e->button());
+ surface->sendMousePressEvent(local.toPoint(), e->button());
}
}
}
update();
if (isDragging()) {
QPoint global = e->pos(); // "global" here means the window of the compositor
- QPoint local;
+ QPointF local;
WaylandSurface *surface = surfaceAt(e->pos(), &local);
if (surface) {
if (!m_dragSourceSurface)
m_lastDragSourcePos = local;
raise(surface);
}
- sendDragMoveEvent(global, local, surface);
+ sendDragMoveEvent(global, local.toPoint(), surface);
return;
}
if (m_moveSurface) {
- QRect geometry = m_moveSurface->geometry();
- geometry.moveTo(e->pos() - m_moveOffset);
- m_moveSurface->setGeometry(geometry);
+ m_moveSurface->setPos(e->posF() - m_moveOffset);
update();
return;
}
- QPoint local;
+ QPointF local;
if (WaylandSurface *surface = surfaceAt(e->pos(), &local))
- surface->sendMouseMoveEvent(local);
+ surface->sendMouseMoveEvent(local.toPoint());
}
void mouseReleaseEvent(QMouseEvent *e) {
sendDragEndEvent();
if (m_dragSourceSurface) {
// Must send a release event to the source too, no matter where the cursor is now.
- m_dragSourceSurface->sendMouseReleaseEvent(m_lastDragSourcePos, e->button());
+ m_dragSourceSurface->sendMouseReleaseEvent(m_lastDragSourcePos.toPoint(), e->button());
m_dragSourceSurface = 0;
}
}
m_moveSurface = 0;
return;
}
- QPoint local;
+ QPointF local;
if (WaylandSurface *surface = surfaceAt(e->pos(), &local))
- surface->sendMouseReleaseEvent(local, e->button());
+ surface->sendMouseReleaseEvent(local.toPoint(), e->button());
}
void keyPressEvent(QKeyEvent *event)
m_surfaces.last()->sendKeyReleaseEvent(event->nativeScanCode());
}
- WaylandSurface *surfaceAt(const QPoint &point, QPoint *local = 0) {
+ WaylandSurface *surfaceAt(const QPointF &point, QPointF *local = 0) {
for (int i = m_surfaces.size() - 1; i >= 0; --i) {
- if (m_surfaces.at(i)->geometry().contains(point)) {
+ WaylandSurface *surface = m_surfaces.at(i);
+ QRect geo(surface->pos().toPoint(),surface->size());
+ if (geo.contains(point.toPoint())) {
if (local)
- *local = point - m_surfaces.at(i)->geometry().topLeft();
- return m_surfaces.at(i);
+ *local = point - surface->pos();
+ return surface;
}
}
return 0;
#endif
WaylandSurface *m_moveSurface;
- QPoint m_moveOffset;
+ QPointF m_moveOffset;
WaylandSurface *m_dragSourceSurface;
- QPoint m_lastDragSourcePos;
+ QPointF m_lastDragSourcePos;
QImage m_cursor;
QPoint m_cursorPos;
WaylandSurface *surface = qobject_cast<WaylandSurface *>(sender());
QPoint pos;
if (!m_surfaces.contains(surface)) {
- uint px = 1 + (qrand() % (m_window->width() - surface->geometry().size().width() - 2));
- uint py = 1 + (qrand() % (m_window->height() - surface->geometry().size().height() - 2));
+ uint px = 1 + (qrand() % (m_window->width() - surface->size().width() - 2));
+ uint py = 1 + (qrand() % (m_window->height() - surface->size().height() - 2));
pos = QPoint(px, py);
- surface->setGeometry(QRect(pos, surface->geometry().size()));
+ surface->setPos(pos);
} else {
- surface->setGeometry(QRect(window()->geometry().topLeft(),surface->geometry().size()));
+ surface->setPos(window()->geometry().topLeft());
m_surfaces.removeOne(surface);
}
m_surfaces.append(surface);
QPointF QWindowCompositor::toSurface(WaylandSurface *surface, const QPointF &pos) const
{
- return pos - surface->geometry().topLeft();
+ return pos - surface->pos();
}
WaylandSurface *QWindowCompositor::surfaceAt(const QPoint &point, QPoint *local)
{
for (int i = m_surfaces.size() - 1; i >= 0; --i) {
- if (m_surfaces.at(i)->geometry().contains(point)) {
+ WaylandSurface *surface = m_surfaces.at(i);
+ QRect geo(surface->pos().toPoint(),surface->size());
+ if (geo.contains(point)) {
if (local)
- *local = toSurface(m_surfaces.at(i), point).toPoint();
- return m_surfaces.at(i);
+ *local = toSurface(surface, point).toPoint();
+ return surface;
}
}
return 0;
QLinkedListIterator<WaylandSurface *> i(surface->subSurfaces());
while (i.hasNext()) {
WaylandSurface *subSurface = i.next();
- QPoint p = subSurface->mapTo(window,QPoint(0,0));
- QRect geo = subSurface->geometry();
- geo.moveTo(p);
- if (geo.isValid()) {
+ QPointF p = subSurface->mapTo(window,QPointF(0,0));
+ if (subSurface->size().isValid()) {
GLuint texture = 0;
if (subSurface->type() == WaylandSurface::Texture) {
texture = subSurface->texture(QOpenGLContext::currentContext());
} else if (surface->type() == WaylandSurface::Shm ) {
texture = m_textureCache->bindTexture(QOpenGLContext::currentContext(),surface->image());
}
- qDebug() << "window geo is" << window->geometry().size();
- m_textureBlitter->drawTexture(texture,geo,window->geometry().size(),0,window->isYInverted(),subSurface->isYInverted());
+ QRect geo(p.toPoint(),subSurface->size());
+ m_textureBlitter->drawTexture(texture,geo,window->size(),0,window->isYInverted(),subSurface->isYInverted());
}
paintChildren(subSurface,window);
}
foreach (WaylandSurface *surface, m_surfaces) {
GLuint texture = composeSurface(surface);
- m_textureBlitter->drawTexture(texture,surface->geometry(),m_window->size(),0,false,surface->isYInverted());
+ QRect geo(surface->pos().toPoint(),surface->size());
+ m_textureBlitter->drawTexture(texture,geo,m_window->size(),0,false,surface->isYInverted());
}
m_textureBlitter->release();
case QEvent::MouseMove: {
QMouseEvent *me = static_cast<QMouseEvent *>(event);
if (m_draggingWindow) {
- QRect geo = m_draggingWindow->geometry();
- geo.moveTopLeft(me->pos() - m_drag_diff);
- m_draggingWindow->setGeometry(geo);
+ m_draggingWindow->setPos(me->posF() - m_drag_diff);
m_renderScheduler.start(0);
} else {
QPoint local;
return d->surface->visible();
}
-QRect WaylandSurface::geometry() const
+QPointF WaylandSurface::pos() const
{
Q_D(const WaylandSurface);
- return d->surface->geometry();
+ return d->surface->pos();
}
-void WaylandSurface::setGeometry(const QRect &geometry)
+void WaylandSurface::setPos(const QPointF &pos)
{
Q_D(WaylandSurface);
- d->surface->setGeometry(geometry);
+ d->surface->setPos(pos);
+}
+
+QSize WaylandSurface::size() const
+{
+ Q_D(const WaylandSurface);
+ d->surface->size();
+}
+
+void WaylandSurface::setSize(const QSize &size)
+{
+ Q_D(WaylandSurface);
+ d->surface->setSize(size);
}
QImage WaylandSurface::image() const
d->surface->setWindowProperty(name, value);
}
-QPoint WaylandSurface::mapToParent(const QPoint &pos) const
+QPointF WaylandSurface::mapToParent(const QPointF &pos) const
{
- return pos + geometry().topLeft();
+ return pos + this->pos();
}
-QPoint WaylandSurface::mapTo(WaylandSurface *parent, const QPoint &pos) const
+QPointF WaylandSurface::mapTo(WaylandSurface *parent, const QPointF &pos) const
{
- QPoint p = pos;
+ QPointF p = pos;
if (parent) {
const WaylandSurface * surface = this;
while (surface != parent) {
{
Q_OBJECT
Q_DECLARE_PRIVATE(WaylandSurface)
- Q_PROPERTY(QRect geometry READ geometry WRITE setGeometry NOTIFY geometryChanged)
+ Q_PROPERTY(QSize size READ size WRITE setSize NOTIFY sizeChanged)
+ Q_PROPERTY(QPointF pos READ pos WRITE setPos NOTIFY posChanged)
public:
enum Type {
Invalid,
bool visible() const;
- void setGeometry(const QRect &geometry);
- QRect geometry() const;
+ QPointF pos() const;
+ void setPos(const QPointF &pos);
+ QSize size() const;
+ void setSize(const QSize &size);
QImage image() const;
#ifdef QT_COMPOSITOR_WAYLAND_GL
QVariantMap windowProperties() const;
void setWindowProperty(const QString &name, const QVariant &value);
- QPoint mapToParent(const QPoint &) const;
- QPoint mapTo(WaylandSurface *, const QPoint &) const;
+ QPointF mapToParent(const QPointF &) const;
+ QPointF mapTo(WaylandSurface *, const QPointF &) const;
signals:
void mapped();
void unmapped();
void damaged(const QRect &rect);
void parentChanged(WaylandSurface *newParent, WaylandSurface *oldParent);
- void geometryChanged();
+ void sizeChanged();
+ void posChanged();
void windowPropertyChanged(const QString &name, const QVariant &value);
friend class Wayland::Surface;
m_surface = surface;
m_surface->setSurfaceItem(this);
- setWidth(surface->geometry().width());
- setHeight(surface->geometry().height());
+ setWidth(surface->size().width());
+ setHeight(surface->size().height());
setSmooth(true);
setFlag(ItemHasContents);
connect(surface, SIGNAL(damaged(const QRect &)), this, SLOT(surfaceDamaged(const QRect &)));
connect(surface, SIGNAL(parentChanged(WaylandSurface*,WaylandSurface*)),
this, SLOT(parentChanged(WaylandSurface*,WaylandSurface*)));
- connect(surface, SIGNAL(geometryChanged()), this, SLOT(updateGeometry()));
+ connect(surface, SIGNAL(sizeChanged()), this, SLOT(updateSize()));
+ connect(surface, SIGNAL(posChanged()), this, SLOT(updatePosition()));
m_damaged = false;
}
}
-void WaylandSurfaceItem::updateGeometry()
+void WaylandSurfaceItem::updateSize()
{
- setPos(m_surface->geometry().topLeft());
- setSize(m_surface->geometry().size());
+ setSize(m_surface->size());
+}
+
+void WaylandSurfaceItem::updatePosition()
+{
+ setPos(m_surface->pos());
}
bool WaylandSurfaceItem::paintEnabled() const
QQuickCanvas::CreateTextureOptions opt = useTextureAlpha() ? QQuickCanvas::TextureHasAlphaChannel : QQuickCanvas::CreateTextureOptions(0);
m_texture = canvas()->createTextureFromId(m_surface->texture(context),
- m_surface->geometry().size(),
+ m_surface->size(),
opt);
} else {
m_texture = canvas()->createTextureFromImage(m_surface->image());
void surfaceDestroyed(QObject *object);
void surfaceDamaged(const QRect &);
void parentChanged(WaylandSurface *newParent, WaylandSurface *oldParent);
- void updateGeometry();
+ void updateSize();
+ void updatePosition();
signals:
void textureChanged();
void SubSurface::setSubSurface(SubSurface *subSurface, int x, int y)
{
-// Q_ASSERT(!m_sub_surfaces.contains(subSurface->m_surface->handle()));
+ Q_ASSERT(!m_sub_surfaces.contains(subSurface->m_surface->handle()));
m_sub_surfaces.append(subSurface->m_surface->handle());
subSurface->setParent(this);
- QRect rect = m_surface->geometry();
- rect.moveTo(x,y);
- subSurface->m_surface->setGeometry(rect);
+ subSurface->m_surface->setPos(QPointF(x,y));
}
void SubSurface::removeSubSurface(SubSurface *subSurfaces)
SurfaceBuffer bufferPool[buffer_pool_size];
- QRect geometry;
+ QPointF position;
+ QSize size;
private:
Surface *q_ptr;
};
return QImage();
}
-QRect Surface::geometry() const
+QPointF Surface::pos() const
{
Q_D(const Surface);
- return d->geometry;
+ return d->position;
}
-void Surface::setGeometry(const QRect &rect)
+void Surface::setPos(const QPointF &pos)
{
Q_D(Surface);
- bool emitChange = false;
- if (rect != d->geometry)
- emitChange = true;
- d->geometry = rect;
+ bool emitChange = pos != d->position;
+ d->position = pos;
if (emitChange)
- d->qtSurface->geometryChanged();
+ d->qtSurface->posChanged();
+}
+
+QSize Surface::size() const
+{
+ Q_D(const Surface);
+ return d->size;
+}
+
+void Surface::setSize(const QSize &size)
+{
+ Q_D(Surface);
+ bool emitChange = size != d->size;
+ d->size = size;
+ if (emitChange)
+ d->qtSurface->sizeChanged();
}
#ifdef QT_COMPOSITOR_WAYLAND_GL
bool emitMap = !d->surfaceBuffer && buffer && (!d->subSurface || !d->subSurface->parent());
bool emitUnmap = d->surfaceBuffer && !buffer;
- if (d->surfaceBuffer && d->surfaceBuffer != d->directRenderBuffer) {
- if (d->textureBuffer == d->surfaceBuffer)
- d->textureBuffer = 0;
+ if (d->surfaceBuffer && !d->surfaceBuffer->textureCreated() && d->surfaceBuffer != d->directRenderBuffer) {
d->surfaceBuffer->destructBufferState();
d->surfaceBuffer = 0;
}
width = d->surfaceBuffer->width();
height = d->surfaceBuffer->height();
}
- QRect geo = geometry();
- geo.setWidth(width);
- geo.setHeight(height);
- setGeometry(geo);
+ setSize(QSize(width,height));
if (emitMap) {
d->qtSurface->mapped();
QImage image() const;
- QRect geometry() const;
- void setGeometry(const QRect &rect);
+ QPointF pos() const;
+ void setPos(const QPointF &pos);
+
+ QSize size() const;
+ void setSize(const QSize &size);
#ifdef QT_COMPOSITOR_WAYLAND_GL
GLuint textureId(QOpenGLContext *context) const;