Commit 8af1ec88 authored by David Edmundson's avatar David Edmundson
Browse files

Add XDG WM Base support to our XDGShell API

Summary:
This adds XDG WM Base (essentially XDG Shell v7/stable edition) into our
existing XDGShell classes which wrap v5, v6 and now this.

It's mostly copy and paste from V6 except for the enum types for gravity
and anchor edges on positioners.

There's been no attempt to share code with V6 as realistically that
won't get updates whereas XDGWMBase will; and at some point we will
want to drop V6 without things being too tangled.

Test Plan:
Same test suite as V6 has

Compiled GTK master and ran against suitably modified kwin
running WAYLAND_DEBUG=1 gtk-demo showed we were using this interface
Everything worked as well as V6 does.

Reviewers: #kwin, romangg

Reviewed By: #kwin, romangg

Subscribers: romangg, zzag, kde-frameworks-devel

Tags: #frameworks

Differential Revision: https://phabricator.kde.org/D13510
parent 7442b72b
......@@ -55,6 +55,7 @@ set(SERVER_LIB_SRCS
xdgforeign_interface.cpp
xdgshell_v5_interface.cpp
xdgshell_v6_interface.cpp
xdgshell_stable_interface.cpp
xdgoutput_interface.cpp
../compat/wayland-xdg-shell-v5-protocol.c
)
......@@ -138,11 +139,6 @@ ecm_add_wayland_server_protocol(SERVER_LIB_SRCS
BASENAME text-input-unstable-v2
)
ecm_add_wayland_server_protocol(SERVER_LIB_SRCS
PROTOCOL ${KWayland_SOURCE_DIR}/src/client/protocols/xdg-shell-unstable-v5.xml
BASENAME xdg-shell-v5
)
ecm_add_wayland_server_protocol(SERVER_LIB_SRCS
PROTOCOL ${KWayland_SOURCE_DIR}/src/client/protocols/xdg-shell-unstable-v6.xml
BASENAME xdg-shell-v6
......@@ -188,6 +184,11 @@ ecm_add_wayland_server_protocol(SERVER_LIB_SRCS
BASENAME xdg-output
)
ecm_add_wayland_server_protocol(SERVER_LIB_SRCS
PROTOCOL ${KWayland_SOURCE_DIR}/src/client/protocols/xdg-shell.xml
BASENAME xdg-shell
)
set(SERVER_GENERATED_SRCS
${CMAKE_CURRENT_BINARY_DIR}/wayland-output-management-client-protocol.h
${CMAKE_CURRENT_BINARY_DIR}/wayland-output-management-server-protocol.h
......@@ -225,6 +226,8 @@ set(SERVER_GENERATED_SRCS
${CMAKE_CURRENT_BINARY_DIR}/wayland-text-input-unstable-v2-server-protocol.h
${CMAKE_CURRENT_BINARY_DIR}/wayland-xdg-shell-v6-client-protocol.h
${CMAKE_CURRENT_BINARY_DIR}/wayland-xdg-shell-v6-server-protocol.h
${CMAKE_CURRENT_BINARY_DIR}/wayland-xdg-shell-client-protocol.h
${CMAKE_CURRENT_BINARY_DIR}/wayland-xdg-shell-server-protocol.h
${CMAKE_CURRENT_BINARY_DIR}/wayland-pointer-gestures-unstable-v1-client-protocol.h
${CMAKE_CURRENT_BINARY_DIR}/wayland-pointer-gestures-unstable-v1-server-protocol.h
${CMAKE_CURRENT_BINARY_DIR}/wayland-pointer-constraints-unstable-v1-client-protocol.h
......
......@@ -376,6 +376,17 @@ add_executable(testXdgShellV6 ${testXdgShellV6_SRCS})
target_link_libraries( testXdgShellV6 Qt5::Test Qt5::Gui KF5::WaylandServer KF5::WaylandClient Wayland::Client)
add_test(NAME kwayland-testXdgShellV6 COMMAND testXdgShellV6)
ecm_mark_as_test(testXdgShellV6)
########################################################
# Test XdgShellStable
########################################################
set( testXdgShellStable_SRCS
test_xdg_shell.cpp
test_xdg_shell_stable.cpp
)
add_executable(testXdgShellStable ${testXdgShellStable_SRCS})
target_link_libraries( testXdgShellStable Qt5::Test Qt5::Gui KF5::WaylandServer KF5::WaylandClient Wayland::Client)
add_test(NAME kwayland-testXdgShellStable COMMAND testXdgShellStable)
ecm_mark_as_test(testXdgShellStable)
########################################################
# Test Pointer Constraints
......
......@@ -76,8 +76,9 @@ void XdgShellTest::init()
QSignalSpy outputAnnouncedSpy(&registry, &Registry::outputAnnounced);
QVERIFY(outputAnnouncedSpy.isValid());
auto shellAnnouncedSignal = m_version == XdgShellInterfaceVersion::UnstableV5 ?
&Registry::xdgShellUnstableV5Announced : &Registry::xdgShellUnstableV6Announced;
auto shellAnnouncedSignal = m_version == XdgShellInterfaceVersion::UnstableV5 ? &Registry::xdgShellUnstableV5Announced :
m_version == XdgShellInterfaceVersion::UnstableV6 ? &Registry::xdgShellUnstableV6Announced :
&Registry::xdgShellStableAnnounced;
QSignalSpy xdgShellAnnouncedSpy(&registry, shellAnnouncedSignal);
QVERIFY(xdgShellAnnouncedSpy.isValid());
......@@ -105,7 +106,18 @@ void XdgShellTest::init()
QCOMPARE(xdgShellAnnouncedSpy.count(), 1);
Registry::Interface iface = m_version == XdgShellInterfaceVersion::UnstableV5 ? Registry::Interface::XdgShellUnstableV5 : Registry::Interface::XdgShellUnstableV6;
Registry::Interface iface;
switch (m_version) {
case XdgShellInterfaceVersion::UnstableV5:
iface = Registry::Interface::XdgShellUnstableV5;
break;
case XdgShellInterfaceVersion::UnstableV6:
iface = Registry::Interface::XdgShellUnstableV6;
break;
case XdgShellInterfaceVersion::Stable:
iface = Registry::Interface::XdgShellStable;
break;
}
m_xdgShell = registry.createXdgShell(registry.interface(iface).name,
registry.interface(iface).version,
......
/********************************************************************
Copyright 2016 Martin Gräßlin <mgraesslin@kde.org>
Copyright 2017 David Edmundson <davidedmundson@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "test_xdg_shell.h"
#include <wayland-xdg-shell-client-protocol.h>
class XdgShellTestStable : public XdgShellTest {
Q_OBJECT
public:
XdgShellTestStable() :
XdgShellTest(KWayland::Server::XdgShellInterfaceVersion::Stable) {}
private Q_SLOTS:
void testMaxSize();
void testMinSize();
void testPopup_data();
void testPopup();
void testMultipleRoles1();
void testMultipleRoles2();
};
void XdgShellTestStable::testMaxSize()
{
qRegisterMetaType<OutputInterface*>();
// this test verifies changing the window maxSize
QSignalSpy xdgSurfaceCreatedSpy(m_xdgShellInterface, &XdgShellInterface::surfaceCreated);
QVERIFY(xdgSurfaceCreatedSpy.isValid());
QScopedPointer<Surface> surface(m_compositor->createSurface());
QScopedPointer<XdgShellSurface> xdgSurface(m_xdgShell->createSurface(surface.data()));
QVERIFY(xdgSurfaceCreatedSpy.wait());
auto serverXdgSurface = xdgSurfaceCreatedSpy.first().first().value<XdgShellSurfaceInterface*>();
QVERIFY(serverXdgSurface);
QSignalSpy maxSizeSpy(serverXdgSurface, &XdgShellSurfaceInterface::maxSizeChanged);
QVERIFY(maxSizeSpy.isValid());
xdgSurface->setMaxSize(QSize(100, 100));
QVERIFY(maxSizeSpy.wait());
QCOMPARE(maxSizeSpy.count(), 1);
QCOMPARE(maxSizeSpy.last().at(0).value<QSize>(), QSize(100,100));
xdgSurface->setMaxSize(QSize(200, 200));
QVERIFY(maxSizeSpy.wait());
QCOMPARE(maxSizeSpy.count(), 2);
QCOMPARE(maxSizeSpy.last().at(0).value<QSize>(), QSize(200,200));
}
void XdgShellTestStable::testPopup_data()
{
QTest::addColumn<XdgPositioner>("positioner");
XdgPositioner positioner(QSize(10,10), QRect(100,100,50,50));
QTest::newRow("default") << positioner;
XdgPositioner positioner2(QSize(20,20), QRect(101,102,51,52));
QTest::newRow("sizeAndAnchorRect") << positioner2;
positioner.setAnchorEdge(Qt::TopEdge | Qt::RightEdge);
QTest::newRow("anchorEdge") << positioner;
positioner.setGravity(Qt::BottomEdge);
QTest::newRow("gravity") << positioner;
positioner.setGravity(Qt::TopEdge | Qt::RightEdge);
QTest::newRow("gravity2") << positioner;
positioner.setConstraints(XdgPositioner::Constraint::SlideX | XdgPositioner::Constraint::FlipY);
QTest::newRow("constraints") << positioner;
positioner.setConstraints(XdgPositioner::Constraint::SlideX | XdgPositioner::Constraint::SlideY | XdgPositioner::Constraint::FlipX | XdgPositioner::Constraint::FlipY | XdgPositioner::Constraint::ResizeX | XdgPositioner::Constraint::ResizeY);
QTest::newRow("constraints2") << positioner;
positioner.setAnchorOffset(QPoint(4,5));
QTest::newRow("offset") << positioner;
}
void XdgShellTestStable::testPopup()
{
QSignalSpy xdgTopLevelCreatedSpy(m_xdgShellInterface, &XdgShellInterface::surfaceCreated);
QSignalSpy xdgPopupCreatedSpy(m_xdgShellInterface, &XdgShellInterface::xdgPopupCreated);
QScopedPointer<Surface> parentSurface(m_compositor->createSurface());
QScopedPointer<XdgShellSurface> xdgParentSurface(m_xdgShell->createSurface(parentSurface.data()));
QVERIFY(xdgTopLevelCreatedSpy.wait());
auto serverXdgTopLevel = xdgTopLevelCreatedSpy.first().first().value<XdgShellSurfaceInterface*>();
QFETCH(XdgPositioner, positioner);
QScopedPointer<Surface> surface(m_compositor->createSurface());
QScopedPointer<XdgShellPopup> xdgSurface(m_xdgShell->createPopup(surface.data(), xdgParentSurface.data(), positioner));
QVERIFY(xdgPopupCreatedSpy.wait());
auto serverXdgPopup = xdgPopupCreatedSpy.first().first().value<XdgShellPopupInterface*>();
QVERIFY(serverXdgPopup);
QCOMPARE(serverXdgPopup->initialSize(), positioner.initialSize());
QCOMPARE(serverXdgPopup->anchorRect(), positioner.anchorRect());
QCOMPARE(serverXdgPopup->anchorEdge(), positioner.anchorEdge());
QCOMPARE(serverXdgPopup->gravity(), positioner.gravity());
QCOMPARE(serverXdgPopup->anchorOffset(), positioner.anchorOffset());
//we have different enums for client server, but they share the same values
QCOMPARE((int)serverXdgPopup->constraintAdjustments(), (int)positioner.constraints());
QCOMPARE(serverXdgPopup->transientFor().data(), serverXdgTopLevel->surface());
}
void XdgShellTestStable::testMinSize()
{
qRegisterMetaType<OutputInterface*>();
// this test verifies changing the window minSize
QSignalSpy xdgSurfaceCreatedSpy(m_xdgShellInterface, &XdgShellInterface::surfaceCreated);
QVERIFY(xdgSurfaceCreatedSpy.isValid());
QScopedPointer<Surface> surface(m_compositor->createSurface());
QScopedPointer<XdgShellSurface> xdgSurface(m_xdgShell->createSurface(surface.data()));
QVERIFY(xdgSurfaceCreatedSpy.wait());
auto serverXdgSurface = xdgSurfaceCreatedSpy.first().first().value<XdgShellSurfaceInterface*>();
QVERIFY(serverXdgSurface);
QSignalSpy minSizeSpy(serverXdgSurface, &XdgShellSurfaceInterface::minSizeChanged);
QVERIFY(minSizeSpy.isValid());
xdgSurface->setMinSize(QSize(200, 200));
QVERIFY(minSizeSpy.wait());
QCOMPARE(minSizeSpy.count(), 1);
QCOMPARE(minSizeSpy.last().at(0).value<QSize>(), QSize(200,200));
xdgSurface->setMinSize(QSize(100, 100));
QVERIFY(minSizeSpy.wait());
QCOMPARE(minSizeSpy.count(), 2);
QCOMPARE(minSizeSpy.last().at(0).value<QSize>(), QSize(100,100));
}
//top level then toplevel
void XdgShellTestStable::testMultipleRoles1()
{
//setting multiple roles on an xdg surface should fail
QSignalSpy xdgSurfaceCreatedSpy(m_xdgShellInterface, &XdgShellInterface::surfaceCreated);
QSignalSpy xdgPopupCreatedSpy(m_xdgShellInterface, &XdgShellInterface::xdgPopupCreated);
QVERIFY(xdgSurfaceCreatedSpy.isValid());
QVERIFY(xdgPopupCreatedSpy.isValid());
QScopedPointer<Surface> surface(m_compositor->createSurface());
//This is testing we work when a client does something stupid
//we can't use KWayland API here because by design that stops you from doing anything stupid
qDebug() << (xdg_wm_base*)*m_xdgShell;
auto xdgSurface = xdg_wm_base_get_xdg_surface(*m_xdgShell, *surface.data());
//create a top level
auto xdgTopLevel1 = xdg_surface_get_toplevel(xdgSurface);
QVERIFY(xdgSurfaceCreatedSpy.wait());
//now try to create another top level for the same xdg surface. It should fail
auto xdgTopLevel2 = xdg_surface_get_toplevel(xdgSurface);
QVERIFY(!xdgSurfaceCreatedSpy.wait(10));
xdg_toplevel_destroy(xdgTopLevel1);
xdg_toplevel_destroy(xdgTopLevel2);
xdg_surface_destroy(xdgSurface);
}
//toplevel then popup
void XdgShellTestStable::testMultipleRoles2()
{
QSignalSpy xdgSurfaceCreatedSpy(m_xdgShellInterface, &XdgShellInterface::surfaceCreated);
QSignalSpy xdgPopupCreatedSpy(m_xdgShellInterface, &XdgShellInterface::xdgPopupCreated);
QVERIFY(xdgSurfaceCreatedSpy.isValid());
QVERIFY(xdgPopupCreatedSpy.isValid());
QScopedPointer<Surface> surface(m_compositor->createSurface());
QScopedPointer<Surface> parentSurface(m_compositor->createSurface());
auto parentXdgSurface = xdg_wm_base_get_xdg_surface(*m_xdgShell, *parentSurface.data());
auto xdgTopLevelParent = xdg_surface_get_toplevel(parentXdgSurface);
QVERIFY(xdgSurfaceCreatedSpy.wait());
auto xdgSurface = xdg_wm_base_get_xdg_surface(*m_xdgShell, *surface.data());
//create a top level
auto xdgTopLevel1 = xdg_surface_get_toplevel(xdgSurface);
QVERIFY(xdgSurfaceCreatedSpy.wait());
//now try to create a popup on the same xdg surface. It should fail
auto positioner = xdg_wm_base_create_positioner(*m_xdgShell);
xdg_positioner_set_anchor_rect(positioner,10, 10, 10, 10);
xdg_positioner_set_size(positioner,10, 100);
auto xdgPopup2 = xdg_surface_get_popup(xdgSurface, parentXdgSurface, positioner);
QVERIFY(!xdgPopupCreatedSpy.wait(10));
xdg_positioner_destroy(positioner);
xdg_toplevel_destroy(xdgTopLevel1);
xdg_toplevel_destroy(xdgTopLevelParent);
xdg_popup_destroy(xdgPopup2);
xdg_surface_destroy(xdgSurface);
}
QTEST_GUILESS_MAIN(XdgShellTestStable)
#include "test_xdg_shell_stable.moc"
......@@ -48,6 +48,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
#include "xdgshell_v5_interface_p.h"
#include "xdgforeign_interface.h"
#include "xdgshell_v6_interface_p.h"
#include "xdgshell_stable_interface_p.h"
#include "appmenu_interface.h"
#include "server_decoration_palette_interface.h"
#include "xdgoutput_interface.h"
......@@ -384,6 +385,9 @@ XdgShellInterface *Display::createXdgShell(const XdgShellInterfaceVersion &versi
case XdgShellInterfaceVersion::UnstableV6:
x = new XdgShellV6Interface(this, parent);
break;
case XdgShellInterfaceVersion::Stable:
x = new XdgShellStableInterface(this, parent);
break;
}
connect(this, &Display::aboutToTerminate, x, [x] { delete x; });
return x;
......
This diff is collapsed.
/****************************************************************************
Copyright 2017 David Edmundson <davidedmundson@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#ifndef KWAYLAND_SERVER_XDGSHELL_STABLE_INTERFACE_P_H
#define KWAYLAND_SERVER_XDGSHELL_STABLE_INTERFACE_P_H
#include "global.h"
#include "resource.h"
#include "xdgshell_interface.h"
#include <KWayland/Server/kwaylandserver_export.h>
#include <QSize>
namespace KWayland
{
namespace Server
{
class Display;
class OutputInterface;
class SeatInterface;
class SurfaceInterface;
class XdgTopLevelStableInterface;
class XdgPopupStableInterface;
class XdgPositionerStableInterface;
class XdgSurfaceStableInterface;
template <typename T>
class GenericShellSurface;
class XdgShellStableInterface : public XdgShellInterface
{
Q_OBJECT
public:
virtual ~XdgShellStableInterface();
/**
* @returns The XdgTopLevelV6Interface for the @p native resource.
**/
XdgTopLevelStableInterface *getSurface(wl_resource *native);
//DAVE we want to rename this, as it's bloody confusing. But XdgShellInterface::getSurface exists and expects that
//also use a less terrible argument name than native. It's obvious it's native from the type
XdgPositionerStableInterface *getPositioner(wl_resource *native);
XdgSurfaceStableInterface *realGetSurface(wl_resource *native);
Display *display() const;
void ping(XdgShellSurfaceInterface * surface);
private:
explicit XdgShellStableInterface(Display *display, QObject *parent = nullptr);
friend class Display;
class Private;
Private *d_func() const;
};
class XdgSurfaceStableInterface : public KWayland::Server::Resource
{
Q_OBJECT
public:
virtual ~XdgSurfaceStableInterface();
SurfaceInterface* surface() const;
XdgTopLevelStableInterface* topLevel() const;
XdgPopupStableInterface *popup() const;
private:
explicit XdgSurfaceStableInterface(XdgShellStableInterface *parent, SurfaceInterface *surface, wl_resource *parentResource);
friend class XdgShellStableInterface;
class Private;
Private *d_func() const;
};
class XdgTopLevelStableInterface : public
XdgShellSurfaceInterface
{
Q_OBJECT
public:
virtual ~XdgTopLevelStableInterface();
private:
explicit XdgTopLevelStableInterface(XdgShellStableInterface *parent, SurfaceInterface *surface, wl_resource *parentResource);
friend class XdgShellStableInterface;
friend class XdgSurfaceStableInterface;
class Private;
Private *d_func() const;
};
class XdgPopupStableInterface : public XdgShellPopupInterface
{
Q_OBJECT
public:
virtual ~XdgPopupStableInterface();
private:
explicit XdgPopupStableInterface(XdgShellStableInterface *parent, SurfaceInterface *surface, wl_resource *parentResource);
friend class XdgShellStableInterface;
friend class XdgSurfaceStableInterface;
friend class GenericShellSurface<XdgPopupStableInterface>;
class Private;
Private *d_func() const;
};
/*
* This is a private internal class that keeps track of sent data
* At the time of PopupCreation these values are copied to the popup
*/
class XdgPositionerStableInterface: public KWayland::Server::Resource
{
public:
QSize initialSize() const;
QRect anchorRect() const;
Qt::Edges anchorEdge() const;
Qt::Edges gravity() const;
PositionerConstraints constraintAdjustments() const;
QPoint anchorOffset() const;
private:
explicit XdgPositionerStableInterface(XdgShellStableInterface *parent, wl_resource *parentResource);
friend class XdgShellStableInterface;
class Private;
Private *d_func() const;
};
}
}
#endif
......@@ -55,7 +55,12 @@ enum class XdgShellInterfaceVersion
* zxdg_shell_v6 (unstable v6)
* @since 5.39
**/
UnstableV6
UnstableV6,
/**
xdg_wm_base (stable)
@since 5.XDGSHELL_VERSION
*/
Stable
};
/**
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment