Blame libxklavier/xklavier_props.c

Packit 7e555f
/*
Packit 7e555f
 * Copyright (C) 2002-2006 Sergey V. Udaltsov <svu@gnome.org>
Packit 7e555f
 *
Packit 7e555f
 * This library is free software; you can redistribute it and/or
Packit 7e555f
 * modify it under the terms of the GNU Lesser General Public
Packit 7e555f
 * License as published by the Free Software Foundation; either
Packit 7e555f
 * version 2 of the License, or (at your option) any later version.
Packit 7e555f
 *
Packit 7e555f
 * This library is distributed in the hope that it will be useful,
Packit 7e555f
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 7e555f
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 7e555f
 * Lesser General Public License for more details.
Packit 7e555f
 *
Packit 7e555f
 * You should have received a copy of the GNU Lesser General Public
Packit 7e555f
 * License along with this library; if not, write to the
Packit 7e555f
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Packit 7e555f
 * Boston, MA 02111-1307, USA.
Packit 7e555f
 */
Packit 7e555f
Packit 7e555f
#include <errno.h>
Packit 7e555f
#include <locale.h>
Packit 7e555f
#include <string.h>
Packit 7e555f
Packit 7e555f
#include <X11/Xlib.h>
Packit 7e555f
#include <X11/Xatom.h>
Packit 7e555f
Packit 7e555f
#include <libxml/xpath.h>
Packit 7e555f
Packit 7e555f
#include "config.h"
Packit 7e555f
Packit 7e555f
#include "xklavier_private.h"
Packit 7e555f
Packit 7e555f
static GObjectClass *parent_class = NULL;
Packit 7e555f
Packit 7e555f
static void xkl_config_rec_destroy(XklConfigRec * data);
Packit 7e555f
Packit 7e555f
G_DEFINE_TYPE(XklConfigItem, xkl_config_item, G_TYPE_OBJECT)
Packit 7e555f
Packit 7e555f
static void
Packit 7e555f
xkl_config_item_init(XklConfigItem * this)
Packit 7e555f
{
Packit 7e555f
}
Packit 7e555f
Packit 7e555f
static void
Packit 7e555f
xkl_config_item_class_init(XklConfigItemClass * klass)
Packit 7e555f
{
Packit 7e555f
}
Packit 7e555f
Packit 7e555f
XklConfigItem *
Packit 7e555f
xkl_config_item_new(void)
Packit 7e555f
{
Packit 7e555f
	return
Packit 7e555f
	    XKL_CONFIG_ITEM(g_object_new
Packit 7e555f
			    (xkl_config_item_get_type(), NULL));
Packit 7e555f
}
Packit 7e555f
Packit 7e555f
const gchar *
Packit 7e555f
xkl_config_item_get_name(XklConfigItem * item)
Packit 7e555f
{
Packit 7e555f
	return item->name;
Packit 7e555f
}
Packit 7e555f
Packit 7e555f
void
Packit 7e555f
xkl_config_item_set_name(XklConfigItem * item,
Packit 7e555f
			 const gchar * name)
Packit 7e555f
{
Packit 7e555f
	if (name != NULL)
Packit 7e555f
		strncpy (item->name, name, XKL_MAX_CI_SHORT_DESC_LENGTH-1);
Packit 7e555f
	else
Packit 7e555f
		item->name[0] = '\0';
Packit 7e555f
}
Packit 7e555f
Packit 7e555f
const gchar *
Packit 7e555f
xkl_config_item_get_short_description(XklConfigItem * item)
Packit 7e555f
{
Packit 7e555f
	return item->short_description;
Packit 7e555f
}
Packit 7e555f
Packit 7e555f
void
Packit 7e555f
xkl_config_item_set_short_description(XklConfigItem * item,
Packit 7e555f
				      const gchar * short_description)
Packit 7e555f
{
Packit 7e555f
	if (short_description != NULL)
Packit 7e555f
		strncpy (item->short_description, short_description, XKL_MAX_CI_DESC_LENGTH-1);
Packit 7e555f
	else
Packit 7e555f
		item->short_description[0] = '\0';
Packit 7e555f
}
Packit 7e555f
Packit 7e555f
const gchar *
Packit 7e555f
xkl_config_item_get_description(XklConfigItem * item)
Packit 7e555f
{
Packit 7e555f
	return item->description;
Packit 7e555f
}
Packit 7e555f
Packit 7e555f
void
Packit 7e555f
xkl_config_item_set_description(XklConfigItem * item,
Packit 7e555f
				const gchar * description)
