2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2015-02-09 12:28:37 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2015 Martin Gräßlin <mgraesslin@kde.org>
|
2015-02-09 12:28:37 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2015-02-09 12:28:37 +00:00
|
|
|
#include "wayland_server.h"
|
2022-03-23 10:13:38 +00:00
|
|
|
|
|
|
|
#include <config-kwin.h>
|
|
|
|
|
2022-10-11 16:42:19 +00:00
|
|
|
#include "backends/drm/drm_backend.h"
|
2022-08-29 07:55:49 +00:00
|
|
|
#include "core/output.h"
|
2022-11-05 10:43:41 +00:00
|
|
|
#include "core/outputbackend.h"
|
2017-11-16 20:48:19 +00:00
|
|
|
#include "idle_inhibition.h"
|
2020-09-04 07:03:04 +00:00
|
|
|
#include "inputpanelv1integration.h"
|
2020-08-07 19:01:42 +00:00
|
|
|
#include "layershellv1integration.h"
|
2023-03-08 08:07:39 +00:00
|
|
|
#include "layershellv1window.h"
|
2020-11-07 02:03:57 +00:00
|
|
|
#include "main.h"
|
2023-11-23 13:48:04 +00:00
|
|
|
#include "options.h"
|
2022-01-13 14:02:41 +00:00
|
|
|
#include "utils/serviceutils.h"
|
2022-03-23 10:13:38 +00:00
|
|
|
#include "virtualdesktops.h"
|
2023-09-13 05:52:59 +00:00
|
|
|
#include "wayland/appmenu.h"
|
2024-01-02 15:17:18 +00:00
|
|
|
#include "wayland/clientconnection.h"
|
2023-09-13 05:52:59 +00:00
|
|
|
#include "wayland/compositor.h"
|
|
|
|
#include "wayland/contenttype_v1.h"
|
|
|
|
#include "wayland/cursorshape_v1.h"
|
|
|
|
#include "wayland/datacontroldevicemanager_v1.h"
|
|
|
|
#include "wayland/datadevicemanager.h"
|
2022-04-22 09:27:33 +00:00
|
|
|
#include "wayland/display.h"
|
2023-09-13 05:52:59 +00:00
|
|
|
#include "wayland/dpms.h"
|
2023-04-11 15:08:47 +00:00
|
|
|
#include "wayland/drmclientbuffer.h"
|
2023-09-13 05:52:59 +00:00
|
|
|
#include "wayland/drmlease_v1.h"
|
2022-04-22 09:27:33 +00:00
|
|
|
#include "wayland/filtered_display.h"
|
2023-09-13 05:52:59 +00:00
|
|
|
#include "wayland/fractionalscale_v1.h"
|
2023-10-25 16:36:33 +00:00
|
|
|
#include "wayland/frog_colormanagement_v1.h"
|
2023-09-13 05:52:59 +00:00
|
|
|
#include "wayland/idle.h"
|
|
|
|
#include "wayland/idleinhibit_v1.h"
|
|
|
|
#include "wayland/idlenotify_v1.h"
|
|
|
|
#include "wayland/inputmethod_v1.h"
|
|
|
|
#include "wayland/keyboard_shortcuts_inhibit_v1.h"
|
|
|
|
#include "wayland/keystate.h"
|
2022-04-22 09:27:33 +00:00
|
|
|
#include "wayland/linuxdmabufv1clientbuffer.h"
|
2023-09-13 05:52:59 +00:00
|
|
|
#include "wayland/lockscreen_overlay_v1.h"
|
|
|
|
#include "wayland/output.h"
|
|
|
|
#include "wayland/output_order_v1.h"
|
|
|
|
#include "wayland/outputdevice_v2.h"
|
|
|
|
#include "wayland/outputmanagement_v2.h"
|
|
|
|
#include "wayland/plasmashell.h"
|
|
|
|
#include "wayland/plasmavirtualdesktop.h"
|
|
|
|
#include "wayland/plasmawindowmanagement.h"
|
|
|
|
#include "wayland/pointerconstraints_v1.h"
|
|
|
|
#include "wayland/pointergestures_v1.h"
|
2023-10-19 14:35:14 +00:00
|
|
|
#include "wayland/presentationtime.h"
|
2023-09-13 05:52:59 +00:00
|
|
|
#include "wayland/primaryselectiondevicemanager_v1.h"
|
|
|
|
#include "wayland/relativepointer_v1.h"
|
|
|
|
#include "wayland/screenedge_v1.h"
|
|
|
|
#include "wayland/seat.h"
|
2023-11-13 09:51:28 +00:00
|
|
|
#include "wayland/securitycontext_v1.h"
|
2023-09-13 05:52:59 +00:00
|
|
|
#include "wayland/server_decoration.h"
|
|
|
|
#include "wayland/server_decoration_palette.h"
|
|
|
|
#include "wayland/shadow.h"
|
|
|
|
#include "wayland/subcompositor.h"
|
|
|
|
#include "wayland/tablet_v2.h"
|
|
|
|
#include "wayland/tearingcontrol_v1.h"
|
|
|
|
#include "wayland/viewporter.h"
|
|
|
|
#include "wayland/xdgactivation_v1.h"
|
|
|
|
#include "wayland/xdgdecoration_v1.h"
|
|
|
|
#include "wayland/xdgforeign_v2.h"
|
|
|
|
#include "wayland/xdgoutput_v1.h"
|
|
|
|
#include "wayland/xdgshell.h"
|
|
|
|
#include "wayland/xdgtopleveldrag_v1.h"
|
|
|
|
#include "wayland/xwaylandkeyboardgrab_v1.h"
|
|
|
|
#include "wayland/xwaylandshell_v1.h"
|
2022-03-23 10:13:38 +00:00
|
|
|
#include "workspace.h"
|
2022-04-22 17:54:31 +00:00
|
|
|
#include "x11window.h"
|
2022-03-23 10:13:38 +00:00
|
|
|
#include "xdgactivationv1.h"
|
|
|
|
#include "xdgshellintegration.h"
|
2022-04-22 18:11:29 +00:00
|
|
|
#include "xdgshellwindow.h"
|
2015-02-09 12:28:37 +00:00
|
|
|
|
2015-05-18 09:23:45 +00:00
|
|
|
// Qt
|
2018-11-07 11:49:09 +00:00
|
|
|
#include <QDir>
|
|
|
|
#include <QFileInfo>
|
2015-05-18 09:23:45 +00:00
|
|
|
|
2015-02-25 13:15:32 +00:00
|
|
|
// system
|
|
|
|
#include <sys/socket.h>
|
2022-03-23 10:13:38 +00:00
|
|
|
#include <sys/types.h>
|
2016-06-20 09:21:16 +00:00
|
|
|
#include <unistd.h>
|
2015-02-25 13:15:32 +00:00
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
// screenlocker
|
2022-02-28 18:58:35 +00:00
|
|
|
#if KWIN_BUILD_SCREENLOCKER
|
2015-11-05 13:09:23 +00:00
|
|
|
#include <KScreenLocker/KsldApp>
|
2022-02-23 13:27:05 +00:00
|
|
|
#endif
|
2015-11-05 13:09:23 +00:00
|
|
|
|
2015-02-09 12:28:37 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
KWIN_SINGLETON_FACTORY(WaylandServer)
|
|
|
|
|
2023-09-13 17:59:29 +00:00
|
|
|
class KWinDisplay : public FilteredDisplay
|
2020-11-18 16:41:16 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
KWinDisplay(QObject *parent)
|
2023-09-13 17:59:29 +00:00
|
|
|
: FilteredDisplay(parent)
|
2022-03-23 10:13:38 +00:00
|
|
|
{
|
|
|
|
}
|
2020-11-18 16:41:16 +00:00
|
|
|
|
2023-09-13 17:59:29 +00:00
|
|
|
QStringList fetchRequestedInterfaces(ClientConnection *client) const
|
2022-03-23 10:13:38 +00:00
|
|
|
{
|
2023-11-13 10:32:54 +00:00
|
|
|
if (!client->securityContextAppId().isEmpty()) {
|
|
|
|
return KWin::fetchRequestedInterfacesForDesktopId(client->securityContextAppId());
|
|
|
|
}
|
2020-11-18 16:41:16 +00:00
|
|
|
return KWin::fetchRequestedInterfaces(client->executablePath());
|
|
|
|
}
|
|
|
|
|
2021-08-22 09:49:57 +00:00
|
|
|
const QSet<QByteArray> interfacesBlackList = {
|
|
|
|
QByteArrayLiteral("org_kde_kwin_remote_access_manager"),
|
|
|
|
QByteArrayLiteral("org_kde_plasma_window_management"),
|
|
|
|
QByteArrayLiteral("org_kde_kwin_fake_input"),
|
|
|
|
QByteArrayLiteral("org_kde_kwin_keystate"),
|
|
|
|
QByteArrayLiteral("zkde_screencast_unstable_v1"),
|
|
|
|
QByteArrayLiteral("org_kde_plasma_activation_feedback"),
|
2022-05-12 16:04:12 +00:00
|
|
|
QByteArrayLiteral("kde_lockscreen_overlay_v1"),
|
2021-08-22 09:49:57 +00:00
|
|
|
};
|
2020-11-18 16:41:16 +00:00
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
const QSet<QByteArray> inputmethodInterfaces = {"zwp_input_panel_v1", "zwp_input_method_v1"};
|
2022-10-04 11:56:45 +00:00
|
|
|
const QSet<QByteArray> xwaylandInterfaces = {
|
|
|
|
QByteArrayLiteral("zwp_xwayland_keyboard_grab_manager_v1"),
|
|
|
|
QByteArrayLiteral("xwayland_shell_v1"),
|
|
|
|
};
|
2020-11-18 16:41:16 +00:00
|
|
|
|
|
|
|
QSet<QString> m_reported;
|
|
|
|
|
2023-09-13 17:59:29 +00:00
|
|
|
bool allowInterface(ClientConnection *client, const QByteArray &interfaceName) override
|
2022-03-23 10:13:38 +00:00
|
|
|
{
|
2023-11-13 09:51:28 +00:00
|
|
|
if (!client->securityContextAppId().isEmpty() && interfaceName == QByteArrayLiteral("wp_security_context_manager_v1")) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-11-18 16:41:16 +00:00
|
|
|
if (client->processId() == getpid()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (client != waylandServer()->inputMethodConnection() && inputmethodInterfaces.contains(interfaceName)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-10-04 11:56:45 +00:00
|
|
|
if (client != waylandServer()->xWaylandConnection() && xwaylandInterfaces.contains(interfaceName)) {
|
2022-08-03 07:08:56 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-11-18 16:41:16 +00:00
|
|
|
if (!interfacesBlackList.contains(interfaceName)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (client->executablePath().isEmpty()) {
|
2021-04-01 11:48:44 +00:00
|
|
|
qCDebug(KWIN_CORE) << "Could not identify process with pid" << client->processId();
|
2020-11-18 16:41:16 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-12-13 12:24:38 +00:00
|
|
|
static bool permissionCheckDisabled = qEnvironmentVariableIntValue("KWIN_WAYLAND_NO_PERMISSION_CHECKS") == 1;
|
|
|
|
if (!permissionCheckDisabled) {
|
2020-11-18 16:41:16 +00:00
|
|
|
auto requestedInterfaces = client->property("requestedInterfaces");
|
|
|
|
if (requestedInterfaces.isNull()) {
|
|
|
|
requestedInterfaces = fetchRequestedInterfaces(client);
|
|
|
|
client->setProperty("requestedInterfaces", requestedInterfaces);
|
|
|
|
}
|
|
|
|
if (!requestedInterfaces.toStringList().contains(QString::fromUtf8(interfaceName))) {
|
|
|
|
if (KWIN_CORE().isDebugEnabled()) {
|
|
|
|
const QString id = client->executablePath() + QLatin1Char('|') + QString::fromUtf8(interfaceName);
|
2022-07-15 11:06:16 +00:00
|
|
|
if (!m_reported.contains(id)) {
|
2020-11-18 16:41:16 +00:00
|
|
|
m_reported.insert(id);
|
|
|
|
qCDebug(KWIN_CORE) << "Interface" << interfaceName << "not in X-KDE-Wayland-Interfaces of" << client->executablePath();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
qCDebug(KWIN_CORE) << "authorized" << client->executablePath() << interfaceName;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-02-09 12:28:37 +00:00
|
|
|
WaylandServer::WaylandServer(QObject *parent)
|
|
|
|
: QObject(parent)
|
2020-11-18 16:41:16 +00:00
|
|
|
, m_display(new KWinDisplay(this))
|
2015-02-09 12:28:37 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-11-10 13:38:45 +00:00
|
|
|
WaylandServer::~WaylandServer()
|
|
|
|
{
|
2021-10-07 15:26:43 +00:00
|
|
|
s_self = nullptr;
|
2015-11-10 13:38:45 +00:00
|
|
|
}
|
2015-11-10 07:52:40 +00:00
|
|
|
|
2023-09-13 17:59:29 +00:00
|
|
|
ClientConnection *WaylandServer::xWaylandConnection() const
|
2020-07-20 08:07:08 +00:00
|
|
|
{
|
|
|
|
return m_xwaylandConnection;
|
|
|
|
}
|
|
|
|
|
2023-09-13 17:59:29 +00:00
|
|
|
ClientConnection *WaylandServer::inputMethodConnection() const
|
2021-12-13 17:29:16 +00:00
|
|
|
{
|
|
|
|
return m_inputMethodServerConnection;
|
|
|
|
}
|
|
|
|
|
2022-04-23 08:33:23 +00:00
|
|
|
void WaylandServer::registerWindow(Window *window)
|
2016-04-22 12:13:37 +00:00
|
|
|
{
|
2022-04-23 08:33:23 +00:00
|
|
|
if (window->readyForPainting()) {
|
|
|
|
Q_EMIT windowAdded(window);
|
2020-02-17 18:39:17 +00:00
|
|
|
} else {
|
2023-03-16 08:47:15 +00:00
|
|
|
connect(window, &Window::windowShown, this, &WaylandServer::windowAdded, Qt::SingleShotConnection);
|
2020-02-17 18:39:17 +00:00
|
|
|
}
|
2022-04-23 08:33:23 +00:00
|
|
|
m_windows << window;
|
2020-02-17 18:39:17 +00:00
|
|
|
}
|
|
|
|
|
2022-04-23 08:33:23 +00:00
|
|
|
void WaylandServer::registerXdgToplevelWindow(XdgToplevelWindow *window)
|
2020-02-17 18:39:17 +00:00
|
|
|
{
|
2020-05-07 14:29:41 +00:00
|
|
|
// TODO: Find a better way and more generic to install extensions.
|
2020-02-17 18:39:17 +00:00
|
|
|
|
2022-04-23 08:33:23 +00:00
|
|
|
SurfaceInterface *surface = window->surface();
|
2020-07-13 11:38:12 +00:00
|
|
|
|
2022-04-23 08:33:23 +00:00
|
|
|
registerWindow(window);
|
2020-02-17 18:39:17 +00:00
|
|
|
|
2021-05-13 06:19:44 +00:00
|
|
|
if (auto shellSurface = PlasmaShellSurfaceInterface::get(surface)) {
|
2022-04-23 08:33:23 +00:00
|
|
|
window->installPlasmaShellSurface(shellSurface);
|
2017-02-07 18:18:18 +00:00
|
|
|
}
|
2020-02-17 18:39:17 +00:00
|
|
|
if (auto decoration = ServerSideDecorationInterface::get(surface)) {
|
2022-04-23 08:33:23 +00:00
|
|
|
window->installServerDecoration(decoration);
|
2020-02-17 18:39:17 +00:00
|
|
|
}
|
2022-04-23 08:33:23 +00:00
|
|
|
if (auto decoration = XdgToplevelDecorationV1Interface::get(window->shellSurface())) {
|
|
|
|
window->installXdgDecoration(decoration);
|
2020-05-07 14:29:41 +00:00
|
|
|
}
|
2020-02-17 18:39:17 +00:00
|
|
|
if (auto menu = m_appMenuManager->appMenuForSurface(surface)) {
|
2022-04-23 08:33:23 +00:00
|
|
|
window->installAppMenu(menu);
|
2017-12-22 14:22:24 +00:00
|
|
|
}
|
2020-02-17 18:39:17 +00:00
|
|
|
if (auto palette = m_paletteManager->paletteForSurface(surface)) {
|
2022-04-23 08:33:23 +00:00
|
|
|
window->installPalette(palette);
|
2018-01-04 18:32:18 +00:00
|
|
|
}
|
2017-10-13 09:32:02 +00:00
|
|
|
|
2022-04-23 08:33:23 +00:00
|
|
|
connect(m_XdgForeign, &XdgForeignV2Interface::transientChanged, window, [this](SurfaceInterface *child) {
|
2021-06-08 07:02:14 +00:00
|
|
|
Q_EMIT foreignTransientChanged(child);
|
2017-10-13 09:32:02 +00:00
|
|
|
});
|
2016-04-22 12:13:37 +00:00
|
|
|
}
|
|
|
|
|
2022-04-23 08:33:23 +00:00
|
|
|
void WaylandServer::registerXdgGenericWindow(Window *window)
|
2020-02-17 18:39:17 +00:00
|
|
|
{
|
2022-04-23 08:33:23 +00:00
|
|
|
if (auto toplevel = qobject_cast<XdgToplevelWindow *>(window)) {
|
|
|
|
registerXdgToplevelWindow(toplevel);
|
2020-02-17 18:39:17 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-04-23 08:33:23 +00:00
|
|
|
if (auto popup = qobject_cast<XdgPopupWindow *>(window)) {
|
|
|
|
registerWindow(popup);
|
|
|
|
if (auto shellSurface = PlasmaShellSurfaceInterface::get(popup->surface())) {
|
|
|
|
popup->installPlasmaShellSurface(shellSurface);
|
2020-08-04 01:15:59 +00:00
|
|
|
}
|
2020-05-07 14:29:41 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-04-23 08:33:23 +00:00
|
|
|
qCDebug(KWIN_CORE) << "Received invalid xdg shell window:" << window->surface();
|
2020-02-17 18:39:17 +00:00
|
|
|
}
|
|
|
|
|
2022-04-14 12:33:28 +00:00
|
|
|
void WaylandServer::handleOutputAdded(Output *output)
|
2021-04-04 14:11:13 +00:00
|
|
|
{
|
2022-07-11 10:41:15 +00:00
|
|
|
if (!output->isPlaceholder() && !output->isNonDesktop()) {
|
2023-09-13 17:59:29 +00:00
|
|
|
m_waylandOutputDevices.insert(output, new OutputDeviceV2Interface(m_display, output));
|
2021-07-26 23:11:50 +00:00
|
|
|
}
|
2021-04-04 14:11:13 +00:00
|
|
|
}
|
|
|
|
|
2022-04-14 12:33:28 +00:00
|
|
|
void WaylandServer::handleOutputRemoved(Output *output)
|
2021-04-04 14:11:13 +00:00
|
|
|
{
|
2022-08-18 09:19:40 +00:00
|
|
|
if (auto outputDevice = m_waylandOutputDevices.take(output)) {
|
|
|
|
outputDevice->remove();
|
2021-07-26 23:11:50 +00:00
|
|
|
}
|
2021-04-04 14:11:13 +00:00
|
|
|
}
|
|
|
|
|
2022-04-14 12:33:28 +00:00
|
|
|
void WaylandServer::handleOutputEnabled(Output *output)
|
2021-04-04 14:11:13 +00:00
|
|
|
{
|
2022-07-11 10:41:15 +00:00
|
|
|
if (!output->isPlaceholder() && !output->isNonDesktop()) {
|
2023-09-13 17:59:29 +00:00
|
|
|
auto waylandOutput = new OutputInterface(waylandServer()->display(), output);
|
2022-10-27 10:37:46 +00:00
|
|
|
m_xdgOutputManagerV1->offer(waylandOutput);
|
2022-10-20 09:30:43 +00:00
|
|
|
|
|
|
|
m_waylandOutputs.insert(output, waylandOutput);
|
2021-07-26 23:11:50 +00:00
|
|
|
}
|
2021-04-04 14:11:13 +00:00
|
|
|
}
|
|
|
|
|
2022-04-14 12:33:28 +00:00
|
|
|
void WaylandServer::handleOutputDisabled(Output *output)
|
2021-04-04 14:11:13 +00:00
|
|
|
{
|
2022-10-20 09:30:43 +00:00
|
|
|
if (auto waylandOutput = m_waylandOutputs.take(output)) {
|
|
|
|
waylandOutput->remove();
|
2021-07-26 23:11:50 +00:00
|
|
|
}
|
2021-04-04 14:11:13 +00:00
|
|
|
}
|
|
|
|
|
2020-07-07 09:45:55 +00:00
|
|
|
bool WaylandServer::start()
|
|
|
|
{
|
|
|
|
return m_display->start();
|
|
|
|
}
|
|
|
|
|
2020-12-09 13:06:15 +00:00
|
|
|
bool WaylandServer::init(const QString &socketName, InitializationFlags flags)
|
2015-02-09 12:28:37 +00:00
|
|
|
{
|
2020-12-09 13:06:15 +00:00
|
|
|
if (!m_display->addSocketName(socketName)) {
|
2020-11-17 13:26:01 +00:00
|
|
|
return false;
|
2015-02-09 12:28:37 +00:00
|
|
|
}
|
2020-11-17 18:09:28 +00:00
|
|
|
return init(flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WaylandServer::init(InitializationFlags flags)
|
|
|
|
{
|
|
|
|
m_initFlags = flags;
|
2020-12-09 21:24:41 +00:00
|
|
|
m_compositor = new CompositorInterface(m_display, m_display);
|
2022-03-23 10:13:38 +00:00
|
|
|
connect(m_compositor, &CompositorInterface::surfaceCreated, this, [this](SurfaceInterface *surface) {
|
2022-04-22 17:39:12 +00:00
|
|
|
// check whether we have a Window with the Surface's id
|
2022-03-23 10:13:38 +00:00
|
|
|
Workspace *ws = Workspace::self();
|
|
|
|
if (!ws) {
|
|
|
|
// it's possible that a Surface gets created before Workspace is created
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (surface->client() != xWaylandConnection()) {
|
|
|
|
// setting surface is only relevant for Xwayland clients
|
|
|
|
return;
|
|
|
|
}
|
2020-11-04 13:35:37 +00:00
|
|
|
|
2022-04-23 08:33:23 +00:00
|
|
|
X11Window *window = ws->findClient([surface](const X11Window *window) {
|
|
|
|
return window->pendingSurfaceId() == surface->id();
|
2022-03-23 10:13:38 +00:00
|
|
|
});
|
2022-04-23 08:33:23 +00:00
|
|
|
if (window) {
|
|
|
|
window->setSurface(surface);
|
2022-03-23 10:13:38 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-11-04 13:35:37 +00:00
|
|
|
|
2023-03-28 11:38:19 +00:00
|
|
|
X11Window *unmanaged = ws->findUnmanaged([surface](const X11Window *unmanaged) {
|
2022-03-23 10:13:38 +00:00
|
|
|
return unmanaged->pendingSurfaceId() == surface->id();
|
|
|
|
});
|
|
|
|
if (unmanaged) {
|
|
|
|
unmanaged->setSurface(surface);
|
|
|
|
return;
|
2015-02-09 15:08:53 +00:00
|
|
|
}
|
2022-03-23 10:13:38 +00:00
|
|
|
|
|
|
|
// The surface will be bound later when a WL_SURFACE_ID message is received.
|
|
|
|
});
|
2018-09-14 11:04:33 +00:00
|
|
|
|
2023-09-13 17:59:29 +00:00
|
|
|
m_xwaylandShell = new XwaylandShellV1Interface(m_display, m_display);
|
|
|
|
connect(m_xwaylandShell, &XwaylandShellV1Interface::surfaceAssociated, this, [](XwaylandSurfaceV1Interface *surface) {
|
2022-10-04 11:56:45 +00:00
|
|
|
X11Window *window = workspace()->findClient([&surface](const X11Window *window) {
|
|
|
|
return window->surfaceSerial() == surface->serial();
|
|
|
|
});
|
|
|
|
if (window) {
|
|
|
|
window->setSurface(surface->surface());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-03-28 11:38:19 +00:00
|
|
|
X11Window *unmanaged = workspace()->findUnmanaged([&surface](const X11Window *window) {
|
2022-10-04 11:56:45 +00:00
|
|
|
return window->surfaceSerial() == surface->serial();
|
|
|
|
});
|
|
|
|
if (unmanaged) {
|
|
|
|
unmanaged->setSurface(surface->surface());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-12-09 21:24:41 +00:00
|
|
|
m_tabletManagerV2 = new TabletManagerV2Interface(m_display, m_display);
|
|
|
|
m_keyboardShortcutsInhibitManager = new KeyboardShortcutsInhibitManagerV1Interface(m_display, m_display);
|
2020-02-17 18:39:17 +00:00
|
|
|
|
2020-12-09 21:24:41 +00:00
|
|
|
m_xdgDecorationManagerV1 = new XdgDecorationManagerV1Interface(m_display, m_display);
|
2022-03-23 10:13:38 +00:00
|
|
|
connect(m_xdgDecorationManagerV1, &XdgDecorationManagerV1Interface::decorationCreated, this, [this](XdgToplevelDecorationV1Interface *decoration) {
|
2022-04-22 18:11:29 +00:00
|
|
|
if (XdgToplevelWindow *toplevel = findXdgToplevelWindow(decoration->toplevel()->surface())) {
|
2022-03-23 10:13:38 +00:00
|
|
|
toplevel->installXdgDecoration(decoration);
|
2019-01-01 17:37:18 +00:00
|
|
|
}
|
2022-03-23 10:13:38 +00:00
|
|
|
});
|
2019-01-01 17:37:18 +00:00
|
|
|
|
2020-12-09 21:24:41 +00:00
|
|
|
new ViewporterInterface(m_display, m_display);
|
2023-11-13 09:51:28 +00:00
|
|
|
new SecurityContextManagerV1Interface(m_display, m_display);
|
2022-06-30 22:23:35 +00:00
|
|
|
new FractionalScaleManagerV1Interface(m_display, m_display);
|
2015-02-09 12:28:37 +00:00
|
|
|
m_display->createShm();
|
2020-12-09 21:24:41 +00:00
|
|
|
m_seat = new SeatInterface(m_display, m_display);
|
|
|
|
new PointerGesturesV1Interface(m_display, m_display);
|
|
|
|
new PointerConstraintsV1Interface(m_display, m_display);
|
2021-10-05 18:37:58 +00:00
|
|
|
new RelativePointerManagerV1Interface(m_display, m_display);
|
2020-12-09 21:24:41 +00:00
|
|
|
m_dataDeviceManager = new DataDeviceManagerInterface(m_display, m_display);
|
|
|
|
new DataControlDeviceManagerV1Interface(m_display, m_display);
|
2023-05-05 11:14:34 +00:00
|
|
|
new CursorShapeManagerV1Interface(m_display, m_display);
|
2022-05-28 14:38:53 +00:00
|
|
|
|
|
|
|
const auto kwinConfig = kwinApp()->config();
|
2023-11-27 13:11:22 +00:00
|
|
|
if (kwinConfig->group(QStringLiteral("Wayland")).readEntry("EnablePrimarySelection", true)) {
|
2022-12-14 09:34:27 +00:00
|
|
|
new PrimarySelectionDeviceManagerV1Interface(m_display, m_display);
|
|
|
|
}
|
2022-05-28 14:38:53 +00:00
|
|
|
|
2020-12-09 21:24:41 +00:00
|
|
|
m_idle = new IdleInterface(m_display, m_display);
|
2017-12-29 17:29:19 +00:00
|
|
|
auto idleInhibition = new IdleInhibition(m_idle);
|
2022-04-23 08:33:23 +00:00
|
|
|
connect(this, &WaylandServer::windowAdded, idleInhibition, &IdleInhibition::registerClient);
|
2020-12-09 21:24:41 +00:00
|
|
|
new IdleInhibitManagerV1Interface(m_display, m_display);
|
2022-09-16 09:12:17 +00:00
|
|
|
new IdleNotifyV1Interface(m_display, m_display);
|
2020-12-09 21:24:41 +00:00
|
|
|
m_plasmaShell = new PlasmaShellInterface(m_display, m_display);
|
2022-03-23 10:13:38 +00:00
|
|
|
connect(m_plasmaShell, &PlasmaShellInterface::surfaceCreated, this, [this](PlasmaShellSurfaceInterface *surface) {
|
2022-04-23 08:33:23 +00:00
|
|
|
if (XdgSurfaceWindow *window = findXdgSurfaceWindow(surface->surface())) {
|
|
|
|
window->installPlasmaShellSurface(surface);
|
2015-06-09 17:10:56 +00:00
|
|
|
}
|
2022-03-23 10:13:38 +00:00
|
|
|
});
|
2020-12-09 21:24:41 +00:00
|
|
|
m_appMenuManager = new AppMenuManagerInterface(m_display, m_display);
|
2022-03-23 10:13:38 +00:00
|
|
|
connect(m_appMenuManager, &AppMenuManagerInterface::appMenuCreated, this, [this](AppMenuInterface *appMenu) {
|
2022-04-23 08:33:23 +00:00
|
|
|
if (XdgToplevelWindow *window = findXdgToplevelWindow(appMenu->surface())) {
|
|
|
|
window->installAppMenu(appMenu);
|
2017-12-22 14:22:24 +00:00
|
|
|
}
|
2022-03-23 10:13:38 +00:00
|
|
|
});
|
2020-12-09 21:24:41 +00:00
|
|
|
m_paletteManager = new ServerSideDecorationPaletteManagerInterface(m_display, m_display);
|
2022-03-23 10:13:38 +00:00
|
|
|
connect(m_paletteManager, &ServerSideDecorationPaletteManagerInterface::paletteCreated, this, [this](ServerSideDecorationPaletteInterface *palette) {
|
2022-04-23 08:33:23 +00:00
|
|
|
if (XdgToplevelWindow *window = findXdgToplevelWindow(palette->surface())) {
|
|
|
|
window->installPalette(palette);
|
2018-01-04 18:32:18 +00:00
|
|
|
}
|
2022-03-23 10:13:38 +00:00
|
|
|
});
|
2017-12-22 14:22:24 +00:00
|
|
|
|
2020-12-09 21:24:41 +00:00
|
|
|
m_windowManagement = new PlasmaWindowManagementInterface(m_display, m_display);
|
2015-06-12 23:48:11 +00:00
|
|
|
m_windowManagement->setShowingDesktopState(PlasmaWindowManagementInterface::ShowingDesktopState::Disabled);
|
2022-03-23 10:13:38 +00:00
|
|
|
connect(m_windowManagement, &PlasmaWindowManagementInterface::requestChangeShowingDesktop, this, [](PlasmaWindowManagementInterface::ShowingDesktopState state) {
|
|
|
|
if (!workspace()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
bool set = false;
|
|
|
|
switch (state) {
|
|
|
|
case PlasmaWindowManagementInterface::ShowingDesktopState::Disabled:
|
|
|
|
set = false;
|
|
|
|
break;
|
|
|
|
case PlasmaWindowManagementInterface::ShowingDesktopState::Enabled:
|
|
|
|
set = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Q_UNREACHABLE();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (set == workspace()->showingDesktop()) {
|
|
|
|
return;
|
2015-06-12 23:48:11 +00:00
|
|
|
}
|
2022-03-23 10:13:38 +00:00
|
|
|
workspace()->setShowingDesktop(set);
|
|
|
|
});
|
[wayland] Use the new plasma virtual desktop protocol
Summary:
implement virtual desktop support for Wayland.
use the new virtual desktop protocol from D12820
The VirtualDesktopManager class needed some big change in order
to accomodate it, which is where most changes are.
Other than that, it's mostly connections to wire up
VirtualDesktopsManager and VirtualDesktopsManagement(the wayland protocol impl)
Depends on D12820
Other notable detail, is the client visibility updated to reflect the presence
of the client in the plasmavirtualdesktop.
(and the unSetDesktop concept)
Test Plan: used a bit a plasma session together with D12820, D13748 and D13746
Reviewers: #plasma, #kwin, graesslin, davidedmundson
Reviewed By: #plasma, #kwin, davidedmundson
Subscribers: hein, zzag, davidedmundson, kwin
Tags: #kwin
Maniphest Tasks: T4457
Differential Revision: https://phabricator.kde.org/D13887
2018-10-29 22:29:15 +00:00
|
|
|
|
2020-12-09 21:24:41 +00:00
|
|
|
m_virtualDesktopManagement = new PlasmaVirtualDesktopManagementInterface(m_display, m_display);
|
[wayland] Use the new plasma virtual desktop protocol
Summary:
implement virtual desktop support for Wayland.
use the new virtual desktop protocol from D12820
The VirtualDesktopManager class needed some big change in order
to accomodate it, which is where most changes are.
Other than that, it's mostly connections to wire up
VirtualDesktopsManager and VirtualDesktopsManagement(the wayland protocol impl)
Depends on D12820
Other notable detail, is the client visibility updated to reflect the presence
of the client in the plasmavirtualdesktop.
(and the unSetDesktop concept)
Test Plan: used a bit a plasma session together with D12820, D13748 and D13746
Reviewers: #plasma, #kwin, graesslin, davidedmundson
Reviewed By: #plasma, #kwin, davidedmundson
Subscribers: hein, zzag, davidedmundson, kwin
Tags: #kwin
Maniphest Tasks: T4457
Differential Revision: https://phabricator.kde.org/D13887
2018-10-29 22:29:15 +00:00
|
|
|
m_windowManagement->setPlasmaVirtualDesktopManagementInterface(m_virtualDesktopManagement);
|
|
|
|
|
2021-08-22 09:49:57 +00:00
|
|
|
m_plasmaActivationFeedback = new PlasmaWindowActivationFeedbackInterface(m_display, m_display);
|
|
|
|
|
2020-12-09 21:24:41 +00:00
|
|
|
new ShadowManagerInterface(m_display, m_display);
|
|
|
|
new DpmsManagerInterface(m_display, m_display);
|
2015-09-01 09:30:30 +00:00
|
|
|
|
2020-12-09 21:24:41 +00:00
|
|
|
m_decorationManager = new ServerSideDecorationManagerInterface(m_display, m_display);
|
2022-03-23 10:13:38 +00:00
|
|
|
connect(m_decorationManager, &ServerSideDecorationManagerInterface::decorationCreated, this, [this](ServerSideDecorationInterface *decoration) {
|
2022-04-23 08:33:23 +00:00
|
|
|
if (XdgToplevelWindow *window = findXdgToplevelWindow(decoration->surface())) {
|
|
|
|
window->installServerDecoration(decoration);
|
2015-12-17 10:14:54 +00:00
|
|
|
}
|
2022-03-23 10:13:38 +00:00
|
|
|
});
|
2016-03-10 18:57:07 +00:00
|
|
|
|
2021-07-21 10:11:21 +00:00
|
|
|
m_outputManagement = new OutputManagementV2Interface(m_display, m_display);
|
2016-03-21 15:44:07 +00:00
|
|
|
|
2020-12-09 21:24:41 +00:00
|
|
|
m_xdgOutputManagerV1 = new XdgOutputManagerV1Interface(m_display, m_display);
|
|
|
|
new SubCompositorInterface(m_display, m_display);
|
|
|
|
m_XdgForeign = new XdgForeignV2Interface(m_display, m_display);
|
|
|
|
m_inputMethod = new InputMethodV1Interface(m_display, m_display);
|
2022-08-03 07:08:56 +00:00
|
|
|
m_xWaylandKeyboardGrabManager = new XWaylandKeyboardGrabManagerV1Interface(m_display, m_display);
|
2020-07-11 16:40:28 +00:00
|
|
|
|
2023-09-13 17:59:29 +00:00
|
|
|
auto activation = new XdgActivationV1Interface(m_display, this);
|
2020-11-07 02:03:57 +00:00
|
|
|
auto init = [this, activation] {
|
2022-05-16 14:58:53 +00:00
|
|
|
m_xdgActivationIntegration = new XdgActivationV1Integration(activation, this);
|
2020-11-07 02:03:57 +00:00
|
|
|
};
|
|
|
|
if (Workspace::self()) {
|
|
|
|
init();
|
|
|
|
} else {
|
2022-03-23 10:13:38 +00:00
|
|
|
connect(static_cast<Application *>(qApp), &Application::workspaceCreated, this, init);
|
2020-11-07 02:03:57 +00:00
|
|
|
}
|
|
|
|
|
2023-09-13 17:59:29 +00:00
|
|
|
auto aboveLockscreen = new LockscreenOverlayV1Interface(m_display, this);
|
|
|
|
connect(aboveLockscreen, &LockscreenOverlayV1Interface::allowRequested, this, [](SurfaceInterface *surface) {
|
2022-05-12 16:04:12 +00:00
|
|
|
auto w = waylandServer()->findWindow(surface);
|
|
|
|
if (!w) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
w->setLockScreenOverlay(true);
|
|
|
|
});
|
|
|
|
|
2023-09-13 17:59:29 +00:00
|
|
|
m_contentTypeManager = new ContentTypeManagerV1Interface(m_display, m_display);
|
|
|
|
m_tearingControlInterface = new TearingControlManagerV1Interface(m_display, m_display);
|
2023-02-09 08:40:13 +00:00
|
|
|
new XdgToplevelDragManagerV1Interface(m_display, this);
|
2022-05-25 08:39:03 +00:00
|
|
|
|
2023-09-13 17:59:29 +00:00
|
|
|
auto screenEdgeManager = new ScreenEdgeManagerV1Interface(m_display, m_display);
|
|
|
|
connect(screenEdgeManager, &ScreenEdgeManagerV1Interface::edgeRequested, this, [this](AutoHideScreenEdgeV1Interface *edge) {
|
2023-03-08 08:07:39 +00:00
|
|
|
if (auto window = qobject_cast<LayerShellV1Window *>(findWindow(edge->surface()))) {
|
|
|
|
window->installAutoHideScreenEdgeV1(edge);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-10-25 16:36:33 +00:00
|
|
|
new FrogColorManagementV1(m_display, m_display);
|
2023-10-19 14:35:14 +00:00
|
|
|
new PresentationTime(m_display, m_display);
|
2016-07-04 07:09:03 +00:00
|
|
|
return true;
|
2015-06-12 23:48:11 +00:00
|
|
|
}
|
|
|
|
|
2023-09-13 17:59:29 +00:00
|
|
|
DrmClientBufferIntegration *WaylandServer::drm()
|
2023-04-11 15:08:47 +00:00
|
|
|
{
|
|
|
|
if (!m_drm) {
|
|
|
|
m_drm = new DrmClientBufferIntegration(m_display);
|
|
|
|
}
|
|
|
|
return m_drm;
|
|
|
|
}
|
|
|
|
|
2023-09-13 17:59:29 +00:00
|
|
|
LinuxDmaBufV1ClientBufferIntegration *WaylandServer::linuxDmabuf()
|
2019-10-26 03:40:01 +00:00
|
|
|
{
|
|
|
|
if (!m_linuxDmabuf) {
|
2021-07-20 19:37:03 +00:00
|
|
|
m_linuxDmabuf = new LinuxDmaBufV1ClientBufferIntegration(m_display);
|
2019-10-26 03:40:01 +00:00
|
|
|
}
|
|
|
|
return m_linuxDmabuf;
|
|
|
|
}
|
|
|
|
|
2017-10-13 09:32:02 +00:00
|
|
|
SurfaceInterface *WaylandServer::findForeignTransientForSurface(SurfaceInterface *surface)
|
|
|
|
{
|
|
|
|
return m_XdgForeign->transientFor(surface);
|
|
|
|
}
|
|
|
|
|
2023-11-23 22:28:24 +00:00
|
|
|
XdgExportedSurface *WaylandServer::exportAsForeign(SurfaceInterface *surface)
|
|
|
|
{
|
|
|
|
return m_XdgForeign->exportSurface(surface);
|
|
|
|
}
|
|
|
|
|
2015-06-12 23:48:11 +00:00
|
|
|
void WaylandServer::initWorkspace()
|
|
|
|
{
|
2023-11-24 12:34:18 +00:00
|
|
|
auto inputPanelV1Integration = new InputPanelV1Integration(this);
|
|
|
|
connect(inputPanelV1Integration, &InputPanelV1Integration::windowCreated,
|
|
|
|
this, &WaylandServer::registerWindow);
|
|
|
|
|
|
|
|
auto xdgShellIntegration = new XdgShellIntegration(this);
|
|
|
|
connect(xdgShellIntegration, &XdgShellIntegration::windowCreated,
|
|
|
|
this, &WaylandServer::registerXdgGenericWindow);
|
|
|
|
|
2023-11-23 13:48:04 +00:00
|
|
|
auto setPingTimeout = [xdgShellIntegration] {
|
|
|
|
xdgShellIntegration->setPingTimeout(std::chrono::milliseconds(options->killPingTimeout()));
|
|
|
|
};
|
|
|
|
connect(options, &Options::killPingTimeoutChanged, xdgShellIntegration, setPingTimeout);
|
|
|
|
setPingTimeout();
|
|
|
|
|
2023-11-24 12:34:18 +00:00
|
|
|
auto layerShellV1Integration = new LayerShellV1Integration(this);
|
|
|
|
connect(layerShellV1Integration, &LayerShellV1Integration::windowCreated,
|
|
|
|
this, &WaylandServer::registerWindow);
|
|
|
|
|
2022-04-27 08:25:55 +00:00
|
|
|
new KeyStateInterface(m_display, m_display);
|
2021-10-02 08:26:51 +00:00
|
|
|
|
[wayland] Use the new plasma virtual desktop protocol
Summary:
implement virtual desktop support for Wayland.
use the new virtual desktop protocol from D12820
The VirtualDesktopManager class needed some big change in order
to accomodate it, which is where most changes are.
Other than that, it's mostly connections to wire up
VirtualDesktopsManager and VirtualDesktopsManagement(the wayland protocol impl)
Depends on D12820
Other notable detail, is the client visibility updated to reflect the presence
of the client in the plasmavirtualdesktop.
(and the unSetDesktop concept)
Test Plan: used a bit a plasma session together with D12820, D13748 and D13746
Reviewers: #plasma, #kwin, graesslin, davidedmundson
Reviewed By: #plasma, #kwin, davidedmundson
Subscribers: hein, zzag, davidedmundson, kwin
Tags: #kwin
Maniphest Tasks: T4457
Differential Revision: https://phabricator.kde.org/D13887
2018-10-29 22:29:15 +00:00
|
|
|
VirtualDesktopManager::self()->setVirtualDesktopManagement(m_virtualDesktopManagement);
|
|
|
|
|
2015-06-12 23:48:11 +00:00
|
|
|
if (m_windowManagement) {
|
2022-03-23 10:13:38 +00:00
|
|
|
connect(workspace(), &Workspace::showingDesktopChanged, this, [this](bool set) {
|
|
|
|
m_windowManagement->setShowingDesktopState(set ? PlasmaWindowManagementInterface::ShowingDesktopState::Enabled : PlasmaWindowManagementInterface::ShowingDesktopState::Disabled);
|
|
|
|
});
|
2020-04-21 14:52:20 +00:00
|
|
|
|
|
|
|
connect(workspace(), &Workspace::workspaceInitialized, this, [this] {
|
2022-03-23 10:13:38 +00:00
|
|
|
auto f = [this]() {
|
2023-10-19 06:50:15 +00:00
|
|
|
QList<quint32> ids;
|
|
|
|
QList<QString> uuids;
|
2022-04-22 17:39:12 +00:00
|
|
|
for (Window *toplevel : workspace()->stackingOrder()) {
|
2022-04-18 08:27:27 +00:00
|
|
|
if (toplevel->windowManagementInterface()) {
|
|
|
|
ids << toplevel->windowManagementInterface()->internalId();
|
|
|
|
uuids << toplevel->windowManagementInterface()->uuid();
|
2020-04-21 14:52:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
m_windowManagement->setStackingOrder(ids);
|
2021-03-16 11:13:03 +00:00
|
|
|
m_windowManagement->setStackingOrderUuids(uuids);
|
2020-04-21 14:52:20 +00:00
|
|
|
};
|
|
|
|
f();
|
|
|
|
connect(workspace(), &Workspace::stackingOrderChanged, this, f);
|
|
|
|
});
|
2015-06-12 23:48:11 +00:00
|
|
|
}
|
2022-07-30 12:21:00 +00:00
|
|
|
|
2022-11-05 10:43:41 +00:00
|
|
|
const auto availableOutputs = kwinApp()->outputBackend()->outputs();
|
2022-07-30 12:21:00 +00:00
|
|
|
for (Output *output : availableOutputs) {
|
|
|
|
handleOutputAdded(output);
|
|
|
|
}
|
2022-11-05 10:43:41 +00:00
|
|
|
connect(kwinApp()->outputBackend(), &OutputBackend::outputAdded, this, &WaylandServer::handleOutputAdded);
|
|
|
|
connect(kwinApp()->outputBackend(), &OutputBackend::outputRemoved, this, &WaylandServer::handleOutputRemoved);
|
2022-07-30 12:21:00 +00:00
|
|
|
|
|
|
|
const auto outputs = workspace()->outputs();
|
|
|
|
for (Output *output : outputs) {
|
|
|
|
handleOutputEnabled(output);
|
|
|
|
}
|
|
|
|
connect(workspace(), &Workspace::outputAdded, this, &WaylandServer::handleOutputEnabled);
|
|
|
|
connect(workspace(), &Workspace::outputRemoved, this, &WaylandServer::handleOutputDisabled);
|
2015-11-06 11:21:34 +00:00
|
|
|
|
2016-04-25 06:51:33 +00:00
|
|
|
if (hasScreenLockerIntegration()) {
|
2021-10-07 06:03:37 +00:00
|
|
|
initScreenLocker();
|
2017-09-30 14:33:45 +00:00
|
|
|
}
|
2022-10-11 16:42:19 +00:00
|
|
|
|
2022-11-05 10:43:41 +00:00
|
|
|
if (auto backend = qobject_cast<DrmBackend *>(kwinApp()->outputBackend())) {
|
2023-09-13 17:59:29 +00:00
|
|
|
m_leaseManager = new DrmLeaseManagerV1(backend, m_display, m_display);
|
2022-10-11 16:42:19 +00:00
|
|
|
}
|
|
|
|
|
2023-09-13 17:59:29 +00:00
|
|
|
m_outputOrder = new OutputOrderV1Interface(m_display, m_display);
|
2022-12-15 10:08:36 +00:00
|
|
|
m_outputOrder->setOutputOrder(workspace()->outputOrder());
|
|
|
|
connect(workspace(), &Workspace::outputOrderChanged, m_outputOrder, [this]() {
|
|
|
|
m_outputOrder->setOutputOrder(workspace()->outputOrder());
|
|
|
|
});
|
|
|
|
|
2021-10-10 15:22:40 +00:00
|
|
|
Q_EMIT initialized();
|
2017-09-30 14:33:45 +00:00
|
|
|
}
|
2015-11-06 14:08:13 +00:00
|
|
|
|
2017-09-30 14:33:45 +00:00
|
|
|
void WaylandServer::initScreenLocker()
|
|
|
|
{
|
2022-02-28 18:58:35 +00:00
|
|
|
#if KWIN_BUILD_SCREENLOCKER
|
2020-03-15 21:40:56 +00:00
|
|
|
auto *screenLockerApp = ScreenLocker::KSldApp::self();
|
|
|
|
|
2017-09-30 14:33:45 +00:00
|
|
|
ScreenLocker::KSldApp::self()->setGreeterEnvironment(kwinApp()->processStartupEnvironment());
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
connect(ScreenLocker::KSldApp::self(), &ScreenLocker::KSldApp::aboutToLock, this, [this, screenLockerApp]() {
|
|
|
|
if (m_screenLockerClientConnection) {
|
|
|
|
// Already sent data to KScreenLocker.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int clientFd = createScreenLockerConnection();
|
|
|
|
if (clientFd < 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ScreenLocker::KSldApp::self()->setWaylandFd(clientFd);
|
2020-03-15 21:40:56 +00:00
|
|
|
|
2022-03-28 16:08:59 +00:00
|
|
|
new LockScreenPresentationWatcher(this);
|
|
|
|
|
2023-10-19 06:50:15 +00:00
|
|
|
const QList<SeatInterface *> seatIfaces = m_display->seats();
|
2022-03-23 10:13:38 +00:00
|
|
|
for (auto *seat : seatIfaces) {
|
2023-09-13 17:59:29 +00:00
|
|
|
connect(seat, &SeatInterface::timestampChanged,
|
2022-03-23 10:13:38 +00:00
|
|
|
screenLockerApp, &ScreenLocker::KSldApp::userActivity);
|
2017-09-30 14:33:45 +00:00
|
|
|
}
|
2022-03-23 10:13:38 +00:00
|
|
|
});
|
2020-03-15 21:40:56 +00:00
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
connect(ScreenLocker::KSldApp::self(), &ScreenLocker::KSldApp::unlocked, this, [this, screenLockerApp]() {
|
|
|
|
if (m_screenLockerClientConnection) {
|
|
|
|
m_screenLockerClientConnection->destroy();
|
|
|
|
delete m_screenLockerClientConnection;
|
|
|
|
m_screenLockerClientConnection = nullptr;
|
|
|
|
}
|
|
|
|
|
2023-10-19 06:50:15 +00:00
|
|
|
const QList<SeatInterface *> seatIfaces = m_display->seats();
|
2022-03-23 10:13:38 +00:00
|
|
|
for (auto *seat : seatIfaces) {
|
2023-09-13 17:59:29 +00:00
|
|
|
disconnect(seat, &SeatInterface::timestampChanged,
|
2022-03-23 10:13:38 +00:00
|
|
|
screenLockerApp, &ScreenLocker::KSldApp::userActivity);
|
2016-04-25 06:51:33 +00:00
|
|
|
}
|
2022-03-23 10:13:38 +00:00
|
|
|
ScreenLocker::KSldApp::self()->setWaylandFd(-1);
|
|
|
|
});
|
2017-09-30 14:33:45 +00:00
|
|
|
|
2022-09-23 12:48:49 +00:00
|
|
|
connect(screenLockerApp, &ScreenLocker::KSldApp::lockStateChanged, this, &WaylandServer::lockStateChanged);
|
|
|
|
|
2022-02-11 16:21:42 +00:00
|
|
|
ScreenLocker::KSldApp::self()->initialize();
|
|
|
|
|
2020-03-17 05:48:05 +00:00
|
|
|
if (m_initFlags.testFlag(InitializationFlag::LockScreen)) {
|
2017-09-30 14:33:45 +00:00
|
|
|
ScreenLocker::KSldApp::self()->lock(ScreenLocker::EstablishLock::Immediate);
|
2015-11-05 13:09:23 +00:00
|
|
|
}
|
2022-02-23 13:27:05 +00:00
|
|
|
#endif
|
2015-02-20 13:54:21 +00:00
|
|
|
}
|
2015-02-09 12:28:37 +00:00
|
|
|
|
2016-12-03 13:54:32 +00:00
|
|
|
WaylandServer::SocketPairConnection WaylandServer::createConnection()
|
2015-02-25 13:15:32 +00:00
|
|
|
{
|
2016-12-03 13:54:32 +00:00
|
|
|
SocketPairConnection ret;
|
2015-02-25 13:15:32 +00:00
|
|
|
int sx[2];
|
|
|
|
if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, sx) < 0) {
|
|
|
|
qCWarning(KWIN_CORE) << "Could not create socket";
|
2016-12-03 13:54:32 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
ret.connection = m_display->createClient(sx[0]);
|
|
|
|
ret.fd = sx[1];
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-03-15 21:40:56 +00:00
|
|
|
int WaylandServer::createScreenLockerConnection()
|
|
|
|
{
|
|
|
|
const auto socket = createConnection();
|
|
|
|
if (!socket.connection) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
m_screenLockerClientConnection = socket.connection;
|
2023-09-13 17:59:29 +00:00
|
|
|
connect(m_screenLockerClientConnection, &ClientConnection::disconnected, this, [this]() {
|
2022-03-23 10:13:38 +00:00
|
|
|
m_screenLockerClientConnection = nullptr;
|
|
|
|
});
|
2020-03-15 21:40:56 +00:00
|
|
|
return socket.fd;
|
|
|
|
}
|
|
|
|
|
2016-12-03 13:54:32 +00:00
|
|
|
int WaylandServer::createXWaylandConnection()
|
|
|
|
{
|
|
|
|
const auto socket = createConnection();
|
|
|
|
if (!socket.connection) {
|
2015-02-25 13:15:32 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2020-07-20 08:07:08 +00:00
|
|
|
m_xwaylandConnection = socket.connection;
|
2022-02-02 03:35:13 +00:00
|
|
|
|
|
|
|
m_xwaylandConnection->setScaleOverride(kwinApp()->xwaylandScale());
|
|
|
|
connect(kwinApp(), &Application::xwaylandScaleChanged, m_xwaylandConnection, [this]() {
|
2023-10-09 08:13:24 +00:00
|
|
|
m_xwaylandConnection->setScaleOverride(kwinApp()->xwaylandScale());
|
2022-02-02 03:35:13 +00:00
|
|
|
});
|
|
|
|
|
2016-12-03 13:54:32 +00:00
|
|
|
return socket.fd;
|
2015-02-25 13:15:32 +00:00
|
|
|
}
|
|
|
|
|
2015-11-10 13:21:48 +00:00
|
|
|
void WaylandServer::destroyXWaylandConnection()
|
|
|
|
{
|
2020-07-20 08:07:08 +00:00
|
|
|
if (!m_xwaylandConnection) {
|
2015-11-10 13:21:48 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-07-20 08:07:08 +00:00
|
|
|
m_xwaylandConnection->destroy();
|
|
|
|
m_xwaylandConnection = nullptr;
|
2015-11-10 13:21:48 +00:00
|
|
|
}
|
|
|
|
|
2015-06-13 02:06:12 +00:00
|
|
|
int WaylandServer::createInputMethodConnection()
|
|
|
|
{
|
2016-12-03 13:54:32 +00:00
|
|
|
const auto socket = createConnection();
|
|
|
|
if (!socket.connection) {
|
2015-06-13 02:06:12 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2016-12-03 13:54:32 +00:00
|
|
|
m_inputMethodServerConnection = socket.connection;
|
|
|
|
return socket.fd;
|
2015-06-13 02:06:12 +00:00
|
|
|
}
|
|
|
|
|
2015-11-10 13:38:45 +00:00
|
|
|
void WaylandServer::destroyInputMethodConnection()
|
|
|
|
{
|
|
|
|
if (!m_inputMethodServerConnection) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_inputMethodServerConnection->destroy();
|
|
|
|
m_inputMethodServerConnection = nullptr;
|
|
|
|
}
|
|
|
|
|
2022-04-23 08:33:23 +00:00
|
|
|
void WaylandServer::removeWindow(Window *c)
|
2015-03-04 08:21:10 +00:00
|
|
|
{
|
2022-04-23 08:33:23 +00:00
|
|
|
m_windows.removeAll(c);
|
2022-09-16 15:20:08 +00:00
|
|
|
if (c->readyForPainting()) {
|
|
|
|
Q_EMIT windowRemoved(c);
|
|
|
|
}
|
2015-03-04 08:21:10 +00:00
|
|
|
}
|
|
|
|
|
2023-09-13 17:59:29 +00:00
|
|
|
static Window *findWindowInList(const QList<Window *> &windows, const SurfaceInterface *surface)
|
2015-06-09 17:10:56 +00:00
|
|
|
{
|
2022-04-23 08:33:23 +00:00
|
|
|
auto it = std::find_if(windows.begin(), windows.end(), [surface](Window *w) {
|
|
|
|
return w->surface() == surface;
|
|
|
|
});
|
|
|
|
if (it == windows.end()) {
|
2015-06-09 17:10:56 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return *it;
|
|
|
|
}
|
|
|
|
|
2023-09-13 17:59:29 +00:00
|
|
|
Window *WaylandServer::findWindow(const SurfaceInterface *surface) const
|
2015-06-09 17:10:56 +00:00
|
|
|
{
|
|
|
|
if (!surface) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2022-04-23 08:33:23 +00:00
|
|
|
if (Window *c = findWindowInList(m_windows, surface)) {
|
2015-06-09 17:10:56 +00:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2022-04-22 18:11:29 +00:00
|
|
|
XdgToplevelWindow *WaylandServer::findXdgToplevelWindow(SurfaceInterface *surface) const
|
2016-08-22 14:55:48 +00:00
|
|
|
{
|
2022-04-23 08:33:23 +00:00
|
|
|
return qobject_cast<XdgToplevelWindow *>(findWindow(surface));
|
2016-08-22 14:55:48 +00:00
|
|
|
}
|
|
|
|
|
2022-04-22 18:11:29 +00:00
|
|
|
XdgSurfaceWindow *WaylandServer::findXdgSurfaceWindow(SurfaceInterface *surface) const
|
2020-08-04 01:15:59 +00:00
|
|
|
{
|
2022-04-23 08:33:23 +00:00
|
|
|
return qobject_cast<XdgSurfaceWindow *>(findWindow(surface));
|
2020-08-04 01:15:59 +00:00
|
|
|
}
|
|
|
|
|
2015-11-16 10:19:38 +00:00
|
|
|
bool WaylandServer::isScreenLocked() const
|
|
|
|
{
|
2022-02-28 18:58:35 +00:00
|
|
|
#if KWIN_BUILD_SCREENLOCKER
|
2016-04-25 06:51:33 +00:00
|
|
|
if (!hasScreenLockerIntegration()) {
|
|
|
|
return false;
|
|
|
|
}
|
2022-03-23 10:13:38 +00:00
|
|
|
return ScreenLocker::KSldApp::self()->lockState() == ScreenLocker::KSldApp::Locked || ScreenLocker::KSldApp::self()->lockState() == ScreenLocker::KSldApp::AcquiringLock;
|
2022-02-23 13:27:05 +00:00
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
2015-11-16 10:19:38 +00:00
|
|
|
}
|
|
|
|
|
2016-04-25 06:51:33 +00:00
|
|
|
bool WaylandServer::hasScreenLockerIntegration() const
|
|
|
|
{
|
2022-02-28 18:58:35 +00:00
|
|
|
#if KWIN_BUILD_SCREENLOCKER
|
2020-03-17 05:48:05 +00:00
|
|
|
return !m_initFlags.testFlag(InitializationFlag::NoLockScreenIntegration);
|
2022-02-23 13:27:05 +00:00
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
2016-04-25 06:51:33 +00:00
|
|
|
}
|
|
|
|
|
2018-12-02 12:09:37 +00:00
|
|
|
bool WaylandServer::hasGlobalShortcutSupport() const
|
|
|
|
{
|
2020-03-17 05:48:05 +00:00
|
|
|
return !m_initFlags.testFlag(InitializationFlag::NoGlobalShortcuts);
|
2018-12-02 12:09:37 +00:00
|
|
|
}
|
|
|
|
|
2020-04-29 08:45:02 +00:00
|
|
|
bool WaylandServer::isKeyboardShortcutsInhibited() const
|
|
|
|
{
|
|
|
|
auto surface = seat()->focusedKeyboardSurface();
|
|
|
|
if (surface) {
|
|
|
|
auto inhibitor = keyboardShortcutsInhibitManager()->findInhibitor(surface, seat());
|
2022-08-03 07:08:56 +00:00
|
|
|
if (inhibitor && inhibitor->isActive()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (m_xWaylandKeyboardGrabManager->hasGrab(surface, seat())) {
|
|
|
|
return true;
|
|
|
|
}
|
2020-04-29 08:45:02 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-11-17 13:26:01 +00:00
|
|
|
QString WaylandServer::socketName() const
|
|
|
|
{
|
|
|
|
const QStringList socketNames = display()->socketNames();
|
|
|
|
if (!socketNames.isEmpty()) {
|
|
|
|
return socketNames.first();
|
|
|
|
}
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2022-03-28 16:08:59 +00:00
|
|
|
#if KWIN_BUILD_SCREENLOCKER
|
|
|
|
WaylandServer::LockScreenPresentationWatcher::LockScreenPresentationWatcher(WaylandServer *server)
|
|
|
|
{
|
2022-04-23 08:33:23 +00:00
|
|
|
connect(server, &WaylandServer::windowAdded, this, [this](Window *window) {
|
|
|
|
if (window->isLockScreen()) {
|
2022-04-26 12:16:42 +00:00
|
|
|
// only signal lockScreenShown once all outputs have been presented at least once
|
|
|
|
connect(window->output()->renderLoop(), &RenderLoop::framePresented, this, [this, windowGuard = QPointer(window)]() {
|
|
|
|
// window might be destroyed before a frame is presented, so it's wrapped in QPointer
|
|
|
|
if (windowGuard) {
|
|
|
|
m_signaledOutputs << windowGuard->output();
|
2022-07-11 10:41:15 +00:00
|
|
|
if (m_signaledOutputs.size() == workspace()->outputs().size()) {
|
2022-04-26 12:16:42 +00:00
|
|
|
ScreenLocker::KSldApp::self()->lockScreenShown();
|
|
|
|
delete this;
|
|
|
|
}
|
2022-03-28 16:08:59 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
QTimer::singleShot(1000, this, [this]() {
|
|
|
|
ScreenLocker::KSldApp::self()->lockScreenShown();
|
|
|
|
delete this;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
#endif
|
2015-02-09 12:28:37 +00:00
|
|
|
}
|
2023-07-05 06:30:14 +00:00
|
|
|
|
|
|
|
#include "moc_wayland_server.cpp"
|