Add libxklavier option to eekboard-xml.
This commit is contained in:
		@ -112,7 +112,8 @@ eekboard_xml_LDADD = \
 | 
				
			|||||||
	$(GTK_LIBS) \
 | 
						$(GTK_LIBS) \
 | 
				
			||||||
	$(LIBXKLAVIER_CFLAGS)
 | 
						$(LIBXKLAVIER_CFLAGS)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
eekboard_xml_SOURCES = xml-main.c
 | 
					eekboard_xml_headers = xklutil.h
 | 
				
			||||||
 | 
					eekboard_xml_SOURCES = xklutil.c xml-main.c
 | 
				
			||||||
 | 
					
 | 
				
			||||||
noinst_HEADERS = \
 | 
					noinst_HEADERS = \
 | 
				
			||||||
	$(libeekboard_a_headers) \
 | 
						$(libeekboard_a_headers) \
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										129
									
								
								src/xklutil.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										129
									
								
								src/xklutil.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,129 @@
 | 
				
			|||||||
 | 
					/* 
 | 
				
			||||||
 | 
					 * Copyright (C) 2011 Daiki Ueno <ueno@unixuser.org>
 | 
				
			||||||
 | 
					 * Copyright (C) 2011 Red Hat, Inc.
 | 
				
			||||||
 | 
					 * 
 | 
				
			||||||
 | 
					 * This library is free software; you can redistribute it and/or
 | 
				
			||||||
 | 
					 * modify it under the terms of the GNU Lesser General Public License
 | 
				
			||||||
 | 
					 * as published by the Free Software Foundation; either version 2 of
 | 
				
			||||||
 | 
					 * the License, or (at your option) any later version.
 | 
				
			||||||
 | 
					 * 
 | 
				
			||||||
 | 
					 * This library is distributed in the hope that it will be useful, but
 | 
				
			||||||
 | 
					 * WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
				
			||||||
 | 
					 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 | 
				
			||||||
 | 
					 * Lesser General Public License for more details.
 | 
				
			||||||
 | 
					 * 
 | 
				
			||||||
 | 
					 * You should have received a copy of the GNU Lesser General Public
 | 
				
			||||||
 | 
					 * License along with this library; if not, write to the Free Software
 | 
				
			||||||
 | 
					 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 | 
				
			||||||
 | 
					 * 02110-1301 USA
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					#include <string.h>
 | 
				
			||||||
 | 
					#include "xklutil.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					XklConfigRec *
 | 
				
			||||||
 | 
					eekboard_xkl_config_rec_new_from_string (const gchar *layouts)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    XklConfigRec *rec;
 | 
				
			||||||
 | 
					    gchar **l, **v;
 | 
				
			||||||
 | 
					    gint i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    l = g_strsplit (layouts, ",", -1);
 | 
				
			||||||
 | 
					    v = g_strdupv (l);
 | 
				
			||||||
 | 
					    for (i = 0; l[i]; i++) {
 | 
				
			||||||
 | 
					        gchar *layout = l[i], *variant = v[i],
 | 
				
			||||||
 | 
					            *variant_start, *variant_end;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        variant_start = strchr (layout, '(');
 | 
				
			||||||
 | 
					        variant_end = strrchr (layout, ')');
 | 
				
			||||||
 | 
					        if (variant_start && variant_end) {
 | 
				
			||||||
 | 
					            *variant_start++ = '\0';
 | 
				
			||||||
 | 
					            g_strlcpy (variant, variant_start,
 | 
				
			||||||
 | 
					                       variant_end - variant_start + 1);
 | 
				
			||||||
 | 
					        } else
 | 
				
			||||||
 | 
					            *variant = '\0';
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    rec = xkl_config_rec_new ();
 | 
				
			||||||
 | 
					    rec->layouts = l;
 | 
				
			||||||
 | 
					    rec->variants = v;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return rec;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static XklConfigItem *
 | 
				
			||||||
 | 
					xkl_config_item_copy (const XklConfigItem *item)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    XklConfigItem *_item = xkl_config_item_new ();
 | 
				
			||||||
 | 
					    memcpy (_item->name,
 | 
				
			||||||
 | 
					            item->name,
 | 
				
			||||||
 | 
					            sizeof (item->name));
 | 
				
			||||||
 | 
					    memcpy (_item->short_description,
 | 
				
			||||||
 | 
					            item->short_description,
 | 
				
			||||||
 | 
					            sizeof (item->short_description));
 | 
				
			||||||
 | 
					    memcpy (_item->description,
 | 
				
			||||||
 | 
					            item->description,
 | 
				
			||||||
 | 
					            sizeof (item->description));
 | 
				
			||||||
 | 
					    return _item;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void
 | 
				
			||||||
 | 
					prepend_item (XklConfigRegistry   *registry,
 | 
				
			||||||
 | 
					              const XklConfigItem *item,
 | 
				
			||||||
 | 
					              gpointer             data)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    GSList **list = data;
 | 
				
			||||||
 | 
					    XklConfigItem *_item = xkl_config_item_copy (item);
 | 
				
			||||||
 | 
					    *list = g_slist_prepend (*list, _item);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static gint
 | 
				
			||||||
 | 
					compare_item_by_name (gconstpointer a, gconstpointer b)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    const XklConfigItem *ia = a, *ib = b;
 | 
				
			||||||
 | 
					    return g_strcmp0 (ia->name, ib->name);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					GSList *
 | 
				
			||||||
 | 
					eekboard_xkl_list_models (XklConfigRegistry *registry)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    GSList *list = NULL;
 | 
				
			||||||
 | 
					    xkl_config_registry_foreach_model (registry, prepend_item, &list);
 | 
				
			||||||
 | 
					    return g_slist_sort (list, compare_item_by_name);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					GSList *
 | 
				
			||||||
 | 
					eekboard_xkl_list_layouts (XklConfigRegistry *registry)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    GSList *list = NULL;
 | 
				
			||||||
 | 
					    xkl_config_registry_foreach_layout (registry, prepend_item, &list);
 | 
				
			||||||
 | 
					    return g_slist_sort (list, compare_item_by_name);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					GSList *
 | 
				
			||||||
 | 
					eekboard_xkl_list_option_groups (XklConfigRegistry *registry)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    GSList *list = NULL;
 | 
				
			||||||
 | 
					    xkl_config_registry_foreach_option_group (registry, prepend_item, &list);
 | 
				
			||||||
 | 
					    return g_slist_sort (list, compare_item_by_name);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					GSList *
 | 
				
			||||||
 | 
					eekboard_xkl_list_layout_variants (XklConfigRegistry *registry,
 | 
				
			||||||
 | 
					                                   const gchar       *layout)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    GSList *list = NULL;
 | 
				
			||||||
 | 
					    xkl_config_registry_foreach_layout_variant (registry,
 | 
				
			||||||
 | 
					                                                layout,
 | 
				
			||||||
 | 
					                                                prepend_item,
 | 
				
			||||||
 | 
					                                                &list);
 | 
				
			||||||
 | 
					    return g_slist_sort (list, compare_item_by_name);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					GSList *
 | 
				
			||||||
 | 
					eekboard_xkl_list_options (XklConfigRegistry *registry,
 | 
				
			||||||
 | 
					                           const gchar       *group)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    GSList *list = NULL;
 | 
				
			||||||
 | 
					    xkl_config_registry_foreach_option (registry, group, prepend_item, &list);
 | 
				
			||||||
 | 
					    return g_slist_sort (list, compare_item_by_name);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										39
									
								
								src/xklutil.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								src/xklutil.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,39 @@
 | 
				
			|||||||
 | 
					/* 
 | 
				
			||||||
 | 
					 * Copyright (C) 2011 Daiki Ueno <ueno@unixuser.org>
 | 
				
			||||||
 | 
					 * Copyright (C) 2011 Red Hat, Inc.
 | 
				
			||||||
 | 
					 * 
 | 
				
			||||||
 | 
					 * This library is free software; you can redistribute it and/or
 | 
				
			||||||
 | 
					 * modify it under the terms of the GNU Lesser General Public License
 | 
				
			||||||
 | 
					 * as published by the Free Software Foundation; either version 2 of
 | 
				
			||||||
 | 
					 * the License, or (at your option) any later version.
 | 
				
			||||||
 | 
					 * 
 | 
				
			||||||
 | 
					 * This library is distributed in the hope that it will be useful, but
 | 
				
			||||||
 | 
					 * WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
				
			||||||
 | 
					 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 | 
				
			||||||
 | 
					 * Lesser General Public License for more details.
 | 
				
			||||||
 | 
					 * 
 | 
				
			||||||
 | 
					 * You should have received a copy of the GNU Lesser General Public
 | 
				
			||||||
 | 
					 * License along with this library; if not, write to the Free Software
 | 
				
			||||||
 | 
					 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 | 
				
			||||||
 | 
					 * 02110-1301 USA
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					#ifndef EEKBOARD_XKLUTIL_H
 | 
				
			||||||
 | 
					#define EEKBOARD_XKLUTIL_H 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <libxklavier/xklavier.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					G_BEGIN_DECLS
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					XklConfigRec *eekboard_xkl_config_rec_new_from_string
 | 
				
			||||||
 | 
					                                                (const gchar       *layouts);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					GSList       *eekboard_xkl_list_models          (XklConfigRegistry *registry);
 | 
				
			||||||
 | 
					GSList       *eekboard_xkl_list_layouts         (XklConfigRegistry *registry);
 | 
				
			||||||
 | 
					GSList       *eekboard_xkl_list_option_groups   (XklConfigRegistry *registry);
 | 
				
			||||||
 | 
					GSList       *eekboard_xkl_list_layout_variants (XklConfigRegistry *registry,
 | 
				
			||||||
 | 
					                                                 const gchar       *layout);
 | 
				
			||||||
 | 
					GSList       *eekboard_xkl_list_options         (XklConfigRegistry *registry,
 | 
				
			||||||
 | 
					                                                 const gchar       *group);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					G_END_DECLS
 | 
				
			||||||
 | 
					#endif  /* EEKBOARD_XKLUTIL_H */
 | 
				
			||||||
