Commit 9e1db786 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧
Browse files

Use wlr_layer_shell_v1 to implement on Wayland

Using the PlasmaShell protocol has all sorts of problems because
placement is decided by the client at a position level rather than by
the application.
This adopts the layer shell and enforces the surface to be full screen
on the correct output and the compositor should be responsible for
placing it correctly.
parent d04ba495
......@@ -76,14 +76,17 @@ find_package(XCB MODULE REQUIRED COMPONENTS XCB KEYSYMS XTEST)
set_package_properties(XCB PROPERTIES TYPE REQUIRED)
add_feature_info("XInput" X11_Xinput_FOUND "Required for grabbing XInput2 devices in the screen locker")
find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS X11Extras)
find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS X11Extras WaylandClient)
find_package(Qt5XkbCommonSupport REQUIRED PRIVATE)
find_package(KF5Wayland CONFIG REQUIRED)
set_package_properties(KF5Wayland PROPERTIES
TYPE REQUIRED
PURPOSE "Required for building screenlocker")
find_package(WaylandScanner)
find_package(QtWaylandScanner)
find_package(Wayland 1.3 COMPONENTS Client Server)
find_package(WaylandProtocols)
set_package_properties(Wayland PROPERTIES
TYPE REQUIRED
......@@ -146,6 +149,7 @@ add_subdirectory(kcheckpass)
add_subdirectory(greeter)
add_subdirectory(kcm)
add_subdirectory(settings)
add_subdirectory(layershell)
add_definitions(-DTRANSLATION_DOMAIN=\"kscreenlocker\")
......
......@@ -50,6 +50,7 @@ target_link_libraries(kscreenlocker_greet
${X11_LIBRARIES}
KF5::WaylandClient
Wayland::Client
layer-shell
)
install(TARGETS kscreenlocker_greet DESTINATION ${KDE_INSTALL_LIBEXECDIR})
......
......@@ -43,7 +43,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// KWayland
#include <KWayland/Client/connection_thread.h>
#include <KWayland/Client/event_queue.h>
#include <KWayland/Client/plasmashell.h>
#include <KWayland/Client/registry.h>
#include <KWayland/Client/surface.h>
// Qt
......@@ -300,10 +299,6 @@ void UnlockApp::screenGeometryChanged(QScreen *screen, const QRect &geo)
}
KQuickAddons::QuickViewSharedEngine* view = m_views[screenIndex];
view->setGeometry(geo);
KWayland::Client::PlasmaShellSurface *plasmaSurface = view->property("plasmaShellSurface").value<KWayland::Client::PlasmaShellSurface *>();
if (plasmaSurface) {
plasmaSurface->setPosition(view->geometry().topLeft());
}
}
void UnlockApp::initialViewSetup()
......@@ -348,14 +343,6 @@ void UnlockApp::desktopResized()
wl_display_flush(m_ksldConnection->display());
}
if (m_plasmaShell) {
using namespace KWayland::Client;
if (Surface *surface = Surface::fromWindow(view)) {
PlasmaShellSurface *shellSurface = m_plasmaShell->createSurface(surface, view);
view->setProperty("plasmaShellSurface", QVariant::fromValue(shellSurface));
}
}
// engine stuff
QQmlContext* context = view->engine()->rootContext();
......@@ -413,11 +400,7 @@ void UnlockApp::desktopResized()
auto *view = m_views.at(i);
auto screen = QGuiApplication::screens()[i];
view->setGeometry(screen->geometry());
KWayland::Client::PlasmaShellSurface *plasmaSurface = view->property("plasmaShellSurface").value<KWayland::Client::PlasmaShellSurface *>();
if (plasmaSurface) {
plasmaSurface->setPosition(view->geometry().topLeft());
}
view->setScreen(screen);
if (auto object = view->property("wallpaperGraphicsObject").value<KDeclarative::QmlObjectSharedEngine*>()) {
//initialize with our size to avoid as much resize events as possible
object->completeInitialization({
......@@ -426,9 +409,8 @@ void UnlockApp::desktopResized()
});
}
// on Wayland we may not use fullscreen as that puts all windows on one screen
if (m_testing || plasmaSurface || QX11Info::isPlatformX11()) {
if (m_testing || QX11Info::isPlatformX11()) {
view->show();
} else {
view->showFullScreen();
......
......@@ -64,8 +64,11 @@ static void signalHandler(int signum)
}
}
Q_IMPORT_PLUGIN(QWaylandLayerShellIntegrationPlugin)
int main(int argc, char* argv[])
{
qputenv("QT_WAYLAND_SHELL_INTEGRATION", "fullscreen-layer-shell");
// disable ptrace on the greeter
#if HAVE_PR_SET_DUMPABLE
prctl(PR_SET_DUMPABLE, 0);
......
remove_definitions(-DQT_NO_SIGNALS_SLOTS_KEYWORDS)
ecm_add_qtwayland_client_protocol(LAYER_SHELL_SOURCES PROTOCOL ${WaylandProtocols_DATADIR}/stable/xdg-shell/xdg-shell.xml BASENAME xdg-shell)
ecm_add_qtwayland_client_protocol(LAYER_SHELL_SOURCES PROTOCOL wlr-layer-shell-unstable-v1.xml BASENAME wlr-layer-shell-unstable-v1)
add_library(layer-shell OBJECT qwaylandlayersurface.cpp qwaylandlayershellintegration.cpp qwaylandlayershell.cpp qwaylandlayershellintegrationplugin.cpp ${LAYER_SHELL_SOURCES})
target_link_libraries(layer-shell Qt5::WaylandClient Wayland::Client)
target_compile_definitions(layer-shell PRIVATE QT_STATICPLUGIN)
target_include_directories(layer-shell PRIVATE ${Qt5WaylandClient_PRIVATE_INCLUDE_DIRS} ${Qt5XkbCommonSupport_PRIVATE_INCLUDE_DIRS})
#install(TARGETS layer-shell
#LIBRARY DESTINATION ${QT_PLUGIN_INSTALL_DIR}/wayland-shell-integration)
{
"Keys":[ "fullscreen-layer-shell" ]
}
/*
* SPDX-FileCopyrightText: 2021 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
* SPDX-FileCopyrightText: 2018 Drew DeVault <sir@cmpwn.com>
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
#include "qwaylandlayershell_p.h"
#include "qwaylandlayersurface_p.h"
#include <qwayland-wlr-layer-shell-unstable-v1.h>
namespace QtLayerShell {
QWaylandLayerShell::QWaylandLayerShell(struct QtWayland::zwlr_layer_shell_v1 *shell)
: QtWayland::zwlr_layer_shell_v1(shell->object())
{
}
QWaylandLayerShell::~QWaylandLayerShell()
{
zwlr_layer_shell_v1_destroy(object());
}
QWaylandLayerSurface *QWaylandLayerShell::createLayerSurface(
QtWaylandClient::QWaylandWindow *window)
{
return new QWaylandLayerSurface(this, window);
}
}
/*
* SPDX-FileCopyrightText: 2021 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
* SPDX-FileCopyrightText: 2018 Drew DeVault <sir@cmpwn.com>
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
#ifndef _LAYERSHELL_H
#define _LAYERSHELL_H
#include <wayland-client.h>
#include <qwayland-wlr-layer-shell-unstable-v1.h>
#include <QtWaylandClient/private/qwaylandshellintegration_p.h>
#include "qwaylandlayersurface_p.h"
namespace QtLayerShell {
class QWaylandLayerShell : public QtWayland::zwlr_layer_shell_v1
{
public:
QWaylandLayerShell(struct QtWayland::zwlr_layer_shell_v1 *shell);
virtual ~QWaylandLayerShell();
QWaylandLayerSurface *createLayerSurface(
QtWaylandClient::QWaylandWindow *window);
// TODO: Popups
};
}
#endif
/*
* SPDX-FileCopyrightText: 2021 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
* SPDX-FileCopyrightText: 2018 Drew DeVault <sir@cmpwn.com>
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
#include "qwaylandlayershellintegration_p.h"
#include "qwaylandlayershell_p.h"
#include <qwayland-wlr-layer-shell-unstable-v1.h>
#include <QtWaylandClient/private/qwaylandwindow_p.h>
#include <QtWaylandClient/private/qwaylanddisplay_p.h>
QT_BEGIN_NAMESPACE
namespace QtLayerShell {
QWaylandLayerShellIntegration::QWaylandLayerShellIntegration() :
m_layerShell(Q_NULLPTR)
{
}
bool QWaylandLayerShellIntegration::initialize(QtWaylandClient::QWaylandDisplay *display)
{
QWaylandShellIntegration::initialize(display);
display->addRegistryListener(registryLayer, this);
return m_layerShell != nullptr;
}
QtWaylandClient::QWaylandShellSurface *QWaylandLayerShellIntegration::
createShellSurface(QtWaylandClient::QWaylandWindow *window)
{
return m_layerShell->createLayerSurface(window);
}
void QWaylandLayerShellIntegration::registryLayer(void *data,
struct wl_registry *registry, uint32_t id,
const QString &interface, uint32_t version)
{
QWaylandLayerShellIntegration *shell =
static_cast<QWaylandLayerShellIntegration *>(data);
if (interface == QStringLiteral("zwlr_layer_shell_v1"))
shell->m_layerShell = new QWaylandLayerShell(
new QtWayland::zwlr_layer_shell_v1(registry, id, version));
}
}
QT_END_NAMESPACE
//#include "qwaylandlayershellintegration.moc"
/*
* SPDX-FileCopyrightText: 2021 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
* SPDX-FileCopyrightText: 2018 Drew DeVault <sir@cmpwn.com>
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
#ifndef _LAYERSHELLINTEGRATION_P_H
#define _LAYERSHELLINTEGRATION_P_H
#include <wayland-client.h>
#include <QtWaylandClient/private/qwaylandshellintegration_p.h>
namespace QtLayerShell {
class QWaylandLayerShell;
class QWaylandLayerShellIntegration : public QtWaylandClient::QWaylandShellIntegration
{
public:
QWaylandLayerShellIntegration();
bool initialize(QtWaylandClient::QWaylandDisplay *display) override;
QtWaylandClient::QWaylandShellSurface *createShellSurface(
QtWaylandClient::QWaylandWindow *window) override;
private:
static void registryLayer(void *data, struct wl_registry *registry,
uint32_t id, const QString &interface, uint32_t version);
QWaylandLayerShell *m_layerShell;
};
}
#endif
/*
* SPDX-FileCopyrightText: 2021 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
* SPDX-FileCopyrightText: 2018 Drew DeVault <sir@cmpwn.com>
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
#include <QtWaylandClient/private/qwaylandshellintegrationplugin_p.h>
#include "qwaylandlayershellintegration_p.h"
using namespace QtLayerShell;
class QWaylandLayerShellIntegrationPlugin :
public QtWaylandClient::QWaylandShellIntegrationPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(
IID QWaylandShellIntegrationFactoryInterface_iid
FILE "layer-shell.json")
public:
QWaylandLayerShellIntegrationPlugin() {}
QtWaylandClient::QWaylandShellIntegration *create(
const QString &key, const QStringList &paramList) override {
Q_UNUSED(key);
Q_UNUSED(paramList);
return new QWaylandLayerShellIntegration();
}
};
// Q_IMPORT_PLUGIN(QWaylandLayerShellIntegrationPlugin);
#include "qwaylandlayershellintegrationplugin.moc"
/*
* SPDX-FileCopyrightText: 2021 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
* SPDX-FileCopyrightText: 2018 Drew DeVault <sir@cmpwn.com>
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
#include "qwaylandlayershell_p.h"
#include "qwaylandlayersurface_p.h"
#include <qwayland-wlr-layer-shell-unstable-v1.h>
#include <QtWaylandClient/private/qwaylandwindow_p.h>
#include <QtWaylandClient/private/qwaylandsurface_p.h>
#include <QtWaylandClient/private/qwaylandscreen_p.h>
namespace QtLayerShell {
QWaylandLayerSurface::QWaylandLayerSurface(QWaylandLayerShell *shell, QtWaylandClient::QWaylandWindow *window)
: QtWaylandClient::QWaylandShellSurface(window)
, QtWayland::zwlr_layer_surface_v1(
// TODO: Specify namespace
shell->get_layer_surface(window->waylandSurface()->object(),
window->waylandScreen()->output(),
QtWayland::zwlr_layer_shell_v1::layer_top,
QStringLiteral("qt")))
{
set_anchor(anchor_top | anchor_bottom | anchor_left | anchor_right);
}
QWaylandLayerSurface::~QWaylandLayerSurface()
{
destroy();
}
void QWaylandLayerSurface::zwlr_layer_surface_v1_closed()
{
window()->window()->close();
}
void QWaylandLayerSurface::zwlr_layer_surface_v1_configure(uint32_t serial,
uint32_t width, uint32_t height)
{
ack_configure(serial);
m_pendingSize = QSize(width, height);
if (!m_configured) {
m_configured = true;
window()->resizeFromApplyConfigure(m_pendingSize);
window()->handleExpose(QRect(QPoint(), m_pendingSize));
} else {
// Later configures are resizes, so we have to queue them up for a time when we
// are not painting to the window.
window()->applyConfigureWhenPossible();
}
}
void QWaylandLayerSurface::applyConfigure()
{
window()->resizeFromApplyConfigure(m_pendingSize);
}
}
/*
* SPDX-FileCopyrightText: 2021 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
* SPDX-FileCopyrightText: 2018 Drew DeVault <sir@cmpwn.com>
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
#ifndef _LAYERSURFACE_H
#define _LAYERSURFACE_H
#include <wayland-client.h>
#include <qwayland-wlr-layer-shell-unstable-v1.h>
#include <QtWaylandClient/private/qwaylandshellsurface_p.h>
namespace QtLayerShell {
class QWaylandLayerShell;
class QWaylandLayerSurface : public QtWaylandClient::QWaylandShellSurface,
public QtWayland::zwlr_layer_surface_v1
{
Q_OBJECT
public:
QWaylandLayerSurface(QWaylandLayerShell *shell,
QtWaylandClient::QWaylandWindow *window);
virtual ~QWaylandLayerSurface();
bool isExposed() const override {
return m_configured;
}
void applyConfigure() override;
private:
void zwlr_layer_surface_v1_configure(uint32_t serial,
uint32_t width, uint32_t height) override;
void zwlr_layer_surface_v1_closed() override;
QSize m_pendingSize;
bool m_configured = false;
};
}
#endif
<?xml version="1.0" encoding="UTF-8"?>
<protocol name="wlr_layer_shell_unstable_v1">
<copyright>
Copyright © 2017 Drew DeVault
Permission to use, copy, modify, distribute, and sell this
software and its documentation for any purpose is hereby granted
without fee, provided that the above copyright notice appear in
all copies and that both that copyright notice and this permission
notice appear in supporting documentation, and that the name of
the copyright holders not be used in advertising or publicity
pertaining to distribution of the software without specific,
written prior permission. The copyright holders make no
representations about the suitability of this software for any
purpose. It is provided "as is" without express or implied
warranty.
THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
THIS SOFTWARE.
</copyright>
<interface name="zwlr_layer_shell_v1" version="1">
<description summary="create surfaces that are layers of the desktop">
Clients can use this interface to assign the surface_layer role to
wl_surfaces. Such surfaces are assigned to a "layer" of the output and
rendered with a defined z-depth respective to each other. They may also be
anchored to the edges and corners of a screen and specify input handling
semantics. This interface should be suitable for the implementation of
many desktop shell components, and a broad number of other applications
that interact with the desktop.
</description>
<request name="get_layer_surface">
<description summary="create a layer_surface from a surface">
Create a layer surface for an existing surface. This assigns the role of
layer_surface, or raises a protocol error if another role is already
assigned.
Creating a layer surface from a wl_surface which has a buffer attached
or committed is a client error, and any attempts by a client to attach
or manipulate a buffer prior to the first layer_surface.configure call
must also be treated as errors.
You may pass NULL for output to allow the compositor to decide which
output to use. Generally this will be the one that the user most
recently interacted with.
Clients can specify a namespace that defines the purpose of the layer
surface.
</description>
<arg name="id" type="new_id" interface="zwlr_layer_surface_v1"/>
<arg name="surface" type="object" interface="wl_surface"/>
<arg name="output" type="object" interface="wl_output" allow-null="true"/>
<arg name="layer" type="uint" enum="layer" summary="layer to add this surface to"/>
<!-- NOTE: Renamed from `namespace` upstream -->
<arg name="layer_namespace" type="string" summary="namespace for the layer surface"/>
</request>
<enum name="error">
<entry name="role" value="0" summary="wl_surface has another role"/>
<entry name="invalid_layer" value="1" summary="layer value is invalid"/>
<entry name="already_constructed" value="2" summary="wl_surface has a buffer attached or committed"/>
</enum>
<enum name="layer">
<description summary="available layers for surfaces">
These values indicate which layers a surface can be rendered in. They
are ordered by z depth, bottom-most first. Traditional shell surfaces
will typically be rendered between the bottom and top layers.
Fullscreen shell surfaces are typically rendered at the top layer.
Multiple surfaces can share a single layer, and ordering within a
single layer is undefined.
</description>
<entry name="background" value="0"/>
<entry name="bottom" value="1"/>
<entry name="top" value="2"/>
<entry name="overlay" value="3"/>
</enum>
</interface>
<interface name="zwlr_layer_surface_v1" version="1">
<description summary="layer metadata interface">
An interface that may be implemented by a wl_surface, for surfaces that
are designed to be rendered as a layer of a stacked desktop-like
environment.
Layer surface state (size, anchor, exclusive zone, margin, interactivity)
is double-buffered, and will be applied at the time wl_surface.commit of
the corresponding wl_surface is called.
</description>
<request name="set_size">
<description summary="sets the size of the surface">
Sets the size of the surface in surface-local coordinates. The
compositor will display the surface centered with respect to its
anchors.
If you pass 0 for either value, the compositor will assign it and
inform you of the assignment in the configure event. You must set your
anchor to opposite edges in the dimensions you omit; not doing so is a
protocol error. Both values are 0 by default.
Size is double-buffered, see wl_surface.commit.
</description>
<arg name="width" type="uint"/>
<arg name="height" type="uint"/>
</request>
<request name="set_anchor">
<description summary="configures the anchor point of the surface">
Requests that the compositor anchor the surface to the specified edges
and corners. If two orthoginal edges are specified (e.g. 'top' and
'left'), then the anchor point will be the intersection of the edges
(e.g. the top left corner of the output); otherwise the anchor point
will be centered on that edge, or in the center if none is specified.
Anchor is double-buffered, see wl_surface.commit.
</description>
<arg name="anchor" type="uint" enum="anchor"/>
</request>
<request name="set_exclusive_zone">
<description summary="configures the exclusive geometry of this surface">
Requests that the compositor avoids occluding an area of the surface
with other surfaces. The compositor's use of this information is
implementation-dependent - do not assume that this region will not
actually be occluded.
A positive value is only meaningful if the surface is anchored to an
edge, rather than a corner. The zone is the number of surface-local
coordinates from the edge that are considered exclusive.
Surfaces that do not wish to have an exclusive zone may instead specify
how they should interact with surfaces that do. If set to zero, the
surface indicates that it would like to be moved to avoid occluding
surfaces with a positive excluzive zone. If set to -1, the surface
indicates that it would not like to be moved to accomodate for other
surfaces, and the compositor should extend it all the way to the edges
it is anchored to.
For example, a panel might set its exclusive zone to 10, so that
maximized shell surfaces are not shown on top of it. A notification
might set its exclusive zone to 0, so that it is moved to avoid
occluding the panel, but shell surfaces are shown underneath it. A
wallpaper or lock screen might set their exclusive zone to -1, so that
they stretch below or over the panel.
The default value is 0.
Exclusive zone is double-buffered, see wl_surface.commit.
</description>
<arg name="zone" type="int"/>
</request>
<request name="set_margin">
<description summary="sets a margin from the anchor point">
Requests that the surface be placed some distance away from the anchor
point on the output, in surface-local coordinates. Setting this value
for edges you are not anchored to has no effect.
The exclusive zone includes the margin.
Margin is double-buffered, see wl_surface.commit.
</description>
<arg name="top" type="int"/>
<arg name="right" type="int"/>
<arg name="bottom" type="int"/>
<arg name="left" type="int"/>
</request>
<request name="set_keyboard_interactivity">
<description summary="requests keyboard events">
Set to 1 to request that the seat send keyboard events to this layer
surface. For layers below the shell surface layer, the seat will use
normal focus semantics. For layers above the shell surface layers, the
seat will always give exclusive keyboard focus to the top-most layer
which has keyboard interactivity set to true.
Layer surfaces receive pointer, touch, and tablet events normally. If
you do not want to receive them, set the input region on your surface
to an empty region.