~kroq-gar78/ubuntu/precise/gnome-control-center/fix-885947

« back to all changes in this revision

Viewing changes to capplets/mouse/gnome-mouse-properties.c

  • Committer: Bazaar Package Importer
  • Author(s): Rodrigo Moya
  • Date: 2011-05-17 10:47:27 UTC
  • mfrom: (0.1.11 experimental) (1.1.45 upstream)
  • Revision ID: james.westby@ubuntu.com-20110517104727-lqel6m8vhfw5jby1
Tags: 1:3.0.1.1-1ubuntu1
* Rebase on Debian, remaining Ubuntu changes:
* debian/control:
  - Build-Depend on hardening-wrapper, dpkg-dev and dh-autoreconf
  - Add dependency on ubuntu-system-service
  - Remove dependency on gnome-icon-theme-symbolic
  - Move dependency on apg, gnome-icon-theme-symbolic and accountsservice to
    be a Recommends: until we get them in main
* debian/rules:
  - Use autoreconf
  - Add binary-post-install rule for gnome-control-center-data
  - Run dh-autoreconf
* debian/gnome-control-center.dirs:
* debian/gnome-control-center.links:
  - Add a link to the control center shell for indicators
* debian/patches/00_disable-nm.patch:
  - Temporary patch to disable building with NetworkManager until we get
    the new one in the archive
* debian/patches/01_git_remove_gettext_calls.patch:
  - Remove calls to AM_GNU_GETTEXT, IT_PROG_INTLTOOL should be enough
* debian/patches/01_git_kill_warning.patch:
  - Kill warning
* debian/patches/50_ubuntu_systemwide_prefs.patch:
  - Ubuntu specific proxy preferences
* debian/patches/51_ubuntu_system_keyboard.patch:
  - Implement the global keyboard spec at https://wiki.ubuntu.com/DefaultKeyboardSettings

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c; style: linux -*- */
2
 
 
3
 
/* mouse-properties-capplet.c
4
 
 * Copyright (C) 2001 Red Hat, Inc.
5
 
 * Copyright (C) 2001 Ximian, Inc.
6
 
 *
7
 
 * Written by: Jonathon Blandford <jrb@redhat.com>,
8
 
 *             Bradford Hovinen <hovinen@ximian.com>,
9
 
 *
10
 
 * This program is free software; you can redistribute it and/or modify
11
 
 * it under the terms of the GNU General Public License as published by
12
 
 * the Free Software Foundation; either version 2, or (at your option)
13
 
 * any later version.
14
 
 *
15
 
 * This program is distributed in the hope that it will be useful,
16
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 
 * GNU General Public License for more details.
19
 
 *
20
 
 * You should have received a copy of the GNU General Public License
21
 
 * along with this program; if not, write to the Free Software
22
 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23
 
 * 02111-1307, USA.
24
 
 */
25
 
 
26
 
#include <config.h>
27
 
 
28
 
#include <glib/gi18n.h>
29
 
#include <string.h>
30
 
#include <gconf/gconf-client.h>
31
 
#include <gdk/gdkx.h>
32
 
#include <math.h>
33
 
 
34
 
#include "capplet-util.h"
35
 
#include "gconf-property-editor.h"
36
 
#include "activate-settings-daemon.h"
37
 
#include "capplet-stock-icons.h"
38
 
#include "gnome-mouse-accessibility.h"
39
 
 
40
 
#include <sys/types.h>
41
 
#include <sys/stat.h>
42
 
#include <dirent.h>
43
 
#ifdef HAVE_XINPUT
44
 
#include <X11/Xatom.h>
45
 
#include <X11/extensions/XInput.h>
46
 
#endif
47
 
 
48
 
#ifdef HAVE_XCURSOR
49
 
#include <X11/Xcursor/Xcursor.h>
50
 
#endif
51
 
 
52
 
enum
53
 
{
54
 
        DOUBLE_CLICK_TEST_OFF,
55
 
        DOUBLE_CLICK_TEST_MAYBE,
56
 
        DOUBLE_CLICK_TEST_ON
57
 
};
58
 
 
59
 
