Browse Source

Use QX11Application with Qt >= 6.2, use QX11Info with Qt 5

pull/756/head
Jonas Kvinge 2 months ago
parent
commit
ecf2c50a26
  1. 11
      .github/workflows/ccpp.yml
  2. 38
      CMakeLists.txt
  3. 1
      debian/control
  4. 4
      dist/unix/strawberry.spec.in
  5. 1
      src/config.h.in
  6. 54
      src/globalshortcuts/globalshortcut-x11.cpp
  7. 9
      src/osd/osdpretty.cpp

11
.github/workflows/ccpp.yml

@ -52,6 +52,7 @@ jobs:
libqt5-qtbase-common-devel
libQt5Sql5-sqlite
libqt5-linguist-devel
libqt5-qtx11extras-devel
libcdio-devel
libgpod-devel
libmtp-devel
@ -124,6 +125,7 @@ jobs:
libqt5-qtbase-common-devel
libQt5Sql5-sqlite
libqt5-linguist-devel
libqt5-qtx11extras-devel
libcdio-devel
libgpod-devel
libmtp-devel
@ -289,6 +291,7 @@ jobs:
libqt5-qtbase-common-devel
libQt5Sql5-sqlite
libqt5-linguist-devel
libqt5-qtx11extras-devel
libcdio-devel
libgpod-devel
libmtp-devel
@ -456,6 +459,7 @@ jobs:
libqt5-qtbase-common-devel
libQt5Sql5-sqlite
libqt5-linguist-devel
libqt5-qtx11extras-devel
libcdio-devel
libgpod-devel
libmtp-devel
@ -611,6 +615,7 @@ jobs:
qt5-qtbase-devel
qt5-qtbase-private-devel
qt5-qttools-devel
qt5-qtx11extras-devel
gstreamer1-devel
gstreamer1-plugins-base-devel
taglib-devel
@ -756,6 +761,7 @@ jobs:
qtbase5-dev-tools
qtbase5-private-dev
qttools5-dev
libqt5x11extras5-dev
libgstreamer1.0-dev
libgstreamer-plugins-base1.0-dev
gstreamer1.0-alsa
@ -813,6 +819,7 @@ jobs:
qtbase5-dev-tools
qtbase5-private-dev
qttools5-dev
libqt5x11extras5-dev
libgstreamer1.0-dev
libgstreamer-plugins-base1.0-dev
gstreamer1.0-alsa
@ -874,6 +881,7 @@ jobs:
qtbase5-dev-tools
qtbase5-private-dev
qttools5-dev
libqt5x11extras5-dev
libgstreamer1.0-dev
libgstreamer-plugins-base1.0-dev
libgstreamer-plugins-good1.0-dev
@ -936,6 +944,7 @@ jobs:
qtbase5-dev-tools
qtbase5-private-dev
qttools5-dev
libqt5x11extras5-dev
libgstreamer1.0-dev
libgstreamer-plugins-base1.0-dev
libgstreamer-plugins-good1.0-dev
@ -998,6 +1007,7 @@ jobs:
qtbase5-dev-tools
qtbase5-private-dev
qttools5-dev
libqt5x11extras5-dev
libgstreamer1.0-dev
libgstreamer-plugins-base1.0-dev
libgstreamer-plugins-good1.0-dev
@ -1060,6 +1070,7 @@ jobs:
qtbase5-dev-tools
qtbase5-private-dev
qttools5-dev
libqt5x11extras5-dev
libgstreamer1.0-dev
libgstreamer-plugins-base1.0-dev
libgstreamer-plugins-good1.0-dev

38
CMakeLists.txt

