Skip to content

Commit

Permalink
Avoid a flashing window blink during startup
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
davvid authored Mar 21, 2024
1 parent ef1bec6 commit eabe6f3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/gui/shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions src/gui/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<QUrl> m_deferredOpen;
Expand Down Expand Up @@ -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 };
Expand Down

0 comments on commit eabe6f3

Please sign in to comment.