summaryrefslogtreecommitdiff
path: root/gnome-settings-daemon/gnome-settings-accessibility-keyboard.c
blob: b89ea528deee6e9e06499ac7aba94278625d8e71 (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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
/* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/* gnome-settings-keyboard.c
 *
 * Copyright © 2001 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.
 */

#include "config.h"

#include <glib/gi18n.h>
#include <gdk/gdk.h>
#include <gdk/gdkx.h>
#include <gtk/gtk.h>

#include <gconf/gconf-client.h>
#include <libgnome/gnome-help.h>

#include "gnome-settings-accessibility-keyboard.h"
#include "gnome-settings-daemon.h"

#ifdef HAVE_X11_EXTENSIONS_XKB_H
#  include <X11/XKBlib.h>
#  include <X11/extensions/XKBstr.h>

#define CONFIG_ROOT "/desktop/gnome/accessibility/keyboard"

#undef DEBUG_ACCESSIBILITY
#ifdef DEBUG_ACCESSIBILITY
#define d(str)		fprintf (stderr, str)
#else
#define d(str)		do { } while (0)
#endif

static int xkbEventBase;
static GtkWidget *ax_slowkeys_dialog = NULL;
static GtkWidget *ax_slowkeys_dialog_hbox = NULL;
static GtkWidget *ax_stickykeys_dialog = NULL;
static GtkWidget *ax_stickykeys_dialog_hbox = NULL;
static gboolean  stickykeys_shortcut_val;
static gboolean  slowkeys_shortcut_val;

static gboolean
xkb_enabled (void)
{
	static gboolean initialized = 0;
	static gboolean have_xkb = 0;

	int opcode, errorBase, major, minor;

	if (initialized)
		return have_xkb;

	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 ();

	return have_xkb;
}

static XkbDescRec *
get_xkb_desc_rec (void)
{
	XkbDescRec *desc;
	Status	    status = Success; /* Any bogus value, to suppress warning */

	if (!xkb_enabled ())
		return NULL;

	gdk_error_trap_push ();
	desc = XkbGetMap (GDK_DISPLAY (), XkbAllMapComponentsMask, XkbUseCoreKbd);
	if (desc != NULL) {
		desc->ctrls = NULL;
		status = XkbGetControls (GDK_DISPLAY (), XkbAllControlsMask, desc);
	}
	XSync (GDK_DISPLAY (), FALSE);
	gdk_error_trap_pop ();

	g_return_val_if_fail (desc != NULL, NULL);
	g_return_val_if_fail (desc->ctrls != NULL, NULL);
	g_return_val_if_fail (status == Success, NULL);

	return desc;
}

static int
get_int (GConfClient *client, char const *key)
{
	int res = gconf_client_get_int  (client, key, NULL);
	if (res <= 0)
		res = 1;
	return res;
}

static gboolean
set_int (GConfClient *client, GConfChangeSet *cs,
	 char const *key, int val)
{
	gconf_change_set_set_int (cs, key, val);
#ifdef DEBUG_ACCESSIBILITY	
		if (val != gconf_client_get_int (client, key, NULL)) {
			g_warning ("%s changed", key);
		}
#endif
	return val != gconf_client_get_int (client, key, NULL);
}

static gboolean
set_bool (GConfClient *client, GConfChangeSet *cs,
	  gboolean in_gconf, char const *key, int val)
{
	gboolean bval = (val != 0);
	if (in_gconf || bval) {
		gconf_change_set_set_bool (cs, key, bval ? TRUE : FALSE);
#ifdef DEBUG_ACCESSIBILITY
		if (bval != gconf_client_get_bool (client, key, NULL)) {
			d ("%s changed", key);
			return TRUE;
		}
#endif
		return (bval != gconf_client_get_bool (client, key, NULL));
	}
	return FALSE;
}

static unsigned long
set_clear (gboolean flag, unsigned long value, unsigned long mask)
{
    if (flag)
	    return value | mask;
    return value & ~mask;
}

static gboolean
set_ctrl_from_gconf (XkbDescRec *desc, GConfClient *client,
		     char const *key, unsigned long mask, gboolean flag)
{
    gboolean result = flag && gconf_client_get_bool (client, key, NULL);
    desc->ctrls->enabled_ctrls =
	    set_clear (result, desc->ctrls->enabled_ctrls, mask);
    return result;
}

static void
set_server_from_gconf (GConfEntry *ignored)
{
	GConfClient	*client = gconf_client_get_default ();
	XkbDescRec	*desc;
	gboolean	 enable_accessX;

	desc = get_xkb_desc_rec ();
	if (!desc) {
		d ("No XKB present\n");
		return;
	}

	/* general */
	enable_accessX = gconf_client_get_bool (client, CONFIG_ROOT "/enable", NULL);

	desc->ctrls->enabled_ctrls = set_clear (enable_accessX,
		desc->ctrls->enabled_ctrls,
		XkbAccessXKeysMask | XkbAccessXFeedbackMask);

	if (set_ctrl_from_gconf (desc, client, CONFIG_ROOT "/timeout_enable",
		XkbAccessXTimeoutMask, enable_accessX)) {
		desc->ctrls->ax_timeout = get_int (client,
			CONFIG_ROOT "/timeout");
		/* disable only the master flag via the server we will disable
		 * the rest on the rebound without affecting gconf state
		 * don't change the option flags at all.
		 */
		desc->ctrls->axt_ctrls_mask = \
			XkbAccessXKeysMask	|
			XkbAccessXFeedbackMask;
		desc->ctrls->axt_ctrls_values = 0;
		desc->ctrls->axt_opts_mask = 0;
	}

	desc->ctrls->ax_options = set_clear (enable_accessX &&
		gconf_client_get_bool (client, CONFIG_ROOT "/feature_state_change_beep", NULL),
		desc->ctrls->ax_options, XkbAX_FeatureFBMask | XkbAX_SlowWarnFBMask);

	/* bounce keys */
	if (set_ctrl_from_gconf (desc, client, CONFIG_ROOT "/bouncekeys_enable",
		XkbBounceKeysMask, enable_accessX)) {
		desc->ctrls->debounce_delay  = get_int (client,
			CONFIG_ROOT "/bouncekeys_delay");
		desc->ctrls->ax_options = set_clear (
			gconf_client_get_bool (client, CONFIG_ROOT "/bouncekeys_beep_reject", NULL),
			desc->ctrls->ax_options, XkbAX_BKRejectFBMask);
	}

	/* mouse keys */
	if (set_ctrl_from_gconf (desc, client, CONFIG_ROOT "/mousekeys_enable",
		XkbMouseKeysMask | XkbMouseKeysAccelMask, enable_accessX)) {
		desc->ctrls->mk_interval     = 100;	/* msec between mousekey events */
		desc->ctrls->mk_curve	     = 50;

		/* We store pixels / sec, XKB wants pixels / event */
		desc->ctrls->mk_max_speed    = get_int (client,
			CONFIG_ROOT "/mousekeys_max_speed") / (1000 / desc->ctrls->mk_interval);
		if (desc->ctrls->mk_max_speed <= 0)
			desc->ctrls->mk_max_speed = 1;

		desc->ctrls->mk_time_to_max  = get_int (client,	/* events before max */
			CONFIG_ROOT "/mousekeys_accel_time") / desc->ctrls->mk_interval;
		if (desc->ctrls->mk_time_to_max <= 0)
			desc->ctrls->mk_time_to_max = 1;

		desc->ctrls->mk_delay	     = get_int (client,	/* ms before 1st event */
			CONFIG_ROOT "/mousekeys_init_delay");
	}

	/* slow keys */
	if (set_ctrl_from_gconf (desc, client, CONFIG_ROOT "/slowkeys_enable",
		XkbSlowKeysMask, enable_accessX)) {
		desc->ctrls->ax_options = set_clear (
			gconf_client_get_bool (client, CONFIG_ROOT "/slowkeys_beep_press", NULL),
			desc->ctrls->ax_options, XkbAX_SKPressFBMask);
		desc->ctrls->ax_options = set_clear (
			gconf_client_get_bool (client, CONFIG_ROOT "/slowkeys_beep_accept", NULL),
			desc->ctrls->ax_options, XkbAX_SKAcceptFBMask);
		desc->ctrls->ax_options = set_clear (
			gconf_client_get_bool (client, CONFIG_ROOT "/slowkeys_beep_reject", NULL),
			desc->ctrls->ax_options, XkbAX_SKRejectFBMask);
		desc->ctrls->slow_keys_delay = get_int (client,
			CONFIG_ROOT "/slowkeys_delay");
		/* anything larger than 500 seems to loose all keyboard input */
		if (desc->ctrls->slow_keys_delay > 500)
			desc->ctrls->slow_keys_delay = 500;
	}

	/* sticky keys */
	if (set_ctrl_from_gconf (desc, client, CONFIG_ROOT "/stickykeys_enable",
		XkbStickyKeysMask, enable_accessX)) {
		desc->ctrls->ax_options |= XkbAX_LatchToLockMask;
		desc->ctrls->ax_options = set_clear (
			gconf_client_get_bool (client, CONFIG_ROOT "/stickykeys_two_key_off", NULL),
			desc->ctrls->ax_options, XkbAX_TwoKeysMask);
		desc->ctrls->ax_options = set_clear (
			gconf_client_get_bool (client, CONFIG_ROOT "/stickykeys_modifier_beep", NULL),
			desc->ctrls->ax_options, XkbAX_StickyKeysFBMask);
	}

	/* toggle keys */
	desc->ctrls->ax_options = set_clear (enable_accessX &&
		gconf_client_get_bool (client, CONFIG_ROOT "/togglekeys_enable", NULL),
		desc->ctrls->ax_options, XkbAX_IndicatorFBMask);

	/*
	fprintf (stderr, "CHANGE to : 0x%x\n", desc->ctrls->enabled_ctrls);
	fprintf (stderr, "CHANGE to : 0x%x (2)\n", desc->ctrls->ax_options);
	*/

	gdk_error_trap_push ();
	XkbSetControls (GDK_DISPLAY (),
			XkbSlowKeysMask		|
			XkbBounceKeysMask	|
			XkbStickyKeysMask	|
			XkbMouseKeysMask	|
			XkbMouseKeysAccelMask	|
			XkbAccessXKeysMask	|
			XkbAccessXTimeoutMask	|
			XkbAccessXFeedbackMask	|
			XkbControlsEnabledMask,
			desc);

	XkbFreeKeyboard (desc, XkbAllComponentsMask, True);

	XSync (GDK_DISPLAY (), FALSE);
	gdk_error_trap_pop ();

	g_object_unref (client);
}

static gboolean
ax_response_callback (gint response_id, guint revert_controls_mask, gboolean enabled)
{
	GError *err = NULL;
	gboolean success;

	switch (response_id)
	{
	    case GTK_RESPONSE_REJECT:
	    case GTK_RESPONSE_CANCEL:
		{
		    GConfClient *client = gconf_client_get_default ();

		    /* we're reverting, so we invert sense of 'enabled' flag */
		    d ("cancelling AccessX request");
		    if (revert_controls_mask == XkbStickyKeysMask)
		    {
			    success = gconf_client_set_bool (client, CONFIG_ROOT "/stickykeys_enable", !enabled, &err);
			    if (err != NULL) 
				    g_error_free (err);
		    }
		    if (revert_controls_mask == XkbSlowKeysMask)
		    {
			    success = gconf_client_set_bool (client, CONFIG_ROOT "/slowkeys_enable", !enabled, &err);
			    if (err != NULL)
				    g_error_free (err);
		    }
		    gconf_client_suggest_sync (client, NULL);
		    set_server_from_gconf (NULL);
		    break;
		}
	    case GTK_RESPONSE_HELP:
		    gnome_help_display_desktop (NULL,
						"user-guide",
						"user-guide.xml",
						"goscustaccess-6",
						&err);
		    if (err != NULL) {
			    GtkWidget *error_dialog = gtk_message_dialog_new (NULL,
									      0,
									      GTK_MESSAGE_ERROR,
									      GTK_BUTTONS_CLOSE,
									      _("There was an error displaying help: %s"), 
									      err->message);
			    g_signal_connect (G_OBJECT (error_dialog),
					      "response",
					      G_CALLBACK (gtk_widget_destroy), NULL);
			    gtk_window_set_resizable (GTK_WINDOW (error_dialog), FALSE);
			    gtk_widget_show (error_dialog);
			    g_error_free (err);
		    }
		    return FALSE;
	    default:
		    break;
	}
	return TRUE;
}

static void
ax_stickykeys_response (GtkDialog *dialog, gint response_id, gpointer data)
{
	gboolean *enabled = data;
	if (ax_response_callback (response_id, XkbStickyKeysMask, *enabled))
	{
		gtk_widget_destroy (ax_stickykeys_dialog);
		ax_stickykeys_dialog = NULL;
	}
}

static void
ax_slowkeys_response (GtkDialog *dialog, gint response_id, gpointer data)
{
	gboolean *enabled = data;
	if (ax_response_callback (response_id, XkbSlowKeysMask, *enabled))
	{
		gtk_widget_destroy (ax_slowkeys_dialog);
		ax_slowkeys_dialog = NULL;
	}
}

static GtkWidget*
warning_dialog_post (GtkWidget *dialog, GtkWidget **hbox, GCallback response, 
		     gboolean *enabled, gchar *title, gchar *user_action_string, gchar *query)
{
	GtkWidget *label;
	gchar *label_markup_string = g_strconcat ("<span weight=\"bold\" size=\"larger\">", 
						  query, "</span>\n\n", user_action_string, NULL);

	if (!dialog)
	{
		dialog = gtk_dialog_new_with_buttons (title, NULL, 0, 
						      GTK_STOCK_CANCEL,
						      GTK_RESPONSE_REJECT,
						      GTK_STOCK_HELP,
						      GTK_RESPONSE_HELP,
						      GTK_STOCK_OK,
						      GTK_RESPONSE_OK,
						      NULL);
		g_signal_connect (G_OBJECT (dialog),
				  "response",
				  G_CALLBACK (response),
				  enabled);
	}
	else
	{
		gtk_widget_destroy (*hbox);
	}
	*hbox = gtk_hbox_new (FALSE, 10);
	gtk_container_add (GTK_CONTAINER (*hbox), gtk_image_new_from_stock (GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_DIALOG));
	label = gtk_label_new (NULL);
	gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
	gtk_label_set_markup (GTK_LABEL (label), label_markup_string);
	g_free (label_markup_string);
	gtk_container_add (GTK_CONTAINER (*hbox), label);
	gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), *hbox);
	gtk_widget_show_all (dialog);

	return dialog;
}

