From c390ee9b80e6b3f800718e586d472cd03aac64cd Mon Sep 17 00:00:00 2001 From: Keegan McAllister Date: Mon, 16 Apr 2012 00:17:53 -0400 Subject: [PATCH] Hardcode the terminals which accept "set window title" terminfo does not have reliable information on this, so we hardcode a whitelist of terminal type prefixes. This is the list from Debian's default screenrc, plus "screen" itself (which also covers tmux). Closes #172. Closes #191. --- src/terminal/terminaldisplay.cc | 7 ++++--- src/terminal/terminaldisplay.h | 2 ++ src/terminal/terminaldisplayinit.cc | 26 +++++++++++++++++++++++++- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/terminal/terminaldisplay.cc b/src/terminal/terminaldisplay.cc index 42bd39f..468c425 100644 --- a/src/terminal/terminaldisplay.cc +++ b/src/terminal/terminaldisplay.cc @@ -42,9 +42,10 @@ std::string Display::new_frame( bool initialized, const Framebuffer &last, const } /* has icon name or window title changed? */ - if ( (!initialized) - || (f.get_icon_name() != frame.last_frame.get_icon_name()) - || (f.get_window_title() != frame.last_frame.get_window_title()) ) { + if ( has_title && + ( (!initialized) + || (f.get_icon_name() != frame.last_frame.get_icon_name()) + || (f.get_window_title() != frame.last_frame.get_window_title()) ) ) { /* set icon name and window title */ if ( f.get_icon_name() == f.get_window_title() ) { /* write combined Icon Name and Window Title */ diff --git a/src/terminal/terminaldisplay.h b/src/terminal/terminaldisplay.h index f0944e6..a3441a0 100644 --- a/src/terminal/terminaldisplay.h +++ b/src/terminal/terminaldisplay.h @@ -56,6 +56,8 @@ namespace Terminal { bool has_bce; /* erases result in cell filled with background color */ + bool has_title; /* supports window title and icon name */ + int posterize_colors; /* downsample input colors >8 to [0..7] */ void put_cell( bool initialized, FrameState &frame, const Framebuffer &f ) const; diff --git a/src/terminal/terminaldisplayinit.cc b/src/terminal/terminaldisplayinit.cc index e61350a..d310774 100644 --- a/src/terminal/terminaldisplayinit.cc +++ b/src/terminal/terminaldisplayinit.cc @@ -25,11 +25,13 @@ #include #include +#include +#include using namespace Terminal; Display::Display( bool use_environment ) - : has_ech( true ), has_bce( true ), posterize_colors( false ) + : has_ech( true ), has_bce( true ), has_title( true ), posterize_colors( false ) { if ( use_environment ) { int errret = -2; @@ -70,6 +72,28 @@ Display::Display( bool use_environment ) has_bce = false; } + /* Check if we can set the window title and icon name. terminfo does not + have reliable information on this, so we hardcode a whitelist of + terminal type prefixes. This is the list from Debian's default + screenrc, plus "screen" itself (which also covers tmux). */ + static const char * const title_term_types[] = { + "xterm", "rxvt", "kterm", "Eterm", "screen" + }; + + has_title = false; + const char *term_type = getenv( "TERM" ); + if ( term_type ) { + for ( size_t i = 0; + i < sizeof( title_term_types ) / sizeof( const char * ); + i++ ) { + if ( 0 == strncmp( term_type, title_term_types[ i ], + strlen( title_term_types[ i ] ) ) ) { + has_title = true; + break; + } + } + } + /* posterization disabled because server now only advertises xterm-256color when client has colors = 256 */ /*