Rocco Rutte:
authorpdmef <pdmef@e385b8ad-14ed-0310-8656-cc95a2468c6d>
Sun, 24 Jul 2005 10:40:17 +0000 (10:40 +0000)
committerpdmef <pdmef@e385b8ad-14ed-0310-8656-cc95a2468c6d>
Sun, 24 Jul 2005 10:40:17 +0000 (10:40 +0000)
- 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
UPGRADING
curs_main.c
doc/manual.txt
globals.h
init.h
main.c
xterm.c [new file with mode: 0644]
xterm.h [new file with mode: 0644]

index 319c23e..3b080f1 100644 (file)
@@ -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)
index 96a4970..831b0ea 100644 (file)
--- 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.
 
index c9ec57f..1f2c605 100644 (file)
@@ -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);
         }
       }
 
index e6b7aa8..57c2574 100644 (file)
        This variable, when _\bs_\be_\bt, makes the thread tree narrower, allowing deeper
        threads to fit on the screen.
 
-       _\b6_\b._\b3_\b._\b1_\b4_\b3  _\bn_\bn_\bt_\bp_\b__\ba_\bs_\bk_\b__\bf_\bo_\bl_\bl_\bo_\bw_\b__\bu_\bp
+       _\b6_\b._\b3_\b._\b1_\b4_\b3  _\bn_\bn_\bt_\bp_\b__\ba_\bs_\bk_\b__\bf_\bo_\bl_\bl_\bo_\bw_\bu_\bp_\b__\bt_\bo
 
        Type: boolean
 
        Default: 'M%?n?AIL&ail?'
 
        Controls the format of the X11 icon title, as long as _\b$_\bx_\bt_\be_\br_\bm_\b__\bs_\be_\bt_\b__\bt_\bi_\bt_\bl_\be_\bs (sec-
-       tion 6.3.336  , page 146) is _\bs_\be_\bt. This string is identical in formatting to the
+       tion 6.3.337  , page 146) is _\bs_\be_\bt. This string is identical in formatting to the
        one used by ``_\b$_\bs_\bt_\ba_\bt_\bu_\bs_\b__\bf_\bo_\br_\bm_\ba_\bt (section 6.3.302  , page 137)''.
 
-       _\b6_\b._\b3_\b._\b3_\b3_\b6  _\bx_\bt_\be_\br_\bm_\b__\bs_\be_\bt_\b__\bt_\bi_\bt_\bl_\be_\bs
+       _\b6_\b._\b3_\b._\b3_\b3_\b6  _\bx_\bt_\be_\br_\bm_\b__\bl_\be_\ba_\bv_\be
+
+       Type: string
+
+       Default: ''
+
+       If _\b$_\bx_\bt_\be_\br_\bm_\b__\bs_\be_\bt_\b__\bt_\bi_\bt_\bl_\be_\bs (section 6.3.337  , page 146) is _\bs_\be_\bt, 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_\bD_\bI_\bS_\bP_\bL_\bA_\bY (section , page ) != x && xprop -id _\bW_\bI_\bN_\bD_\bO_\bW_\bI_\bD (section , page ) | grep
+       WM_NAME | cut -d ''' -f 2`'
+
+       _\b6_\b._\b3_\b._\b3_\b3_\b7  _\bx_\bt_\be_\br_\bm_\b__\bs_\be_\bt_\b__\bt_\bi_\bt_\bl_\be_\bs
 
        Type: boolean
 
        you're in an appropriate terminal). The default must be _\bu_\bn_\bs_\be_\bt to force in the
        validity checking.
 
-       _\b6_\b._\b3_\b._\b3_\b3_\b7  _\bx_\bt_\be_\br_\bm_\b__\bt_\bi_\bt_\bl_\be
-
-       The Mutt-ng E-Mail Client                                                   148
+       _\b6_\b._\b3_\b._\b3_\b3_\b8  _\bx_\bt_\be_\br_\bm_\b__\bt_\bi_\bt_\bl_\be
 
        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
-       _\b$_\bx_\bt_\be_\br_\bm_\b__\bs_\be_\bt_\b__\bt_\bi_\bt_\bl_\be_\bs (section 6.3.336  , page 146) has been _\bs_\be_\bt. This string is
+       _\b$_\bx_\bt_\be_\br_\bm_\b__\bs_\be_\bt_\b__\bt_\bi_\bt_\bl_\be_\bs (section 6.3.337  , page 146) has been _\bs_\be_\bt. This string is
        identical in formatting to the one used by ``_\b$_\bs_\bt_\ba_\bt_\bu_\bs_\b__\bf_\bo_\br_\bm_\ba_\bt (section 6.3.302  ,
        page 137)''.
 
        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
             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
 
        _\b6_\b._\b4_\b._\b2  _\bi_\bn_\bd_\be_\bx
index 1245487..850e5aa 100644 (file)
--- 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 (file)
--- 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 (file)
--- 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 (file)
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 <stdio.h>
+#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 (file)
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 */