static void
ax_slowkeys_warning_dialog_post (gboolean enabled)
{
	slowkeys_shortcut_val = enabled;
	ax_slowkeys_dialog = warning_dialog_post (ax_slowkeys_dialog,
						  &ax_slowkeys_dialog_hbox,
						  (GCallback) ax_slowkeys_response,
						  &slowkeys_shortcut_val,
						  _("Slow Keys Alert"),
						  _("You just held down the Shift key for 8 seconds.  This is the shortcut for the Slow Keys feature, which affects the way your keyboard works."),
						  enabled ? _("Do you want to activate Slow Keys?") : 
						  _("Do you want to deactivate Slow Keys?"));
}

static void
ax_stickykeys_warning_dialog_post (gboolean enabled)
{
	stickykeys_shortcut_val = enabled;
	ax_stickykeys_dialog = warning_dialog_post (ax_stickykeys_dialog,
						    &ax_stickykeys_dialog_hbox,
						    (GCallback) ax_stickykeys_response,
						    &stickykeys_shortcut_val,
						    _("Sticky Keys Alert"),
						    enabled ? _("You just pressed the Shift key 5 times in a row.  This is the shortcut for the Sticky Keys feature, which affects the way your keyboard works.") : 
						    _("You just pressed two keys at once, or pressed the Shift key 5 times in a row.  This turns off the Sticky Keys feature, which affects the way your keyboard works."),
						    enabled ? _("Do you want to activate Sticky Keys?") : 
						    _("Do you want to deactivate Sticky Keys?"));
}

