[LyX/2.3.x] Use backing store also with wayland platform

Jean-Marc Lasgouttes lasgouttes at lyx.org
Thu Nov 7 11:26:56 UTC 2019


commit aaf96b30250e68b5e54320aa2477f627691835a7
Author: Jean-Marc Lasgouttes <lasgouttes at lyx.org>
Date:   Sat Jul 13 16:21:37 2019 +0200

    Use backing store also with wayland platform
    
    Like with macOS, the Wayland compositor seems to require a
    backingstore when doing partial updates like we do.
    
    This extends the mechanism that has been introduced for macOS. This
    has to be done at run time, not compile time.
    
    Fixes bug #11692.
    
    (cherry picked from commit 575761c665229e70d9ce9b2bd941d01a1873b9f1)
---
 src/frontends/qt4/GuiWorkArea.cpp       |   61 ++++++++++++++++++++++++++++---
 src/frontends/qt4/GuiWorkArea_Private.h |   50 +++++---------------------
 status.23x                              |    1 +
 3 files changed, 65 insertions(+), 47 deletions(-)

diff --git a/src/frontends/qt4/GuiWorkArea.cpp b/src/frontends/qt4/GuiWorkArea.cpp
index 5ef177d..e16ea16 100644
--- a/src/frontends/qt4/GuiWorkArea.cpp
+++ b/src/frontends/qt4/GuiWorkArea.cpp
@@ -239,13 +239,27 @@ SyntheticMouseEvent::SyntheticMouseEvent()
 
 
 GuiWorkArea::Private::Private(GuiWorkArea * parent)
-: p(parent), buffer_view_(0), lyx_view_(0),
-  caret_(0), caret_visible_(false),
-  need_resize_(false), preedit_lines_(1),
-  last_pixel_ratio_(1.0),
-  completer_(new GuiCompleter(p, p)), dialog_mode_(false), shell_escape_(false),
-  read_only_(false), clean_(true), externally_modified_(false)
-{
+: p(parent), buffer_view_(0), lyx_view_(0), caret_(0),
+  caret_visible_(false), need_resize_(false), preedit_lines_(1),
+  last_pixel_ratio_(1.0), completer_(new GuiCompleter(p, p)),
+  dialog_mode_(false), shell_escape_(false), read_only_(false),
+  clean_(true), externally_modified_(false)
+{
+/* Qt on macOS and Wayland does not respect the
+ * Qt::WA_OpaquePaintEvent attribute and resets the widget backing
+ * store at each update. Therefore, we use our own backing store in
+ * these two cases. */
+#if QT_VERSION >= 0x050000
+	use_backingstore_ = guiApp->platformName() == "cocoa"
+		|| guiApp->platformName().contains("wayland");
+#else
+#  ifdef Q_OS_MAC
+	use_backingstore_ = true;
+#  else
+	use_backingstore_ = false;
+#  endif
+#endif
+
 	int const time = QApplication::cursorFlashTime() / 2;
 	if (time > 0) {
 		caret_timeout_.setInterval(time);
@@ -1257,6 +1271,41 @@ void GuiWorkArea::Private::paintPreeditText(GuiPainter & pain)
 }
 
 
+void GuiWorkArea::Private::resetScreen()
+{
+	if (use_backingstore_) {
+		int const pr = p->pixelRatio();
+		screen_ = QImage(static_cast<int>(pr * p->viewport()->width()),
+		                 static_cast<int>(pr * p->viewport()->height()),
+		                 QImage::Format_ARGB32_Premultiplied);
+#  if QT_VERSION >= 0x050000
+		screen_.setDevicePixelRatio(pr);
+#  endif
+	}
+}
+
+
+QPaintDevice * GuiWorkArea::Private::screenDevice()
+{
+	if (use_backingstore_)
+		return &screen_;
+	else
+		return p->viewport();
+}
+
+
+void GuiWorkArea::Private::updateScreen(QRectF const & rc)
+{
+	if (use_backingstore_) {
+		QPainter qpain(p->viewport());
+		double const pr = p->pixelRatio();
+		QRectF const rcs = QRectF(rc.x() * pr, rc.y() * pr,
+		                          rc.width() * pr, rc.height() * pr);
+		qpain.drawImage(rc, screen_, rcs);
+	}
+}
+
+
 void GuiWorkArea::paintEvent(QPaintEvent * ev)
 {
 	// Do not trigger the painting machinery if we are not ready (see
diff --git a/src/frontends/qt4/GuiWorkArea_Private.h b/src/frontends/qt4/GuiWorkArea_Private.h
index 83012fa..6342eab 100644
--- a/src/frontends/qt4/GuiWorkArea_Private.h
+++ b/src/frontends/qt4/GuiWorkArea_Private.h
@@ -20,14 +20,6 @@
 #include <QMouseEvent>
 #include <QTimer>
 
-#ifdef Q_OS_MAC
-/* Qt on macOS does not respect the Qt::WA_OpaquePaintEvent attribute
- * and resets the widget backing store at each update. Therefore, we
- * use our own backing store in this case */
-#define LYX_BACKINGSTORE 1
-#include <QPainter>
-#endif
-
 namespace lyx {
 
 class Buffer;
@@ -107,37 +99,12 @@ struct GuiWorkArea::Private
 
 	void paintPreeditText(GuiPainter & pain);
 
-	void resetScreen() {
-#ifdef LYX_BACKINGSTORE
-		int const pr = p->pixelRatio();
-		screen_ = QImage(static_cast<int>(pr * p->viewport()->width()),
-		                 static_cast<int>(pr * p->viewport()->height()),
-		                 QImage::Format_ARGB32_Premultiplied);
-#  if QT_VERSION >= 0x050000
-		screen_.setDevicePixelRatio(pr);
-#  endif
-#endif
-	}
-
-	QPaintDevice * screenDevice() {
-#ifdef LYX_BACKINGSTORE
-		return &screen_;
-#else
-		return p->viewport();
-#endif
-	}
-
-#ifdef LYX_BACKINGSTORE
-	void updateScreen(QRectF const & rc) {
-		QPainter qpain(p->viewport());
-		double const pr = p->pixelRatio();
-		QRectF const rcs = QRectF(rc.x() * pr, rc.y() * pr,
-		                          rc.width() * pr, rc.height() * pr);
-		qpain.drawImage(rc, screen_, rcs);
-	}
-#else
-	void updateScreen(QRectF const & ) {}
-#endif
+	/// Prepare screen for next painting
+	void resetScreen();
+	/// Where painting takes place
+	QPaintDevice * screenDevice();
+	/// Put backingstore to screen if necessary
+	void updateScreen(QRectF const & rc);
 
 	///
 	GuiWorkArea * p;
@@ -146,10 +113,11 @@ struct GuiWorkArea::Private
 	///
 	GuiView * lyx_view_;
 
-#ifdef LYX_BACKINGSTORE
+	/// Do we need an intermediate image when painting (for now macOS and Wayland)
+	bool use_backingstore_;
 	///
 	QImage screen_;
-#endif
+
 	///
 	CaretWidget * caret_;
 	/// is the caret currently displayed
diff --git a/status.23x b/status.23x
index 8026ad9..62d9787 100644
--- a/status.23x
+++ b/status.23x
@@ -34,6 +34,7 @@ What's new
 - Do not issue error dialog when no tag is found in git repository for
   tree-revision info inset.
 
+- Fix display with Wayland (bug 11692).
 
 
 * DOCUMENTATION AND LOCALIZATION


More information about the lyx-cvs mailing list