Skip to content
Snippets Groups Projects
Commit b3b4778c authored by Johan Klokkhammer Helsing's avatar Johan Klokkhammer Helsing Committed by Johan Helsing
Browse files

Make wl_shell and xdg_shell use the QWaylandShellIntegration interface


This simplifies the code in QWaylandDisplay and hopefully makes it easier to
implement a prioritized shell selection mechanism later.

Change-Id: I2bb3a13f8acedb60a6606cb3a8b5b228095eadf9
Reviewed-by: default avatarGiulio Camuffo <giulio.camuffo@kdab.com>
parent 1db3dee9
No related branches found
No related tags found
No related merge requests found
......@@ -59,8 +59,10 @@ SOURCES += qwaylandintegration.cpp \
qwaylanddatasource.cpp \
qwaylandshellsurface.cpp \
qwaylandwlshellsurface.cpp \
qwaylandwlshellintegration.cpp \
qwaylandxdgshell.cpp \
qwaylandxdgsurface.cpp \
qwaylandxdgshellintegration.cpp \
qwaylandextendedsurface.cpp \
qwaylandsubsurface.cpp \
qwaylandtouch.cpp \
......@@ -92,8 +94,10 @@ HEADERS += qwaylandintegration_p.h \
qwaylanddatasource_p.h \
qwaylandshellsurface_p.h \
qwaylandwlshellsurface_p.h \
qwaylandwlshellintegration_p.h \
qwaylandxdgshell_p.h \
qwaylandxdgsurface_p.h \
qwaylandxdgshellintegration_p.h \
qwaylandextendedsurface_p.h \
qwaylandsubsurface_p.h \
qwaylandtouch_p.h \
......
......@@ -77,16 +77,8 @@ struct wl_surface *QWaylandDisplay::createSurface(void *handle)
QWaylandShellSurface *QWaylandDisplay::createShellSurface(QWaylandWindow *window)
{
if (mWaylandIntegration->shellIntegration())
return mWaylandIntegration->shellIntegration()->createShellSurface(window);
if (shellXdg()) {
return new QWaylandXdgSurface(shellXdg()->get_xdg_surface(window->object()), window);
} else if (shell()) {
return new QWaylandWlShellSurface(shell()->get_shell_surface(window->object()), window);
}
return Q_NULLPTR;
Q_ASSERT(mWaylandIntegration->shellIntegration());
return mWaylandIntegration->shellIntegration()->createShellSurface(window);
}
struct ::wl_region *QWaylandDisplay::createRegion(const QRegion &qregion)
......@@ -248,11 +240,6 @@ void QWaylandDisplay::registry_global(uint32_t id, const QString &interface, uin
mCompositor.init(registry, id, mCompositorVersion);
} else if (interface == QStringLiteral("wl_shm")) {
mShm = static_cast<struct wl_shm *>(wl_registry_bind(registry, id, &wl_shm_interface,1));
} else if (interface == QStringLiteral("xdg_shell")
&& qEnvironmentVariableIsSet("QT_WAYLAND_USE_XDG_SHELL")) {
mShellXdg.reset(new QWaylandXdgShell(registry,id));
} else if (interface == QStringLiteral("wl_shell")){
mShell.reset(new QtWayland::wl_shell(registry, id, 1));
} else if (interface == QStringLiteral("wl_seat")) {
QWaylandInputDevice *inputDevice = mWaylandIntegration->createInputDevice(this, version, id);
mInputDevices.append(inputDevice);
......@@ -301,6 +288,15 @@ void QWaylandDisplay::registry_global_remove(uint32_t id)
}
}
bool QWaylandDisplay::hasRegistryGlobal(const QString &interfaceName)
{
Q_FOREACH (const RegistryGlobal &global, mGlobals)
if (global.interface == interfaceName)
return true;
return false;
}
void QWaylandDisplay::addRegistryListener(RegistryListener listener, void *data)
{
Listener l = { listener, data };
......@@ -356,11 +352,6 @@ void QWaylandDisplay::forceRoundTrip()
wl_callback_destroy(callback);
}
QtWayland::xdg_shell *QWaylandDisplay::shellXdg()
{
return mShellXdg.data();
}
bool QWaylandDisplay::supportsWindowDecoration() const
{
static bool disabled = qgetenv("QT_WAYLAND_DISABLE_WINDOWDECORATION").toInt();
......
......@@ -128,9 +128,6 @@ public:
QtWayland::wl_compositor *compositor() { return &mCompositor; }
int compositorVersion() const { return mCompositorVersion; }
QtWayland::wl_shell *shell() { return mShell.data(); }
QtWayland::xdg_shell *shellXdg();
QList<QWaylandInputDevice *> inputDevices() const { return mInputDevices; }
QWaylandInputDevice *defaultInputDevice() const;
QWaylandInputDevice *currentInputDevice() const { return defaultInputDevice(); }
......@@ -151,6 +148,7 @@ public:
: id(id_), interface(interface_), version(version_), registry(registry_) { }
};
QList<RegistryGlobal> globals() const { return mGlobals; }
bool hasRegistryGlobal(const QString &interfaceName);
/* wl_registry_add_listener does not add but rather sets a listener, so this function is used
* to enable many listeners at once. */
......@@ -193,8 +191,6 @@ private:
struct wl_display *mDisplay;
QtWayland::wl_compositor mCompositor;
struct wl_shm *mShm;
QScopedPointer<QtWayland::wl_shell> mShell;
QScopedPointer<QWaylandXdgShell> mShellXdg;
QList<QWaylandScreen *> mScreens;
QList<QWaylandInputDevice *> mInputDevices;
QList<Listener> mRegistryListeners;
......
......@@ -69,6 +69,8 @@
#include "qwaylandshellintegration_p.h"
#include "qwaylandshellintegrationfactory_p.h"
#include "qwaylandxdgshellintegration_p.h"
#include "qwaylandwlshellintegration_p.h"
#include "qwaylandinputdeviceintegration_p.h"
#include "qwaylandinputdeviceintegrationfactory_p.h"
......@@ -360,17 +362,29 @@ void QWaylandIntegration::initializeShellIntegration()
QByteArray integrationName = qgetenv("QT_WAYLAND_SHELL_INTEGRATION");
QString targetKey = QString::fromLocal8Bit(integrationName);
if (targetKey.isEmpty()) {
return;
if (!targetKey.isEmpty()) {
QStringList keys = QWaylandShellIntegrationFactory::keys();
if (keys.contains(targetKey)) {
qDebug("Using the '%s' shell integration", qPrintable(targetKey));
mShellIntegration = QWaylandShellIntegrationFactory::create(targetKey, QStringList());
}
} else {
QStringList preferredShells;
if (qEnvironmentVariableIsSet("QT_WAYLAND_USE_XDG_SHELL"))
preferredShells << QLatin1String("xdg_shell");
preferredShells << QLatin1String("wl_shell");
Q_FOREACH (QString preferredShell, preferredShells) {
if (mDisplay->hasRegistryGlobal(preferredShell)) {
mShellIntegration = createShellIntegration(preferredShell);
break;
}
}
}
QStringList keys = QWaylandShellIntegrationFactory::keys();
if (keys.contains(targetKey)) {
mShellIntegration = QWaylandShellIntegrationFactory::create(targetKey, QStringList());
}
if (mShellIntegration && mShellIntegration->initialize(mDisplay)) {
qDebug("Using the '%s' shell integration", qPrintable(targetKey));
} else {
Q_ASSERT(mShellIntegration);
if (!mShellIntegration->initialize(mDisplay)) {
delete mShellIntegration;
mShellIntegration = Q_NULLPTR;
qWarning("Failed to load shell integration %s", qPrintable(targetKey));
......@@ -403,6 +417,17 @@ void QWaylandIntegration::initializeInputDeviceIntegration()
}
}
QWaylandShellIntegration *QWaylandIntegration::createShellIntegration(const QString &interfaceName)
{
if (interfaceName == QLatin1Literal("wl_shell")) {
return new QWaylandWlShellIntegration(mDisplay);
} else if (interfaceName == QLatin1Literal("xdg_shell")) {
return new QWaylandXdgShellIntegration(mDisplay);
} else {
return Q_NULLPTR;
}
}
}
QT_END_NAMESPACE
......@@ -115,6 +115,7 @@ private:
void initializeServerBufferIntegration();
void initializeShellIntegration();
void initializeInputDeviceIntegration();
QWaylandShellIntegration *createShellIntegration(const QString& interfaceName);
QPlatformFontDatabase *mFontDb;
QPlatformClipboard *mClipboard;
......
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qwaylandwlshellintegration_p.h"
#include <QtWaylandClient/private/qwaylandwindow_p.h>
#include <QtWaylandClient/private/qwaylanddisplay_p.h>
#include <QtWaylandClient/private/qwaylandwlshellsurface_p.h>
QT_BEGIN_NAMESPACE
namespace QtWaylandClient {
QWaylandWlShellIntegration::QWaylandWlShellIntegration(QWaylandDisplay *display)
: m_wlShell(Q_NULLPTR)
{
Q_FOREACH (QWaylandDisplay::RegistryGlobal global, display->globals()) {
if (global.interface == QLatin1String("wl_shell")) {
m_wlShell = new QtWayland::wl_shell(display->wl_registry(), global.id, 1);
break;
}
}
}
QWaylandShellSurface *QWaylandWlShellIntegration::createShellSurface(QWaylandWindow *window)
{
return new QWaylandWlShellSurface(m_wlShell->get_shell_surface(window->object()), window);
}
}
QT_END_NAMESPACE
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QWAYLANDWLSHELLINTEGRATION_P_H
#define QWAYLANDWLSHELLINTEGRATION_P_H
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists purely as an
// implementation detail. This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//
#include <wayland-client.h>
#include <private/qwayland-wayland.h>
#include <QtWaylandClient/private/qwaylandshellintegration_p.h>
QT_BEGIN_NAMESPACE
namespace QtWaylandClient {
class Q_WAYLAND_CLIENT_EXPORT QWaylandWlShellIntegration : public QWaylandShellIntegration
{
public:
QWaylandWlShellIntegration(QWaylandDisplay* display);
bool initialize(QWaylandDisplay *) Q_DECL_OVERRIDE { return m_wlShell != Q_NULLPTR; }
QWaylandShellSurface *createShellSurface(QWaylandWindow *window) Q_DECL_OVERRIDE;
private:
QtWayland::wl_shell *m_wlShell;
};
}
QT_END_NAMESPACE
#endif // QWAYLANDWLSHELLINTEGRATION_P_H
......@@ -37,6 +37,7 @@
#include "qwaylandwindow_p.h"
#include "qwaylandinputdevice_p.h"
#include "qwaylandscreen_p.h"
#include "qwaylandxdgsurface_p.h"
#include <QtCore/QDebug>
......@@ -60,6 +61,10 @@ QWaylandXdgShell::~QWaylandXdgShell()
xdg_shell_destroy(object());
}
QWaylandXdgSurface *QWaylandXdgShell::createXdgSurface(QWaylandWindow *window)
{
return new QWaylandXdgSurface(this, window);
}
void QWaylandXdgShell::xdg_shell_ping(uint32_t serial)
{
......
......@@ -61,15 +61,17 @@ namespace QtWaylandClient {
class QWaylandWindow;
class QWaylandInputDevice;
class QWaylandXdgSurface;
class Q_WAYLAND_CLIENT_EXPORT QWaylandXdgShell : public QtWayland::xdg_shell
{
public:
QWaylandXdgShell(struct ::xdg_shell *shell);
QWaylandXdgShell(struct ::wl_registry *registry, uint32_t id);
virtual ~QWaylandXdgShell();
QWaylandXdgSurface *createXdgSurface(QWaylandWindow *window);
private:
void xdg_shell_ping(uint32_t serial) Q_DECL_OVERRIDE;
};
......
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qwaylandxdgshellintegration_p.h"
#include <QtWaylandClient/private/qwaylandwindow_p.h>
#include <QtWaylandClient/private/qwaylanddisplay_p.h>
#include <QtWaylandClient/private/qwaylandxdgsurface_p.h>
#include <QtWaylandClient/private/qwaylandxdgshell_p.h>
QT_BEGIN_NAMESPACE
namespace QtWaylandClient {
QWaylandXdgShellIntegration::QWaylandXdgShellIntegration(QWaylandDisplay *display)
: m_xdgShell(Q_NULLPTR)
{
Q_FOREACH (QWaylandDisplay::RegistryGlobal global, display->globals()) {
if (global.interface == QLatin1String("xdg_shell")) {
m_xdgShell = new QWaylandXdgShell(display->wl_registry(), global.id);
break;
}
}
}
QWaylandShellSurface *QWaylandXdgShellIntegration::createShellSurface(QWaylandWindow *window)
{
return m_xdgShell->createXdgSurface(window);
}
}
QT_END_NAMESPACE
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QWAYLANDXDGSHELLINTEGRATION_P_H
#define QWAYLANDXDGSHELLINTEGRATION_P_H
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists purely as an
// implementation detail. This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//
#include <wayland-client.h>
#include <QtWaylandClient/private/qwaylandshellintegration_p.h>
QT_BEGIN_NAMESPACE
namespace QtWaylandClient {
class QWaylandXdgShell;
class Q_WAYLAND_CLIENT_EXPORT QWaylandXdgShellIntegration : public QWaylandShellIntegration
{
public:
QWaylandXdgShellIntegration(QWaylandDisplay *display);
bool initialize(QWaylandDisplay *) Q_DECL_OVERRIDE { return m_xdgShell != Q_NULLPTR; }
QWaylandShellSurface *createShellSurface(QWaylandWindow *window) Q_DECL_OVERRIDE;
private:
QWaylandXdgShell *m_xdgShell;
};
}
QT_END_NAMESPACE
#endif // QWAYLANDXDGSHELLINTEGRATION_P_H
......@@ -39,16 +39,18 @@
#include "qwaylandabstractdecoration_p.h"
#include "qwaylandscreen_p.h"
#include "qwaylandextendedsurface_p.h"
#include "qwaylandxdgshell_p.h"
QT_BEGIN_NAMESPACE
namespace QtWaylandClient {
QWaylandXdgSurface::QWaylandXdgSurface(struct ::xdg_surface *xdg_surface, QWaylandWindow *window)
QWaylandXdgSurface::QWaylandXdgSurface(QWaylandXdgShell *shell, QWaylandWindow *window)
: QWaylandShellSurface(window)
, QtWayland::xdg_surface(xdg_surface)
, QtWayland::xdg_surface(shell->get_xdg_surface(window->object()))
, m_window(window)
, m_shell(shell)
, m_maximized(false)
, m_minimized(false)
, m_fullscreen(false)
......@@ -130,8 +132,7 @@ void QWaylandXdgSurface::updateTransientParent(QWindow *parent)
QWaylandWindow *parent_wayland_window = static_cast<QWaylandWindow *>(parent->handle());
if (!parent_wayland_window)
return;
QtWayland::xdg_shell *shell = parent_wayland_window->display()->shellXdg();
set_parent(shell->get_xdg_surface(parent_wayland_window->object()));
set_parent(m_shell->get_xdg_surface(parent_wayland_window->object()));
}
void QWaylandXdgSurface::setTitle(const QString & title)
......
......@@ -63,13 +63,14 @@ namespace QtWaylandClient {
class QWaylandWindow;
class QWaylandInputDevice;
class QWaylandExtendedSurface;
class QWaylandXdgShell;
class Q_WAYLAND_CLIENT_EXPORT QWaylandXdgSurface : public QWaylandShellSurface
, public QtWayland::xdg_surface
{
Q_OBJECT
public:
QWaylandXdgSurface(struct ::xdg_surface *shell_surface, QWaylandWindow *window);
QWaylandXdgSurface(QWaylandXdgShell *shell, QWaylandWindow *window);
virtual ~QWaylandXdgSurface();
using QtWayland::xdg_surface::resize;
......@@ -105,6 +106,7 @@ private:
private:
QWaylandWindow *m_window;
QWaylandXdgShell* m_shell;
bool m_maximized;
bool m_minimized;
bool m_fullscreen;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment