Add WaylandSurface class
authorJørgen Lind <jorgen.lind@nokia.com>
Mon, 14 Mar 2011 11:22:09 +0000 (12:22 +0100)
committerJørgen Lind <jorgen.lind@nokia.com>
Mon, 14 Mar 2011 11:24:25 +0000 (12:24 +0100)
This class is intended to be used when implementing a compositor

examples/qwidget-compositor/main.cpp
src/qt-compositor/private/wlcompositor.cpp
src/qt-compositor/private/wlcompositor.h
src/qt-compositor/private/wlsurface.cpp
src/qt-compositor/private/wlsurface.h
src/qt-compositor/qt-compositor.pri
src/qt-compositor/qtcompositor.cpp
src/qt-compositor/qtcompositor.h
src/qt-compositor/waylandsurface.cpp [new file with mode: 0644]
src/qt-compositor/waylandsurface.h [new file with mode: 0644]

index 2f06771..13b29c0 100644 (file)
@@ -40,6 +40,8 @@
 
 #include "qtcompositor.h"
 
+#include "waylandsurface.h"
+
 #include <QApplication>
 #include <QWidget>
 #include <QTimer>
@@ -72,43 +74,36 @@ public:
     }
 
 protected:
-    int surfaceIndex(uint winId) {
-        for (int i = 0; i < m_surfaces.size(); ++i)
-            if (m_surfaces.at(i).first == winId)
-                return i;
-        return -1;
-    }
 