Packit 7e555f
{
Packit 7e555f
	if (description != NULL)
Packit 7e555f
		strncpy (item->description, description, XKL_MAX_CI_NAME_LENGTH-1);
Packit 7e555f
	else
Packit 7e555f
		item->description[0] = '\0';
Packit 7e555f
}
Packit 7e555f
Packit 7e555f
G_DEFINE_TYPE(XklConfigRec, xkl_config_rec, G_TYPE_OBJECT)
Packit 7e555f
Packit 7e555f
static void
Packit 7e555f
xkl_config_rec_finalize(GObject * obj)
Packit 7e555f
{
Packit 7e555f
	XklConfigRec *this = (XklConfigRec *) obj;
Packit 7e555f
	xkl_config_rec_destroy(this);
Packit 7e555f
	G_OBJECT_CLASS(parent_class)->finalize(obj);
Packit 7e555f
}
Packit 7e555f
Packit 7e555f
static void
Packit 7e555f
xkl_config_rec_class_init(XklConfigRecClass * klass)
Packit 7e555f
{
Packit 7e555f
	GObjectClass *object_class;
Packit 7e555f
Packit 7e555f
	object_class = (GObjectClass *) klass;
Packit 7e555f
	parent_class = g_type_class_peek_parent(object_class);
Packit 7e555f
	object_class->finalize = xkl_config_rec_finalize;
Packit 7e555f
}
Packit 7e555f
Packit 7e555f
XklConfigRec *
Packit 7e555f
xkl_config_rec_new(void)
Packit 7e555f
{
Packit 7e555f
	return
Packit 7e555f
	    XKL_CONFIG_REC(g_object_new(xkl_config_rec_get_type(), NULL));
Packit 7e555f
}
Packit 7e555f
Packit 7e555f
static gboolean
Packit 7e555f
xkl_strings_equal(gchar * p1, gchar * p2)
Packit 7e555f
{
Packit 7e555f
	if (p1 == p2)
Packit 7e555f
		return TRUE;
Packit 7e555f
	if ((p1 == NULL && p2 != NULL) || (p1 != NULL && p2 == NULL))
Packit 7e555f
		return FALSE;
Packit 7e555f
	return !g_ascii_strcasecmp(p1, p2);
Packit 7e555f
}
Packit 7e555f
Packit 7e555f
static gboolean
Packit 7e555f
xkl_lists_equal(gchar ** items1, gchar ** items2)
Packit 7e555f
{
Packit 7e555f
	if (items1 == items2)
Packit 7e555f
		return TRUE;
Packit 7e555f
Packit 7e555f
	if ((items1 == NULL && items2 != NULL) ||
Packit 7e555f
	    (items1 != NULL && items2 == NULL))
Packit 7e555f
		return FALSE;
Packit 7e555f
Packit 7e555f
	while (*items1 != NULL && *items2 != NULL)
Packit 7e555f
		if (!xkl_strings_equal(*items1++, *items2++))
Packit 7e555f
			return FALSE;
Packit 7e555f
Packit 7e555f
	return (*items1 == NULL && *items2 == NULL);
Packit 7e555f
}
Packit 7e555f
Packit 7e555f
static gboolean
Packit 7e555f
xkl_engine_get_default_names_prop(XklEngine * engine,
Packit 7e555f
				  char **rules_file_out,
Packit 7e555f
				  XklConfigRec * data)
Packit 7e555f
{
Packit 7e555f
	if (rules_file_out != NULL)
Packit 7e555f
		*rules_file_out = g_strdup(XKB_DEFAULT_RULESET);
Packit 7e555f
	data->model = g_strdup(xkl_engine_priv(engine, default_model));
Packit 7e555f
/* keeping Nvariants = Nlayouts */
Packit 7e555f
	data->layouts = g_new0(char *, 2);
Packit 7e555f
	data->layouts[0] =
Packit 7e555f
	    g_strdup(xkl_engine_priv(engine, default_layout));
Packit 7e555f
	data->variants = g_new0(char *, 2);
Packit 7e555f
	data->variants[0] = g_strdup("");
Packit 7e555f
	data->options = g_new0(char *, 1);
Packit 7e555f
	return TRUE;
Packit 7e555f
}
Packit 7e555f
Packit 7e555f
gboolean
Packit 7e555f
xkl_config_rec_get_full_from_server(char **rules_file_out,
Packit 7e555f
				    XklConfigRec * data,
Packit 7e555f
				    XklEngine * engine)
