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->m_window->setProperty(
"_q_showWithoutActivating", !d->m_takesFocus);
150 d->platformSurfaceCreated(window);
153bool PlasmaShellWaylandIntegration::eventFilter(
QObject *watched,
QEvent *event)
162 d->platformSurfaceCreated(window);
168void PlasmaShellWaylandIntegration::setPosition(
const QPoint &position)
170 if (position == d->m_position) {
174 d->m_position = position;
175 if (d->m_shellSurface) {
176 d->m_shellSurface->set_position(d->m_position->x(), d->m_position->y());
180void PlasmaShellWaylandIntegration::setPanelBehavior(QtWayland::org_kde_plasma_surface::panel_behavior panelBehavior)
182 if (panelBehavior == d->m_panelBehavior) {
185 d->m_panelBehavior = panelBehavior;
186 if (d->m_shellSurface) {
187 d->m_shellSurface->set_panel_behavior(panelBehavior);
191void PlasmaShellWaylandIntegration::setRole(QtWayland::org_kde_plasma_surface::role role)
193 if (role == d->m_role) {
197 if (d->m_shellSurface) {
198 d->m_shellSurface->set_role(role);
202void PlasmaShellWaylandIntegration::setTakesFocus(
bool takesFocus)
204 if (takesFocus == d->m_takesFocus) {
207 d->m_takesFocus = takesFocus;
208 d->m_window->setProperty(
"_q_showWithoutActivating", !d->m_takesFocus);
209 if (d->m_shellSurface) {
210 d->m_shellSurface->set_panel_takes_focus(takesFocus);
214#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.
void initialize(StandardShortcut id)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
virtual bool event(QEvent *e)
T qobject_cast(QObject *object)