class QWidgetCompositor : public QWidget, public WaylandCompositor
#endif
{
+ Q_OBJECT
public:
QWidgetCompositor() : WaylandCompositor(this), m_dragSurface(0) {
setMouseTracking(true);
}
}
-protected:
-
- void surfaceCreated(WaylandSurface *) {
- update();
- }
-
- void surfaceDestroyed(WaylandSurface *surface) {
+private slots:
+ void surfaceDestroyed(QObject *object) {
+ WaylandSurface *surface = qobject_cast<WaylandSurface *>(object);
m_surfaces.removeAll(surface);
if (m_surfaces.isEmpty())
setInputFocus(0);
update();
}
- void surfaceMapped(WaylandSurface *surface, const QRect &rect) {
+ void surfaceMapped(const QRect &rect) {
+ WaylandSurface *surface = qobject_cast<WaylandSurface *>(sender());
QPoint pos;
- int index = m_surfaces.indexOf(surface);
- if (index == -1) {
+ if (!m_surfaces.contains(surface)) {
uint px = 1 + (qrand() % (width() - rect.width() - 2));
uint py = 1 + (qrand() % (height() - rect.height() - 2));
pos = QPoint(px, py);
surface->setGeometry(QRect(pos, rect.size()));
m_surfaces.append(surface);
} else {
- m_surfaces[index]->setGeometry(rect);
+ surface->setGeometry(rect);
}
setInputFocus(surface);
update();
}
- void surfaceDamaged(WaylandSurface *surface, const QRect &rect) {
+ void surfaceDamaged(const QRect &rect) {
+ WaylandSurface *surface = qobject_cast<WaylandSurface *>(sender());
+ surfaceDamaged(surface, rect);
+ }
+
+protected:
+ void surfaceDamaged(WaylandSurface *surface, const QRect &rect)
+ {
#ifdef QT_COMPOSITOR_WAYLAND_GL
Q_UNUSED(surface);
Q_UNUSED(rect);
#endif
}
+ void surfaceCreated(WaylandSurface *surface) {
+ connect(surface, SIGNAL(destroyed(QObject *)), this, SLOT(surfaceDestroyed(QObject *)));
+ connect(surface, SIGNAL(mapped(const QRect &)), this, SLOT(surfaceMapped(const QRect &)));
+ connect(surface, SIGNAL(damaged(const QRect &)), this, SLOT(surfaceDamaged(const QRect &)));
+ update();
+ }
+
void paintEvent(QPaintEvent *) {
QPainter p(this);
}
+#include "main.moc"
fprintf(stderr, "wl_event_loop_dispatch error: %d\n", ret);
}
-void Compositor::surfaceResized(Surface *surface, const QSize &size)
-{
- m_qt_compositor->surfaceMapped(surface->handle(), QRect(QPoint(), size));
-}
-
void Compositor::surfaceDestroyed(Surface *surface)
{
m_surfaces.removeOne(surface);
- m_qt_compositor->surfaceDestroyed(surface->handle());
}
void Compositor::setInputFocus(Surface *surface)
wl_input_device_set_pointer_focus(&m_input, base, time, 0, 0, 0, 0);
}
-void Compositor::surfaceDamaged(Surface *surface, const QRect &rect)
-{
- m_qt_compositor->surfaceDamaged(surface->handle(), rect);
-}
-
QWidget * Compositor::topLevelWidget() const
{
return m_qt_compositor->topLevelWidget();
struct wl_input_device *inputDevice() { return &m_input; }
void createSurface(struct wl_client *client, int id);
-
- void surfaceResized(Surface *surface, const QSize &size);
void surfaceDestroyed(Surface *surface);
- void surfaceDamaged(Surface *surface, const QRect &rect);
uint currentTimeMsecs() const;
{
Q_D(Surface);
d->compositor->surfaceDestroyed(this);
+ delete d->qtSurface;
}
WaylandSurface::Type Surface::type() const
void Surface::damage(const QRect &rect)
{
Q_D(Surface);
- d->compositor->surfaceDamaged(this, rect);
+ emit d->qtSurface->damaged(rect);
}
QImage Surface::image() const
glDeleteTextures(1,&d->texture_id);
d->texture_id = d->compositor->graphicsHWIntegration()->createTextureFromBuffer(buffer);
- d->compositor->surfaceResized(this,QSize(buffer->width,buffer->height));
+ emit d->qtSurface->mapped(QRect(QPoint(), QSize(buffer->width, buffer->height)));
}
GLuint Surface::textureId() const
Q_D(Surface);
d->shm_buffer = shm_buffer;
d->type = WaylandSurface::Shm;
- d->compositor->surfaceResized(this, shm_buffer->size());
+ emit d->qtSurface->mapped(QRect(QPoint(), shm_buffer->size()));
}
QWidget *topLevelWidget()const;
virtual void surfaceCreated(WaylandSurface *surface) = 0;
- virtual void surfaceDestroyed(WaylandSurface *surface) = 0;
- virtual void surfaceMapped(WaylandSurface *surface, const QRect &rect) = 0;
- virtual void surfaceDamaged(WaylandSurface *surface, const QRect &rect) = 0;
Wayland::Compositor *handle() const;
private:
#include "private/wlsurface.h"
-class WaylandSurfacePrivate
+class WaylandSurfacePrivate : public QObjectPrivate
{
public:
WaylandSurfacePrivate(Wayland::Surface *srfc)
};
WaylandSurface::WaylandSurface(Wayland::Surface *surface)
- : d_ptr(new WaylandSurfacePrivate(surface))
+ : QObject(*new WaylandSurfacePrivate(surface))
{
}
class Surface;
}
-class WaylandSurface
+class WaylandSurface : public QObject
{
+ Q_OBJECT
Q_DECLARE_PRIVATE(WaylandSurface)
public:
-
enum Type {
Invalid,
Shm,
void sendKeyReleaseEvent(uint code);
Wayland::Surface *handle() const;
-protected:
- QScopedPointer<WaylandSurfacePrivate> d_ptr;
-private:
- Q_DISABLE_COPY(WaylandSurface)
+
+signals:
+ void mapped(const QRect &rect);
+ void damaged(const QRect &rect);
+
+ friend class Wayland::Surface;
};
#endif // WAYLANDSURFACE_H