mirror of
https://github.com/brl/mutter.git
synced 2024-11-28 11:00:54 -05:00
Truncate ridiculously long titles to avoid crashing or letting the pager
2005-10-03 Elijah Newren <newren@gmail.com> Truncate ridiculously long titles to avoid crashing or letting the pager crash. Based on patch from Ray, incorporating suggestions from Havoc and some extensions of my own. Fixes #315070. * src/display.c (set_utf8_string_hint, meta_display_open): * src/xprops.[ch] (meta_prop_set_utf8_string_hint): Move set_utf8_string_hint() to props.[ch], namespace it ("meta_prop_"), and make it public * src/tabpopup.c (utf8_strndup, meta_ui_tab_popup_new): * src/util.[ch] (meta_g_utf8_strndup): Move utf8_strndup() to util.[ch], namespace it ("meta_g_"), and make it public * src/display.c (meta_display_open): * src/display.h (struct _MetaDisplay): add net_wm_visible_name and net_wm_visible_icon_name atoms to the list of atoms we work with * src/window-props.c (set_window_title, set_icon_title): If title length is greater than 512, truncate it and set _NET_WM_VISIBLE_NAME or _NET_WM_VISIBLE_ICON_NAME accordingly
This commit is contained in:
parent
fcba59e685
commit
ef5299ee92
25
ChangeLog
25
ChangeLog
@ -1,3 +1,28 @@
|
|||||||
|
2005-10-03 Elijah Newren <newren@gmail.com>
|
||||||
|
|
||||||
|
Truncate ridiculously long titles to avoid crashing or letting the
|
||||||
|
pager crash. Based on patch from Ray, incorporating suggestions
|
||||||
|
from Havoc and some extensions of my own. Fixes #315070.
|
||||||
|
|
||||||
|
* src/display.c (set_utf8_string_hint, meta_display_open):
|
||||||
|
* src/xprops.[ch] (meta_prop_set_utf8_string_hint):
|
||||||
|
Move set_utf8_string_hint() to props.[ch], namespace it
|
||||||
|
("meta_prop_"), and make it public
|
||||||
|
|
||||||
|
* src/tabpopup.c (utf8_strndup, meta_ui_tab_popup_new):
|
||||||
|
* src/util.[ch] (meta_g_utf8_strndup):
|
||||||
|
Move utf8_strndup() to util.[ch], namespace it ("meta_g_"), and
|
||||||
|
make it public
|
||||||
|
|
||||||
|
* src/display.c (meta_display_open):
|
||||||
|
* src/display.h (struct _MetaDisplay):
|
||||||
|
add net_wm_visible_name and net_wm_visible_icon_name atoms to the
|
||||||
|
list of atoms we work with
|
||||||
|
|
||||||
|
* src/window-props.c (set_window_title, set_icon_title): If title
|
||||||
|
length is greater than 512, truncate it and set
|
||||||
|
_NET_WM_VISIBLE_NAME or _NET_WM_VISIBLE_ICON_NAME accordingly
|
||||||
|
|
||||||
2005-10-03 Elijah Newren <newren@gmail.com>
|
2005-10-03 Elijah Newren <newren@gmail.com>
|
||||||
|
|
||||||
Get the tabbing window outline to work with gtk+ 2.8.4 again.
|
Get the tabbing window outline to work with gtk+ 2.8.4 again.
|
||||||
|
@ -121,20 +121,6 @@ static void prefs_changed_callback (MetaPreference pref,
|
|||||||
static void sanity_check_timestamps (MetaDisplay *display,
|
static void sanity_check_timestamps (MetaDisplay *display,
|
||||||
Time known_good_timestamp);
|
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
|
static void
|
||||||
ping_data_free (MetaPingData *ping_data)
|
ping_data_free (MetaPingData *ping_data)
|
||||||
{
|
{
|
||||||
@ -302,7 +288,9 @@ meta_display_open (const char *name)
|
|||||||
"_NET_MOVERESIZE_WINDOW",
|
"_NET_MOVERESIZE_WINDOW",
|
||||||
"_NET_DESKTOP_GEOMETRY",
|
"_NET_DESKTOP_GEOMETRY",
|
||||||
"_NET_DESKTOP_VIEWPORT",
|
"_NET_DESKTOP_VIEWPORT",
|
||||||
"_METACITY_VERSION"
|
"_METACITY_VERSION",
|
||||||
|
"_NET_WM_VISIBLE_NAME",
|
||||||
|
"_NET_WM_VISIBLE_ICON_NAME"
|
||||||
};
|
};
|
||||||
Atom atoms[G_N_ELEMENTS(atom_names)];
|
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_geometry = atoms[89];
|
||||||
display->atom_net_desktop_viewport = atoms[90];
|
display->atom_net_desktop_viewport = atoms[90];
|
||||||
display->atom_metacity_version = atoms[91];
|
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;
|
display->prop_hooks = NULL;
|
||||||
meta_display_init_window_prop_hooks (display);
|
meta_display_init_window_prop_hooks (display);
|
||||||
@ -637,12 +627,12 @@ meta_display_open (const char *name)
|
|||||||
display->leader_window = meta_create_offscreen_window (display->xdisplay,
|
display->leader_window = meta_create_offscreen_window (display->xdisplay,
|
||||||
DefaultRootWindow (display->xdisplay));
|
DefaultRootWindow (display->xdisplay));
|
||||||
|
|
||||||
set_utf8_string_hint (display,
|
meta_prop_set_utf8_string_hint (display,
|
||||||
display->leader_window,
|
display->leader_window,
|
||||||
display->atom_net_wm_name,
|
display->atom_net_wm_name,
|
||||||
"Metacity");
|
"Metacity");
|
||||||
|
|
||||||
set_utf8_string_hint (display,
|
meta_prop_set_utf8_string_hint (display,
|
||||||
display->leader_window,
|
display->leader_window,
|
||||||
display->atom_metacity_version,
|
display->atom_metacity_version,
|
||||||
VERSION);
|
VERSION);
|
||||||
|
@ -183,6 +183,8 @@ struct _MetaDisplay
|
|||||||
Atom atom_net_desktop_geometry;
|
Atom atom_net_desktop_geometry;
|
||||||
Atom atom_net_desktop_viewport;
|
Atom atom_net_desktop_viewport;
|
||||||
Atom atom_metacity_version;
|
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,
|
/* This is the actual window from focus events,
|
||||||
* not the one we last set
|
* not the one we last set
|
||||||
|
@ -98,20 +98,6 @@ outline_window_expose (GtkWidget *widget,
|
|||||||
return FALSE;
|
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*
|
static GdkPixbuf*
|
||||||
dimm_icon (GdkPixbuf *pixbuf)
|
dimm_icon (GdkPixbuf *pixbuf)
|
||||||
{
|
{
|
||||||
@ -238,7 +224,7 @@ meta_ui_tab_popup_new (const MetaTabEntry *entries,
|
|||||||
tmp = markup;
|
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);
|
g_free (tmp);
|
||||||
}
|
}
|
||||||
te->widget = NULL;
|
te->widget = NULL;
|
||||||
|
14
src/util.c
14
src/util.c
@ -161,6 +161,20 @@ meta_set_replace_current_wm (gboolean setting)
|
|||||||
replace_current = setting;
|
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
|
static int
|
||||||
utf8_fputs (const char *str,
|
utf8_fputs (const char *str,
|
||||||
FILE *f)
|
FILE *f)
|
||||||
|
@ -88,6 +88,7 @@ void meta_print_backtrace (void);
|
|||||||
#define _(x) dgettext (GETTEXT_PACKAGE, x)
|
#define _(x) dgettext (GETTEXT_PACKAGE, x)
|
||||||
#define N_(x) 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 */
|
/* To disable verbose mode, we make these functions into no-ops */
|
||||||
#ifdef WITH_VERBOSE_MODE
|
#ifdef WITH_VERBOSE_MODE
|
||||||
|
@ -190,6 +190,8 @@ reload_net_wm_user_time (MetaWindow *window,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define MAX_TITLE_LENGTH 512
|
||||||
|
|
||||||
static void
|
static void
|
||||||
set_window_title (MetaWindow *window,
|
set_window_title (MetaWindow *window,
|
||||||
const char *title)
|
const char *title)
|
||||||
@ -200,8 +202,16 @@ set_window_title (MetaWindow *window,
|
|||||||
|
|
||||||
if (title == NULL)
|
if (title == NULL)
|
||||||
window->title = g_strdup ("");
|
window->title = g_strdup ("");
|
||||||
else
|
else if (g_utf8_strlen (title, MAX_TITLE_LENGTH + 1) <= MAX_TITLE_LENGTH)
|
||||||
window->title = g_strdup (title);
|
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 */
|
/* strndup is a hack since GNU libc has broken %.10s */
|
||||||
str = g_strndup (window->title, 10);
|
str = g_strndup (window->title, 10);
|
||||||
@ -285,8 +295,17 @@ set_icon_title (MetaWindow *window,
|
|||||||
|
|
||||||
if (title == NULL)
|
if (title == NULL)
|
||||||
window->icon_name = g_strdup ("");
|
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);
|
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
|
static void
|
||||||
|
14
src/xprops.c
14
src/xprops.c
@ -524,6 +524,20 @@ meta_prop_get_utf8_list (MetaDisplay *display,
|
|||||||
return utf8_list_from_results (&results, str_p, n_str_p);
|
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
|
static gboolean
|
||||||
window_from_results (GetPropertyResults *results,
|
window_from_results (GetPropertyResults *results,
|
||||||
Window *window_p)
|
Window *window_p)
|
||||||
|
@ -95,6 +95,11 @@ gboolean meta_prop_get_utf8_list (MetaDisplay *display,
|
|||||||
Atom xatom,
|
Atom xatom,
|
||||||
char ***str_p,
|
char ***str_p,
|
||||||
int *n_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,
|
gboolean meta_prop_get_window (MetaDisplay *display,
|
||||||
Window xwindow,
|
Window xwindow,
|
||||||
Atom xatom,
|
Atom xatom,
|
||||||
|
Loading…
Reference in New Issue
Block a user