summaryrefslogtreecommitdiff
path: root/capplets/accessibility/keyboard/gnome-accessibility-keyboard-properties.c
blob: 8646e3d697b66d40698f604d50f550df3ef59438 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/* -*- mode: c; style: linux -*- */

/* gnome-accessibility-keyboard-properties.c
 * Copyright (C) 2002 Ximian, Inc.
 *
 * Written by: Jody Goldberg <jody@gnome.org>
 *
 * 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 <gconf/gconf-client.h>

#include <capplet-util.h>
#include <activate-settings-daemon.h>
#include "accessibility-keyboard.h"

#ifdef HAVE_X11_EXTENSIONS_XKB_H
#  include <X11/X.h>
#  include <X11/Xlib.h>
#  include <X11/XKBlib.h>
#  include <X11/extensions/XKBstr.h>
#  include <gdk/gdk.h>
#  include <gdk/gdkx.h>

static void
xkb_enabled (void)
{
	gboolean have_xkb = FALSE;
	int opcode, errorBase, major, minor, xkbEventBase;

	gdk_error_trap_push ();
	have_xkb = XkbQueryExtension (GDK_DISPLAY (),
				      &opcode, &xkbEventBase, &errorBase, &major, &minor)
		&& XkbUseExtension (GDK_DISPLAY (), &major, &minor);
	XSync (GDK_DISPLAY (), FALSE);
	gdk_error_trap_pop ();

	if (!have_xkb) {
		GtkWidget *warn = gtk_message_dialog_new (NULL, 0,
		      GTK_MESSAGE_WARNING, GTK_BUTTONS_CLOSE,
		      _("This system does not seem to have the XKB extension.  The keyboard accessibility features will not operate without it."));
		gtk_dialog_run (GTK_DIALOG (warn));
		gtk_widget_destroy (warn);
	}
}
#endif

static void
dialog_response (GtkWidget *widget,
		 gint       response_id,
		 GConfChangeSet *changeset)
{
	switch (response_id) {
	case GTK_RESPONSE_HELP:
		capplet_help (GTK_WINDOW (widget),
			      "user-guide.xml",
			      "goscustaccess-6");
		break;
	case GTK_RESPONSE_DELETE_EVENT:
	case GTK_RESPONSE_CLOSE:
		gtk_main_quit ();
		break;
	default:
		/* Import CDE AccessX File */
		break;
	}
}

int
main (int argc, char **argv) 
{
	GtkWidget *dialog;
	GConfChangeSet *changeset;
	bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);

	gnome_program_init ("gnome-accessibility-keyboard-properties", VERSION,
			    LIBGNOMEUI_MODULE, argc, argv,
			    GNOME_PARAM_APP_DATADIR, GNOMECC_DATA_DIR,
			    NULL);
	activate_settings_daemon ();

#ifdef HAVE_X11_EXTENSIONS_XKB_H
	xkb_enabled ();
#endif

	changeset = NULL;
	dialog = setup_accessX_dialog (changeset);
	g_signal_connect (G_OBJECT (dialog),
		"response",
		G_CALLBACK (dialog_response), changeset);
	capplet_set_icon (dialog, "gnome-settings-accessibility-keyboard");
	gtk_widget_show_all (dialog);
	gtk_main ();

	return 0;
}