/* We use this in at least half a dozen places, so it makes sense just to
60
 
 * define the macro */
61
 
 
62
 
#define DOUBLE_CLICK_KEY "/desktop/gnome/peripherals/mouse/double_click"
63
 
 
64
 
/* State in testing the double-click speed. Global for a great deal of
65
 
 * convenience
66
 
 */
67
 
static gint double_click_state = DOUBLE_CLICK_TEST_OFF;
68
 
 
69
 
/* normalization routines */
70
 
/* All of our scales but double_click are on the range 1->10 as a result, we
71
 
 * have a few routines to convert from whatever the gconf key is to our range.
72
 
 */
73
 
static GConfValue *
74
 
double_click_from_gconf (GConfPropertyEditor *peditor, const GConfValue *value)
75
 
{
76
 
        GConfValue *new_value;
77
 
 
78
 
        new_value = gconf_value_new (GCONF_VALUE_INT);
79
 
        gconf_value_set_int (new_value, CLAMP ((int) floor ((gconf_value_get_int (value) + 50) / 100.0) * 100, 100, 1000));
80
 
        return new_value;
81
 
}
82
 
 
83
 
static void
84
 
get_default_mouse_info (int *default_numerator, int *default_denominator, int *default_threshold)
85
 
{
86
 
        int numerator, denominator;
87
 
        int threshold;
88
 
        int tmp_num, tmp_den, tmp_threshold;
89
 
 
90
 
        /* Query X for the default value */
91
 
        XGetPointerControl (GDK_DISPLAY (), &numerator, &denominator,
92
 
                            &threshold);
93
 
        XChangePointerControl (GDK_DISPLAY (), True, True, -1, -1, -1);
94
 
        XGetPointerControl (GDK_DISPLAY (), &tmp_num, &tmp_den, &tmp_threshold);
95
 
        XChangePointerControl (GDK_DISPLAY (), True, True, numerator, denominator, threshold);
96
 
 
97
 
        if (default_numerator)
98
 
                *default_numerator = tmp_num;
99
 
 
100
 
        if (default_denominator)
101
 
                *default_denominator = tmp_den;
102
 
 
103
 
        if (default_threshold)
104
 
                *default_threshold = tmp_threshold;
105
 
 
106
 
}
107
 
 
108
 
static GConfValue *
109
 
motion_acceleration_from_gconf (GConfPropertyEditor *peditor,
110
 
                                const GConfValue *value)
111
 
{
112
 
        GConfValue *new_value;
113
 
        gfloat motion_acceleration;
114
 
 
115
 
        new_value = gconf_value_new (GCONF_VALUE_FLOAT);
116
 
 
117
 
        if (gconf_value_get_float (value) == -1.0) {
118
 
                int numerator, denominator;
119
 
 
120
 
                get_default_mouse_info (&numerator, &denominator, NULL);
121
 
 
122
 
                motion_acceleration = CLAMP ((gfloat)(numerator / denominator), 0.2, 6.0);
123
 
        }
124
 
        else {
125
 
                motion_acceleration = CLAMP (gconf_value_get_float (value), 0.2, 6.0);
126
 
        }
127
 
 
128
 
        if (motion_acceleration >= 1)
129
 
                gconf_value_set_float (new_value, motion_acceleration + 4);
130
 
        else
131
 
                gconf_value_set_float (new_value, motion_acceleration * 5);
132
 
 
133
 
        return new_value;
134
 
}
135
 
 
136
 
static GConfValue *
137
 
motion_acceleration_to_gconf (GConfPropertyEditor *peditor,
138
 
                              const GConfValue *value)
139
 
