INCLUDEPATH += $$PWD
-HEADERS += $$PWD/waylandexport.h
+HEADERS += \
+ $$PWD/waylandexport.h \
+ $$PWD/waylandobject.h \
+ $$PWD/waylandresourcecollection.h \
+SOURCES += \
+ $$PWD/waylandresourcecollection.cpp \
**
****************************************************************************/
-#ifndef WL_OBJECT_H
-#define WL_OBJECT_H
+#ifndef WAYLAND_OBJECT_H
+#define WAYLAND_OBJECT_H
#include <wayland-server.h>
}
-#endif //WL_OBJECT_H
+#endif //WAYLAND_OBJECT_H
--- /dev/null
+/****************************************************************************
+**
+** This file is part of QtCompositor**
+**
+** Copyright © 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+**
+** Contact: Nokia Corporation qt-info@nokia.com
+**
+** You may use this file under the terms of the BSD license as follows:
+**
+** Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+**
+** Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+**
+** Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in the
+** documentation and/or other materials provided with the distribution.
+**
+** Neither the name of Nokia Corporation and its Subsidiary(-ies) nor the
+** names of its contributors may be used to endorse or promote products
+** derived from this software without specific prior written permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+**
+****************************************************************************/
+
+#include "waylandresourcecollection.h"
+
+#include <QtCore/qglobal.h>
+
+namespace Wayland {
+
+ResourceCollection::ResourceCollection()
+{
+ wl_list_init(&client_resources);
+}
+
+ResourceCollection::~ResourceCollection()
+{
+
+}
+
+void ResourceCollection::registerResource(struct wl_resource *resource)
+{
+ wl_list_insert(&client_resources,&resource->link);
+ struct wl_listener *listener = new struct wl_listener;
+ listener->func = ResourceCollection::destroy_listener_func;
+ wl_list_insert(&resource->destroy_listener_list,&listener->link);
+}
+
+struct wl_resource *ResourceCollection::resourceForClient(wl_client *client) const
+{
+ struct wl_resource *resource;
+ wl_list_for_each(resource,&client_resources, link) {
+ if (resource->client == client) {
+ return resource;
+ }
+ }
+ return 0;
+
+}
+
+bool ResourceCollection::resourceListIsEmpty() const
+{
+ return wl_list_empty(const_cast<struct wl_list *>(&client_resources));
+}
+
+void ResourceCollection::destroy_listener_func(struct wl_listener *listener,
+ wl_resource *resource,
+ uint32_t time)
+{
+ Q_UNUSED(time);
+ wl_list_remove(&resource->link);
+ delete listener;
+}
+
+
+}
--- /dev/null
+/****************************************************************************
+**
+** This file is part of QtCompositor**
+**
+** Copyright © 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+**
+** Contact: Nokia Corporation qt-info@nokia.com
+**
+** You may use this file under the terms of the BSD license as follows:
+**
+** Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+**
+** Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+**
+** Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in the
+** documentation and/or other materials provided with the distribution.
+**
+** Neither the name of Nokia Corporation and its Subsidiary(-ies) nor the
+** names of its contributors may be used to endorse or promote products
+** derived from this software without specific prior written permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+**
+****************************************************************************/
+
+#ifndef WAYLAND_RESOURCE_OBJECT_H
+#define WAYLAND_RESOURCE_OBJECT_H
+
+#include <wayland-server.h>
+
+namespace Wayland {
+
+class ResourceCollection
+{
+public:
+ ResourceCollection();
+ virtual ~ResourceCollection();
+ void registerResource(struct wl_resource *resource);
+ struct wl_resource *resourceForClient(struct wl_client *client) const;
+ bool resourceListIsEmpty() const;
+
+protected:
+ struct wl_list client_resources;
+private:
+ static void destroy_listener_func(struct wl_listener *listener,
+ struct wl_resource *resource, uint32_t time);
+
+};
+
+}
+
+#endif //WAYLAND_RESOURCE_OBJECT_H
+++ /dev/null
-INCLUDEPATH += $$PWD
-
-HEADERS += \
- $$PWD/waylandobject.h
-
#include "wlcompositor.h"
-#include "waylandobject.h"
#include "wldisplay.h"
#include "wlshmbuffer.h"
#include "wlsurface.h"
m_input = new InputDevice(this);
m_data_device_manager = new DataDeviceManager(this);
- wl_display_add_global(m_display->handle(),&wl_output_interface,m_output.base(),Output::output_bind_func);
+ wl_display_add_global(m_display->handle(),&wl_output_interface, &m_output,Output::output_bind_func);
- wl_display_add_global(m_display->handle(), &wl_shell_interface, m_shell.base(), Shell::bind_func);
+ wl_display_add_global(m_display->handle(), &wl_shell_interface, &m_shell, Shell::bind_func);
if (wl_display_add_socket(m_display->handle(), qt_compositor->socketName())) {
QList<struct wl_client *> prevClientList = clients();
m_surfaces << surface;
if (!prevClientList.contains(client)) {
- m_windowManagerIntegration->setScreenOrientation(client, m_output.base(), m_orientation);
+ m_windowManagerIntegration->setScreenOrientation(client, m_output.resourceForClient(client), m_orientation);
emit clientAdded(client);
}
QList<struct wl_client*> clientList = clients();
for (int i = 0; i < clientList.length(); ++i) {
struct wl_client *client = clientList.at(i);
- m_windowManagerIntegration->setScreenOrientation(client, m_output.base(), orientation);
+ m_windowManagerIntegration->setScreenOrientation(client, m_output.resourceForClient(client), orientation);
}
}
: m_compositor(compositor)
, m_current_selection_source(0)
{
- wl_display_add_global(compositor->wl_display(), &wl_data_device_manager_interface, base(), DataDeviceManager::bind_func_drag);
+ wl_display_add_global(compositor->wl_display(), &wl_data_device_manager_interface, this, DataDeviceManager::bind_func_drag);
}
void DataDeviceManager::setCurrentSelectionSource(DataSource *source)
#ifndef WLDATADEVICEMANAGER_H
#define WLDATADEVICEMANAGER_H
-#include "waylandobject.h"
-
#include "wlcompositor.h"
#include <QtCore/QList>
class DataDevice;
class DataSource;
-class DataDeviceManager : public Object<struct wl_object>
+class DataDeviceManager
{
public:
DataDeviceManager(Compositor *compositor);
struct wl_resource *DataOffer::addDataDeviceResource(struct wl_resource *data_device_resource)
{
- for (int i = 0; i < m_clients_data_resource.size(); i++) {
- if (m_clients_data_resource.at(i)->client == data_device_resource->client) {
- qDebug() << "This should not happen, the client tries to add twice to a data offer";
- return 0;
- }
+ if (resourceForClient(data_device_resource->client)) {
+ qDebug() << "This should not happen, the client tries to add twice to a data offer";
+ return 0;
}
struct wl_resource *new_object =
wl_client_new_object(data_device_resource->client,&wl_data_offer_interface,&data_interface,this);
wl_resource_post_event(data_device_resource,WL_DATA_DEVICE_DATA_OFFER,new_object);
- m_clients_data_resource.append(new_object);
+ registerResource(new_object);
QList<QByteArray> offer_list = m_data_source->offerList();
for (int i = 0; i < offer_list.size(); i++) {
wl_resource_post_event(new_object, WL_DATA_OFFER_OFFER, offer_list.at(i).constData());
return new_object;
}
-void DataOffer::removeClient(struct wl_client *client)
-{
- for (int i = 0; i < m_clients_data_resource.size(); i++) {
- struct wl_resource *resource = m_clients_data_resource.at(i);
- if (resource->client == client) {
- wl_resource_destroy(resource,Compositor::currentTimeMsecs());
- m_clients_data_resource.removeAt(i);
- break;
- }
- }
-}
-
const struct wl_data_offer_interface DataOffer::data_interface = {
DataOffer::accept,
DataOffer::receive,
void DataOffer::destroy(wl_client *client, wl_resource *resource)
{
+ Q_UNUSED(client);
qDebug() << "dataOFFER DESTROY!";
DataOffer *data_offer = static_cast<DataOffer *>(resource->data);
- data_offer->removeClient(client);
- if (data_offer->m_clients_data_resource.size() == 0) {
+ if (data_offer->resourceListIsEmpty()) {
delete data_offer;
}
}
#include "wldatasource.h"
+#include "waylandresourcecollection.h"
+
namespace Wayland
{
-class DataOffer
+class DataOffer : public ResourceCollection
{
public:
DataOffer(DataSource *data_source);
~DataOffer();
struct wl_resource *addDataDeviceResource(struct wl_resource *client_resource);
- void removeClient(struct wl_client *client);
private:
DataSource *m_data_source;
- QList<struct wl_resource *> m_clients_data_resource;
-
static void accept(struct wl_client *client,
struct wl_resource *resource,
uint32_t time,
static ShmBuffer *currentCursor;
InputDevice::InputDevice(Compositor *compositor)
+ : m_compositor(compositor)
{
wl_input_device_init(base());
wl_display_add_global(compositor->wl_display(),&wl_input_device_interface,this,InputDevice::bind_func);
struct wl_buffer *buffer = reinterpret_cast<struct wl_buffer *>(buffer_resource);
qDebug() << "Client input device attach" << client << buffer << x << y;
-// Compositor *compositor = wayland_cast<Compositor *>(device_base->compositor);
+ InputDevice *inputDevice = wayland_cast<InputDevice *>(device_base);
ShmBuffer *shmBuffer = static_cast<ShmBuffer *>(buffer->user_data);
if (shmBuffer) {
-// compositor->qtCompositor()->changeCursor(shmBuffer->image(), x, y);
+ inputDevice->m_compositor->qtCompositor()->changeCursor(shmBuffer->image(), x, y);
currentCursor = shmBuffer;
}
}
#define WLINPUTDEVICE_H
#include "waylandobject.h"
+
+#include <stdint.h>
+
#include <QtCore/QList>
namespace Wayland {
static void destroy_resource(struct wl_resource *resource);
private:
+ Compositor *m_compositor;
QList<DataDevice *>m_data_devices;
};
Output *output = static_cast<Output *>(data);
struct wl_resource *resource = wl_client_add_object(client,&wl_output_interface,0,id,data);
+ output->registerResource(resource);
wl_resource_post_event(resource, WL_OUTPUT_GEOMETRY, 0, 0,
output->size().width(), output->size().height(),0,"","");
#ifndef WL_OUTPUT_H
#define WL_OUTPUT_H
-#include "waylandobject.h"
+#include "waylandresourcecollection.h"
#include <QtCore/QRect>
namespace Wayland {
-class Output : public Object<struct wl_object>
+class Output : public ResourceCollection
{
public:
Output();
#ifndef WLSHELL_H
#define WLSHELL_H
-#include "waylandobject.h"
+#include "waylandresourcecollection.h"
namespace Wayland {
class Compositor;
-class Shell : public Object<struct wl_object>
+class Shell
{
public:
Shell(Compositor *compositor);
#include "waylandexport.h"
-#include "waylandobject.h"
#include "wlshmbuffer.h"
#include "waylandsurface.h"
+#include "waylandobject.h"
+
#include <QtCore/QRect>
#include <QtGui/QImage>
#include "waylandwindowmanagerintegration.h"
-#include "waylandobject.h"
#include "wayland_wrapper/wldisplay.h"
#include "wayland_wrapper/wlcompositor.h"
void WindowManagerServerIntegration::setVisibilityOnScreen(wl_client *client, bool visible)
{
- struct wl_resource *win_mgr_resource = getWindowManagerResourceForClient(client);
+ struct wl_resource *win_mgr_resource = resourceForClient(client);
wl_resource_post_event(win_mgr_resource,WL_WINDOWMANAGER_CLIENT_ONSCREEN_VISIBILITY,visible);
}
-void WindowManagerServerIntegration::setScreenOrientation(wl_client *client, wl_object *output, Qt::ScreenOrientation orientation)
+void WindowManagerServerIntegration::setScreenOrientation(wl_client *client, wl_resource *output_resource, Qt::ScreenOrientation orientation)
{
- struct wl_resource *win_mgr_resource = getWindowManagerResourceForClient(client);
- wl_resource_post_event(win_mgr_resource,WL_WINDOWMANAGER_SET_SCREEN_ROTATION,output, qint32(orientation));
+ struct wl_resource *win_mgr_resource = resourceForClient(client);
+ wl_resource_post_event(win_mgr_resource,WL_WINDOWMANAGER_SET_SCREEN_ROTATION,output_resource, qint32(orientation));
}
// client -> server
data.data = (void*) byteValue.constData();
data.alloc = 0;
- struct wl_resource *win_mgr_resource = getWindowManagerResourceForClient(client);
+ struct wl_resource *win_mgr_resource = resourceForClient(client);
wl_resource_post_event(win_mgr_resource,WL_WINDOWMANAGER_SET_GENERIC_PROPERTY,surface, name.toLatin1().constData(),&data);
}
emit clientAuthenticated(client);
}
-struct wl_resource *WindowManagerServerIntegration::getWindowManagerResourceForClient(wl_client *client) const
-{
- for (int i = 0; i < m_client_resources.size(); i++) {
- if (m_client_resources.at(i)->client == client) {
- return m_client_resources.at(i);
- }
- }
- return 0;
-}
-
void WindowManagerServerIntegration::bind_func(struct wl_client *client, void *data,
uint32_t version, uint32_t id)
{
Q_UNUSED(version);
WindowManagerServerIntegration *win_mgr = static_cast<WindowManagerServerIntegration *>(data);
struct wl_resource *resource = wl_client_add_object(client,&wl_windowmanager_interface,&windowmanager_interface,id,data);
- resource->destroy = destroy_resource;
- win_mgr->m_client_resources.append(resource);
+ win_mgr->registerResource(resource);
}
-void WindowManagerServerIntegration::destroy_resource(wl_resource *win_mgr_integration_resource)
-{
- WindowManagerServerIntegration *win_mgr = static_cast<WindowManagerServerIntegration *>(win_mgr_integration_resource->data);
- win_mgr->m_client_resources.removeOne(win_mgr_integration_resource);
- free(win_mgr_integration_resource);
-}
void WindowManagerServerIntegration::map_client_to_process(struct wl_client *client,
struct wl_resource *window_mgr_resource,
#ifndef WAYLANDWINDOWMANAGERINTEGRATION_H
#define WAYLANDWINDOWMANAGERINTEGRATION_H
+#include "waylandexport.h"
+#include "waylandresourcecollection.h"
+
#include <qwindowdefs.h>
#include <stdint.h>
-#include "waylandexport.h"
-
#include <QObject>
#include <QMap>
#include <QVariant>
class WindowManagerObject;
class WaylandManagedClient;
-class Q_COMPOSITOR_EXPORT WindowManagerServerIntegration : public QObject
+class Q_COMPOSITOR_EXPORT WindowManagerServerIntegration : public QObject, private Wayland::ResourceCollection
{
Q_OBJECT
public:
WaylandManagedClient *managedClient(wl_client *client) const;
void setVisibilityOnScreen(wl_client *client, bool visible);
- void setScreenOrientation(wl_client *client, wl_object *output, Qt::ScreenOrientation orientationInDegrees);
+ void setScreenOrientation(wl_client *client, struct wl_resource *output_resource, Qt::ScreenOrientation orientationInDegrees);
void updateWindowProperty(wl_client *client, struct wl_surface *surface, const char *name, struct wl_array *value);
void setWindowProperty(wl_client *client, struct wl_surface *surface, const QString &name, const QVariant &value);
private:
QMap<wl_client*, WaylandManagedClient*> m_managedClients;
- QList<struct wl_resource *>m_client_resources;
- struct wl_resource *getWindowManagerResourceForClient(struct wl_client *client) const;
-
static void bind_func(struct wl_client *client, void *data,
uint32_t version, uint32_t id);
This version of Qt-Compositor is checked against the following sha1 from the
Wayland repository:
-58bb064afa3bfc706e3b30dd170804235aa272ea
+187eace6139754eae58a21303c808a270f70dc3f