3d83284
--- mc-4.6.1a/src/main.c.userhost	2005-10-16 18:11:07.000000000 +0200
3d83284
+++ mc-4.6.1a/src/main.c	2005-10-16 18:14:26.000000000 +0200
3d83284
@@ -28,6 +28,7 @@
3d83284
 #include <stdio.h>
3d83284
 #include <stdlib.h>
3d83284
 #include <string.h>
556d3c0
+#include <pwd.h>
3d83284
 
3d83284
 #include <sys/types.h>
3d83284
 #include <sys/stat.h>
3d83284
@@ -1608,9 +1609,22 @@ void
e52ead9
 update_xterm_title_path (void)
e52ead9
 {
3d83284
     char *p, *s;
e52ead9
+    char h[64];
e52ead9
+    struct passwd *pw;
e52ead9
 
e52ead9
     if (xterm_flag && xterm_title) {
e52ead9
 	p = s = g_strdup (strip_home_and_password (current_panel->cwd));
3d83284
+	if ( !gethostname (h, 64) ) {
3d83284
+	    h[63] = '\0'; /* Be sure the hostname is NUL terminated */
3d83284
+	    s = g_strdup_printf ("%s:%s", h, s);
3d83284
+	    g_free (p);
3d83284
+	    p = s;
3d83284
+	}
3d83284
+	if ( (pw = getpwuid(getuid())) ) {
3d83284
+	    s = g_strdup_printf ("%s@%s", pw->pw_name, s);
3d83284
+	    g_free (p);
3d83284
+	    p = s;
3d83284
+	}
e52ead9
 	do {
65f3b0e
 #ifndef UTF8
3d83284
 	    if (!is_printable ((unsigned char) *s))
3d83284
--- mc-4.6.1a/src/main.h.viewfile	2005-09-05 04:10:48.000000000 +0200
3d83284
+++ mc-4.6.1a/src/main.h	2005-10-17 14:41:46.000000000 +0200
3d83284
@@ -67,6 +67,7 @@ extern int alternate_plus_minus;
3d83284
 extern int only_leading_plus_minus;
3d83284
 extern int output_starts_shell;
3d83284
 extern int midnight_shutdown;
3d83284
+extern char *xterm_title_str;
3d83284
 extern char cmd_buf [512];
3d83284
 extern const char *shell;
3d83284
 
3d83284
--- mc-4.6.1a/src/view.c.viewfile	2005-10-17 14:41:46.000000000 +0200
3d83284
+++ mc-4.6.1a/src/view.c	2005-10-17 15:11:54.000000000 +0200
3d83284
@@ -3344,6 +3344,11 @@ mc_internal_viewer (const char *command,
3d83284
     WButtonBar *bar;
3d83284
     Dlg_head *view_dlg;
3d83284
 
3d83284
+    if (xterm_flag && xterm_title && xterm_title_str) {
3d83284
+	fprintf (stdout, "\33]0;mc - %s/%s\7", xterm_title_str, file);
3d83284
+	fflush(stdout);
3d83284
+    }
3d83284
+
3d83284
     /* Create dialog and widgets, put them on the dialog */
3d83284
     view_dlg =
3d83284
 	create_dlg (0, 0, LINES, COLS, NULL, view_dialog_callback,
3d83284
@@ -3367,6 +3372,8 @@ mc_internal_viewer (const char *command,
3d83284
     }
3d83284
     destroy_dlg (view_dlg);
3d83284
 
3d83284
+    update_xterm_title_path();
3d83284
+
3d83284
     return succeeded;
3d83284
 }
3d83284
 
3d83284
--- mc-4.6.1a/src/main.c.viewfile	2005-10-17 14:41:46.000000000 +0200
3d83284
+++ mc-4.6.1a/src/main.c	2005-10-17 14:41:46.000000000 +0200
3d83284
@@ -270,6 +270,9 @@ int midnight_shutdown = 0;
3d83284
 /* The user's shell */
3d83284
 const char *shell = NULL;
3d83284
 
3d83284
+/* The xterm title */
3d83284
+char *xterm_title_str = NULL;
3d83284
+
3d83284
 /* mc_home: The home of MC */
3d83284
 char *mc_home = NULL;
3d83284
 
3d83284
@@ -1617,6 +1620,7 @@ update_xterm_title_path (void)
3d83284
     struct passwd *pw;
3d83284
 
3d83284
     if (xterm_flag && xterm_title) {
3d83284
+	if ( xterm_title_str ) g_free (xterm_title_str);
3d83284
 	p = s = g_strdup (strip_home_and_password (current_panel->cwd));
3d83284
 	if ( !gethostname (h, 64) ) {
3d83284
 	    h[63] = '\0'; /* Be sure the hostname is NUL terminated */
3d83284
@@ -1639,7 +1643,7 @@ update_xterm_title_path (void)
3d83284
 	} while (*++s);
3d83284
 	fprintf (stdout, "\33]0;mc - %s\7", p);
3d83284
 	fflush (stdout);
3d83284
-	g_free (p);
3d83284
+	xterm_title_str = p;
3d83284
     }
3d83284
 }
3d83284
 
3d83284
--- mc-4.6.1a/edit/editwidget.c.viewfile	2005-10-17 14:41:46.000000000 +0200
3d83284
+++ mc-4.6.1a/edit/editwidget.c	2005-10-17 14:41:46.000000000 +0200
3d83284
@@ -44,6 +44,9 @@
3d83284
 #include "../src/widget.h"	/* buttonbar_redraw() */
3d83284
 #include "../src/menu.h"	/* menubar_new() */
3d83284
 #include "../src/key.h"		/* is_idle() */
3d83284
+#include "../src/main.h"	/* xterm_title_str */
3d83284
+#include "../src/win.h"		/* xterm_flag */
3d83284
+#include "../src/layout.h"	/* xterm_title */
3d83284
 
3d83284
 WEdit *wedit;
3d83284
 struct WMenu *edit_menubar;
3d83284
@@ -184,6 +187,11 @@ edit_file (const char *_file, int line)
3d83284
     static int made_directory = 0;
3d83284
     Dlg_head *edit_dlg;
3d83284
     WButtonBar *edit_bar;
3d83284
+    
3d83284
+    if (xterm_flag && xterm_title && xterm_title_str) {
3d83284
+	fprintf (stdout, "\33]0;mc - %s/%s\7", xterm_title_str, _file);
3d83284
+	fflush(stdout);
3d83284
+    }
3d83284
 
3d83284
     if (!made_directory) {
3d83284
 	char *dir = concat_dir_and_file (home_dir, EDIT_DIR);
3d83284
@@ -219,6 +227,8 @@ edit_file (const char *_file, int line)
3d83284
     edit_done_menu (edit_menubar);		/* editmenu.c */
3d83284
 
3d83284
     destroy_dlg (edit_dlg);
3d83284
+    
3d83284
+    update_xterm_title_path();
3d83284
 
3d83284
     return 1;
3d83284
 }