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

View File

@ -531,25 +531,11 @@ xsettings_client_destroy (XSettingsClient *client)
free (client);
}
XSettingsResult
const XSettingsSetting *
xsettings_client_get_setting (XSettingsClient *client,
const char *name,
XSettingsSetting **setting)
const char *name)
{
XSettingsSetting *search;
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;
return g_hash_table_lookup (client->settings, name);
}
Bool

View File

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

View File

@ -31,53 +31,6 @@
#include <X11/Xlib.h>
#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
xsettings_setting_equal (XSettingsSetting *setting_a,
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_ungrab_func _gdk_x11_xsettings_client_set_ungrab_func
#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_free _gdk_x11_xsettings_setting_free
@ -91,7 +90,6 @@ struct _XSettingsSetting
} data;
};
XSettingsSetting *xsettings_setting_copy (XSettingsSetting *setting);
void xsettings_setting_free (XSettingsSetting *setting);
int xsettings_setting_equal (XSettingsSetting *setting_a,
XSettingsSetting *setting_b);