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"
|
2022-04-22 09:27:33 +00:00
|
|
|
#include "wayland/display.h"
|
|
|
|
#include "wayland/xdgshell_interface.h"
|
2020-05-07 14:29:41 +00:00
|
|
|
#include "wayland_server.h"
|
|
|
|
#include "workspace.h"
|
2022-04-22 18:11:29 +00:00
|
|
|
#include "xdgshellwindow.h"
|
2020-05-07 14:29:41 +00:00
|
|
|
|
|
|
|
using namespace KWaylandServer;
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
2022-04-23 08:33:23 +00:00
|
|
|
* The WaylandXdgShellIntegration class is a factory class for xdg-shell windows.
|
2020-05-07 14:29:41 +00:00
|
|
|
*
|
|
|
|
* The xdg-shell protocol defines two surface roles - xdg_toplevel and xdg_popup. On the
|
2022-04-22 18:11:29 +00:00
|
|
|
* compositor side, those roles are represented by XdgToplevelWindow and XdgPopupWindow,
|
2020-05-07 14:29:41 +00:00
|
|
|
* respectively.
|
|
|
|
*
|
|
|
|
* WaylandXdgShellIntegration monitors for new xdg_toplevel and xdg_popup objects. If it
|
2022-04-22 18:11:29 +00:00
|
|
|
* detects one, it will create an XdgToplevelWindow or XdgPopupWindow based on the current
|
2020-05-07 14:29:41 +00:00
|
|
|
* 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
|
|
|
{
|
2022-04-23 08:33:23 +00:00
|
|
|
// Note that the window is going to be destroyed and immediately re-created when the
|
2022-04-22 18:11:29 +00:00
|
|
|
// underlying surface is unmapped. XdgToplevelWindow is re-created right away since
|
2022-04-23 08:33:23 +00:00
|
|
|
// we don't want too loose any window requests that are allowed to be sent prior to
|
2020-05-07 14:29:41 +00:00
|
|
|
// 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] {
|
2022-04-22 18:11:29 +00:00
|
|
|
createXdgToplevelWindow(toplevel);
|
2022-03-23 10:13:38 +00:00
|
|
|
});
|
2020-05-07 14:29:41 +00:00
|
|
|
|
2022-04-22 18:11:29 +00:00
|
|
|
createXdgToplevelWindow(toplevel);
|
2020-05-07 14:29:41 +00:00
|
|
|
}
|
|
|
|
|
2022-04-22 18:11:29 +00:00
|
|
|
void XdgShellIntegration::createXdgToplevelWindow(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
|
|
|
}
|
|
|
|
|
2022-04-23 08:33:23 +00:00
|
|
|
Q_EMIT windowCreated(new XdgToplevelWindow(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
|
|
|
}
|
|
|
|
|
2022-04-23 08:33:23 +00:00
|
|
|
Q_EMIT windowCreated(new XdgPopupWindow(popup));
|
2020-05-07 14:29:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace KWin
|