diff --git a/capplets/Makefile.am b/capplets/Makefile.am index 956064b0d..d0c804087 100644 --- a/capplets/Makefile.am +++ b/capplets/Makefile.am @@ -1,4 +1,4 @@ -always_built_SUBDIRS = desktop-links mouse-properties \ +always_built_SUBDIRS = desktop-links new-mouse-properties \ new-screensaver-properties new-background-properties \ theme-switcher sound-properties new-bell-properties \ ui-properties url-properties gnome-edit-properties \ diff --git a/capplets/background/main.c b/capplets/background/main.c index 3b78f9c5c..71b07a300 100644 --- a/capplets/background/main.c +++ b/capplets/background/main.c @@ -68,9 +68,7 @@ setup_capplet_widget (void) gtk_signal_connect (GTK_OBJECT (prefs_widget), "cancel", GTK_SIGNAL_FUNC (cancel_cb), NULL); - /* FIXME */ - gtk_widget_show_all (GTK_WIDGET - (CAPPLET_WIDGET (prefs_widget)->dialog)); + gtk_widget_show_all (GTK_WIDGET (prefs_widget)); preferences_thaw (prefs); } diff --git a/capplets/keyboard/ChangeLog b/capplets/keyboard/ChangeLog index e69de29bb..db2cb4914 100644 --- a/capplets/keyboard/ChangeLog +++ b/capplets/keyboard/ChangeLog @@ -0,0 +1,5 @@ +2000-09-12 Bradford Hovinen + + * preferences.c (preferences_clone): Added in missing code to copy + preferences over + diff --git a/capplets/keyboard/preferences.c b/capplets/keyboard/preferences.c index 637c5f9ec..50eb8a444 100644 --- a/capplets/keyboard/preferences.c +++ b/capplets/keyboard/preferences.c @@ -3,7 +3,10 @@ /* preferences.c * Copyright (C) 2000 Helix Code, Inc. * - * Written by Bradford Hovinen + * Written by Bradford Hovinen , + * Jaka Mocnik + * + * Based on gnome-core/desktop-properties/property-keyboard.c * * 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 @@ -120,8 +123,11 @@ preferences_clone (Preferences *prefs) object = preferences_new (); new_prefs = PREFERENCES (object); - - /* Code to copy data from old preferences object to new one */ + new_prefs->rate = prefs->rate; + new_prefs->delay = prefs->delay; + new_prefs->repeat = prefs->repeat; + new_prefs->click_volume = prefs->click_volume; + new_prefs->click_on_keypress = prefs->click_on_keypress; return object; } diff --git a/capplets/mouse/Makefile.am b/capplets/mouse/Makefile.am new file mode 100644 index 000000000..612bf56c7 --- /dev/null +++ b/capplets/mouse/Makefile.am @@ -0,0 +1,37 @@ +Applicationsdir = $(datadir)/control-center/Desktop +Applications_DATA = \ + mouse-properties.desktop + +Gladedir = $(datadir)/control-center-data +Glade_DATA = \ + mouse-properties.glade + +EXTRA_DIST = ChangeLog $(Applications_DATA) $(Glade_DATA) + +INCLUDES = \ + -DGNOMELOCALEDIR=\""$(datadir)/locale"\" \ + -DGNOME_ICONDIR=\""${prefix}/share/pixmaps"\" \ + -DG_LOG_DOMAIN=\"mouse-properties\" \ + -DGLADE_DATADIR=\""$(Gladedir)"\" \ + $(GNOME_INCLUDEDIR) \ + $(XML_CFLAGS) \ + $(LIBGLADE_CFLAGS) \ + -I$(top_srcdir)/ \ + -I$(top_srcdir)/intl \ + -I$(top_srcdir)/libcapplet + +bin_PROGRAMS = mouse-properties-capplet + +mouse_properties_capplet_SOURCES = \ + prefs-widget.c prefs-widget.h \ + preferences.c preferences.h \ + main.c + +mouse_properties_capplet_LDADD = \ + $(GNOME_LIBDIR) \ + $(GNOMEUI_LIBS) \ + $(ORBIT_LIBS) \ + $(GNOME_XML_LIB) \ + $(LIBGLADE_LIBS) \ + -lgdk_pixbuf \ + ../../libcapplet/libcapplet.la diff --git a/capplets/mouse/main.c b/capplets/mouse/main.c new file mode 100644 index 000000000..025762475 --- /dev/null +++ b/capplets/mouse/main.c @@ -0,0 +1,185 @@ +/* -*- mode: c; style: linux -*- */ + +/* main.c + * Copyright (C) 2000 Helix Code, Inc. + * + * Written by Bradford Hovinen (hovinen@helixcode.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. + */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include +#include +#include +#include + +#include + +#include + +#include "preferences.h" +#include "prefs-widget.h" + +static Preferences *prefs; +static Preferences *old_prefs; +static PrefsWidget *prefs_widget; + +static void +ok_cb (GtkWidget *widget) +{ + preferences_save (prefs); + preferences_apply_now (prefs); +} + +static void +cancel_cb (GtkWidget *widget) +{ + preferences_save (old_prefs); + preferences_apply_now (old_prefs); +} + +static void +setup_capplet_widget (void) +{ + preferences_freeze (prefs); + + prefs_widget = PREFS_WIDGET (prefs_widget_new (prefs)); + + gtk_signal_connect (GTK_OBJECT (prefs_widget), "ok", + GTK_SIGNAL_FUNC (ok_cb), NULL); + gtk_signal_connect (GTK_OBJECT (prefs_widget), "cancel", + GTK_SIGNAL_FUNC (cancel_cb), NULL); + + gtk_widget_show_all (GTK_WIDGET (prefs_widget)); + + preferences_thaw (prefs); +} + +static void +do_get_xml (void) +{ + Preferences *prefs; + xmlDocPtr doc; + + prefs = PREFERENCES (preferences_new ()); + preferences_load (prefs); + doc = preferences_write_xml (prefs); + xmlDocDump (stdout, doc); + gtk_object_destroy (GTK_OBJECT (prefs)); +} + +static void +do_set_xml (void) +{ + Preferences *prefs; + xmlDocPtr doc; + char *buffer; + int len = 0; + + while (!feof (stdin)) { + if (!len) buffer = g_new (char, 16384); + else buffer = g_renew (char, buffer, len + 16384); + fread (buffer + len, 1, 16384, stdin); + len += 16384; + } + + doc = xmlParseMemory (buffer, strlen (buffer)); + + prefs = preferences_read_xml (doc); + + if (prefs) + preferences_save (prefs); + else + g_warning ("Error while reading the screensaver config file"); +} + +int +main (int argc, char **argv) +{ + GnomeClient *client; + GnomeClientFlags flags; + gint token, res; + gchar *restart_args[3]; + + bindtextdomain (PACKAGE, GNOMELOCALEDIR); + textdomain (PACKAGE); + + glade_gnome_init (); + res = gnome_capplet_init ("mouse-properties", + VERSION, argc, argv, NULL, + 0, NULL); + + if (res < 0) { + g_error ("Could not initialize the capplet."); + } + else if (res == 3) { + do_get_xml (); + return 0; + } + else if (res == 4) { + do_set_xml (); + return 0; + } + + client = gnome_master_client (); + flags = gnome_client_get_flags (client); + + if (flags & GNOME_CLIENT_IS_CONNECTED) { + token = gnome_startup_acquire_token + ("GNOME_MOUSE_PROPERTIES", + gnome_client_get_id (client)); + + if (token) { + gnome_client_set_priority (client, 20); + gnome_client_set_restart_style (client, + GNOME_RESTART_ANYWAY); + restart_args[0] = argv[0]; + restart_args[1] = "--init-session-settings"; + restart_args[2] = NULL; + gnome_client_set_restart_command (client, 2, + restart_args); + } else { + gnome_client_set_restart_style (client, + GNOME_RESTART_NEVER); + } + } else { + token = 1; + } + + gnome_window_icon_set_default_from_file + (GNOME_ICONDIR"/gnome-mouse.png"); + + prefs = PREFERENCES (preferences_new ()); + preferences_load (prefs); + + if (token) { + preferences_apply_now (prefs); + } + + if (!res) { + old_prefs = PREFERENCES (preferences_clone (prefs)); + setup_capplet_widget (); + + capplet_gtk_main (); + } + + return 0; +} diff --git a/capplets/mouse/mouse-properties.desktop b/capplets/mouse/mouse-properties.desktop new file mode 100644 index 000000000..65d92876d --- /dev/null +++ b/capplets/mouse/mouse-properties.desktop @@ -0,0 +1,59 @@ +[Desktop Entry] +Name=Mouse +Name[ca]=Propietats del ratolí +Name[cs]=My¹ +Name[da]=Mus +Name[de]=Maus +Name[el]=Ñõèìßóåéò ðïíôéêéïý +Name[es]=Propiedades del ratón +Name[et]=Hiir +Name[fi]=Hiiri +Name[fr]=Souris +Name[gl]=Rato +Name[hu]=Egér +Name[it]=Mouse +Name[ja]=¥Þ¥¦¥¹ +Name[ko]=¸¶¿ì½º ¼³Á¤ +Name[lt]=Pelë +Name[no]=Mus +Name[pl]=Mysz +Name[pt]=Propriedades do Rato +Name[pt_BR]=Propriedades do Mouse +Name[ru]=íÙÛØ +Name[sl]=Mi¹ka +Name[sv]=Mus +Name[uk]=íÉÛÁ +Name[wa]=Sori +Name[zh_TW.Big5]=·Æ¹« +Name[zh_CN.GB2312]=»¬Êó +Comment=Mouse Properties +Comment[ca]=Configurar el ratolí +Comment[cs]=Nastavení my¹i +Comment[da]=Museegenskaber +Comment[de]=Einstellungen für die Maus +Comment[el]=Ôñïðïðïßçóç ôùí ñõèìßóåùí ôïõ ðïíôéêéïý +Comment[es]=Modifica las propiedades del ratón +Comment[et]=Hiire häälestus +Comment[fi]=Hiiren asetukset +Comment[fr]=Configuration des propriétés de la souris +Comment[gl]=Propiedades do rato. +Comment[hu]=Az egér beállítása +Comment[it]=Impostazioni del mouse +Comment[ja]=¥Þ¥¦¥¹¤ÎÀßÄê +Comment[ko]=¸¶¿ì½º ¼³Á¤ +Comment[lt]=Pelës savybës +Comment[no]=Egenskaper for mus +Comment[pl]=Ustawienia myszy +Comment[pt]=Modifica as propriedades do rato +Comment[pt_BR]=Modifica as propriedades do Mouse +Comment[ru]=ó×ÏÊÓÔ×Á ÍÙÛÉ +Comment[sl]=Lastnosti mi¹ke +Comment[sv]=Egenskaper för mus +Comment[uk]=÷ÌÁÓÔÉ×ÏÓÔ¦ ÍÉÛ¦ +Comment[wa]=Candjî les prôpietés del sori +Comment[zh_TW.Big5]=·Æ¹«³]©w +Comment[zh_CN.GB2312]=»¬ÊóÉ趨 +Exec=mouse-properties-capplet +Icon=gnome-mouse.png +Terminal=0 +Type=Application diff --git a/capplets/mouse/mouse-properties.glade b/capplets/mouse/mouse-properties.glade new file mode 100644 index 000000000..538687e99 --- /dev/null +++ b/capplets/mouse/mouse-properties.glade @@ -0,0 +1,400 @@ + + + + + New-mouse-properties + new-mouse-properties + + src + pixmaps + C + True + True + + + + GtkWindow + window1 + window1 + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + False + False + True + False + + + GtkTable + prefs_widget + 5 + 2 + 2 + False + 5 + 5 + + + GtkPixmap + mouse_pixmap + 0 + 0.5 + 0 + 0 + True + + 0 + 2 + 0 + 1 + 0 + 0 + True + True + False + False + True + True + + + + + GtkFrame + frame1 + + 0 + GTK_SHADOW_ETCHED_IN + + 0 + 1 + 1 + 2 + 0 + 0 + False + True + False + False + True + True + + + + GtkVBox + vbox1 + 5 + False + 5 + + + GtkRadioButton + left_handed_select + True + + toggled + left_handed_selected_cb + Tue, 12 Sep 2000 15:07:52 GMT + + + False + True + rtol_group + + 0 + False + False + + + + + GtkRadioButton + right_handed_select + True + + toggled + right_handed_selected_cb + Tue, 12 Sep 2000 15:08:05 GMT + + + False + True + rtol_group + + 0 + False + False + + + + + + + GtkFrame + frame2 + + 0 + GTK_SHADOW_ETCHED_IN + + 1 + 2 + 1 + 2 + 0 + 0 + False + False + False + False + True + True + + + + GtkTable + table2 + 5 + 5 + 3 + False + 5 + 5 + + + GtkHSeparator + hseparator1 + + 0 + 3 + 2 + 3 + 0 + 0 + True + True + False + False + True + True + + + + + GtkLabel + label1 + + GTK_JUSTIFY_CENTER + False + 0 + 0.5 + 0 + 0 + + 0 + 3 + 0 + 1 + 0 + 0 + False + False + False + False + True + False + + + + + GtkLabel + label2 + + GTK_JUSTIFY_CENTER + False + 0 + 0.5 + 0 + 0 + + 0 + 3 + 3 + 4 + 0 + 0 + False + False + False + False + True + False + + + + + GtkHScale + acceleration_entry + True + False + GTK_POS_TOP + 1 + GTK_UPDATE_CONTINUOUS + 0 + 0 + 7 + 0 + 0 + 0 + + 1 + 2 + 1 + 2 + 0 + 0 + False + True + False + False + True + True + + + + + GtkHScale + threshold_entry + True + False + GTK_POS_TOP + 1 + GTK_UPDATE_CONTINUOUS + 0 + 0 + 7 + 0 + 0 + 0 + + 1 + 2 + 4 + 5 + 0 + 0 + False + True + False + False + True + True + + + + + GtkLabel + label3 + + GTK_JUSTIFY_CENTER + False + 1 + 0.5 + 0 + 0 + + 0 + 1 + 1 + 2 + 0 + 0 + False + False + False + False + True + False + + + + + GtkLabel + label5 + + GTK_JUSTIFY_CENTER + False + 0 + 0.5 + 0 + 0 + + 2 + 3 + 1 + 2 + 0 + 0 + False + False + False + False + True + False + + + + + GtkLabel + label6 + + GTK_JUSTIFY_CENTER + False + 0 + 0.5 + 0 + 0 + + 2 + 3 + 4 + 5 + 0 + 0 + False + False + False + False + True + False + + + + + GtkLabel + label4 + + GTK_JUSTIFY_CENTER + False + 1 + 0.5 + 0 + 0 + + 0 + 1 + 4 + 5 + 0 + 0 + False + False + False + False + True + False + + + + + + + + diff --git a/capplets/mouse/preferences.c b/capplets/mouse/preferences.c new file mode 100644 index 000000000..f74ee92f6 --- /dev/null +++ b/capplets/mouse/preferences.c @@ -0,0 +1,387 @@ +/* -*- mode: c; style: linux -*- */ + +/* preferences.c + * Copyright (C) 2000 Helix Code, Inc. + * Copyright (C) 1998, 1999 Red Hat, Inc., Tom Tromey + * + * Written by Bradford Hovinen , + * Jonathan Blandford , + * Tom Tromey + * + * 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. + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include + +#include +#include +#include + +#include "preferences.h" + +/* Maximum number of mouse buttons we handle. */ +#define MAX_BUTTONS 10 + +/* Half the number of acceleration levels we support. */ +#define MAX_ACCEL 3 + +/* Maximum threshold we support. */ +#define MAX_THRESH 7 + +static GtkObjectClass *parent_class; + +static void preferences_init (Preferences *prefs); +static void preferences_class_init (PreferencesClass *class); + +static gint xml_read_int (xmlNodePtr node, + gchar *propname); +static xmlNodePtr xml_write_int (gchar *name, + gchar *propname, + gint number); + +static gint apply_timeout_cb (Preferences *prefs); + +guint +preferences_get_type (void) +{ + static guint preferences_type = 0; + + if (!preferences_type) { + GtkTypeInfo preferences_info = { + "Preferences", + sizeof (Preferences), + sizeof (PreferencesClass), + (GtkClassInitFunc) preferences_class_init, + (GtkObjectInitFunc) preferences_init, + (GtkArgSetFunc) NULL, + (GtkArgGetFunc) NULL + }; + + preferences_type = + gtk_type_unique (gtk_object_get_type (), + &preferences_info); + } + + return preferences_type; +} + +static void +preferences_init (Preferences *prefs) +{ + prefs->frozen = FALSE; + + /* Code to initialize preferences object to defaults */ +} + +static void +preferences_class_init (PreferencesClass *class) +{ + GtkObjectClass *object_class; + + object_class = (GtkObjectClass *) class; + object_class->destroy = preferences_destroy; + + parent_class = + GTK_OBJECT_CLASS (gtk_type_class (gtk_object_get_type ())); +} + +GtkObject * +preferences_new (void) +{ + GtkObject *object; + + object = gtk_type_new (preferences_get_type ()); + + return object; +} + +GtkObject * +preferences_clone (Preferences *prefs) +{ + GtkObject *object; + Preferences *new_prefs; + + g_return_val_if_fail (prefs != NULL, NULL); + g_return_val_if_fail (IS_PREFERENCES (prefs), NULL); + + object = preferences_new (); + + new_prefs = PREFERENCES (object); + new_prefs->rtol = prefs->rtol; + new_prefs->acceleration = prefs->acceleration; + new_prefs->threshold = prefs->threshold; + new_prefs->nbuttons = prefs->nbuttons; + + return object; +} + +void +preferences_destroy (GtkObject *object) +{ + Preferences *prefs; + + g_return_if_fail (object != NULL); + g_return_if_fail (IS_PREFERENCES (object)); + + prefs = PREFERENCES (object); + + parent_class->destroy (object); +} + +void +preferences_load (Preferences *prefs) +{ + unsigned char buttons[MAX_BUTTONS]; + int acc_num, acc_den, thresh; + gboolean rtol_default; + + g_return_if_fail (prefs != NULL); + g_return_if_fail (IS_PREFERENCES (prefs)); + + prefs->nbuttons = XGetPointerMapping (GDK_DISPLAY (), buttons, + MAX_BUTTONS); + g_assert (prefs->nbuttons <= MAX_BUTTONS); + + /* Note that we only handle right-to-left and left-to-right. + Most weird mappings are treated as l-to-r. + We could handle this by showing the mouse buttons and letting the + user drag-and-drop them to reorder. But I'm not convinced this + is worth it. */ + /* FIXME: this ignores the fact that a mouse with the weird little + roller generates B4 and B5 when the roller is moved. That + shouldn't change when we remap the other mouse buttons. */ + prefs->rtol = gnome_config_get_bool_with_default + ("/Desktop/Mouse/right-to-left=false", &rtol_default); + if (rtol_default) + prefs->rtol = (buttons[prefs->nbuttons - 1] == 1); + + prefs->threshold = gnome_config_get_int ("/Desktop/Mouse/threshold=-1"); + prefs->acceleration = gnome_config_get_int + ("/Desktop/Mouse/acceleration=-1"); + + if (prefs->threshold == -1 || prefs->acceleration == -1) { + XGetPointerControl (GDK_DISPLAY (), &acc_num, + &acc_den, &thresh); + + if (prefs->threshold == -1) + prefs->threshold = thresh; + if (prefs->acceleration == -1) { + /* Only support cases in our range. If neither the + * numerator nor denominator is 1, then rescale. */ + if (acc_num != 1 && acc_den != 1) { + if (acc_num > acc_den) { + acc_num = (int) + ((double) acc_num / acc_den); + acc_den = 1; + } else { + acc_den = (int) + ((double) acc_den / acc_num); + acc_num = 1; + } + } + + if (acc_num > MAX_ACCEL) + acc_num = MAX_ACCEL; + if (acc_den > MAX_ACCEL) + acc_den = MAX_ACCEL; + if (acc_den == 1) + prefs->acceleration = acc_num + MAX_ACCEL - 1; + else + prefs->acceleration = MAX_ACCEL - acc_den; + } + } +} + +void +preferences_save (Preferences *prefs) +{ + g_return_if_fail (prefs != NULL); + g_return_if_fail (IS_PREFERENCES (prefs)); + + gnome_config_set_int ("/Desktop/Mouse/acceleration", + prefs->acceleration); + gnome_config_set_int ("/Desktop/Mouse/threshold", prefs->threshold); + gnome_config_set_bool ("/Desktop/Mouse/right-to-left", prefs->rtol); + + gnome_config_sync (); +} + +void +preferences_changed (Preferences *prefs) +{ + if (prefs->frozen) return; + + if (prefs->timeout_id) + gtk_timeout_remove (prefs->timeout_id); + + /* Live update in this case could be very problematic, so we're going + * to disable it */ + +/* preferences_apply_now (prefs); */ +} + +void +preferences_apply_now (Preferences *prefs) +{ + unsigned char buttons[MAX_BUTTONS], i; + int num, den, max; + + g_return_if_fail (prefs != NULL); + g_return_if_fail (IS_PREFERENCES (prefs)); + + if (prefs->timeout_id) + gtk_timeout_remove (prefs->timeout_id); + + prefs->timeout_id = 0; + + g_assert (prefs->nbuttons <= MAX_BUTTONS); + + /* Ignore buttons above 3 -- these are assumed to be a wheel. If we + * have a non-wheeled mouse, this may do weird things */ + + max = MIN (prefs->nbuttons, 3); + for (i = 0; i < max; ++i) + buttons[i] = prefs->rtol ? (max - i) : (i + 1); + for (; i < prefs->nbuttons; ++i) + buttons[i] = i + 1; + + XSetPointerMapping (GDK_DISPLAY (), buttons, prefs->nbuttons); + + if (prefs->acceleration < MAX_ACCEL) { + num = 1; + den = MAX_ACCEL - prefs->acceleration; + } else { + num = prefs->acceleration - MAX_ACCEL + 1; + den = 1; + } + + XChangePointerControl (GDK_DISPLAY (), True, True, + num, den, prefs->threshold); +} + +void preferences_freeze (Preferences *prefs) +{ + prefs->frozen = TRUE; +} + +void preferences_thaw (Preferences *prefs) +{ + prefs->frozen = FALSE; +} + +Preferences * +preferences_read_xml (xmlDocPtr xml_doc) +{ + Preferences *prefs; + xmlNodePtr root_node, node; + + prefs = PREFERENCES (preferences_new ()); + + root_node = xmlDocGetRootElement (xml_doc); + + if (strcmp (root_node->name, "mouse-properties")) + return NULL; + + for (node = root_node->childs; node; node = node->next) { + if (!strcmp (node->name, "acceleration")) + prefs->acceleration = atoi (xmlNodeGetContent (node)); + else if (!strcmp (node->name, "threshold")) + prefs->threshold = atoi (xmlNodeGetContent (node)); + else if (!strcmp (node->name, "right-to-left")) + prefs->rtol = TRUE; + } + + return prefs; +} + +xmlDocPtr +preferences_write_xml (Preferences *prefs) +{ + xmlDocPtr doc; + xmlNodePtr node; + char *tmp; + + doc = xmlNewDoc ("1.0"); + + node = xmlNewDocNode (doc, NULL, "mouse-properties", NULL); + + xmlAddChild (node, xml_write_int ("acceleration", NULL, + prefs->acceleration)); + + xmlAddChild (node, xml_write_int ("threshold", NULL, + prefs->threshold)); + + if (prefs->rtol) + xmlNewChild (node, NULL, "right-to-left", NULL); + + xmlDocSetRootElement (doc, node); + + return doc; +} + +/* Read a numeric value from a node */ + +static gint +xml_read_int (xmlNodePtr node, char *propname) +{ + char *text; + + if (propname == NULL) + text = xmlNodeGetContent (node); + else + text = xmlGetProp (node, propname); + + if (text == NULL) + return 0; + else + return atoi (text); +} + +/* Write out a numeric value in a node */ + +static xmlNodePtr +xml_write_int (gchar *name, gchar *propname, gint number) +{ + xmlNodePtr node; + gchar *str; + + g_return_val_if_fail (name != NULL, NULL); + + str = g_strdup_printf ("%d", number); + + node = xmlNewNode (NULL, name); + + if (propname == NULL) + xmlNodeSetContent (node, str); + else + xmlSetProp (node, propname, str); + + g_free (str); + + return node; +} + +static gint +apply_timeout_cb (Preferences *prefs) +{ + preferences_apply_now (prefs); + + return TRUE; +} diff --git a/capplets/mouse/preferences.h b/capplets/mouse/preferences.h new file mode 100644 index 000000000..1f95dfe96 --- /dev/null +++ b/capplets/mouse/preferences.h @@ -0,0 +1,73 @@ +/* -*- mode: c; style: linux -*- */ + +/* preferences.h + * Copyright (C) 2000 Helix Code, Inc. + * + * Written by Bradford Hovinen + * + * 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. + */ + +#ifndef __PREFERENCES_H +#define __PREFERENCES_H + +#include + +#include + +#define PREFERENCES(obj) GTK_CHECK_CAST (obj, preferences_get_type (), Preferences) +#define PREFERENCES_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, preferences_get_type (), PreferencesClass) +#define IS_PREFERENCES(obj) GTK_CHECK_TYPE (obj, preferences_get_type ()) + +typedef struct _Preferences Preferences; +typedef struct _PreferencesClass PreferencesClass; + +struct _Preferences +{ + GtkObject object; + + gboolean frozen; + guint timeout_id; + + gboolean rtol; + gint nbuttons; + gint acceleration; + gint threshold; +}; + +struct _PreferencesClass +{ + GtkObjectClass klass; +}; + +guint preferences_get_type (void); + +GtkObject *preferences_new (void); +GtkObject *preferences_clone (Preferences *prefs); +void preferences_destroy (GtkObject *object); + +void preferences_load (Preferences *prefs); +void preferences_save (Preferences *prefs); +void preferences_changed (Preferences *prefs); +void preferences_apply_now (Preferences *prefs); + +void preferences_freeze (Preferences *prefs); +void preferences_thaw (Preferences *prefs); + +Preferences *preferences_read_xml (xmlDocPtr xml_doc); +xmlDocPtr preferences_write_xml (Preferences *prefs); + +#endif /* __PREFERENCES_H */ diff --git a/capplets/mouse/prefs-widget.c b/capplets/mouse/prefs-widget.c new file mode 100644 index 000000000..e411a75b4 --- /dev/null +++ b/capplets/mouse/prefs-widget.c @@ -0,0 +1,319 @@ +/* -*- mode: c; style: linux -*- */ + +/* prefs-widget.c + * Copyright (C) 2000 Helix Code, Inc. + * + * Written by Bradford Hovinen + * + * 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. + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include + +#include "prefs-widget.h" + +#define WID(str) (glade_xml_get_widget (prefs_widget->dialog_data, str)) + +enum { + ARG_0, + ARG_PREFERENCES +}; + +static CappletWidgetClass *parent_class; + +static void prefs_widget_init (PrefsWidget *prefs_widget); +static void prefs_widget_class_init (PrefsWidgetClass *class); + +static void prefs_widget_set_arg (GtkObject *object, + GtkArg *arg, + guint arg_id); +static void prefs_widget_get_arg (GtkObject *object, + GtkArg *arg, + guint arg_id); + +static void read_preferences (PrefsWidget *prefs_widget, + Preferences *prefs); + + +static void left_handed_selected_cb (GtkToggleButton *tb, + PrefsWidget *prefs_widget); +static void right_handed_selected_cb (GtkToggleButton *tb, + PrefsWidget *prefs_widget); +static void acceleration_changed_cb (GtkAdjustment *adjustment, + PrefsWidget *prefs_widget); +static void threshold_changed_cb (GtkAdjustment *adjustment, + PrefsWidget *prefs_widget); + +guint +prefs_widget_get_type (void) +{ + static guint prefs_widget_type = 0; + + if (!prefs_widget_type) { + GtkTypeInfo prefs_widget_info = { + "PrefsWidget", + sizeof (PrefsWidget), + sizeof (PrefsWidgetClass), + (GtkClassInitFunc) prefs_widget_class_init, + (GtkObjectInitFunc) prefs_widget_init, + (GtkArgSetFunc) NULL, + (GtkArgGetFunc) NULL + }; + + prefs_widget_type = + gtk_type_unique (capplet_widget_get_type (), + &prefs_widget_info); + } + + return prefs_widget_type; +} + +static void +prefs_widget_init (PrefsWidget *prefs_widget) +{ + GtkWidget *widget; + GtkAdjustment *adjustment; + GdkPixbuf *pixbuf; + GdkPixmap *pixmap; + GdkBitmap *mask; + char *filename; + + prefs_widget->dialog_data = + glade_xml_new (GLADE_DATADIR "/mouse-properties.glade", + "prefs_widget"); + + widget = glade_xml_get_widget (prefs_widget->dialog_data, + "prefs_widget"); + gtk_container_add (GTK_CONTAINER (prefs_widget), widget); + + filename = gnome_pixmap_file ("gnome-mouse.png"); + pixbuf = gdk_pixbuf_new_from_file (filename); + g_free (filename); + + if (pixbuf) { + gdk_pixbuf_render_pixmap_and_mask (pixbuf, &pixmap, &mask, + 100); + gtk_pixmap_set (GTK_PIXMAP (WID ("mouse_pixmap")), + pixmap, mask); + gdk_pixbuf_unref (pixbuf); + } + + glade_xml_signal_connect_data + (prefs_widget->dialog_data, "left_handed_selected_cb", + left_handed_selected_cb, prefs_widget); + + glade_xml_signal_connect_data + (prefs_widget->dialog_data, "right_handed_selected_cb", + right_handed_selected_cb, prefs_widget); + + adjustment = gtk_range_get_adjustment + (GTK_RANGE (WID ("acceleration_entry"))); + gtk_signal_connect (GTK_OBJECT (adjustment), "value_changed", + acceleration_changed_cb, prefs_widget); + + adjustment = gtk_range_get_adjustment + (GTK_RANGE (WID ("threshold_entry"))); + gtk_signal_connect (GTK_OBJECT (adjustment), "value_changed", + threshold_changed_cb, prefs_widget); +} + +static void +prefs_widget_class_init (PrefsWidgetClass *class) +{ + GtkObjectClass *object_class; + + gtk_object_add_arg_type ("PrefsWidget::preferences", + GTK_TYPE_POINTER, + GTK_ARG_READWRITE, + ARG_PREFERENCES); + + object_class = GTK_OBJECT_CLASS (class); + object_class->set_arg = prefs_widget_set_arg; + object_class->get_arg = prefs_widget_get_arg; + + parent_class = CAPPLET_WIDGET_CLASS + (gtk_type_class (capplet_widget_get_type ())); +} + +static void +prefs_widget_set_arg (GtkObject *object, GtkArg *arg, guint arg_id) +{ + PrefsWidget *prefs_widget; + + g_return_if_fail (object != NULL); + g_return_if_fail (IS_PREFS_WIDGET (object)); + + prefs_widget = PREFS_WIDGET (object); + + switch (arg_id) { + case ARG_PREFERENCES: + if (prefs_widget->prefs) + gtk_object_unref (GTK_OBJECT (prefs_widget->prefs)); + + prefs_widget->prefs = GTK_VALUE_POINTER (*arg); + + if (prefs_widget->prefs) { + gtk_object_ref (GTK_OBJECT (prefs_widget->prefs)); + read_preferences (prefs_widget, prefs_widget->prefs); + } + + break; + + default: + g_warning ("Bad argument set"); + break; + } +} + +static void +prefs_widget_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) +{ + PrefsWidget *prefs_widget; + + g_return_if_fail (object != NULL); + g_return_if_fail (IS_PREFS_WIDGET (object)); + + prefs_widget = PREFS_WIDGET (object); + + switch (arg_id) { + case ARG_PREFERENCES: + GTK_VALUE_POINTER (*arg) = prefs_widget->prefs; + break; + + default: + g_warning ("Bad argument get"); + break; + } +} + +GtkWidget * +prefs_widget_new (Preferences *prefs) +{ + g_return_val_if_fail (prefs == NULL || IS_PREFERENCES (prefs), NULL); + + return gtk_widget_new (prefs_widget_get_type (), + "preferences", prefs, + NULL); +} + +void +prefs_widget_set_preferences (PrefsWidget *prefs_widget, Preferences *prefs) +{ + g_return_if_fail (prefs_widget != NULL); + g_return_if_fail (IS_PREFS_WIDGET (prefs_widget)); + g_return_if_fail (prefs != NULL); + g_return_if_fail (IS_PREFERENCES (prefs)); + + gtk_object_set (GTK_OBJECT (prefs_widget), "preferences", prefs, NULL); +} + +static void +read_preferences (PrefsWidget *prefs_widget, Preferences *prefs) +{ + GtkAdjustment *adjustment; + + g_return_if_fail (prefs_widget != NULL); + g_return_if_fail (IS_PREFS_WIDGET (prefs_widget)); + g_return_if_fail (prefs != NULL); + g_return_if_fail (IS_PREFERENCES (prefs)); + + if (prefs->rtol) { + gtk_toggle_button_set_active + (GTK_TOGGLE_BUTTON (WID ("right_handed_select")), + TRUE); + } else { + gtk_toggle_button_set_active + (GTK_TOGGLE_BUTTON (WID ("left_handed_select")), + TRUE); + } + + adjustment = gtk_range_get_adjustment + (GTK_RANGE (WID ("acceleration_entry"))); + gtk_adjustment_set_value (adjustment, prefs->acceleration); + + adjustment = gtk_range_get_adjustment + (GTK_RANGE (WID ("threshold_entry"))); + gtk_adjustment_set_value (adjustment, prefs->threshold); +} + +static void +left_handed_selected_cb (GtkToggleButton *tb, PrefsWidget *prefs_widget) +{ + g_return_if_fail (prefs_widget != NULL); + g_return_if_fail (IS_PREFS_WIDGET (prefs_widget)); + g_return_if_fail (prefs_widget->prefs != NULL); + g_return_if_fail (IS_PREFERENCES (prefs_widget->prefs)); + + if (gtk_toggle_button_get_active (tb)) { + prefs_widget->prefs->rtol = FALSE; + preferences_changed (prefs_widget->prefs); + } + + capplet_widget_state_changed (CAPPLET_WIDGET (prefs_widget), TRUE); +} + +static void +right_handed_selected_cb (GtkToggleButton *tb, PrefsWidget *prefs_widget) +{ + g_return_if_fail (prefs_widget != NULL); + g_return_if_fail (IS_PREFS_WIDGET (prefs_widget)); + g_return_if_fail (prefs_widget->prefs != NULL); + g_return_if_fail (IS_PREFERENCES (prefs_widget->prefs)); + + if (gtk_toggle_button_get_active (tb)) { + prefs_widget->prefs->rtol = TRUE; + preferences_changed (prefs_widget->prefs); + } + + capplet_widget_state_changed (CAPPLET_WIDGET (prefs_widget), TRUE); +} + +static void +acceleration_changed_cb (GtkAdjustment *adjustment, PrefsWidget *prefs_widget) +{ + g_return_if_fail (prefs_widget != NULL); + g_return_if_fail (IS_PREFS_WIDGET (prefs_widget)); + g_return_if_fail (prefs_widget->prefs != NULL); + g_return_if_fail (IS_PREFERENCES (prefs_widget->prefs)); + g_return_if_fail (adjustment != NULL); + g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment)); + + prefs_widget->prefs->acceleration = adjustment->value; + + preferences_changed (prefs_widget->prefs); + capplet_widget_state_changed (CAPPLET_WIDGET (prefs_widget), TRUE); +} + + +static void +threshold_changed_cb (GtkAdjustment *adjustment, PrefsWidget *prefs_widget) +{ + g_return_if_fail (prefs_widget != NULL); + g_return_if_fail (IS_PREFS_WIDGET (prefs_widget)); + g_return_if_fail (prefs_widget->prefs != NULL); + g_return_if_fail (IS_PREFERENCES (prefs_widget->prefs)); + g_return_if_fail (adjustment != NULL); + g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment)); + + prefs_widget->prefs->threshold = adjustment->value; + + preferences_changed (prefs_widget->prefs); + capplet_widget_state_changed (CAPPLET_WIDGET (prefs_widget), TRUE); +} diff --git a/capplets/mouse/prefs-widget.h b/capplets/mouse/prefs-widget.h new file mode 100644 index 000000000..e642e030e --- /dev/null +++ b/capplets/mouse/prefs-widget.h @@ -0,0 +1,60 @@ +/* -*- mode: c; style: linux -*- */ + +/* prefs-widget.h + * Copyright (C) 2000 Helix Code, Inc. + * + * Written by Bradford Hovinen + * + * 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. + */ + +#ifndef __PREFS_WIDGET_H +#define __PREFS_WIDGET_H + +#include +#include +#include + +#include "preferences.h" + +#define PREFS_WIDGET(obj) GTK_CHECK_CAST (obj, prefs_widget_get_type (), PrefsWidget) +#define PREFS_WIDGET_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, prefs_widget_get_type (), PrefsWidgetClass) +#define IS_PREFS_WIDGET(obj) GTK_CHECK_TYPE (obj, prefs_widget_get_type ()) + +typedef struct _PrefsWidget PrefsWidget; +typedef struct _PrefsWidgetClass PrefsWidgetClass; + +struct _PrefsWidget +{ + CappletWidget capplet_widget; + + Preferences *prefs; + GladeXML *dialog_data; +}; + +struct _PrefsWidgetClass +{ + CappletWidgetClass parent_class; +}; + +guint prefs_widget_get_type (void); + +GtkWidget *prefs_widget_new (Preferences *prefs); + +void prefs_widget_set_preferences (PrefsWidget *prefs_widget, + Preferences *prefs); + +#endif /* __PREFS_WIDGET_H */