Le 28/08/2024 à 20:51, Enrico Forestieri a écrit :
I am not sure I understand your concern. That makes the -geometry option work also on Windows. Maybe those lines can be transferred in the following guard, i.e.,

I propose a more radical approach, which is to change -geometry to -windowgeometry on all platforms. This means that -geometry is now supported everywhere.

What I did not do is remove the hand-made parsing of geometry that is used for window-new lfun only on Windows (why?). Can this go away?

The second patch gets rid of QPA_XCB and replaces it with a runtime decision depending on current platform. In theory, this would allow for cocoa/xcb or win32/xcb binaries (like we have xcb/wayland binaries), with some extra work of course.

Thoughts?

JMarc

PS: the cmake part of second patch is missing, but it is straightforward: get rid of QPA_XCB and define HAVE_XCB_XCB_H HAVE_LIXCB if they are available.
From f2efed661bde9e03baf8269ee1f302c7489a162e Mon Sep 17 00:00:00 2001
From: Jean-Marc Lasgouttes <[email protected]>
Date: Thu, 29 Aug 2024 11:10:31 +0200
Subject: [PATCH 1/2] Streamline -geometry argument support

---
 src/LyX.cpp                         | 23 +++++------------------
 src/frontends/qt/GuiApplication.cpp | 14 --------------
 2 files changed, 5 insertions(+), 32 deletions(-)

diff --git a/src/LyX.cpp b/src/LyX.cpp
index c0dbd019b9..8f13f83713 100644
--- a/src/LyX.cpp
+++ b/src/LyX.cpp
@@ -127,8 +127,6 @@ namespace {
 string cl_system_support;
 string cl_user_support;
 
-string geometryArg;
-
 LyX * singleton_ = nullptr;
 
 void showFileError(string const & error)
@@ -611,7 +609,7 @@ void LyX::execCommands()
 	}
 
 	// create the first main window
-	lyx::dispatch(FuncRequest(LFUN_WINDOW_NEW, geometryArg));
+	lyx::dispatch(FuncRequest(LFUN_WINDOW_NEW));
 
 	if (!pimpl_->files_to_load_.empty()) {
 		// if some files were specified at command-line we assume that the
@@ -1342,20 +1340,6 @@ int parse_import(string const & type, string const & file, string & batch)
 }
 
 
-int parse_geometry(string const & arg1, string const &, string &)
-{
-	geometryArg = arg1;
-#if !defined(QPA_XCB)
-	// don't remove "-geometry", it will be pruned out later in the
-	// frontend if need be.
-	return -1;
-#else
-	// but that is only done if QPA_XCB is not defined.
-	return 1;
-#endif
-}
-
-
 int parse_batch(string const &, string const &, string &)
 {
 	use_gui = false;
@@ -1433,7 +1417,6 @@ void LyX::easyParse(int & argc, char * argv[])
 	cmdmap["--export-to"] = parse_export_to;
 	cmdmap["-i"] = parse_import;
 	cmdmap["--import"] = parse_import;
-	cmdmap["-geometry"] = parse_geometry;
 	cmdmap["-batch"] = parse_batch;
 	cmdmap["-f"] = parse_force;
 	cmdmap["--force-overwrite"] = parse_force;
@@ -1446,6 +1429,10 @@ void LyX::easyParse(int & argc, char * argv[])
 	cmdmap["--ignore-error-message"] = parse_ignore_error_message;
 
 	for (int i = 1; i < argc; ++i) {
+		// Let Qt handle -geometry even when not on X11.
+		if (from_utf8(argv[i]) == "-geometry")
+			argv[i] = const_cast<char *>("-qwindowgeometry");
+
 		map<string, cmd_helper>::const_iterator it
 			= cmdmap.find(argv[i]);
 
diff --git a/src/frontends/qt/GuiApplication.cpp b/src/frontends/qt/GuiApplication.cpp
index 6665631d31..f7eabe276c 100644
--- a/src/frontends/qt/GuiApplication.cpp
+++ b/src/frontends/qt/GuiApplication.cpp
@@ -172,20 +172,6 @@ namespace lyx {
 
 frontend::Application * createApplication(int & argc, char * argv[])
 {
-#if !defined(QPA_XCB)
-	// prune -geometry argument(s) by shifting
-	// the following ones 2 places down.
-	for (int i = 0 ; i < argc ; ++i) {
-		if (strcmp(argv[i], "-geometry") == 0) {
-			int const remove = (i+1) < argc ? 2 : 1;
-			argc -= remove;
-			for (int j = i; j < argc; ++j)
-				argv[j] = argv[j + remove];
-			--i;
-		}
-	}
-#endif
-
 #if defined(Q_OS_WIN) || defined(Q_CYGWIN_WIN)
 	// On Windows, allow bringing the LyX window to top
 	AllowSetForegroundWindow(ASFW_ANY);
-- 
2.34.1

From 7a3577239c6d047e529e51c8c279d96dc39d2380 Mon Sep 17 00:00:00 2001
From: Jean-Marc Lasgouttes <[email protected]>
Date: Thu, 29 Aug 2024 11:15:26 +0200
Subject: [PATCH 2/2] Get rid of QPA_XCB

---
 config/qt.m4                        | 22 +++-------------------
 src/frontends/qt/GuiApplication.cpp | 28 ++++++++++++++++------------
 src/frontends/qt/GuiApplication.h   |  6 +++---
 3 files changed, 22 insertions(+), 34 deletions(-)

diff --git a/config/qt.m4 b/config/qt.m4
index 6a455f9134..93b8575ad3 100644
--- a/config/qt.m4
+++ b/config/qt.m4
@@ -217,31 +217,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/src/frontends/qt/GuiApplication.cpp b/src/frontends/qt/GuiApplication.cpp
index f7eabe276c..00648c1561 100644
--- a/src/frontends/qt/GuiApplication.cpp
+++ b/src/frontends/qt/GuiApplication.cpp
@@ -121,7 +121,7 @@
 #include <QThreadPool>
 #include <QWidget>
 
-#if defined(QPA_XCB)
+#ifdef HAVE_XCB_XCB_H
 #include <xcb/xcb.h>
 #ifdef HAVE_QT5_X11_EXTRAS
 #include <QtX11Extras/QX11Info>
@@ -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()));
 
@@ -3498,7 +3502,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 38c3c0a6e0..a2fce4d6fe 100644
--- a/src/frontends/qt/GuiApplication.h
+++ b/src/frontends/qt/GuiApplication.h
@@ -20,7 +20,7 @@
 
 #include <QApplication>
 #include <QList>
-#ifdef QPA_XCB
+#if defined(HAVE_XCB_XCB_H) && defined(HAVE_LIBXCB)
 #include <QAbstractNativeEventFilter>
 #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
 {
@@ -121,7 +121,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
-- 
2.34.1

-- 
lyx-devel mailing list
[email protected]
http://lists.lyx.org/mailman/listinfo/lyx-devel

Reply via email to