gnome-control-center/capplets/keyboard/gnome-keyboard-properties-xkbpv.c

121 lines
4 KiB
C
Raw Normal View History

2004-07-13 23:11:34 +00:00
/* -*- mode: c; style: linux -*- */
/* gnome-keyboard-properties-xkb.c
* Copyright (C) 2003 Sergey V. Oudaltsov
*
* Written by: Sergey V. Oudaltsov <svu@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <gnome.h>
#include <glade/glade.h>
2005-01-02 01:59:28 +00:00
#include "libgswitchit/gswitchit_config.h"
2004-07-13 23:11:34 +00:00
#include "capplet-util.h"
#include "gnome-keyboard-properties-xkb.h"
#include "libkbdraw/keyboard-drawing.h"
2005-01-02 01:59:28 +00:00
#ifdef HAVE_X11_EXTENSIONS_XKB_H
#include "X11/XKBlib.h"
/**
* BAD STYLE: Taken from xklavier_private_xkb.h
* Any ideas on architectural improvements are WELCOME
*/
2006-04-19 23:30:05 +00:00
extern gboolean xkl_xkb_config_native_prepare (XklEngine * engine,
const XklConfigRec * data,
XkbComponentNamesPtr component_names);
extern void xkl_xkb_config_native_cleanup (XklEngine * engine,
XkbComponentNamesPtr component_names);
2005-01-02 01:59:28 +00:00
/* */
#endif
2004-07-26 23:07:03 +00:00
2005-04-10 02:19:13 +00:00
static KeyboardDrawingGroupLevel groupsLevels[] = {{0,1},{0,3},{0,0},{0,2}};
2004-12-31 00:52:49 +00:00
static KeyboardDrawingGroupLevel * pGroupsLevels[] = {
groupsLevels, groupsLevels+1, groupsLevels+2, groupsLevels+3 };
GtkWidget*
2005-01-02 01:59:28 +00:00
xkb_layout_preview_create_widget (GladeXML * chooserDialog)
2004-12-31 00:52:49 +00:00
{
GtkWidget *kbdraw = keyboard_drawing_new ();
keyboard_drawing_set_groups_levels (KEYBOARD_DRAWING (kbdraw), pGroupsLevels);
return kbdraw;
}
2004-07-26 23:07:03 +00:00
void
2005-01-02 01:59:28 +00:00
xkb_layout_preview_update (GladeXML * chooserDialog)
2004-07-26 23:07:03 +00:00
{
2005-01-02 01:59:28 +00:00
#ifdef HAVE_X11_EXTENSIONS_XKB_H
GtkWidget *chooser = CWID ( "xkb_layout_chooser");
GtkWidget *availableLayoutsTree = CWID ("xkb_layouts_available");
GtkTreeSelection *selection =
gtk_tree_view_get_selection (GTK_TREE_VIEW (availableLayoutsTree));
GtkTreeIter selectedIter;
GtkTreeModel *model;
GtkWidget *kbdraw = GTK_WIDGET (g_object_get_data (G_OBJECT (chooser), "kbdraw"));
if (kbdraw != NULL &&
gtk_tree_selection_get_selected (selection, &model, &selectedIter))
2004-10-15 22:43:13 +00:00
{
2005-01-02 01:59:28 +00:00
gchar *id;
2006-04-19 23:30:05 +00:00
XklConfigRec *data;
2005-01-02 01:59:28 +00:00
char **p, *layout, *variant;
XkbComponentNamesRec componentNames;
gtk_tree_model_get (model, &selectedIter, AVAIL_LAYOUT_TREE_COL_ID, &id, -1);
2006-04-19 23:30:05 +00:00
data = xkl_config_rec_new ();
if (xkl_config_rec_get_from_server (data, engine))
2005-01-02 01:59:28 +00:00
{
2006-04-19 23:30:05 +00:00
if( ( p = data->layouts ) != NULL )
g_strfreev(data->layouts);
2005-01-02 01:59:28 +00:00
2006-04-19 23:30:05 +00:00
if( ( p = data->variants ) != NULL )
g_strfreev(data->variants);
2005-07-27 22:50:42 +00:00
2006-04-19 23:30:05 +00:00
data->layouts = g_realloc (data->layouts, sizeof (char*) * 2);
data->variants = g_realloc (data->variants, sizeof (char*) * 2);
2005-01-02 01:59:28 +00:00
if (GSwitchItKbdConfigSplitItems (id, &layout, &variant)
&& variant != NULL)
{
2006-04-19 23:30:05 +00:00
data->layouts[0] = (layout == NULL) ? NULL : g_strdup (layout);
data->variants[0] = (variant == NULL) ? NULL : g_strdup (variant);
2005-01-02 01:59:28 +00:00
} else
{
2006-04-19 23:30:05 +00:00
data->layouts[0] = (id == NULL) ? NULL : g_strdup (id);
data->variants[0] = NULL;
2005-01-02 01:59:28 +00:00
}
2006-04-19 23:30:05 +00:00
data->layouts[1] = data->variants[1] = NULL;
if (xkl_xkb_config_native_prepare (engine, data, &componentNames))
2005-01-02 01:59:28 +00:00
{
keyboard_drawing_set_keyboard (KEYBOARD_DRAWING (kbdraw), &componentNames);
2006-04-19 23:30:05 +00:00
xkl_xkb_config_native_cleanup (engine, &componentNames);
2005-01-02 01:59:28 +00:00
}
}
2006-04-19 23:30:05 +00:00
g_object_unref (G_OBJECT (data));
2004-10-15 22:43:13 +00:00
}
2005-01-02 01:59:28 +00:00
#endif
2004-07-13 23:11:34 +00:00
}