2020-05-07 14:29:41 +00:00
|
|
|
/*
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2020 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
|
|
|
|
|
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2020-05-07 14:29:41 +00:00
|
|
|
|
2020-09-03 19:26:04 +00:00
|
|
|
#include "xdgshellintegration.h"
|
2020-05-07 14:29:41 +00:00
|
|
|
#include "wayland_server.h"
|
|
|
|
#include "workspace.h"
|
|
|
|
#include "xdgshellclient.h"
|
|
|
|
|
|
|
|
#include <KWaylandServer/display.h>
|
|
|
|
#include <KWaylandServer/xdgshell_interface.h>
|
|
|
|
|
|
|
|
using namespace KWaylandServer;
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The WaylandXdgShellIntegration class is a factory class for xdg-shell clients.
|
|
|
|
*
|
|
|
|
* The xdg-shell protocol defines two surface roles - xdg_toplevel and xdg_popup. On the
|
|
|
|
* compositor side, those roles are represented by XdgToplevelClient and XdgPopupClient,
|
|
|
|
* respectively.
|
|
|
|
*
|
|
|
|
* WaylandXdgShellIntegration monitors for new xdg_toplevel and xdg_popup objects. If it
|
|
|
|
* detects one, it will create an XdgToplevelClient or XdgPopupClient based on the current
|
|
|
|
* surface role of the underlying xdg_surface object.
|
|
|
|
*/
|
|
|
|
|
2020-09-03 19:26:04 +00:00
|
|
|
XdgShellIntegration::XdgShellIntegration(QObject *parent)
|
2020-05-07 14:29:41 +00:00
|
|
|
: WaylandShellIntegration(parent)
|
|
|
|
{
|
2020-12-09 21:24:41 +00:00
|
|
|
XdgShellInterface *shell = new XdgShellInterface(waylandServer()->display(), this);
|
2020-05-07 14:29:41 +00:00
|
|
|
|
|
|
|
connect(shell, &XdgShellInterface::toplevelCreated,
|
2020-09-03 19:26:04 +00:00
|
|
|
this, &XdgShellIntegration::registerXdgToplevel);
|
2020-05-07 14:29:41 +00:00
|
|
|
connect(shell, &XdgShellInterface::popupCreated,
|
2020-09-03 19:26:04 +00:00
|
|
|
this, &XdgShellIntegration::registerXdgPopup);
|
2020-05-07 14:29:41 +00:00
|
|
|
}
|
|
|
|
|
2020-09-03 19:26:04 +00:00
|
|
|
void XdgShellIntegration::registerXdgToplevel(XdgToplevelInterface *toplevel)
|
2020-05-07 14:29:41 +00:00
|
|
|
{
|
|
|
|
// Note that the client is going to be destroyed and immediately re-created when the
|
|
|
|
// underlying surface is unmapped. XdgToplevelClient is re-created right away since
|
|
|
|
// we don't want too loose any client requests that are allowed to be sent prior to
|
|
|
|
// the first initial commit, e.g. set_maximized or set_fullscreen.
|
|
|
|
connect(toplevel, &XdgToplevelInterface::resetOccurred,
|
2022-03-23 10:13:38 +00:00
|
|
|
this, [this, toplevel] {
|
|
|
|
createXdgToplevelClient(toplevel);
|
|
|
|
});
|
2020-05-07 14:29:41 +00:00
|
|
|
|
|
|
|
createXdgToplevelClient(toplevel);
|
|
|
|
}
|
|
|
|
|
2020-09-03 19:26:04 +00:00
|
|
|
void XdgShellIntegration::createXdgToplevelClient(XdgToplevelInterface *toplevel)
|
2020-05-07 14:29:41 +00:00
|
|
|
{
|
|
|
|
if (!workspace()) {
|
2020-07-07 09:45:55 +00:00
|
|
|
qCWarning(KWIN_CORE, "An xdg-toplevel surface has been created while the compositor "
|
2022-03-23 10:13:38 +00:00
|
|
|
"is still not fully initialized. That is a compositor bug!");
|
2020-07-07 09:45:55 +00:00
|
|
|
return;
|
2020-05-07 14:29:41 +00:00
|
|
|
}
|
|
|
|
|
2021-06-08 07:02:14 +00:00
|
|
|
Q_EMIT clientCreated(new XdgToplevelClient(toplevel));
|
2020-05-07 14:29:41 +00:00
|
|
|
}
|
|
|
|
|
2020-09-03 19:26:04 +00:00
|
|
|
void XdgShellIntegration::registerXdgPopup(XdgPopupInterface *popup)
|
2020-05-07 14:29:41 +00:00
|
|
|
{
|
|
|
|
if (!workspace()) {
|
2020-07-07 09:45:55 +00:00
|
|
|
qCWarning(KWIN_CORE, "An xdg-popup surface has been created while the compositor is "
|
2022-03-23 10:13:38 +00:00
|
|
|
"still not fully initialized. That is a compositor bug!");
|
2020-07-07 09:45:55 +00:00
|
|
|
return;
|
2020-05-07 14:29:41 +00:00
|
|
|
}
|
|
|
|
|
2021-06-08 07:02:14 +00:00
|
|
|
Q_EMIT clientCreated(new XdgPopupClient(popup));
|
2020-05-07 14:29:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace KWin
|