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
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
*
* Copyright © 2001 Ximian, Inc.
* Copyright (C) 2007 William Jon McCann <mccann@jhu.edu>
* Copyright (C) 2012-2021 MATE Developers
*
* 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 of the License, 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "config.h"
#include <sys/types.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <locale.h>
#include <glib.h>
#include <glib/gi18n.h>
#include <gdk/gdk.h>
#include <gdk/gdkx.h>
#include <gtk/gtk.h>
#include <gio/gio.h>
#include <X11/XKBlib.h>
#include <X11/extensions/XKBstr.h>
#include <X11/extensions/XInput.h>
#include <X11/extensions/XIproto.h>
#ifdef HAVE_LIBNOTIFY
#include <libnotify/notify.h>
#endif /* HAVE_LIBNOTIFY */
#include "mate-settings-profile.h"
#include "msd-a11y-keyboard-manager.h"
#ifdef HAVE_LIBATSPI
# include "msd-a11y-keyboard-atspi.h"
#endif
#include "msd-a11y-preferences-dialog.h"
#define CONFIG_SCHEMA "org.mate.accessibility-keyboard"
#ifdef HAVE_LIBATSPI
# define KEY_CAPSLOCK_BEEP_ENABLED "capslock-beep-enable"
#endif
#define NOTIFICATION_TIMEOUT 30
struct MsdA11yKeyboardManagerPrivate
{
int xkbEventBase;
gboolean stickykeys_shortcut_val;
gboolean slowkeys_shortcut_val;
GtkWidget *stickykeys_alert;
GtkWidget *slowkeys_alert;
GtkWidget *preferences_dialog;
GtkStatusIcon *status_icon;
XkbDescRec *original_xkb_desc;
#ifdef HAVE_LIBATSPI
MsdA11yKeyboardAtspi *capslock_beep;
#endif
GSettings *settings;
#ifdef HAVE_LIBNOTIFY
NotifyNotification *notification;
#endif /* HAVE_LIBNOTIFY */
};
/* Keep in sync with the org.mate.accessibility-keyboard.TogglekeysBackend
* enum from the org.mate.accessibility-keyboard schema. */
typedef enum
{
TOGGLEKEYS_BACKEND_XKB,
TOGGLEKEYS_BACKEND_INTERNAL,
} TogglekeysBackend;
static void msd_a11y_keyboard_manager_finalize (GObject *object);
static void msd_a11y_keyboard_manager_ensure_status_icon (MsdA11yKeyboardManager *manager);
static void set_server_from_settings (MsdA11yKeyboardManager *manager);
G_DEFINE_TYPE_WITH_PRIVATE (MsdA11yKeyboardManager, msd_a11y_keyboard_manager, G_TYPE_OBJECT)
static gpointer manager_object = NULL;
static gboolean
togglekeys_backend_enabled (MsdA11yKeyboardManager *manager,
TogglekeysBackend backend)
{
return (g_settings_get_boolean (manager->priv->settings, "togglekeys-enable") &&
g_settings_get_enum (manager->priv->settings, "togglekeys-backend") == (gint) backend);
}
static GdkFilterReturn
devicepresence_filter (GdkXEvent *xevent,
GdkEvent *event,
gpointer data)
{
XEvent *xev = (XEvent *) xevent;
G_GNUC_UNUSED XEventClass class_presence;
int xi_presence;
DevicePresence (gdk_x11_get_default_xdisplay (), xi_presence, class_presence);
if (xev->type == xi_presence)
{
XDevicePresenceNotifyEvent *dpn = (XDevicePresenceNotifyEvent *) xev;
if (dpn->devchange == DeviceEnabled) {
set_server_from_settings (data);
}
}
return GDK_FILTER_CONTINUE;
}
static gboolean
supports_xinput_devices (void)
{
gint op_code, event, error;
return XQueryExtension (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()),
"XInputExtension",
&op_code,
&event,
&error);
}
static void
set_devicepresence_handler (MsdA11yKeyboardManager *manager)
{
Display *display;
GdkDisplay *gdk_display;
XEventClass class_presence;
G_GNUC_UNUSED int xi_presence;
if (!supports_xinput_devices ())
return;
display = gdk_x11_get_default_xdisplay ();
gdk_display = gdk_display_get_default ();
gdk_x11_display_error_trap_push (gdk_display);
DevicePresence (display, xi_presence, class_presence);
/* FIXME:
* Note that this might overwrite other events, see:
* https://bugzilla.gnome.org/show_bug.cgi?id=610245#c2
**/
XSelectExtensionEvent (display,
RootWindow (display, DefaultScreen (display)),
&class_presence, 1);
gdk_display_flush (gdk_display);
if (!gdk_x11_display_error_trap_pop (gdk_display))
gdk_window_add_filter (NULL, devicepresence_filter, manager);
}
static gboolean
xkb_enabled (MsdA11yKeyboardManager *manager)
{
gboolean have_xkb;
int opcode, errorBase, major, minor;
have_xkb = XkbQueryExtension (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()),
&opcode,
&manager->priv->xkbEventBase,
&errorBase,
&major,
&minor)
&& XkbUseExtension (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), &major, &minor);
return have_xkb;
}
static XkbDescRec *
get_xkb_desc_rec (MsdA11yKeyboardManager *manager)
{
GdkDisplay *display;
XkbDescRec *desc;
Status status = Success;
display = gdk_display_get_default ();
gdk_x11_display_error_trap_push (display);
desc = XkbGetMap (GDK_DISPLAY_XDISPLAY(display), XkbAllMapComponentsMask, XkbUseCoreKbd);
if (desc != NULL) {
desc->ctrls = NULL;
status = XkbGetControls (GDK_DISPLAY_XDISPLAY(display), XkbAllControlsMask, desc);
}
gdk_x11_display_error_trap_pop_ignored (display);
g_return_val_if_fail (desc != NULL && desc->ctrls != NULL, NULL);
g_return_val_if_fail (status == Success, NULL);
return desc;
}
static int
get_int (GSettings *settings,
char const *key)
{
int res = g_settings_get_int (settings, key);
if (res <= 0) {
res = 1;
}
return res;
}
static gboolean
set_int (GSettings *settings,
char const *key,
int val)
{
int pre_val = g_settings_get_int (settings, key);
g_settings_set_int (settings, key, val);
#ifdef MATE_ENABLE_DEBUG
if (val != pre_val) {
g_warning ("%s changed", key);
}
#endif /* MATE_ENABLE_DEBUG */
return val != pre_val;
}
static gboolean
set_bool (GSettings *settings,
char const *key,
int val)
{
gboolean bval = (val != 0);
gboolean pre_val = g_settings_get_boolean (settings, key);
g_settings_set_boolean (settings, key, bval ? TRUE : FALSE);
#ifdef MATE_ENABLE_DEBUG
if (bval != pre_val) {
g_debug ("%s changed", key);
return TRUE;
}
#endif /* MATE_ENABLE_DEBUG */
return (bval != pre_val);
}
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_settings (XkbDescRec *desc,
GSettings *settings,
char const *key,
unsigned long mask)
{
gboolean result = g_settings_get_boolean (settings, key);
desc->ctrls->enabled_ctrls = set_clear (result, desc->ctrls->enabled_ctrls, mask);
return result;
}
static void
set_server_from_settings (MsdA11yKeyboardManager *manager)
{
XkbDescRec *desc;
gboolean enable_accessX;
GdkDisplay *display;
mate_settings_profile_start (NULL);
desc = get_xkb_desc_rec (manager);
if (!desc) {
return;
}
/* general */
enable_accessX = g_settings_get_boolean (manager->priv->settings, "enable");
desc->ctrls->enabled_ctrls = set_clear (enable_accessX,
desc->ctrls->enabled_ctrls,
XkbAccessXKeysMask);
if (set_ctrl_from_settings (desc, manager->priv->settings, "timeout-enable",
XkbAccessXTimeoutMask)) {
desc->ctrls->ax_timeout = get_int (manager->priv->settings, "timeout");
/* disable only the master flag via the server we will disable
* the rest on the rebound without affecting gsettings 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 (g_settings_get_boolean (manager->priv->settings, "feature-state-change-beep"),
desc->ctrls->ax_options,
XkbAccessXFeedbackMask | XkbAX_FeatureFBMask | XkbAX_SlowWarnFBMask);
/* bounce keys */
if (set_ctrl_from_settings (desc,
manager->priv->settings,
"bouncekeys-enable",
XkbBounceKeysMask)) {
desc->ctrls->debounce_delay = get_int (manager->priv->settings,
"bouncekeys-delay");
desc->ctrls->ax_options = set_clear (g_settings_get_boolean (manager->priv->settings, "bouncekeys-beep-reject"),
desc->ctrls->ax_options,
XkbAccessXFeedbackMask | XkbAX_BKRejectFBMask);
}
/* mouse keys */
if (set_ctrl_from_settings (desc,
manager->priv->settings,
"mousekeys-enable",
XkbMouseKeysMask | XkbMouseKeysAccelMask)) {
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 (manager->priv->settings,
"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 (manager->priv->settings, /* events before max */
"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 (manager->priv->settings, /* ms before 1st event */
"mousekeys-init-delay");
}
/* slow keys */
if (set_ctrl_from_settings (desc,
manager->priv->settings,
"slowkeys-enable",
XkbSlowKeysMask)) {
desc->ctrls->ax_options = set_clear (g_settings_get_boolean (manager->priv->settings, "slowkeys-beep-press"),
desc->ctrls->ax_options,
XkbAccessXFeedbackMask | XkbAX_SKPressFBMask);
desc->ctrls->ax_options = set_clear (g_settings_get_boolean (manager->priv->settings, "slowkeys-beep-accept"),
desc->ctrls->ax_options,
XkbAccessXFeedbackMask | XkbAX_SKAcceptFBMask);
desc->ctrls->ax_options = set_clear (g_settings_get_boolean (manager->priv->settings, "slowkeys-beep-reject"),
desc->ctrls->ax_options,
XkbAccessXFeedbackMask | XkbAX_SKRejectFBMask);
desc->ctrls->slow_keys_delay = get_int (manager->priv->settings,
"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_settings (desc,
manager->priv->settings,
"stickykeys-enable",
XkbStickyKeysMask)) {
desc->ctrls->ax_options = set_clear (g_settings_get_boolean (manager->priv->settings, "stickykeys-latch-to-lock"),
desc->ctrls->ax_options,
XkbAccessXFeedbackMask | XkbAX_LatchToLockMask);
desc->ctrls->ax_options = set_clear (g_settings_get_boolean (manager->priv->settings, "stickykeys-two-key-off"),
desc->ctrls->ax_options,
XkbAccessXFeedbackMask | XkbAX_TwoKeysMask);
desc->ctrls->ax_options = set_clear (g_settings_get_boolean (manager->priv->settings, "stickykeys-modifier-beep"),
desc->ctrls->ax_options,
XkbAccessXFeedbackMask | XkbAX_StickyKeysFBMask);
}
/* toggle keys */
desc->ctrls->ax_options = set_clear (togglekeys_backend_enabled (manager, TOGGLEKEYS_BACKEND_XKB),
desc->ctrls->ax_options,
XkbAccessXFeedbackMask | XkbAX_IndicatorFBMask);
/*
g_debug ("CHANGE to : 0x%x", desc->ctrls->enabled_ctrls);
g_debug ("CHANGE to : 0x%x (2)", desc->ctrls->ax_options);
*/
display = gdk_display_get_default ();
gdk_x11_display_error_trap_push (display);
XkbSetControls (GDK_DISPLAY_XDISPLAY(display),
XkbSlowKeysMask |
XkbBounceKeysMask |
XkbStickyKeysMask |
XkbMouseKeysMask |
XkbMouseKeysAccelMask |
XkbAccessXKeysMask |
XkbAccessXTimeoutMask |
XkbAccessXFeedbackMask |
XkbControlsEnabledMask,
desc);
XkbFreeKeyboard (desc, XkbAllComponentsMask, True);
XSync (GDK_DISPLAY_XDISPLAY(display), FALSE);
gdk_x11_display_error_trap_pop_ignored (display);
mate_settings_profile_end (NULL);
}
static gboolean
ax_response_callback (MsdA11yKeyboardManager *manager,
GtkWindow *parent,
gint response_id,
guint revert_controls_mask,
gboolean enabled)
{
GError *err;
switch (response_id) {
case GTK_RESPONSE_DELETE_EVENT:
case GTK_RESPONSE_REJECT:
case GTK_RESPONSE_CANCEL:
/* we're reverting, so we invert sense of 'enabled' flag */
g_debug ("cancelling AccessX request");
if (revert_controls_mask == XkbStickyKeysMask) {
g_settings_set_boolean (manager->priv->settings,
"stickykeys-enable",
!enabled);
}
else if (revert_controls_mask == XkbSlowKeysMask) {
g_settings_set_boolean (manager->priv->settings,
"slowkeys-enable",
!enabled);
}
set_server_from_settings (manager);
break;
case GTK_RESPONSE_HELP:
err = NULL;
if (!gtk_show_uri_on_window (parent,
"help:mate-user-guide/goscustaccess-6",
gtk_get_current_event_time(),
&err)) {
GtkWidget *error_dialog = gtk_message_dialog_new (parent,
0,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
_("There was an error displaying help: %s"),
err->message);
g_signal_connect (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,
MsdA11yKeyboardManager *manager)
{
if (ax_response_callback (manager, GTK_WINDOW (dialog),
response_id, XkbStickyKeysMask,
manager->priv->stickykeys_shortcut_val)) {
gtk_widget_destroy (GTK_WIDGET (dialog));
}
}
static void
ax_slowkeys_response (GtkDialog *dialog,
gint response_id,
MsdA11yKeyboardManager *manager)
{
if (ax_response_callback (manager, GTK_WINDOW (dialog),
response_id, XkbSlowKeysMask,
manager->priv->slowkeys_shortcut_val)) {
gtk_widget_destroy (GTK_WIDGET (dialog));
}
}
static void
maybe_show_status_icon (MsdA11yKeyboardManager *manager)
{
gboolean show;
/* for now, show if accessx is enabled */
show = g_settings_get_boolean (manager->priv->settings, "enable");
if (!show && manager->priv->status_icon == NULL)
return;
msd_a11y_keyboard_manager_ensure_status_icon (manager);
gtk_status_icon_set_visible (manager->priv->status_icon, show);
}
#ifdef HAVE_LIBNOTIFY
static void
on_notification_closed (NotifyNotification *notification G_GNUC_UNUSED,
MsdA11yKeyboardManager *manager)
{
g_object_unref (manager->priv->notification);
manager->priv->notification = NULL;
}
static void
on_slow_keys_action (NotifyNotification *notification,
const char *action,
MsdA11yKeyboardManager *manager)
{
gboolean res;
int response_id;
g_assert (action != NULL);
if (strcmp (action, "accept") == 0) {
response_id = GTK_RESPONSE_ACCEPT;
} else if (strcmp (action, "reject") == 0) {
response_id = GTK_RESPONSE_REJECT;
} else {
return;
}
res = ax_response_callback (manager, NULL,
response_id, XkbSlowKeysMask,
manager->priv->slowkeys_shortcut_val);
if (res) {
notify_notification_close (manager->priv->notification, NULL);
}
}
static void
on_sticky_keys_action (NotifyNotification *notification,
const char *action,
MsdA11yKeyboardManager *manager)
{
gboolean res;
int response_id;
g_assert (action != NULL);
if (strcmp (action, "accept") == 0) {
response_id = GTK_RESPONSE_ACCEPT;
} else if (strcmp (action, "reject") == 0) {
response_id = GTK_RESPONSE_REJECT;
} else {
return;
}
res = ax_response_callback (manager, NULL,
response_id, XkbStickyKeysMask,
manager->priv->stickykeys_shortcut_val);
if (res) {
notify_notification_close (manager->priv->notification, NULL);
}
}
#endif /* HAVE_LIBNOTIFY */
static gboolean
ax_slowkeys_warning_post_bubble (MsdA11yKeyboardManager *manager,
gboolean enabled)
{
#ifdef HAVE_LIBNOTIFY
gboolean res;
const char *title;
const char *message;
GError *error;
title = enabled ?
_("Do you want to activate Slow Keys?") :
_("Do you want to deactivate Slow Keys?");
message = _("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.");
if (manager->priv->status_icon == NULL || ! gtk_status_icon_is_embedded (manager->priv->status_icon)) {
return FALSE;
}
if (manager->priv->slowkeys_alert != NULL) {
gtk_widget_destroy (manager->priv->slowkeys_alert);
}
if (manager->priv->notification != NULL) {
notify_notification_close (manager->priv->notification, NULL);
}
msd_a11y_keyboard_manager_ensure_status_icon (manager);
manager->priv->notification = notify_notification_new (title,
message,
"preferences-desktop-accessibility");
notify_notification_set_timeout (manager->priv->notification, NOTIFICATION_TIMEOUT * 1000);
notify_notification_add_action (manager->priv->notification,
"reject",
enabled ? _("Don't activate") : _("Don't deactivate"),
(NotifyActionCallback) on_slow_keys_action,
manager,
NULL);
notify_notification_add_action (manager->priv->notification,
"accept",
enabled ? _("Activate") : _("Deactivate"),
(NotifyActionCallback) on_slow_keys_action,
manager,
NULL);
g_signal_connect (manager->priv->notification,
"closed",
G_CALLBACK (on_notification_closed),
manager);
error = NULL;
res = notify_notification_show (manager->priv->notification, &error);
if (! res) {
g_warning ("MsdA11yKeyboardManager: unable to show notification: %s", error->message);
g_error_free (error);
notify_notification_close (manager->priv->notification, NULL);
}
return res;
#else
return FALSE;
#endif /* HAVE_LIBNOTIFY */
}
static void
ax_slowkeys_warning_post_dialog (MsdA11yKeyboardManager *manager,
gboolean enabled)
{
const char *title;
const char *message;
title = enabled ?
_("Do you want to activate Slow Keys?") :
_("Do you want to deactivate Slow Keys?");
message = _("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.");
if (manager->priv->slowkeys_alert != NULL) {
gtk_widget_show (manager->priv->slowkeys_alert);
return;
}
manager->priv->slowkeys_alert = gtk_message_dialog_new (NULL,
0,
GTK_MESSAGE_WARNING,
GTK_BUTTONS_NONE,
"%s", title);
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (manager->priv->slowkeys_alert),
"%s", message);
gtk_dialog_add_button (GTK_DIALOG (manager->priv->slowkeys_alert),
GTK_STOCK_HELP,
GTK_RESPONSE_HELP);
gtk_dialog_add_button (GTK_DIALOG (manager->priv->slowkeys_alert),
enabled ? _("Do_n't activate") : _("Do_n't deactivate"),
GTK_RESPONSE_REJECT);
gtk_dialog_add_button (GTK_DIALOG (manager->priv->slowkeys_alert),
enabled ? _("_Activate") : _("_Deactivate"),
GTK_RESPONSE_ACCEPT);
gtk_window_set_title (GTK_WINDOW (manager->priv->slowkeys_alert),
_("Slow Keys Alert"));
gtk_window_set_icon_name (GTK_WINDOW (manager->priv->slowkeys_alert),
"input-keyboard");
gtk_dialog_set_default_response (GTK_DIALOG (manager->priv->slowkeys_alert),
GTK_RESPONSE_ACCEPT);
g_signal_connect (manager->priv->slowkeys_alert,
"response",
G_CALLBACK (ax_slowkeys_response),
manager);
gtk_widget_show (manager->priv->slowkeys_alert);
g_object_add_weak_pointer (G_OBJECT (manager->priv->slowkeys_alert),
(gpointer*) &manager->priv->slowkeys_alert);
}
static void
ax_slowkeys_warning_post (MsdA11yKeyboardManager *manager,
gboolean enabled)
{
manager->priv->slowkeys_shortcut_val = enabled;
/* alway try to show something */
if (! ax_slowkeys_warning_post_bubble (manager, enabled)) {
ax_slowkeys_warning_post_dialog (manager, enabled);
}
}
static gboolean
ax_stickykeys_warning_post_bubble (MsdA11yKeyboardManager *manager,
gboolean enabled)
{
#ifdef HAVE_LIBNOTIFY
gboolean res;
const char *title;
const char *message;
GError *error;
title = enabled ?
_("Do you want to activate Sticky Keys?") :
_("Do you want to deactivate Sticky Keys?");
message = 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.");
if (manager->priv->status_icon == NULL || ! gtk_status_icon_is_embedded (manager->priv->status_icon)) {
return FALSE;
}
if (manager->priv->slowkeys_alert != NULL) {
gtk_widget_destroy (manager->priv->slowkeys_alert);
}
if (manager->priv->notification != NULL) {
notify_notification_close (manager->priv->notification, NULL);
}
msd_a11y_keyboard_manager_ensure_status_icon (manager);
manager->priv->notification = notify_notification_new (title,
message,
"preferences-desktop-accessibility");
notify_notification_set_timeout (manager->priv->notification, NOTIFICATION_TIMEOUT * 1000);
notify_notification_add_action (manager->priv->notification,
"reject",
enabled ? _("Don't activate") : _("Don't deactivate"),
(NotifyActionCallback) on_sticky_keys_action,
manager,
NULL);
notify_notification_add_action (manager->priv->notification,
"accept",
enabled ? _("Activate") : _("Deactivate"),
(NotifyActionCallback) on_sticky_keys_action,
manager,
NULL);
g_signal_connect (manager->priv->notification,
"closed",
G_CALLBACK (on_notification_closed),
manager);
error = NULL;
res = notify_notification_show (manager->priv->notification, &error);
if (! res) {
g_warning ("MsdA11yKeyboardManager: unable to show notification: %s", error->message);
g_error_free (error);
notify_notification_close (manager->priv->notification, NULL);
}
return res;
#else
return FALSE;
#endif /* HAVE_LIBNOTIFY */
}
static void
ax_stickykeys_warning_post_dialog (MsdA11yKeyboardManager *manager,
gboolean enabled)
{
const char *title;
const char *message;
title = enabled ?
_("Do you want to activate Sticky Keys?") :
_("Do you want to deactivate Sticky Keys?");
message = 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.");
if (manager->priv->stickykeys_alert != NULL) {
gtk_widget_show (manager->priv->stickykeys_alert);
return;
}
manager->priv->stickykeys_alert = gtk_message_dialog_new (NULL,
0,
GTK_MESSAGE_WARNING,
GTK_BUTTONS_NONE,
"%s", title);
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (manager->priv->stickykeys_alert),
"%s", message);
gtk_dialog_add_button (GTK_DIALOG (manager->priv->stickykeys_alert),
GTK_STOCK_HELP,
GTK_RESPONSE_HELP);
gtk_dialog_add_button (GTK_DIALOG (manager->priv->stickykeys_alert),
enabled ? _("Do_n't activate") : _("Do_n't deactivate"),
GTK_RESPONSE_REJECT);
gtk_dialog_add_button (GTK_DIALOG (manager->priv->stickykeys_alert),
enabled ? _("_Activate") : _("_Deactivate"),
GTK_RESPONSE_ACCEPT);
gtk_window_set_title (GTK_WINDOW (manager->priv->stickykeys_alert),
_("Sticky Keys Alert"));
gtk_window_set_icon_name (GTK_WINDOW (manager->priv->stickykeys_alert),
"input-keyboard");
gtk_dialog_set_default_response (GTK_DIALOG (manager->priv->stickykeys_alert),
GTK_RESPONSE_ACCEPT);
g_signal_connect (manager->priv->stickykeys_alert,
"response",
G_CALLBACK (ax_stickykeys_response),
manager);
gtk_widget_show (manager->priv->stickykeys_alert);
g_object_add_weak_pointer (G_OBJECT (manager->priv->stickykeys_alert),
(gpointer*) &manager->priv->stickykeys_alert);
}
static void
ax_stickykeys_warning_post (MsdA11yKeyboardManager *manager,
gboolean enabled)
{
manager->priv->stickykeys_shortcut_val = enabled;
/* alway try to show something */
if (! ax_stickykeys_warning_post_bubble (manager, enabled)) {
ax_stickykeys_warning_post_dialog (manager, enabled);
}
}
static void
set_settings_from_server (MsdA11yKeyboardManager *manager)
{
GSettings *settings;
XkbDescRec *desc;
gboolean changed = FALSE;
gboolean slowkeys_changed;
gboolean stickykeys_changed;
desc = get_xkb_desc_rec (manager);
if (! desc) {
return;
}
settings = g_settings_new (CONFIG_SCHEMA);
g_settings_delay(settings);
/*
fprintf (stderr, "changed to : 0x%x\n", desc->ctrls->enabled_ctrls);
fprintf (stderr, "changed to : 0x%x (2)\n", desc->ctrls->ax_options);
*/
changed |= set_bool (settings,
"enable",
desc->ctrls->enabled_ctrls & XkbAccessXKeysMask);
changed |= set_bool (settings,
"feature-state-change-beep",
desc->ctrls->ax_options & (XkbAX_FeatureFBMask | XkbAX_SlowWarnFBMask));
changed |= set_bool (settings,
"timeout-enable",
desc->ctrls->enabled_ctrls & XkbAccessXTimeoutMask);
changed |= set_int (settings,
"timeout",
desc->ctrls->ax_timeout);
changed |= set_bool (settings,
"bouncekeys-enable",
desc->ctrls->enabled_ctrls & XkbBounceKeysMask);
changed |= set_int (settings,
"bouncekeys-delay",
desc->ctrls->debounce_delay);
changed |= set_bool (settings,
"bouncekeys-beep-reject",
desc->ctrls->ax_options & XkbAX_BKRejectFBMask);
changed |= set_bool (settings,
"mousekeys-enable",
desc->ctrls->enabled_ctrls & XkbMouseKeysMask);
changed |= set_int (settings,
"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 (settings,
"mousekeys-accel-time",
desc->ctrls->mk_time_to_max * desc->ctrls->mk_interval);
changed |= set_int (settings,
"mousekeys-init-delay",
desc->ctrls->mk_delay);
slowkeys_changed = set_bool (settings,
"slowkeys-enable",
desc->ctrls->enabled_ctrls & XkbSlowKeysMask);
changed |= set_bool (settings,
"slowkeys-beep-press",
desc->ctrls->ax_options & XkbAX_SKPressFBMask);
changed |= set_bool (settings,
"slowkeys-beep-accept",
desc->ctrls->ax_options & XkbAX_SKAcceptFBMask);
changed |= set_bool (settings,
"slowkeys-beep-reject",
desc->ctrls->ax_options & XkbAX_SKRejectFBMask);
changed |= set_int (settings,
"slowkeys-delay",
desc->ctrls->slow_keys_delay);
stickykeys_changed = set_bool (settings,
"stickykeys-enable",
desc->ctrls->enabled_ctrls & XkbStickyKeysMask);
changed |= set_bool (settings,
"stickykeys-latch-to-lock",
desc->ctrls->ax_options & XkbAX_LatchToLockMask);
changed |= set_bool (settings,
"stickykeys-two-key-off",
desc->ctrls->ax_options & XkbAX_TwoKeysMask);
changed |= set_bool (settings,
"stickykeys-modifier-beep",
desc->ctrls->ax_options & XkbAX_StickyKeysFBMask);
if (g_settings_get_enum (manager->priv->settings, "togglekeys-backend") == TOGGLEKEYS_BACKEND_XKB) {
changed |= set_bool (settings,
"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_post (manager,
desc->ctrls->enabled_ctrls & XkbSlowKeysMask);
} else {
ax_stickykeys_warning_post (manager,
desc->ctrls->enabled_ctrls & XkbStickyKeysMask);
}
}
}
XkbFreeKeyboard (desc, XkbAllComponentsMask, True);
changed |= (stickykeys_changed | slowkeys_changed);
if (changed) {
g_settings_apply (settings);
}
g_object_unref (settings);
}
typedef struct {
GdkDisplay *display;
gint count;
} BeepSequenceData;
static gboolean
on_beep_dequence_timeout (gpointer user_data)
{
BeepSequenceData *data = user_data;
gdk_display_beep (data->display);
data->count--;
return data->count > 0;
}
static void
beep_sequence (MsdA11yKeyboardManager *manager,
GdkDisplay *display,
gint count,
gint delay)
{
g_return_if_fail (MSD_IS_A11Y_KEYBOARD_MANAGER (manager));
if (count < 1)
return;
if (! display)
display = gdk_display_get_default ();
gdk_display_beep (display);
if (count > 1) {
BeepSequenceData *data = g_malloc (sizeof *data);
/* don't allow more than 8 beeps total, nor a delay outside
* the range 50ms-5s: anything outside this is not very
* reasonable and is more likely to be a broken setting,
* and we don't want to be beeping forever. */
g_warn_if_fail (count <= 8);
g_warn_if_fail (delay >= 50 && delay <= 5000);
data->display = display;
data->count = MIN (8, count) - 1;
delay = CLAMP (delay, 50, 5000);
g_timeout_add_full (G_PRIORITY_DEFAULT, (guint) delay,
on_beep_dequence_timeout, data, g_free);
}
}
static GdkFilterReturn
cb_xkb_event_filter (GdkXEvent *xevent,
GdkEvent *ignored1,
MsdA11yKeyboardManager *manager)
{
XEvent *xev = (XEvent *) xevent;
XkbEvent *xkbEv = (XkbEvent *) xevent;
if (xev->xany.type == (manager->priv->xkbEventBase + XkbEventCode) &&
xkbEv->any.xkb_type == XkbControlsNotify) {
g_debug ("XKB state changed");
set_settings_from_server (manager);
} else if (xev->xany.type == (manager->priv->xkbEventBase + XkbEventCode) &&
xkbEv->any.xkb_type == XkbAccessXNotify) {
if (xkbEv->accessx.detail == XkbAXN_AXKWarning) {
g_debug ("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_settings_from_server().
*/
}
} else if (xev->xany.type == (manager->priv->xkbEventBase + XkbEventCode) &&
xkbEv->any.xkb_type == XkbIndicatorStateNotify &&
togglekeys_backend_enabled (manager, TOGGLEKEYS_BACKEND_INTERNAL)) {
GdkDisplay *display = gdk_x11_lookup_xdisplay (xkbEv->any.display);
gint beep_count;
gint beep_delay;
if (xkbEv->indicators.state & xkbEv->indicators.changed) {
beep_count = g_settings_get_int (manager->priv->settings, "togglekeys-enable-beep-count");
beep_delay = g_settings_get_int (manager->priv->settings, "togglekeys-enable-beep-delay");
} else {
beep_count = g_settings_get_int (manager->priv->settings, "togglekeys-disable-beep-count");
beep_delay = g_settings_get_int (manager->priv->settings, "togglekeys-disable-beep-delay");
}
beep_sequence (manager, display, beep_count, beep_delay);
}
return GDK_FILTER_CONTINUE;
}
static void
keyboard_callback (GSettings *settings G_GNUC_UNUSED,
gchar *key G_GNUC_UNUSED,
MsdA11yKeyboardManager *manager)
{
set_server_from_settings (manager);
maybe_show_status_icon (manager);
}
#ifdef HAVE_LIBATSPI
static void
capslock_beep_callback (GSettings *settings,
gchar *key G_GNUC_UNUSED,
MsdA11yKeyboardManager *manager)
{
if (g_settings_get_boolean (settings, KEY_CAPSLOCK_BEEP_ENABLED))
msd_a11y_keyboard_atspi_start (manager->priv->capslock_beep);
else
msd_a11y_keyboard_atspi_stop (manager->priv->capslock_beep);
}
#endif
static gboolean
start_a11y_keyboard_idle_cb (MsdA11yKeyboardManager *manager)
{
guint event_mask;
g_debug ("Starting a11y_keyboard manager");
mate_settings_profile_start (NULL);
manager->priv->settings = g_settings_new (CONFIG_SCHEMA);
#ifdef HAVE_LIBATSPI
manager->priv->capslock_beep = msd_a11y_keyboard_atspi_new ();
if (g_settings_get_boolean (manager->priv->settings, KEY_CAPSLOCK_BEEP_ENABLED))
msd_a11y_keyboard_atspi_start (manager->priv->capslock_beep);
g_signal_connect (manager->priv->settings, "changed::"KEY_CAPSLOCK_BEEP_ENABLED,
G_CALLBACK (capslock_beep_callback), manager);
#endif
if (!xkb_enabled (manager))
goto out;
g_signal_connect (manager->priv->settings, "changed", G_CALLBACK (keyboard_callback), manager);
set_devicepresence_handler (manager);
/* Save current xkb state so we can restore it on exit
*/
manager->priv->original_xkb_desc = get_xkb_desc_rec (manager);
event_mask = XkbControlsNotifyMask;
event_mask |= XkbIndicatorStateNotifyMask;
#ifdef MATE_ENABLE_DEBUG
event_mask |= XkbAccessXNotifyMask; /* make default when AXN_AXKWarning works */
#endif /* MATE_ENABLE_DEBUG */
/* be sure to init before starting to monitor the server */
set_server_from_settings (manager);
XkbSelectEvents (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()),
XkbUseCoreKbd,
event_mask,
event_mask);
gdk_window_add_filter (NULL,
(GdkFilterFunc) cb_xkb_event_filter,
manager);
maybe_show_status_icon (manager);
out:
mate_settings_profile_end (NULL);
return FALSE;
}
gboolean
msd_a11y_keyboard_manager_start (MsdA11yKeyboardManager *manager,
GError **error)
{
mate_settings_profile_start (NULL);
/* give our initialization a lower priority over msd-keyoboard so it
* restores the numlock state before we might start monitoring it */
g_idle_add_full (G_PRIORITY_LOW,
(GSourceFunc) start_a11y_keyboard_idle_cb, manager,
NULL);
mate_settings_profile_end (NULL);
return TRUE;
}
static void
restore_server_xkb_config (MsdA11yKeyboardManager *manager)
{
GdkDisplay *display;
display = gdk_display_get_default ();
gdk_x11_display_error_trap_push (display);
XkbSetControls (GDK_DISPLAY_XDISPLAY(display),
XkbSlowKeysMask |
XkbBounceKeysMask |
XkbStickyKeysMask |
XkbMouseKeysMask |
XkbMouseKeysAccelMask |
XkbAccessXKeysMask |
XkbAccessXTimeoutMask |
XkbAccessXFeedbackMask |
XkbControlsEnabledMask,
manager->priv->original_xkb_desc);
XkbFreeKeyboard (manager->priv->original_xkb_desc,
XkbAllComponentsMask, True);
XSync (GDK_DISPLAY_XDISPLAY(display), FALSE);
gdk_x11_display_error_trap_pop_ignored (display);
manager->priv->original_xkb_desc = NULL;
}
void
msd_a11y_keyboard_manager_stop (MsdA11yKeyboardManager *manager)
{
MsdA11yKeyboardManagerPrivate *p = manager->priv;
g_debug ("Stopping a11y_keyboard manager");
gdk_window_remove_filter (NULL, devicepresence_filter, manager);
if (p->status_icon)
gtk_status_icon_set_visible (p->status_icon, FALSE);
if (p->settings != NULL) {
g_object_unref (p->settings);
p->settings = NULL;
}
gdk_window_remove_filter (NULL,
(GdkFilterFunc) cb_xkb_event_filter,
manager);
/* Disable all the AccessX bits
*/
restore_server_xkb_config (manager);
if (p->slowkeys_alert != NULL)
gtk_widget_destroy (p->slowkeys_alert);
if (p->stickykeys_alert != NULL)
gtk_widget_destroy (p->stickykeys_alert);
p->slowkeys_shortcut_val = FALSE;
p->stickykeys_shortcut_val = FALSE;
#ifdef HAVE_LIBATSPI
g_clear_object (&p->capslock_beep);
#endif
}
static void
msd_a11y_keyboard_manager_class_init (MsdA11yKeyboardManagerClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = msd_a11y_keyboard_manager_finalize;
}
static void
on_preferences_dialog_response (GtkDialog *dialog,
int response G_GNUC_UNUSED,
MsdA11yKeyboardManager *manager)
{
g_signal_handlers_disconnect_by_func (dialog,
on_preferences_dialog_response,
manager);
gtk_widget_destroy (GTK_WIDGET (dialog));
manager->priv->preferences_dialog = NULL;
}
static void
on_status_icon_activate (GtkStatusIcon *status_icon G_GNUC_UNUSED,
MsdA11yKeyboardManager *manager)
{
if (manager->priv->preferences_dialog == NULL) {
manager->priv->preferences_dialog = msd_a11y_preferences_dialog_new ();
g_signal_connect (manager->priv->preferences_dialog,
"response",
G_CALLBACK (on_preferences_dialog_response),
manager);
gtk_window_present (GTK_WINDOW (manager->priv->preferences_dialog));
} else {
g_signal_handlers_disconnect_by_func (manager->priv->preferences_dialog,
on_preferences_dialog_response,
manager);
gtk_widget_destroy (GTK_WIDGET (manager->priv->preferences_dialog));
manager->priv->preferences_dialog = NULL;
}
}
static void
msd_a11y_keyboard_manager_ensure_status_icon (MsdA11yKeyboardManager *manager)
{
mate_settings_profile_start (NULL);
if (!manager->priv->status_icon) {
manager->priv->status_icon = gtk_status_icon_new_from_icon_name ("preferences-desktop-accessibility");
g_signal_connect (manager->priv->status_icon,
"activate",
G_CALLBACK (on_status_icon_activate),
manager);
}
mate_settings_profile_end (NULL);
}
static void
msd_a11y_keyboard_manager_init (MsdA11yKeyboardManager *manager)
{
manager->priv = msd_a11y_keyboard_manager_get_instance_private (manager);
}
static void
msd_a11y_keyboard_manager_finalize (GObject *object)
{
MsdA11yKeyboardManager *a11y_keyboard_manager;
g_return_if_fail (object != NULL);
g_return_if_fail (MSD_IS_A11Y_KEYBOARD_MANAGER (object));
a11y_keyboard_manager = MSD_A11Y_KEYBOARD_MANAGER (object);
g_return_if_fail (a11y_keyboard_manager->priv != NULL);
G_OBJECT_CLASS (msd_a11y_keyboard_manager_parent_class)->finalize (object);
}
MsdA11yKeyboardManager *
msd_a11y_keyboard_manager_new (void)
{
if (manager_object != NULL) {
g_object_ref (manager_object);
} else {
manager_object = g_object_new (MSD_TYPE_A11Y_KEYBOARD_MANAGER, NULL);
g_object_add_weak_pointer (manager_object,
(gpointer *) &manager_object);
}
return MSD_A11Y_KEYBOARD_MANAGER (manager_object);
}
|