Skip to content

Commit e922128

Browse files
committed
Support duplicate clipboard updates
Instead of using the contents of the clipboard to determine if the user has copied any text, use a sequence number that is updated whenever text is copied. Consider the following scenario (as described in #1090): 1. User copies text 'abc' on remote machine via mosh. 2. User copies text 'xyz' on local machine. 3. User copies text 'abc' on remote machine again. The local clipboard will still has 'xyz' because the most recent copy text 'abc' matches the last text copied via mosh, so it does not detect that the user copied new text and does not update the local clipboard. This patch updates detection of newly copied text via a sequence number. This number is an 8-bit unsigned integer that is updated every time new text is copied. This will roll over after 256 clipboard updates, but that is fine as we only care about it being different than the last value. Fixes #1090. Fixes #637.
1 parent 3c23372 commit e922128

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

src/terminal/terminaldisplay.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ std::string Display::new_frame( bool initialized, const Framebuffer &last, const
111111
}
112112

113113
/* has clipboard changed? */
114-
if (f.get_clipboard() != frame.last_frame.get_clipboard()) {
114+
if (f.get_clipboard_seqnum() != frame.last_frame.get_clipboard_seqnum()) {
115115
frame.append( "\033]52;" );
116116
const title_type &clipboard( f.get_clipboard() );
117117
for ( title_type::const_iterator i = clipboard.begin();

src/terminal/terminalframebuffer.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ DrawState::DrawState( int s_width, int s_height )
7878
}
7979

8080
Framebuffer::Framebuffer( int s_width, int s_height )
81-
: rows(), icon_name(), window_title(), clipboard(), bell_count( 0 ), title_initialized( false ), ds( s_width, s_height )
81+
: rows(), icon_name(), window_title(), clipboard(), bell_count( 0 ),
82+
title_initialized( false ), clipboard_seqnum( 0 ), ds( s_width, s_height )
8283
{
8384
assert( s_height > 0 );
8485
assert( s_width > 0 );
@@ -90,7 +91,7 @@ Framebuffer::Framebuffer( int s_width, int s_height )
9091
Framebuffer::Framebuffer( const Framebuffer &other )
9192
: rows( other.rows ), icon_name( other.icon_name ), window_title( other.window_title ),
9293
clipboard( other.clipboard ), bell_count( other.bell_count ),
93-
title_initialized( other.title_initialized ), ds( other.ds )
94+
title_initialized( other.title_initialized ), clipboard_seqnum( other.clipboard_seqnum ), ds( other.ds )
9495
{
9596
}
9697

@@ -103,6 +104,7 @@ Framebuffer & Framebuffer::operator=( const Framebuffer &other )
103104
clipboard = other.clipboard;
104105
bell_count = other.bell_count;
105106
title_initialized = other.title_initialized;
107+
clipboard_seqnum = other.clipboard_seqnum;
106108
ds = other.ds;
107109
}
108110
return *this;
@@ -384,6 +386,7 @@ void Framebuffer::reset( void )
384386
rows = rows_type( height, newrow() );
385387
window_title.clear();
386388
clipboard.clear();
389+
clipboard_seqnum = 0;
387390
/* do not reset bell_count */
388391
}
389392

src/terminal/terminalframebuffer.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ namespace Terminal {
382382
title_type clipboard;
383383
unsigned int bell_count;
384384
bool title_initialized; /* true if the window title has been set via an OSC */
385+
uint8_t clipboard_seqnum;
385386

386387
row_pointer newrow( void )
387388
{
@@ -452,7 +453,13 @@ namespace Terminal {
452453
bool is_title_initialized( void ) const { return title_initialized; }
453454
void set_icon_name( const title_type &s ) { icon_name = s; }
454455
void set_window_title( const title_type &s ) { window_title = s; }
455-
void set_clipboard( const title_type &s ) { clipboard = s; }
456+
void set_clipboard( const title_type &s )
457+
{
458+
clipboard = s;
459+
// Rolling over 255 -> 0 is okay
460+
clipboard_seqnum++;
461+
}
462+
uint8_t get_clipboard_seqnum ( void ) const { return clipboard_seqnum; }
456463
const title_type & get_icon_name( void ) const { return icon_name; }
457464
const title_type & get_window_title( void ) const { return window_title; }
458465
const title_type & get_clipboard( void ) const { return clipboard; }
@@ -469,7 +476,7 @@ namespace Terminal {
469476

470477
bool operator==( const Framebuffer &x ) const
471478
{
472-
return ( rows == x.rows ) && ( window_title == x.window_title ) && ( clipboard == x.clipboard ) && ( bell_count == x.bell_count ) && ( ds == x.ds );
479+
return ( rows == x.rows ) && ( window_title == x.window_title ) && ( clipboard == x.clipboard ) && ( clipboard_seqnum == x.clipboard_seqnum ) && ( bell_count == x.bell_count ) && ( ds == x.ds );
473480
}
474481
};
475482
}

0 commit comments

Comments
 (0)