-    void surfaceCreated(uint) {
+    void surfaceCreated(WaylandSurface *) {
+        update();
     }
 
-    void surfaceDestroyed(uint winId) {
-        m_surfaces.removeAt(surfaceIndex(winId));
+    void surfaceDestroyed(WaylandSurface *surface) {
+        m_surfaces.removeAll(surface);
         if (m_surfaces.isEmpty())
             setInputFocus(0);
         update();
     }
 
-    void surfaceMapped(uint winId, const QRect &rect) {
+    void surfaceMapped(WaylandSurface *surface, const QRect &rect) {
         QPoint pos;
-        int index = surfaceIndex(winId);
+        int index = m_surfaces.indexOf(surface);
         if (index == -1) {
             uint px = 1 + (qrand() % (width() - rect.width() - 2));
             uint py = 1 + (qrand() % (height() - rect.height() - 2));
             pos = QPoint(px, py);
-            m_surfaces.append(qMakePair(winId, QRect(pos, rect.size())));
+            surface->setGeometry(QRect(pos, rect.size()));
+            m_surfaces.append(surface);
         } else {
-            m_surfaces[index].second.setSize(rect.size());
+            m_surfaces[index]->setGeometry(rect);
         }
-        setInputFocus(winId);
+        setInputFocus(surface);
         update();
     }
 
-    void surfaceDamaged(uint winId, const QRect &rect) {
-        int index = surfaceIndex(winId);
-        if (index != -1) {
-            update(rect.translated(m_surfaces.at(index).second.topLeft()));
-        }
+    void surfaceDamaged(WaylandSurface *surface, const QRect &rect) {
+        update(rect.translated(surface->geometry().topLeft()));
     }
 
     void paintEvent(QPaintEvent *) {
@@ -118,27 +113,27 @@ protected:
             p.drawPixmap(rect(), m_backgroundScaled);
 
         for (int i = 0; i < m_surfaces.size(); ++i) {
-            if (hasImage(m_surfaces.at(i).first)) {
-                QImage img = image(m_surfaces.at(i).first);
-                p.drawImage(m_surfaces.at(i).second.topLeft(), img);
-            }
+            if (m_surfaces.at(i)->type() == WaylandSurface::Texture) {
 #ifdef QT_COMPOSITOR_WAYLAND_GL
-            else {
                 QPlatformGLContext *glcontext = platformWindow()->glContext();
                 if (glcontext) {
                     QGLContext *context = QGLContext::fromPlatformGLContext(glcontext);
                     context->makeCurrent();
-                    context->drawTexture(m_surfaces.at(i).second,textureId(m_surfaces.at(i).first));
+                    context->drawTexture(m_surfaces.at(i)->geometry(),m_surfaces.at(i)->texture());
                 }
-            }
+                break;
 #endif //QT_COMPOSITOR_WAYLAND_GL
+            } else if (m_surfaces.at(i)->type() == WaylandSurface::Shm) {
+                QImage img = m_surfaces.at(i)->image();
+                p.drawImage(m_surfaces.at(i)->geometry(), img);
+            }
         }
 
         frameFinished();
 
 #ifdef QT_COMPOSITOR_WAYLAND_GL
         //jl:FIX FIX FIX:)
-        update();
+//        update();
         glFinish();
 #endif
     }
@@ -152,8 +147,8 @@ protected:
     }
 
     int raise(int index) {
-        setInputFocus(m_surfaces.at(index).first);
-        surfaceDamaged(m_surfaces.at(index).first, QRect(QPoint(), m_surfaces.at(index).second.size()));
+        setInputFocus(m_surfaces.at(index));
+        surfaceDamaged(m_surfaces.at(index), QRect(QPoint(), m_surfaces.at(index)->geometry().size()));
         m_surfaces.append(m_surfaces.takeAt(index));
         return m_surfaces.size() - 1;
     }
@@ -168,22 +163,22 @@ protected:
                 m_dragIndex = index;
                 m_dragOffset = local;
             } else {
-                setInputFocus(m_surfaces.at(index).first);
-                sendMousePressEvent(m_surfaces.at(index).first, local.x(), local.y(), e->button());
+                setInputFocus(m_surfaces.at(index));
+                m_surfaces.at(index)->sendMousePressEvent(local.x(), local.y(), e->button());
             }
         }
     }
 
     void mouseMoveEvent(QMouseEvent *e) {
         if (m_dragging) {
-            m_surfaces[m_dragIndex].second.moveTo(e->pos() - m_dragOffset);
+            m_surfaces[m_dragIndex]->geometry().moveTo(e->pos() - m_dragOffset);
             update();
             return;
         }
         QPoint local;
         int index = surfaceIndex(e->pos(), &local);
         if (index != -1)
-            sendMouseMoveEvent(m_surfaces.at(index).first, local.x(), local.y());
+            m_surfaces.at(index)->sendMouseMoveEvent(local.x(), local.y());
     }
 
     void mouseReleaseEvent(QMouseEvent *e) {
@@ -194,28 +189,28 @@ protected:
         QPoint local;
         int index = surfaceIndex(e->pos(), &local);
         if (index != -1)
-            sendMouseReleaseEvent(m_surfaces.at(index).first, local.x(), local.y(), e->button());
+            m_surfaces.at(index)->sendMouseReleaseEvent(local.x(), local.y(), e->button());
     }
 
     void keyPressEvent(QKeyEvent *event)
     {
         if (m_surfaces.isEmpty())
             return;
-        sendKeyPressEvent(m_surfaces.last().first, event->nativeScanCode());
+        m_surfaces.last()->sendKeyPressEvent(event->nativeScanCode());
     }
 
     void keyReleaseEvent(QKeyEvent *event)
     {
         if (m_surfaces.isEmpty())
             return;
-        sendKeyReleaseEvent(m_surfaces.last().first, event->nativeScanCode());
+        m_surfaces.last()->sendKeyReleaseEvent(event->nativeScanCode());
     }
 
     int surfaceIndex(const QPoint &point, QPoint *local = 0) {
         for (int i = m_surfaces.size() - 1; i >= 0; --i) {
-            if (m_surfaces.at(i).second.contains(point)) {
+            if (m_surfaces.at(i)->geometry().contains(point)) {
                 if (local)
-                    *local = point - m_surfaces.at(i).second.topLeft();
+                    *local = point - m_surfaces.at(i)->geometry().topLeft();
                 return i;
             }
         }
@@ -226,7 +221,7 @@ private:
     QImage m_background;
     QPixmap m_backgroundScaled;
 
-    QList<QPair<uint, QRect> > m_surfaces;
+    QList<WaylandSurface *> m_surfaces;
 
     bool m_dragging;
     int m_dragIndex;
index ef728f8..947b452 100644 (file)
@@ -58,7 +58,6 @@
 #include <stddef.h>
 #include <errno.h>
 #include <fcntl.h>
-#include <linux/input.h>
 #include <unistd.h>
 
 #include <sys/mman.h>
@@ -236,7 +235,7 @@ void Compositor::createSurface(struct wl_client *client, int id)
     addClientResource(client, &surface->base()->resource, id, &wl_surface_interface,
             &surface_interface, destroy_surface);
 
-    m_qt_compositor->surfaceCreated(id);
+    m_qt_compositor->surfaceCreated(surface->handle());
 
     m_surfaces << surface;
 }
@@ -272,6 +271,7 @@ QImage Compositor::image(uint winId) const
     return QImage();
 }
 