{
140
 
        GConfValue *new_value;
141
 
        gfloat motion_acceleration;
142
 
 
143
 
        new_value = gconf_value_new (GCONF_VALUE_FLOAT);
144
 
        motion_acceleration = CLAMP (gconf_value_get_float (value), 1.0, 10.0);
145
 
 
146
 
        if (motion_acceleration < 5)
147
 
                gconf_value_set_float (new_value, motion_acceleration / 5.0);
148
 
        else
149
 
                gconf_value_set_float (new_value, motion_acceleration - 4);
150
 
 
151
 
        return new_value;
152
 
}
153
 
 
154
 
static GConfValue *
155
 
threshold_from_gconf (GConfPropertyEditor *peditor,
156
 
                      const GConfValue *value)
157
 
{
158
 
        GConfValue *new_value;
159
 
 
160
 
        new_value = gconf_value_new (GCONF_VALUE_FLOAT);
161
 
 
162
 
        if (gconf_value_get_int (value) == -1) {
163
 
                int threshold;
164
 
 
165
 
                get_default_mouse_info (NULL, NULL, &threshold);
166
 
                gconf_value_set_float (new_value, CLAMP (threshold, 1, 10));
167
 
        }
168
 
        else {
169
 
                gconf_value_set_float (new_value, CLAMP (gconf_value_get_int (value), 1, 10));
170
 
        }
171
 
 
172
 
        return new_value;
173
 
}
174
 
 
175
 
static GConfValue *
176
 
drag_threshold_from_gconf (GConfPropertyEditor *peditor,
177
 
                           const GConfValue *value)
178
 
{
179
 
        GConfValue *new_value;
180
 
 
181
 
        new_value = gconf_value_new (GCONF_VALUE_FLOAT);
182
 
 
183
 
        gconf_value_set_float (new_value, CLAMP (gconf_value_get_int (value), 1, 10));
184
 
 
185
 
        return new_value;
186
 
}
187
 
 
188
 
/* Double Click handling */
189
 
 
190
 
struct test_data_t
191
 
{
192
 
        gint *timeout_id;
193
 
        GtkWidget *image;
194
 
};
195
 
 
196
 
/* Timeout for the double click test */
197
 
 
198
 
static gboolean
199
 
test_maybe_timeout (struct test_data_t *data)
200
 
{
201
 
        double_click_state = DOUBLE_CLICK_TEST_OFF;
202
 
 
203
 
        gtk_image_set_from_stock (GTK_IMAGE (data->image),
204
 
                                  MOUSE_DBLCLCK_OFF, mouse_capplet_dblclck_icon_get_size());
205
 
 
206
 
        *data->timeout_id = 0;
207
 
 
208
 
        return FALSE;
209
 
}
210
 
 
211
 
/* Callback issued when the user clicks the double click testing area. */
212
 
 
213
 
static gboolean
214
 
event_box_button_press_event (GtkWidget   *widget,
215
 
                              GdkEventButton *event,
216
 
                              GConfChangeSet *changeset)
217
 
