mirror of
https://invent.kde.org/plasma/layer-shell-qt.git
synced 2025-07-14 11:04:20 -04:00
Ensure we can set per-window properties before the intial commit
In the current implementation we cannot use a LayerShellQt before the shell surface is created. At the moment a shell surface is created, the constructor is run and then QtWayland commits the current state. This means the compositor configures the window before a client has any chance to set anchors or margins. This works whilst we're just being a simple fullscreen window, but won't scale for plasmashell in the future. This patch makes LayerShellQt::Window always creatable, and we can set and cache properties before the platform window is created, just like one can on QWindow and XDGShell properties. This also makes it less potentially crashy as ::get always returns a valid result, and sets up the public API to be QML-able as an attached property in future. Co-authored on Aleix's patch for the unit test
This commit is contained in:
@ -15,58 +15,133 @@ using namespace LayerShellQt;
|
||||
class LayerShellQt::WindowPrivate
|
||||
{
|
||||
public:
|
||||
WindowPrivate(QWaylandLayerSurface *surface)
|
||||
: surface(surface)
|
||||
WindowPrivate(QWindow *window)
|
||||
: parentWindow(window)
|
||||
{
|
||||
}
|
||||
|
||||
QWaylandLayerSurface *const surface;
|
||||
QWindow *parentWindow;
|
||||
QString scope = QStringLiteral("qt");
|
||||
Window::Anchors anchor = {Window::AnchorTop | Window::AnchorBottom | Window::AnchorLeft | Window::AnchorRight};
|
||||
int32_t exclusionZone = 0;
|
||||
bool keyboardInteractivity = false;
|
||||
Window::Layer layer = Window::LayerTop;
|
||||
QMargins margins;
|
||||
QWaylandLayerSurface* getSurface() const;
|
||||
};
|
||||
|
||||
Window::~Window() = default;
|
||||
static QMap<QWindow*, Window*> s_map;
|
||||
|
||||
void Window::setAnchor(Anchor anchor)
|
||||
Window::~Window()
|
||||
{
|
||||
d->surface->setAnchor(anchor);
|
||||
s_map.remove(d->parentWindow);
|
||||
}
|
||||
|
||||
void Window::setAnchor(Anchors anchor)
|
||||
{
|
||||
d->anchor = anchor;
|
||||
if (auto surface = d->getSurface()) {
|
||||
surface->setAnchor(anchor);
|
||||
}
|
||||
}
|
||||
|
||||
Window::Anchors Window::anchor() const
|
||||
{
|
||||
return d->anchor;
|
||||
}
|
||||
|
||||
void Window::setExclusiveZone(int32_t zone)
|
||||
{
|
||||
d->surface->setExclusiveZone(zone);
|
||||
d->exclusionZone = zone;
|
||||
if (auto surface= d->getSurface()) {
|
||||
surface->setExclusiveZone(zone);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t Window::exclusionZone() const
|
||||
{
|
||||
return d->exclusionZone;
|
||||
}
|
||||
|
||||
void Window::setMargins(const QMargins &margins)
|
||||
{
|
||||
d->surface->setMargins(margins);
|
||||
d->margins = margins;
|
||||
if (auto surface= d->getSurface()) {
|
||||
surface->setMargins(margins);
|
||||
}
|
||||
}
|
||||
|
||||
QMargins Window::margins() const
|
||||
{
|
||||
return d->margins;
|
||||
}
|
||||
|
||||
void Window::setKeyboardInteractivity(bool enabled)
|
||||
{
|
||||
d->surface->setKeyboardInteractivity(enabled);
|
||||
d->keyboardInteractivity = enabled;
|
||||
if (auto surface= d->getSurface()) {
|
||||
surface->setKeyboardInteractivity(enabled);
|
||||
}
|
||||
}
|
||||
|
||||
bool Window::keyboardInteractivity() const
|
||||
{
|
||||
return d->keyboardInteractivity;
|
||||
}
|
||||
|
||||
void Window::setLayer(Layer layer)
|
||||
{
|
||||
d->surface->setLayer(layer);
|
||||
d->layer = layer;
|
||||
if (auto surface= d->getSurface()) {
|
||||
surface->setLayer(layer);
|
||||
}
|
||||
}
|
||||
|
||||
void Window::setScope(const QString &scope)
|
||||
{
|
||||
d->scope = scope;
|
||||
//this is static and must be set before the platform window is created
|
||||
}
|
||||
|
||||
QString Window::scope() const
|
||||
{
|
||||
return d->scope;
|
||||
}
|
||||
|
||||
Window::Layer Window::layer() const
|
||||
{
|
||||
return d->layer;
|
||||
}
|
||||
|
||||
Window::Window(WindowPrivate *d)
|
||||
: d(d)
|
||||
: QObject(d->parentWindow)
|
||||
, d(d)
|
||||
{
|
||||
s_map.insert(d->parentWindow, this);
|
||||
}
|
||||
|
||||
Window *Window::get(QWindow *window)
|
||||
QWaylandLayerSurface *WindowPrivate::getSurface() const
|
||||
{
|
||||
auto ww = dynamic_cast<QtWaylandClient::QWaylandWindow *>(window->handle());
|
||||
if (!parentWindow) {
|
||||
return nullptr;
|
||||
}
|
||||
auto ww = dynamic_cast<QtWaylandClient::QWaylandWindow *>(parentWindow->handle());
|
||||
if (!ww) {
|
||||
qCDebug(LAYERSHELLQT) << "window not a wayland window" << window;
|
||||
qCDebug(LAYERSHELLQT) << "window not a wayland window" << parentWindow;
|
||||
return nullptr;
|
||||
}
|
||||
QWaylandLayerSurface *s = qobject_cast<QWaylandLayerSurface *>(ww->shellSurface());
|
||||
if (!s) {
|
||||
qCDebug(LAYERSHELLQT) << "window not using wlr-layer-shell" << window << ww->shellSurface();
|
||||
qCDebug(LAYERSHELLQT) << "window not using wlr-layer-shell" << parentWindow << ww->shellSurface();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return new Window(new WindowPrivate(s));
|
||||
return s;
|
||||
}
|
||||
|
||||
Window *Window::get(QWindow *window)
|
||||
{
|
||||
if (s_map.contains(window)) {
|
||||
return s_map[window];
|
||||
}
|
||||
return new Window(new WindowPrivate(window));
|
||||
}
|
||||
|
Reference in New Issue
Block a user