Packit 7e555f
{
Packit 7e555f
	gboolean rv = xkl_config_rec_get_from_root_window_property(data,
Packit 7e555f
								   xkl_engine_priv
Packit 7e555f
								   (engine,
Packit 7e555f
								    base_config_atom),
Packit 7e555f
								   rules_file_out,
Packit 7e555f
								   engine);
Packit 7e555f
Packit 7e555f
	if (!rv)
Packit 7e555f
		rv = xkl_engine_get_default_names_prop(engine,
Packit 7e555f
						       rules_file_out,
Packit 7e555f
						       data);
Packit 7e555f
Packit 7e555f
	return rv;
Packit 7e555f
}
Packit 7e555f
Packit 7e555f
gboolean
Packit 7e555f
xkl_config_rec_equals(XklConfigRec * data1, XklConfigRec * data2)
Packit 7e555f
{
Packit 7e555f
	if (data1 == data2)
Packit 7e555f
		return TRUE;
Packit 7e555f
	if (!xkl_strings_equal(data1->model, data2->model))
Packit 7e555f
		return FALSE;
Packit 7e555f
	if (!xkl_lists_equal(data1->layouts, data2->layouts))
Packit 7e555f
		return FALSE;
Packit 7e555f
	if (!xkl_lists_equal(data1->variants, data2->variants))
Packit 7e555f
		return FALSE;
Packit 7e555f
	return xkl_lists_equal(data1->options, data2->options);
Packit 7e555f
}
Packit 7e555f
Packit 7e555f
void
Packit 7e555f
xkl_config_rec_set_layouts(XklConfigRec * data,
Packit 7e555f
			   const gchar ** new_layouts)
Packit 7e555f
{
Packit 7e555f
        g_strfreev (data->layouts);
Packit 7e555f
	data->layouts = g_strdupv ((gchar**) new_layouts);
Packit 7e555f
}
Packit 7e555f
Packit 7e555f
void
Packit 7e555f
xkl_config_rec_set_variants(XklConfigRec * data,
Packit 7e555f
			   const gchar ** new_variants)
Packit 7e555f
{
Packit 7e555f
        g_strfreev (data->variants);
Packit 7e555f
	data->variants = g_strdupv ((gchar**) new_variants);
Packit 7e555f
}
Packit 7e555f
Packit 7e555f
void
Packit 7e555f
xkl_config_rec_set_options(XklConfigRec * data,
Packit 7e555f
			   const gchar ** new_options)
Packit 7e555f
{
Packit 7e555f
        g_strfreev (data->options);
Packit 7e555f
	data->options = g_strdupv ((gchar**) new_options);
Packit 7e555f
}
Packit 7e555f
Packit 7e555f
void
Packit 7e555f
xkl_config_rec_set_model(XklConfigRec * data,
Packit 7e555f
			 const gchar * new_model)