+//XXX: sort this out. Static function?
 uint Compositor::currentTimeMsecs() const
 {
     //### we throw away the time information
@@ -291,19 +291,17 @@ void Compositor::processWaylandEvents()
 
 void Compositor::surfaceResized(Surface *surface, const QSize &size)
 {
-    m_qt_compositor->surfaceMapped(surface->id(), QRect(QPoint(), size));
+    m_qt_compositor->surfaceMapped(surface->handle(), QRect(QPoint(), size));
 }
 
 void Compositor::surfaceDestroyed(Surface *surface)
 {
     m_surfaces.removeOne(surface);
-    m_qt_compositor->surfaceDestroyed(surface->id());
+    m_qt_compositor->surfaceDestroyed(surface->handle());
 }
 
-void Compositor::setInputFocus(uint winId)
+void Compositor::setInputFocus(Surface *surface)
 {
-    Surface *surface = getSurfaceFromWinId(winId);
-
     wl_surface *base = surface ? surface->base() : 0;
 
     ulong time = currentTimeMsecs();
@@ -314,73 +312,7 @@ void Compositor::setInputFocus(uint winId)
 
 void Compositor::surfaceDamaged(Surface *surface, const QRect &rect)
 {
-    surface->commit();
-    m_qt_compositor->surfaceDamaged(surface->id(), rect);
-}
-
-uint32_t toWaylandButton(Qt::MouseButton button)
-{
-    switch (button) {
-    case Qt::LeftButton:
-        return BTN_LEFT;
-    case Qt::RightButton:
-        return BTN_RIGHT;
-    default:
-        return BTN_MIDDLE;
-    }
-}
-
-void Compositor::sendMousePressEvent(uint winId, int x, int y, Qt::MouseButton button)
-{
-    wl_client *client = getClientFromWinId(winId);
-    if (client) {
-        uint32_t time = currentTimeMsecs();
-        wl_client_post_event(client, &m_input.object,
-                             WL_INPUT_DEVICE_BUTTON, time, toWaylandButton(button), 1);
-    }
-    sendMouseMoveEvent(winId, x, y);
-}
-
-void Compositor::sendMouseReleaseEvent(uint winId, int x, int y, Qt::MouseButton button)
-{
-    wl_client *client = getClientFromWinId(winId);
-    if (client)
-        wl_client_post_event(client, &m_input.object,
-                             WL_INPUT_DEVICE_BUTTON, currentTimeMsecs(), toWaylandButton(button), 0);
-    sendMouseMoveEvent(winId, x, y);
-}
-
-void Compositor::sendMouseMoveEvent(uint winId, int x, int y)
-{
-    wl_client *client = getClientFromWinId(winId);
-
-    if (client) {
-        uint32_t time = currentTimeMsecs();
-        wl_input_device_set_pointer_focus(&m_input,
-            getSurfaceFromWinId(winId)->base(), time, x, y, x, y);
-        wl_client_post_event(client, &m_input.object,
-             WL_INPUT_DEVICE_MOTION, time, x, y, x, y);
-    }
-}
-
-void Compositor::sendKeyPressEvent(uint winId, uint code)
-{
-    wl_client *client = getClientFromWinId(winId);
-    if (m_input.keyboard_focus != NULL) {
-        uint32_t time = currentTimeMsecs();
-        wl_client_post_event(client, &m_input.object,
-                             WL_INPUT_DEVICE_KEY, time, code - 8, 1);
-    }
-}
-
-void Compositor::sendKeyReleaseEvent(uint winId, uint code)
-{
-    wl_client *client = getClientFromWinId(winId);
-    if (m_input.keyboard_focus != NULL) {
-        uint32_t time = currentTimeMsecs();
-        wl_client_post_event(client, &m_input.object,
-                             WL_INPUT_DEVICE_KEY, time, code - 8, 0);
-    }
+    m_qt_compositor->surfaceDamaged(surface->handle(), rect);
 }
 
 QWidget * Compositor::topLevelWidget() const
@@ -397,3 +329,8 @@ GraphicsHardwareIntegration * Compositor::graphicsHWIntegration() const
 
 }
 
+wl_input_device * Wayland::Compositor::defaultInputDevice()
+{
+    return &m_input;
+}
+
index b7f23e9..2bf5bc3 100644 (file)
@@ -64,7 +64,7 @@ public:
     ~Compositor();
 
     void frameFinished();
-    void setInputFocus(uint winId);
+    void setInputFocus(Surface *surface);
 
     Surface *getSurfaceFromWinId(uint winId) const;
     struct wl_client *getClientFromWinId(uint winId) const;
@@ -80,13 +80,6 @@ public:
     void surfaceDestroyed(Surface *surface);
     void surfaceDamaged(Surface *surface, const QRect &rect);
 
-    void sendMousePressEvent(uint winId, int x, int y, Qt::MouseButton button);
-    void sendMouseReleaseEvent(uint winId, int x, int y, Qt::MouseButton button);
-    void sendMouseMoveEvent(uint winId, int x, int y);
-
-    void sendKeyPressEvent(uint winId, uint code);
-    void sendKeyReleaseEvent(uint winId, uint code);
-
     uint currentTimeMsecs() const;
 
     QWidget *topLevelWidget() const;
@@ -94,6 +87,7 @@ public:
     GraphicsHardwareIntegration *graphicsHWIntegration() const;
 #endif
 
+    wl_input_device *defaultInputDevice();
 private slots:
     void processWaylandEvents();
 
index e2ba676..f6ee13f 100644 (file)
@@ -40,6 +40,8 @@
 
 #include "wlsurface.h"
 
+#include "../waylandsurface.h"
+
 #include "wlcompositor.h"
 #include "wlshmbuffer.h"
 
@@ -47,6 +49,8 @@
 
 #include <wayland-server.h>
 
+#include <linux/input.h>
+
 #ifdef QT_COMPOSITOR_WAYLAND_GL
 #include "../graphicshardwareintegration.cpp"
 #include <QtGui/QPlatformGLContext>
@@ -58,38 +62,25 @@ class SurfacePrivate
 {
 public:
     SurfacePrivate(struct wl_client *client, Compositor *compositor)
-        : m_client(client)
-        , m_compositor(compositor)
+        : client(client)
+        , compositor(compositor)
     {
-        current.type = State::Invalid;
-        staged.type = State::Invalid;
+        type = WaylandSurface::Invalid;
 #ifdef QT_COMPOSITOR_WAYLAND_GL
-        staged.texture_id = current.texture_id = 0;
+        texture_id = 0;
 #endif
     }
 
-    struct State {
-        enum BufferType {
-            Shm,
-            Texture,
-            Invalid
-        };
-
-        BufferType type;
+    WaylandSurface::Type type;
+    QRect rect;
+    struct wl_client *client;
+    Compositor *compositor;
+    WaylandSurface *qtSurface;
 
-        ShmBuffer *shm_buffer;
+    ShmBuffer *shm_buffer;
 #ifdef QT_COMPOSITOR_WAYLAND_GL
-        GLuint texture_id;
+    GLuint texture_id;
 #endif
-        QRect rect;
-
-    };
-
-    State current;
-    State staged;
-
-    struct wl_client *m_client;
-    Compositor *m_compositor;
 };
 
 
@@ -161,30 +152,33 @@ Surface::Surface(struct wl_client *client, Compositor *compositor)
 {
     base()->client = client;
     wl_list_init(&base()->destroy_listener_list);
+    d_ptr->qtSurface = new WaylandSurface(this);
+
 }
 
 Surface::~Surface()
 {
     Q_D(Surface);
-    d->m_compositor->surfaceDestroyed(this);
+    d->compositor->surfaceDestroyed(this);
 }
-void Surface::damage(const QRect &rect)
+
+WaylandSurface::Type Surface::type() const
 {
-    Q_D(Surface);
-    d->m_compositor->surfaceDamaged(this, rect);
+    Q_D(const Surface);
+    return d->type;
 }
 
-bool Surface::hasImage() const
+void Surface::damage(const QRect &rect)
 {
-    Q_D(const Surface);
-    return d->current.type == SurfacePrivate::State::Shm;
+    Q_D(Surface);
+    d->compositor->surfaceDamaged(this, rect);
 }
 
 QImage Surface::image() const
 {
     Q_D(const Surface);
-    if (d->current.type == SurfacePrivate::State::Shm) {
-        return d->current.shm_buffer->image();
+    if (d->type == WaylandSurface::Shm) {
+        return d->shm_buffer->image();
     }
     return QImage();
 }
@@ -194,53 +188,109 @@ QImage Surface::image() const
 void Surface::attachHWBuffer(struct wl_buffer *buffer)
 {
     Q_D(Surface);
-    d->staged.type = SurfacePrivate::State::Texture;
-    d->current.type = d->staged.type;
+    d->type = WaylandSurface::Texture;
 
     //make current for the topLevel. We could have used the eglContext,
     //but then we would need to handle eglSurfaces as well.
-    d->m_compositor->topLevelWidget()->platformWindow()->glContext()->makeCurrent();
-
-    glDeleteTextures(1,&d->staged.texture_id);
+    d->compositor->topLevelWidget()->platformWindow()->glContext()->makeCurrent();
 
-    d->staged.texture_id = d->m_compositor->graphicsHWIntegration()->createTextureFromBuffer(buffer);
-    d->m_compositor->surfaceResized(this,QSize(buffer->width,buffer->height));
-}
+    glDeleteTextures(1,&d->texture_id);
 
-bool Surface::hasTexture() const
-{
-    Q_D(const Surface);
-    return (d->current.type == SurfacePrivate::State::Texture);
+    d->texture_id = d->compositor->graphicsHWIntegration()->createTextureFromBuffer(buffer);
+    d->compositor->surfaceResized(this,QSize(buffer->width,buffer->height));
 }
 
 GLuint Surface::textureId() const
 {
     Q_D(const Surface);
-    return d->current.texture_id;
+    return d->texture_id;
 }
 #endif // QT_COMPOSITOR_WAYLAND_GL
 
 void Surface::attachShm(Wayland::ShmBuffer *shm_buffer)
 {
     Q_D(Surface);
-    d->current.shm_buffer = d->current.shm_buffer = shm_buffer;
-    d->current.type = d->staged.type = SurfacePrivate::State::Shm;
-    d->m_compositor->surfaceResized(this, shm_buffer->size());
+    d->shm_buffer = shm_buffer;
+    d->type = WaylandSurface::Shm;
+    d->compositor->surfaceResized(this, shm_buffer->size());
 }
 
 
 void Surface::mapTopLevel()
 {
     Q_D(Surface);
-    d->staged.rect = QRect(0, 0, 200, 200);
+    d->rect = QRect(0, 0, 200, 200);
 }
 
-void Surface::commit()
+WaylandSurface * Surface::handle() const
+{
+    Q_D(const Surface);
+    return d->qtSurface;
+}
+
+uint32_t toWaylandButton(Qt::MouseButton button)
+{
+    switch (button) {
+    case Qt::LeftButton:
+        return BTN_LEFT;
+    case Qt::RightButton:
+        return BTN_RIGHT;
+    default:
+        return BTN_MIDDLE;
+    }
+}
+
+void Surface::sendMousePressEvent(int x, int y, Qt::MouseButton button)
+{
+    Q_D(Surface);
+    if (d->client) {
+        uint32_t time = d->compositor->currentTimeMsecs();
+        wl_client_post_event(d->client, &d->compositor->defaultInputDevice()->object,
+                             WL_INPUT_DEVICE_BUTTON, time, toWaylandButton(button), 1);
+    }
+    sendMouseMoveEvent(x, y);
+}
+
+void Surface::sendMouseReleaseEvent(int x, int y, Qt::MouseButton button)
+{
+    Q_D(Surface);
+    if (d->client)
+        wl_client_post_event(d->client, &d->compositor->defaultInputDevice()->object,
+                             WL_INPUT_DEVICE_BUTTON, d->compositor->currentTimeMsecs(), toWaylandButton(button), 0);
+    sendMouseMoveEvent(x, y);
+}
+
+void Surface::sendMouseMoveEvent(int x, int y)
 {
     Q_D(Surface);
-    SurfacePrivate::State tmpState = d->current;
-    d->current = d->staged;
-    d->staged = tmpState;
+    if (d->client) {
+        uint32_t time = d->compositor->currentTimeMsecs();
+        wl_input_device_set_pointer_focus(d->compositor->defaultInputDevice(),
+            base(), time, x, y, x, y);
+        wl_client_post_event(d->client, &d->compositor->defaultInputDevice()->object,
+             WL_INPUT_DEVICE_MOTION, time, x, y, x, y);
+    }
+}
+
+void Surface::sendKeyPressEvent(uint code)
+{
+    Q_D(Surface);
+    if (d->compositor->defaultInputDevice()->keyboard_focus != NULL) {
+        uint32_t time = d->compositor->currentTimeMsecs();
+        wl_client_post_event(d->client, &d->compositor->defaultInputDevice()->object,
+                             WL_INPUT_DEVICE_KEY, time, code - 8, 1);
+    }
+
+}
+
+void Surface::sendKeyReleaseEvent(uint code)
+{
+    Q_D(Surface);
+    if (d->compositor->defaultInputDevice()->keyboard_focus != NULL) {
+        uint32_t time = d->compositor->currentTimeMsecs();
+        wl_client_post_event(d->client, &d->compositor->defaultInputDevice()->object,
+                             WL_INPUT_DEVICE_KEY, time, code - 8, 0);
+    }
 }
 
 }
index 57470d9..1d312ea 100644 (file)
@@ -51,6 +51,8 @@
 #include <QtCore/QMetaType>
 #include <QtGui/private/qapplication_p.h>
 
+#include "../waylandsurface.h"
+
 #ifdef QT_COMPOSITOR_WAYLAND_GL
 #define GL_GLEXT_PROTOTYPES
 #include <GLES2/gl2.h>
@@ -71,6 +73,8 @@ public:
     Surface(struct wl_client *client, Compositor *compositor);
     ~Surface();
 
+    WaylandSurface::Type type() const;
+
     uint id() const { return base()->resource.object.id; }
 #ifdef QT_COMPOSITOR_WAYLAND_GL
     void attachHWBuffer(struct wl_buffer *buffer);
@@ -79,18 +83,23 @@ public:
 
     void mapTopLevel();
 
-    void commit();
-
     void damage(const QRect &rect);
 
     QImage image() const;
-    bool hasImage() const;
 
 #ifdef QT_COMPOSITOR_WAYLAND_GL
-    bool hasTexture() const;
     GLuint textureId() const;
 #endif
 
+    void sendMousePressEvent(int x, int y, Qt::MouseButton button);
+    void sendMouseReleaseEvent(int x, int y, Qt::MouseButton button);
+    void sendMouseMoveEvent(int x, int y);
+
+    void sendKeyPressEvent(uint code);
+    void sendKeyReleaseEvent(uint code);
+
+
+    WaylandSurface *handle() const;
 protected:
     QScopedPointer<SurfacePrivate> d_ptr;
 private:
index 1d6a3cc..1ec6c23 100644 (file)
@@ -25,6 +25,7 @@ use_pkgconfig {
 
 SOURCES += $$PWD/qtcompositor.cpp \
         $$PWD/graphicshardwareintegration.cpp \
+        $$PWD/waylandsurface.cpp \
         $$PWD/private/wlcompositor.cpp \
         $$PWD/private/wlsurface.cpp \
         $$PWD/private/wloutput.cpp \
@@ -34,6 +35,7 @@ SOURCES += $$PWD/qtcompositor.cpp \
 
 HEADERS += $$PWD/qtcompositor.h \
         $$PWD/graphicshardwareintegration.h \
+        $$PWD/waylandsurface.h \
         $$PWD/private/wlcompositor.h \
         $$PWD/private/wlsurface.h \
         $$PWD/private/wloutput.h \
index 79b1bfb..bae0b48 100644 (file)
@@ -60,34 +60,10 @@ void WaylandCompositor::frameFinished()
     m_compositor->frameFinished();
 }
 
-void WaylandCompositor::setInputFocus(uint winId)
+void WaylandCompositor::setInputFocus(WaylandSurface *surface)
 {
-    m_compositor->setInputFocus(winId);
-}
-
-void WaylandCompositor::sendMousePressEvent(uint winId, int x, int y, Qt::MouseButton button)
-{
-    m_compositor->sendMousePressEvent(winId, x, y, button);
-}
-
-void WaylandCompositor::sendMouseReleaseEvent(uint winId, int x, int y, Qt::MouseButton button)
-{
-    m_compositor->sendMouseReleaseEvent(winId, x, y, button);
-}
-
-void WaylandCompositor::sendMouseMoveEvent(uint winId, int x, int y)
-{
-    m_compositor->sendMouseMoveEvent(winId, x, y);
-}
-
-void WaylandCompositor::sendKeyPressEvent(uint winId, uint code)
-{
-    m_compositor->sendKeyPressEvent(winId, code);
-}
-
-void WaylandCompositor::sendKeyReleaseEvent(uint winId, uint code)
-{
-    m_compositor->sendKeyReleaseEvent(winId, code);
+    Wayland::Surface *surfaceImpl = surface? surface->handle():0;
+    m_compositor->setInputFocus(surfaceImpl);
 }
 
 void WaylandCompositor::setDirectRenderWinId(uint winId)
@@ -100,28 +76,6 @@ uint WaylandCompositor::directRenderWinId() const
     return 0;
 }
 
