]> git.lyx.org Git - lyx.git/commitdiff
Add lyxrc option to force the use of backing store
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 16 Dec 2021 11:38:19 +0000 (12:38 +0100)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 13 Jan 2022 16:24:28 +0000 (17:24 +0100)
LyX relies on a a backing store to draw when running under macOS or
Wayland, because Qt arbitrarily overwrites parts of the workarea
before we paint (and we paint only the parts that need to be painted).
However it seems that this is also necessary on X11 when the WM theme
is translucid. Since there is no way that I know of to detect this
situation, this patch adds a LyXRC setting to manually select this
drawing strategy.

Note that using a backing store is not always a good solution, since
this disables subpixel aliasing.

At this point there is no UI for the variable.

Fixes bug #12119

(cherry picked from commit c213eb7f75d53165f55e64f0149fec833e5b5b5e)
(cherry picked from commit 1ed9257c6dc57fc11990b86d5774ac9a8e70cfa6)

lib/RELEASE-NOTES
src/LyXRC.cpp
src/LyXRC.h
src/frontends/qt4/GuiApplication.cpp
src/frontends/qt4/GuiApplication.h
src/frontends/qt4/GuiWorkArea.cpp
status.23x

index a5760387efb32c8a469fa9bccede9d3c6c3dd24c..f05fdd1299a379b61f363d97e19e150ce5d15d11 100644 (file)
@@ -1,3 +1,14 @@
+!Important Change in LyX 2.3.7
+
+The following pref variable was added:
+
+* \draw_strategy partial|backingstore: when this is set to
+  "backingstore", the drawing code will force the use of an
+  intermediate surface, instead of just drawing changed regions on
+  screen. Note that "backingstore" is actually always enforced on
+  macOS and Wayland (default: partial).
+
+
 !Important Change in LyX 2.3.1
 
 * A change to how math macros are output can break some documents that use
index e8e66e221d7e260827d627c4734fa231eac9247b..0753534cf31088bd6b45f7bd1182d77c03f50654 100644 (file)
@@ -105,6 +105,7 @@ LexerKeyword lyxrcTags[] = {
        { "\\dialogs_iconify_with_main", LyXRC::RC_DIALOGS_ICONIFY_WITH_MAIN },
        { "\\display_graphics", LyXRC::RC_DISPLAY_GRAPHICS },
        { "\\document_path", LyXRC::RC_DOCUMENTPATH },
+       { "\\draw_strategy", LyXRC::RC_DRAW_STRATEGY },
        { "\\editor_alternatives", LyXRC::RC_EDITOR_ALTERNATIVES },
        { "\\escape_chars", LyXRC::RC_ESC_CHARS },
        { "\\example_path", LyXRC::RC_EXAMPLEPATH },
@@ -1244,6 +1245,20 @@ LyXRC::ReturnValues LyXRC::read(Lexer & lexrc, bool check_format)
                        lexrc >> mouse_middlebutton_paste;
                        break;
 
+               case RC_DRAW_STRATEGY:
+                       if (lexrc.next()) {
+                               string const tmp = lexrc.getString();
+                               if (tmp == "partial")
+                                       draw_strategy = DS_PARTIAL;
+                               else if (tmp == "backingstore")
+                                       draw_strategy = DS_BACKINGSTORE;
+                               else {
+                                       draw_strategy = DS_PARTIAL;
+                                       LYXERR0("Unrecognized draw strategy " << tmp <<'"');
+                               }
+                       }
+                       break;
+
                case RC_LAST:
                        break; // this is just a dummy
                }
@@ -2064,10 +2079,28 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc, string const & name) c
                }
                if (tag != RC_LAST)
                        break;
+               // fall through
+       case RC_DRAW_STRATEGY:
+               if (ignore_system_lyxrc ||
+                       draw_strategy != system_lyxrc.draw_strategy) {
+                       string status;
+                       switch (draw_strategy) {
+                       case DS_PARTIAL:
+                               status = "partial";
+                               break;
+                       case DS_BACKINGSTORE:
+                               status = "backingstore";
+                               break;
+                       }
+                       os << "\\draw_strategy " << status << '\n';
+               }
+               if (tag != RC_LAST)
+                       break;
+               // fall through
 
        os << "\n#\n"
