Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Manage focus between multiple displays on Linux Wayland
Forum Updated to NodeBB v4.3 + New Features

Manage focus between multiple displays on Linux Wayland

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 2 Posters 324 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    leo099
    wrote on last edited by
    #1

    Hi,
    I am trying to understand the right way to manage focus when creating QQuickView across multiple monitors.
    I have created a minimal app to reproduce what I am trying to do.
    main.cpp:

    #include <QGuiApplication>
    #include <QQuickView>
    #include <QScreen>
    #include <QQmlContext>
    
    int main(int argc, char *argv[]) {
        QGuiApplication app(argc, argv);
    
        const QList<QScreen *> screens = QGuiApplication::screens();
    
        // Create a QQuickView for each screen
        QList<QQuickView *> views;
        QQuickView *primaryScreenView;
        for (QScreen *screen : screens) {
            QQuickView *view = new QQuickView;
            views.append(view);
    
            view->setScreen(screen);
            view->setResizeMode(QQuickView::SizeRootObjectToView);
            view->setGeometry(screen->geometry());
            view->setFlags(Qt::FramelessWindowHint);
    
            bool isPrimaryScreen = QGuiApplication::primaryScreen() == screen;
            view->rootContext()->setContextProperty(QStringLiteral("primaryScreen"), QVariant::fromValue(isPrimaryScreen));
            if (isPrimaryScreen) {
                primaryScreenView = view;
            }
    
            view->setSource(QUrl("qrc:/Main.qml"));
    
            qInfo() << "Adding view for" << screen->name() << screen->geometry() << " primary: " << isPrimaryScreen;
            view->showFullScreen();
        }
    
        primaryScreenView->requestActivate();
    
        return app.exec();
    }
    
    

    Main.qml:

    import QtQuick 2.15
    
    Rectangle {
        id: root
        width: 1920
        height: 1080
        color: "lightblue"
    
        Component.onCompleted: {
            console.log("Screen ", root.Screen.name, " primary: ", primaryScreen);
        }
    
        Column {
            anchors.centerIn: parent
    
            Text {
                anchors.horizontalCenter: parent.horizontalCenter
                text: "Hello, World!"
                font.pixelSize: 48
            }
    
            TextInput {
                id: input
                visible: primaryScreen
                focus: primaryScreen
                anchors.horizontalCenter: parent.horizontalCenter
                text: "Type here"
                font.pixelSize: 24
            }
        }
    }
    

    On my Linux machine when running the graphical session on X11 this works as expected having the TextInput on the primary screen focused. But on Wayland the TextInput is not focused, instead the QQuickView on the last monitor to be added is active, and I need to click on the input to focus it.

    I found multiple sources claiming that requestActivate() does nothing on Wayland, as the rules governing which window is active are stricter compared to X11, is this true? If so, how can I achieve to have focus on my primary display instead of the last added one?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Just a quick that came to mind: what about adding the primary screen widget as last ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      L 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi and welcome to devnet,

        Just a quick that came to mind: what about adding the primary screen widget as last ?

        L Offline
        L Offline
        leo099
        wrote on last edited by
        #3

        @SGaist Yes, I have tried this:
        main.cpp:

            // ...
            // Create a QQuickView for each screen
            QList<QQuickView *> views;
            QQuickView *primaryScreenView;
            for (QScreen *screen : screens) {
                // ...
                if (isPrimaryScreen) {
                    primaryScreenView = view;
                } else {
                    view->showFullScreen();
               }
            }
        
            primaryScreenView->showFullScreen();
            // ...
        

        and it works.

        It feels like a workaround and I do not know if it would be accepted to fix this issue in the SDDM greeter, but I can try opening a pull request since it is an easy enough fix.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          That's something worth discussing.
          I currently don't know the details of the Wayland protocols and how to leverage them from Qt for your situation.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved