[LyX/master] Remove legacy code to compute geometry

Jean-Marc Lasgouttes lasgouttes at lyx.org
Fri Aug 30 12:51:23 UTC 2024


commit 3c59a9a23cdcae77fd0b85dc2d66d86fe611d051
Author: Jean-Marc Lasgouttes <lasgouttes at lyx.org>
Date:   Fri Aug 30 14:31:47 2024 +0200

    Remove legacy code to compute geometry
    
    This code is not necessary anymore after the fix to #13069.
    
    Remove the first QString argument to createView(). Set the autoShow
    parameter to false by default and rename createView(id) to
    createAndShowView(id) to avoid member function overloading issues.
    
    Remove optional <GEOMETRY> argument of window-new lfun.
    Document the removal of the argument in release notes.
---
 lib/RELEASE-NOTES                   |  4 +++
 src/LyXAction.cpp                   |  4 +--
 src/frontends/qt/GuiApplication.cpp | 61 +++++++------------------------------
 src/frontends/qt/GuiApplication.h   | 13 ++++----
 4 files changed, 22 insertions(+), 60 deletions(-)

diff --git a/lib/RELEASE-NOTES b/lib/RELEASE-NOTES
index e7c4b9feca..64191591aa 100644
--- a/lib/RELEASE-NOTES
+++ b/lib/RELEASE-NOTES
@@ -15,6 +15,10 @@
 
 !!!The following LyX functions have been changed in 2.5:
 
+- The funcion window_new does not take an optional <GEOMETRY>
+  parameter anymore. This only worked in windows and existed for
+  internal reasons.
+
 !!!The following LyX functions have been removed in 2.5:
 
 !!!The following LyX function has been added and then removed in 2.5 development cycle:
diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp
index e07f260b25..489002364c 100644
--- a/src/LyXAction.cpp
+++ b/src/LyXAction.cpp
@@ -4417,9 +4417,7 @@ void LyXAction::init()
  * \var lyx::FuncCode lyx::LFUN_WINDOW_NEW
  * \li Action: Creates new empty LyX window.
  * \li Notion: Already opened documents from the previous window can be found under View menu.
- * \li Syntax: window-new [<GEOMETRY>]
- * \li Params: <GEOMETRY>: pass the geometry of the window. This parameter is currently
-                           accepted only on Windows platform.
+ * \li Syntax: window-new
  * \li Origin: Abdel, 21 Oct 2006
  * \endvar
  */
