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
|
/* -*- mode: c; style: linux -*- */
/* keyboard-properties.c
* Copyright (C) 2000-2001 Ximian, Inc.
* Copyright (C) 2001 Jonathan Blandford
*
* Written by: Bradford Hovinen <hovinen@ximian.com>
* Rachel Hestilow <hestilow@ximian.com>
* Jonathan Blandford <jrb@redhat.com>
*
* 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., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdlib.h>
#include <gio/gio.h>
#include "capplet-util.h"
#include "activate-settings-daemon.h"
#include "capplet-stock-icons.h"
#include "mate-keyboard-properties-a11y.h"
#include "mate-keyboard-properties-xkb.h"
#define KEYBOARD_SCHEMA "org.mate.peripherals-keyboard"
#define INTERFACE_SCHEMA "org.mate.interface"
#define TYPING_BREAK_SCHEMA "org.mate.typing-break"
enum {
RESPONSE_APPLY = 1,
RESPONSE_CLOSE
};
static GSettings * keyboard_settings = NULL;
static GSettings * interface_settings = NULL;
static GSettings * typing_break_settings = NULL;
static GtkBuilder *
create_dialog (void)
{
GtkBuilder *dialog;
GtkSizeGroup *size_group;
GtkWidget *image;
GError *error = NULL;
static const gchar *uifile = MATECC_UI_DIR "/mate-keyboard-properties-dialog.ui";
dialog = gtk_builder_new ();
if (gtk_builder_add_from_file (dialog, uifile, &error) == 0) {
g_warning ("Could not load UI: %s", error->message);
g_error_free (error);
g_object_unref (dialog);
return NULL;
}
size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
gtk_size_group_add_widget (size_group, WID ("repeat_slow_label"));
gtk_size_group_add_widget (size_group, WID ("delay_short_label"));
gtk_size_group_add_widget (size_group, WID ("blink_slow_label"));
g_object_unref (G_OBJECT (size_group));
size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
gtk_size_group_add_widget (size_group, WID ("repeat_fast_label"));
gtk_size_group_add_widget (size_group, WID ("delay_long_label"));
gtk_size_group_add_widget (size_group, WID ("blink_fast_label"));
g_object_unref (G_OBJECT (size_group));
size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
gtk_size_group_add_widget (size_group, WID ("repeat_delay_scale"));
gtk_size_group_add_widget (size_group, WID ("repeat_speed_scale"));
gtk_size_group_add_widget (size_group, WID ("cursor_blink_time_scale"));
g_object_unref (G_OBJECT (size_group));
image = gtk_image_new_from_icon_name ("list-add", GTK_ICON_SIZE_BUTTON);
gtk_button_set_image (GTK_BUTTON (WID ("xkb_layouts_add")), image);
image = gtk_image_new_from_icon_name ("view-refresh", GTK_ICON_SIZE_BUTTON);
gtk_button_set_image (GTK_BUTTON (WID ("xkb_reset_to_defaults")), image);
return dialog;
}
static void
dialog_response (GtkWidget * widget,
gint response_id, guint data)
{
if (response_id == GTK_RESPONSE_HELP)
capplet_help (GTK_WINDOW (widget), "goscustperiph-2");
else
gtk_main_quit ();
}
static void
setup_dialog (GtkBuilder * dialog)
{
gchar *monitor;
g_settings_bind (keyboard_settings,
"repeat",
WID ("repeat_toggle"),
"active",
G_SETTINGS_BIND_DEFAULT);
g_settings_bind (keyboard_settings,
"repeat",
WID ("repeat_table"),
"sensitive",
G_SETTINGS_BIND_DEFAULT);
g_settings_bind (keyboard_settings,
"delay",
gtk_range_get_adjustment (GTK_RANGE (WID ("repeat_delay_scale"))),
"value",
G_SETTINGS_BIND_DEFAULT);
g_settings_bind (keyboard_settings,
"rate",
gtk_range_get_adjustment (GTK_RANGE (WID ("repeat_speed_scale"))),
"value",
G_SETTINGS_BIND_DEFAULT);
g_settings_bind (interface_settings,
"cursor-blink",
WID ("cursor_toggle"),
"active",
G_SETTINGS_BIND_DEFAULT);
g_settings_bind (interface_settings,
"cursor-blink",
WID ("cursor_hbox"),
"sensitive",
G_SETTINGS_BIND_DEFAULT);
g_settings_bind (interface_settings,
"cursor-blink-time",
gtk_range_get_adjustment (GTK_RANGE (WID ("cursor_blink_time_scale"))),
"value",
G_SETTINGS_BIND_DEFAULT);
/* Ergonomics */
monitor = g_find_program_in_path ("mate-typing-monitor");
if (monitor != NULL) {
g_free (monitor);
g_settings_bind (typing_break_settings,
"enabled",
WID ("break_enabled_toggle"),
"active",
G_SETTINGS_BIND_DEFAULT);
g_settings_bind (typing_break_settings,
"enabled",
WID ("break_details_table"),
"sensitive",
G_SETTINGS_BIND_DEFAULT);
g_settings_bind (typing_break_settings,
"type-time",
WID ("break_enabled_spin"),
"value",
G_SETTINGS_BIND_DEFAULT);
g_settings_bind (typing_break_settings,
"break-time",
WID ("break_interval_spin"),
"value",
G_SETTINGS_BIND_DEFAULT);
g_settings_bind (typing_break_settings,
"allow-postpone",
WID ("break_postponement_toggle"),
"active",
G_SETTINGS_BIND_DEFAULT);
} else {
/* don't show the typing break tab if the daemon is not available */
GtkNotebook *nb = GTK_NOTEBOOK (WID ("keyboard_notebook"));
gint tb_page = gtk_notebook_page_num (nb, WID ("break_enabled_toggle"));
gtk_notebook_remove_page (nb, tb_page);
}
g_signal_connect (WID ("keyboard_dialog"), "response",
(GCallback) dialog_response, NULL);
setup_xkb_tabs (dialog);
setup_a11y_tabs (dialog);
}
int
main (int argc, char **argv)
{
GtkBuilder *dialog;
GOptionContext *context;
static gboolean apply_only = FALSE;
static gboolean switch_to_typing_break_page = FALSE;
static gboolean switch_to_a11y_page = FALSE;
static GOptionEntry cap_options[] = {
{"apply", 0, 0, G_OPTION_ARG_NONE, &apply_only,
N_
("Just apply settings and quit (compatibility only; now handled by daemon)"),
NULL},
{"init-session-settings", 0, 0, G_OPTION_ARG_NONE,
&apply_only,
N_
("Just apply settings and quit (compatibility only; now handled by daemon)"),
NULL},
{"typing-break", 0, 0, G_OPTION_ARG_NONE,
&switch_to_typing_break_page,
N_
("Start the page with the typing break settings showing"),
NULL},
{"a11y", 0, 0, G_OPTION_ARG_NONE,
&switch_to_a11y_page,
N_
("Start the page with the accessibility settings showing"),
NULL},
{NULL}
};
context = g_option_context_new (_("- MATE Keyboard Preferences"));
g_option_context_add_main_entries (context, cap_options,
GETTEXT_PACKAGE);
capplet_init (context, &argc, &argv);
activate_settings_daemon ();
keyboard_settings = g_settings_new (KEYBOARD_SCHEMA);
interface_settings = g_settings_new (INTERFACE_SCHEMA);
typing_break_settings = g_settings_new (TYPING_BREAK_SCHEMA);
dialog = create_dialog ();
if (!dialog) /* Warning was already printed to console */
exit (EXIT_FAILURE);
setup_dialog (dialog);
if (switch_to_typing_break_page) {
gtk_notebook_set_current_page (GTK_NOTEBOOK
(WID
("keyboard_notebook")),
4);
}
else if (switch_to_a11y_page) {
gtk_notebook_set_current_page (GTK_NOTEBOOK
(WID
("keyboard_notebook")),
2);
}
capplet_set_icon (WID ("keyboard_dialog"),
"preferences-desktop-keyboard");
gtk_widget_show (WID ("keyboard_dialog"));
gtk_main ();
finalize_a11y_tabs ();
g_object_unref (keyboard_settings);
g_object_unref (interface_settings);
g_object_unref (typing_break_settings);
return 0;
}
|