Skip to content

Commit 7c60920

Browse files
Merge pull request #1453 from contour-terminal/fix/dead_lock
Fix dead lock of terminal
2 parents bbcf80d + f222566 commit 7c60920

File tree

4 files changed

+9
-19
lines changed

4 files changed

+9
-19
lines changed

metainfo.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
<release version="0.4.3" urgency="medium" type="development">
108108
<description>
109109
<ul>
110-
<li> ... </li>
110+
<li>Fixes dead lock bug on mouse selection.</li>
111111
</ul>
112112
</description>
113113
</release>

src/contour/TerminalSession.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -954,17 +954,18 @@ bool TerminalSession::operator()(actions::ClearHistoryAndReset)
954954

955955
bool TerminalSession::operator()(actions::CopyPreviousMarkRange)
956956
{
957-
copyToClipboard(terminal().extractLastMarkRange());
957+
crispy::locked(_terminal, [&]() { copyToClipboard(terminal().extractLastMarkRange()); });
958958
return true;
959959
}
960960

961961
bool TerminalSession::operator()(actions::CopySelection copySelection)
962962
{
963+
963964
switch (copySelection.format)
964965
{
965966
case actions::CopyFormat::Text:
966967
// Copy the selection in pure text, plus whitespaces and newline.
967-
copyToClipboard(terminal().extractSelectionText());
968+
crispy::locked(_terminal, [&]() { copyToClipboard(terminal().extractSelectionText()); });
968969
break;
969970
case actions::CopyFormat::HTML:
970971
// TODO: This requires walking through each selected cell and construct HTML+CSS for it.
@@ -1098,7 +1099,9 @@ bool TerminalSession::operator()(actions::OpenFileManager)
10981099

10991100
bool TerminalSession::operator()(actions::OpenSelection)
11001101
{
1101-
QDesktopServices::openUrl(QUrl(QString::fromUtf8(terminal().extractSelectionText().c_str())));
1102+
crispy::locked(_terminal, [&]() {
1103+
QDesktopServices::openUrl(QUrl(QString::fromUtf8(terminal().extractSelectionText().c_str())));
1104+
});
11021105
return true;
11031106
}
11041107

src/vtbackend/Terminal.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,8 +1253,6 @@ namespace
12531253

12541254
string Terminal::extractSelectionText() const
12551255
{
1256-
auto const _ = std::scoped_lock { *this };
1257-
12581256
if (!_selection || _selection->state() == Selection::State::Waiting)
12591257
return "";
12601258

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

12751273
string Terminal::extractLastMarkRange() const
12761274
{
1277-
auto const _ = std::lock_guard { *this };
1278-
12791275
// -1 because we always want to start extracting one line above the cursor by default.
12801276
auto const bottomLine =
12811277
_currentScreen->cursor().position.line + LineOffset(-1) + _settings.copyLastMarkRangeOffset;

src/vtbackend/Terminal.h

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -391,17 +391,9 @@ class Terminal
391391
void updateInputMethodPreeditString(std::string preeditString);
392392
// }}}
393393

394-
void lock() const
395-
{
396-
_outerLock.lock();
397-
_innerLock.lock();
398-
}
394+
void lock() const { _outerLock.lock(); }
399395

400-
void unlock() const
401-
{
402-
_outerLock.unlock();
403-
_innerLock.unlock();
404-
}
396+
void unlock() const { _outerLock.unlock(); }
405397

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

811803
// synchronization
812804
std::mutex mutable _outerLock;
813-
std::mutex mutable _innerLock;
814805

815806
// terminal clock
816807
std::chrono::steady_clock::time_point _currentTime;

0 commit comments

Comments
 (0)