~ubuntu-branches/debian/jessie/mate-control-center/jessie

« back to all changes in this revision

Viewing changes to capplets/keyboard/mate-keyboard-properties-xkbpv.c

  • Committer: Package Import Robot
  • Author(s): Mike Gabriel
  • Date: 2014-05-02 23:20:06 UTC
  • Revision ID: package-import@ubuntu.com-20140502232006-9626h14ggaz2hc9h
Tags: upstream-1.8.1+dfsg1
ImportĀ upstreamĀ versionĀ 1.8.1+dfsg1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: c; style: linux -*- */
 
2
 
 
3
/* mate-keyboard-properties-xkbpv.c
 
4
 * Copyright (C) 2003-2007 Sergey V. Udaltsov
 
5
 *
 
6
 * Written by: Sergey V. Udaltsov <svu@gnome.org>
 
7
 *
 
8
 * This program is free software; you can redistribute it and/or modify
 
9
 * it under the terms of the GNU General Public License as published by
 
10
 * the Free Software Foundation; either version 2, or (at your option)
 
11
 * any later version.
 
12
 *
 
13
 * This program is distributed in the hope that it will be useful,
 
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
 * GNU General Public License for more details.
 
17
 *
 
18
 * You should have received a copy of the GNU General Public License
 
19
 * along with this program; if not, write to the Free Software
 
20
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 
21
 * 02110-1301, USA.
 
22
 */
 
23
 
 
24
#ifdef HAVE_CONFIG_H
 
25
#  include <config.h>
 
26
#endif
 
27
 
 
28
#include <libmatekbd/matekbd-keyboard-drawing.h>
 
29
 
 
30
#include "capplet-util.h"
 
31
#include "mate-keyboard-properties-xkb.h"
 
32
 
 
33
#ifdef HAVE_X11_EXTENSIONS_XKB_H
 
34
#include "X11/XKBlib.h"
 
35
/**
 
36
 * BAD STYLE: Taken from xklavier_private_xkb.h
 
37
 * Any ideas on architectural improvements are WELCOME
 
38
 */
 
39
extern gboolean xkl_xkb_config_native_prepare (XklEngine * engine,
 
40
                                               const XklConfigRec * data,
 
41
                                               XkbComponentNamesPtr
 
42
                                               component_names);
 
43
 
 
44
extern void xkl_xkb_config_native_cleanup (XklEngine * engine,
 
45
                                           XkbComponentNamesPtr
 
46
                                           component_names);
 
47
 
 
48
/* */
 
49
#endif
 
50
 
 
51
static MatekbdKeyboardDrawingGroupLevel groupsLevels[] =
 
52
    { {0, 1}, {0, 3}, {0, 0}, {0, 2} };
 
53
static MatekbdKeyboardDrawingGroupLevel *pGroupsLevels[] = {
 
54
        groupsLevels, groupsLevels + 1, groupsLevels + 2, groupsLevels + 3
 
55
};
 
56
 
 
57
GtkWidget *
 
58
xkb_layout_preview_create_widget (GtkBuilder * chooserDialog)
 
59
{
 
60
        GtkWidget *kbdraw = matekbd_keyboard_drawing_new ();
 
61
 
 
62
        matekbd_keyboard_drawing_set_groups_levels (MATEKBD_KEYBOARD_DRAWING
 
63
                                                 (kbdraw), pGroupsLevels);
 
64
        return kbdraw;
 
65
}
 
66
 
 
67
void
 
68
xkb_layout_preview_update (GtkBuilder * chooser_dialog)
 
69
{
 
70
#ifdef HAVE_X11_EXTENSIONS_XKB_H
 
71
        GtkWidget *chooser = CWID ("xkb_layout_chooser");
 
72
        GtkWidget *kbdraw =
 
73
            GTK_WIDGET (g_object_get_data (G_OBJECT (chooser), "kbdraw"));
 
74
        gchar *id = xkb_layout_chooser_get_selected_id (chooser_dialog);
 
75
        xkb_layout_preview_set_drawing_layout (kbdraw, id);
 
76
        g_free (id);
 
77
#endif
 
78
}
 
79
 
 
80
void
 
81
xkb_layout_preview_set_drawing_layout (GtkWidget * kbdraw,
 
82
                                       const gchar * id)
 
83
{
 
84
#ifdef HAVE_X11_EXTENSIONS_XKB_H
 
85
        if (kbdraw != NULL) {
 
86
                if (id != NULL) {
 
87
                        XklConfigRec *data;
 
88
                        char **p, *layout, *variant;
 
89
                        XkbComponentNamesRec component_names;
 
90
 
 
91
                        data = xkl_config_rec_new ();
 
92
                        if (xkl_config_rec_get_from_server (data, engine)) {
 
93
                                if ((p = data->layouts) != NULL)
 
94
                                        g_strfreev (data->layouts);
 
95
 
 
96
                                if ((p = data->variants) != NULL)
 
97
                                        g_strfreev (data->variants);
 
98
 
 
99
                                data->layouts = g_new0 (char *, 2);
 
100
                                data->variants = g_new0 (char *, 2);
 
101
                                if (matekbd_keyboard_config_split_items
 
102
                                    (id, &layout, &variant)
 
103
                                    && variant != NULL) {
 
104
                                        data->layouts[0] =
 
105
                                            (layout ==
 
106
                                             NULL) ? NULL :
 
107
                                            g_strdup (layout);
 
108
                                        data->variants[0] =
 
109
                                            (variant ==
 
110
                                             NULL) ? NULL :
 
111
                                            g_strdup (variant);
 
112
                                } else {
 
113
                                        data->layouts[0] =
 
114
                                            (id ==
 
115
                                             NULL) ? NULL : g_strdup (id);
 
116
                                        data->variants[0] = NULL;
 
117
                                }
 
118
 
 
119
                                if (xkl_xkb_config_native_prepare
 
120
                                    (engine, data, &component_names)) {
 
121
                                        matekbd_keyboard_drawing_set_keyboard
 
122
                                            (MATEKBD_KEYBOARD_DRAWING
 
123
                                             (kbdraw), &component_names);
 
124
 
 
125
                                        xkl_xkb_config_native_cleanup
 
126
                                            (engine, &component_names);
 
127
                                }
 
128
                        }
 
129
                        g_object_unref (G_OBJECT (data));
 
130
                } else
 
131
                        matekbd_keyboard_drawing_set_keyboard
 
132
                            (MATEKBD_KEYBOARD_DRAWING (kbdraw), NULL);
 
133
 
 
134
        }
 
135
#endif
 
136
}