Packit 7e555f
{
Packit 7e555f
        g_free (data->model);
Packit 7e555f
	data->model = g_strdup (new_model);
Packit 7e555f
}
Packit 7e555f
Packit 7e555f
void
Packit 7e555f
xkl_config_rec_init(XklConfigRec * data)
Packit 7e555f
{
Packit 7e555f
	/* clear the structure VarDefsPtr... */
Packit 7e555f
	data->model = NULL;
Packit 7e555f
	data->layouts = data->variants = data->options = NULL;
Packit 7e555f
}
Packit 7e555f
Packit 7e555f
void
Packit 7e555f
xkl_config_rec_destroy(XklConfigRec * data)
Packit 7e555f
{
Packit 7e555f
	if (data->model != NULL)
Packit 7e555f
		g_free(data->model);
Packit 7e555f
Packit 7e555f
	g_strfreev(data->layouts);
Packit 7e555f
	g_strfreev(data->variants);
Packit 7e555f
	g_strfreev(data->options);
Packit 7e555f
	data->layouts = data->variants = data->options = NULL;
Packit 7e555f
}
Packit 7e555f
Packit 7e555f
void
Packit 7e555f
xkl_config_rec_reset(XklConfigRec * data)
Packit 7e555f
{
Packit 7e555f
	xkl_config_rec_destroy(data);
Packit 7e555f
	xkl_config_rec_init(data);
Packit 7e555f
}
Packit 7e555f
Packit 7e555f
gboolean
Packit 7e555f
xkl_config_rec_get_from_server(XklConfigRec * data, XklEngine * engine)
Packit 7e555f
{
Packit 7e555f
	return xkl_config_rec_get_full_from_server(NULL, data, engine);
Packit 7e555f
}
Packit 7e555f
Packit 7e555f
gboolean
Packit 7e555f
xkl_config_rec_get_from_backup(XklConfigRec * data, XklEngine * engine)
Packit 7e555f
{
Packit 7e555f
	return xkl_config_rec_get_from_root_window_property(data,
Packit 7e555f
							    xkl_engine_priv
Packit 7e555f
							    (engine,
Packit 7e555f
							     backup_config_atom),
Packit 7e555f
							    NULL, engine);
Packit 7e555f
}
Packit 7e555f
Packit 7e555f
gboolean
Packit 7e555f
xkl_engine_backup_names_prop(XklEngine * engine)
Packit 7e555f
{
Packit 7e555f
	gboolean rv = TRUE;
Packit 7e555f
	gchar *rf = NULL;
Packit 7e555f
	XklConfigRec *data = xkl_config_rec_new();
Packit 7e555f
	gboolean cgp = FALSE;
Packit 7e555f
Packit 7e555f
	if (xkl_config_rec_get_from_root_window_property
Packit 7e555f
	    (data, xkl_engine_priv(engine, backup_config_atom), NULL,
Packit 7e555f
	     engine)) {
Packit 7e555f
		g_object_unref(G_OBJECT(data));
Packit 7e555f
		return TRUE;
Packit 7e555f
	}
Packit 7e555f
	/* "backup" property is not defined */
Packit 7e555f
	xkl_config_rec_reset(data);
Packit 7e555f
	cgp = xkl_config_rec_get_full_from_server(&rf, data, engine);
Packit 7e555f
Packit 7e555f
	if (cgp) {
Packit 7e555f
		if (!xkl_config_rec_set_to_root_window_property
Packit 7e555f
		    (data, xkl_engine_priv(engine, backup_config_atom),
Packit 7e555f
		     rf, engine)) {
Packit 7e555f
			xkl_debug(150,
Packit 7e555f
				  "Could not backup the configuration");
Packit 7e555f
			rv = FALSE;
Packit 7e555f
		}
Packit 7e555f
		if (rf != NULL)
Packit 7e555f
			g_free(rf);
Packit 7e555f
	} else {
Packit 7e555f
		xkl_debug(150,
Packit 7e555f
			  "Could not get the configuration for backup");
Packit 7e555f
		rv = FALSE;
Packit 7e555f
	}
Packit 7e555f
	g_object_unref(G_OBJECT(data));
Packit 7e555f
	return rv;
Packit 7e555f
}
Packit 7e555f
Packit 7e555f
gboolean
Packit 7e555f
xkl_restore_names_prop(XklEngine * engine)
Packit 7e555f
{
Packit 7e555f
	gboolean rv = TRUE;
Packit 7e555f
	gchar *rf = NULL;
Packit 7e555f
	XklConfigRec *data = xkl_config_rec_new();
Packit 7e555f
Packit 7e555f
	if (!xkl_config_rec_get_from_root_window_property
Packit 7e555f
	    (data, xkl_engine_priv(engine, backup_config_atom), NULL,
Packit 7e555f
	     engine)) {
Packit 7e555f
		g_object_unref(G_OBJECT(data));
Packit 7e555f
		return FALSE;
Packit 7e555f
	}
Packit 7e555f
Packit 7e555f
	if (!xkl_config_rec_set_to_root_window_property
Packit 7e555f
	    (data, xkl_engine_priv(engine, base_config_atom), rf,
Packit 7e555f
	     engine)) {
Packit 7e555f
		xkl_debug(150, "Could not backup the configuration");
Packit 7e555f
		rv = FALSE;
Packit 7e555f
	}
Packit 7e555f
	g_object_unref(G_OBJECT(data));
Packit 7e555f
	return rv;
Packit 7e555f
}
Packit 7e555f
Packit 7e555f
gboolean
Packit 7e555f
xkl_config_rec_get_from_root_window_property(XklConfigRec * data,
Packit 7e555f
					     Atom rules_atom,
Packit 7e555f
					     gchar ** rules_file_out,
Packit 7e555f
					     XklEngine * engine)
