How to use setScope in layer-shell-qt ? Is it really static?

Hello everyone :slight_smile:

I want to set a window’s scope use the LayerShellQt::window::setScope function in package layer-shell-qt. And here is the source code of setScope:

// layer-shell-qt code
void Window::setScope(const QString &scope)
{
    d->scope = scope;
    // this is static and must be set before the platform window is created
}

As the comment, setScope is static. But I don’t think that it’s a static function.

And here is my code:

// my demo code
if (auto layerShellWindow = LayerShellQt::Window::get(window->windowHandle())) {
    qDebug() << "MMMMMM scope is " << layerShellWindow->scope();
    layerShellWindow->setScope("screenlock");
    qDebug() << "MMMMMM scope now is " << layerShellWindow->scope();
}

I can set the scope to “screenlock” successfully. But in KWin, It seems the scope is from another library(maybe wayland or kwayland-server, I’m not sure, only working on this for a few days) , and it seems that it has nothing to do with layer-shell-qt. So in this code of KWin, the scope is always “window”, which is the default scope in layer-shell-qt of class WindowPrivate.

// KWin code
LayerShellV1Client::LayerShellV1Client(LayerSurfaceV1Interface *shellSurface,
                                       AbstractOutput *output,
                                       LayerShellV1Integration *integration)
    : WaylandClient(shellSurface->surface())
    , m_desiredOutput(output)
    , m_integration(integration)
    , m_shellSurface(shellSurface)
    , m_windowType(scopeToType(shellSurface->scope()))
{

In summary, how to use the setScope function in layer-shell-qt, is there a demo? Or is it wrong?

Thank you all! My respect :slight_smile:

Been working on for a while, I’ve found that the interface setScope(my modified function, not the origin one) and setLayer works when the window is QQuickWindow type, and don’t work when the window is widget type.

Don’t know why, but I would check it out if I got time.

here is the working code:

#include <QApplication>
#include <QQuickView>

#include <KWindowSystem>

#include <LayerShellQt/Shell>


int main(int argc, char *argv[])
{
    LayerShellQt::Shell::useLayerShell();

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
    QApplication app(argc, argv);

    QQuickView window;

    window.setFlags(Qt::FramelessWindowHint);


    if (auto layerShellWindow = LayerShellQt::Window::get(&window)) {
        layerShellWindow->setExclusiveZone(-1);
        layerShellWindow->setLayer(LayerShellQt::Window::LayerOverlay);
        layerShellWindow->setScope("ScreenLock");
    }

    window.setSource(QUrl("qrc:/main.qml"));
    window.show();

    return app.exec();
}

NOTICE! You should call setLayer before window.show()!

Does anybody know why it’s working for QQuickWindow type but not QWidget type?

Thanks in advance:)