Added new mouse properties capplet
2000-09-12 Bradford Hovinen <hovinen@helixcode.com> * new-keyboard-properties/preferences.c (preferences_clone): Added in missing code to copy preferences over
This commit is contained in:
parent
e97f9d324b
commit
96acc3fd51
12 changed files with 1536 additions and 7 deletions
|
@ -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 \
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
2000-09-12 Bradford Hovinen <hovinen@helixcode.com>
|
||||
|
||||
* preferences.c (preferences_clone): Added in missing code to copy
|
||||
preferences over
|
||||
|
|
@ -3,7 +3,10 @@
|
|||
/* preferences.c
|
||||
* Copyright (C) 2000 Helix Code, Inc.
|
||||
*
|
||||
* Written by Bradford Hovinen <hovinen@helixcode.com>
|
||||
* Written by Bradford Hovinen <hovinen@helixcode.com>,
|
||||
* Jaka Mocnik <jaka.mocnik@kiss.uni-lj.si>
|
||||
*
|
||||
* 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;
|
||||
}
|
||||
|
|
37
capplets/mouse/Makefile.am
Normal file
37
capplets/mouse/Makefile.am
Normal file
|
@ -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
|
185
capplets/mouse/main.c
Normal file
185
capplets/mouse/main.c
Normal 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 ("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;
|
||||
}
|
59
capplets/mouse/mouse-properties.desktop
Normal file
59
capplets/mouse/mouse-properties.desktop
Normal file
|
@ -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
|
400
capplets/mouse/mouse-properties.glade
Normal file
400
capplets/mouse/mouse-properties.glade
Normal file
|
@ -0,0 +1,400 @@
|
|||
<?xml version="1.0"?>
|
||||
<GTK-Interface>
|
||||
|
||||
<project>
|
||||
<name>New-mouse-properties</name>
|
||||
<program_name>new-mouse-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>GtkTable</class>
|
||||
<name>prefs_widget</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>GtkPixmap</class>
|
||||
<name>mouse_pixmap</name>
|
||||
<xalign>0</xalign>
|
||||
<yalign>0.5</yalign>
|
||||
<xpad>0</xpad>
|
||||
<ypad>0</ypad>
|
||||
<build_insensitive>True</build_insensitive>
|
||||
<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>True</xexpand>
|
||||
<yexpand>True</yexpand>
|
||||
<xshrink>False</xshrink>
|
||||
<yshrink>False</yshrink>
|
||||
<xfill>True</xfill>
|
||||
<yfill>True</yfill>
|
||||
</child>
|
||||
</widget>
|
||||
|
||||
<widget>
|
||||
<class>GtkFrame</class>
|
||||
<name>frame1</name>
|
||||
<label>Mouse buttons</label>
|
||||
<label_xalign>0</label_xalign>
|
||||
<shadow_type>GTK_SHADOW_ETCHED_IN</shadow_type>
|
||||
<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>True</yexpand>
|
||||
<xshrink>False</xshrink>
|
||||
<yshrink>False</yshrink>
|
||||
<xfill>True</xfill>
|
||||
<yfill>True</yfill>
|
||||
</child>
|
||||
|
||||
<widget>
|
||||
<class>GtkVBox</class>
|
||||
<name>vbox1</name>
|
||||
<border_width>5</border_width>
|
||||
<homogeneous>False</homogeneous>
|
||||
<spacing>5</spacing>
|
||||
|
||||
<widget>
|
||||
<class>GtkRadioButton</class>
|
||||
<name>left_handed_select</name>
|
||||
<can_focus>True</can_focus>
|
||||
<signal>
|
||||
<name>toggled</name>
|
||||
<handler>left_handed_selected_cb</handler>
|
||||
<last_modification_time>Tue, 12 Sep 2000 15:07:52 GMT</last_modification_time>
|
||||
</signal>
|
||||
<label>Left handed</label>
|
||||
<active>False</active>
|
||||
<draw_indicator>True</draw_indicator>
|
||||
<group>rtol_group</group>
|
||||
<child>
|
||||
<padding>0</padding>
|
||||
<expand>False</expand>
|
||||
<fill>False</fill>
|
||||
</child>
|
||||
</widget>
|
||||
|
||||
<widget>
|
||||
<class>GtkRadioButton</class>
|
||||
<name>right_handed_select</name>
|
||||
<can_focus>True</can_focus>
|
||||
<signal>
|
||||
<name>toggled</name>
|
||||
<handler>right_handed_selected_cb</handler>
|
||||
<last_modification_time>Tue, 12 Sep 2000 15:08:05 GMT</last_modification_time>
|
||||
</signal>
|
||||
<label>Right handed</label>
|
||||
<active>False</active>
|
||||
<draw_indicator>True</draw_indicator>
|
||||
<group>rtol_group</group>
|
||||
<child>
|
||||
<padding>0</padding>
|
||||
<expand>False</expand>
|
||||
<fill>False</fill>
|
||||
</child>
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
|
||||
<widget>
|
||||
<class>GtkFrame</class>
|
||||
<name>frame2</name>
|
||||
<label>Mouse motion</label>
|
||||
<label_xalign>0</label_xalign>
|
||||
<shadow_type>GTK_SHADOW_ETCHED_IN</shadow_type>
|
||||
<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>False</xexpand>
|
||||
<yexpand>False</yexpand>
|
||||
<xshrink>False</xshrink>
|
||||
<yshrink>False</yshrink>
|
||||
<xfill>True</xfill>
|
||||
<yfill>True</yfill>
|
||||
</child>
|
||||
|
||||
<widget>
|
||||
<class>GtkTable</class>
|
||||
<name>table2</name>
|
||||
<border_width>5</border_width>
|
||||
<rows>5</rows>
|
||||
<columns>3</columns>
|
||||
<homogeneous>False</homogeneous>
|
||||
<row_spacing>5</row_spacing>
|
||||
<column_spacing>5</column_spacing>
|
||||
|
||||
<widget>
|
||||
<class>GtkHSeparator</class>
|
||||
<name>hseparator1</name>
|
||||
<child>
|
||||
<left_attach>0</left_attach>
|
||||
<right_attach>3</right_attach>
|
||||
<top_attach>2</top_attach>
|
||||
<bottom_attach>3</bottom_attach>
|
||||
<xpad>0</xpad>
|
||||
<ypad>0</ypad>
|
||||
<xexpand>True</xexpand>
|
||||
<yexpand>True</yexpand>
|
||||
<xshrink>False</xshrink>
|
||||
<yshrink>False</yshrink>
|
||||
<xfill>True</xfill>
|
||||
<yfill>True</yfill>
|
||||
</child>
|
||||
</widget>
|
||||
|
||||
<widget>
|
||||
<class>GtkLabel</class>
|
||||
<name>label1</name>
|
||||
<label>Acceleration</label>
|
||||
<justify>GTK_JUSTIFY_CENTER</justify>
|
||||
<wrap>False</wrap>
|
||||
<xalign>0</xalign>
|
||||
<yalign>0.5</yalign>
|
||||
<xpad>0</xpad>
|
||||
<ypad>0</ypad>
|
||||
<child>
|
||||
<left_attach>0</left_attach>
|
||||
<right_attach>3</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>label2</name>
|
||||
<label>Threshold</label>
|
||||
<justify>GTK_JUSTIFY_CENTER</justify>
|
||||
<wrap>False</wrap>
|
||||
<xalign>0</xalign>
|
||||
<yalign>0.5</yalign>
|
||||
<xpad>0</xpad>
|
||||
<ypad>0</ypad>
|
||||
<child>
|
||||
<left_attach>0</left_attach>
|
||||
<right_attach>3</right_attach>
|
||||
<top_attach>3</top_attach>
|
||||
<bottom_attach>4</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>GtkHScale</class>
|
||||
<name>acceleration_entry</name>
|
||||
<can_focus>True</can_focus>
|
||||
<draw_value>False</draw_value>
|
||||
<value_pos>GTK_POS_TOP</value_pos>
|
||||
<digits>1</digits>
|
||||
<policy>GTK_UPDATE_CONTINUOUS</policy>
|
||||
<value>0</value>
|
||||
<lower>0</lower>
|
||||
<upper>7</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>False</xexpand>
|
||||
<yexpand>True</yexpand>
|
||||
<xshrink>False</xshrink>
|
||||
<yshrink>False</yshrink>
|
||||
<xfill>True</xfill>
|
||||
<yfill>True</yfill>
|
||||
</child>
|
||||
</widget>
|
||||
|
||||
<widget>
|
||||
<class>GtkHScale</class>
|
||||
<name>threshold_entry</name>
|
||||
<can_focus>True</can_focus>
|
||||
<draw_value>False</draw_value>
|
||||
<value_pos>GTK_POS_TOP</value_pos>
|
||||
<digits>1</digits>
|
||||
<policy>GTK_UPDATE_CONTINUOUS</policy>
|
||||
<value>0</value>
|
||||
<lower>0</lower>
|
||||
<upper>7</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>4</top_attach>
|
||||
<bottom_attach>5</bottom_attach>
|
||||
<xpad>0</xpad>
|
||||
<ypad>0</ypad>
|
||||
<xexpand>False</xexpand>
|
||||
<yexpand>True</yexpand>
|
||||
<xshrink>False</xshrink>
|
||||
<yshrink>False</yshrink>
|
||||
<xfill>True</xfill>
|
||||
<yfill>True</yfill>
|
||||
</child>
|
||||
</widget>
|
||||
|
||||
<widget>
|
||||
<class>GtkLabel</class>
|
||||
<name>label3</name>
|
||||
<label>Slow</label>
|
||||
<justify>GTK_JUSTIFY_CENTER</justify>
|
||||
<wrap>False</wrap>
|
||||
<xalign>1</xalign>
|
||||
<yalign>0.5</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>False</yfill>
|
||||
</child>
|
||||
</widget>
|
||||
|
||||
<widget>
|
||||
<class>GtkLabel</class>
|
||||
<name>label5</name>
|
||||
<label>Fast</label>
|
||||
<justify>GTK_JUSTIFY_CENTER</justify>
|
||||
<wrap>False</wrap>
|
||||
<xalign>0</xalign>
|
||||
<yalign>0.5</yalign>
|
||||
<xpad>0</xpad>
|
||||
<ypad>0</ypad>
|
||||
<child>
|
||||
<left_attach>2</left_attach>
|
||||
<right_attach>3</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>False</yfill>
|
||||
</child>
|
||||
</widget>
|
||||
|
||||
<widget>
|
||||
<class>GtkLabel</class>
|
||||
<name>label6</name>
|
||||
<label>Large</label>
|
||||
<justify>GTK_JUSTIFY_CENTER</justify>
|
||||
<wrap>False</wrap>
|
||||
<xalign>0</xalign>
|
||||
<yalign>0.5</yalign>
|
||||
<xpad>0</xpad>
|
||||
<ypad>0</ypad>
|
||||
<child>
|
||||
<left_attach>2</left_attach>
|
||||
<right_attach>3</right_attach>
|
||||
<top_attach>4</top_attach>
|
||||
<bottom_attach>5</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>label4</name>
|
||||
<label>Small</label>
|
||||
<justify>GTK_JUSTIFY_CENTER</justify>
|
||||
<wrap>False</wrap>
|
||||
<xalign>1</xalign>
|
||||
<yalign>0.5</yalign>
|
||||
<xpad>0</xpad>
|
||||
<ypad>0</ypad>
|
||||
<child>
|
||||
<left_attach>0</left_attach>
|
||||
<right_attach>1</right_attach>
|
||||
<top_attach>4</top_attach>
|
||||
<bottom_attach>5</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>
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
|
||||
</GTK-Interface>
|
387
capplets/mouse/preferences.c
Normal file
387
capplets/mouse/preferences.c
Normal file
|
@ -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 <hovinen@helixcode.com>,
|
||||
* Jonathan Blandford <jrb@redhat.com>,
|
||||
* Tom Tromey <tromey@cygnus.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 <X11/Xlib.h>
|
||||
#include <gdk/gdkx.h>
|
||||
|
||||
#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;
|
||||
}
|
73
capplets/mouse/preferences.h
Normal file
73
capplets/mouse/preferences.h
Normal file
|
@ -0,0 +1,73 @@
|
|||
/* -*- 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;
|
||||
|
||||
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 */
|
319
capplets/mouse/prefs-widget.c
Normal file
319
capplets/mouse/prefs-widget.c
Normal file
|
@ -0,0 +1,319 @@
|
|||
/* -*- 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 <gdk-pixbuf/gdk-pixbuf.h>
|
||||
|
||||
#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);
|
||||
}
|
60
capplets/mouse/prefs-widget.h
Normal file
60
capplets/mouse/prefs-widget.h
Normal 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 */
|
Loading…
Add table
Add a link
Reference in a new issue