static void
set_gconf_from_server (GConfEntry *ignored)
{
	gboolean	in_gconf;
	GConfClient	*client = gconf_client_get_default ();
	GConfChangeSet *cs = gconf_change_set_new ();
	XkbDescRec	*desc = get_xkb_desc_rec ();
	gboolean changed = FALSE, slowkeys_changed, stickykeys_changed;

	if (!desc) {
		d ("No XKB present\n");
		return;
	}

	/*
  	  fprintf (stderr, "changed to : 0x%x\n", desc->ctrls->enabled_ctrls);
	  fprintf (stderr, "changed to : 0x%x (2)\n", desc->ctrls->ax_options);
	*/

	/* always toggle this irrespective of the state */
	changed |= set_bool (client, cs, TRUE, CONFIG_ROOT "/enable",
		desc->ctrls->enabled_ctrls & (XkbAccessXKeysMask | XkbAccessXFeedbackMask));

	/* if master is disabled in gconf do not change gconf state of subordinates
	 * to match the server.  However, we should enable the master if one of the subordinates
	 * get enabled.
	 */
	in_gconf = gconf_client_get_bool (client, CONFIG_ROOT "/enable", NULL);

	changed |= set_bool (client, cs, in_gconf, CONFIG_ROOT "/feature_state_change_beep",
		desc->ctrls->ax_options & (XkbAX_FeatureFBMask | XkbAX_SlowWarnFBMask));
	changed |= set_bool (client, cs, in_gconf, CONFIG_ROOT "/timeout_enable",
		desc->ctrls->enabled_ctrls & XkbAccessXTimeoutMask);
	changed |= set_int (client, cs, CONFIG_ROOT "/timeout",
		desc->ctrls->ax_timeout);

	changed |= set_bool (client, cs, in_gconf, CONFIG_ROOT "/bouncekeys_enable",
		desc->ctrls->enabled_ctrls & XkbBounceKeysMask);
	changed |= set_int (client, cs, CONFIG_ROOT "/bouncekeys_delay",
		desc->ctrls->debounce_delay);
	changed |= set_bool (client, cs, TRUE, CONFIG_ROOT "/bouncekeys_beep_reject",
		desc->ctrls->ax_options & XkbAX_BKRejectFBMask);

	changed |= set_bool (client, cs, in_gconf, CONFIG_ROOT "/mousekeys_enable",
		desc->ctrls->enabled_ctrls & XkbMouseKeysMask);
	changed |= set_int (client, cs, CONFIG_ROOT "/mousekeys_max_speed",
		desc->ctrls->mk_max_speed * (1000 / desc->ctrls->mk_interval));
	/* NOTE : mk_time_to_max is measured in events not time */
	changed |= set_int (client, cs, CONFIG_ROOT "/mousekeys_accel_time",
		desc->ctrls->mk_time_to_max * desc->ctrls->mk_interval);
	changed |= set_int (client, cs, CONFIG_ROOT "/mousekeys_init_delay",
		desc->ctrls->mk_delay);

	slowkeys_changed = set_bool (client, cs, in_gconf, CONFIG_ROOT "/slowkeys_enable",
				     desc->ctrls->enabled_ctrls & XkbSlowKeysMask);
	changed |= set_bool (client, cs, TRUE, CONFIG_ROOT "/slowkeys_beep_press",
		desc->ctrls->ax_options & XkbAX_SKPressFBMask);
	changed |= set_bool (client, cs, TRUE, CONFIG_ROOT "/slowkeys_beep_accept",
		desc->ctrls->ax_options & XkbAX_SKAcceptFBMask);
	changed |= set_bool (client, cs, TRUE, CONFIG_ROOT "/slowkeys_beep_reject",
		desc->ctrls->ax_options & XkbAX_SKRejectFBMask);
	changed |= set_int (client, cs, CONFIG_ROOT "/slowkeys_delay",
		desc->ctrls->slow_keys_delay);

	stickykeys_changed = set_bool (client, cs, in_gconf, CONFIG_ROOT "/stickykeys_enable",
				       desc->ctrls->enabled_ctrls & XkbStickyKeysMask);  
	changed |= set_bool (client, cs, TRUE, CONFIG_ROOT "/stickykeys_two_key_off",
		desc->ctrls->ax_options & XkbAX_TwoKeysMask);
	changed |= set_bool (client, cs, TRUE, CONFIG_ROOT "/stickykeys_modifier_beep",
		desc->ctrls->ax_options & XkbAX_StickyKeysFBMask);

	changed |= set_bool (client, cs, in_gconf, CONFIG_ROOT "/togglekeys_enable",
		desc->ctrls->ax_options & XkbAX_IndicatorFBMask);

	if (!changed && stickykeys_changed^slowkeys_changed)
	{
		/* 
		 * sticky or slowkeys has changed, singly, without our intervention.
		 * 99% chance this is due to a keyboard shortcut being used.
		 * we need to detect via this hack until we get 
		 *  XkbAXN_AXKWarning notifications working (probable XKB bug),
		 *  at which time we can directly intercept such shortcuts instead.
		 * See cb_xkb_event_filter () below.
		 */

                /* sanity check: are keyboard shortcuts available? */
		if (desc->ctrls->enabled_ctrls & XkbAccessXKeysMask) 
		{
			if (slowkeys_changed)
				ax_slowkeys_warning_dialog_post (desc->ctrls->enabled_ctrls & XkbSlowKeysMask);	
			else
				ax_stickykeys_warning_dialog_post (desc->ctrls->enabled_ctrls & XkbStickyKeysMask);
		}
	}

	XkbFreeKeyboard (desc, XkbAllComponentsMask, True);

	changed |= (stickykeys_changed | slowkeys_changed);

	if (changed) {
		gconf_client_commit_change_set (client, cs, FALSE, NULL);
		gconf_client_suggest_sync (client, NULL);
	}
	gconf_change_set_unref (cs);
	g_object_unref (client);
}