{
218
 
        gint                       double_click_time;
219
 
        GConfValue                *value;
220
 
        static struct test_data_t  data;
221
 
        static gint                test_on_timeout_id     = 0;
222
 
        static gint                test_maybe_timeout_id  = 0;
223
 
        static guint32             double_click_timestamp = 0;
224
 
        GtkWidget                 *image;
225
 
        GConfClient               *client;
226
 
 
227
 
        if (event->type != GDK_BUTTON_PRESS)
228
 
                return FALSE;
229
 
 
230
 
        image = g_object_get_data (G_OBJECT (widget), "image");
231
 
 
232
 
        if (!(changeset && gconf_change_set_check_value (changeset, DOUBLE_CLICK_KEY, &value))) {
233
 
                client = gconf_client_get_default();
234
 
                double_click_time = gconf_client_get_int (client, DOUBLE_CLICK_KEY, NULL);
235
 
                g_object_unref (client);
236
 
 
237
 
        } else
238
 
                double_click_time = gconf_value_get_int (value);
239
 
 
240
 
        if (test_maybe_timeout_id != 0)
241
 
                g_source_remove  (test_maybe_timeout_id);
242
 
        if (test_on_timeout_id != 0)
243
 
                g_source_remove (test_on_timeout_id);
244
 
 
245
 
        switch (double_click_state) {
246
 
        case DOUBLE_CLICK_TEST_OFF:
247
 
                double_click_state = DOUBLE_CLICK_TEST_MAYBE;
248
 
                data.image = image;
249
 
                data.timeout_id = &test_maybe_timeout_id;
250
 
                test_maybe_timeout_id = g_timeout_add (double_click_time, (GtkFunction) test_maybe_timeout, &data);
251
 
                break;
252
 
        case DOUBLE_CLICK_TEST_MAYBE:
253
 
                if (event->time - double_click_timestamp < double_click_time) {
254
 
                        double_click_state = DOUBLE_CLICK_TEST_ON;
255
 
                        data.image = image;
256
 
                        data.timeout_id = &test_on_timeout_id;
257
 
                        test_on_timeout_id = g_timeout_add (2500, (GtkFunction) test_maybe_timeout, &data);
258
 
                }
259
 
                break;
260
 
        case DOUBLE_CLICK_TEST_ON:
261
 
                double_click_state = DOUBLE_CLICK_TEST_OFF;
262
 
                break;
263
 
        }
264
 
 
265
 
        double_click_timestamp = event->time;
266
 
 
267
 
        switch (double_click_state) {
268
 
        case DOUBLE_CLICK_TEST_ON:
269
 
                gtk_image_set_from_stock (GTK_IMAGE (image),
270
 
                                          MOUSE_DBLCLCK_ON, mouse_capplet_dblclck_icon_get_size());
271
 
                break;
272
 
        case DOUBLE_CLICK_TEST_MAYBE:
273
 
                gtk_image_set_from_stock (GTK_IMAGE (image),
274
 
                                          MOUSE_DBLCLCK_MAYBE, mouse_capplet_dblclck_icon_get_size());
275
 
                break;
276
 
        case DOUBLE_CLICK_TEST_OFF:
277
 
                gtk_image_set_from_stock (GTK_IMAGE (image),
278
 
                                          MOUSE_DBLCLCK_OFF, mouse_capplet_dblclck_icon_get_size());
279
 
                break;
280
 
        }
281
 
 
282
 
        return TRUE;
283
 
}
284
 
 
285
 
static void
286
 
orientation_radio_button_release_event (GtkWidget   *widget,
287
 
                                        GdkEventButton *event)
288
 
{
289
 
        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
290
 
}
291
 
 
292
 
static GConfValue *
293
 
left_handed_from_gconf (GConfPropertyEditor *peditor,
294
 
                        const GConfValue *value)
295
 
{
296
 
        GConfValue *new_value;
297
 
 
298
 
        new_value = gconf_value_new (GCONF_VALUE_INT);
299
 
 
300
 
        gconf_value_set_int (new_value, gconf_value_get_bool (value));
301
 
 
302
 
        return new_value;
303
 
}
304
 
 
305
 
static GConfValue *
306
 
left_handed_to_gconf (GConfPropertyEditor *peditor,
307
 
                      const GConfValue *value)
308
 
{
309
 
        GConfValue *new_value;
310
 
 
311
 
        new_value = gconf_value_new (GCONF_VALUE_BOOL);
312
 
 
313
 
        gconf_value_set_bool (new_value, gconf_value_get_int (value) == 1);
314
 
 
315
 
        return new_value;
316
 
}
317
 
 
318
 
static void
319
 
scrollmethod_changed_event (GConfPropertyEditor *peditor,
320
 
                            const gchar *key,
321
 
                            const GConfValue *value,
322
 
                            GtkBuilder *dialog)
323
 
{
324
 
        GtkToggleButton *disabled = GTK_TOGGLE_BUTTON (WID ("scroll_disabled_radio"));
325
 
 
326
 
        gtk_widget_set_sensitive (WID ("horiz_scroll_toggle"),
327
 
                                  !gtk_toggle_button_get_active (disabled));
328
 
}
329
 
 
330
 
static void
331
 
synaptics_check_capabilities (GtkBuilder *dialog)
332
 
