From 6e43a028dcc0b297f7f19583e917011c17e75066 Mon Sep 17 00:00:00 2001 From: "Bradford Hovinen (Gdict maintainer)" Date: Mon, 11 Sep 2000 02:40:14 +0000 Subject: [PATCH] Added new keyboard properties capplet --- capplets/Makefile.am | 2 +- capplets/keyboard/ChangeLog | 0 capplets/keyboard/Makefile.am | 38 ++ capplets/keyboard/keyboard-properties.desktop | 59 +++ capplets/keyboard/keyboard-properties.glade | 360 +++++++++++++++++ capplets/keyboard/main.c | 185 +++++++++ capplets/keyboard/preferences.c | 374 ++++++++++++++++++ capplets/keyboard/preferences.h | 74 ++++ capplets/keyboard/prefs-widget.c | 325 +++++++++++++++ capplets/keyboard/prefs-widget.h | 60 +++ 10 files changed, 1476 insertions(+), 1 deletion(-) create mode 100644 capplets/keyboard/ChangeLog create mode 100644 capplets/keyboard/Makefile.am create mode 100644 capplets/keyboard/keyboard-properties.desktop create mode 100644 capplets/keyboard/keyboard-properties.glade create mode 100644 capplets/keyboard/main.c create mode 100644 capplets/keyboard/preferences.c create mode 100644 capplets/keyboard/preferences.h create mode 100644 capplets/keyboard/prefs-widget.c create mode 100644 capplets/keyboard/prefs-widget.h diff --git a/capplets/Makefile.am b/capplets/Makefile.am index 5cc4b9eb9..956064b0d 100644 --- a/capplets/Makefile.am +++ b/capplets/Makefile.am @@ -2,7 +2,7 @@ always_built_SUBDIRS = desktop-links mouse-properties \ new-screensaver-properties new-background-properties \ theme-switcher sound-properties new-bell-properties \ ui-properties url-properties gnome-edit-properties \ - session-properties wm-properties keyboard-properties \ + session-properties wm-properties new-keyboard-properties \ mime-type SUBDIRS = $(always_built_SUBDIRS) diff --git a/capplets/keyboard/ChangeLog b/capplets/keyboard/ChangeLog new file mode 100644 index 000000000..e69de29bb diff --git a/capplets/keyboard/Makefile.am b/capplets/keyboard/Makefile.am new file mode 100644 index 000000000..e774fdc53 --- /dev/null +++ b/capplets/keyboard/Makefile.am @@ -0,0 +1,38 @@ +Applicationsdir = $(datadir)/control-center/Desktop +Applications_DATA = \ + keyboard-properties.desktop + +Gladedir = $(datadir)/control-center-data +Glade_DATA = \ + keyboard-properties.glade + +EXTRA_DIST = ChangeLog $(Applications_DATA) $(Glade_DATA) + +INCLUDES = \ + -DGNOMELOCALEDIR=\""$(datadir)/locale"\" \ + -DGNOME_ICONDIR=\""${prefix}/share/pixmaps"\" \ + -DG_LOG_DOMAIN=\"keyboard-properties\" \ + -DGLADE_DATADIR=\""$(Gladedir)"\" \ + $(GNOME_INCLUDEDIR) \ + $(XML_CFLAGS) \ + $(LIBGLADE_CFLAGS) \ + -I$(top_srcdir)/ \ + -I$(top_srcdir)/intl \ + -I$(top_srcdir)/libcapplet + +bin_PROGRAMS = keyboard-properties-capplet + +keyboard_properties_capplet_SOURCES = \ + prefs-widget.c prefs-widget.h \ + preferences.c preferences.h \ + main.c + +keyboard_properties_capplet_LDADD = \ + $(GNOME_LIBDIR) \ + $(GNOMEUI_LIBS) \ + $(ORBIT_LIBS) \ + $(GNOME_XML_LIB) \ + $(LIBGLADE_LIBS) \ + $(XF86MISC_LIBS) \ + -lgdk_pixbuf \ + ../../libcapplet/libcapplet.la diff --git a/capplets/keyboard/keyboard-properties.desktop b/capplets/keyboard/keyboard-properties.desktop new file mode 100644 index 000000000..3ff352fd8 --- /dev/null +++ b/capplets/keyboard/keyboard-properties.desktop @@ -0,0 +1,59 @@ +[Desktop Entry] +Name=Keyboard +Name[ca]=Propietats del teclat +Name[cs]=Klávesnice +Name[da]=Tastatur +Name[de]=Tastatur +Name[el]=Ñõèìßóåéò ðëçêôñïëïãßïõ +Name[es]=Propiedades del Teclado +Name[et]=Klaviatuur +Name[fi]=Näppäimistö +Name[fr]=Clavier +Name[gl]=Teclado +Name[hu]=Billentyûzet +Name[it]=Tastiera +Name[ja]=¥­¡¼¥Ü¡¼¥É +Name[ko]=ÀÚÆÇ +Name[lt]=Klaviatûra +Name[no]=Tastatur +Name[pl]=Klawiatura +Name[pt]=Propriedades do Teclado +Name[pt_BR]=Propriedades do Teclado +Name[ru]=ëÌÁ×ÉÁÔÕÒÁ +Name[sl]=Tipkovnica +Name[sv]=Tangentbord +Name[uk]=ëÌÁצÁÔÕÒÁ +Name[wa]=Prôpietés del taprece +Name[zh_TW.Big5]=Áä½L +Name[zh_CN.GB2312]=¼üÅÌ +Comment=Keyboard Properties +Comment[ca]=Configurar el teclat +Comment[cs]=Nastavení klávesnice. +Comment[da]=Tastaturegenskaber +Comment[de]=Tastatureinstellungen +Comment[el]=Ôñïðïðïßçóç ôùí ñõèìßóåùí ôïõ ðëçêôñïëïãßïõ +Comment[es]=Modifica las propiedades del teclado +Comment[et]=Klaviatuuri häälestus +Comment[fi]=Näppäimistön asetukset +Comment[fr]=Configuration des propriétés du clavier +Comment[gl]=Propiedades do teclado +Comment[hu]=Billentyûzet beállításai +Comment[it]=Impostazioni della tastiera +Comment[ja]=¥­¡¼¥Ü¡¼¥É¤ÎÀßÄê +Comment[ko]=ÀÚÆÇ ¼Ó¼º +Comment[lt]=Klaviatûros savybës +Comment[no]=Egenskaper for tastatur +Comment[pl]=Ustawienia klawiatury +Comment[pt]=Propriedades do Teclado +Comment[pt_BR]=Propriedades do Teclado +Comment[ru]=ó×ÏÊÓÔ×Á ËÌÁ×ÉÁÔÕÒÙ +Comment[sl]=Lastnosti Tipkovnice +Comment[sv]=Tangentbordsinställningar +Comment[uk]=÷ÌÁÓÔÉ×ÏÓÔ¦ ËÌÁצÁÔÕÒÉ +Comment[wa]=Candjî les prôpietés del taprece +Comment[zh_TW.Big5]=Áä½L³]©w +Comment[zh_CN.GB2312]=¼üÅÌÉ趨 +Exec=keyboard-properties +Icon=gnome-cckeyboard.png +Terminal=0 +Type=Application diff --git a/capplets/keyboard/keyboard-properties.glade b/capplets/keyboard/keyboard-properties.glade new file mode 100644 index 000000000..bfdc81504 --- /dev/null +++ b/capplets/keyboard/keyboard-properties.glade @@ -0,0 +1,360 @@ + + + + + New-keyboard-properties + new-keyboard-properties + + src + pixmaps + C + True + True + + + + GtkWindow + window1 + window1 + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + False + False + True + False + + + GtkVBox + prefs_widget + 5 + False + 5 + + + GtkFrame + frame1 + + 0 + GTK_SHADOW_ETCHED_IN + + 0 + True + True + + + + GtkTable + table1 + 5 + 3 + 2 + False + 5 + 5 + + + GtkHScale + rate_entry + True + True + GTK_POS_TOP + 0 + GTK_UPDATE_CONTINUOUS + 0 + 0 + 255 + 0 + 0 + 0 + + 1 + 2 + 1 + 2 + 0 + 0 + True + False + False + False + True + True + + + + + GtkHScale + delay_entry + True + True + GTK_POS_TOP + 0 + GTK_UPDATE_CONTINUOUS + 0 + 0 + 10000 + 0 + 0 + 0 + + 1 + 2 + 2 + 3 + 0 + 0 + True + False + False + False + True + True + + + + + GtkCheckButton + repeat_toggle + True + + toggled + repeat_toggled_cb + Mon, 11 Sep 2000 02:12:19 GMT + + + False + True + + 0 + 2 + 0 + 1 + 0 + 0 + False + False + False + False + True + False + + + + + GtkLabel + label1 + + GTK_JUSTIFY_LEFT + False + 0 + 1 + 0 + 0 + + 0 + 1 + 1 + 2 + 0 + 0 + False + False + False + False + True + True + + + + + GtkLabel + label2 + + GTK_JUSTIFY_LEFT + False + 0 + 1 + 0 + 0 + + 0 + 1 + 2 + 3 + 0 + 0 + False + False + False + False + True + True + + + + + + + GtkFrame + frame2 + + 0 + GTK_SHADOW_ETCHED_IN + + 0 + True + True + + + + GtkTable + table2 + 5 + 2 + 2 + False + 5 + 5 + + + GtkCheckButton + click_toggle + True + + toggled + click_toggled_cb + Mon, 11 Sep 2000 02:02:18 GMT + + + False + True + + 0 + 2 + 0 + 1 + 0 + 0 + False + False + False + False + True + False + + + + + GtkLabel + label3 + + GTK_JUSTIFY_RIGHT + False + 0 + 1 + 0 + 0 + + 0 + 1 + 1 + 2 + 0 + 0 + False + False + False + False + True + True + + + + + GtkHScale + click_volume_entry + True + True + GTK_POS_TOP + 0 + GTK_UPDATE_CONTINUOUS + 0 + 0 + 100 + 0 + 0 + 0 + + 1 + 2 + 1 + 2 + 0 + 0 + True + False + False + False + True + True + + + + + + + GtkFrame + frame3 + + 0 + GTK_SHADOW_ETCHED_IN + + 0 + True + True + + + + GtkHBox + hbox1 + 5 + False + 5 + + + GtkLabel + label4 + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkEntry + entry1 + True + True + True + 0 + + + 0 + True + True + + + + + + + + diff --git a/capplets/keyboard/main.c b/capplets/keyboard/main.c new file mode 100644 index 000000000..b81da9846 --- /dev/null +++ b/capplets/keyboard/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 ("keyboard-properties-capplet", + 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_KEYBOARD_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-cckeyboard.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/keyboard/preferences.c b/capplets/keyboard/preferences.c new file mode 100644 index 000000000..637c5f9ec --- /dev/null +++ b/capplets/keyboard/preferences.c @@ -0,0 +1,374 @@ +/* -*- mode: c; style: linux -*- */ + +/* preferences.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 +#include +#include + +#ifdef HAVE_X11_EXTENSIONS_XF86MISC_H +#include +#endif + +#include "preferences.h" + +static GtkObjectClass *parent_class; + +#ifdef HAVE_X11_EXTENSIONS_XF86MISC_H +static XF86MiscKbdSettings kbdsettings; +#endif + +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); + + /* Code to copy data from old preferences object to new one */ + + 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) +{ + XKeyboardState kbdstate; + gboolean repeat_default, click_default; + gint event_base_return, error_base_return; + + g_return_if_fail (prefs != NULL); + g_return_if_fail (IS_PREFERENCES (prefs)); + + prefs->rate = gnome_config_get_int ("/Desktop/Keyboard/rate=-"); + prefs->delay = gnome_config_get_int ("/Desktop/Keyboard/delay=-1"); + prefs->repeat = gnome_config_get_bool_with_default + ("/Desktop/Keyboard/repeat=true", &repeat_default); + prefs->click_volume = gnome_config_get_int + ("/Desktop/Keyboard/clickvolume=-1"); + prefs->click_on_keypress = gnome_config_get_bool_with_default + ("/Desktop/Keyboard/click=false", &click_default); + + XGetKeyboardControl (GDK_DISPLAY (), &kbdstate); + + if (repeat_default) + prefs->repeat = kbdstate.global_auto_repeat; + + if (prefs->rate == -1 || prefs->delay == -1) { +#ifdef HAVE_X11_EXTENSIONS_XF86MISC_H + if (XF86MiscQueryExtension (GDK_DISPLAY (), + &event_base_return, + &error_base_return) == True) + { + XF86MiscGetKbdSettings (GDK_DISPLAY (), &kbdsettings); + prefs->rate = kbdsettings.rate; + prefs->delay = kbdsettings.delay; + } else { + prefs->rate = 5; + prefs->delay = 500; + } +#else + /* FIXME: how to get the keyboard speed on non-xf86? */ + prefs->rate = 5; + prefs->delay = 500; +#endif + } + + if (click_default) + prefs->click_on_keypress = (kbdstate.key_click_percent == 0); + + if (prefs->click_volume == -1) + prefs->click_volume = kbdstate.key_click_percent; +} + +void +preferences_save (Preferences *prefs) +{ + g_return_if_fail (prefs != NULL); + g_return_if_fail (IS_PREFERENCES (prefs)); + + gnome_config_set_bool ("/Desktop/Keyboard/repeat", prefs->repeat); + gnome_config_set_int ("/Desktop/Keyboard/delay", prefs->delay); + gnome_config_set_int ("/Desktop/Keyboard/rate", prefs->rate); + gnome_config_set_bool ("/Desktop/Keyboard/click", + prefs->click_on_keypress); + gnome_config_set_int ("/Desktop/Keyboard/clickvolume", + prefs->click_volume); + + gnome_config_sync (); +} + +void +preferences_changed (Preferences *prefs) +{ + if (prefs->frozen) return; + + if (prefs->timeout_id) + gtk_timeout_remove (prefs->timeout_id); + + preferences_apply_now (prefs); +} + +void +preferences_apply_now (Preferences *prefs) +{ + XKeyboardControl kbdcontrol; + int event_base_return, error_base_return; + + 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; + + if (prefs->repeat) { + XAutoRepeatOn (GDK_DISPLAY ()); +#ifdef HAVE_X11_EXTENSIONS_XF86MISC_H + if (XF86MiscQueryExtension (GDK_DISPLAY (), + &event_base_return, + &error_base_return) == True) + { + kbdsettings.rate = prefs->rate; + kbdsettings.delay = prefs->delay; + XF86MiscSetKbdSettings (GDK_DISPLAY (), &kbdsettings); + } else { + XAutoRepeatOff (GDK_DISPLAY ()); + } +#endif + } else { + XAutoRepeatOff (GDK_DISPLAY ()); + } + + kbdcontrol.key_click_percent = + prefs->click_on_keypress ? prefs->click_volume : 0; + XChangeKeyboardControl (GDK_DISPLAY (), KBKeyClickPercent, + &kbdcontrol); +} + +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, "keyboard-properties")) + return NULL; + + for (node = root_node->childs; node; node = node->next) { + if (!strcmp (node->name, "rate")) + prefs->rate = xml_read_int (node, NULL); + else if (!strcmp (node->name, "delay")) + prefs->delay = xml_read_int (node, NULL); + else if (!strcmp (node->name, "repeat")) + prefs->repeat = TRUE; + else if (!strcmp (node->name, "click-volume")) + prefs->click_volume = xml_read_int (node, NULL); + else if (!strcmp (node->name, "click-on-keypress")) + prefs->click_on_keypress = TRUE; + } + + return prefs; +} + +xmlDocPtr +preferences_write_xml (Preferences *prefs) +{ + xmlDocPtr doc; + xmlNodePtr node; + char *tmp; + + doc = xmlNewDoc ("1.0"); + + node = xmlNewDocNode (doc, NULL, "keyboard-properties", NULL); + + xmlAddChild (node, xml_write_int ("rate", NULL, prefs->rate)); + xmlAddChild (node, xml_write_int ("delay", NULL, prefs->delay)); + + if (prefs->repeat) + xmlNewChild (node, NULL, "repeat", NULL); + + xmlAddChild (node, xml_write_int ("click-volume", NULL, + prefs->click_volume)); + + if (prefs->click_on_keypress) + xmlNewChild (node, NULL, "click-on-keypress", 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/keyboard/preferences.h b/capplets/keyboard/preferences.h new file mode 100644 index 000000000..c8417b3ec --- /dev/null +++ b/capplets/keyboard/preferences.h @@ -0,0 +1,74 @@ +/* -*- 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; + + gint rate; + gint delay; + gint repeat; + gint click_volume; + gint click_on_keypress; +}; + +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/keyboard/prefs-widget.c b/capplets/keyboard/prefs-widget.c new file mode 100644 index 000000000..a3306e0e8 --- /dev/null +++ b/capplets/keyboard/prefs-widget.c @@ -0,0 +1,325 @@ +/* -*- 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 "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 repeat_toggled_cb (GtkToggleButton *button, + PrefsWidget *prefs_widget); +static void rate_changed_cb (GtkAdjustment *adjustment, + PrefsWidget *prefs_widget); +static void delay_changed_cb (GtkAdjustment *adjustment, + PrefsWidget *prefs_widget); +static void click_toggled_cb (GtkToggleButton *button, + PrefsWidget *prefs_widget); +static void click_volume_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; + + prefs_widget->dialog_data = + glade_xml_new (GLADE_DATADIR "/keyboard-properties.glade", + "prefs_widget"); + + glade_xml_signal_connect_data + (prefs_widget->dialog_data, "repeat_toggled_cb", + repeat_toggled_cb, prefs_widget); + + widget = glade_xml_get_widget (prefs_widget->dialog_data, + "prefs_widget"); + gtk_container_add (GTK_CONTAINER (prefs_widget), widget); + + adjustment = gtk_range_get_adjustment + (GTK_RANGE (WID ("rate_entry"))); + gtk_signal_connect (GTK_OBJECT (adjustment), "value_changed", + rate_changed_cb, prefs_widget); + + adjustment = gtk_range_get_adjustment + (GTK_RANGE (WID ("delay_entry"))); + gtk_signal_connect (GTK_OBJECT (adjustment), "value_changed", + delay_changed_cb, prefs_widget); + + glade_xml_signal_connect_data + (prefs_widget->dialog_data, "click_toggled_cb", + click_toggled_cb, prefs_widget); + + adjustment = gtk_range_get_adjustment + (GTK_RANGE (WID ("click_volume_entry"))); + gtk_signal_connect (GTK_OBJECT (adjustment), "value_changed", + click_volume_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)); + + gtk_toggle_button_set_active + (GTK_TOGGLE_BUTTON (WID ("repeat_toggle")), prefs->repeat); + + adjustment = gtk_range_get_adjustment + (GTK_RANGE (WID ("rate_entry"))); + gtk_adjustment_set_value (adjustment, prefs->rate); + + adjustment = gtk_range_get_adjustment + (GTK_RANGE (WID ("delay_entry"))); + gtk_adjustment_set_value (adjustment, prefs->delay); + + gtk_toggle_button_set_active + (GTK_TOGGLE_BUTTON (WID ("click_toggle")), + prefs->click_on_keypress); + + adjustment = gtk_range_get_adjustment + (GTK_RANGE (WID ("click_volume_entry"))); + gtk_adjustment_set_value (adjustment, prefs->click_volume); +} + +static void +repeat_toggled_cb (GtkToggleButton *button, 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 (button != NULL); + g_return_if_fail (GTK_IS_TOGGLE_BUTTON (button)); + + prefs_widget->prefs->repeat = + gtk_toggle_button_get_active (button); + + preferences_changed (prefs_widget->prefs); + capplet_widget_state_changed (CAPPLET_WIDGET (prefs_widget), TRUE); +} + +static void +rate_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->rate = adjustment->value; + + preferences_changed (prefs_widget->prefs); + capplet_widget_state_changed (CAPPLET_WIDGET (prefs_widget), TRUE); +} + +static void +delay_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->delay = adjustment->value; + + preferences_changed (prefs_widget->prefs); + capplet_widget_state_changed (CAPPLET_WIDGET (prefs_widget), TRUE); +} + +static void +click_toggled_cb (GtkToggleButton *button, 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 (button != NULL); + g_return_if_fail (GTK_IS_TOGGLE_BUTTON (button)); + + prefs_widget->prefs->click_on_keypress = + gtk_toggle_button_get_active (button); + + preferences_changed (prefs_widget->prefs); + capplet_widget_state_changed (CAPPLET_WIDGET (prefs_widget), TRUE); +} + +static void +click_volume_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->click_volume = adjustment->value; + + preferences_changed (prefs_widget->prefs); + capplet_widget_state_changed (CAPPLET_WIDGET (prefs_widget), TRUE); +} diff --git a/capplets/keyboard/prefs-widget.h b/capplets/keyboard/prefs-widget.h new file mode 100644 index 000000000..e642e030e --- /dev/null +++ b/capplets/keyboard/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 */