static GdkFilterReturn 
cb_xkb_event_filter (GdkXEvent *xevent, GdkEvent *ignored1, gpointer ignored2)
{
	XEvent   *xev   = (XEvent *) xevent;
	XkbEvent *xkbEv = (XkbEvent *) xevent;

	if (xev->xany.type == (xkbEventBase + XkbEventCode) &&
	    xkbEv->any.xkb_type == XkbControlsNotify) {
		d ("Someone changed XKB state\n");
		set_gconf_from_server (NULL);
	}
	else if (xev->xany.type == (xkbEventBase + XkbEventCode) &&
		 xkbEv->any.xkb_type == XkbAccessXNotify) {
		if (xkbEv->accessx.detail == XkbAXN_AXKWarning) {
			d ("About to turn on an AccessX feature from the keyboard!");
			/* 
			 * TODO: when XkbAXN_AXKWarnings start working, we need to 
			 * invoke ax_keys_warning_dialog_run here instead of in
			 * set_gconf_from_server().
			 */
		}
	}

	return GDK_FILTER_CONTINUE;
}

void
gnome_settings_accessibility_keyboard_load (GConfClient *client)
{
	static gboolean has_filter = FALSE;
	guint event_mask = XkbControlsNotifyMask;
#ifdef DEBUG_ACCESSIBILITY	
	event_mask = XkbControlsNotifyMask | XkbAccessXNotifyMask); /* make default when AXN_AXKWarning works */
#endif
	if (!xkb_enabled ())
		return;

	/* be sure to init before starting to monitor the server */
	set_server_from_gconf (NULL);

	/* be careful not to install multipled filters */
	if (has_filter)
		return;

	gdk_error_trap_push ();
	XkbSelectEvents (GDK_DISPLAY (),
			 XkbUseCoreKbd,
			 event_mask,
			 event_mask);

	XSync (GDK_DISPLAY (), FALSE);
	gdk_error_trap_pop ();

	gdk_window_add_filter (NULL, 
			       &cb_xkb_event_filter, NULL);
}


void
gnome_settings_accessibility_keyboard_init (GConfClient *client)
{
	gnome_settings_daemon_register_callback (CONFIG_ROOT, &set_server_from_gconf);
}
#else

void
gnome_settings_accessibility_keyboard_load (GConfClient *client)
{
	g_warning ("Unsupported in this build");
}
void
gnome_settings_accessibility_keyboard_init (GConfClient *client)
{
}
#endif