{
333
 
#ifdef HAVE_XINPUT
334
 
        int numdevices, i;
335
 
        XDeviceInfo *devicelist;
336
 
        Atom realtype, prop;
337
 
        int realformat;
338
 
        unsigned long nitems, bytes_after;
339
 
        unsigned char *data;
340
 
 
341
 
        prop = XInternAtom (GDK_DISPLAY (), "Synaptics Capabilities", True);
342
 
        if (!prop)
343
 
                return;
344
 
 
345
 
        devicelist = XListInputDevices (GDK_DISPLAY (), &numdevices);
346
 
        for (i = 0; i < numdevices; i++) {
347
 
                if (devicelist[i].use != IsXExtensionPointer)
348
 
                        continue;
349
 
 
350
 
                gdk_error_trap_push ();
351
 
                XDevice *device = XOpenDevice (GDK_DISPLAY (),
352
 
                                               devicelist[i].id);
353
 
                if (gdk_error_trap_pop ())
354
 
                        continue;
355
 
 
356
 
                gdk_error_trap_push ();
357
 
                if ((XGetDeviceProperty (GDK_DISPLAY (), device, prop, 0, 2, False,
358
 
                                         XA_INTEGER, &realtype, &realformat, &nitems,
359
 
                                         &bytes_after, &data) == Success) && (realtype != None)) {
360
 
                        /* Property data is booleans for has_left, has_middle, has_right, has_double, has_triple.
361
 
                         * Newer drivers (X.org/kerrnel) will also include has_pressure and has_width. */
362
 
                        if (!data[0]) {
363
 
                                gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (WID ("tap_to_click_toggle")), TRUE);
364
 
                                gtk_widget_set_sensitive (WID ("tap_to_click_toggle"), FALSE);
365
 
                        }
366
 
 
367
 
                        /* Disable two finger scrolling unless the hardware supports
368
 
                         * double touch or can emulate it based on finger width. */
369
 
                        if (!(data[3] ||(nitems >= 6 && data[5])))
370
 
                                gtk_widget_set_sensitive (WID ("scroll_twofinger_radio"), FALSE);
371
 
 
372
 
                        XFree (data);
373
 
                }
374
 
                gdk_error_trap_pop ();
375
 
 
376
 
                XCloseDevice (GDK_DISPLAY (), device);
377
 
        }
378
 
        XFreeDeviceList (devicelist);
379
 
#endif
380
 
}
381
 
 
382
 
static gboolean
383
 
find_synaptics (void)
384
 
{
385
 
        gboolean ret = FALSE;
386
 
#ifdef HAVE_XINPUT
387
 
        int numdevices, i;
388
 
        XDeviceInfo *devicelist;
389
 
        Atom realtype, prop;
390
 
        int realformat;
391
 
        unsigned long nitems, bytes_after;
392
 
        unsigned char *data;
393
 
        XExtensionVersion *version;
394
 
 
395
 
        /* Input device properties require version 1.5 or higher */
396
 
        version = XGetExtensionVersion (GDK_DISPLAY (), "XInputExtension");
397
 
        if (!version->present ||
398
 
                (version->major_version * 1000 + version->minor_version) < 1005) {
399
 
                XFree (version);
400
 
                return False;
401
 
        }
402
 
 
403
 
        prop = XInternAtom (GDK_DISPLAY (), "Synaptics Off", True);
404
 
        if (!prop)
405
 
                return False;
406
 
 
407
 
        devicelist = XListInputDevices (GDK_DISPLAY (), &numdevices);
408
 
        for (i = 0; i < numdevices; i++) {
409
 
                if (devicelist[i].use != IsXExtensionPointer)
410
 
                        continue;
411
 
 
412
 
                gdk_error_trap_push();
413
 
                XDevice *device = XOpenDevice (GDK_DISPLAY (),
414
 
                                               devicelist[i].id);
415
 
                if (gdk_error_trap_pop ())
416
 
                        continue;
417
 
 
418
 
                gdk_error_trap_push ();
419
 
                if ((XGetDeviceProperty (GDK_DISPLAY (), device, prop, 0, 1, False,
420
 
                                         XA_INTEGER, &realtype, &realformat, &nitems,
421
 
                                         &bytes_after, &data) == Success) && (realtype != None)) {
422
 
                        XFree (data);
423
 
                        ret = TRUE;
424
 
                }
425
 
                gdk_error_trap_pop ();
426
 
 
427
 
                XCloseDevice (GDK_DISPLAY (), device);
428
 
 
429
 
                if (ret)
430
 
                        break;
431
 
        }
432
 
 
433
 
        XFree (version);
434
 
        XFreeDeviceList (devicelist);
435
 
#endif
436
 
        return ret;
437
 
}
438
 
 
439
 
