summaryrefslogtreecommitdiff
path: root/capplets/keyboard/mate-keyboard-properties.c
blob: bb744afbf6eb07082207234d1d9af454eaec6e36 (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
/* -*- 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 "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"

#define GET_RANGE(s) GTK_RANGE (gtk_builder_get_object (dialog, s))

enum {
	RESPONSE_APPLY = 1,
	RESPONSE_CLOSE
};

static GSettings * keyboard_settings = NULL;
static GSettings * interface_settings = NULL;
static GSettings * typing_break_settings = NULL;

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",
	                 gtk_builder_get_object (dialog, "repeat_toggle"), "active",
	                 G_SETTINGS_BIND_DEFAULT);
	g_settings_bind (keyboard_settings, "repeat",
	                 gtk_builder_get_object (dialog, "repeat_table"), "sensitive",
	                 G_SETTINGS_BIND_DEFAULT);
	g_settings_bind (keyboard_settings, "delay",
	                 gtk_range_get_adjustment (GET_RANGE ("repeat_delay_scale")), "value",
	                 G_SETTINGS_BIND_DEFAULT);
	g_settings_bind (keyboard_settings, "rate",
	                 gtk_range_get_adjustment (GET_RANGE ("repeat_speed_scale")), "value",
	                 G_SETTINGS_BIND_DEFAULT);
	g_settings_bind (interface_settings, "cursor-blink",
	                 gtk_builder_get_object (dialog, "cursor_toggle"), "active",
	                 G_SETTINGS_BIND_DEFAULT);
	g_settings_bind (interface_settings, "cursor-blink",
	                 gtk_builder_get_object (dialog, "cursor_hbox"), "sensitive",
	                 G_SETTINGS_BIND_DEFAULT);
	g_settings_bind (interface_settings, "cursor-blink-time",
	                 gtk_range_get_adjustment (GET_RANGE ("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",
		                 gtk_builder_get_object (dialog, "break_enabled_toggle"), "active",
		                 G_SETTINGS_BIND_DEFAULT);
		g_settings_bind (typing_break_settings, "enabled",
		                 gtk_builder_get_object (dialog, "break_details_table"), "sensitive",
		                 G_SETTINGS_BIND_DEFAULT);
		g_settings_bind (typing_break_settings, "type-time",
		                 gtk_builder_get_object (dialog, "break_enabled_spin"), "value",
		                 G_SETTINGS_BIND_DEFAULT);
		g_settings_bind (typing_break_settings, "break-time",
		                 gtk_builder_get_object (dialog, "break_interval_spin"), "value",
		                 G_SETTINGS_BIND_DEFAULT);
		g_settings_bind (typing_break_settings, "allow-postpone",
		                 gtk_builder_get_object (dialog, "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 (gtk_builder_get_object (dialog, "keyboard_notebook"));
		gint tb_page = gtk_notebook_page_num (nb, WID ("break_enabled_toggle"));
		gtk_notebook_remove_page (nb, tb_page);
	}

	g_signal_connect (gtk_builder_get_object (dialog, "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, 0, 0, G_OPTION_ARG_NONE, NULL, 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);
	g_option_context_free (context);

	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 = gtk_builder_new_from_resource ("/org/mate/mcc/keyboard/mate-keyboard-properties-dialog.ui");

	setup_dialog (dialog);

        GtkNotebook* nb = GTK_NOTEBOOK (gtk_builder_get_object (dialog, "keyboard_notebook"));
        gtk_widget_add_events (GTK_WIDGET (nb), GDK_SCROLL_MASK);
        g_signal_connect (nb, "scroll-event",
                          G_CALLBACK (capplet_notebook_scroll_event_cb),
                          NULL);

	if (switch_to_typing_break_page) {
		gtk_notebook_set_current_page (nb, 4);
	}
	else if (switch_to_a11y_page) {
		gtk_notebook_set_current_page (nb, 2);

	}

	capplet_set_icon (WID ("keyboard_dialog"),
			  "input-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;
}