7#include "plasmashellwaylandintegration.h"
9#include <QGuiApplication>
10#include <QPlatformSurfaceEvent>
11#include <QWaylandClientExtensionTemplate>
14#include <qpa/qplatformwindow_p.h>
16#include <KWindowSystem>
18class PlasmaShellManager :
public QWaylandClientExtensionTemplate<PlasmaShellManager>,
public QtWayland::org_kde_plasma_shell
22 : QWaylandClientExtensionTemplate<PlasmaShellManager>(8)
28class PlasmaShellSurface :
public QtWayland::org_kde_plasma_surface
31 PlasmaShellSurface(struct ::org_kde_plasma_surface *impl)
32 : QtWayland::org_kde_plasma_surface(impl)
41class WaylandIntegrationSingleton
44 WaylandIntegrationSingleton();
45 std::unique_ptr<PlasmaShellManager> shellManager;
49WaylandIntegrationSingleton::WaylandIntegrationSingleton()
52 shellManager = std::make_unique<PlasmaShellManager>();
56Q_GLOBAL_STATIC(WaylandIntegrationSingleton, s_waylandIntegration)
58class PlasmaShellWaylandIntegrationPrivate
63 void platformSurfaceCreated(
QWindow *window);
64 void surfaceCreated();
65 void surfaceDestroyed();
69 std::optional<QPoint> m_position;
70 QtWayland::org_kde_plasma_surface::panel_behavior m_panelBehavior = QtWayland::org_kde_plasma_surface::panel_behavior_always_visible;
71 QtWayland::org_kde_plasma_surface::role m_role = QtWayland::org_kde_plasma_surface::role_normal;
72 bool m_takesFocus =
false;
73 std::unique_ptr<PlasmaShellSurface> m_shellSurface;
82void PlasmaShellWaylandIntegrationPrivate::platformSurfaceCreated(
QWindow *window)
84 auto waylandWindow =
window->nativeInterface<QNativeInterface::Private::QWaylandWindow>();
88 QObject::connect(waylandWindow, SIGNAL(surfaceCreated()), q, SLOT(surfaceCreated()));
89 QObject::connect(waylandWindow, SIGNAL(surfaceDestroyed()), q, SLOT(surfaceDestroyed()));
90 if (waylandWindow->surface()) {
95void PlasmaShellWaylandIntegrationPrivate::surfaceCreated()
97 struct wl_surface *surface =
nullptr;
98 if (!s_waylandIntegration->shellManager || !s_waylandIntegration->shellManager->isActive()) {
102 if (
auto waylandWindow = m_window->nativeInterface<QNativeInterface::Private::QWaylandWindow>()) {
103 surface = waylandWindow->surface();
110 m_shellSurface = std::make_unique<PlasmaShellSurface>(s_waylandIntegration->shellManager->get_surface(surface));
111 if (m_shellSurface) {
113 m_shellSurface->set_position(m_position->x(), m_position->y());
115 m_shellSurface->set_panel_takes_focus(m_takesFocus);
116 m_shellSurface->set_role(m_role);
117 m_shellSurface->set_skip_switcher(
true);
118 m_shellSurface->set_skip_taskbar(
true);
122void PlasmaShellWaylandIntegrationPrivate::surfaceDestroyed()
124 m_shellSurface.reset();
136PlasmaShellWaylandIntegration::~PlasmaShellWaylandIntegration()
138 s_waylandIntegration->windows.remove(d->m_window);
141PlasmaShellWaylandIntegration::PlasmaShellWaylandIntegration(
QWindow *window)
143 , d(new PlasmaShellWaylandIntegrationPrivate(this,
window))
148 d->m_window->installEventFilter(
this);
149 d->platformSurfaceCreated(window);
152bool PlasmaShellWaylandIntegration::eventFilter(
QObject *watched,
QEvent *event)
161 d->platformSurfaceCreated(window);
167void PlasmaShellWaylandIntegration::setPosition(
const QPoint &position)
169 if (position == d->m_position) {
173 d->m_position = position;
174 if (d->m_shellSurface) {
175 d->m_shellSurface->set_position(d->m_position->x(), d->m_position->y());
179void PlasmaShellWaylandIntegration::setPanelBehavior(QtWayland::org_kde_plasma_surface::panel_behavior panelBehavior)
181 if (panelBehavior == d->m_panelBehavior) {
184 d->m_panelBehavior = panelBehavior;
185 if (d->m_shellSurface) {
186 d->m_shellSurface->set_panel_behavior(panelBehavior);
190void PlasmaShellWaylandIntegration::setRole(QtWayland::org_kde_plasma_surface::role role)
192 if (role == d->m_role) {
196 if (d->m_shellSurface) {
197 d->m_shellSurface->set_role(role);
201void PlasmaShellWaylandIntegration::setTakesFocus(
bool takesFocus)
203 if (takesFocus == d->m_takesFocus) {
206 d->m_takesFocus = takesFocus;
207 if (d->m_shellSurface) {
208 d->m_shellSurface->set_panel_takes_focus(takesFocus);
212#include "moc_plasmashellwaylandintegration.cpp"
static bool isPlatformWayland()
The PlasmaWaylandShellIntegration class exposes Plasma specific specific wayland extensions for.
static PlasmaShellWaylandIntegration * get(QWindow *window)
Returns the relevant PlasmaWaylandShellIntegration instance for this window creating one if needed.
KCRASH_EXPORT void initialize()
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
virtual bool event(QEvent *e)
T qobject_cast(QObject *object)