From d55b98847cceda082cb01ef9b522e333308a4792 Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Wed, 20 Mar 2024 20:43:37 -0700 Subject: [PATCH] Avoid a flashing window blink during startup The very first paint events cause a bright flash of unstyled shell content to appear before the configured colors are applied. Defer displaying the shell widget until nvim sends us colors. Instead of seeing the shell with its constructor-provided colors we will instead see Qt's default window background color, which follows the user's desktop theme and dark mode settings. The shell is made visible either after nvim sends a "default_colors_set" message and the colors are applied, or when the visibility timer fires, whichever happens first. In practice, the "default_colors_set" message is typically received before the timer times out and runs its callback. --- src/gui/shell.cpp | 25 +++++++++++++++++++++++++ src/gui/shell.h | 4 ++++ 2 files changed, 29 insertions(+) diff --git a/src/gui/shell.cpp b/src/gui/shell.cpp index a8ea05025..90a29f5e9 100644 --- a/src/gui/shell.cpp +++ b/src/gui/shell.cpp @@ -103,6 +103,15 @@ Shell::Shell(NeovimConnector *nvim, QWidget *parent) m_nvim->setRequestHandler(new ShellRequestHandler(this)); } +void Shell::ensureVisible() noexcept +{ + if (!m_shown) { + m_shown = true; + setVisible(true); + setFocus(); + } +} + void Shell::handleFontError(const QString& msg) { if (m_attached) { @@ -326,6 +335,10 @@ void Shell::init() return; } + // Pull Request#1101: Defer displaying the shell until colors have been set + if (!m_shown) { + setVisible(false); + } connect(m_nvim->api0(), &NeovimApi0::neovimNotification, this, &Shell::handleNeovimNotification); connect(m_nvim->api0(), &NeovimApi0::on_ui_try_resize, @@ -365,6 +378,16 @@ void Shell::init() // Set initial value m_nvim->api0()->vim_set_var("GuiWindowFrameless", (windowFlags() & Qt::FramelessWindowHint) ? 1: 0); + + // Make the shell visible even when default_colors_set is not received, + // e.g. when using the older cell-based grid protocol. + if (!m_shown) { + constexpr int visibility_timeout{ 850 }; + m_visibility_timer.setInterval(visibility_timeout); + m_visibility_timer.setSingleShot(true); + connect(&m_visibility_timer, &QTimer::timeout, this, &Shell::ensureVisible); + m_visibility_timer.start(); + } } void Shell::neovimError(NeovimConnector::NeovimError err) @@ -1127,6 +1150,8 @@ void Shell::handleDefaultColorsSet(const QVariantList& opargs) setBackground(backgroundColor); setSpecial(specialColor); + // Display the shell now that the default colors have been set. + ensureVisible(); // Cells drawn with the default colors require a re-paint update(); emit colorsChanged(); diff --git a/src/gui/shell.h b/src/gui/shell.h index 69562dc70..d4d9216e7 100644 --- a/src/gui/shell.h +++ b/src/gui/shell.h @@ -190,10 +190,12 @@ protected slots: private slots: void setAttached(bool attached); + void ensureVisible() noexcept; private: bool m_init_called{ false }; bool m_attached{ false }; + bool m_shown{ false }; NeovimConnector* m_nvim{ nullptr }; QList m_deferredOpen; @@ -231,6 +233,8 @@ private slots: Qt::MouseButton m_mouseclick_pending; // Accumulates remainder of steppy scroll QPoint m_scrollDeltaRemainder; + // Ensures that the Shell widget is made visible + QTimer m_visibility_timer; // Properties bool m_neovimBusy{ false };