Added new keyboard properties capplet

This commit is contained in:
Bradford Hovinen (Gdict maintainer) 2000-09-11 02:40:14 +00:00
parent e4b4b7af40
commit 6e43a028dc
10 changed files with 1476 additions and 1 deletions

View file

@ -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)

View file

View file

@ -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

View file

@ -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

View file

@ -0,0 +1,360 @@
<?xml version="1.0"?>
<GTK-Interface>
<project>
<name>New-keyboard-properties</name>
<program_name>new-keyboard-properties</program_name>
<directory></directory>
<source_directory>src</source_directory>
<pixmaps_directory>pixmaps</pixmaps_directory>
<language>C</language>
<gnome_support>True</gnome_support>
<gettext_support>True</gettext_support>
</project>
<widget>
<class>GtkWindow</class>
<name>window1</name>
<title>window1</title>
<type>GTK_WINDOW_TOPLEVEL</type>
<position>GTK_WIN_POS_NONE</position>
<modal>False</modal>
<allow_shrink>False</allow_shrink>
<allow_grow>True</allow_grow>
<auto_shrink>False</auto_shrink>
<widget>
<class>GtkVBox</class>
<name>prefs_widget</name>
<border_width>5</border_width>
<homogeneous>False</homogeneous>
<spacing>5</spacing>
<widget>
<class>GtkFrame</class>
<name>frame1</name>
<label>Auto-repeat</label>
<label_xalign>0</label_xalign>
<shadow_type>GTK_SHADOW_ETCHED_IN</shadow_type>
<child>
<padding>0</padding>
<expand>True</expand>
<fill>True</fill>
</child>
<widget>
<class>GtkTable</class>
<name>table1</name>
<border_width>5</border_width>
<rows>3</rows>
<columns>2</columns>
<homogeneous>False</homogeneous>
<row_spacing>5</row_spacing>
<column_spacing>5</column_spacing>
<widget>
<class>GtkHScale</class>
<name>rate_entry</name>
<can_focus>True</can_focus>
<draw_value>True</draw_value>
<value_pos>GTK_POS_TOP</value_pos>
<digits>0</digits>
<policy>GTK_UPDATE_CONTINUOUS</policy>
<value>0</value>
<lower>0</lower>
<upper>255</upper>
<step>0</step>
<page>0</page>
<page_size>0</page_size>
<child>
<left_attach>1</left_attach>
<right_attach>2</right_attach>
<top_attach>1</top_attach>
<bottom_attach>2</bottom_attach>
<xpad>0</xpad>
<ypad>0</ypad>
<xexpand>True</xexpand>
<yexpand>False</yexpand>
<xshrink>False</xshrink>
<yshrink>False</yshrink>
<xfill>True</xfill>
<yfill>True</yfill>
</child>
</widget>
<widget>
<class>GtkHScale</class>
<name>delay_entry</name>
<can_focus>True</can_focus>
<draw_value>True</draw_value>
<value_pos>GTK_POS_TOP</value_pos>
<digits>0</digits>
<policy>GTK_UPDATE_CONTINUOUS</policy>
<value>0</value>
<lower>0</lower>
<upper>10000</upper>
<step>0</step>
<page>0</page>
<page_size>0</page_size>
<child>
<left_attach>1</left_attach>
<right_attach>2</right_attach>
<top_attach>2</top_attach>
<bottom_attach>3</bottom_attach>
<xpad>0</xpad>
<ypad>0</ypad>
<xexpand>True</xexpand>
<yexpand>False</yexpand>
<xshrink>False</xshrink>
<yshrink>False</yshrink>
<xfill>True</xfill>
<yfill>True</yfill>
</child>
</widget>
<widget>
<class>GtkCheckButton</class>
<name>repeat_toggle</name>
<can_focus>True</can_focus>
<signal>
<name>toggled</name>
<handler>repeat_toggled_cb</handler>
<last_modification_time>Mon, 11 Sep 2000 02:12:19 GMT</last_modification_time>
</signal>
<label>Enable auto-repeat</label>
<active>False</active>
<draw_indicator>True</draw_indicator>
<child>
<left_attach>0</left_attach>
<right_attach>2</right_attach>
<top_attach>0</top_attach>
<bottom_attach>1</bottom_attach>
<xpad>0</xpad>
<ypad>0</ypad>
<xexpand>False</xexpand>
<yexpand>False</yexpand>
<xshrink>False</xshrink>
<yshrink>False</yshrink>
<xfill>True</xfill>
<yfill>False</yfill>
</child>
</widget>
<widget>
<class>GtkLabel</class>
<name>label1</name>
<label>Repeat rate</label>
<justify>GTK_JUSTIFY_LEFT</justify>
<wrap>False</wrap>
<xalign>0</xalign>
<yalign>1</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
<child>
<left_attach>0</left_attach>
<right_attach>1</right_attach>
<top_attach>1</top_attach>
<bottom_attach>2</bottom_attach>
<xpad>0</xpad>
<ypad>0</ypad>
<xexpand>False</xexpand>
<yexpand>False</yexpand>
<xshrink>False</xshrink>
<yshrink>False</yshrink>
<xfill>True</xfill>
<yfill>True</yfill>
</child>
</widget>
<widget>
<class>GtkLabel</class>
<name>label2</name>
<label>Repeat delay</label>
<justify>GTK_JUSTIFY_LEFT</justify>
<wrap>False</wrap>
<xalign>0</xalign>
<yalign>1</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
<child>
<left_attach>0</left_attach>
<right_attach>1</right_attach>
<top_attach>2</top_attach>
<bottom_attach>3</bottom_attach>
<xpad>0</xpad>
<ypad>0</ypad>
<xexpand>False</xexpand>
<yexpand>False</yexpand>
<xshrink>False</xshrink>
<yshrink>False</yshrink>
<xfill>True</xfill>
<yfill>True</yfill>
</child>
</widget>
</widget>
</widget>
<widget>
<class>GtkFrame</class>
<name>frame2</name>
<label>Keyboard click</label>
<label_xalign>0</label_xalign>
<shadow_type>GTK_SHADOW_ETCHED_IN</shadow_type>
<child>
<padding>0</padding>
<expand>True</expand>
<fill>True</fill>
</child>
<widget>
<class>GtkTable</class>
<name>table2</name>
<border_width>5</border_width>
<rows>2</rows>
<columns>2</columns>
<homogeneous>False</homogeneous>
<row_spacing>5</row_spacing>
<column_spacing>5</column_spacing>
<widget>
<class>GtkCheckButton</class>
<name>click_toggle</name>
<can_focus>True</can_focus>
<signal>
<name>toggled</name>
<handler>click_toggled_cb</handler>
<last_modification_time>Mon, 11 Sep 2000 02:02:18 GMT</last_modification_time>
</signal>
<label>Click on keypress</label>
<active>False</active>
<draw_indicator>True</draw_indicator>
<child>
<left_attach>0</left_attach>
<right_attach>2</right_attach>
<top_attach>0</top_attach>
<bottom_attach>1</bottom_attach>
<xpad>0</xpad>
<ypad>0</ypad>
<xexpand>False</xexpand>
<yexpand>False</yexpand>
<xshrink>False</xshrink>
<yshrink>False</yshrink>
<xfill>True</xfill>
<yfill>False</yfill>
</child>
</widget>
<widget>
<class>GtkLabel</class>
<name>label3</name>
<label>Click volume</label>
<justify>GTK_JUSTIFY_RIGHT</justify>
<wrap>False</wrap>
<xalign>0</xalign>
<yalign>1</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
<child>
<left_attach>0</left_attach>
<right_attach>1</right_attach>
<top_attach>1</top_attach>
<bottom_attach>2</bottom_attach>
<xpad>0</xpad>
<ypad>0</ypad>
<xexpand>False</xexpand>
<yexpand>False</yexpand>
<xshrink>False</xshrink>
<yshrink>False</yshrink>
<xfill>True</xfill>
<yfill>True</yfill>
</child>
</widget>
<widget>
<class>GtkHScale</class>
<name>click_volume_entry</name>
<can_focus>True</can_focus>
<draw_value>True</draw_value>
<value_pos>GTK_POS_TOP</value_pos>
<digits>0</digits>
<policy>GTK_UPDATE_CONTINUOUS</policy>
<value>0</value>
<lower>0</lower>
<upper>100</upper>
<step>0</step>
<page>0</page>
<page_size>0</page_size>
<child>
<left_attach>1</left_attach>
<right_attach>2</right_attach>
<top_attach>1</top_attach>
<bottom_attach>2</bottom_attach>
<xpad>0</xpad>
<ypad>0</ypad>
<xexpand>True</xexpand>
<yexpand>False</yexpand>
<xshrink>False</xshrink>
<yshrink>False</yshrink>
<xfill>True</xfill>
<yfill>True</yfill>
</child>
</widget>
</widget>
</widget>
<widget>
<class>GtkFrame</class>
<name>frame3</name>
<label>Preview</label>
<label_xalign>0</label_xalign>
<shadow_type>GTK_SHADOW_ETCHED_IN</shadow_type>
<child>
<padding>0</padding>
<expand>True</expand>
<fill>True</fill>
</child>
<widget>
<class>GtkHBox</class>
<name>hbox1</name>
<border_width>5</border_width>
<homogeneous>False</homogeneous>
<spacing>5</spacing>
<widget>
<class>GtkLabel</class>
<name>label4</name>
<label>Test settings</label>
<justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap>
<xalign>0.5</xalign>
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>False</fill>
</child>
</widget>
<widget>
<class>GtkEntry</class>
<name>entry1</name>
<can_focus>True</can_focus>
<editable>True</editable>
<text_visible>True</text_visible>
<text_max_length>0</text_max_length>
<text></text>
<child>
<padding>0</padding>
<expand>True</expand>
<fill>True</fill>
</child>
</widget>
</widget>
</widget>
</widget>
</widget>
</GTK-Interface>

