mirror of
https://invent.kde.org/plasma/layer-shell-qt.git
synced 2026-02-20 04:23:03 -05:00
Window: Ensure we integrate windows that were already were shown in a different shell
This commit is contained in:
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include <layershellqt_logging.h>
|
#include <layershellqt_logging.h>
|
||||||
|
|
||||||
|
#include <QPlatformSurfaceEvent>
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
@ -187,6 +188,13 @@ Window::Window(QWindow *window)
|
|||||||
{
|
{
|
||||||
s_map.insert(d->parentWindow, this);
|
s_map.insert(d->parentWindow, this);
|
||||||
window->installEventFilter(this);
|
window->installEventFilter(this);
|
||||||
|
if (window->isVisible()) {
|
||||||
|
qCWarning(LAYERSHELLQT) << d->parentWindow << "already has a shell integration. Call QWindow::close() first and show it again.";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (window->handle()) {
|
||||||
|
initializeShell();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Window::eventFilter(QObject *watched, QEvent *event)
|
bool Window::eventFilter(QObject *watched, QEvent *event)
|
||||||
@ -196,28 +204,34 @@ bool Window::eventFilter(QObject *watched, QEvent *event)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (event->type() == QEvent::PlatformSurface) {
|
if (event->type() == QEvent::PlatformSurface) {
|
||||||
auto waylandWindow = dynamic_cast<QtWaylandClient::QWaylandWindow *>(window->handle());
|
if (auto pse = static_cast<QPlatformSurfaceEvent *>(event); pse->surfaceEventType() == QPlatformSurfaceEvent::SurfaceCreated) {
|
||||||
if (!waylandWindow) {
|
initializeShell();
|
||||||
qCWarning(LAYERSHELLQT) << window << "is not a wayland window. Not creating zwlr_layer_surface";
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static QWaylandLayerShellIntegration *shellIntegration = nullptr;
|
|
||||||
if (!shellIntegration) {
|
|
||||||
shellIntegration = new QWaylandLayerShellIntegration();
|
|
||||||
if (!shellIntegration->initialize(waylandWindow->display())) {
|
|
||||||
delete shellIntegration;
|
|
||||||
shellIntegration = nullptr;
|
|
||||||
qCWarning(LAYERSHELLQT)
|
|
||||||
<< "Failed to initialize layer-shell integration, possibly because compositor does not support the layer-shell protocol";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
waylandWindow->setShellIntegration(shellIntegration);
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Window::initializeShell()
|
||||||
|
{
|
||||||
|
auto waylandWindow = dynamic_cast<QtWaylandClient::QWaylandWindow *>(d->parentWindow->handle());
|
||||||
|
if (!waylandWindow) {
|
||||||
|
qCWarning(LAYERSHELLQT) << d->parentWindow << "is not a wayland window. Not creating zwlr_layer_surface";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
static QWaylandLayerShellIntegration *shellIntegration = nullptr;
|
||||||
|
if (!shellIntegration) {
|
||||||
|
shellIntegration = new QWaylandLayerShellIntegration();
|
||||||
|
if (!shellIntegration->initialize(waylandWindow->display())) {
|
||||||
|
delete shellIntegration;
|
||||||
|
shellIntegration = nullptr;
|
||||||
|
qCWarning(LAYERSHELLQT) << "Failed to initialize layer-shell integration, possibly because compositor does not support the layer-shell protocol";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
waylandWindow->setShellIntegration(shellIntegration);
|
||||||
|
}
|
||||||
|
|
||||||
Window *Window::get(QWindow *window)
|
Window *Window::get(QWindow *window)
|
||||||
{
|
{
|
||||||
if (!window) {
|
if (!window) {
|
||||||
|
|||||||
@ -150,6 +150,8 @@ Q_SIGNALS:
|
|||||||
void layerChanged();
|
void layerChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void initializeShell();
|
||||||
|
|
||||||
Window(QWindow *window);
|
Window(QWindow *window);
|
||||||
QScopedPointer<WindowPrivate> d;
|
QScopedPointer<WindowPrivate> d;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user