Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt 5.x on Linux - detect X11 vs Wayland
QtWS25 Last Chance

Qt 5.x on Linux - detect X11 vs Wayland

Scheduled Pinned Locked Moved General and Desktop
12 Posts 3 Posters 6.0k Views
  • 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.
  • I Offline
    I Offline
    ileonte
    wrote on last edited by
    #1

    I haven't looked seriously into Qt development since the days of 4.8 but I've recently started doing it again and I have a question I can't seem to find the answer to: with Q_WS_ constants being dropped in favor of Q_OS_ in Qt 5.x how do I detect if my application is being built on an X11 Linux installation versus a Wayland one (or DirectFB or any other graphics backend) ?

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

      Hi and welcome to devnet,

      AFAIK, there's no drop in replacements. Out of curiosity, what would it change for your application ?

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

      I 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi and welcome to devnet,

        AFAIK, there's no drop in replacements. Out of curiosity, what would it change for your application ?

        I Offline
        I Offline
        ileonte
        wrote on last edited by
        #3

        @SGaist for this application in particular I'd like to have it respond to a global key binding. Not sure if this is even possible on Wayland without the help of the compositor but on X11 at least I can get away with a fairly window-manager-agnostic solution by using XGrabKey() and a native event filter on the QApplication object.

        ? 1 Reply Last reply
        0
        • I ileonte

          @SGaist for this application in particular I'd like to have it respond to a global key binding. Not sure if this is even possible on Wayland without the help of the compositor but on X11 at least I can get away with a fairly window-manager-agnostic solution by using XGrabKey() and a native event filter on the QApplication object.

          ? Offline
          ? Offline
          A Former User
          wrote on last edited by A Former User
          #4

          @ileonte Hi, I'm not sure if I understood your intention correctly. Maybe you can check for the presence of the DISPLAY (X11) and WAYLAND_DISPLAY environment variables at runtime?

          I 1 Reply Last reply
          0
          • ? A Former User

            @ileonte Hi, I'm not sure if I understood your intention correctly. Maybe you can check for the presence of the DISPLAY (X11) and WAYLAND_DISPLAY environment variables at runtime?

            I Offline
            I Offline
            ileonte
            wrote on last edited by ileonte
            #5

            @Wieland I'm talking about compile-time detection - stuff like "do I include xcb headers or wayland headers ?" or "do I tell qmake to include my X11-specific GlobalShortcut implementation into the SOURCES variable or should it include the Wayland one ?". This was possible in Qt 4.x by checking QT_WS_* defines in C++ code and by using x11:SOURCES += ... in the project file but these don't work anymore.

            ? 1 Reply Last reply
            0
            • I ileonte

              @Wieland I'm talking about compile-time detection - stuff like "do I include xcb headers or wayland headers ?" or "do I tell qmake to include my X11-specific GlobalShortcut implementation into the SOURCES variable or should it include the Wayland one ?". This was possible in Qt 4.x by checking QT_WS_* defines in C++ code and by using x11:SOURCES += ... in the project file but these don't work anymore.

              ? Offline
              ? Offline
              A Former User
              wrote on last edited by A Former User
              #6

              @ileonte Ok, understood. AFAIK there is nothing like QT_WS_* there at the moment. I think (but maybe I'm wrong) that #ifdef WAYLAND_VERSION could do the job.

              I 1 Reply Last reply
              0
              • ? A Former User

                @ileonte Ok, understood. AFAIK there is nothing like QT_WS_* there at the moment. I think (but maybe I'm wrong) that #ifdef WAYLAND_VERSION could do the job.

                I Offline
                I Offline
                ileonte
                wrote on last edited by
                #7

                @Wieland as far as I understand platform-specific code is kept in plugins in Qt 5.x which means that define you speak of would only be present if I include Wayland headers myself, which is what the initial problem is all about.

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

                  Isn't wayland a "drop-in" replacement for X11 ?

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

                  I 1 Reply Last reply
                  0
                  • SGaistS SGaist

                    Isn't wayland a "drop-in" replacement for X11 ?

                    I Offline
                    I Offline
                    ileonte
                    wrote on last edited by
                    #9

                    Nope, not even close to :) Especially if you have to interact with it directly instead of through some high-level layer like Qt.

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

                      Yup, my bad, I've misunderstood the goal of the project. But in that case, shouldn't you be able to use XGrabKey with both wayland and X11 ?

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

                      I 1 Reply Last reply
                      0
                      • SGaistS SGaist

                        Yup, my bad, I've misunderstood the goal of the project. But in that case, shouldn't you be able to use XGrabKey with both wayland and X11 ?

                        I Offline
                        I Offline
                        ileonte
                        wrote on last edited by ileonte
                        #11

                        @SGaist XGrabKey() is an Xlib function and needs to communicate with an X11 server. On Wayland there is no such thing (people will point to Xwayland but that is not really a solution - Qt itself is a native Wayland client so forcing the extra dependency on Xlib for people running pure-Wayland doesn't make sense).

                        In any case, this is really not the point of this topic. The point is that I find it strange for Qt to remove this extra bit of platform detection capability. It wasn't that long ago that MacOS was in a similar situation where there were multiple Qt versions (Cocoa vs Carbon) but at that time you still had Q_WS_* to fall back to. On current Linux you have at least 3 competing windowing solutions (X11 vs Wayland vs Mir). Relying on OS detection alone doesn't cut it in cases where you need/want to do something that Qt hasn't covered.

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

                          Cocoa VS Carbon was another situation, you would either build for one or the other, you wouldn't have both at the same time.

                          In your current situation, how do you plan to distribute the wayland version of your application ?

                          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