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.
This commit is contained in:
Havoc Pennington 2002-11-20 04:54:01 +00:00 committed by Havoc Pennington
parent 60293ee189
commit b8788e9c0d
3 changed files with 36 additions and 7 deletions

View File

@ -1,3 +1,14 @@
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.
2002-11-19 Havoc Pennington <hp@pobox.com>
* src/window.c (meta_window_client_message): do a

View File

@ -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;
}
}

View File

@ -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))
{