185
capplets/keyboard/main.c Normal file
View file

@ -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 <config.h>
#endif
#include <gtk/gtk.h>
#include <gnome.h>
#include <libgnomeui/gnome-window-icon.h>
#include <tree.h>
#include <parser.h>
#include <glade/glade.h>
#include <capplet-widget.h>
#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;
}

View file

@ -0,0 +1,374 @@
/* -*- mode: c; style: linux -*- */
/* preferences.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 "config.h"
#endif
#include <stdlib.h>
#include <gnome.h>
#include <gdk/gdkx.h>
#include <X11/X.h>
#ifdef HAVE_X11_EXTENSIONS_XF86MISC_H
#include <X11/extensions/xf86misc.h>
#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;
}

View file

@ -0,0 +1,74 @@
/* -*- mode: c; style: linux -*- */
/* preferences.h
* 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.
*/
#ifndef __PREFERENCES_H
#define __PREFERENCES_H
#include <gtk/gtk.h>
#include <tree.h>
#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 */

View file

@ -0,0 +1,325 @@
/* -*- mode: c; style: linux -*- */
/* prefs-widget.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 "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);
}

View file

@ -0,0 +1,60 @@
/* -*- mode: c; style: linux -*- */
/* prefs-widget.h
* 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.
*/
#ifndef __PREFS_WIDGET_H
#define __PREFS_WIDGET_H
#include <gtk/gtk.h>
#include <glade/glade.h>
#include <capplet-widget.h>
#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 */