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

Support additional OSC 52 clipboard types #1104

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions src/terminal/terminaldisplay.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ std::string Display::new_frame( bool initialized, const Framebuffer& last, const
}

/* has clipboard changed? */
if ( f.get_clipboard() != frame.last_frame.get_clipboard() ) {
frame.append( "\033]52;c;" );
if ( f.get_clipboard_seqnum() != frame.last_frame.get_clipboard_seqnum() ) {
frame.append( "\033]52;" );
const title_type& clipboard( f.get_clipboard() );
for ( title_type::const_iterator i = clipboard.begin(); i != clipboard.end(); i++ ) {
frame.append( *i );
Expand Down
6 changes: 4 additions & 2 deletions src/terminal/terminalframebuffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ DrawState::DrawState( int s_width, int s_height )

Framebuffer::Framebuffer( int s_width, int s_height )
: rows(), icon_name(), window_title(), clipboard(), bell_count( 0 ), title_initialized( false ),
ds( s_width, s_height )
clipboard_seqnum( 0 ), ds( s_width, s_height )
{
assert( s_height > 0 );
assert( s_width > 0 );
Expand All @@ -85,7 +85,7 @@ Framebuffer::Framebuffer( int s_width, int s_height )
Framebuffer::Framebuffer( const Framebuffer& other )
: rows( other.rows ), icon_name( other.icon_name ), window_title( other.window_title ),
clipboard( other.clipboard ), bell_count( other.bell_count ), title_initialized( other.title_initialized ),
ds( other.ds )
clipboard_seqnum( other.clipboard_seqnum ), ds( other.ds )
{}

Framebuffer& Framebuffer::operator=( const Framebuffer& other )
Expand All @@ -97,6 +97,7 @@ Framebuffer& Framebuffer::operator=( const Framebuffer& other )
clipboard = other.clipboard;
bell_count = other.bell_count;
title_initialized = other.title_initialized;
clipboard_seqnum = other.clipboard_seqnum;
ds = other.ds;
}
return *this;
Expand Down Expand Up @@ -379,6 +380,7 @@ void Framebuffer::reset( void )
rows = rows_type( height, newrow() );
window_title.clear();
clipboard.clear();
clipboard_seqnum = 0;
/* do not reset bell_count */
}

Expand Down
11 changes: 9 additions & 2 deletions src/terminal/terminalframebuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ class Framebuffer
title_type clipboard;
unsigned int bell_count;
bool title_initialized; /* true if the window title has been set via an OSC */
uint8_t clipboard_seqnum;

row_pointer newrow( void )
{
Expand Down Expand Up @@ -461,7 +462,13 @@ class Framebuffer
bool is_title_initialized( void ) const { return title_initialized; }
void set_icon_name( const title_type& s ) { icon_name = s; }
void set_window_title( const title_type& s ) { window_title = s; }
void set_clipboard( const title_type& s ) { clipboard = s; }
void set_clipboard( const title_type& s )
{
clipboard = s;
// Rolling over 255 -> 0 is okay
clipboard_seqnum++;
}
uint8_t get_clipboard_seqnum ( void ) const { return clipboard_seqnum; }
const title_type& get_icon_name( void ) const { return icon_name; }
const title_type& get_window_title( void ) const { return window_title; }
const title_type& get_clipboard( void ) const { return clipboard; }
Expand All @@ -479,7 +486,7 @@ class Framebuffer
bool operator==( const Framebuffer& x ) const
{
return ( rows == x.rows ) && ( window_title == x.window_title ) && ( clipboard == x.clipboard )
&& ( bell_count == x.bell_count ) && ( ds == x.ds );
&& ( clipboard_seqnum == x.clipboard_seqnum ) && ( bell_count == x.bell_count ) && ( ds == x.ds );
}
};
}
Expand Down
11 changes: 7 additions & 4 deletions src/terminal/terminalfunctions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -591,10 +591,13 @@ static Function func_CSI_DECSTR( CSI, "!p", CSI_DECSTR );
/* xterm uses an Operating System Command to set the window title */
void Dispatcher::OSC_dispatch( const Parser::OSC_End* act __attribute( ( unused ) ), Framebuffer* fb )
{
/* handle osc copy clipboard sequence 52;c; */
if ( OSC_string.size() >= 5 && OSC_string[0] == L'5' && OSC_string[1] == L'2' && OSC_string[2] == L';'
&& OSC_string[3] == L'c' && OSC_string[4] == L';' ) {
Terminal::Framebuffer::title_type clipboard( OSC_string.begin() + 5, OSC_string.end() );
/* Handle OSC copy clipboard sequence 52;c; and variants */
if ( OSC_string.size() >= 5 && OSC_string[0] == L'5' && OSC_string[1] == L'2' && OSC_string[2] == L';') {
/* Capture the options and clipboard contents
e.g. '52;c;bW9zaCBpcyBncmVhdAo='
^^^^^^^^^^^^^^^^^^^^^^^
capture this part */
Terminal::Framebuffer::title_type clipboard( OSC_string.begin() + 3, OSC_string.end() );
fb->set_clipboard( clipboard );
/* handle osc terminal title sequence */
} else if ( OSC_string.size() >= 1 ) {
Expand Down