gnome-control-center/panels/mouse/gnome-mouse-properties.c

379 lines
12 KiB
C
Raw Normal View History

/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2001 Red Hat, Inc.
* Copyright (C) 2001 Ximian, Inc.
*
* Written by: Jonathon Blandford <jrb@redhat.com>,
* Bradford Hovinen <hovinen@ximian.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., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*/
#include <config.h>
#include <glib/gi18n.h>
#include <string.h>
#include <gdk/gdkx.h>
#include <gnome-settings-daemon/gsd-enums.h>
2001-12-16 08:23:09 +00:00
#include <math.h>
#include "gnome-mouse-properties.h"
#include "gsd-input-helper.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <X11/Xatom.h>
#include <X11/extensions/XInput.h>
#define WID(x) (GtkWidget*) gtk_builder_get_object (dialog, x)
2001-12-16 08:23:09 +00:00
enum
{
DOUBLE_CLICK_TEST_OFF,
DOUBLE_CLICK_TEST_MAYBE,
DOUBLE_CLICK_TEST_ON
2001-12-16 08:23:09 +00:00
};
/* State in testing the double-click speed. Global for a great deal of
* convenience
*/
static gint double_click_state = DOUBLE_CLICK_TEST_OFF;
static GSettings *mouse_settings = NULL;
static GSettings *touchpad_settings = NULL;
2001-12-16 08:23:09 +00:00
/* Double Click handling */
Added exception RollbackDataNotFound Added exception LocationNotFound 2001-08-21 Bradford Hovinen <hovinen@ximian.com> * idl/ConfigArchiver.idl: Added exception RollbackDataNotFound Added exception LocationNotFound * archive.c (archive_get_current_location_id): Use archive_create_location rather than location_new (archive_get_current_location_id): Unref the location once we have created it * archiver-client.c (location_client_load_rollback_data): Don't try to parse the XML file if there was an exception * bonobo-config-archiver.c (bonobo_config_archiver_new): Make sure to release_unref location and archive if aborting (bonobo_config_archiver_new): Reinitialize exception structure after we have succeeded * location.c (location_get_rollback_filename): Recurse on parent location if parent_chain is set to TRUE * archive.c (impl_ConfigArchiver_Archive_getLocation): Set the LocationNotFound exception if the location returned was NULL * location.c (impl_ConfigArchiver_Location_getRollbackFilename): Don't try * archive.c (impl_ConfigArchiver_Archive_getLocation): Don't try to CORBA_Object_duplicate the result if it is NULL (archive_get_location): Don't try to cast the result of location_open before we know whether it is non-NULL (impl_ConfigArchiver_Archive_createLocation): Call bonobo_object_from_servant on parent_ref->servant * location.c (location_destroy): Remove debugging message; make remaining debugging message more enlightening * archive.c (archive_get_child_locations): Rename from archive_foreach_child_location; rewrite to return a GList of child locations (impl_ConfigArchiver_Archive_getChildLocations): Use archive_get_child_locations (archive_destroy): Remove debugging message * bonobo-moniker-archiver.c (archive_resolve): Remove debugging messages * archive.c (archive_get_location): Remove debugging messages * config-log.c (dump_log): Remove debugging messages * archive.c (archive_foreach_child_location): Build a list first and then traverse it to avoid screwing up the tree traversal * mouse-properties-capplet.c (apply_settings): Use a CORBA exception structure
2001-08-22 13:56:23 +00:00
struct test_data_t
2001-12-16 08:23:09 +00:00
{
gint *timeout_id;
GtkWidget *image;
};
/* Timeout for the double click test */
static gboolean
test_maybe_timeout (struct test_data_t *data)
{
2001-12-16 08:23:09 +00:00
double_click_state = DOUBLE_CLICK_TEST_OFF;
gtk_image_set_from_icon_name (GTK_IMAGE (data->image), "face-plain", GTK_ICON_SIZE_DIALOG);
*data->timeout_id = 0;
Added exception RollbackDataNotFound Added exception LocationNotFound 2001-08-21 Bradford Hovinen <hovinen@ximian.com> * idl/ConfigArchiver.idl: Added exception RollbackDataNotFound Added exception LocationNotFound * archive.c (archive_get_current_location_id): Use archive_create_location rather than location_new (archive_get_current_location_id): Unref the location once we have created it * archiver-client.c (location_client_load_rollback_data): Don't try to parse the XML file if there was an exception * bonobo-config-archiver.c (bonobo_config_archiver_new): Make sure to release_unref location and archive if aborting (bonobo_config_archiver_new): Reinitialize exception structure after we have succeeded * location.c (location_get_rollback_filename): Recurse on parent location if parent_chain is set to TRUE * archive.c (impl_ConfigArchiver_Archive_getLocation): Set the LocationNotFound exception if the location returned was NULL * location.c (impl_ConfigArchiver_Location_getRollbackFilename): Don't try * archive.c (impl_ConfigArchiver_Archive_getLocation): Don't try to CORBA_Object_duplicate the result if it is NULL (archive_get_location): Don't try to cast the result of location_open before we know whether it is non-NULL (impl_ConfigArchiver_Archive_createLocation): Call bonobo_object_from_servant on parent_ref->servant * location.c (location_destroy): Remove debugging message; make remaining debugging message more enlightening * archive.c (archive_get_child_locations): Rename from archive_foreach_child_location; rewrite to return a GList of child locations (impl_ConfigArchiver_Archive_getChildLocations): Use archive_get_child_locations (archive_destroy): Remove debugging message * bonobo-moniker-archiver.c (archive_resolve): Remove debugging messages * archive.c (archive_get_location): Remove debugging messages * config-log.c (dump_log): Remove debugging messages * archive.c (archive_foreach_child_location): Build a list first and then traverse it to avoid screwing up the tree traversal * mouse-properties-capplet.c (apply_settings): Use a CORBA exception structure
2001-08-22 13:56:23 +00:00
2001-12-16 08:23:09 +00:00
return FALSE;
}
/* Callback issued when the user clicks the double click testing area. */
static gboolean
event_box_button_press_event (GtkWidget *widget,
GdkEventButton *event,
GtkBuilder *dialog)
{
gint double_click_time;
static struct test_data_t data;
static gint test_on_timeout_id = 0;
static gint test_maybe_timeout_id = 0;
static guint32 double_click_timestamp = 0;
GtkWidget *image;
2001-12-16 08:23:09 +00:00
if (event->type != GDK_BUTTON_PRESS)
return FALSE;
image = g_object_get_data (G_OBJECT (widget), "image");
double_click_time = g_settings_get_int (mouse_settings, "double-click");
2001-12-16 08:23:09 +00:00
if (test_maybe_timeout_id != 0)
g_source_remove (test_maybe_timeout_id);
2001-12-16 08:23:09 +00:00
if (test_on_timeout_id != 0)
g_source_remove (test_on_timeout_id);
2001-12-16 08:23:09 +00:00
switch (double_click_state) {
case DOUBLE_CLICK_TEST_OFF:
double_click_state = DOUBLE_CLICK_TEST_MAYBE;
data.image = image;
data.timeout_id = &test_maybe_timeout_id;
test_maybe_timeout_id = g_timeout_add (double_click_time, (GSourceFunc) test_maybe_timeout, &data);
2001-12-16 08:23:09 +00:00
break;
case DOUBLE_CLICK_TEST_MAYBE:
if (event->time - double_click_timestamp < double_click_time) {
double_click_state = DOUBLE_CLICK_TEST_ON;
data.image = image;
data.timeout_id = &test_on_timeout_id;
test_on_timeout_id = g_timeout_add (2500, (GSourceFunc) test_maybe_timeout, &data);
2001-12-16 08:23:09 +00:00
}
break;
case DOUBLE_CLICK_TEST_ON:
double_click_state = DOUBLE_CLICK_TEST_OFF;
break;
}
2001-12-16 08:23:09 +00:00
double_click_timestamp = event->time;
switch (double_click_state) {
case DOUBLE_CLICK_TEST_ON:
gtk_image_set_from_icon_name (GTK_IMAGE (image), "face-laugh", GTK_ICON_SIZE_DIALOG);
2001-12-16 08:23:09 +00:00
break;
case DOUBLE_CLICK_TEST_MAYBE:
gtk_image_set_from_icon_name (GTK_IMAGE (image), "face-smile", GTK_ICON_SIZE_DIALOG);
2001-12-16 08:23:09 +00:00
break;
case DOUBLE_CLICK_TEST_OFF:
gtk_image_set_from_icon_name (GTK_IMAGE (image), "face-plain", GTK_ICON_SIZE_DIALOG);
2001-12-16 08:23:09 +00:00
break;
}
2001-12-16 08:23:09 +00:00
return TRUE;
}
static void
orientation_radio_button_release_event (GtkWidget *widget,
GdkEventButton *event)
{
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
}
static void
scrollmethod_changed_event (GtkToggleButton *button, GtkBuilder *dialog)
{
GsdTouchpadScrollMethod method;
GtkToggleButton *disabled = GTK_TOGGLE_BUTTON (WID ("scroll_disabled_radio"));
gtk_widget_set_sensitive (WID ("horiz_scroll_toggle"),
!gtk_toggle_button_get_active (disabled));
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (WID ("scroll_edge_radio"))))
method = GSD_TOUCHPAD_SCROLL_METHOD_EDGE_SCROLLING;
else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (WID ("scroll_twofinger_radio"))))
method = GSD_TOUCHPAD_SCROLL_METHOD_TWO_FINGER_SCROLLING;
else
method = GSD_TOUCHPAD_SCROLL_METHOD_DISABLED;
g_settings_set_enum (touchpad_settings, "scroll-method", method);
}
static void
synaptics_check_capabilities (GtkBuilder *dialog)
{
int numdevices, i;
XDeviceInfo *devicelist;
Atom realtype, prop;
int realformat;
unsigned long nitems, bytes_after;
unsigned char *data;
prop = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), "Synaptics Capabilities", True);
if (!prop)
return;
devicelist = XListInputDevices (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), &numdevices);
for (i = 0; i < numdevices; i++) {
if (devicelist[i].use != IsXExtensionPointer)
continue;
gdk_error_trap_push ();
XDevice *device = XOpenDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),
devicelist[i].id);
if (gdk_error_trap_pop ())
continue;
gdk_error_trap_push ();
if ((XGetDeviceProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), device, prop, 0, 2, False,
XA_INTEGER, &realtype, &realformat, &nitems,
&bytes_after, &data) == Success) && (realtype != None)) {
/* Property data is booleans for has_left, has_middle, has_right, has_double, has_triple.
* Newer drivers (X.org/kerrnel) will also include has_pressure and has_width. */
if (!data[0]) {
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (WID ("tap_to_click_toggle")), TRUE);
gtk_widget_set_sensitive (WID ("tap_to_click_toggle"), FALSE);
}
/* Disable two finger scrolling unless the hardware supports
* double touch or can emulate it based on finger width. */
if (!(data[3] ||(nitems >= 6 && data[5])))
gtk_widget_set_sensitive (WID ("scroll_twofinger_radio"), FALSE);
XFree (data);
}
2010-10-06 12:52:45 +02:00
gdk_error_trap_pop_ignored ();
XCloseDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), device);
}
XFreeDeviceList (devicelist);
}
/* Set up the property editors in the dialog. */
2001-12-16 08:23:09 +00:00
static void
setup_dialog (GtkBuilder *dialog)
2001-12-16 08:23:09 +00:00
{
GtkRadioButton *radio;
/* Orientation radio buttons */
radio = GTK_RADIO_BUTTON (WID ("left_handed_radio"));
g_settings_bind (mouse_settings, "left-handed", radio, "active", G_SETTINGS_BIND_DEFAULT);
/* explicitly connect to button-release so that you can change orientation with either button */
g_signal_connect (WID ("right_handed_radio"), "button_release_event",
G_CALLBACK (orientation_radio_button_release_event), NULL);
g_signal_connect (WID ("left_handed_radio"), "button_release_event",
G_CALLBACK (orientation_radio_button_release_event), NULL);
Cleanup of gconf and a few other things, patch from Kjartan Maraas 2005-05-22 Sebastien Bacher <seb128@debian.org> * ChangeLog capplets/about-me/e-image-chooser.c capplets/accessibility/at-properties/at-startup-session.h capplets/accessibility/keyboard/accessibility-keyboard.c capplets/background/gnome-wp-info.c capplets/common/gconf-property-editor.c capplets/common/gnome-theme-apply.c capplets/default-applications/gnome-default-applications-properties.c capplets/keybindings/gnome-keybinding-properties.c capplets/keyboard/gnome-keyboard-properties.c capplets/mouse/gnome-mouse-properties.c capplets/network/gnome-network-preferences.c capplets/sound/sound-properties-capplet.c capplets/theme-switcher/gnome-theme-details.c capplets/theme-switcher/gnome-theme-manager.c capplets/ui-properties/gnome-ui-properties.c capplets/windows/gnome-window-properties.c gnome-settings-daemon/factory.c gnome-settings-daemon/gnome-settings-accessibility-keyboard.c gnome-settings-daemon/gnome-settings-background.c gnome-settings-daemon/gnome-settings-daemon.c gnome-settings-daemon/gnome-settings-daemon.h gnome-settings-daemon/gnome-settings-font.c gnome-settings-daemon/gnome-settings-keybindings.c gnome-settings-daemon/gnome-settings-keybindings.h gnome-settings-daemon/gnome-settings-keyboard-xkb.c gnome-settings-daemon/gnome-settings-keyboard.c gnome-settings-daemon/gnome-settings-locate-pointer.h gnome-settings-daemon/gnome-settings-mouse.c gnome-settings-daemon/gnome-settings-multimedia-keys.c gnome-settings-daemon/gnome-settings-screensaver.c gnome-settings-daemon/gnome-settings-sound.c gnome-settings-daemon/gnome-settings-xmodmap.c gnome-settings-daemon/gnome-settings-xrdb.c gnome-settings-daemon/gnome-settings-xsettings.c libbackground/applier.c libbackground/applier.h libbackground/preferences.c libsounds/sound-properties.c libsounds/sound-view.h libwindow-settings/gnome-wm-manager.c libwindow-settings/metacity-window-manager.c typing-break/drw-break-window.c typing-break/drw-utils.h typing-break/drwright.c vfs-methods/fontilus/font-view.c vfs-methods/themus/themus-theme-applier.c: Cleanup of gconf and a few other things, patch from Kjartan Maraas <kmaraas@gnome.org> (Closes: #301945).
2005-05-22 15:46:45 +00:00
/* Locate pointer toggle */
g_settings_bind (mouse_settings, "locate-pointer",
WID ("locate_pointer_toggle"), "active",
G_SETTINGS_BIND_DEFAULT);
2001-12-16 08:23:09 +00:00
/* Double-click time */
g_settings_bind (mouse_settings, "double-click",
gtk_range_get_adjustment (GTK_RANGE (WID ("delay_scale"))), "value",
G_SETTINGS_BIND_DEFAULT);
gtk_image_set_from_icon_name (GTK_IMAGE (WID ("double_click_image")), "face-plain", GTK_ICON_SIZE_DIALOG);
g_object_set_data (G_OBJECT (WID ("double_click_eventbox")), "image", WID ("double_click_image"));
g_signal_connect (WID ("double_click_eventbox"), "button_press_event",
G_CALLBACK (event_box_button_press_event), dialog);
/* speed */
g_settings_bind (mouse_settings, "motion-acceleration",
gtk_range_get_adjustment (GTK_RANGE (WID ("accel_scale"))), "value",
G_SETTINGS_BIND_DEFAULT);
g_settings_bind (mouse_settings, "motion-threshold",
gtk_range_get_adjustment (GTK_RANGE (WID ("sensitivity_scale"))), "value",
G_SETTINGS_BIND_DEFAULT);
/* DnD threshold */
g_settings_bind (mouse_settings, "drag-threshold",
gtk_range_get_adjustment (GTK_RANGE (WID ("drag_threshold_scale"))), "value",
G_SETTINGS_BIND_DEFAULT);
/* Trackpad page */
if (touchpad_is_present () == FALSE)
gtk_notebook_remove_page (GTK_NOTEBOOK (WID ("prefs_widget")), -1);
else {
g_settings_bind (touchpad_settings, "disable-while-typing",
WID ("disable_w_typing_toggle"), "active",
G_SETTINGS_BIND_DEFAULT);
g_settings_bind (touchpad_settings, "tap-to-click",
WID ("tap_to_click_toggle"), "active",
G_SETTINGS_BIND_DEFAULT);
g_settings_bind (touchpad_settings, "horiz-scroll-enabled",
WID ("horiz_scroll_toggle"), "active",
G_SETTINGS_BIND_DEFAULT);
g_settings_bind (touchpad_settings, "motion-acceleration",
gtk_range_get_adjustment (GTK_RANGE (WID ("touchpad_accel_scale"))), "value",
G_SETTINGS_BIND_DEFAULT);
g_settings_bind (touchpad_settings, "motion-threshold",
gtk_range_get_adjustment (GTK_RANGE (WID ("touchpad_sensitivity_scale"))), "value",
G_SETTINGS_BIND_DEFAULT);
g_signal_connect (WID ("scroll_disabled_radio"), "toggled",
G_CALLBACK (scrollmethod_changed_event), dialog);
g_signal_connect (WID ("scroll_edge_radio"), "toggled",
G_CALLBACK (scrollmethod_changed_event), dialog);
g_signal_connect (WID ("scroll_twofinger_radio"), "toggled",
G_CALLBACK (scrollmethod_changed_event), dialog);
synaptics_check_capabilities (dialog);
scrollmethod_changed_event (GTK_TOGGLE_BUTTON (WID ("scroll_disabled_radio")), dialog);
}
}
/* Construct the dialog */
static void
create_dialog (GtkBuilder *dialog)
{
GtkSizeGroup *size_group;
2001-12-16 08:23:09 +00:00
size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
gtk_size_group_add_widget (size_group, WID ("acceleration_label"));
gtk_size_group_add_widget (size_group, WID ("sensitivity_label"));
gtk_size_group_add_widget (size_group, WID ("threshold_label"));
gtk_size_group_add_widget (size_group, WID ("timeout_label"));
2001-12-16 08:23:09 +00:00
size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
gtk_size_group_add_widget (size_group, WID ("acceleration_fast_label"));
gtk_size_group_add_widget (size_group, WID ("sensitivity_high_label"));
gtk_size_group_add_widget (size_group, WID ("threshold_large_label"));
gtk_size_group_add_widget (size_group, WID ("timeout_long_label"));
2001-12-16 08:23:09 +00:00
size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
gtk_size_group_add_widget (size_group, WID ("acceleration_slow_label"));
gtk_size_group_add_widget (size_group, WID ("sensitivity_low_label"));
gtk_size_group_add_widget (size_group, WID ("threshold_small_label"));
gtk_size_group_add_widget (size_group, WID ("timeout_short_label"));
}
/* Callback issued when a button is clicked on the dialog */
static void
dialog_response_cb (GtkDialog *dialog, gint response_id, gpointer user_data)
{
/*
if (response_id == GTK_RESPONSE_HELP)
capplet_help (GTK_WINDOW (dialog),
"goscustperiph-5");
else
gtk_main_quit ();
*/
}
GtkWidget *
gnome_mouse_properties_init (GtkBuilder *dialog)
{
GtkWidget *dialog_win, *w;
gchar *start_page = NULL;
mouse_settings = g_settings_new ("org.gnome.settings-daemon.peripherals.mouse");
touchpad_settings = g_settings_new ("org.gnome.settings-daemon.peripherals.touchpad");
create_dialog (dialog);
if (dialog) {
setup_dialog (dialog);
dialog_win = WID ("mouse_properties_dialog");
g_signal_connect (dialog_win, "response",
G_CALLBACK (dialog_response_cb), NULL);
if (start_page != NULL) {
gchar *page_name;
page_name = g_strconcat (start_page, "_vbox", NULL);
g_free (start_page);
w = WID (page_name);
if (w != NULL) {
GtkNotebook *nb;
gint pindex;
nb = GTK_NOTEBOOK (WID ("prefs_widget"));
pindex = gtk_notebook_page_num (nb, w);
if (pindex != -1)
gtk_notebook_set_current_page (nb, pindex);
}
g_free (page_name);
}
} else {
dialog_win = NULL;
}
return dialog_win;
}