Index: src/display.c
===================================================================
RCS file: /cvs/gnome/metacity/src/display.c,v
retrieving revision 1.258
diff -p -u -r1.258 display.c
--- src/display.c	11 Jul 2005 13:25:08 -0000	1.258
+++ src/display.c	3 Oct 2005 18:05:16 -0000
@@ -122,20 +122,6 @@ static void    sanity_check_timestamps  
                                           Time         known_good_timestamp);
 
 static void
-set_utf8_string_hint (MetaDisplay *display,
-                      Window xwindow,
-                      Atom atom,
-                      const char *val)
-{
-  meta_error_trap_push (display);
-  XChangeProperty (display->xdisplay, 
-                   xwindow, atom,
-                   display->atom_utf8_string, 
-                   8, PropModeReplace, (guchar*) val, strlen (val));
-  meta_error_trap_pop (display, FALSE);
-}
-
-static void
 ping_data_free (MetaPingData *ping_data)
 {
   /* Remove the timeout */
@@ -302,7 +288,9 @@ meta_display_open (const char *name)
     "_NET_MOVERESIZE_WINDOW",
     "_NET_DESKTOP_GEOMETRY",
     "_NET_DESKTOP_VIEWPORT",
-    "_METACITY_VERSION"
+    "_METACITY_VERSION",
+    "_NET_WM_VISIBLE_NAME",
+    "_NET_WM_VISIBLE_ICON_NAME"
   };
   Atom atoms[G_N_ELEMENTS(atom_names)];
   
@@ -460,6 +448,8 @@ meta_display_open (const char *name)
   display->atom_net_desktop_geometry = atoms[89];
   display->atom_net_desktop_viewport = atoms[90];
   display->atom_metacity_version = atoms[91];
+  display->atom_net_wm_visible_name = atoms[92];
+  display->atom_net_wm_visible_icon_name = atoms[93];
 
   display->prop_hooks = NULL;
   meta_display_init_window_prop_hooks (display);
@@ -637,15 +627,15 @@ meta_display_open (const char *name)
     display->leader_window = meta_create_offscreen_window (display->xdisplay,
                                                            DefaultRootWindow (display->xdisplay));                                                           
 
-    set_utf8_string_hint (display,
-                          display->leader_window,
-                          display->atom_net_wm_name,
-                          "Metacity");
+    meta_prop_set_utf8_string_hint (display,
+                                    display->leader_window,
+                                    display->atom_net_wm_name,
+                                    "Metacity");
     
-    set_utf8_string_hint (display,
-                          display->leader_window,
-                          display->atom_metacity_version,
-                          VERSION);
+    meta_prop_set_utf8_string_hint (display,
+                                    display->leader_window,
+                                    display->atom_metacity_version,
+                                    VERSION);
 
     data[0] = display->leader_window;
     XChangeProperty (display->xdisplay,
Index: src/display.h
===================================================================
RCS file: /cvs/gnome/metacity/src/display.h,v
retrieving revision 1.133
diff -p -u -r1.133 display.h
--- src/display.h	11 Jul 2005 13:25:08 -0000	1.133
+++ src/display.h	3 Oct 2005 18:05:16 -0000
@@ -183,6 +183,8 @@ struct _MetaDisplay
   Atom atom_net_desktop_geometry;
   Atom atom_net_desktop_viewport;
   Atom atom_metacity_version;
+  Atom atom_net_wm_visible_name;
+  Atom atom_net_wm_visible_icon_name;
 
   /* This is the actual window from focus events,
    * not the one we last set
Index: src/tabpopup.c
===================================================================
RCS file: /cvs/gnome/metacity/src/tabpopup.c,v
retrieving revision 1.34
diff -p -u -r1.34 tabpopup.c
--- src/tabpopup.c	3 Oct 2005 17:11:49 -0000	1.34
+++ src/tabpopup.c	3 Oct 2005 18:05:16 -0000
@@ -98,20 +98,6 @@ outline_window_expose (GtkWidget      *w
   return FALSE;
 }
 
-static char*
-utf8_strndup (const char *src,
-              int         n)
-{
-  const gchar *s = src;
-  while (n && *s)
-    {
-      s = g_utf8_next_char (s);
-      n--;
-    }
-
-  return g_strndup (src, s - src);
-}
-
 static GdkPixbuf*
 dimm_icon (GdkPixbuf *pixbuf)
 {
@@ -238,7 +224,7 @@ meta_ui_tab_popup_new (const MetaTabEntr
               tmp = markup;
             }
             
-          te->title = utf8_strndup (tmp, max_chars_per_title);
+          te->title = meta_g_utf8_strndup (tmp, max_chars_per_title);
           g_free (tmp);
         }
       te->widget = NULL;
Index: src/util.c
===================================================================
RCS file: /cvs/gnome/metacity/src/util.c,v
retrieving revision 1.35
diff -p -u -r1.35 util.c
--- src/util.c	16 Sep 2004 23:18:22 -0000	1.35
+++ src/util.c	3 Oct 2005 18:05:16 -0000
@@ -161,6 +161,20 @@ meta_set_replace_current_wm (gboolean se
   replace_current = setting;
 }
 
+char *
+meta_g_utf8_strndup (const gchar *src,
+                     gsize        n)
+{
+  const gchar *s = src;
+  while (n && *s)
+    {
+      s = g_utf8_next_char (s);
+      n--;
+    }
+
+  return g_strndup (src, s - src);
+}
+
 static int
 utf8_fputs (const char *str,
             FILE       *f)
Index: src/util.h
===================================================================
RCS file: /cvs/gnome/metacity/src/util.h,v
retrieving revision 1.25
diff -p -u -r1.25 util.h
--- src/util.h	26 Dec 2003 00:05:26 -0000	1.25
+++ src/util.h	3 Oct 2005 18:05:16 -0000
@@ -88,6 +88,7 @@ void meta_print_backtrace (void);
 #define _(x) dgettext (GETTEXT_PACKAGE, x)
 #define N_(x) x
 
+char* meta_g_utf8_strndup (const gchar *src, gsize n);
 
 /* To disable verbose mode, we make these functions into no-ops */
 #ifdef WITH_VERBOSE_MODE
Index: src/window-props.c
===================================================================
RCS file: /cvs/gnome/metacity/src/window-props.c,v
retrieving revision 1.19
diff -p -u -r1.19 window-props.c
--- src/window-props.c	20 Feb 2005 17:14:16 -0000	1.19
+++ src/window-props.c	3 Oct 2005 18:05:16 -0000
@@ -190,6 +190,8 @@ reload_net_wm_user_time (MetaWindow    *
     }
 }
 
