From d7e2ca377f9fab169431e41e820973fad49224b5 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Thu, 29 Aug 2024 11:15:26 +0200 Subject: [PATCH] Get rid of QPA_XCB define Since the platform is selected at run time (e.g. xcb vs. Wayland), it is not a good idea to decide at compile time what code is run. Another example is on macOS, where having xcb libraries available will lead to lauching the Xquartz whenever LyX is running. With this patch, things are separated: - the code is run when run-time platform is "xcb". - the support code is compiled in when xcb header and libraries are available. The cmake code is courtesy of Kornel Benko. Fixes ticket #13086. (cherry picked from commit 18c310a8cf60ebc8cab27aeea6fc0a6e1fcc7fcc) (cherry picked from commit f1fddd86efa22ac9342de723f5ca724f252f8cbe) (cherry picked from commit 3bc4554e5762c3484477e1c590632756e3f310ad) (cherry picked from commit 8c14748e782d93870a7328df383403fb37da936f) --- CMakeLists.txt | 8 ++++++- config/qt.m4 | 22 +++---------------- development/cmake/ConfigureChecks.cmake | 7 +------ development/cmake/config.h.cmake | 8 +++---- src/CMakeLists.txt | 1 - src/frontends/qt/GuiApplication.cpp | 28 ++++++++++++++----------- src/frontends/qt/GuiApplication.h | 6 +++--- status.24x | 3 +++ 8 files changed, 37 insertions(+), 46 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 58c6b1eb52..a1f3f8efc0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -805,7 +805,6 @@ if(LYX_USE_QT MATCHES "QT6|QT5") Qt5_wrap_ui(${ARGN}) endmacro() endif() - # set QPA_XCB if QT uses X11 find_package(${QtVal}Core CONFIG REQUIRED) if (${QtVal}Core_FOUND) find_package(${QtVal}Widgets CONFIG REQUIRED) @@ -1188,6 +1187,13 @@ get_data_destination(dest_data) list(APPEND tmp_vi " LyX files dir: ${CMAKE_INSTALL_PREFIX}/${dest_data}") string(REPLACE ";" "\\n" VERSION_INFO "${tmp_vi}") +# the result XCB_LIBRARY will be used in src/CMakeLists.txt and also in configuring config.h +find_library(XCB_LIBRARY NAMES xcb) +if (XCB_LIBRARY) + set(HAVE_LIBXCB 1 CACHE BOOL "" FORCE) +else() + set(HAVE_LIBXCB 0 CACHE BOOL "" FORCE) +endif() configure_file(${LYX_CMAKE_DIR}/config.h.cmake ${TOP_BINARY_DIR}/config.h) unset(opts) unset(tmp_vi) diff --git a/config/qt.m4 b/config/qt.m4 index 96810bfc9b..1f57441845 100644 --- a/config/qt.m4 +++ b/config/qt.m4 @@ -214,31 +214,15 @@ AC_DEFUN([QT_DO_IT_ALL], fi;; esac + dnl Specific support for X11 will be built if these are available + AC_CHECK_HEADERS([xcb/xcb.h]) + AC_CHECK_LIB([xcb], [xcb_send_event]) save_CPPFLAGS=$CPPFLAGS CPPFLAGS="$save_CPPFLAGS $QT_CORE_INCLUDES" AC_CHECK_HEADER(QtGui/qtgui-config.h, [lyx_qt_config=QtGui/qtgui-config.h], [lyx_qt_config=qconfig.h]) - AC_MSG_CHECKING([whether Qt uses the X Window system]) - if test x$USE_QT6 = xyes ; then - dnl FIXME: Check whether defining QPA_XCB makes sense with Qt6 - AC_PREPROC_IFELSE([AC_LANG_SOURCE([ - [#include <$lyx_qt_config>] - [#if !defined(QT_FEATURE_xcb) || QT_FEATURE_xcb < 0] - [#error Fail] - [#endif]])], - [AC_MSG_RESULT(yes) - AC_DEFINE(QPA_XCB, 1, [Define if Qt uses the X Window System])], - [AC_MSG_RESULT(no)]) - else - AC_EGREP_CPP(xcb, - [#include <$lyx_qt_config> - QT_QPA_DEFAULT_PLATFORM_NAME], - [AC_MSG_RESULT(yes) - AC_DEFINE(QPA_XCB, 1, [Define if Qt uses the X Window System])], - [AC_MSG_RESULT(no)]) - fi CPPFLAGS=$save_CPPFLAGS QT_FIND_TOOL([QT_MOC], [moc]) diff --git a/development/cmake/ConfigureChecks.cmake b/development/cmake/ConfigureChecks.cmake index 9062372c38..7e6707ca59 100644 --- a/development/cmake/ConfigureChecks.cmake +++ b/development/cmake/ConfigureChecks.cmake @@ -28,7 +28,7 @@ test_big_endian(WORDS_BIGENDIAN) set(Include_Defines) foreach(_h_file aspell.h aspell/aspell.h limits.h locale.h stdlib.h sys/stat.h sys/time.h sys/types.h sys/utime.h - sys/socket.h unistd.h inttypes.h utime.h string.h argz.h) + sys/socket.h unistd.h inttypes.h utime.h string.h argz.h xcb/xcb.h) string(REGEX REPLACE "[/\\.]" "_" _hf ${_h_file}) string(TOUPPER ${_hf} _HF) check_include_files(${_h_file} HAVE_${_HF}) @@ -275,7 +275,6 @@ else() endif() endif() -set(QPA_XCB) set(HAVE_QT5_X11_EXTRAS) set(HAVE_QT6_X11_EXTRAS) if (LYX_USE_QT MATCHES "QT5|QT6") @@ -312,10 +311,6 @@ if (LYX_USE_QT MATCHES "QT5|QT6") } " QT_USES_X11) - if(QT_USES_X11 AND NOT LYX_USE_QT MATCHES "QT6") - set(QPA_XCB ${QT_USES_X11}) - message(STATUS "Found QPA_XCB = ${QPA_XCB}") - endif() endif() if (${QtVal}X11Extras_FOUND) diff --git a/development/cmake/config.h.cmake b/development/cmake/config.h.cmake index 15bceaac46..6b5b82f803 100644 --- a/development/cmake/config.h.cmake +++ b/development/cmake/config.h.cmake @@ -64,9 +64,6 @@ #cmakedefine Z_PREFIX 1 -// Defined if QT=QT5 uses X11 -#cmakedefine QPA_XCB 1 - // Define if you have the Qt5X11Extras module #cmakedefine HAVE_QT5_X11_EXTRAS 1 @@ -91,10 +88,13 @@ ${Include_used_spellchecker} // Define to 1 if enchant is version 2.x at least #cmakedefine HAVE_ENCHANT2 1 -#endif // config.h guard +// Define to 1 if have xcb library +#cmakedefine HAVE_LIBXCB ${HAVE_LIBXCB} #define MYTHES_H_LOCATION <${MYTHES_DIR}/mythes.hxx> +#endif // config.h guard + // Unguarded cleanup of global namespace: #ifdef ColorMode diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4debde6c16..b89ecee2f6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -148,7 +148,6 @@ if(QT_USES_X11) find_package(X11 REQUIRED) target_link_libraries(${_lyx} ${X11_X11_LIB}) # we need it because we use XSendEvent if(HAVE_QT5_X11_EXTRAS) - find_library(XCB_LIBRARY NAMES xcb) if (XCB_LIBRARY MATCHES "NOTFOUND") message(FATAL_ERROR "Need xcb library to use with QT5_X11_EXTRAS") endif() diff --git a/src/frontends/qt/GuiApplication.cpp b/src/frontends/qt/GuiApplication.cpp index 9a94fa53cd..de955e4e7c 100644 --- a/src/frontends/qt/GuiApplication.cpp +++ b/src/frontends/qt/GuiApplication.cpp @@ -121,7 +121,7 @@ #include #include -#if defined(QPA_XCB) +#ifdef HAVE_XCB_XCB_H #include #ifdef HAVE_QT5_X11_EXTRAS #include @@ -1157,10 +1157,14 @@ GuiApplication::GuiApplication(int & argc, char ** argv) // Install Qt native translator for GUI elements. installTranslator(&d->qt_trans_); -#ifdef QPA_XCB - // Enable reception of XCB events. - installNativeEventFilter(this); + if (platformName() == "xcb") { +#if defined(HAVE_XCB_XCB_H) && defined(HAVE_LIBXCB) + // Enable reception of XCB events. + installNativeEventFilter(this); +#else + LYXERR0("Warning: X11 support is incomplete in this LyX binary."); #endif + } // FIXME: quitOnLastWindowClosed is true by default. We should have a // lyxrc setting for this in order to let the application stay resident. @@ -1181,13 +1185,13 @@ GuiApplication::GuiApplication(int & argc, char ** argv) this, SLOT(onApplicationStateChanged(Qt::ApplicationState))); #endif -#if defined(QPA_XCB) - // doubleClickInterval() is 400 ms on X11 which is just too long. - // On Windows and Mac OS X, the operating system's value is used. - // On Microsoft Windows, calling this function sets the double - // click interval for all applications. So we don't! - QApplication::setDoubleClickInterval(300); -#endif + if (platformName() == "xcb") { + // doubleClickInterval() is 400 ms on X11 which is just too long. + // On Windows and Mac OS X, the operating system's value is used. + // On Microsoft Windows, calling this function sets the double + // click interval for all applications. So we don't! + QApplication::setDoubleClickInterval(300); + } connect(this, SIGNAL(lastWindowClosed()), this, SLOT(onLastWindowClosed())); @@ -3477,7 +3481,7 @@ bool GuiApplication::longOperationStarted() { // // X11 specific stuff goes here... -#if defined(QPA_XCB) +#if defined(HAVE_XCB_XCB_H) && defined(HAVE_LIBXCB) bool GuiApplication::nativeEventFilter(const QByteArray & eventType, void * message, QINTPTR *) { diff --git a/src/frontends/qt/GuiApplication.h b/src/frontends/qt/GuiApplication.h index b27964dde4..b31face5b7 100644 --- a/src/frontends/qt/GuiApplication.h +++ b/src/frontends/qt/GuiApplication.h @@ -20,7 +20,7 @@ #include #include -#ifdef QPA_XCB +#if defined(HAVE_XCB_XCB_H) && defined(HAVE_LIBXCB) #include #endif @@ -53,7 +53,7 @@ There should be only one instance of this class. No Qt object initialisation should be done before the instantiation of this class. */ class GuiApplication : public QApplication, public Application -#ifdef QPA_XCB +#if defined(HAVE_XCB_XCB_H) && defined(HAVE_LIBXCB) , public QAbstractNativeEventFilter #endif { @@ -120,7 +120,7 @@ public: //@{ bool notify(QObject * receiver, QEvent * event) override; void commitData(QSessionManager & sm); -#if defined(QPA_XCB) +#if defined(HAVE_XCB_XCB_H) && defined(HAVE_LIBXCB) #if (QT_VERSION < 0x060000) #define QINTPTR long #else diff --git a/status.24x b/status.24x index 64b9892a13..77034ea06f 100644 --- a/status.24x +++ b/status.24x @@ -59,6 +59,9 @@ What's new - Make -geometry command-line option work on all platforms. +- Fix macOS bug, where XQuartz application would be launched for no + reason (bug #13086). + * DOCUMENTATION AND LOCALIZATION