From dc2c2ef1ba4d0a0f3c2552459b9f962594a3536b Mon Sep 17 00:00:00 2001 From: pdmef Date: Sun, 24 Jul 2005 10:40:17 +0000 Subject: [PATCH] Rocco Rutte: - implement feature request #1135 by addind $xterm_leave with some working example in The Fine Manual git-svn-id: svn://svn.berlios.de/mutt-ng/trunk@337 e385b8ad-14ed-0310-8656-cc95a2468c6d --- Makefile.am | 3 ++- UPGRADING | 2 ++ curs_main.c | 21 +++------------------ doc/manual.txt | 35 +++++++++++++++++++++++++---------- globals.h | 1 + init.h | 14 ++++++++++++++ main.c | 7 ++++--- xterm.c | 22 ++++++++++++++++++++++ xterm.h | 15 +++++++++++++++ 9 files changed, 88 insertions(+), 32 deletions(-) create mode 100644 xterm.c create mode 100644 xterm.h diff --git a/Makefile.am b/Makefile.am index 319c23e..3b080f1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -38,7 +38,8 @@ muttng_SOURCES = $(BUILT_SOURCES) \ score.c send.c sendlib.c signal.c sort.c \ status.c system.c thread.c charset.c history.c lib.c \ muttlib.c editmsg.c utf8.c mbyte.c wcwidth.c md5c.c \ - url.c ascii.c mutt_idna.c sidebar.c hcache.c crypt-mod.c crypt-mod.h + url.c ascii.c mutt_idna.c sidebar.c hcache.c crypt-mod.c crypt-mod.h \ + xterm.c muttng_LDADD = @MUTT_LIB_OBJECTS@ @LIBOBJS@ $(LIBIMAP) $(LIBPOP) $(LIBNNTP) \ -Llib -lsane $(MUTTLIBS) $(INTLLIBS) $(LIBICONV) diff --git a/UPGRADING b/UPGRADING index 96a4970..831b0ea 100644 --- a/UPGRADING +++ b/UPGRADING @@ -12,6 +12,8 @@ sources of information. 2005-24-07: + The $xterm_leave option has been added. + The '^' shortcut pointing to the current folder is no longer only available in muttng as it has been integrated into mutt, too. diff --git a/curs_main.c b/curs_main.c index c9ec57f..1f2c605 100644 --- a/curs_main.c +++ b/curs_main.c @@ -23,6 +23,7 @@ #include "buffy.h" #include "mx.h" #include "sidebar.h" +#include "xterm.h" #ifdef USE_POP #include "pop.h" @@ -100,22 +101,6 @@ static const char *No_visible = N_("No visible messages."); extern const char *ReleaseDate; extern size_t UngetCount; -static void set_xterm_title_bar (char *title) -{ - fputs ("\033]2;", stdout); - fputs (title, stdout); - fputs ("\007", stdout); - fflush (stdout); -} - -static void set_xterm_icon_name (char *name) -{ - fputs ("\033]1;", stdout); - fputs (name, stdout); - fputs ("\007", stdout); - fflush (stdout); -} - void index_make_entry (char *s, size_t l, MUTTMENU * menu, int num) { format_flag flag = @@ -578,9 +563,9 @@ int mutt_index_menu (void) menu->redraw &= ~REDRAW_STATUS; if (option (OPTXTERMSETTITLES)) { menu_status_line (buf, sizeof (buf), menu, NONULL (XtermTitle)); - set_xterm_title_bar (buf); + mutt_xterm_set_title (buf); menu_status_line (buf, sizeof (buf), menu, NONULL (XtermIcon)); - set_xterm_icon_name (buf); + mutt_xterm_set_icon (buf); } } diff --git a/doc/manual.txt b/doc/manual.txt index e6b7aa8..57c2574 100644 --- a/doc/manual.txt +++ b/doc/manual.txt @@ -5458,7 +5458,7 @@ This variable, when _s_e_t, makes the thread tree narrower, allowing deeper threads to fit on the screen. - _6_._3_._1_4_3 _n_n_t_p___a_s_k___f_o_l_l_o_w___u_p + _6_._3_._1_4_3 _n_n_t_p___a_s_k___f_o_l_l_o_w_u_p___t_o Type: boolean @@ -8060,10 +8060,28 @@ Default: 'M%?n?AIL&ail?' Controls the format of the X11 icon title, as long as _$_x_t_e_r_m___s_e_t___t_i_t_l_e_s (sec- - tion 6.3.336 , page 146) is _s_e_t. This string is identical in formatting to the + tion 6.3.337 , page 146) is _s_e_t. This string is identical in formatting to the one used by ``_$_s_t_a_t_u_s___f_o_r_m_a_t (section 6.3.302 , page 137)''. - _6_._3_._3_3_6 _x_t_e_r_m___s_e_t___t_i_t_l_e_s + _6_._3_._3_3_6 _x_t_e_r_m___l_e_a_v_e + + Type: string + + Default: '' + + If _$_x_t_e_r_m___s_e_t___t_i_t_l_e_s (section 6.3.337 , page 146) is _s_e_t, this string will be + used to set the title when leaving mutt-ng. For terminal-based programs, + there's no easy and portable way to read the current title so mutt-ng cannot + read it upon startup and restore it when exiting. + + Based on the xterm FAQ, the following might work: set xterm_leave = '`test + + The Mutt-ng E-Mail Client 148 + + x_D_I_S_P_L_A_Y (section , page ) != x && xprop -id _W_I_N_D_O_W_I_D (section , page ) | grep + WM_NAME | cut -d ''' -f 2`' + + _6_._3_._3_3_7 _x_t_e_r_m___s_e_t___t_i_t_l_e_s Type: boolean @@ -8073,16 +8091,14 @@ you're in an appropriate terminal). The default must be _u_n_s_e_t to force in the validity checking. - _6_._3_._3_3_7 _x_t_e_r_m___t_i_t_l_e - - The Mutt-ng E-Mail Client 148 + _6_._3_._3_3_8 _x_t_e_r_m___t_i_t_l_e Type: string Default: 'Mutt-ng with %?m?%m messages&no messages?%?n? [%n New]?' Controls the format of the title bar of the xterm provided that - _$_x_t_e_r_m___s_e_t___t_i_t_l_e_s (section 6.3.336 , page 146) has been _s_e_t. This string is + _$_x_t_e_r_m___s_e_t___t_i_t_l_e_s (section 6.3.337 , page 146) has been _s_e_t. This string is identical in formatting to the one used by ``_$_s_t_a_t_u_s___f_o_r_m_a_t (section 6.3.302 , page 137)''. @@ -8100,6 +8116,8 @@ tings for this menu will affect the default bindings for all menus (except as noted). + The Mutt-ng E-Mail Client 149 + bottom-page L move to the bottom of the page current-bottom not bound move current entry to bottom of page current-middle not bound move current entry to middle of page @@ -8130,9 +8148,6 @@ tag-prefix ; apply next command to tagged entries tag-prefix-cond not bound apply next function ONLY to tagged messages top-page H move to the top of the page - - The Mutt-ng E-Mail Client 149 - what-key not bound display the keycode for a key press _6_._4_._2 _i_n_d_e_x diff --git a/globals.h b/globals.h index 1245487..850e5aa 100644 --- a/globals.h +++ b/globals.h @@ -169,6 +169,7 @@ WHERE char *TrashPath; WHERE char *Username; WHERE char *Visual; WHERE char *XtermTitle; +WHERE char *XtermLeave; WHERE char *XtermIcon; WHERE char *CurrentFolder; diff --git a/init.h b/init.h index 2befb51..1ce0224 100644 --- a/init.h +++ b/init.h @@ -3578,6 +3578,20 @@ struct option_t MuttVars[] = { ** (as long as you're in an appropriate terminal). The default must ** be \fIunset\fP to force in the validity checking. */ + {"xterm_leave", DT_STR, R_BOTH, UL &XtermLeave, UL "" }, + /* + ** .pp + ** If $$xterm_set_titles is \fIset\fP, this string will be used to + ** set the title when leaving mutt-ng. For terminal-based programs, + ** there's no easy and portable way to read the current title so mutt-ng + ** cannot read it upon startup and restore it when exiting. + ** + ** .pp + ** Based on the xterm FAQ, the following might work: + ** + ** .pp + ** \fTset xterm_leave = "`test x$DISPLAY != x && xprop -id $WINDOWID | grep WM_NAME | cut -d '"' -f 2`"\fT + */ {"xterm_title", DT_STR, R_BOTH, UL &XtermTitle, UL "Mutt-ng with %?m?%m messages&no messages?%?n? [%n New]?"}, /* ** .pp diff --git a/main.c b/main.c index 659d764..2c4a49d 100644 --- a/main.c +++ b/main.c @@ -25,6 +25,7 @@ #include "url.h" #include "mutt_crypt.h" #include "mutt_idna.h" +#include "xterm.h" #include "lib/mem.h" #include "lib/intl.h" @@ -501,13 +502,11 @@ int main (int argc, char **argv) int version = 0; int i; int explicit_folder = 0; - long sek; extern char *optarg; extern int optind; /* initialize random number for tmp file creation */ - time (&sek); - srand (sek); + srand ((unsigned int) time (NULL)); /* sanity check against stupid administrators */ @@ -938,6 +937,8 @@ int main (int argc, char **argv) M_READONLY : 0, NULL)) || !explicit_folder) { mutt_index_menu (); + if (option (OPTXTERMSETTITLES)) + mutt_xterm_set_title (NONULL (XtermLeave)); if (Context) FREE (&Context); } diff --git a/xterm.c b/xterm.c new file mode 100644 index 0000000..1b2d852 --- /dev/null +++ b/xterm.c @@ -0,0 +1,22 @@ +/* + * This file is part of mutt-ng, see http://www.muttng.org/. + * It's licensed under the GNU General Public License, + * please see the file GPL in the top level source directory. + */ +#include +#include "xterm.h" +#include "lib/str.h" + +void mutt_xterm_set_title (char *title) { + fputs ("\033]2;", stdout); + fputs (NONULL (title), stdout); + fputs ("\007", stdout); + fflush (stdout); +} + +void mutt_xterm_set_icon (char *name) { + fputs ("\033]1;", stdout); + fputs (NONULL (name), stdout); + fputs ("\007", stdout); + fflush (stdout); +} diff --git a/xterm.h b/xterm.h new file mode 100644 index 0000000..62a8d7f --- /dev/null +++ b/xterm.h @@ -0,0 +1,15 @@ +/* + * This file is part of mutt-ng, see http://www.muttng.org/. + * It's licensed under the GNU General Public License, + * please see the file GPL in the top level source directory. + */ +#ifndef MUTT_XTERM_H +#define MUTT_XTERM_H + +/* sets the current xterm's title */ +void mutt_xterm_set_title (char *title); + +/* sets the current xterm's icon */ +void mutt_xterm_set_icon (char *name); + +#endif /* !MUTT_XTERM_H */ -- 2.20.1