diff options
author | Havoc Pennington <hp@pobox.com> | 2002-11-20 04:54:01 +0000 |
---|---|---|
committer | Havoc Pennington <hp@src.gnome.org> | 2002-11-20 04:54:01 +0000 |
commit | b8788e9c0d944a225ca56f1e45b50e583c5a4a28 (patch) | |
tree | b5acee617e4c45d11e85adba0667ac7e8d020823 /src | |
parent | 60293ee1892531e2876a1bddd3f355a976e381b3 (diff) | |
download | metacity-b8788e9c0d944a225ca56f1e45b50e583c5a4a28.tar.gz |
Should really fix #98303
2002-11-19 Havoc Pennington <hp@pobox.com>
Should really fix #98303
* src/prefs.c (meta_prefs_change_workspace_name): add
bad hack to treat empty string the same as null
* src/menu.c (get_workspace_name_with_accel): allocate one more
than the length of "name" so we have room for a nul byte (and
don't malloc(0) on empty strings). Also some formatting cleanups.
Diffstat (limited to 'src')
-rw-r--r-- | src/menu.c | 15 | ||||
-rw-r--r-- | src/prefs.c | 17 |
2 files changed, 25 insertions, 7 deletions
@@ -131,7 +131,7 @@ activate_cb (GtkWidget *menuitem, gpointer data) * The calling code owns the string, and is reponsible to free the * memory after use. */ -static char * +static char* get_workspace_name_with_accel (Display *display, Window xroot, int index) @@ -148,6 +148,7 @@ get_workspace_name_with_accel (Display *display, * integer, insert a '_' before the number if it is less than 10 and * return it */ + number = 0; if (sscanf (name, _("Workspace %d"), &number) == 1) { char *new_name; @@ -171,24 +172,24 @@ get_workspace_name_with_accel (Display *display, char *new_name; const char *source; char *dest; - source = name; + /* * Assume the worst case, that every character is a _ */ - dest = new_name = g_malloc0 (strlen (name) * 2); + new_name = g_malloc0 (strlen (name) * 2 + 1); + /* * Now iterate down the strings, adding '_' to escape as we go */ + dest = new_name; + source = name; while (*source != '\0') { if (*source == '_') *dest++ = '_'; *dest++ = *source++; } - /* - * We don't free *name as we don't own it, and pass ownership of - * *new_name to the calling code. - */ + return new_name; } } diff --git a/src/prefs.c b/src/prefs.c index 3b55ca3a..502506e0 100644 --- a/src/prefs.c +++ b/src/prefs.c @@ -1602,6 +1602,10 @@ meta_prefs_get_workspace_name (int i) g_return_val_if_fail (i >= 0 && i < MAX_REASONABLE_WORKSPACES, NULL); g_assert (workspace_names[i] != NULL); + + meta_topic (META_DEBUG_PREFS, + "Getting workspace name for %d: \"%s\"\n", + i, workspace_names[i]); return workspace_names[i]; } @@ -1615,6 +1619,19 @@ meta_prefs_change_workspace_name (int i, g_return_if_fail (i >= 0 && i < MAX_REASONABLE_WORKSPACES); + meta_topic (META_DEBUG_PREFS, + "Changing name of workspace %d to %s\n", + i, name ? name : "none"); + + /* This is a bad hack. We have to treat empty string as + * "unset" because the root window property can't contain + * null. So it gets empty string instead and we don't want + * that to result in setting the empty string as a value that + * overrides "unset". + */ + if (name && *name == '\0') + name = NULL; + if ((name == NULL && workspace_names[i] == NULL) || (name && workspace_names[i] && strcmp (name, workspace_names[i]) == 0)) { |