User:CodingKoopa/Qt

From ArchWiki

Configuration

Qt Platform Abstraction

Starting with Qt 5, Qt implements environment specific details such as window system integration, look and feel, and native menus/dialogs using the Qt Platform Abstraction (QPA) layer.

The QPA API is implemented by platform plugins (also "QPA plugins"). The platform plugins available for Linux include:

  • xcb, implementing support for Xorg via the XCB library.
  • wayland, implementing support for Wayland. The Wayland platform plugin is not to confused with the Qt Wayland Compositor module used for developing a compositor using Qt, both of which live under the qtwayland repository.
    • The wayland-egl platform plugin provides the default mechanism for sharing graphics buffers with a Qt-based compositor. This is likely not what you are looking for.
  • Platform plugins intended for embedded platforms, such as eglfs and linuxfb.
  • vnc, which hosts a VNC server.

The QT_QPA_PLATFORM environment variable can be used to specify which plugin is used. It may be a semi-colon separated list of platform plugins to try until one is loaded successfully [1] [2]. Qt programs also recognize the -platform argument, with a higher priority [3]. For example, to try Wayland and exit if that fails:

$ QT_QPA_PLATFORM=wayland qt-program

Qt defaults to X [4] [5], meaning that QT_QPA_PLATFORM or -platform must be set in order to make Qt use Wayland. Display managers with Wayland support, such as SDDM [6], may set this variable automatically. You can use env in a process spawned within the desktop environment to verify this.

The remainder of this section only considers implementation details that pertain to the Xorg and Wayland platform plugins, that may not be applicable to others.

Platform Integration

TODO: check that this stuff applies to Qt 5

The highest level QPA API is QPlatformIntegration, which is implemented by QXcbIntegration and QWaylandIntegration. In addition to providing access to the rest of the QPA functionality, the platform integration is responsible for:

  • Parsing platform specific command line arguments.
  • Initializing the client of the display server.
    • For xcb, QXcbConnection connects to the X server associated with an X11 display.
      • If the -display display_number command line argument is passed, this display number is used. [7] Otherwise, the DISPLAY environment variable is used. [8]
      • The X server will be grabbed unless one of the following conditions exists, starting from highest precedence:
        • The QT_XCB_NO_GRAB_SERVER environment variable is set.
        • The -nograb command line argument is passed.
        • The program is detected to be running under a debugger. This is the only condition that can be overridden with the -dograb command line argument.
      • If the -xcb-xlib option [9] is enabled when building Qt, then Xlib rather than XCB is used to open and close the display. For most of the other interactions with the X server, XCB is still used, via XGetXCBConnection(3). This option is enabled by default, so this is the case on Arch.
      • The XSync, XFixes, XRender, XShape, and XKB Xorg server extensions are initialized unconditionally.
      • The MIT-SHM, RandR, and XInput2 Xorg server extensions are initialized unless, respectively, the QT_XCB_NO_MITSHM [10], QT_XCB_NO_XRANDR, or QT_XCB_NO_XI2 [11] environment variables are set.
    • For wayland, QWaylandDisplay connects to the Wayland compositor and creates a Wayland display.
  • Low level, API-specific window initialization.
    • xcb TODO PICKUP FROM HERE
and wayland both try OpenGL, then Vulkan.
    • QPlatformServices
  • QPlatformServices (Internal)
  • QPlatformTheme

TODO: pick up from https://github.com/qt/qtbase/tree/v6.3.1/src/plugins/platforms class list TODO: mention https://github.com/qt/qtbase/blob/87c2a401dabacddb94b61595e2873627c222c60a/src/gui/kernel/qplatformintegration.h#L4 (perhaps prefer this over QPlatformServices)

Platform Services

The QPlatformServices QPA API handles desktop environment detection. For all of the Linux platform plugins, this is implemented by the QGenericUnixServices class (implementation file). [12] [13]

Desktop Environment Detection

The detection goes as follows:

  • If the standardized XDG_CURRENT_DESKTOP environment variable is set, it's used.
  • If the classic environment-specific variables KDE_FULL_SESSION or GNOME_DESKTOP_SESSION_ID, are set, then the corresponding value is used.
  • If the legacy DESKTOP_SESSION is set to a path, Qt will try reading it as a session desktop entry, and use the value of the DesktopNames key as-is.
    • If not set to a path (or if parsing failed), and the variable (or basename of the failed path) is set to one of gnome, xfce, or kde, the corresponding value is be used.

Opening Files

Opening URIs

Platform Themes

Platform theme plugins TODO: https://github.com/qt/qtbase/tree/fb981a0954119ed0dfa4a402fdef78e7257ffc96/src/plugins/platformthemes