+#define MAX_TITLE_LENGTH 512
+
 static void
 set_window_title (MetaWindow *window,
                   const char *title)
@@ -200,8 +202,16 @@ set_window_title (MetaWindow *window,
   
   if (title == NULL)
     window->title = g_strdup ("");
-  else
+  else if (g_utf8_strlen (title, MAX_TITLE_LENGTH + 1) <= MAX_TITLE_LENGTH)
     window->title = g_strdup (title);
+  else
+    {
+      window->title = meta_g_utf8_strndup (title, MAX_TITLE_LENGTH);
+      meta_prop_set_utf8_string_hint (window->display,
+                                      window->xwindow,
+                                      window->display->atom_net_wm_visible_name,
+                                      window->title);
+    }
   
   /* strndup is a hack since GNU libc has broken %.10s */
   str = g_strndup (window->title, 10);
@@ -285,8 +295,17 @@ set_icon_title (MetaWindow *window,
   
   if (title == NULL)
     window->icon_name = g_strdup ("");
-  else
+  else if (g_utf8_strlen (title, MAX_TITLE_LENGTH + 1) <= MAX_TITLE_LENGTH)
     window->icon_name = g_strdup (title);
+  else
+    {
+      window->icon_name = meta_g_utf8_strndup (title, MAX_TITLE_LENGTH);
+      meta_prop_set_utf8_string_hint (window->display,
+                                      window->xwindow,
+                                      window->display->atom_net_wm_visible_icon_name,
+                                      window->icon_name);
+    }
+
 }
 
 static void
Index: src/xprops.c
===================================================================
RCS file: /cvs/gnome/metacity/src/xprops.c,v
retrieving revision 1.22
diff -p -u -r1.22 xprops.c
--- src/xprops.c	11 Jun 2005 02:28:04 -0000	1.22
+++ src/xprops.c	3 Oct 2005 18:05:16 -0000
@@ -524,6 +524,20 @@ meta_prop_get_utf8_list (MetaDisplay   *
   return utf8_list_from_results (&results, str_p, n_str_p);
 }
 
+void
+meta_prop_set_utf8_string_hint (MetaDisplay *display,
+                                Window xwindow,
+                                Atom atom,
+                                const char *val)
+{
+  meta_error_trap_push (display);
+  XChangeProperty (display->xdisplay, 
+                   xwindow, atom,
+                   display->atom_utf8_string, 
+                   8, PropModeReplace, (guchar*) val, strlen (val));
+  meta_error_trap_pop (display, FALSE);
+}
+
 static gboolean
 window_from_results (GetPropertyResults *results,
                      Window             *window_p)
Index: src/xprops.h
===================================================================
RCS file: /cvs/gnome/metacity/src/xprops.h,v
retrieving revision 1.10
diff -p -u -r1.10 xprops.h
--- src/xprops.h	19 Jun 2004 00:45:24 -0000	1.10
+++ src/xprops.h	3 Oct 2005 18:05:16 -0000
@@ -95,6 +95,11 @@ gboolean meta_prop_get_utf8_list     (Me
                                       Atom           xatom,
                                       char        ***str_p,
                                       int           *n_str_p);
+void     meta_prop_set_utf8_string_hint
+                                     (MetaDisplay *display,
+                                      Window xwindow,
+                                      Atom atom,
+                                      const char *val);
 gboolean meta_prop_get_window        (MetaDisplay   *display,
                                       Window         xwindow,
                                       Atom           xatom,
