Skip to content

Commit 9a12771

Browse files
wolfschafequalsraf
authored andcommitted
Fix CloseEvent, Forceful Exit
When the user or the Window Manager tries to close the application a second time after nvim displays the "Yes Save/No Save/Cancel" prompt, the application will now exit gracefully and not save the unsaved changes.
1 parent 4c07b2c commit 9a12771

File tree

5 files changed

+15
-2
lines changed

5 files changed

+15
-2
lines changed

src/gui/app.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,9 @@ bool App::event(QEvent* event) noexcept
241241
}
242242
else if (event->type() == QEvent::Quit) {
243243
for (auto window : s_windows) {
244-
if (!window->close()) {
244+
if (window->isClosing()) {
245+
window->emitForceClose();
246+
} else if (!window->close()) {
245247
event->setAccepted(false);
246248
}
247249
}
@@ -271,7 +273,7 @@ void App::showUi() noexcept
271273

272274
// delete the main window when closed to emit `destroyed()` signal to
273275
// support `:cq` return codes (Pull#644).
274-
setQuitOnLastWindowClosed(false);
276+
setQuitOnLastWindowClosed(true);
275277

276278
// Window geometry should be restored only when the user does not specify
277279
// one of the following command line arguments. Argument "maximized" can

src/gui/mainwindow.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,9 @@ void MainWindow::handleClosing()
280280
}
281281
emit closing(m_exitStatus);
282282
}
283+
void MainWindow::emitForceClose() const noexcept {
284+
emit m_shell->forceQuit();
285+
}
283286

284287
void MainWindow::closeEvent(QCloseEvent *ev)
285288
{

src/gui/mainwindow.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ class MainWindow: public QMainWindow
2929
void restoreWindowGeometry();
3030

3131
bool active() const noexcept { return m_isActive; }
32+
bool isClosing() const noexcept { return m_inCloseEvent; }
33+
void emitForceClose() const noexcept;
3234

3335
signals:
3436
void neovimAttachmentChanged(bool);

src/gui/shell.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,6 +1711,10 @@ void Shell::closeEvent(QCloseEvent *ev)
17111711
// Try to wait for neovim to quit
17121712
QEventLoop loop;
17131713
connect(m_nvim, &NeovimConnector::processExited, &loop, &QEventLoop::quit);
1714+
connect(this, &Shell::forceQuit, &loop, [this] {
1715+
bailoutIfinputBlocking();
1716+
m_nvim->api0()->vim_command("q!");
1717+
});
17141718
MsgpackRequest * request = m_nvim->api0()->vim_command("confirm qa");
17151719
connect(request, &MsgpackRequest::finished, &loop, [&loop, ev](){
17161720
//This will fire if we cancel the closing

src/gui/shell.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ class Shell: public ShellWidget
9494
void setGuiAdaptiveStyle(const QString& styleName);
9595
void showGuiAdaptiveStyleList();
9696

97+
void forceQuit();
98+
9799
public slots:
98100
void handleNeovimNotification(const QByteArray &name, const QVariantList& args);
99101
void resizeNeovim(const QSize&);

0 commit comments

Comments
 (0)