/* Set up the property editors in the dialog. */
440
 
static void
441
 
setup_dialog (GtkBuilder *dialog, GConfChangeSet *changeset)
442
 
{
443
 
        GtkRadioButton    *radio;
444
 
        GObject           *peditor;
445
 
 
446
 
        /* Orientation radio buttons */
447
 
        radio = GTK_RADIO_BUTTON (WID ("left_handed_radio"));
448
 
        peditor = gconf_peditor_new_select_radio
449
 
                (changeset, "/desktop/gnome/peripherals/mouse/left_handed", gtk_radio_button_get_group (radio),
450
 
                 "conv-to-widget-cb", left_handed_from_gconf,
451
 
                 "conv-from-widget-cb", left_handed_to_gconf,
452
 
                 NULL);
453
 
        /* explicitly connect to button-release so that you can change orientation with either button */
454
 
        g_signal_connect (WID ("right_handed_radio"), "button_release_event",
455
 
                G_CALLBACK (orientation_radio_button_release_event), NULL);
456
 
        g_signal_connect (WID ("left_handed_radio"), "button_release_event",
457
 
                G_CALLBACK (orientation_radio_button_release_event), NULL);
458
 
 
459
 
        /* Locate pointer toggle */
460
 
        peditor = gconf_peditor_new_boolean
461
 
                (changeset, "/desktop/gnome/peripherals/mouse/locate_pointer", WID ("locate_pointer_toggle"), NULL);
462
 
 
463
 
        /* Double-click time */
464
 
        peditor = gconf_peditor_new_numeric_range
465
 
                (changeset, DOUBLE_CLICK_KEY, WID ("delay_scale"),
466
 
                 "conv-to-widget-cb", double_click_from_gconf,
467
 
                 NULL);
468
 
        gtk_image_set_from_stock (GTK_IMAGE (WID ("double_click_image")), MOUSE_DBLCLCK_OFF, mouse_capplet_dblclck_icon_get_size ());
469
 
        g_object_set_data (G_OBJECT (WID ("double_click_eventbox")), "image", WID ("double_click_image"));
470
 
        g_signal_connect (WID ("double_click_eventbox"), "button_press_event",
471
 
                          G_CALLBACK (event_box_button_press_event), changeset);
472
 
 
473
 
        /* speed */
474
 
        gconf_peditor_new_numeric_range
475
 
                (changeset, "/desktop/gnome/peripherals/mouse/motion_acceleration", WID ("accel_scale"),
476
 
                 "conv-to-widget-cb", motion_acceleration_from_gconf,
477
 
                 "conv-from-widget-cb", motion_acceleration_to_gconf,
478
 
                 NULL);
479
 
 
480
 
        gconf_peditor_new_numeric_range
481
 
                (changeset, "/desktop/gnome/peripherals/mouse/motion_threshold", WID ("sensitivity_scale"),
482
 
                 "conv-to-widget-cb", threshold_from_gconf,
483
 
                 NULL);
484
 
 
485
 
        /* DnD threshold */
486
 
        gconf_peditor_new_numeric_range
487
 
                (changeset, "/desktop/gnome/peripherals/mouse/drag_threshold", WID ("drag_threshold_scale"),
488
 
                 "conv-to-widget-cb", drag_threshold_from_gconf,
489
 
                 NULL);
490
 
 
491
 
        /* Trackpad page */
492
 
        if (find_synaptics () == FALSE)
493
 
                gtk_notebook_remove_page (GTK_NOTEBOOK (WID ("prefs_widget")), -1);
494
 
        else {
495
 
                gconf_peditor_new_boolean
496
 
                        (changeset, "/desktop/gnome/peripherals/touchpad/disable_while_typing", WID ("disable_w_typing_toggle"), NULL);
497
 
                gconf_peditor_new_boolean
498
 
                        (changeset, "/desktop/gnome/peripherals/touchpad/tap_to_click", WID ("tap_to_click_toggle"), NULL);
499
 
                gconf_peditor_new_boolean
500
 
                        (changeset, "/desktop/gnome/peripherals/touchpad/horiz_scroll_enabled", WID ("horiz_scroll_toggle"), NULL);
501
 
                radio = GTK_RADIO_BUTTON (WID ("scroll_disabled_radio"));
502
 
                peditor = gconf_peditor_new_select_radio
503
 
                        (changeset, "/desktop/gnome/peripherals/touchpad/scroll_method", gtk_radio_button_get_group (radio),
504
 
                         NULL);
505
 
 
506
 
                synaptics_check_capabilities (dialog);
507
 
                scrollmethod_changed_event (GCONF_PROPERTY_EDITOR (peditor), NULL, NULL, dialog);
508
 
                g_signal_connect (peditor, "value-changed",
509
 
                                  G_CALLBACK (scrollmethod_changed_event), dialog);
510
 
        }
511
 
 
512
 
}
513
 
 
514
 
/* Construct the dialog */
515
 
 
516
 
static GtkBuilder *
517
 
create_dialog (void)
518
 
{
519
 
        GtkBuilder   *dialog;
520
 
        GtkSizeGroup *size_group;
521
 
        GError       *error = NULL;
522
 
 
523
 
        dialog = gtk_builder_new ();
524
 
        gtk_builder_add_from_file (dialog, GNOMECC_UI_DIR "/gnome-mouse-properties.ui", &error);
525
 
        if (error != NULL) {
526
 
                g_warning ("Error loading UI file: %s", error->message);
527
 
                return NULL;
528
 
        }
529
 
 
530
 
        size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
531
 
        gtk_size_group_add_widget (size_group, WID ("acceleration_label"));
532
 
        gtk_size_group_add_widget (size_group, WID ("sensitivity_label"));
533
 
        gtk_size_group_add_widget (size_group, WID ("threshold_label"));
534
 
        gtk_size_group_add_widget (size_group, WID ("timeout_label"));
535
 
 
536
 
        size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
537
 
        gtk_size_group_add_widget (size_group, WID ("acceleration_fast_label"));
538
 
        gtk_size_group_add_widget (size_group, WID ("sensitivity_high_label"));
539
 
        gtk_size_group_add_widget (size_group, WID ("threshold_large_label"));
540
 
        gtk_size_group_add_widget (size_group, WID ("timeout_long_label"));
541
 
 
542
 
        size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
543
 
        gtk_size_group_add_widget (size_group, WID ("acceleration_slow_label"));
544
 
        gtk_size_group_add_widget (size_group, WID ("sensitivity_low_label"));
545
 
        gtk_size_group_add_widget (size_group, WID ("threshold_small_label"));
546
 
        gtk_size_group_add_widget (size_group, WID ("timeout_short_label"));
547
 
 
548
 
        size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
549
 
        gtk_size_group_add_widget (size_group, WID ("simulated_delay_label"));
550
 
        gtk_size_group_add_widget (size_group, WID ("dwell_delay_label"));
551
 
        gtk_size_group_add_widget (size_group, WID ("dwell_threshold_label"));
552
 
 
553
 
        size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
554
 
        gtk_size_group_add_widget (size_group, WID ("simulated_delay_short_label"));
555
 
        gtk_size_group_add_widget (size_group, WID ("dwell_delay_short_label"));
556
 
        gtk_size_group_add_widget (size_group, WID ("dwell_threshold_small_label"));
557
 
 
558
 
        size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
559
 
        gtk_size_group_add_widget (size_group, WID ("simulated_delay_long_label"));
560
 
        gtk_size_group_add_widget (size_group, WID ("dwell_delay_long_label"));
561
 
        gtk_size_group_add_widget (size_group, WID ("dwell_threshold_large_label"));
562
 
 
563
 
        return dialog;
564
 
}
565
 
 
566
 
/* Callback issued when a button is clicked on the dialog */
567
 
 
568
 
static void
569
 
dialog_response_cb (GtkDialog *dialog, gint response_id, GConfChangeSet *changeset)
570
 
{
571
 
        if (response_id == GTK_RESPONSE_HELP)
572
 
                capplet_help (GTK_WINDOW (dialog),
573
 
                              "goscustperiph-5");
574
 
        else
575
 
                gtk_main_quit ();
576
 
}
577
 
 
578
 
int
579
 
main (int argc, char **argv)
580
 
{
581
 
        GConfClient    *client;
582
 
        GtkBuilder     *dialog;
583
 
        GtkWidget      *dialog_win, *w;
584
 
        gchar *start_page = NULL;
585
 
 
586
 
        GOptionContext *context;
587
 
        GOptionEntry cap_options[] = {
588
 
                {"show-page", 'p', G_OPTION_FLAG_IN_MAIN,
589
 
                 G_OPTION_ARG_STRING,
590
 
                 &start_page,
591
 
                 /* TRANSLATORS: don't translate the terms in brackets */
592
 
                 N_("Specify the name of the page to show (general|accessibility)"),
593
 
                 N_("page") },
594
 
                {NULL}
595
 
        };
596
 
 
597
 
        context = g_option_context_new (_("- GNOME Mouse Preferences"));
598
 
        g_option_context_add_main_entries (context, cap_options, GETTEXT_PACKAGE);
599
 
        capplet_init (context, &argc, &argv);
600
 
 
601
 
        capplet_init_stock_icons ();
602
 
 
603
 
        activate_settings_daemon ();
604
 
 
605
 
        client = gconf_client_get_default ();
606
 
        gconf_client_add_dir (client, "/desktop/gnome/peripherals/mouse", GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
607
 
        gconf_client_add_dir (client, "/desktop/gnome/peripherals/touchpad", GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
608
 
 
609
 
        dialog = create_dialog ();
610
 
 
611
 
        if (dialog) {
612
 
                setup_dialog (dialog, NULL);
613
 
                setup_accessibility (dialog, client);
614
 
 
615
 
                dialog_win = WID ("mouse_properties_dialog");
616
 
                g_signal_connect (dialog_win, "response",
617
 
                                  G_CALLBACK (dialog_response_cb), NULL);
618
 
 
619
 
                if (start_page != NULL) {
620
 
                        gchar *page_name;
621
 
 
622
 
                        page_name = g_strconcat (start_page, "_vbox", NULL);
623
 
                        g_free (start_page);
624
 
 
625
 
                        w = WID (page_name);
626
 
                        if (w != NULL) {
627
 
                                GtkNotebook *nb;
628
 
                                gint pindex;
629
 
 
630
 
                                nb = GTK_NOTEBOOK (WID ("prefs_widget"));
631
 
                                pindex = gtk_notebook_page_num (nb, w);
632
 
                                if (pindex != -1)
633
 
                                        gtk_notebook_set_current_page (nb, pindex);
634
 
                        }
635
 
                        g_free (page_name);
636
 
                }
637
 
 
638
 
                capplet_set_icon (dialog_win, "input-mouse");
639
 
                gtk_widget_show (dialog_win);
640
 
 
641
 
                gtk_main ();
642
 
 
643
 
                g_object_unref (dialog);
644
 
        }
645
 
 
646
 
        g_object_unref (client);
647
 
 
648
 
        return 0;
649
 
}