@ -177,6 +177,10 @@ if(QT_VERSION_MAJOR)
set(QT_DEFAULT_MAJOR_VERSION ${QT_VERSION_MAJOR})
endif()
if(X11_FOUND AND BUILD_WITH_QT5)
list(APPEND QT_OPTIONAL_COMPONENTS X11Extras)
endif()
find_package(Qt${QT_VERSION_MAJOR} ${QT_MIN_VERSION} REQUIRED COMPONENTS ${QT_COMPONENTS} OPTIONAL_COMPONENTS ${QT_OPTIONAL_COMPONENTS})
set(QtCore_LIBRARIES Qt${QT_VERSION_MAJOR}::Core)
@ -191,6 +195,11 @@ if(Qt${QT_VERSION_MAJOR}DBus_FOUND)
list(APPEND QT_LIBRARIES Qt${QT_VERSION_MAJOR}::DBus)
get_target_property(QT_DBUSXML2CPP_EXECUTABLE Qt${QT_VERSION_MAJOR}::qdbusxml2cpp LOCATION)
endif()
if(BUILD_WITH_QT5 AND Qt5X11Extras_FOUND)
set(HAVE_X11EXTRAS ON)
set(QtX11Extras_LIBRARIES Qt5::X11Extras)
list(APPEND QT_LIBRARIES Qt5::X11Extras)
endif()
if(Qt${QT_VERSION_MAJOR}Test_FOUND)
set(QtTest_LIBRARIES Qt${QT_VERSION_MAJOR}::Test)
endif()
@ -232,12 +241,14 @@ if(X11_FOUND)
message(WARNING, "Missing X11/XF86keysym.h")
endif()
find_path(QPA_QPLATFORMNATIVEINTERFACE_H qpa/qplatformnativeinterface.h PATHS ${Qt${QT_VERSION_MAJOR}Gui_PRIVATE_INCLUDE_DIRS})
if(QPA_QPLATFORMNATIVEINTERFACE_H)
set(HAVE_QPA_QPLATFORMNATIVEINTERFACE_H ON)
message(STATUS "Have qpa/qplatformnativeinterface.h header.")
else()
message(STATUS "Missing qpa/qplatformnativeinterface.h header.")
if(BUILD_WITH_QT5 OR (BUILD_WITH_QT6 AND Qt6Core_VERSION VERSION_LESS 6.2.0))
find_path(QPA_QPLATFORMNATIVEINTERFACE_H qpa/qplatformnativeinterface.h PATHS ${Qt${QT_VERSION_MAJOR}Gui_PRIVATE_INCLUDE_DIRS})
if(QPA_QPLATFORMNATIVEINTERFACE_H)
set(HAVE_QPA_QPLATFORMNATIVEINTERFACE_H ON)
message(STATUS "Have qpa/qplatformnativeinterface.h header.")
else()
message(STATUS "Missing qpa/qplatformnativeinterface.h header.")
endif()
endif()
endif(X11_FOUND)
@ -351,10 +362,17 @@ optional_component(GLOBALSHORTCUTS ON "Global shortcuts"
DEPENDS "D-Bus, X11, Windows or macOS" HAVE_GLOBALSHORTCUTS_SUPPORT
)
optional_component(X11_GLOBALSHORTCUTS ON "X11 global shortcuts"
DEPENDS "X11" X11_FOUND
DEPENDS "qpa/qplatformnativeinterface.h" HAVE_QPA_QPLATFORMNATIVEINTERFACE_H
)
if(BUILD_WITH_QT6 AND (Qt6Core_VERSION VERSION_EQUAL 6.2.0 OR Qt6Core_VERSION VERSION_GREATER 6.2.0))
optional_component(X11_GLOBALSHORTCUTS ON "X11 global shortcuts" DEPENDS "X11" X11_FOUND)
else()
if(HAVE_X11EXTRAS OR HAVE_QPA_QPLATFORMNATIVEINTERFACE_H)
set(HAVE_X11EXTRAS_OR_QPA_QPLATFORMNATIVEINTERFACE_H ON)
endif()
optional_component(X11_GLOBALSHORTCUTS ON "X11 global shortcuts"
DEPENDS "X11" X11_FOUND
DEPENDS "Qt >= 6.2, X11Extras or qpa/qplatformnativeinterface.h header" HAVE_X11EXTRAS_OR_QPA_QPLATFORMNATIVEINTERFACE_H
)
endif()
optional_component(AUDIOCD ON "Devices: Audio CD support"
DEPENDS "libcdio" LIBCDIO_FOUND

1
debian/control

@ -20,6 +20,7 @@ Build-Depends: debhelper (>= 11),
qtbase5-private-dev,
qtbase5-dev-tools,
qttools5-dev,
libqt5x11extras5-dev,
libgstreamer1.0-dev,
libgstreamer-plugins-base1.0-dev,
libcdio-dev,

4
dist/unix/strawberry.spec.in

@ -58,6 +58,7 @@ BuildRequires: pkgconfig(Qt@QT_VERSION_MAJOR@Network)
BuildRequires: pkgconfig(Qt@QT_VERSION_MAJOR@Sql)
BuildRequires: pkgconfig(Qt@QT_VERSION_MAJOR@DBus)
BuildRequires: pkgconfig(Qt@QT_VERSION_MAJOR@Test)
BuildRequires: pkgconfig(Qt@QT_VERSION_MAJOR@X11Extras)
%else
BuildRequires: cmake(Qt@QT_VERSION_MAJOR@Core)
BuildRequires: cmake(Qt@QT_VERSION_MAJOR@Gui)
@ -67,6 +68,9 @@ BuildRequires: cmake(Qt@QT_VERSION_MAJOR@Network)
BuildRequires: cmake(Qt@QT_VERSION_MAJOR@Sql)
BuildRequires: cmake(Qt@QT_VERSION_MAJOR@DBus)
BuildRequires: cmake(Qt@QT_VERSION_MAJOR@Test)
%if "@QT_VERSION_MAJOR@" == "5"
BuildRequires: cmake(Qt@QT_VERSION_MAJOR@X11Extras)
%endif
%endif
%if 0%{?suse_version} || 0%{?fedora_version} || 0%{?mageia}
BuildRequires: cmake(Qt@QT_VERSION_MAJOR@LinguistTools)

1
src/config.h.in

@ -46,6 +46,7 @@
#define TRANSLATIONS_DIR "${CMAKE_INSTALL_PREFIX}/share/strawberry/translations"
#cmakedefine HAVE_QPA_QPLATFORMNATIVEINTERFACE_H
#cmakedefine HAVE_X11EXTRAS
#cmakedefine ENABLE_WIN32_CONSOLE

54
src/globalshortcuts/globalshortcut-x11.cpp

@ -37,7 +37,15 @@
#include <xcb/xcb.h>
#include <xcb/xproto.h>
#include <qpa/qplatformnativeinterface.h>
#if QT_VERSION >= QT_VERSION_CHECK(6, 2, 0)
# include <QGuiApplication>
#elif defined(HAVE_X11EXTRAS)
# include <QX11Info>
#elif defined(HAVE_QPA_QPLATFORMNATIVEINTERFACE_H)
# include <qpa/qplatformnativeinterface.h>
#else
# error "Missing Qt >= 6.2, X11Extras or qpa/qplatformnativeinterface.h header."
#endif
const QVector<quint32> GlobalShortcut::mask_modifiers_ = QVector<quint32>() << 0 << Mod2Mask << LockMask << (Mod2Mask | LockMask);
@ -45,6 +53,23 @@ namespace {
Display *X11Display() {
#if QT_VERSION >= QT_VERSION_CHECK(6, 2, 0) // 6.2: Use the new native interface.
if (!qApp) return nullptr;
if (QNativeInterface::QX11Application *x11_app = qApp->nativeInterface<QNativeInterface::QX11Application>()) {
return x11_app->display();
}
else {
return nullptr;
}
#elif defined(HAVE_X11EXTRAS) // Qt 5: Use X11Extras
return QX11Info::display();
#elif defined(HAVE_QPA_QPLATFORMNATIVEINTERFACE_H) // Use private headers.
if (!qApp) return nullptr;
QPlatformNativeInterface *native = qApp->platformNativeInterface();
@ -53,10 +78,31 @@ Display *X11Display() {
void *display = native->nativeResourceForIntegration("display");
return reinterpret_cast<Display*>(display);
#else
# error "Missing Qt >= 6.2, X11Extras or qpa/qplatformnativeinterface.h header."
#endif
}
quint32 AppRootWindow() {
#if QT_VERSION >= QT_VERSION_CHECK(6, 2, 0) // 6.2: Use the new native interface.
if (QNativeInterface::QX11Application *x11_app = qApp->nativeInterface<QNativeInterface::QX11Application>()) {
return static_cast<xcb_window_t>(reinterpret_cast<quintptr>(x11_app->connection()));
}
else {
return 0;
}
#elif defined(HAVE_X11EXTRAS) // Qt 5: Use X11Extras
return QX11Info::appRootWindow();
#elif defined(HAVE_QPA_QPLATFORMNATIVEINTERFACE_H) // Use private headers.
if (!qApp) return 0;
QPlatformNativeInterface *native = qApp->platformNativeInterface();
@ -67,6 +113,12 @@ quint32 AppRootWindow() {
return static_cast<xcb_window_t>(reinterpret_cast<quintptr>(native->nativeResourceForScreen("rootwindow", screen)));
#else
# error "Missing Qt >= 6.2, X11Extras or qpa/qplatformnativeinterface.h header."
#endif
}
} // namespace

9
src/osd/osdpretty.cpp

@ -55,7 +55,10 @@
#include <QSettings>
#include <QFlags>
#include <QtEvents>
#if defined(HAVE_X11) && defined(HAVE_QPA_QPLATFORMNATIVEINTERFACE_H)
#ifdef HAVE_X11EXTRAS
# include <QX11Info>
#elif defined(HAVE_X11) && defined(HAVE_QPA_QPLATFORMNATIVEINTERFACE_H)
# include <qpa/qplatformnativeinterface.h>
#endif
@ -213,7 +216,9 @@ void OSDPretty::ScreenRemoved(QScreen *screen) {
bool OSDPretty::IsTransparencyAvailable() {
#if defined(HAVE_X11) && defined(HAVE_QPA_QPLATFORMNATIVEINTERFACE_H)
#ifdef HAVE_X11EXTRAS
return QX11Info::isCompositingManagerRunning();
#elif defined(HAVE_X11) && defined(HAVE_QPA_QPLATFORMNATIVEINTERFACE_H)
if (qApp) {
QPlatformNativeInterface *native = qApp->platformNativeInterface();
QScreen *screen = popup_screen_ == nullptr ? QGuiApplication::primaryScreen() : popup_screen_;

Loading…
Cancel
Save