@ -17,26 +17,42 @@
 | 
				
			|||||||
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 | 
					 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 | 
				
			||||||
 * 02110-1301 USA
 | 
					 * 02110-1301 USA
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
#include <stdlib.h>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef HAVE_CONFIG_H
 | 
					#ifdef HAVE_CONFIG_H
 | 
				
			||||||
#include "config.h"
 | 
					#include "config.h"
 | 
				
			||||||
#endif  /* HAVE_CONFIG_H */
 | 
					#endif  /* HAVE_CONFIG_H */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <string.h>
 | 
				
			||||||
 | 
					#include <stdlib.h>
 | 
				
			||||||
 | 
					#include <gdk/gdkx.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "eek/eek-xml.h"
 | 
					#include "eek/eek-xml.h"
 | 
				
			||||||
#include "eek/eek-xkl.h"
 | 
					#include "eek/eek-xkl.h"
 | 
				
			||||||
#include "eek/eek-gtk.h"
 | 
					#include "eek/eek-gtk.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "xklutil.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define BUFSIZE 8192
 | 
					#define BUFSIZE 8192
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static gchar *opt_load = NULL;
 | 
					static gchar *opt_load = NULL;
 | 
				
			||||||
static gboolean opt_dump = FALSE;
 | 
					static gboolean opt_dump = FALSE;
 | 
				
			||||||
 | 
					static gchar *opt_model = NULL;
 | 
				
			||||||
 | 
					static gchar *opt_layouts = NULL;
 | 
				
			||||||
 | 
					static gchar *opt_options = NULL;
 | 
				
			||||||
 | 
					static gchar *opt_list = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const GOptionEntry options[] = {
 | 
					static const GOptionEntry options[] = {
 | 
				
			||||||
    {"load", 'l', 0, G_OPTION_ARG_STRING, &opt_load,
 | 
					    {"load", 'l', 0, G_OPTION_ARG_STRING, &opt_load,
 | 
				
			||||||
     "Show the keyboard loaded from an XML file"},
 | 
					     "Show the keyboard loaded from an XML file"},
 | 
				
			||||||
    {"dump", 'd', 0, G_OPTION_ARG_NONE, &opt_dump,
 | 
					    {"dump", 'd', 0, G_OPTION_ARG_NONE, &opt_dump,
 | 
				
			||||||
     "Dump the current layout as XML"},
 | 
					     "Dump the current layout as XML"},
 | 
				
			||||||
 | 
					    {"list", 'L', 0, G_OPTION_ARG_STRING, &opt_list,
 | 
				
			||||||
 | 
					     "List configuration items for given spec"},
 | 
				
			||||||
 | 
					    {"model", '\0', 0, G_OPTION_ARG_STRING, &opt_model,
 | 
				
			||||||
 | 
					     "Specify model"},
 | 
				
			||||||
 | 
					    {"layouts", '\0', 0, G_OPTION_ARG_STRING, &opt_layouts,
 | 
				
			||||||
 | 
					     "Specify layouts"},
 | 
				
			||||||
 | 
					    {"options", '\0', 0, G_OPTION_ARG_STRING, &opt_options,
 | 
				
			||||||
 | 
					     "Specify options"},
 | 
				
			||||||
    {NULL}
 | 
					    {NULL}
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -46,6 +62,15 @@ on_destroy (gpointer user_data)
 | 
				
			|||||||
    gtk_main_quit ();
 | 
					    gtk_main_quit ();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void
 | 
				
			||||||
 | 
					print_item (gpointer data,
 | 
				
			||||||
 | 
					            gpointer user_data)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    XklConfigItem *item = data;
 | 
				
			||||||
 | 
					    g_assert (item);
 | 
				
			||||||
 | 
					    printf ("%s: %s\n", item->name, item->description);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int
 | 
					int
 | 
				
			||||||
main (int argc, char **argv)
 | 
					main (int argc, char **argv)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@ -106,6 +131,26 @@ main (int argc, char **argv)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        output = g_string_sized_new (BUFSIZE);
 | 
					        output = g_string_sized_new (BUFSIZE);
 | 
				
			||||||
        layout = eek_xkl_layout_new ();
 | 
					        layout = eek_xkl_layout_new ();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (opt_model)
 | 
				
			||||||
 | 
					            eek_xkl_layout_set_model (EEK_XKL_LAYOUT(layout), opt_model);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (opt_layouts) {
 | 
				
			||||||
 | 
					            XklConfigRec *rec;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            rec = eekboard_xkl_config_rec_new_from_string (opt_layouts);
 | 
				
			||||||
 | 
					            eek_xkl_layout_set_layouts (EEK_XKL_LAYOUT(layout), rec->layouts);
 | 
				
			||||||
 | 
					            eek_xkl_layout_set_variants (EEK_XKL_LAYOUT(layout), rec->variants);
 | 
				
			||||||
 | 
					            g_object_unref (rec);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (opt_options) {
 | 
				
			||||||
 | 
					            gchar **options;
 | 
				
			||||||
 | 
					            options = g_strsplit (opt_options, ",", -1);
 | 
				
			||||||
 | 
					            eek_xkl_layout_set_options (EEK_XKL_LAYOUT(layout), options);
 | 
				
			||||||
 | 
					            g_strfreev (options);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        keyboard = eek_keyboard_new (layout, 640, 480);
 | 
					        keyboard = eek_keyboard_new (layout, 640, 480);
 | 
				
			||||||
        g_object_unref (layout);
 | 
					        g_object_unref (layout);
 | 
				
			||||||
        eek_keyboard_output (keyboard, output, 0);
 | 
					        eek_keyboard_output (keyboard, output, 0);
 | 
				
			||||||
@ -113,8 +158,43 @@ main (int argc, char **argv)
 | 
				
			|||||||
        fwrite (output->str, sizeof(gchar), output->len, stdout);
 | 
					        fwrite (output->str, sizeof(gchar), output->len, stdout);
 | 
				
			||||||
        g_string_free (output, TRUE);
 | 
					        g_string_free (output, TRUE);
 | 
				
			||||||
        exit (0);
 | 
					        exit (0);
 | 
				
			||||||
 | 
					    } else if (opt_list) {
 | 
				
			||||||
 | 
					        GdkDisplay *display;
 | 
				
			||||||
 | 
					        XklEngine *engine;
 | 
				
			||||||
 | 
					        XklConfigRegistry *registry;
 | 
				
			||||||
 | 
					        GSList *items = NULL, *head;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        display = gdk_display_get_default ();
 | 
				
			||||||
 | 
					        engine = xkl_engine_get_instance (GDK_DISPLAY_XDISPLAY(display));
 | 
				
			||||||
 | 
					        registry = xkl_config_registry_get_instance (engine);
 | 
				
			||||||
 | 
					        xkl_config_registry_load (registry, FALSE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (g_strcmp0 (opt_list, "model") == 0) {
 | 
				
			||||||
 | 
					            items = eekboard_xkl_list_models (registry);
 | 
				
			||||||
 | 
					        } else if (g_strcmp0 (opt_list, "layout") == 0) {
 | 
				
			||||||
 | 
					            items = eekboard_xkl_list_layouts (registry);
 | 
				
			||||||
 | 
					        } else if (g_strcmp0 (opt_list, "option-group") == 0) {
 | 
				
			||||||
 | 
					            items = eekboard_xkl_list_option_groups (registry);
 | 
				
			||||||
 | 
					        } else if (g_str_has_prefix (opt_list, "layout-variant-")) {
 | 
				
			||||||
 | 
					            items =  eekboard_xkl_list_layout_variants
 | 
				
			||||||
 | 
					                (registry,
 | 
				
			||||||
 | 
					                 opt_list + strlen ("layout-variant-"));
 | 
				
			||||||
 | 
					        } else if (g_str_has_prefix (opt_list, "option-")) {
 | 
				
			||||||
 | 
					            items = eekboard_xkl_list_options
 | 
				
			||||||
 | 
					                (registry,
 | 
				
			||||||
 | 
					                 opt_list + strlen ("option-"));
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            g_printerr ("Unknown list spec \"%s\"\n", opt_list);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        g_slist_foreach (items, print_item, NULL);
 | 
				
			||||||
 | 
					        for (head = items; head; head = g_slist_next (head))
 | 
				
			||||||
 | 
					            g_object_unref (head->data);
 | 
				
			||||||
 | 
					        g_slist_free (items);
 | 
				
			||||||
 | 
					        g_object_unref (engine);
 | 
				
			||||||
 | 
					        g_object_unref (registry);
 | 
				
			||||||
 | 
					        exit (0);
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        g_printerr ("Specify -l or -d option\n");
 | 
					        g_printerr ("Specify -l, -d, or -L option\n");
 | 
				
			||||||
        exit (1);
 | 
					        exit (1);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user