diff --git a/src/frontends/qt/GuiApplication.cpp b/src/frontends/qt/GuiApplication.cpp
index 00648c1561..a4c8b328b3 100644
--- a/src/frontends/qt/GuiApplication.cpp
+++ b/src/frontends/qt/GuiApplication.cpp
@@ -1771,7 +1771,7 @@ void GuiApplication::dispatch(FuncRequest const & cmd, DispatchResult & dr)
 	switch (cmd.action()) {
 
 	case LFUN_WINDOW_NEW:
-		createView(toqstr(cmd.argument()));
+		createAndShowView();
 		break;
 
 	case LFUN_WINDOW_CLOSE:
@@ -1811,7 +1811,7 @@ void GuiApplication::dispatch(FuncRequest const & cmd, DispatchResult & dr)
 		validateCurrentView();
 		if (!current_view_
 		   || (!lyxrc.open_buffers_in_tabs && current_view_->documentBufferView() != nullptr)) {
-			createView(QString(), false); // keep hidden
+			createView(); // keep hidden
 			current_view_->newDocument(to_utf8(cmd.argument()));
 			current_view_->show();
 			current_view_->activateWindow();
@@ -1826,7 +1826,7 @@ void GuiApplication::dispatch(FuncRequest const & cmd, DispatchResult & dr)
 		validateCurrentView();
 		if (!current_view_
 		   || (!lyxrc.open_buffers_in_tabs && current_view_->documentBufferView() != nullptr)) {
-			createView();
+			createAndShowView();
 			current_view_->newDocument(file, temp, true);
 			if (!current_view_->documentBufferView())
 				current_view_->close();
@@ -1850,7 +1850,7 @@ void GuiApplication::dispatch(FuncRequest const & cmd, DispatchResult & dr)
 			&& !is_open)) {
 			// We want the ui session to be saved per document and not per
 			// window number. The filename crc is a good enough identifier.
-			createView(support::checksum(fname));
+			createAndShowView(support::checksum(fname));
 			current_view_->openDocuments(fname, cmd.origin());
 			if (!current_view_->documentBufferView())
 				current_view_->close();
@@ -1873,7 +1873,7 @@ void GuiApplication::dispatch(FuncRequest const & cmd, DispatchResult & dr)
 	case LFUN_HELP_OPEN: {
 		// FIXME: create a new method shared with LFUN_FILE_OPEN.
 		if (current_view_ == nullptr)
-			createView();
+			createAndShowView();
 		string const arg = to_utf8(cmd.argument());
 		if (arg.empty()) {
 			current_view_->message(_("Missing argument"));
@@ -2263,7 +2263,7 @@ void GuiApplication::dispatch(FuncRequest const & cmd, DispatchResult & dr)
 		    || name == "progress" || name == "texinfo")
 		{
 			if (current_view_ == nullptr)
-				createView();
+				createAndShowView();
 		}
 	}
 	// fall through
@@ -2572,14 +2572,13 @@ bool GuiApplication::rtlContext() const
 }
 
 
-void GuiApplication::createView(int view_id)
+void GuiApplication::createAndShowView(int view_id)
 {
-	createView(QString(), true, view_id);
+	createView(true, view_id);
 }
 
 
-void GuiApplication::createView(QString const & geometry_arg, bool autoShow,
-	int view_id)
+void GuiApplication::createView(bool autoShow, int view_id)
 {
 	// release the keyboard which might have been grabbed by the global
 	// menubar on Mac to catch shortcuts even without any GuiView.
@@ -2603,44 +2602,6 @@ void GuiApplication::createView(QString const & geometry_arg, bool autoShow,
 		view->activateWindow();
 	}
 
-	if (!geometry_arg.isEmpty()) {
-#if defined(Q_OS_WIN) || defined(Q_CYGWIN_WIN)
-		int x, y;
-		int w, h;
-		QChar sx, sy;
-		QRegularExpression re( "[=]*(?:([0-9]+)[xX]([0-9]+)){0,1}[ ]*(?:([+-][0-9]*)){0,1}(?:([+-][0-9]*)){0,1}" );
-		QRegularExpressionMatch match = re.match(geometry_arg);
-		w = match.captured(1).toInt();
-		h = match.captured(2).toInt();
-		x = match.captured(3).toInt();
-		y = match.captured(4).toInt();
-		sx = match.captured(3).isEmpty() ? '+' : match.captured(3).at(0);
-		sy = match.captured(4).isEmpty() ? '+' : match.captured(4).at(0);
-
-		// Set initial geometry such that we can get the frame size.
-		view->setGeometry(x, y, w, h);
-		int framewidth = view->geometry().x() - view->x();
-		int titleheight = view->geometry().y() - view->y();
-		// Negative displacements must be interpreted as distances
-		// from the right or bottom screen borders.
-		if (sx == '-' || sy == '-') {
-			QRect rec = QGuiApplication::primaryScreen()->geometry();
-			if (sx == '-')
-				x += rec.width() - w - framewidth;
-			if (sy == '-')
-				y += rec.height() - h - titleheight;
-			view->setGeometry(x, y, w, h);
-		}
-		// Make sure that the left and top frame borders are visible.
-		if (view->x() < 0 || view->y() < 0) {
-			if (view->x() < 0)
-				x = framewidth;
-			if (view->y() < 0)
-				y = titleheight;
-			view->setGeometry(x, y, w, h);
-		}
-#endif
-	}
 	view->setFocus();
 }
 
@@ -2900,7 +2861,7 @@ void GuiApplication::restoreGuiSession()
 		if (!current_view_ || (!lyxrc.open_buffers_in_tabs
 			  && current_view_->documentBufferView() != nullptr)) {
 			string const & fname = file_name.absFileName();
-			createView(support::checksum(fname));
+			createAndShowView(support::checksum(fname));
 		}
 		current_view_->loadDocument(file_name, false);
 
@@ -3469,7 +3430,7 @@ void GuiApplication::onApplicationStateChanged(Qt::ApplicationState state)
 		/// cmd+tab only one QEvent::ApplicationStateChangeEvent event
 		if (d->views_.empty() && d->last_state_ == state) {
 			LYXERR(Debug::GUI, "Open new window...");
-			createView();
+			createAndShowView();
 		}
 		break;
 	}
diff --git a/src/frontends/qt/GuiApplication.h b/src/frontends/qt/GuiApplication.h
index a2fce4d6fe..22e35c7d9f 100644
--- a/src/frontends/qt/GuiApplication.h
+++ b/src/frontends/qt/GuiApplication.h
@@ -132,13 +132,12 @@ public:
 #endif
 	//@}
 
-	/// Create the main window with given geometry settings.
-	/// \param geometry_arg: only for Windows platform.
-	/// \param optional id identifier.
-	void createView(QString const & geometry_arg = QString(),
-		bool autoShow = true, int id = 0);
-	/// FIXME: this method and the one above are quite ugly.
-	void createView(int id);
+	/// Create the main window
+	/// \param autoShow: show the created window
+	/// \param id: optional identifier.
+	void createView(bool autoShow = false, int id = 0);
+	/// Same as createView, but with \c autoShow = true
+	void createAndShowView(int id = 0);
 	///
 	GuiView const * currentView() const { return current_view_; }
 	///


More information about the lyx-cvs mailing list