Packit 7e555f
{
Packit 7e555f
	Atom real_prop_type;
Packit 7e555f
	int fmt;
Packit 7e555f
	unsigned long nitems, extra_bytes;
Packit 7e555f
	char *prop_data = NULL, *out;
Packit 7e555f
	Status rtrn;
Packit 7e555f
Packit 7e555f
	/* no such atom! */
Packit 7e555f
	if (rules_atom == None) {	/* property cannot exist */
Packit 7e555f
		xkl_last_error_message = "Could not find the atom";
Packit 7e555f
		return FALSE;
Packit 7e555f
	}
Packit 7e555f
Packit 7e555f
	rtrn =
Packit 7e555f
	    XGetWindowProperty(xkl_engine_get_display(engine),
Packit 7e555f
			       xkl_engine_priv(engine, root_window),
Packit 7e555f
			       rules_atom, 0L, XKB_RF_NAMES_PROP_MAXLEN,
Packit 7e555f
			       False, XA_STRING, &real_prop_type, &fmt,
Packit 7e555f
			       &nitems, &extra_bytes,
Packit 7e555f
			       (unsigned char **) (void *) &prop_data);
Packit 7e555f
	/* property not found! */
Packit 7e555f
	if (rtrn != Success) {
Packit 7e555f
		xkl_last_error_message = "Could not get the property";
Packit 7e555f
		return FALSE;
Packit 7e555f
	}
Packit 7e555f
	/* set rules file to "" */
Packit 7e555f
	if (rules_file_out)
Packit 7e555f
		*rules_file_out = NULL;
Packit 7e555f
Packit 7e555f
	/* has to be array of strings */
Packit 7e555f
	if ((extra_bytes > 0) || (real_prop_type != XA_STRING)
Packit 7e555f
	    || (fmt != 8)) {
Packit 7e555f
		if (prop_data)
Packit 7e555f
			XFree(prop_data);
Packit 7e555f
		xkl_last_error_message = "Wrong property format";
Packit 7e555f
		return FALSE;
Packit 7e555f
	}
Packit 7e555f
Packit 7e555f
	if (!prop_data) {
Packit 7e555f
		xkl_last_error_message = "No properties returned";
Packit 7e555f
		return FALSE;
Packit 7e555f
	}
Packit 7e555f
Packit 7e555f
	/* rules file */
Packit 7e555f
	out = prop_data;
Packit 7e555f
	if (out && (*out) && rules_file_out)
Packit 7e555f
		*rules_file_out = g_strdup(out);
Packit 7e555f
	out += strlen(out) + 1;
Packit 7e555f
Packit 7e555f
	/* if user is interested in rules only - don't waste the time */
Packit 7e555f
	if (!data) {
Packit 7e555f
		XFree(prop_data);
Packit 7e555f
		return TRUE;
Packit 7e555f
	}
Packit 7e555f
Packit 7e555f
	if ((out - prop_data) < nitems) {
Packit 7e555f
		if (*out)
Packit 7e555f
			data->model = g_strdup(out);
Packit 7e555f
		out += strlen(out) + 1;
Packit 7e555f
	}
Packit 7e555f
Packit 7e555f
	if ((out - prop_data) < nitems) {
Packit 7e555f
		xkl_config_rec_split_layouts(data, out);
Packit 7e555f
		out += strlen(out) + 1;
Packit 7e555f
	}
Packit 7e555f
Packit 7e555f
	if ((out - prop_data) < nitems) {
Packit 7e555f
		gint nv, nl;
Packit 7e555f
		gchar **layout, **variant;
Packit 7e555f
		xkl_config_rec_split_variants(data, out);
Packit 7e555f
		/*
Packit 7e555f
		   Now have to ensure that number of variants matches the number of layouts
Packit 7e555f
		   The 'remainder' is filled with NULLs (not ""s!)
Packit 7e555f
		 */
Packit 7e555f
Packit 7e555f
		nv = g_strv_length(data->variants);
Packit 7e555f
		nl = g_strv_length(data->layouts);
Packit 7e555f
		if (nv < nl) {
Packit 7e555f
			data->variants = g_realloc(data->variants,
Packit 7e555f
						   (nl +
Packit 7e555f
						    1) * sizeof(char *));
Packit 7e555f
			memset(data->variants + nv + 1, 0,
Packit 7e555f
			       (nl - nv) * sizeof(char *));
Packit 7e555f
		}
Packit 7e555f
		/* take variants from layouts like ru(winkeys) */
Packit 7e555f
		layout = data->layouts;
Packit 7e555f
		variant = data->variants;
Packit 7e555f
		while (*layout != NULL && *variant == NULL) {
Packit 7e555f
			gchar *varstart = g_strstr_len(*layout, -1, "(");
Packit 7e555f
			if (varstart != NULL) {
Packit 7e555f
				gchar *varend =
Packit 7e555f
				    g_strstr_len(varstart, -1, ")");
Packit 7e555f
				if (varend != NULL) {
Packit 7e555f
					gint varlen = varend - varstart;
Packit 7e555f
					gint laylen = varstart - *layout;
Packit 7e555f
					/* I am not sure - but I assume variants in layout have priority */
Packit 7e555f
					gchar *var = *variant =
Packit 7e555f
					    (*variant !=
Packit 7e555f
					     NULL) ? g_realloc(*variant,
Packit 7e555f
							       varlen) :
Packit 7e555f
					    g_new(gchar, varlen);
Packit 7e555f
					memcpy(var, varstart + 1,
Packit 7e555f
					       --varlen);
Packit 7e555f
					var[varlen] = '\0';
Packit 7e555f
					/* Resize the original layout */
Packit 7e555f
					*layout =
Packit 7e555f
					    g_realloc(*layout, laylen + 1);
Packit 7e555f
					(*layout)[laylen] = '\0';
Packit 7e555f
				}
Packit 7e555f
			}
Packit 7e555f
			layout++;
Packit 7e555f
			variant++;
Packit 7e555f
		}
Packit 7e555f
		out += strlen(out) + 1;
Packit 7e555f
	}
Packit 7e555f
Packit 7e555f
	if ((out - prop_data) < nitems) {
Packit 7e555f
		xkl_config_rec_split_options(data, out);
Packit 7e555f
	}
Packit 7e555f
	XFree(prop_data);
Packit 7e555f
	return TRUE;
Packit 7e555f
}
Packit 7e555f
Packit 7e555f
/* taken from XFree86 maprules.c */
Packit 7e555f
gboolean
Packit 7e555f
xkl_config_rec_set_to_root_window_property(const XklConfigRec * data,
Packit 7e555f
					   Atom rules_atom,
Packit 7e555f
					   gchar * rules_file,
Packit 7e555f
					   XklEngine * engine)
