Skip to content

Commit

Permalink
Merge pull request #1453 from contour-terminal/fix/dead_lock
Browse files Browse the repository at this point in the history
Fix dead lock of terminal
  • Loading branch information
christianparpart authored Feb 4, 2024
2 parents bbcf80d + f222566 commit 7c60920
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 19 deletions.
2 changes: 1 addition & 1 deletion metainfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
<release version="0.4.3" urgency="medium" type="development">
<description>
<ul>
<li> ... </li>
<li>Fixes dead lock bug on mouse selection.</li>
</ul>
</description>
</release>
Expand Down
9 changes: 6 additions & 3 deletions src/contour/TerminalSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -954,17 +954,18 @@ bool TerminalSession::operator()(actions::ClearHistoryAndReset)

bool TerminalSession::operator()(actions::CopyPreviousMarkRange)
{
copyToClipboard(terminal().extractLastMarkRange());
crispy::locked(_terminal, [&]() { copyToClipboard(terminal().extractLastMarkRange()); });
return true;
}

bool TerminalSession::operator()(actions::CopySelection copySelection)
{

switch (copySelection.format)
{
case actions::CopyFormat::Text:
// Copy the selection in pure text, plus whitespaces and newline.
copyToClipboard(terminal().extractSelectionText());
crispy::locked(_terminal, [&]() { copyToClipboard(terminal().extractSelectionText()); });
break;
case actions::CopyFormat::HTML:
// TODO: This requires walking through each selected cell and construct HTML+CSS for it.
Expand Down Expand Up @@ -1098,7 +1099,9 @@ bool TerminalSession::operator()(actions::OpenFileManager)

bool TerminalSession::operator()(actions::OpenSelection)
{
QDesktopServices::openUrl(QUrl(QString::fromUtf8(terminal().extractSelectionText().c_str())));
crispy::locked(_terminal, [&]() {
QDesktopServices::openUrl(QUrl(QString::fromUtf8(terminal().extractSelectionText().c_str())));
});
return true;
}

Expand Down
4 changes: 0 additions & 4 deletions src/vtbackend/Terminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1253,8 +1253,6 @@ namespace

string Terminal::extractSelectionText() const
{
auto const _ = std::scoped_lock { *this };

if (!_selection || _selection->state() == Selection::State::Waiting)
return "";

Expand All @@ -1274,8 +1272,6 @@ string Terminal::extractSelectionText() const

string Terminal::extractLastMarkRange() const
{
auto const _ = std::lock_guard { *this };

// -1 because we always want to start extracting one line above the cursor by default.
auto const bottomLine =
_currentScreen->cursor().position.line + LineOffset(-1) + _settings.copyLastMarkRangeOffset;
Expand Down
13 changes: 2 additions & 11 deletions src/vtbackend/Terminal.h
Original file line number Diff line number Diff line change
Expand Up @@ -391,17 +391,9 @@ class Terminal
void updateInputMethodPreeditString(std::string preeditString);
// }}}

void lock() const
{
_outerLock.lock();
_innerLock.lock();
}
void lock() const { _outerLock.lock(); }

void unlock() const
{
_outerLock.unlock();
_innerLock.unlock();
}
void unlock() const { _outerLock.unlock(); }

[[nodiscard]] ColorPalette const& colorPalette() const noexcept { return _state.colorPalette; }
[[nodiscard]] ColorPalette& colorPalette() noexcept { return _state.colorPalette; }
Expand Down Expand Up @@ -810,7 +802,6 @@ class Terminal

// synchronization
std::mutex mutable _outerLock;
std::mutex mutable _innerLock;

// terminal clock
std::chrono::steady_clock::time_point _currentTime;
Expand Down

0 comments on commit 7c60920

Please sign in to comment.