x11: Return XSetting without copying

This commit is contained in:
Benjamin Otte 2013-02-10 00:02:53 +01:00
parent 1f95eddbda
commit 63f0797e70
5 changed files with 9 additions and 77 deletions

View File

@ -1353,8 +1353,7 @@ gdk_x11_screen_get_setting (GdkScreen *screen,
{ {
GdkX11Screen *x11_screen = GDK_X11_SCREEN (screen); GdkX11Screen *x11_screen = GDK_X11_SCREEN (screen);
const char *xsettings_name = NULL; const char *xsettings_name = NULL;
XSettingsResult result; const XSettingsSetting *setting;
XSettingsSetting *setting = NULL;
gboolean success = FALSE; gboolean success = FALSE;
GValue tmp_val = G_VALUE_INIT; GValue tmp_val = G_VALUE_INIT;
@ -1362,9 +1361,8 @@ gdk_x11_screen_get_setting (GdkScreen *screen,
if (!xsettings_name) if (!xsettings_name)
goto out; goto out;
result = xsettings_client_get_setting (x11_screen->xsettings_client, setting = xsettings_client_get_setting (x11_screen->xsettings_client, xsettings_name);
xsettings_name, &setting); if (setting == NULL)
if (result != XSETTINGS_SUCCESS)
goto out; goto out;
switch (setting->type) switch (setting->type)
@ -1413,9 +1411,6 @@ gdk_x11_screen_get_setting (GdkScreen *screen,
g_value_unset (&tmp_val); g_value_unset (&tmp_val);
out: out:
if (setting)
xsettings_setting_free (setting);
if (success) if (success)
return TRUE; return TRUE;
else else

View File

@ -531,25 +531,11 @@ xsettings_client_destroy (XSettingsClient *client)
free (client); free (client);
} }
XSettingsResult const XSettingsSetting *
xsettings_client_get_setting (XSettingsClient *client, xsettings_client_get_setting (XSettingsClient *client,
const char *name, const char *name)
XSettingsSetting **setting)
{ {
XSettingsSetting *search; return g_hash_table_lookup (client->settings, name);
if (client->settings == NULL)
return XSETTINGS_NO_ENTRY;
search = g_hash_table_lookup (client->settings, name);
if (search)
{
*setting = xsettings_setting_copy (search);
return *setting ? XSETTINGS_SUCCESS : XSETTINGS_NO_MEM;
}
else
return XSETTINGS_NO_ENTRY;
} }
Bool Bool

View File

@ -63,9 +63,9 @@ void xsettings_client_set_ungrab_func (XSettingsClient *client,
void xsettings_client_destroy (XSettingsClient *client); void xsettings_client_destroy (XSettingsClient *client);
Bool xsettings_client_process_event (XSettingsClient *client, Bool xsettings_client_process_event (XSettingsClient *client,
XEvent *xev); XEvent *xev);
XSettingsResult xsettings_client_get_setting (XSettingsClient *client, const XSettingsSetting *
const char *name, xsettings_client_get_setting (XSettingsClient *client,
XSettingsSetting **setting); const char *name);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -31,53 +31,6 @@
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/Xmd.h> /* For CARD32 */ #include <X11/Xmd.h> /* For CARD32 */
XSettingsSetting *
xsettings_setting_copy (XSettingsSetting *setting)
{
XSettingsSetting *result;
size_t str_len;
result = malloc (sizeof *result);
if (!result)
return NULL;
str_len = strlen (setting->name);
result->name = malloc (str_len + 1);
if (!result->name)
goto err;
memcpy (result->name, setting->name, str_len + 1);
result->type = setting->type;
switch (setting->type)
{
case XSETTINGS_TYPE_INT:
result->data.v_int = setting->data.v_int;
break;
case XSETTINGS_TYPE_COLOR:
result->data.v_color = setting->data.v_color;
break;
case XSETTINGS_TYPE_STRING:
str_len = strlen (setting->data.v_string);
result->data.v_string = malloc (str_len + 1);
if (!result->data.v_string)
goto err;
memcpy (result->data.v_string, setting->data.v_string, str_len + 1);
break;
}
return result;
err:
if (result->name)
free (result->name);
free (result);
return NULL;
}
int int
xsettings_setting_equal (XSettingsSetting *setting_a, xsettings_setting_equal (XSettingsSetting *setting_a,
XSettingsSetting *setting_b) XSettingsSetting *setting_b)

View File

@ -38,7 +38,6 @@ extern "C" {
#define xsettings_client_set_grab_func _gdk_x11_xsettings_client_set_grab_func #define xsettings_client_set_grab_func _gdk_x11_xsettings_client_set_grab_func
#define xsettings_client_set_ungrab_func _gdk_x11_xsettings_client_set_ungrab_func #define xsettings_client_set_ungrab_func _gdk_x11_xsettings_client_set_ungrab_func
#define xsettings_client_process_event _gdk_x11_xsettings_client_process_event #define xsettings_client_process_event _gdk_x11_xsettings_client_process_event
#define xsettings_setting_copy _gdk_x11_xsettings_setting_copy
#define xsettings_setting_equal _gdk_x11_xsettings_setting_equal #define xsettings_setting_equal _gdk_x11_xsettings_setting_equal
#define xsettings_setting_free _gdk_x11_xsettings_setting_free #define xsettings_setting_free _gdk_x11_xsettings_setting_free
@ -91,7 +90,6 @@ struct _XSettingsSetting
} data; } data;
}; };
XSettingsSetting *xsettings_setting_copy (XSettingsSetting *setting);
void xsettings_setting_free (XSettingsSetting *setting); void xsettings_setting_free (XSettingsSetting *setting);
int xsettings_setting_equal (XSettingsSetting *setting_a, int xsettings_setting_equal (XSettingsSetting *setting_a,
XSettingsSetting *setting_b); XSettingsSetting *setting_b);