Requires clients to have the X-KDE-Wayland-Interfaces=kde_lockscreenallowed_v1 set in their desktop file, then they will be able to use the kde_lockscreenallowed_v1 protocol to raise any surface above the lockscreen. The protocol has only 1 method, raise_surface to do exactly that. Makes it possible to implement https://invent.kde.org/teams/plasma-mobile/issues/-/issues/98remotes/origin/work/zzag/batch-output-updates
parent
123549f8f3
commit
4f20e9216f
12 changed files with 245 additions and 4 deletions
@ -0,0 +1,54 @@ |
||||
/*
|
||||
SPDX-FileCopyrightText: 2022 Aleix Pol Gonzalez <aleixpol@kde.org> |
||||
|
||||
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
||||
*/ |
||||
|
||||
#include "lockscreen_overlay_v1_interface.h" |
||||
#include "display.h" |
||||
#include "seat_interface.h" |
||||
#include "surface_interface.h" |
||||
|
||||
#include "qwayland-server-kde-lockscreen-overlay-v1.h" |
||||
|
||||
namespace KWaylandServer |
||||
{ |
||||
static constexpr int s_version = 1; |
||||
|
||||
class LockscreenOverlayV1InterfacePrivate : public QtWaylandServer::kde_lockscreen_overlay_v1 |
||||
{ |
||||
public: |
||||
LockscreenOverlayV1InterfacePrivate(Display *display, LockscreenOverlayV1Interface *q) |
||||
: QtWaylandServer::kde_lockscreen_overlay_v1(*display, s_version) |
||||
, q(q) |
||||
{ |
||||
} |
||||
|
||||
protected: |
||||
void kde_lockscreen_overlay_v1_allow(Resource *resource, struct ::wl_resource *surface) override |
||||
{ |
||||
auto surfaceIface = SurfaceInterface::get(surface); |
||||
if (surfaceIface->isMapped()) { |
||||
wl_resource_post_error(resource->handle, error_invalid_surface_state, "surface is already mapped"); |
||||
return; |
||||
} |
||||
Q_EMIT q->allowRequested(surfaceIface); |
||||
} |
||||
void kde_lockscreen_overlay_v1_destroy(Resource *resource) override |
||||
{ |
||||
wl_resource_destroy(resource->handle); |
||||
} |
||||
|
||||
private: |
||||
LockscreenOverlayV1Interface *const q; |
||||
}; |
||||
|
||||
LockscreenOverlayV1Interface::~LockscreenOverlayV1Interface() = default; |
||||
|
||||
LockscreenOverlayV1Interface::LockscreenOverlayV1Interface(Display *display, QObject *parent) |
||||
: QObject(parent) |
||||
, d(new LockscreenOverlayV1InterfacePrivate(display, this)) |
||||
{ |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,43 @@ |
||||
/*
|
||||
SPDX-FileCopyrightText: 2022 Aleix Pol Gonzalez <aleixpol@kde.org> |
||||
|
||||
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
||||
*/ |
||||
|
||||
#pragma once |
||||
|
||||
#include "kwin_export.h" |
||||
|
||||
#include <QObject> |
||||
#include <QVector> |
||||
#include <functional> |
||||
#include <optional> |
||||
|
||||
struct wl_resource; |
||||
|
||||
namespace KWaylandServer |
||||
{ |
||||
class Display; |
||||
class SurfaceInterface; |
||||
|
||||
class LockscreenOverlayV1InterfacePrivate; |
||||
|
||||
class KWIN_EXPORT LockscreenOverlayV1Interface : public QObject |
||||
{ |
||||
Q_OBJECT |
||||
Q_DISABLE_COPY(LockscreenOverlayV1Interface) |
||||
public: |
||||
explicit LockscreenOverlayV1Interface(Display *display, QObject *parent = nullptr); |
||||
~LockscreenOverlayV1Interface() override; |
||||
|
||||
Q_SIGNALS: |
||||
/// Notifies about the @p surface being activated
|
||||
void allowRequested(SurfaceInterface *surface); |
||||
|
||||
private: |
||||
friend class LockscreenOverlayV1InterfacePrivate; |
||||
LockscreenOverlayV1Interface(LockscreenOverlayV1Interface *parent); |
||||
QScopedPointer<LockscreenOverlayV1InterfacePrivate> d; |
||||
}; |
||||
|
||||
} |
||||
@ -0,0 +1,89 @@ |
||||
/*
|
||||
SPDX-FileCopyrightText: 2022 Aleix Pol Gonzalez <aleixpol@kde.org> |
||||
|
||||
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL |
||||
*/ |
||||
|
||||
#include "qwayland-kde-lockscreen-overlay-v1.h" |
||||
#include <KWindowSystem> |
||||
#include <QWaylandClientExtensionTemplate> |
||||
#include <QtWidgets> |
||||
#include <qpa/qplatformnativeinterface.h> |
||||
|
||||
class WaylandAboveLockscreen : public QWaylandClientExtensionTemplate<WaylandAboveLockscreen>, public QtWayland::kde_lockscreen_overlay_v1 |
||||
{ |
||||
public: |
||||
WaylandAboveLockscreen() |
||||
: QWaylandClientExtensionTemplate<WaylandAboveLockscreen>(1) |
||||
{ |
||||
QMetaObject::invokeMethod(this, "addRegistryListener"); |
||||
} |
||||
|
||||
void allowWindow(QWindow *window) |
||||
{ |
||||
QPlatformNativeInterface *native = qGuiApp->platformNativeInterface(); |
||||
wl_surface *surface = reinterpret_cast<wl_surface *>(native->nativeResourceForWindow(QByteArrayLiteral("surface"), window)); |
||||
allow(surface); |
||||
} |
||||
}; |
||||
|
||||
class WidgetAllower : public QObject |
||||
{ |
||||
public: |
||||
WidgetAllower(QWidget *widget) |
||||
: QObject(widget) |
||||
, m_widget(widget) |
||||
{ |
||||
widget->installEventFilter(this); |
||||
} |
||||
|
||||
bool eventFilter(QObject * /*watched*/, QEvent *event) override |
||||
{ |
||||
if (auto w = m_widget->windowHandle()) { |
||||
WaylandAboveLockscreen aboveLockscreen; |
||||
Q_ASSERT(aboveLockscreen.isInitialized()); |
||||
aboveLockscreen.allowWindow(w); |
||||
deleteLater(); |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
QWidget *const m_widget; |
||||
}; |
||||
|
||||
int main(int argc, char *argv[]) |
||||
{ |
||||
|
||||
QApplication app(argc, argv); |
||||
QWidget window1(nullptr, Qt::Window); |
||||
window1.setWindowTitle("Window 1"); |
||||
window1.setLayout(new QVBoxLayout); |
||||
QPushButton p("Lock && Raise the Window 2"); |
||||
window1.layout()->addWidget(&p); |
||||
window1.show(); |
||||
|
||||
QWidget window2(nullptr, Qt::Window); |
||||
window2.setWindowTitle("Window 2"); |
||||
window2.setLayout(new QVBoxLayout); |
||||
QPushButton p2("Close"); |
||||
window2.layout()->addWidget(&p2); |
||||
|
||||
new WidgetAllower(&window2); |
||||
auto raiseWindow2 = [&] { |
||||
KWindowSystem::requestXdgActivationToken(window2.windowHandle(), 0, "lockscreenoverlaytest.desktop"); |
||||
}; |
||||
QObject::connect(KWindowSystem::self(), &KWindowSystem::xdgActivationTokenArrived, &window2, [&window2](int, const QString &token) { |
||||
KWindowSystem::setCurrentXdgActivationToken(token); |
||||
KWindowSystem::activateWindow(window2.windowHandle()); |
||||
}); |
||||
|
||||
QObject::connect(&p, &QPushButton::clicked, &app, [&] { |
||||
QProcess::execute("loginctl", {"lock-session"}); |
||||
window2.showFullScreen(); |
||||
QTimer::singleShot(3000, &app, raiseWindow2); |
||||
}); |
||||
|
||||
QObject::connect(&p2, &QPushButton::clicked, &window2, &QWidget::close); |
||||
|
||||
return app.exec(); |
||||
} |
||||
@ -0,0 +1,9 @@ |
||||
# copy to $(qtpaths --install-prefix)/share/applications/ |
||||
# remember to change the Exec line to your builddir path |
||||
|
||||
[Desktop Entry] |
||||
Exec=absolute/path/to/the/executable/bin/lockscreenoverlaytest |
||||
Type=Application |
||||
X-KDE-Wayland-Interfaces=kde_lockscreen_overlay_v1 |
||||
NoDisplay=true |
||||
Name=KWin LockScreen Overay Test |
||||
Loading…
Reference in new issue