Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid a flashing window blink during startup #1101

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading