1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
3
* Copyright (C) 2001, 2012 Red Hat, Inc.
4
* Copyright (C) 2001 Ximian, Inc.
6
* Written by: Jonathon Blandford <jrb@redhat.com>,
7
* Bradford Hovinen <hovinen@ximian.com>,
8
* Ondrej Holy <oholy@redhat.com>,
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)
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.
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
28
#include <glib/gi18n.h>
32
#include <gnome-settings-daemon/gsd-enums.h>
35
#include "gnome-mouse-properties.h"
36
#include "gsd-input-helper.h"
38
#include <sys/types.h>
42
#include <X11/Xatom.h>
43
#include <X11/extensions/XInput.h>
45
#define WID(x) (GtkWidget*) gtk_builder_get_object (dialog, x)
47
static GSettings *mouse_settings = NULL;
48
static GSettings *touchpad_settings = NULL;
49
static GdkDeviceManager *device_manager = NULL;
50
static guint device_added_id = 0;
51
static guint device_removed_id = 0;
52
static gboolean changing_scroll = FALSE;
55
orientation_radio_button_release_event (GtkWidget *widget,
56
GdkEventButton *event)
58
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
62
setup_scrollmethod_radios (GtkBuilder *dialog)
64
GsdTouchpadScrollMethod method;
67
method = g_settings_get_enum (touchpad_settings, "scroll-method");
68
active = (method == GSD_TOUCHPAD_SCROLL_METHOD_TWO_FINGER_SCROLLING);
69
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (WID ("two_finger_scroll_toggle")), active);
73
scrollmethod_changed_event (GtkToggleButton *button, GtkBuilder *dialog)
75
GsdTouchpadScrollMethod method;
80
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (WID ("two_finger_scroll_toggle"))))
81
method = GSD_TOUCHPAD_SCROLL_METHOD_TWO_FINGER_SCROLLING;
83
method = GSD_TOUCHPAD_SCROLL_METHOD_EDGE_SCROLLING;
85
g_settings_set_enum (touchpad_settings, "scroll-method", method);
89
synaptics_check_capabilities (GtkBuilder *dialog)
92
XDeviceInfo *devicelist;
95
unsigned long nitems, bytes_after;
98
prop = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), "Synaptics Capabilities", True);
102
devicelist = XListInputDevices (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), &numdevices);
103
for (i = 0; i < numdevices; i++) {
104
if (devicelist[i].use != IsXExtensionPointer)
107
gdk_error_trap_push ();
108
XDevice *device = XOpenDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),
110
if (gdk_error_trap_pop ())
113
gdk_error_trap_push ();
114
if ((XGetDeviceProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), device, prop, 0, 2, False,
115
XA_INTEGER, &realtype, &realformat, &nitems,
116
&bytes_after, &data) == Success) && (realtype != None)) {
117
/* Property data is booleans for has_left, has_middle, has_right, has_double, has_triple.
118
* Newer drivers (X.org/kerrnel) will also include has_pressure and has_width. */
120
gtk_widget_set_sensitive (WID ("tap_to_click_toggle"), FALSE);
123
/* Disable two finger scrolling unless the hardware supports
126
gtk_widget_set_sensitive (WID ("two_finger_scroll_toggle"), FALSE);
130
gdk_error_trap_pop_ignored ();
132
XCloseDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), device);
134
XFreeDeviceList (devicelist);
138
pointer_speed_scale_event (GtkRange *scale, GtkBuilder *dialog)
142
GtkAdjustment *adjustment;
144
if (GTK_WIDGET (scale) == WID ("pointer_speed_scale"))
145
settings = mouse_settings;
147
settings = touchpad_settings;
149
g_settings_set_double (settings, "motion-acceleration", gtk_range_get_value (scale));
151
adjustment = gtk_range_get_adjustment (scale);
152
value = gtk_adjustment_get_upper (adjustment) - gtk_range_get_value (scale) + 1;
153
g_settings_set_int (settings, "motion-threshold", value);
156
/* Set up the property editors in the dialog. */
158
setup_dialog (GtkBuilder *dialog)
160
GtkRadioButton *radio;
161
gboolean touchpad_present, mouse_present;
163
/* Orientation radio buttons */
164
radio = GTK_RADIO_BUTTON (WID ("left_handed_radio"));
165
g_settings_bind (mouse_settings, "left-handed", radio, "active", G_SETTINGS_BIND_DEFAULT);
167
/* explicitly connect to button-release so that you can change orientation with either button */
168
g_signal_connect (WID ("right_handed_radio"), "button_release_event",
169
G_CALLBACK (orientation_radio_button_release_event), NULL);
170
g_signal_connect (WID ("left_handed_radio"), "button_release_event",
171
G_CALLBACK (orientation_radio_button_release_event), NULL);
173
/* Double-click time */
174
g_settings_bind (mouse_settings, "double-click",
175
gtk_range_get_adjustment (GTK_RANGE (WID ("double_click_scale"))), "value",
176
G_SETTINGS_BIND_DEFAULT);
179
mouse_present = mouse_is_present ();
180
gtk_widget_set_visible (WID ("mouse_vbox"), mouse_present);
182
g_signal_connect (WID ("pointer_speed_scale"), "value-changed",
183
G_CALLBACK (pointer_speed_scale_event), dialog);
184
g_settings_bind (mouse_settings, "motion-acceleration",
185
gtk_range_get_adjustment (GTK_RANGE (WID ("pointer_speed_scale"))), "value",
186
G_SETTINGS_BIND_DEFAULT);
189
touchpad_present = touchpad_is_present ();
190
gtk_widget_set_visible (WID ("touchpad_vbox"), touchpad_present);
192
g_settings_bind (touchpad_settings, "touchpad-enabled",
193
WID ("touchpad_enabled_switch"), "active",
194
G_SETTINGS_BIND_DEFAULT);
195
g_settings_bind (touchpad_settings, "touchpad-enabled",
196
WID ("touchpad_options_box"), "sensitive",
197
G_SETTINGS_BIND_GET);
199
g_settings_bind (touchpad_settings, "disable-while-typing",
200
WID ("disable_w_typing_toggle"), "active",
201
G_SETTINGS_BIND_DEFAULT);
202
g_settings_bind (touchpad_settings, "tap-to-click",
203
WID ("tap_to_click_toggle"), "active",
204
G_SETTINGS_BIND_DEFAULT);
205
g_settings_bind (touchpad_settings, "natural-scroll",
206
WID ("natural_scroll_toggle"), "active",
207
G_SETTINGS_BIND_DEFAULT);
208
g_settings_bind (touchpad_settings, "motion-acceleration",
209
gtk_range_get_adjustment (GTK_RANGE (WID ("touchpad_pointer_speed_scale"))), "value",
210
G_SETTINGS_BIND_DEFAULT);
212
g_signal_connect (WID ("touchpad_pointer_speed_scale"), "value-changed",
213
G_CALLBACK (pointer_speed_scale_event), dialog);
215
if (touchpad_present) {
216
synaptics_check_capabilities (dialog);
217
setup_scrollmethod_radios (dialog);
220
g_signal_connect (WID ("two_finger_scroll_toggle"), "toggled",
221
G_CALLBACK (scrollmethod_changed_event), dialog);
224
/* Construct the dialog */
227
create_dialog (GtkBuilder *dialog)
229
GtkSizeGroup *size_group;
231
size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
232
gtk_size_group_add_widget (size_group, WID ("primary_button_label"));
233
gtk_size_group_add_widget (size_group, WID ("pointer_speed_label"));
234
gtk_size_group_add_widget (size_group, WID ("double_click_label"));
235
gtk_size_group_add_widget (size_group, WID ("touchpad_pointer_speed_label"));
237
size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
238
gtk_size_group_add_widget (size_group, WID ("pointer_speed_fast_label"));
239
gtk_size_group_add_widget (size_group, WID ("double_click_fast_label"));
240
gtk_size_group_add_widget (size_group, WID ("touchpad_pointer_speed_fast_label"));
242
size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
243
gtk_size_group_add_widget (size_group, WID ("pointer_speed_slow_label"));
244
gtk_size_group_add_widget (size_group, WID ("double_click_slow_label"));
245
gtk_size_group_add_widget (size_group, WID ("touchpad_pointer_speed_slow_label"));
247
gtk_widget_set_direction (WID ("primary_button_box"), GTK_TEXT_DIR_LTR);
250
/* Callback issued when a button is clicked on the dialog */
253
device_changed (GdkDeviceManager *device_manager,
259
present = touchpad_is_present ();
260
gtk_widget_set_visible (WID ("touchpad_vbox"), present);
263
changing_scroll = TRUE;
264
synaptics_check_capabilities (dialog);
265
setup_scrollmethod_radios (dialog);
266
changing_scroll = FALSE;
269
present = mouse_is_present ();
270
gtk_widget_set_visible (WID ("mouse_vbox"), present);
274
gnome_mouse_properties_init (GtkBuilder *dialog)
276
mouse_settings = g_settings_new ("org.gnome.settings-daemon.peripherals.mouse");
277
touchpad_settings = g_settings_new ("org.gnome.settings-daemon.peripherals.touchpad");
279
device_manager = gdk_display_get_device_manager (gdk_display_get_default ());
280
device_added_id = g_signal_connect (device_manager, "device-added",
281
G_CALLBACK (device_changed), dialog);
282
device_removed_id = g_signal_connect (device_manager, "device-removed",
283
G_CALLBACK (device_changed), dialog);
285
create_dialog (dialog);
286
setup_dialog (dialog);
288
return WID ("mouse_properties_dialog");
292
gnome_mouse_properties_dispose (GtkWidget *widget)
294
if (mouse_settings != NULL) {
295
g_object_unref (mouse_settings);
296
mouse_settings = NULL;
298
if (touchpad_settings != NULL) {
299
g_object_unref (touchpad_settings);
300
touchpad_settings = NULL;
302
if (device_manager != NULL) {
303
g_signal_handler_disconnect (device_manager, device_added_id);
305
g_signal_handler_disconnect (device_manager, device_removed_id);
306
device_removed_id = 0;
307
device_manager = NULL;