Packit 7e555f
{
Packit 7e555f
	gint len;
Packit 7e555f
	gchar *pval;
Packit 7e555f
	gchar *next;
Packit 7e555f
	gchar *all_layouts = xkl_config_rec_merge_layouts(data);
Packit 7e555f
	gchar *all_variants = xkl_config_rec_merge_variants(data);
Packit 7e555f
	gchar *all_options = xkl_config_rec_merge_options(data);
Packit 7e555f
	Display *display;
Packit 7e555f
Packit 7e555f
	len = (rules_file ? strlen(rules_file) : 0);
Packit 7e555f
	len += (data->model ? strlen(data->model) : 0);
Packit 7e555f
	len += (all_layouts ? strlen(all_layouts) : 0);
Packit 7e555f
	len += (all_variants ? strlen(all_variants) : 0);
Packit 7e555f
	len += (all_options ? strlen(all_options) : 0);
Packit 7e555f
	if (len < 1) {
Packit 7e555f
		if (all_layouts)
Packit 7e555f
			g_free(all_layouts);
Packit 7e555f
		if (all_variants)
Packit 7e555f
			g_free(all_variants);
Packit 7e555f
		if (all_options)
Packit 7e555f
			g_free(all_options);
Packit 7e555f
		return TRUE;
Packit 7e555f
	}
Packit 7e555f
Packit 7e555f
	len += 5;		/* trailing NULs */
Packit 7e555f
Packit 7e555f
	pval = next = g_new(char, len + 1);
Packit 7e555f
	if (!pval) {
Packit 7e555f
		xkl_last_error_message = "Could not allocate buffer";
Packit 7e555f
		if (all_layouts != NULL)
Packit 7e555f
			g_free(all_layouts);
Packit 7e555f
		if (all_variants != NULL)
Packit 7e555f
			g_free(all_variants);
Packit 7e555f
		if (all_options != NULL)
Packit 7e555f
			g_free(all_options);
Packit 7e555f
		return FALSE;
Packit 7e555f
	}
Packit 7e555f
	if (rules_file) {
Packit 7e555f
		strcpy(next, rules_file);
Packit 7e555f
		next += strlen(rules_file);
Packit 7e555f
	}
Packit 7e555f
	*next++ = '\0';
Packit 7e555f
	if (data->model) {
Packit 7e555f
		strcpy(next, data->model);
Packit 7e555f
		next += strlen(data->model);
Packit 7e555f
	}
Packit 7e555f
	*next++ = '\0';
Packit 7e555f
	if (data->layouts) {
Packit 7e555f
		strcpy(next, all_layouts);
Packit 7e555f
		next += strlen(all_layouts);
Packit 7e555f
	}
Packit 7e555f
	*next++ = '\0';
Packit 7e555f
	if (data->variants) {
Packit 7e555f
		strcpy(next, all_variants);
Packit 7e555f
		next += strlen(all_variants);
Packit 7e555f
	}
Packit 7e555f
	*next++ = '\0';
Packit 7e555f
	if (data->options) {
Packit 7e555f
		strcpy(next, all_options);
Packit 7e555f
		next += strlen(all_options);
Packit 7e555f
	}
Packit 7e555f
	*next++ = '\0';
Packit 7e555f
	if ((next - pval) != len) {
Packit 7e555f
		xkl_debug(150, "Illegal final position: %d/%d\n",
Packit 7e555f
			  (next - pval), len);
Packit 7e555f
		if (all_layouts != NULL)
Packit 7e555f
			g_free(all_layouts);
Packit 7e555f
		if (all_variants != NULL)
Packit 7e555f
			g_free(all_variants);
Packit 7e555f
		if (all_options != NULL)
Packit 7e555f
			g_free(all_options);
Packit 7e555f
		g_free(pval);
Packit 7e555f
		xkl_last_error_message = "Internal property parsing error";
Packit 7e555f
		return FALSE;
Packit 7e555f
	}
Packit 7e555f
Packit 7e555f
	display = xkl_engine_get_display(engine);
Packit 7e555f
	XChangeProperty(display, xkl_engine_priv(engine, root_window),
Packit 7e555f
			     rules_atom, XA_STRING, 8, PropModeReplace,
Packit 7e555f
			     (unsigned char *) pval, len);
Packit 7e555f
	XSync(display, False);
Packit 7e555f
#if 0
Packit 7e555f
	for (i = len - 1; --i >= 0;)
Packit 7e555f
		if (pval[i] == '\0')
Packit 7e555f
			pval[i] = '?';
Packit 7e555f
	XklDebug(150, "Stored [%s] of length %d to [%s] of %X\n", pval,
Packit 7e555f
		 len, propName, _xklRootWindow);
Packit 7e555f
#endif
Packit 7e555f
	if (all_layouts != NULL)
Packit 7e555f
		g_free(all_layouts);
Packit 7e555f
	if (all_variants != NULL)
Packit 7e555f
		g_free(all_variants);
Packit 7e555f
	if (all_options != NULL)
Packit 7e555f
		g_free(all_options);
Packit 7e555f
	g_free(pval);
Packit 7e555f
	return TRUE;
Packit 7e555f
}