From 2541da1d8339b65d84f35f6a62bf8476670de1f8 Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Wed, 20 Nov 2002 03:57:20 +0000 Subject: [PATCH] Fix #98303 and assorted cleanup 2002-11-19 Havoc Pennington Fix #98303 and assorted cleanup * src/prefs.c (meta_preference_to_string): handle META_PREF_WORKSPACE_NAMES * src/menu.c (get_workspace_name_with_accel): assert that the workspace has a name * src/screen.c (meta_screen_ensure_workspace_popup): assert that we got a workspace name (meta_screen_ensure_workspace_popup): assert that we got a workspace name * src/prefs.c (update_workspace_name): fix screwiness (strcmp with a freed string, assorted bad logic) (init_workspace_names): assert that we filled in a default workspace name (meta_prefs_get_workspace_name): assert non-NULL workspace name --- ChangeLog | 21 +++++++++++++++++++++ src/menu.c | 4 +++- src/prefs.c | 23 +++++++++++++++++------ src/screen.c | 10 +++++++++- 4 files changed, 50 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6e7004566..e2aa55a69 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,24 @@ +2002-11-19 Havoc Pennington + + Fix #98303 and assorted cleanup + + * src/prefs.c (meta_preference_to_string): handle + META_PREF_WORKSPACE_NAMES + + * src/menu.c (get_workspace_name_with_accel): assert that the + workspace has a name + + * src/screen.c (meta_screen_ensure_workspace_popup): assert that + we got a workspace name + (meta_screen_ensure_workspace_popup): assert that we got a + workspace name + + * src/prefs.c (update_workspace_name): fix screwiness (strcmp with + a freed string, assorted bad logic) + (init_workspace_names): assert that we filled in a default + workspace name + (meta_prefs_get_workspace_name): assert non-NULL workspace name + 2002-11-16 Bill Haneman * src/themes/Atlanta/metacity-theme-1.xml: diff --git a/src/menu.c b/src/menu.c index 9cec2f5fb..ea340b9ea 100644 --- a/src/menu.c +++ b/src/menu.c @@ -141,6 +141,8 @@ get_workspace_name_with_accel (Display *display, name = meta_core_get_workspace_name_with_index (display, xroot, index); + g_assert (name != NULL); + /* * If the name is of the form "Workspace x" where x is an unsigned * integer, insert a '_' before the number if it is less than 10 and @@ -188,7 +190,7 @@ get_workspace_name_with_accel (Display *display, * *new_name to the calling code. */ return new_name; - } + } } static GtkWidget* diff --git a/src/prefs.c b/src/prefs.c index e607d25c4..3b55ca3ae 100644 --- a/src/prefs.c +++ b/src/prefs.c @@ -1137,6 +1137,10 @@ meta_preference_to_string (MetaPreference pref) case META_PREF_BUTTON_LAYOUT: return "BUTTON_LAYOUT"; break; + + case META_PREF_WORKSPACE_NAMES: + return "WORKSPACE_NAMES"; + break; } return "(unknown)"; @@ -1342,6 +1346,8 @@ init_workspace_names (void) update_workspace_name (key, str_val); + g_assert (workspace_names[i] != NULL); + g_free (str_val); g_free (key); @@ -1553,21 +1559,23 @@ update_workspace_name (const char *name, return FALSE; } - if ((workspace_names[i] == NULL && value == NULL) || - (workspace_names[i] && value && strcmp (workspace_names[i], value) == 0)) + if (workspace_names[i] && value && strcmp (workspace_names[i], value) == 0) { meta_topic (META_DEBUG_PREFS, "Workspace name %d is unchanged\n", i); return FALSE; - } - - g_free (workspace_names[i]); + } + if (value != NULL) - workspace_names[i] = g_strdup (value); + { + g_free (workspace_names[i]); + workspace_names[i] = g_strdup (value); + } else { /* use a default name */ char *d; + d = g_strdup_printf (_("Workspace %d"), i + 1); if (workspace_names[i] && strcmp (workspace_names[i], d) == 0) { @@ -1576,6 +1584,7 @@ update_workspace_name (const char *name, } else { + g_free (workspace_names[i]); workspace_names[i] = d; } } @@ -1591,6 +1600,8 @@ const char* 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); return workspace_names[i]; } diff --git a/src/screen.c b/src/screen.c index ca24ef7dc..8be27c351 100644 --- a/src/screen.c +++ b/src/screen.c @@ -1137,6 +1137,9 @@ meta_screen_ensure_workspace_popup (MetaScreen *screen) entries[iter].key = (MetaTabEntryKey) workspace; entries[iter].title = meta_workspace_get_name (workspace); entries[iter].icon = NULL; + + g_assert (entries[iter].title != NULL); + iter++; } } @@ -1156,6 +1159,8 @@ meta_screen_ensure_workspace_popup (MetaScreen *screen) entries[i].key = (MetaTabEntryKey) workspace; entries[i].title = meta_workspace_get_name (workspace); entries[i].icon = NULL; + + g_assert (entries[i].title != NULL); } } @@ -1416,7 +1421,7 @@ update_workspace_names (MetaScreen *screen) name = meta_prefs_get_workspace_name (i); if (name) - g_string_append_len (flattened, name, + g_string_append_len (flattened, name, strlen (name) + 1); else g_string_append_len (flattened, "", 1); @@ -1462,6 +1467,9 @@ meta_screen_update_workspace_names (MetaScreen *screen) i = 0; while (i < n_names) { + meta_topic (META_DEBUG_PREFS, + "Setting workspace %d name to \"%s\" due to _NET_DESKTOP_NAMES change\n", + i, names[i] ? names[i] : "null"); meta_prefs_change_workspace_name (i, names[i]); ++i;