-bool WaylandCompositor::hasImage(uint winId) const
-{
-    return m_compositor->getSurfaceFromWinId(winId)->hasImage();
-}
-
-const QImage WaylandCompositor::image(uint winId) const
-{
-    return m_compositor->image(winId);
-}
-
-#ifdef QT_COMPOSITOR_WAYLAND_GL
-GLuint WaylandCompositor::textureId(uint winId) const
-{
-    return m_compositor->getSurfaceFromWinId(winId)->textureId();
-}
-
-bool WaylandCompositor::hasTexture(uint winId) const
-{
-    return m_compositor->getSurfaceFromWinId(winId)->hasTexture();
-}
-#endif
-
 QWidget * WaylandCompositor::topLevelWidget() const
 {
     return m_toplevel_widget;
index c940e0c..eb96065 100644 (file)
@@ -52,6 +52,7 @@
 #endif
 
 class QWidget;
+class WaylandSurface;
 
 namespace Wayland
 {
@@ -64,34 +65,19 @@ public:
     WaylandCompositor(QWidget *topLevelWidget = 0);
     virtual ~WaylandCompositor();
 
-    void sendMousePressEvent(uint winId, int x, int y, Qt::MouseButton button);
-    void sendMouseReleaseEvent(uint winId, int x, int y, Qt::MouseButton button);
-    void sendMouseMoveEvent(uint winId, int x, int y);
-
-    void sendKeyPressEvent(uint winId, uint code);
-    void sendKeyReleaseEvent(uint winId, uint code);
-
     void frameFinished();
 
-    void setInputFocus(uint winId);
+    void setInputFocus(WaylandSurface *surface);
 
     void setDirectRenderWinId(uint winId);
     uint directRenderWinId() const;
 
     QWidget *topLevelWidget()const;
 
-    bool hasImage(uint winId) const;
-    const QImage image(uint winId) const;
-
-#ifdef QT_COMPOSITOR_WAYLAND_GL
-    bool hasTexture(uint winId) const;
-    GLuint textureId(uint winId) const;
-#endif
-
-    virtual void surfaceCreated(uint winId) = 0;
-    virtual void surfaceDestroyed(uint winId) = 0;
-    virtual void surfaceMapped(uint winId, const QRect &rect) = 0;
-    virtual void surfaceDamaged(uint winId, const QRect &rect) = 0;
+    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:
diff --git a/src/qt-compositor/waylandsurface.cpp b/src/qt-compositor/waylandsurface.cpp
new file mode 100644 (file)
index 0000000..e32dabd
--- /dev/null
@@ -0,0 +1,89 @@
+#include "waylandsurface.h"
+
+#include "private/wlsurface.h"
+
+class WaylandSurfacePrivate
+{
+public:
+    WaylandSurfacePrivate(Wayland::Surface *srfc)
+        : surface(srfc)
+    {}
+
+    Wayland::Surface *surface;
+    QRect geometry;
+};
+
+WaylandSurface::WaylandSurface(Wayland::Surface *surface)
+    : d_ptr(new WaylandSurfacePrivate(surface))
+{
+
+}
+
+WaylandSurface::Type WaylandSurface::type() const
+{
+    Q_D(const WaylandSurface);
+    return d->surface->type();
+}
+
+QRect WaylandSurface::geometry() const
+{
+    Q_D(const WaylandSurface);
+    return d->geometry;
+}
+
+void WaylandSurface::setGeometry(const QRect &geometry)
+{
+    Q_D(WaylandSurface);
+    d->geometry = geometry;
+}
+
+QImage WaylandSurface::image() const
+{
+    Q_D(const WaylandSurface);
+    return d->surface->image();
+}
+
+#ifdef QT_COMPOSITOR_WAYLAND_GL
+GLuint WaylandSurface::texture() const
+{
+    Q_D(const WaylandSurface);
+    return d->surface->textureId();
+}
+#endif //QT_COMPOSITOR_WAYLAND_GL
+
+Wayland::Surface * WaylandSurface::handle() const
+{
+    Q_D(const WaylandSurface);
+    return d->surface;
+}
+
+void WaylandSurface::sendMousePressEvent(int x, int y, Qt::MouseButton button)
+{
+    Q_D(WaylandSurface);
+    d->surface->sendMousePressEvent(x,y,button);
+}
+
+void WaylandSurface::sendMouseReleaseEvent(int x, int y, Qt::MouseButton button)
+{
+    Q_D(WaylandSurface);
+    d->surface->sendMouseReleaseEvent(x,y,button);
+}
+
+void WaylandSurface::sendMouseMoveEvent(int x, int y)
+{
+    Q_D(WaylandSurface);
+    d->surface->sendMouseMoveEvent(x,y);
+}
+
+void WaylandSurface::sendKeyPressEvent(uint code)
+{
+    Q_D(WaylandSurface);
+    d->surface->sendKeyPressEvent(code);
+}
+
+void WaylandSurface::sendKeyReleaseEvent(uint code)
+{
+    Q_D(WaylandSurface);
+    d->surface->sendKeyReleaseEvent(code);
+}
+
diff --git a/src/qt-compositor/waylandsurface.h b/src/qt-compositor/waylandsurface.h
new file mode 100644 (file)
index 0000000..4ecfda0
--- /dev/null
@@ -0,0 +1,54 @@
+#ifndef WAYLANDSURFACE_H
+#define WAYLANDSURFACE_H
+
+#include <QtCore/QScopedPointer>
+#include <QtGui/QImage>
+
+#ifdef QT_COMPOSITOR_WAYLAND_GL
+#include <QtOpenGL/QGLContext>
+#endif
+
+class WaylandSurfacePrivate;
+
+namespace Wayland {
+class Surface;
+}
+
+class WaylandSurface
+{
+    Q_DECLARE_PRIVATE(WaylandSurface)
+public:
+
+    enum Type {
+        Invalid,
+        Shm,
+        Texture
+    };
+
+    WaylandSurface(Wayland::Surface *surface);
+
+    Type type() const;
+
+    void setGeometry(const QRect &geometry);
+    QRect geometry() const;
+
+    QImage image() const;
+#ifdef QT_COMPOSITOR_WAYLAND_GL
+    GLuint texture() const;
+#endif
+
+    void sendMousePressEvent(int x, int y, Qt::MouseButton button);
+    void sendMouseReleaseEvent(int x, int y, Qt::MouseButton button);
+    void sendMouseMoveEvent(int x, int y);
+
+    void sendKeyPressEvent(uint code);
+    void sendKeyReleaseEvent(uint code);
+
+    Wayland::Surface *handle() const;
+protected:
+    QScopedPointer<WaylandSurfacePrivate> d_ptr;
+private:
+    Q_DISABLE_COPY(WaylandSurface)
+};
+
+#endif // WAYLANDSURFACE_H