-                       << "# COLOR SECTION ###################################\n"
-                       << "#\n\n";
+               << "# COLOR SECTION ###################################\n"
+               << "#\n\n";
 
        // fall through
        case RC_SET_COLOR:
@@ -2963,6 +2996,7 @@ void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new)
                                package().document_dir() = FileName(lyxrc.document_path);
                }
                // fall through
+       case LyXRC::RC_DRAW_STRATEGY:
        case LyXRC::RC_EDITOR_ALTERNATIVES:
        case LyXRC::RC_ESC_CHARS:
        case LyXRC::RC_EXAMPLEPATH:
index 7049bf8d5e865f8c351a0a006c54b2cdc366ff9a..6e494d078617e753a953c9732a8889b1fce471b5 100644 (file)
@@ -183,6 +183,7 @@ public:
                RC_VIEWER_ALTERNATIVES,
                RC_VISUAL_CURSOR,
                RC_CLOSE_BUFFER_WITH_LAST_VIEW,
+               RC_DRAW_STRATEGY,
                RC_LAST
        };
 
@@ -533,6 +534,17 @@ public:
        int cursor_width;
        /// One of: yes, no, ask
        std::string close_buffer_with_last_view;
+
+       enum DrawStrategy {
+               // draw all (not implemented yet)
+               // FS_FULL,
+               // draw only what has changed
+               DS_PARTIAL,
+               // draw in backing store (only what has changed)
+               DS_BACKINGSTORE
+       };
+       ///
+       DrawStrategy draw_strategy = DS_PARTIAL;
 };
 
 
index 271e4c7d4ddae58c57fbe44eb5575123d7112642..246b45671e21b15c78bae2e423e65e4c05290988 100644 (file)
@@ -2509,6 +2509,26 @@ Menus & GuiApplication::menus()
 }
 
 
+bool GuiApplication::needsBackingStore() const
+{
+       /* 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. It is also possible to force the use of the
+        * backing store for cases like x11 with transparent WM themes.
+        */
+#if QT_VERSION >= 0x050000
+       return platformName() == "cocoa" || platformName().contains("wayland");
+#else
+#  ifdef Q_OS_MAC
+       return true;
+#  else
+    return false;
+#  endif // Q_OS_MAC
+#endif // QT_VERSION
+}
+
+
 QList<int> GuiApplication::viewIds() const
 {
        return d->views_.keys();
index eb25bc1b1e5452f8aee7342e323f3d657c416ddf..8c6b0e06b2c15b9fc80685f8ba7b9be29ed92879 100644 (file)
@@ -103,6 +103,9 @@ public:
        ///
        Menus & menus();
 
+       /// \returns true if painting the workarea requires a backing store.
+       bool needsBackingStore() const;
+
        /// \name Methods inherited from QApplication class
        //@{
        bool notify(QObject * receiver, QEvent * event) override;
index a16a9c8ffe83be1cdbb3527b756821150c833d9c..731802087e00302a8143b16ec14a136524cf4836 100644 (file)
@@ -245,20 +245,10 @@ GuiWorkArea::Private::Private(GuiWorkArea * parent)
   dialog_mode_(false), shell_escape_(false), read_only_(false),
   clean_(true), externally_modified_(false), needs_caret_geometry_update_(true)
 {
-/* 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
+       use_backingstore_ = lyxrc.draw_strategy == LyXRC::DS_BACKINGSTORE
+               || guiApp->needsBackingStore();
+       LYXERR(Debug::WORKAREA, "Drawing strategy is: "
+                               << (use_backingstore_ ? "backingstore" : "partial"));
 
        int const time = QApplication::cursorFlashTime() / 2;
        if (time > 0) {
index 12af42228a55e331f83db1f405887b173596b3d5..5f56fee5925d822ab5a654b0427e3a61107e9cd5 100644 (file)
@@ -44,6 +44,9 @@ What's new
 
 - Fix broken modifier handling for Qt-5.12 on Mac (bug 12247).
 
+- Add new pref variable \draw_strategy to fix some cases where display
+  is blinking (bug 12119).
+
 
 * DOCUMENTATION AND LOCALIZATION