From edf19ab7b493a3ae414878739976da45e3e3e95d Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Thu, 14 Feb 2013 17:20:26 +0100 Subject: [PATCH] x11: Store GDK name in xsettings hash table The X name is only used while reading the property, so no need to keep it. --- gdk/x11/gdkscreen-x11.c | 15 +++-------- gdk/x11/gdksettings.c | 19 +------------- gdk/x11/xsettings-client.c | 53 ++++++++++++++++++++++++-------------- 3 files changed, 38 insertions(+), 49 deletions(-) diff --git a/gdk/x11/gdkscreen-x11.c b/gdk/x11/gdkscreen-x11.c index 5c3608f498..4ab66c3575 100644 --- a/gdk/x11/gdkscreen-x11.c +++ b/gdk/x11/gdkscreen-x11.c @@ -47,8 +47,6 @@ #include #endif -#include "gdksettings.c" - static void gdk_x11_screen_dispose (GObject *object); static void gdk_x11_screen_finalize (GObject *object); static void init_randr_support (GdkScreen *screen); @@ -1352,23 +1350,18 @@ gdk_x11_screen_get_setting (GdkScreen *screen, GValue *value) { GdkX11Screen *x11_screen = GDK_X11_SCREEN (screen); - const char *xsettings_name = NULL; const XSettingsSetting *setting; gboolean success = FALSE; GValue tmp_val = G_VALUE_INIT; - xsettings_name = gdk_to_xsettings_name (name); - if (!xsettings_name) - goto out; - - setting = xsettings_client_get_setting (x11_screen->xsettings_client, xsettings_name); + setting = xsettings_client_get_setting (x11_screen->xsettings_client, name); if (setting == NULL) goto out; switch (setting->type) { case XSETTINGS_TYPE_INT: - if (check_transform (xsettings_name, G_TYPE_INT, G_VALUE_TYPE (value))) + if (check_transform (name, G_TYPE_INT, G_VALUE_TYPE (value))) { g_value_init (&tmp_val, G_TYPE_INT); g_value_set_int (&tmp_val, setting->data.v_int); @@ -1378,7 +1371,7 @@ gdk_x11_screen_get_setting (GdkScreen *screen, } break; case XSETTINGS_TYPE_STRING: - if (check_transform (xsettings_name, G_TYPE_STRING, G_VALUE_TYPE (value))) + if (check_transform (name, G_TYPE_STRING, G_VALUE_TYPE (value))) { g_value_init (&tmp_val, G_TYPE_STRING); g_value_set_string (&tmp_val, setting->data.v_string); @@ -1388,7 +1381,7 @@ gdk_x11_screen_get_setting (GdkScreen *screen, } break; case XSETTINGS_TYPE_COLOR: - if (!check_transform (xsettings_name, GDK_TYPE_RGBA, G_VALUE_TYPE (value))) + if (!check_transform (name, GDK_TYPE_RGBA, G_VALUE_TYPE (value))) { GdkRGBA rgba; diff --git a/gdk/x11/gdksettings.c b/gdk/x11/gdksettings.c index cfd2676027..b5ca7b8fb4 100644 --- a/gdk/x11/gdksettings.c +++ b/gdk/x11/gdksettings.c @@ -79,7 +79,7 @@ static const struct { {"Gtk/RecentFilesEnabled", "gtk-recent-files-enabled"} }; -static G_GNUC_UNUSED const char * +static const char * gdk_from_xsettings_name (const char *xname) { static GHashTable *hash = NULL; @@ -97,20 +97,3 @@ gdk_from_xsettings_name (const char *xname) return g_hash_table_lookup (hash, xname); } -static G_GNUC_UNUSED const char * -gdk_to_xsettings_name (const char *gdkname) -{ - static GHashTable *hash = NULL; - guint i; - - if (G_UNLIKELY (hash == NULL)) - { - hash = g_hash_table_new (g_str_hash, g_str_equal); - - for (i = 0; i < G_N_ELEMENTS (gdk_settings_map); i++) - g_hash_table_insert (hash, (gpointer)gdk_settings_map[i].gdkname, - (gpointer)gdk_settings_map[i].xname); - } - - return g_hash_table_lookup (hash, gdkname); -} diff --git a/gdk/x11/xsettings-client.c b/gdk/x11/xsettings-client.c index 479ac9d865..2385dd78e1 100644 --- a/gdk/x11/xsettings-client.c +++ b/gdk/x11/xsettings-client.c @@ -59,7 +59,7 @@ struct _XSettingsClient Atom selection_atom; Atom xsettings_atom; - GHashTable *settings; /* string => XSettingsSetting */ + GHashTable *settings; /* string of GDK settings name => XSettingsSetting */ }; static void @@ -78,10 +78,7 @@ gdk_xsettings_notify (const char *name, new_event.setting.window = gdk_screen_get_root_window (screen); new_event.setting.send_event = FALSE; new_event.setting.action = action; - new_event.setting.name = (char*) gdk_from_xsettings_name (name); - - if (!new_event.setting.name) - return; + new_event.setting.name = (char*) name; gdk_event_put (&new_event); } @@ -230,7 +227,8 @@ parse_settings (unsigned char *data, CARD32 n_entries; CARD32 i; XSettingsSetting *setting = NULL; - char *name; + char *x_name = NULL; + const char *gdk_name; buffer.pos = buffer.data = data; buffer.len = len; @@ -270,7 +268,7 @@ parse_settings (unsigned char *data, setting = g_new (XSettingsSetting, 1); setting->type = XSETTINGS_TYPE_INT; /* No allocated memory */ - if (!fetch_string (&buffer, name_len, &name) || + if (!fetch_string (&buffer, name_len, &x_name) || /* last change serial (we ignore it) */ !fetch_card32 (&buffer, &v_int)) goto out; @@ -282,14 +280,14 @@ parse_settings (unsigned char *data, goto out; setting->data.v_int = (INT32)v_int; - GDK_NOTE(SETTINGS, g_print(" %s = %d\n", name, (gint) setting->data.v_int)); + GDK_NOTE(SETTINGS, g_print(" %s = %d\n", x_name, (gint) setting->data.v_int)); break; case XSETTINGS_TYPE_STRING: if (!fetch_card32 (&buffer, &v_int) || !fetch_string (&buffer, v_int, &setting->data.v_string)) goto out; - GDK_NOTE(SETTINGS, g_print(" %s = \"%s\"\n", name, setting->data.v_string)); + GDK_NOTE(SETTINGS, g_print(" %s = \"%s\"\n", x_name, setting->data.v_string)); break; case XSETTINGS_TYPE_COLOR: if (!fetch_ushort (&buffer, &setting->data.v_color.red) || @@ -298,32 +296,45 @@ parse_settings (unsigned char *data, !fetch_ushort (&buffer, &setting->data.v_color.alpha)) goto out; - GDK_NOTE(SETTINGS, g_print(" %s = #%02X%02X%02X%02X\n", name, + GDK_NOTE(SETTINGS, g_print(" %s = #%02X%02X%02X%02X\n", x_name, setting->data.v_color.alpha, setting->data.v_color.red, setting->data.v_color.green, setting->data.v_color.blue)); break; default: /* Quietly ignore unknown types */ - GDK_NOTE(SETTINGS, g_print(" %s = ignored (unknown type %u)\n", name, type)); + GDK_NOTE(SETTINGS, g_print(" %s = ignored (unknown type %u)\n", x_name, type)); break; } setting->type = type; - if (settings == NULL) - settings = g_hash_table_new_full (g_str_hash, g_str_equal, - g_free, - (GDestroyNotify) xsettings_setting_free); + gdk_name = gdk_from_xsettings_name (x_name); + g_free (x_name); + x_name = NULL; - if (g_hash_table_lookup (settings, name) != NULL) + if (gdk_name == NULL) { - g_warning ("Invalid XSETTINGS property (Duplicate entry for '%s')", name); - goto out; + GDK_NOTE(SETTINGS, g_print(" ==> unknown to GTK\n")); + } + else + { + GDK_NOTE(SETTINGS, g_print(" ==> storing as '%s'\n", gdk_name)); + + if (settings == NULL) + settings = g_hash_table_new_full (g_str_hash, g_str_equal, + NULL, + (GDestroyNotify) xsettings_setting_free); + + if (g_hash_table_lookup (settings, gdk_name) != NULL) + { + g_warning ("Invalid XSETTINGS property (Duplicate entry for '%s')", gdk_name); + goto out; + } + + g_hash_table_insert (settings, (gpointer) gdk_name, setting); } - g_hash_table_insert (settings, name, setting); setting = NULL; - name = NULL; } return settings; @@ -336,6 +347,8 @@ parse_settings (unsigned char *data, if (settings) g_hash_table_unref (settings); + g_free (x_name); + return NULL; }