converted more modules to the new arch.

2007-06-06  Rodrigo Moya <rodrigo@gnome-db.org>

	* gnome-settings-default-editor.c:
	* gnome-settings-gtk1theme.c:
	* gnome-settings-mouse.c:
	* gnome-settings-sound.c:
	* gnome-settings-xsettings.c: converted more modules to the new arch.

	* gnome-settings-daemon.c (gnome_settings_daemon_new): now this is much
	cleaner.

svn path=/trunk/; revision=7697
This commit is contained in:
Rodrigo Moya 2007-06-06 11:51:40 +00:00 committed by Rodrigo Moya
parent 6bfc75101d
commit ff9f268fff
13 changed files with 1032 additions and 865 deletions

View file

@ -1,3 +1,14 @@
2007-06-06 Rodrigo Moya <rodrigo@gnome-db.org>
* gnome-settings-default-editor.c:
* gnome-settings-gtk1theme.c:
* gnome-settings-mouse.c:
* gnome-settings-sound.c:
* gnome-settings-xsettings.c: converted more modules to the new arch.
* gnome-settings-daemon.c (gnome_settings_daemon_new): now this is much
cleaner.
2007-06-05 Rodrigo Moya <rodrigo@gnome-db.org> 2007-06-05 Rodrigo Moya <rodrigo@gnome-db.org>
* gnome-settings-font.c: * gnome-settings-font.c:

View file

@ -29,10 +29,8 @@ gnome_settings_daemon_SOURCES = \
gnome-settings-dbus.c \ gnome-settings-dbus.c \
gnome-settings-dbus.h \ gnome-settings-dbus.h \
gnome-settings-default-editor.c \ gnome-settings-default-editor.c \
gnome-settings-default-editor.h \
gnome-settings-font.c \ gnome-settings-font.c \
gnome-settings-gtk1theme.c \ gnome-settings-gtk1theme.c \
gnome-settings-gtk1theme.h \
gnome-settings-keybindings.c \ gnome-settings-keybindings.c \
gnome-settings-keybindings.h \ gnome-settings-keybindings.h \
gnome-settings-keyboard-xkb.h \ gnome-settings-keyboard-xkb.h \
@ -43,14 +41,12 @@ gnome_settings_daemon_SOURCES = \
gnome-settings-locate-pointer.h \ gnome-settings-locate-pointer.h \
gnome-settings-module.c \ gnome-settings-module.c \
gnome-settings-module.h \ gnome-settings-module.h \
gnome-settings-mouse.h \
gnome-settings-mouse.c \ gnome-settings-mouse.c \
gnome-settings-multimedia-keys.h \ gnome-settings-multimedia-keys.h \
gnome-settings-multimedia-keys.c \ gnome-settings-multimedia-keys.c \
gnome-settings-screensaver.c \ gnome-settings-screensaver.c \
gnome-settings-server.h \ gnome-settings-server.h \
gnome-settings-sound.c \ gnome-settings-sound.c \
gnome-settings-sound.h \
gnome-settings-typing-break.c \ gnome-settings-typing-break.c \
gnome-settings-typing-break.h \ gnome-settings-typing-break.h \
gnome-settings-xmodmap.c \ gnome-settings-xmodmap.c \

View file

@ -36,16 +36,11 @@
#include "gnome-settings-xmodmap.h" #include "gnome-settings-xmodmap.h"
/*#include "gnome-settings-disk.h"*/ /*#include "gnome-settings-disk.h"*/
#include "gnome-settings-xsettings.h"
#include "gnome-settings-mouse.h"
#include "gnome-settings-keyboard-xkb.h" #include "gnome-settings-keyboard-xkb.h"
#include "gnome-settings-keyboard.h" #include "gnome-settings-keyboard.h"
#include "gnome-settings-sound.h"
#include "gnome-settings-accessibility-keyboard.h" #include "gnome-settings-accessibility-keyboard.h"
#include "gnome-settings-default-editor.h"
#include "gnome-settings-keybindings.h" #include "gnome-settings-keybindings.h"
#include "gnome-settings-multimedia-keys.h" #include "gnome-settings-multimedia-keys.h"
#include "gnome-settings-gtk1theme.h"
#include "gnome-settings-xrdb.h" #include "gnome-settings-xrdb.h"
#include "gnome-settings-typing-break.h" #include "gnome-settings-typing-break.h"
@ -55,8 +50,13 @@ struct _GnomeSettingsDaemonPrivate {
GType gnome_settings_module_background_get_type (void); GType gnome_settings_module_background_get_type (void);
GType gnome_settings_module_clipboard_get_type (void); GType gnome_settings_module_clipboard_get_type (void);
GType gnome_settings_module_default_editor_get_type (void);
GType gnome_settings_module_font_get_type (void); GType gnome_settings_module_font_get_type (void);
GType gnome_settings_module_gtk1_get_type (void);
GType gnome_settings_module_mouse_get_type (void);
GType gnome_settings_module_screensaver_get_type (void); GType gnome_settings_module_screensaver_get_type (void);
GType gnome_settings_module_sound_get_type (void);
GType gnome_settings_module_xsettings_get_type (void);
static GObjectClass *parent_class = NULL; static GObjectClass *parent_class = NULL;
XSettingsManager **managers = NULL; XSettingsManager **managers = NULL;
@ -186,8 +186,13 @@ gnome_settings_daemon_init (GnomeSettingsDaemon *settings)
/* register all internal modules types */ /* register all internal modules types */
if (!gnome_settings_module_background_get_type () if (!gnome_settings_module_background_get_type ()
|| !gnome_settings_module_clipboard_get_type () || !gnome_settings_module_clipboard_get_type ()
|| !gnome_settings_module_default_editor_get_type ()
|| !gnome_settings_module_font_get_type () || !gnome_settings_module_font_get_type ()
|| !gnome_settings_module_screensaver_get_type ()) || !gnome_settings_module_gtk1_get_type ()
|| !gnome_settings_module_mouse_get_type ()
|| !gnome_settings_module_screensaver_get_type ()
|| !gnome_settings_module_sound_get_type ()
|| !gnome_settings_module_xsettings_get_type ())
return; return;
/* create hash table for loaded modules */ /* create hash table for loaded modules */
@ -271,19 +276,14 @@ gnome_settings_daemon_new (void)
client = gnome_settings_get_config_client (); client = gnome_settings_get_config_client ();
/* gnome_settings_disk_init (client);*/ /* gnome_settings_disk_init (client);*/
gnome_settings_xsettings_init (client);
gnome_settings_mouse_init (client);
/* Essential - xkb initialization should happen before */ /* Essential - xkb initialization should happen before */
gnome_settings_keyboard_xkb_set_post_activation_callback ((PostActivationCallback) gnome_settings_load_modmap_files, NULL); gnome_settings_keyboard_xkb_set_post_activation_callback ((PostActivationCallback) gnome_settings_load_modmap_files, NULL);
gnome_settings_keyboard_xkb_init (client); gnome_settings_keyboard_xkb_init (client);
gnome_settings_keyboard_init (client); gnome_settings_keyboard_init (client);
gnome_settings_multimedia_keys_init (client); gnome_settings_multimedia_keys_init (client);
/* */ /* */
gnome_settings_sound_init (client);
gnome_settings_accessibility_keyboard_init (client); gnome_settings_accessibility_keyboard_init (client);
gnome_settings_default_editor_init (client);
gnome_settings_keybindings_init (client); gnome_settings_keybindings_init (client);
gnome_settings_gtk1_theme_init (client);
gnome_settings_xrdb_init (client); gnome_settings_xrdb_init (client);
gnome_settings_typing_break_init (client); gnome_settings_typing_break_init (client);
@ -303,18 +303,13 @@ gnome_settings_daemon_new (void)
} }
/* gnome_settings_disk_load (client);*/ /* gnome_settings_disk_load (client);*/
gnome_settings_xsettings_load (client);
gnome_settings_mouse_load (client);
/* Essential - xkb initialization should happen before */ /* Essential - xkb initialization should happen before */
gnome_settings_keyboard_xkb_load (client); gnome_settings_keyboard_xkb_load (client);
gnome_settings_keyboard_load (client); gnome_settings_keyboard_load (client);
gnome_settings_multimedia_keys_load (client); gnome_settings_multimedia_keys_load (client);
/* */ /* */
gnome_settings_sound_load (client);
gnome_settings_accessibility_keyboard_load (client); gnome_settings_accessibility_keyboard_load (client);
gnome_settings_default_editor_load (client);
gnome_settings_keybindings_load (client); gnome_settings_keybindings_load (client);
gnome_settings_gtk1_theme_load (client);
gnome_settings_xrdb_load (client); gnome_settings_xrdb_load (client);
gnome_settings_typing_break_load (client); gnome_settings_typing_break_load (client);

View file

@ -18,20 +18,83 @@
#include <config.h> #include <config.h>
#include "gnome-settings-daemon.h" #include "gnome-settings-module.h"
#include "gnome-settings-default-editor.h" #include "utils.h"
#include <libgnomevfs/gnome-vfs-mime-handlers.h> #include <libgnomevfs/gnome-vfs-mime-handlers.h>
#include <libgnomevfs/gnome-vfs-mime-monitor.h> #include <libgnomevfs/gnome-vfs-mime-monitor.h>
#include <string.h> #include <string.h>
typedef struct {
GnomeSettingsModule parent;
} GnomeSettingsModuleDefaultEditor;
typedef struct {
GnomeSettingsModuleClass parent_class;
} GnomeSettingsModuleDefaultEditorClass;
static GnomeSettingsModuleRunlevel gnome_settings_module_default_editor_get_runlevel (GnomeSettingsModule *module);
static gboolean gnome_settings_module_default_editor_initialize (GnomeSettingsModule *module,
GConfClient *config_client);
static gboolean gnome_settings_module_default_editor_start (GnomeSettingsModule *module);
static gboolean gnome_settings_module_default_editor_stop (GnomeSettingsModule *module);
/* #define DE_DEBUG */ /* #define DE_DEBUG */
#define SYNC_CHANGES_KEY "/apps/gnome_settings_daemon/default_editor/sync_text_types" #define SYNC_CHANGES_KEY "/apps/gnome_settings_daemon/default_editor/sync_text_types"
static gboolean sync_changes; static gboolean sync_changes;
static void
gnome_settings_module_default_editor_class_init (GnomeSettingsModuleDefaultEditorClass *klass)
{
GnomeSettingsModuleClass *module_class;
module_class = (GnomeSettingsModuleClass *) klass;
module_class->get_runlevel = gnome_settings_module_default_editor_get_runlevel;
module_class->initialize = gnome_settings_module_default_editor_initialize;
module_class->start = gnome_settings_module_default_editor_start;
module_class->stop = gnome_settings_module_default_editor_stop;
}
static void
gnome_settings_module_default_editor_init (GnomeSettingsModuleDefaultEditor *module)
{
}
GType
gnome_settings_module_default_editor_get_type (void)
{
static GType module_type = 0;
if (!module_type) {
static const GTypeInfo module_info = {
sizeof (GnomeSettingsModuleDefaultEditorClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) gnome_settings_module_default_editor_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GnomeSettingsModuleDefaultEditor),
0, /* n_preallocs */
(GInstanceInitFunc) gnome_settings_module_default_editor_init,
};
module_type = g_type_register_static (GNOME_SETTINGS_TYPE_MODULE,
"GnomeSettingsModuleDefaultEditor",
&module_info, 0);
}
return module_type;
}
static GnomeSettingsModuleRunlevel
gnome_settings_module_default_editor_get_runlevel (GnomeSettingsModule *module)
{
return GNOME_SETTINGS_MODULE_RUNLEVEL_GNOME_SETTINGS;
}
#ifdef DE_DEBUG #ifdef DE_DEBUG
static void static void
print_mime_app (const char *mime_type) print_mime_app (const char *mime_type)
@ -120,19 +183,29 @@ vfs_change_cb (GnomeVFSMIMEMonitor *monitor, GConfClient *client)
PRINT_STATE; PRINT_STATE;
} }
void static gboolean
gnome_settings_default_editor_init (GConfClient *client) gnome_settings_module_default_editor_initialize (GnomeSettingsModule *module, GConfClient *config_client)
{ {
sync_changes = gconf_client_get_bool (client, SYNC_CHANGES_KEY, NULL); sync_changes = gconf_client_get_bool (config_client, SYNC_CHANGES_KEY, NULL);
gnome_settings_register_config_callback (SYNC_CHANGES_KEY, sync_changes_cb); gnome_settings_register_config_callback (SYNC_CHANGES_KEY, sync_changes_cb);
g_signal_connect (gnome_vfs_mime_monitor_get (), "data_changed", g_signal_connect (gnome_vfs_mime_monitor_get (), "data_changed",
G_CALLBACK (vfs_change_cb), client); G_CALLBACK (vfs_change_cb), config_client);
return TRUE;
} }
void static gboolean
gnome_settings_default_editor_load (GConfClient *client) gnome_settings_module_default_editor_start (GnomeSettingsModule *module)
{ {
vfs_change_cb (NULL, client); vfs_change_cb (NULL, gnome_settings_module_get_config_client (module));
return TRUE;
}
static gboolean
gnome_settings_module_default_editor_stop (GnomeSettingsModule *module)
{
return TRUE;
} }

View file

@ -1,18 +0,0 @@
/*
* gnome-settings-default-editor.h: sync default editor changes to mime database
*
* Copyright 2002 Sun Microsystems, Inc.
*
* Author: jacob berkman <jacob@ximian.com>
*
*/
#ifndef GNOME_SETTINGS_DEFAULT_EDITOR_H
#define GNOME_SETTINGS_DEFAULT_EDITOR_H
#include <gconf/gconf-client.h>
void gnome_settings_default_editor_init (GConfClient *client);
void gnome_settings_default_editor_load (GConfClient *client);
#endif /* GNOME_SETTINGS_DEFAULT_EDITOR_H */

View file

@ -27,11 +27,74 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include "gnome-settings-daemon.h" #include <gdk/gdkx.h>
#include "gnome-settings-gtk1theme.h" #include "gnome-settings-module.h"
#include "utils.h"
#define GTK_THEME_KEY "/desktop/gnome/interface/gtk_theme" #define GTK_THEME_KEY "/desktop/gnome/interface/gtk_theme"
typedef struct {
GnomeSettingsModule parent;
} GnomeSettingsModuleGtk1;
typedef struct {
GnomeSettingsModuleClass parent_class;
} GnomeSettingsModuleGtk1Class;
static GnomeSettingsModuleRunlevel gnome_settings_module_gtk1_get_runlevel (GnomeSettingsModule *module);
static gboolean gnome_settings_module_gtk1_initialize (GnomeSettingsModule *module, GConfClient *config_client);
static gboolean gnome_settings_module_gtk1_start (GnomeSettingsModule *module);
static gboolean gnome_settings_module_gtk1_stop (GnomeSettingsModule *module);
static void
gnome_settings_module_gtk1_class_init (GnomeSettingsModuleGtk1Class *klass)
{
GnomeSettingsModuleClass *module_class;
module_class = (GnomeSettingsModuleClass *) klass;
module_class->get_runlevel = gnome_settings_module_gtk1_get_runlevel;
module_class->initialize = gnome_settings_module_gtk1_initialize;
module_class->start = gnome_settings_module_gtk1_start;
module_class->stop = gnome_settings_module_gtk1_stop;
}
static void
gnome_settings_module_gtk1_init (GnomeSettingsModuleGtk1 *module)
{
}
GType
gnome_settings_module_gtk1_get_type (void)
{
static GType module_type = 0;
if (!module_type) {
static const GTypeInfo module_info = {
sizeof (GnomeSettingsModuleGtk1Class),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) gnome_settings_module_gtk1_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GnomeSettingsModuleGtk1),
0, /* n_preallocs */
(GInstanceInitFunc) gnome_settings_module_gtk1_init,
};
module_type = g_type_register_static (GNOME_SETTINGS_TYPE_MODULE,
"GnomeSettingsModuleGtk1",
&module_info, 0);
}
return module_type;
}
static GnomeSettingsModuleRunlevel
gnome_settings_module_gtk1_get_runlevel (GnomeSettingsModule *module)
{
return GNOME_SETTINGS_MODULE_RUNLEVEL_GNOME_SETTINGS;
}
/* Given the theme filename, return the needed contents for the RC file /* Given the theme filename, return the needed contents for the RC file
* in the user's home directory * in the user's home directory
*/ */
@ -208,15 +271,25 @@ apply_settings (void)
g_free (rc_filename); g_free (rc_filename);
} }
void static gboolean
gnome_settings_gtk1_theme_init (GConfClient *client) gnome_settings_module_gtk1_initialize (GnomeSettingsModule *module, GConfClient *config_client)
{ {
gnome_settings_register_config_callback (GTK_THEME_KEY, gnome_settings_register_config_callback (GTK_THEME_KEY,
(GnomeSettingsConfigCallback) apply_settings); (GnomeSettingsConfigCallback) apply_settings);
return TRUE;
} }
void static gboolean
gnome_settings_gtk1_theme_load (GConfClient *client) gnome_settings_module_gtk1_start (GnomeSettingsModule *module)
{ {
apply_settings (); apply_settings ();
return TRUE;
}
static gboolean
gnome_settings_module_gtk1_stop (GnomeSettingsModule *module)
{
return TRUE;
} }

View file

@ -1,34 +0,0 @@
/* -*- mode: c; style: linux -*- */
/* gnome-settings-keyboard.h
*
* Copyright © 2002 Red Hat, Inc.
*
* Written by Owen Taylor <otaylor@redhat.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 __GNOME_SETTINGS_GTK1THEME_H
#define __GNOME_SETTINGS_GTK1THEME_H
#include <gconf/gconf.h>
#include <gconf/gconf-client.h>
void gnome_settings_gtk1_theme_init (GConfClient *client);
void gnome_settings_gtk1_theme_load (GConfClient *client);
#endif

View file

@ -14,18 +14,79 @@
#include <gconf/gconf.h> #include <gconf/gconf.h>
#include "gnome-settings-mouse.h"
#include "gnome-settings-locate-pointer.h" #include "gnome-settings-locate-pointer.h"
#include "gnome-settings-daemon.h" #include "gnome-settings-module.h"
typedef struct {
GnomeSettingsModule parent;
} GnomeSettingsModuleMouse;
typedef struct {
GnomeSettingsModuleClass parent_class;
} GnomeSettingsModuleMouseClass;
static GnomeSettingsModuleRunlevel gnome_settings_module_mouse_get_runlevel (GnomeSettingsModule *module);
static gboolean gnome_settings_module_mouse_initialize (GnomeSettingsModule *module, GConfClient *config_client);
static gboolean gnome_settings_module_mouse_start (GnomeSettingsModule *module);
static gboolean gnome_settings_module_mouse_stop (GnomeSettingsModule *module);
static void
gnome_settings_module_mouse_class_init (GnomeSettingsModuleMouseClass *klass)
{
GnomeSettingsModuleClass *module_class;
module_class = (GnomeSettingsModuleClass *) klass;
module_class->get_runlevel = gnome_settings_module_mouse_get_runlevel;
module_class->initialize = gnome_settings_module_mouse_initialize;
module_class->start = gnome_settings_module_mouse_start;
module_class->stop = gnome_settings_module_mouse_stop;
}
static void
gnome_settings_module_mouse_init (GnomeSettingsModuleMouse *module)
{
}
GType
gnome_settings_module_mouse_get_type (void)
{
static GType module_type = 0;
if (!module_type) {
static const GTypeInfo module_info = {
sizeof (GnomeSettingsModuleMouseClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) gnome_settings_module_mouse_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GnomeSettingsModuleMouse),
0, /* n_preallocs */
(GInstanceInitFunc) gnome_settings_module_mouse_init,
};
module_type = g_type_register_static (GNOME_SETTINGS_TYPE_MODULE,
"GnomeSettingsModuleMouse",
&module_info, 0);
}
return module_type;
}
static GnomeSettingsModuleRunlevel
gnome_settings_module_mouse_get_runlevel (GnomeSettingsModule *module)
{
return GNOME_SETTINGS_MODULE_RUNLEVEL_XSETTINGS;
}
#ifdef HAVE_XINPUT #ifdef HAVE_XINPUT
static gboolean static gboolean
supports_xinput_devices (void) supports_xinput_devices (void)
{ {
gint op_code, event, error; gint op_code, event, error;
return XQueryExtension (GDK_DISPLAY (), "XInputExtension", return XQueryExtension (GDK_DISPLAY (), "XInputExtension",
&op_code, &event, &error); &op_code, &event, &error);
} }
#endif #endif
@ -34,241 +95,217 @@ configure_button_layout (guchar *buttons,
gint n_buttons, gint n_buttons,
gboolean left_handed) gboolean left_handed)
{ {
const gint left_button = 1; const gint left_button = 1;
gint right_button; gint right_button;
gint i; gint i;
/* if the button is higher than 2 (3rd button) then it's /* if the button is higher than 2 (3rd button) then it's
* probably one direction of a scroll wheel or something else * probably one direction of a scroll wheel or something else
* uninteresting * uninteresting
*/ */
right_button = MIN (n_buttons, 3); right_button = MIN (n_buttons, 3);
/* If we change things we need to make sure we only swap buttons. /* If we change things we need to make sure we only swap buttons.
* If we end up with multiple physical buttons assigned to the same * If we end up with multiple physical buttons assigned to the same
* logical button the server will complain. This code assumes physical * logical button the server will complain. This code assumes physical
* button 0 is the physical left mouse button, and that the physical * button 0 is the physical left mouse button, and that the physical
* button other than 0 currently assigned left_button or right_button * button other than 0 currently assigned left_button or right_button
* is the physical right mouse button. * is the physical right mouse button.
*/ */
/* check if the current mapping satisfies the above assumptions */ /* check if the current mapping satisfies the above assumptions */
if (buttons[left_button - 1] != left_button && if (buttons[left_button - 1] != left_button &&
buttons[left_button - 1] != right_button) buttons[left_button - 1] != right_button)
/* The current mapping is weird. Swapping buttons is probably not a /* The current mapping is weird. Swapping buttons is probably not a
* good idea. * good idea.
*/ */
return; return;
/* check if we are left_handed and currently not swapped */ /* check if we are left_handed and currently not swapped */
if (left_handed && buttons[left_button - 1] == left_button) if (left_handed && buttons[left_button - 1] == left_button) {
{ /* find the right button */
/* find the right button */ for (i = 0; i < n_buttons; i++) {
for (i = 0; i < n_buttons; i++) if (buttons[i] == right_button) {
{ buttons[i] = left_button;
if (buttons[i] == right_button) break;
{ }
buttons[i] = left_button; }
break; /* swap the buttons */
} buttons[left_button - 1] = right_button;
} }
/* swap the buttons */ /* check if we are not left_handed but are swapped */
buttons[left_button - 1] = right_button; else if (!left_handed && buttons[left_button - 1] == right_button) {
} /* find the right button */
/* check if we are not left_handed but are swapped */ for (i = 0; i < n_buttons; i++) {
else if (!left_handed && buttons[left_button - 1] == right_button) if (buttons[i] == left_button) {
{ buttons[i] = right_button;
/* find the right button */ break;
for (i = 0; i < n_buttons; i++) }
{ }
if (buttons[i] == left_button) /* swap the buttons */
{ buttons[left_button - 1] = left_button;
buttons[i] = right_button; }
break;
}
}
/* swap the buttons */
buttons[left_button - 1] = left_button;
}
} }
#ifdef HAVE_XINPUT #ifdef HAVE_XINPUT
static gboolean static gboolean
xinput_device_has_buttons (XDeviceInfo *device_info) xinput_device_has_buttons (XDeviceInfo *device_info)
{ {
int i; int i;
XAnyClassInfo *class_info; XAnyClassInfo *class_info;
class_info = device_info->inputclassinfo; class_info = device_info->inputclassinfo;
for (i = 0; i < device_info->num_classes; i++) for (i = 0; i < device_info->num_classes; i++) {
{ if (class_info->class == ButtonClass) {
if (class_info->class == ButtonClass) XButtonInfo *button_info;
{
XButtonInfo *button_info;
button_info = (XButtonInfo *) class_info; button_info = (XButtonInfo *) class_info;
if (button_info->num_buttons > 0) if (button_info->num_buttons > 0)
return TRUE; return TRUE;
} }
class_info = (XAnyClassInfo *) (((guchar *) class_info) + class_info = (XAnyClassInfo *) (((guchar *) class_info) +
class_info->length); class_info->length);
} }
return FALSE; return FALSE;
} }
static void static void
set_xinput_devices_left_handed (gboolean left_handed) set_xinput_devices_left_handed (gboolean left_handed)
{ {
XDeviceInfo *device_info; XDeviceInfo *device_info;
gint n_devices; gint n_devices;
guchar *buttons; guchar *buttons;
gsize buttons_capacity = 16; gsize buttons_capacity = 16;
gint n_buttons; gint n_buttons;
gint i; gint i;
device_info = XListInputDevices (GDK_DISPLAY (), &n_devices); device_info = XListInputDevices (GDK_DISPLAY (), &n_devices);
if (n_devices > 0) if (n_devices > 0)
buttons = g_new (guchar, buttons_capacity); buttons = g_new (guchar, buttons_capacity);
else else
buttons = NULL; buttons = NULL;
for (i = 0; i < n_devices; i++) for (i = 0; i < n_devices; i++) {
{ XDevice *device = NULL;
XDevice *device = NULL;
if ((device_info[i].use != IsXExtensionDevice) || if ((device_info[i].use != IsXExtensionDevice) ||
(!xinput_device_has_buttons (&device_info[i]))) (!xinput_device_has_buttons (&device_info[i])))
continue; continue;
gdk_error_trap_push (); gdk_error_trap_push ();
device = XOpenDevice (GDK_DISPLAY (), device_info[i].id); device = XOpenDevice (GDK_DISPLAY (), device_info[i].id);
if ((gdk_error_trap_pop () != 0) || if ((gdk_error_trap_pop () != 0) ||
(device == NULL)) (device == NULL))
continue; continue;
n_buttons = XGetDeviceButtonMapping (GDK_DISPLAY (), device, n_buttons = XGetDeviceButtonMapping (GDK_DISPLAY (), device,
buttons, buttons,
buttons_capacity); buttons_capacity);
while (n_buttons > buttons_capacity) while (n_buttons > buttons_capacity) {
{ buttons_capacity = n_buttons;
buttons_capacity = n_buttons; buttons = (guchar *) g_realloc (buttons,
buttons = (guchar *) g_realloc (buttons, buttons_capacity * sizeof (guchar));
buttons_capacity * sizeof (guchar));
n_buttons = XGetDeviceButtonMapping (GDK_DISPLAY (), device, n_buttons = XGetDeviceButtonMapping (GDK_DISPLAY (), device,
buttons, buttons,
buttons_capacity); buttons_capacity);
} }
configure_button_layout (buttons, n_buttons, left_handed); configure_button_layout (buttons, n_buttons, left_handed);
XSetDeviceButtonMapping (GDK_DISPLAY (), device, buttons, n_buttons); XSetDeviceButtonMapping (GDK_DISPLAY (), device, buttons, n_buttons);
XCloseDevice (GDK_DISPLAY (), device); XCloseDevice (GDK_DISPLAY (), device);
} }
g_free (buttons); g_free (buttons);
if (device_info != NULL) if (device_info != NULL)
XFreeDeviceList (device_info); XFreeDeviceList (device_info);
} }
#endif #endif
static void static void
set_left_handed (gboolean left_handed) set_left_handed (gboolean left_handed)
{ {
guchar *buttons ; guchar *buttons ;
gsize buttons_capacity = 16; gsize buttons_capacity = 16;
gint n_buttons, i; gint n_buttons, i;
#ifdef HAVE_XINPUT #ifdef HAVE_XINPUT
if (supports_xinput_devices ()) if (supports_xinput_devices ())
set_xinput_devices_left_handed (left_handed); set_xinput_devices_left_handed (left_handed);
#endif #endif
buttons = g_new (guchar, buttons_capacity); buttons = g_new (guchar, buttons_capacity);
n_buttons = XGetPointerMapping (GDK_DISPLAY (), buttons, n_buttons = XGetPointerMapping (GDK_DISPLAY (), buttons,
(gint) buttons_capacity); (gint) buttons_capacity);
while (n_buttons > buttons_capacity) while (n_buttons > buttons_capacity) {
{ buttons_capacity = n_buttons;
buttons_capacity = n_buttons; buttons = (guchar *) g_realloc (buttons,
buttons = (guchar *) g_realloc (buttons, buttons_capacity * sizeof (guchar));
buttons_capacity * sizeof (guchar));
n_buttons = XGetPointerMapping (GDK_DISPLAY (), buttons, n_buttons = XGetPointerMapping (GDK_DISPLAY (), buttons,
(gint) buttons_capacity); (gint) buttons_capacity);
} }
configure_button_layout (buttons, n_buttons, left_handed); configure_button_layout (buttons, n_buttons, left_handed);
/* X refuses to change the mapping while buttons are engaged, /* X refuses to change the mapping while buttons are engaged,
* so if this is the case we'll retry a few times * so if this is the case we'll retry a few times
*/ */
for (i = 0; i < 20 && for (i = 0;
XSetPointerMapping (GDK_DISPLAY (), buttons, n_buttons) == MappingBusy; i < 20 && XSetPointerMapping (GDK_DISPLAY (), buttons, n_buttons) == MappingBusy;
++i) ++i) {
{ g_usleep (300);
g_usleep (300); }
}
g_free (buttons); g_free (buttons);
} }
static void static void
set_motion_acceleration (gfloat motion_acceleration) set_motion_acceleration (gfloat motion_acceleration)
{ {
gint numerator, denominator; gint numerator, denominator;
if (motion_acceleration >= 1.0) if (motion_acceleration >= 1.0) {
{ /* we want to get the acceleration, with a resolution of 0.5
/* we want to get the acceleration, with a resolution of 0.5 */
*/ if ((motion_acceleration - floor (motion_acceleration)) < 0.25) {
if ((motion_acceleration - floor (motion_acceleration)) < 0.25) numerator = floor (motion_acceleration);
{ denominator = 1;
numerator = floor (motion_acceleration); } else if ((motion_acceleration - floor (motion_acceleration)) < 0.5) {
denominator = 1; numerator = ceil (2.0 * motion_acceleration);
denominator = 2;
} else if ((motion_acceleration - floor (motion_acceleration)) < 0.75) {
numerator = floor (2.0 *motion_acceleration);
denominator = 2;
} else {
numerator = ceil (motion_acceleration);
denominator = 1;
}
} else if (motion_acceleration < 1.0 && motion_acceleration > 0) {
/* This we do to 1/10ths */
numerator = floor (motion_acceleration * 10) + 1;
denominator= 10;
} else {
numerator = -1;
denominator = -1;
} }
else if ((motion_acceleration - floor (motion_acceleration)) < 0.5)
{
numerator = ceil (2.0 * motion_acceleration);
denominator = 2;
}
else if ((motion_acceleration - floor (motion_acceleration)) < 0.75)
{
numerator = floor (2.0 *motion_acceleration);
denominator = 2;
}
else
{
numerator = ceil (motion_acceleration);
denominator = 1;
}
}
else if (motion_acceleration < 1.0 && motion_acceleration > 0)
{
/* This we do to 1/10ths */
numerator = floor (motion_acceleration * 10) + 1;
denominator= 10;
}
else
{
numerator = -1;
denominator = -1;
}
XChangePointerControl (GDK_DISPLAY (), True, False, XChangePointerControl (GDK_DISPLAY (), True, False,
numerator, denominator, numerator, denominator,
0); 0);
} }
static void static void
set_motion_threshold (gint motion_threshold) set_motion_threshold (gint motion_threshold)
{ {
XChangePointerControl (GDK_DISPLAY (), False, True, XChangePointerControl (GDK_DISPLAY (), False, True,
0, 0, motion_threshold); 0, 0, motion_threshold);
} }
@ -281,199 +318,189 @@ filter (GdkXEvent *xevent,
GdkEvent *event, GdkEvent *event,
gpointer data) gpointer data)
{ {
XEvent *xev = (XEvent *) xevent; XEvent *xev = (XEvent *) xevent;
guint keyval; guint keyval;
gint group; gint group;
GdkScreen *screen = (GdkScreen *)data; GdkScreen *screen = (GdkScreen *)data;
if (xev->type == KeyPress || if (xev->type == KeyPress ||
xev->type == KeyRelease) xev->type == KeyRelease) {
{ /* get the keysym */
/* get the keysym */ group = (xev->xkey.state & KEYBOARD_GROUP_MASK) >> KEYBOARD_GROUP_SHIFT;
group = (xev->xkey.state & KEYBOARD_GROUP_MASK) >> KEYBOARD_GROUP_SHIFT; gdk_keymap_translate_keyboard_state (gdk_keymap_get_default (),
gdk_keymap_translate_keyboard_state (gdk_keymap_get_default (), xev->xkey.keycode,
xev->xkey.keycode, xev->xkey.state,
xev->xkey.state, group,
group, &keyval,
&keyval, NULL, NULL, NULL);
NULL, NULL, NULL); if (keyval == GDK_Control_L || keyval == GDK_Control_R) {
if (keyval == GDK_Control_L || keyval == GDK_Control_R) if (xev->type == KeyPress) {
{ XAllowEvents (gdk_x11_get_default_xdisplay (),
if (xev->type == KeyPress) SyncKeyboard,
{ xev->xkey.time);
XAllowEvents (gdk_x11_get_default_xdisplay (), } else {
SyncKeyboard, XAllowEvents (gdk_x11_get_default_xdisplay (),
xev->xkey.time); AsyncKeyboard,
} xev->xkey.time);
else gnome_settings_locate_pointer (screen);
{ }
XAllowEvents (gdk_x11_get_default_xdisplay (), } else {
AsyncKeyboard, XAllowEvents (gdk_x11_get_default_xdisplay (),
xev->xkey.time); ReplayKeyboard,
gnome_settings_locate_pointer (screen); xev->xkey.time);
} XUngrabKeyboard (gdk_x11_get_default_xdisplay (),
} xev->xkey.time);
else }
{
XAllowEvents (gdk_x11_get_default_xdisplay (),
ReplayKeyboard,
xev->xkey.time);
XUngrabKeyboard (gdk_x11_get_default_xdisplay (),
xev->xkey.time);
}
return GDK_FILTER_REMOVE; return GDK_FILTER_REMOVE;
} }
return GDK_FILTER_CONTINUE; return GDK_FILTER_CONTINUE;
} }
static void static void
set_locate_pointer (gboolean locate_pointer) set_locate_pointer (gboolean locate_pointer)
{ {
GdkKeymapKey *keys; GdkKeymapKey *keys;
GdkDisplay *display; GdkDisplay *display;
int n_screens; int n_screens;
int n_keys; int n_keys;
gboolean has_entries; gboolean has_entries;
static const guint keyvals[] = { GDK_Control_L, GDK_Control_R }; static const guint keyvals[] = { GDK_Control_L, GDK_Control_R };
unsigned j; unsigned j;
display = gdk_display_get_default (); display = gdk_display_get_default ();
n_screens = gdk_display_get_n_screens (display); n_screens = gdk_display_get_n_screens (display);
for (j = 0 ; j < G_N_ELEMENTS (keyvals) ; j++) { for (j = 0 ; j < G_N_ELEMENTS (keyvals) ; j++) {
has_entries = gdk_keymap_get_entries_for_keyval (gdk_keymap_get_default (), has_entries = gdk_keymap_get_entries_for_keyval (gdk_keymap_get_default (),
keyvals[j], keyvals[j],
&keys, &keys,
&n_keys); &n_keys);
if (has_entries) if (has_entries) {
{ gint i, j;
gint i, j;
for (i = 0; i < n_keys; i++) for (i = 0; i < n_keys; i++) {
{ for(j=0; j< n_screens; j++) {
for(j=0; j< n_screens; j++) GdkScreen *screen = gdk_display_get_screen (display, j);
{ Window xroot = gdk_x11_drawable_get_xid (gdk_screen_get_root_window (screen));
GdkScreen *screen = gdk_display_get_screen (display, j);
Window xroot = gdk_x11_drawable_get_xid (gdk_screen_get_root_window (screen));
if (locate_pointer) if (locate_pointer) {
{ XGrabKey (GDK_DISPLAY_XDISPLAY (display),
XGrabKey (GDK_DISPLAY_XDISPLAY (display), keys[i].keycode,
keys[i].keycode, 0,
0, xroot,
xroot, False,
False, GrabModeAsync,
GrabModeAsync, GrabModeSync);
GrabModeSync); XGrabKey (GDK_DISPLAY_XDISPLAY (display),
XGrabKey (GDK_DISPLAY_XDISPLAY (display), keys[i].keycode,
keys[i].keycode, LockMask,
LockMask, xroot,
xroot, False,
False, GrabModeAsync,
GrabModeAsync, GrabModeSync);
GrabModeSync); XGrabKey (GDK_DISPLAY_XDISPLAY (display),
XGrabKey (GDK_DISPLAY_XDISPLAY (display), keys[i].keycode,
keys[i].keycode, Mod2Mask,
Mod2Mask, xroot,
xroot, False,
False, GrabModeAsync,
GrabModeAsync, GrabModeSync);
GrabModeSync); XGrabKey (GDK_DISPLAY_XDISPLAY (display),
XGrabKey (GDK_DISPLAY_XDISPLAY (display), keys[i].keycode,
keys[i].keycode, Mod4Mask,
Mod4Mask, xroot,
xroot, False,
False, GrabModeAsync,
GrabModeAsync, GrabModeSync);
GrabModeSync); } else {
} XUngrabKey (GDK_DISPLAY_XDISPLAY (display),
else keys[i].keycode,
{ Mod4Mask,
XUngrabKey (GDK_DISPLAY_XDISPLAY (display), xroot);
keys[i].keycode, XUngrabKey (GDK_DISPLAY_XDISPLAY (display),
Mod4Mask, keys[i].keycode,
xroot); Mod2Mask,
XUngrabKey (GDK_DISPLAY_XDISPLAY (display), xroot);
keys[i].keycode, XUngrabKey (GDK_DISPLAY_XDISPLAY (display),
Mod2Mask, keys[i].keycode,
xroot); LockMask,
XUngrabKey (GDK_DISPLAY_XDISPLAY (display), xroot);
keys[i].keycode, XUngrabKey (GDK_DISPLAY_XDISPLAY (display),
LockMask, keys[i].keycode,
xroot); 0,
XUngrabKey (GDK_DISPLAY_XDISPLAY (display), xroot);
keys[i].keycode, }
0, }
xroot); }
} g_free (keys);
} if (locate_pointer) {
for (i = 0; i < n_screens; i++) {
GdkScreen *screen;
screen = gdk_display_get_screen (display, i);
gdk_window_add_filter (gdk_screen_get_root_window (screen),
filter,
screen);
}
} else {
for (i = 0; i < n_screens; i++) {
GdkScreen *screen;
screen = gdk_display_get_screen (display, i);
gdk_window_remove_filter (gdk_screen_get_root_window (screen),
filter,
screen);
}
}
}
} }
g_free (keys);
if (locate_pointer)
{
for (i = 0; i < n_screens; i++)
{
GdkScreen *screen;
screen = gdk_display_get_screen (display, i);
gdk_window_add_filter (gdk_screen_get_root_window (screen),
filter,
screen);
}
}
else
{
for (i = 0; i < n_screens; i++)
{
GdkScreen *screen;
screen = gdk_display_get_screen (display, i);
gdk_window_remove_filter (gdk_screen_get_root_window (screen),
filter,
screen);
}
}
}
}
} }
static void static void
mouse_callback (GConfEntry *entry) mouse_callback (GConfEntry *entry)
{ {
if (! strcmp (entry->key, "/desktop/gnome/peripherals/mouse/left_handed")) if (! strcmp (entry->key, "/desktop/gnome/peripherals/mouse/left_handed")) {
{ if (entry->value->type == GCONF_VALUE_BOOL)
if (entry->value->type == GCONF_VALUE_BOOL) set_left_handed (gconf_value_get_bool (entry->value));
set_left_handed (gconf_value_get_bool (entry->value)); } else if (! strcmp (entry->key, "/desktop/gnome/peripherals/mouse/motion_acceleration")) {
} if (entry->value->type == GCONF_VALUE_FLOAT)
else if (! strcmp (entry->key, "/desktop/gnome/peripherals/mouse/motion_acceleration")) set_motion_acceleration (gconf_value_get_float (entry->value));
{ } else if (! strcmp (entry->key, "/desktop/gnome/peripherals/mouse/motion_threshold")) {
if (entry->value->type == GCONF_VALUE_FLOAT) if (entry->value->type == GCONF_VALUE_INT)
set_motion_acceleration (gconf_value_get_float (entry->value)); set_motion_threshold (gconf_value_get_int (entry->value));
} } else if (! strcmp (entry->key, "/desktop/gnome/peripherals/mouse/locate_pointer")) {
else if (! strcmp (entry->key, "/desktop/gnome/peripherals/mouse/motion_threshold")) if (entry->value->type == GCONF_VALUE_BOOL)
{ set_locate_pointer (gconf_value_get_bool (entry->value));
if (entry->value->type == GCONF_VALUE_INT) }
set_motion_threshold (gconf_value_get_int (entry->value));
}
else if (! strcmp (entry->key, "/desktop/gnome/peripherals/mouse/locate_pointer"))
{
if (entry->value->type == GCONF_VALUE_BOOL)
set_locate_pointer (gconf_value_get_bool (entry->value));
}
} }
void static gboolean
gnome_settings_mouse_init (GConfClient *client) gnome_settings_module_mouse_initialize (GnomeSettingsModule *module, GConfClient *config_client)
{ {
gnome_settings_register_config_callback ("/desktop/gnome/peripherals/mouse", mouse_callback); gnome_settings_register_config_callback ("/desktop/gnome/peripherals/mouse", mouse_callback);
return TRUE;
} }
void static gboolean
gnome_settings_mouse_load (GConfClient *client) gnome_settings_module_mouse_start (GnomeSettingsModule *module)
{ {
set_left_handed (gconf_client_get_bool (client, "/desktop/gnome/peripherals/mouse/left_handed", NULL)); GConfClient *client = gnome_settings_module_get_config_client (module);
set_motion_acceleration (gconf_client_get_float (client, "/desktop/gnome/peripherals/mouse/motion_acceleration", NULL));
set_motion_threshold (gconf_client_get_int (client, "/desktop/gnome/peripherals/mouse/motion_threshold", NULL)); set_left_handed (gconf_client_get_bool (client, "/desktop/gnome/peripherals/mouse/left_handed", NULL));
set_locate_pointer (gconf_client_get_bool (client, "/desktop/gnome/peripherals/mouse/locate_pointer", NULL)); set_motion_acceleration (gconf_client_get_float (client,
"/desktop/gnome/peripherals/mouse/motion_acceleration", NULL));
set_motion_threshold (gconf_client_get_int (client,
"/desktop/gnome/peripherals/mouse/motion_threshold", NULL));
set_locate_pointer (gconf_client_get_bool (client,
"/desktop/gnome/peripherals/mouse/locate_pointer", NULL));
return TRUE;
}
static gboolean
gnome_settings_module_mouse_stop (GnomeSettingsModule *module)
{
return TRUE;
} }

View file

@ -1,25 +0,0 @@
/*
* Copyright © 2001 Jonathan Blandford <jrb@gnome.org>
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation, and that the name of Red Hat not be used in advertising or
* publicity pertaining to distribution of the software without specific,
* written prior permission. Red Hat makes no representations about the
* suitability of this software for any purpose. It is provided "as is"
* without express or implied warranty.
*
* Authors: Jonathan Blandford
*/
#ifndef MOUSE_SETTINGS_H
#define MOUSE_SETTINGS_H
#include <gconf/gconf-client.h>
void gnome_settings_mouse_init (GConfClient *client);
void gnome_settings_mouse_load (GConfClient *client);
#endif

View file

@ -42,8 +42,70 @@
#include <libgnome/gnome-exec.h> #include <libgnome/gnome-exec.h>
#include <libgnomeui/gnome-client.h> #include <libgnomeui/gnome-client.h>
#include "libsounds/sound-properties.h" #include "libsounds/sound-properties.h"
#include "gnome-settings-sound.h" #include "gnome-settings-module.h"
#include "gnome-settings-daemon.h" #include "utils.h"
typedef struct {
GnomeSettingsModule parent;
} GnomeSettingsModuleSound;
typedef struct {
GnomeSettingsModuleClass parent_class;
} GnomeSettingsModuleSoundClass;
static GnomeSettingsModuleRunlevel gnome_settings_module_sound_get_runlevel (GnomeSettingsModule *module);
static gboolean gnome_settings_module_sound_initialize (GnomeSettingsModule *module, GConfClient *config_client);
static gboolean gnome_settings_module_sound_start (GnomeSettingsModule *module);
static gboolean gnome_settings_module_sound_stop (GnomeSettingsModule *module);
static void
gnome_settings_module_sound_class_init (GnomeSettingsModuleSoundClass *klass)
{
GnomeSettingsModuleClass *module_class;
module_class = (GnomeSettingsModuleClass *) klass;
module_class->get_runlevel = gnome_settings_module_sound_get_runlevel;
module_class->initialize = gnome_settings_module_sound_initialize;
module_class->start = gnome_settings_module_sound_start;
module_class->stop = gnome_settings_module_sound_stop;
}
static void
gnome_settings_module_sound_init (GnomeSettingsModuleSound *module)
{
}
GType
gnome_settings_module_sound_get_type (void)
{
static GType module_type = 0;
if (!module_type) {
static const GTypeInfo module_info = {
sizeof (GnomeSettingsModuleSoundClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) gnome_settings_module_sound_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GnomeSettingsModuleSound),
0, /* n_preallocs */
(GInstanceInitFunc) gnome_settings_module_sound_init,
};
module_type = g_type_register_static (GNOME_SETTINGS_TYPE_MODULE,
"GnomeSettingsModuleSound",
&module_info, 0);
}
return module_type;
}
static GnomeSettingsModuleRunlevel
gnome_settings_module_sound_get_runlevel (GnomeSettingsModule *module)
{
return GNOME_SETTINGS_MODULE_RUNLEVEL_GNOME_SETTINGS;
}
/* start_gnome_sound /* start_gnome_sound
* *
@ -179,14 +241,13 @@ apply_settings (void)
#endif #endif
} else { } else {
#ifdef HAVE_ESD #ifdef HAVE_ESD
if (!set_esd_standby) if (!set_esd_standby)
#endif #endif
stop_gnome_sound (); stop_gnome_sound ();
} }
if (enable_sound && if (enable_sound &&
(!inited || event_changed_old != event_changed_new)) (!inited || event_changed_old != event_changed_new)) {
{
SoundProperties *props; SoundProperties *props;
inited = TRUE; inited = TRUE;
@ -200,15 +261,27 @@ apply_settings (void)
} }
} }
void static gboolean
gnome_settings_sound_init (GConfClient *client) gnome_settings_module_sound_initialize (GnomeSettingsModule *module, GConfClient *config_client)
{ {
gnome_settings_register_config_callback ("/desktop/gnome/sound", gnome_settings_register_config_callback ("/desktop/gnome/sound",
(GnomeSettingsConfigCallback) apply_settings); (GnomeSettingsConfigCallback) apply_settings);
return TRUE;
} }
void static gboolean
gnome_settings_sound_load (GConfClient *client) gnome_settings_module_sound_start (GnomeSettingsModule *module)
{ {
apply_settings (); apply_settings ();
return TRUE;
}
static gboolean
gnome_settings_module_sound_stop (GnomeSettingsModule *module)
{
stop_gnome_sound ();
return TRUE;
} }

View file

@ -1,33 +0,0 @@
/* -*- mode: c; style: linux -*- */
/* gnome-settings-sound.h
*
* Copyright © 2001 Ximian, Inc.
*
* Written by Rachel Hestilow <hestilow@ximian.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*/
#ifndef __GNOME_SETTINGS_SOUND_H__
#define __GNOME_SETTINGS_SOUND_H__
#include <gconf/gconf.h>
void gnome_settings_sound_init (GConfClient *client);
void gnome_settings_sound_load (GConfClient *client);
#endif /* __GNOME_SETTINGS_SOUND_H__ */

View file

@ -1,14 +1,35 @@
/*
* Copyright (C) 2007 The GNOME Foundation
*
* Authors: Rodrigo Moya
*
* 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 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#include <config.h> #include <config.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <locale.h> #include <locale.h>
#include <glib.h>
#include <glib/gi18n.h> #include <glib/gi18n.h>
#include <gdk/gdkx.h>
#include <gconf/gconf-client.h> #include <gconf/gconf-client.h>
#include "gnome-settings-daemon.h" #include "gnome-settings-module.h"
#include "gnome-settings-xsettings.h"
#include "xsettings-manager.h" #include "xsettings-manager.h"
#include "utils.h"
extern XSettingsManager **managers; extern XSettingsManager **managers;
@ -23,15 +44,28 @@ extern XSettingsManager **managers;
typedef struct _TranslationEntry TranslationEntry; typedef struct _TranslationEntry TranslationEntry;
typedef void (* TranslationFunc) (TranslationEntry *trans, typedef void (* TranslationFunc) (TranslationEntry *trans,
GConfValue *value); GConfValue *value);
struct _TranslationEntry
{ struct _TranslationEntry {
const char *gconf_key; const char *gconf_key;
const char *xsetting_name; const char *xsetting_name;
GConfValueType gconf_type; GConfValueType gconf_type;
TranslationFunc translate; TranslationFunc translate;
}; };
typedef struct {
GnomeSettingsModule parent;
} GnomeSettingsModuleXSettings;
typedef struct {
GnomeSettingsModuleClass parent_class;
} GnomeSettingsModuleXSettingsClass;
static GnomeSettingsModuleRunlevel gnome_settings_module_xsettings_get_runlevel (GnomeSettingsModule *module);
static gboolean gnome_settings_module_xsettings_initialize (GnomeSettingsModule *module, GConfClient *config_client);
static gboolean gnome_settings_module_xsettings_start (GnomeSettingsModule *module);
static gboolean gnome_settings_module_xsettings_stop (GnomeSettingsModule *module);
#ifdef HAVE_XFT2 #ifdef HAVE_XFT2
/* X servers sometimes lie about the screen's physical dimensions, so we cannot /* X servers sometimes lie about the screen's physical dimensions, so we cannot
* compute an accurate DPI value. When this happens, the user gets fonts that * compute an accurate DPI value. When this happens, the user gets fonts that
@ -51,215 +85,258 @@ static void gnome_settings_update_xft (GConfClient *client);
static void xft_callback (GConfEntry *entry); static void xft_callback (GConfEntry *entry);
#endif /* HAVE_XFT2 */ #endif /* HAVE_XFT2 */
static void
gnome_settings_module_xsettings_class_init (GnomeSettingsModuleXSettingsClass *klass)
{
GnomeSettingsModuleClass *module_class;
module_class = (GnomeSettingsModuleClass *) klass;
module_class->get_runlevel = gnome_settings_module_xsettings_get_runlevel;
module_class->initialize = gnome_settings_module_xsettings_initialize;
module_class->start = gnome_settings_module_xsettings_start;
module_class->stop = gnome_settings_module_xsettings_stop;
}
static void
gnome_settings_module_xsettings_init (GnomeSettingsModuleXSettings *module)
{
}
GType
gnome_settings_module_xsettings_get_type (void)
{
static GType module_type = 0;
if (!module_type) {
static const GTypeInfo module_info = {
sizeof (GnomeSettingsModuleXSettingsClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) gnome_settings_module_xsettings_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GnomeSettingsModuleXSettings),
0, /* n_preallocs */
(GInstanceInitFunc) gnome_settings_module_xsettings_init,
};
module_type = g_type_register_static (GNOME_SETTINGS_TYPE_MODULE,
"GnomeSettingsModuleXSettings",
&module_info, 0);
}
return module_type;
}
static GnomeSettingsModuleRunlevel
gnome_settings_module_xsettings_get_runlevel (GnomeSettingsModule *module)
{
return GNOME_SETTINGS_MODULE_RUNLEVEL_SERVICES;
}
static void static void
translate_bool_int (TranslationEntry *trans, translate_bool_int (TranslationEntry *trans,
GConfValue *value) GConfValue *value)
{ {
int i; int i;
g_assert (value->type == trans->gconf_type); g_assert (value->type == trans->gconf_type);
for (i = 0; managers [i]; i++) for (i = 0; managers [i]; i++)
xsettings_manager_set_int (managers [i], trans->xsetting_name, xsettings_manager_set_int (managers [i], trans->xsetting_name,
gconf_value_get_bool (value)); gconf_value_get_bool (value));
} }
static void static void
translate_int_int (TranslationEntry *trans, translate_int_int (TranslationEntry *trans,
GConfValue *value) GConfValue *value)
{ {
int i; int i;
g_assert (value->type == trans->gconf_type); g_assert (value->type == trans->gconf_type);
for (i = 0; managers [i]; i++) for (i = 0; managers [i]; i++)
xsettings_manager_set_int (managers [i], trans->xsetting_name, xsettings_manager_set_int (managers [i], trans->xsetting_name,
gconf_value_get_int (value)); gconf_value_get_int (value));
} }
static void static void
translate_string_string (TranslationEntry *trans, translate_string_string (TranslationEntry *trans,
GConfValue *value) GConfValue *value)
{ {
int i; int i;
g_assert (value->type == trans->gconf_type); g_assert (value->type == trans->gconf_type);
for (i = 0; managers [i]; i++) for (i = 0; managers [i]; i++)
xsettings_manager_set_string (managers [i], xsettings_manager_set_string (managers [i],
trans->xsetting_name, trans->xsetting_name,
gconf_value_get_string (value)); gconf_value_get_string (value));
} }
static void static void
translate_string_string_toolbar (TranslationEntry *trans, translate_string_string_toolbar (TranslationEntry *trans,
GConfValue *value) GConfValue *value)
{ {
int i; int i;
const char *tmp; const char *tmp;
g_assert (value->type == trans->gconf_type); g_assert (value->type == trans->gconf_type);
/* This is kind of a workaround since GNOME expects the key value to be /* This is kind of a workaround since GNOME expects the key value to be
* "both_horiz" and gtk+ wants the XSetting to be "both-horiz". * "both_horiz" and gtk+ wants the XSetting to be "both-horiz".
*/ */
tmp = gconf_value_get_string (value); tmp = gconf_value_get_string (value);
if (tmp && strcmp (tmp, "both_horiz") == 0) if (tmp && strcmp (tmp, "both_horiz") == 0)
tmp = "both-horiz"; tmp = "both-horiz";
for (i = 0; managers [i]; i++) for (i = 0; managers [i]; i++)
xsettings_manager_set_string (managers [i], xsettings_manager_set_string (managers [i],
trans->xsetting_name, trans->xsetting_name,
tmp); tmp);
} }
static TranslationEntry translations [] = { static TranslationEntry translations [] = {
{ "/desktop/gnome/peripherals/mouse/double_click", "Net/DoubleClickTime", { "/desktop/gnome/peripherals/mouse/double_click", "Net/DoubleClickTime",
GCONF_VALUE_INT, translate_int_int }, GCONF_VALUE_INT, translate_int_int },
{ "/desktop/gnome/peripherals/mouse/drag_threshold", "Net/DndDragThreshold", { "/desktop/gnome/peripherals/mouse/drag_threshold", "Net/DndDragThreshold",
GCONF_VALUE_INT, translate_int_int }, GCONF_VALUE_INT, translate_int_int },
{ "/desktop/gnome/gtk-color-palette", "Gtk/ColorPalette", { "/desktop/gnome/gtk-color-palette", "Gtk/ColorPalette",
GCONF_VALUE_STRING, translate_string_string }, GCONF_VALUE_STRING, translate_string_string },
{ "/desktop/gnome/interface/font_name", "Gtk/FontName", { "/desktop/gnome/interface/font_name", "Gtk/FontName",
GCONF_VALUE_STRING, translate_string_string }, GCONF_VALUE_STRING, translate_string_string },
{ "/desktop/gnome/interface/gtk_key_theme", "Gtk/KeyThemeName", { "/desktop/gnome/interface/gtk_key_theme", "Gtk/KeyThemeName",
GCONF_VALUE_STRING, translate_string_string }, GCONF_VALUE_STRING, translate_string_string },
{ "/desktop/gnome/interface/toolbar_style", "Gtk/ToolbarStyle", { "/desktop/gnome/interface/toolbar_style", "Gtk/ToolbarStyle",
GCONF_VALUE_STRING, translate_string_string_toolbar }, GCONF_VALUE_STRING, translate_string_string_toolbar },
{ "/desktop/gnome/interface/toolbar_icon_size", "Gtk/ToolbarIconSize", { "/desktop/gnome/interface/toolbar_icon_size", "Gtk/ToolbarIconSize",
GCONF_VALUE_STRING, translate_string_string }, GCONF_VALUE_STRING, translate_string_string },
{ "/desktop/gnome/interface/can_change_accels", "Gtk/CanChangeAccels", { "/desktop/gnome/interface/can_change_accels", "Gtk/CanChangeAccels",
GCONF_VALUE_BOOL, translate_bool_int }, GCONF_VALUE_BOOL, translate_bool_int },
{ "/desktop/gnome/interface/cursor_blink", "Net/CursorBlink", { "/desktop/gnome/interface/cursor_blink", "Net/CursorBlink",
GCONF_VALUE_BOOL, translate_bool_int }, GCONF_VALUE_BOOL, translate_bool_int },
{ "/desktop/gnome/interface/cursor_blink_time", "Net/CursorBlinkTime", { "/desktop/gnome/interface/cursor_blink_time", "Net/CursorBlinkTime",
GCONF_VALUE_INT, translate_int_int }, GCONF_VALUE_INT, translate_int_int },
{ "/desktop/gnome/interface/gtk_theme", "Net/ThemeName", { "/desktop/gnome/interface/gtk_theme", "Net/ThemeName",
GCONF_VALUE_STRING, translate_string_string }, GCONF_VALUE_STRING, translate_string_string },
{ "/desktop/gnome/interface/gtk_color_scheme", "Gtk/ColorScheme", { "/desktop/gnome/interface/gtk_color_scheme", "Gtk/ColorScheme",
GCONF_VALUE_STRING, translate_string_string }, GCONF_VALUE_STRING, translate_string_string },
{ "/desktop/gnome/interface/gtk-im-preedit-style", "Gtk/IMPreeditStyle", { "/desktop/gnome/interface/gtk-im-preedit-style", "Gtk/IMPreeditStyle",
GCONF_VALUE_STRING, translate_string_string }, GCONF_VALUE_STRING, translate_string_string },
{ "/desktop/gnome/interface/gtk-im-status-style", "Gtk/IMStatusStyle", { "/desktop/gnome/interface/gtk-im-status-style", "Gtk/IMStatusStyle",
GCONF_VALUE_STRING, translate_string_string }, GCONF_VALUE_STRING, translate_string_string },
{ "/desktop/gnome/interface/icon_theme", "Net/IconThemeName", { "/desktop/gnome/interface/icon_theme", "Net/IconThemeName",
GCONF_VALUE_STRING, translate_string_string }, GCONF_VALUE_STRING, translate_string_string },
{ "/desktop/gnome/interface/file_chooser_backend", "Gtk/FileChooserBackend", { "/desktop/gnome/interface/file_chooser_backend", "Gtk/FileChooserBackend",
GCONF_VALUE_STRING, translate_string_string }, GCONF_VALUE_STRING, translate_string_string },
{ "/desktop/gnome/interface/menus_have_icons", "Gtk/MenuImages", { "/desktop/gnome/interface/menus_have_icons", "Gtk/MenuImages",
GCONF_VALUE_BOOL, translate_bool_int }, GCONF_VALUE_BOOL, translate_bool_int },
{ "/desktop/gnome/interface/menubar_accel", "Gtk/MenuBarAccel", { "/desktop/gnome/interface/menubar_accel", "Gtk/MenuBarAccel",
GCONF_VALUE_STRING, translate_string_string }, GCONF_VALUE_STRING, translate_string_string },
{ "/desktop/gnome/peripherals/mouse/cursor_theme", "Gtk/CursorThemeName", { "/desktop/gnome/peripherals/mouse/cursor_theme", "Gtk/CursorThemeName",
GCONF_VALUE_STRING, translate_string_string }, GCONF_VALUE_STRING, translate_string_string },
{ "/desktop/gnome/peripherals/mouse/cursor_size", "Gtk/CursorThemeSize", { "/desktop/gnome/peripherals/mouse/cursor_size", "Gtk/CursorThemeSize",
GCONF_VALUE_INT, translate_int_int }, GCONF_VALUE_INT, translate_int_int },
{ "/desktop/gnome/interface/show_input_method_menu", "Gtk/ShowInputMethodMenu", { "/desktop/gnome/interface/show_input_method_menu", "Gtk/ShowInputMethodMenu",
GCONF_VALUE_BOOL, translate_bool_int }, GCONF_VALUE_BOOL, translate_bool_int },
{ "/desktop/gnome/interface/show_unicode_menu", "Gtk/ShowUnicodeMenu", { "/desktop/gnome/interface/show_unicode_menu", "Gtk/ShowUnicodeMenu",
GCONF_VALUE_BOOL, translate_bool_int }, GCONF_VALUE_BOOL, translate_bool_int },
}; };
static TranslationEntry* static TranslationEntry*
find_translation_entry (const char *gconf_key) find_translation_entry (const char *gconf_key)
{ {
int i; int i;
i = 0; i = 0;
while (i < G_N_ELEMENTS (translations)) while (i < G_N_ELEMENTS (translations)) {
{ if (strcmp (translations[i].gconf_key, gconf_key) == 0)
if (strcmp (translations[i].gconf_key, gconf_key) == 0) return &translations[i];
return &translations[i];
++i; ++i;
} }
return NULL; return NULL;
} }
static const gchar* static const gchar*
type_to_string (GConfValueType type) type_to_string (GConfValueType type)
{ {
switch (type) switch (type) {
{ case GCONF_VALUE_INT:
case GCONF_VALUE_INT: return "int";
return "int"; case GCONF_VALUE_STRING:
case GCONF_VALUE_STRING: return "string";
return "string"; case GCONF_VALUE_FLOAT:
case GCONF_VALUE_FLOAT: return "float";
return "float"; case GCONF_VALUE_BOOL:
case GCONF_VALUE_BOOL: return "bool";
return "bool"; case GCONF_VALUE_SCHEMA:
case GCONF_VALUE_SCHEMA: return "schema";
return "schema"; case GCONF_VALUE_LIST:
case GCONF_VALUE_LIST: return "list";
return "list"; case GCONF_VALUE_PAIR:
case GCONF_VALUE_PAIR: return "pair";
return "pair"; case GCONF_VALUE_INVALID:
case GCONF_VALUE_INVALID: return "*invalid*";
return "*invalid*"; default:
default: g_assert_not_reached();
g_assert_not_reached(); return NULL; /* for warnings */
return NULL; /* for warnings */ }
}
} }
static void static void
process_value (TranslationEntry *trans, process_value (TranslationEntry *trans,
GConfValue *val) GConfValue *val)
{ {
if (val == NULL) if (val == NULL) {
{ int i;
int i;
for (i = 0; managers [i]; i++) for (i = 0; managers [i]; i++)
xsettings_manager_delete_setting (managers [i], trans->xsetting_name); xsettings_manager_delete_setting (managers [i], trans->xsetting_name);
} } else {
else if (val->type == trans->gconf_type)
{ (* trans->translate) (trans, val);
if (val->type == trans->gconf_type) else {
{ g_warning (_("GConf key %s set to type %s but its expected type was %s\n"),
(* trans->translate) (trans, val); trans->gconf_key,
} type_to_string (val->type),
else type_to_string (trans->gconf_type));
{ }
g_warning (_("GConf key %s set to type %s but its expected type was %s\n"), }
trans->gconf_key,
type_to_string (val->type),
type_to_string (trans->gconf_type));
}
}
} }
static void static void
xsettings_callback (GConfEntry *entry) xsettings_callback (GConfEntry *entry)
{ {
TranslationEntry *trans; TranslationEntry *trans;
int i; int i;
trans = find_translation_entry (entry->key); trans = find_translation_entry (entry->key);
if (trans == NULL) if (trans == NULL)
return; return;
process_value (trans, entry->value); process_value (trans, entry->value);
for (i = 0; managers [i]; i++) for (i = 0; managers [i]; i++)
xsettings_manager_set_string (managers [i], "Net/FallbackIconTheme", xsettings_manager_set_string (managers [i], "Net/FallbackIconTheme",
"gnome"); "gnome");
for (i = 0; managers [i]; i++) for (i = 0; managers [i]; i++)
xsettings_manager_notify (managers [i]); xsettings_manager_notify (managers [i]);
} }
void static gboolean
gnome_settings_xsettings_init (GConfClient *client) gnome_settings_module_xsettings_initialize (GnomeSettingsModule *module, GConfClient *config_client)
{ {
gnome_settings_register_config_callback ("/desktop/gnome/peripherals/mouse", xsettings_callback); gnome_settings_register_config_callback ("/desktop/gnome/peripherals/mouse", xsettings_callback);
gnome_settings_register_config_callback ("/desktop/gtk", xsettings_callback); gnome_settings_register_config_callback ("/desktop/gtk", xsettings_callback);
gnome_settings_register_config_callback ("/desktop/gnome/interface", xsettings_callback); gnome_settings_register_config_callback ("/desktop/gnome/interface", xsettings_callback);
return TRUE;
#ifdef HAVE_XFT2 #ifdef HAVE_XFT2
gnome_settings_register_config_callback (FONT_RENDER_DIR, xft_callback); gnome_settings_register_config_callback (FONT_RENDER_DIR, xft_callback);
#endif /* HAVE_XFT2 */ #endif /* HAVE_XFT2 */
} }
@ -267,15 +344,15 @@ gnome_settings_xsettings_init (GConfClient *client)
static void static void
xft_callback (GConfEntry *entry) xft_callback (GConfEntry *entry)
{ {
GConfClient *client; GConfClient *client;
int i; int i;
client = gnome_settings_get_config_client (); client = gnome_settings_get_config_client ();
gnome_settings_update_xft (client); gnome_settings_update_xft (client);
for (i = 0; managers [i]; i++) for (i = 0; managers [i]; i++)
xsettings_manager_notify (managers [i]); xsettings_manager_notify (managers [i]);
} }
static double static double
@ -294,65 +371,60 @@ dpi_from_pixels_and_mm (int pixels, int mm)
static double static double
get_dpi_from_x_server (void) get_dpi_from_x_server (void)
{ {
GdkScreen *screen; GdkScreen *screen;
double dpi; double dpi;
screen = gdk_screen_get_default (); screen = gdk_screen_get_default ();
if (screen) if (screen) {
{ double width_dpi, height_dpi;
double width_dpi, height_dpi;
width_dpi = dpi_from_pixels_and_mm (gdk_screen_get_width (screen), gdk_screen_get_width_mm (screen)); width_dpi = dpi_from_pixels_and_mm (gdk_screen_get_width (screen), gdk_screen_get_width_mm (screen));
height_dpi = dpi_from_pixels_and_mm (gdk_screen_get_height (screen), gdk_screen_get_height_mm (screen)); height_dpi = dpi_from_pixels_and_mm (gdk_screen_get_height (screen), gdk_screen_get_height_mm (screen));
if (width_dpi < DPI_LOW_REASONABLE_VALUE || width_dpi > DPI_HIGH_REASONABLE_VALUE if (width_dpi < DPI_LOW_REASONABLE_VALUE || width_dpi > DPI_HIGH_REASONABLE_VALUE
|| height_dpi < DPI_LOW_REASONABLE_VALUE || height_dpi > DPI_HIGH_REASONABLE_VALUE) || height_dpi < DPI_LOW_REASONABLE_VALUE || height_dpi > DPI_HIGH_REASONABLE_VALUE)
dpi = DPI_FALLBACK; dpi = DPI_FALLBACK;
else else
dpi = (width_dpi + height_dpi) / 2.0; dpi = (width_dpi + height_dpi) / 2.0;
} } else {
else /* Huh!? No screen? */
{
/* Huh!? No screen? */
dpi = DPI_FALLBACK; dpi = DPI_FALLBACK;
} }
return dpi; return dpi;
} }
static double static double
get_dpi_from_gconf_or_x_server (GConfClient *client) get_dpi_from_gconf_or_x_server (GConfClient *client)
{ {
GConfValue *value; GConfValue *value;
double dpi; double dpi;
value = gconf_client_get_without_default (client, FONT_DPI_KEY, NULL); value = gconf_client_get_without_default (client, FONT_DPI_KEY, NULL);
/* If the user has ever set the DPI preference in GConf, we use that. /* If the user has ever set the DPI preference in GConf, we use that.
* Otherwise, we see if the X server reports a reasonable DPI value: some X * Otherwise, we see if the X server reports a reasonable DPI value: some X
* servers report completely bogus values, and the user gets huge or tiny * servers report completely bogus values, and the user gets huge or tiny
* fonts which are unusable. * fonts which are unusable.
*/ */
if (value) if (value) {
{ dpi = gconf_value_get_float (value);
dpi = gconf_value_get_float (value); gconf_value_free (value);
gconf_value_free (value); } else
} dpi = get_dpi_from_x_server ();
else
dpi = get_dpi_from_x_server ();
return dpi; return dpi;
} }
typedef struct typedef struct
{ {
gboolean antialias; gboolean antialias;
gboolean hinting; gboolean hinting;
int dpi; int dpi;
const char *rgba; const char *rgba;
const char *hintstyle; const char *hintstyle;
} GnomeXftSettings; } GnomeXftSettings;
static const char *rgba_types[] = { "rgb", "bgr", "vbgr", "vrgb" }; static const char *rgba_types[] = { "rgb", "bgr", "vbgr", "vrgb" };
@ -364,125 +436,110 @@ static void
gnome_xft_settings_get (GConfClient *client, gnome_xft_settings_get (GConfClient *client,
GnomeXftSettings *settings) GnomeXftSettings *settings)
{ {
char *antialiasing = gconf_client_get_string (client, FONT_ANTIALIASING_KEY, NULL); char *antialiasing = gconf_client_get_string (client, FONT_ANTIALIASING_KEY, NULL);
char *hinting = gconf_client_get_string (client, FONT_HINTING_KEY, NULL); char *hinting = gconf_client_get_string (client, FONT_HINTING_KEY, NULL);
char *rgba_order = gconf_client_get_string (client, FONT_RGBA_ORDER_KEY, NULL); char *rgba_order = gconf_client_get_string (client, FONT_RGBA_ORDER_KEY, NULL);
double dpi = get_dpi_from_gconf_or_x_server (client); double dpi = get_dpi_from_gconf_or_x_server (client);
settings->antialias = TRUE; settings->antialias = TRUE;
settings->hinting = TRUE; settings->hinting = TRUE;
settings->hintstyle = "hintfull"; settings->hintstyle = "hintfull";
settings->dpi = dpi * 1024; /* Xft wants 1/1024ths of an inch */ settings->dpi = dpi * 1024; /* Xft wants 1/1024ths of an inch */
settings->rgba = "rgb"; settings->rgba = "rgb";
if (rgba_order) if (rgba_order) {
{ int i;
int i; gboolean found = FALSE;
gboolean found = FALSE;
for (i = 0; i < G_N_ELEMENTS (rgba_types) && !found; i++) for (i = 0; i < G_N_ELEMENTS (rgba_types) && !found; i++)
if (strcmp (rgba_order, rgba_types[i]) == 0) if (strcmp (rgba_order, rgba_types[i]) == 0) {
{ settings->rgba = rgba_types[i];
settings->rgba = rgba_types[i]; found = TRUE;
found = TRUE; }
}
if (!found) if (!found)
g_warning ("Invalid value for " FONT_RGBA_ORDER_KEY ": '%s'", g_warning ("Invalid value for " FONT_RGBA_ORDER_KEY ": '%s'",
rgba_order); rgba_order);
} }
if (hinting) if (hinting) {
{ if (strcmp (hinting, "none") == 0) {
if (strcmp (hinting, "none") == 0) settings->hinting = 0;
{ settings->hintstyle = "hintnone";
settings->hinting = 0; } else if (strcmp (hinting, "slight") == 0) {
settings->hintstyle = "hintnone"; settings->hinting = 1;
settings->hintstyle = "hintslight";
} else if (strcmp (hinting, "medium") == 0) {
settings->hinting = 1;
settings->hintstyle = "hintmedium";
} else if (strcmp (hinting, "full") == 0) {
settings->hinting = 1;
settings->hintstyle = "hintfull";
} else
g_warning ("Invalid value for " FONT_HINTING_KEY ": '%s'",
hinting);
} }
else if (strcmp (hinting, "slight") == 0)
{
settings->hinting = 1;
settings->hintstyle = "hintslight";
}
else if (strcmp (hinting, "medium") == 0)
{
settings->hinting = 1;
settings->hintstyle = "hintmedium";
}
else if (strcmp (hinting, "full") == 0)
{
settings->hinting = 1;
settings->hintstyle = "hintfull";
}
else
g_warning ("Invalid value for " FONT_HINTING_KEY ": '%s'",
hinting);
}
if (antialiasing) if (antialiasing) {
{ gboolean use_rgba = FALSE;
gboolean use_rgba = FALSE;
if (strcmp (antialiasing, "none") == 0) if (strcmp (antialiasing, "none") == 0)
settings->antialias = 0; settings->antialias = 0;
else if (strcmp (antialiasing, "grayscale") == 0) else if (strcmp (antialiasing, "grayscale") == 0)
settings->antialias = 1; settings->antialias = 1;
else if (strcmp (antialiasing, "rgba") == 0) else if (strcmp (antialiasing, "rgba") == 0) {
{ settings->antialias = 1;
settings->antialias = 1; use_rgba = TRUE;
use_rgba = TRUE; } else
g_warning ("Invalid value for " FONT_ANTIALIASING_KEY " : '%s'",
antialiasing);
if (!use_rgba)
settings->rgba = "none";
} }
else
g_warning ("Invalid value for " FONT_ANTIALIASING_KEY " : '%s'",
antialiasing);
if (!use_rgba) g_free (rgba_order);
settings->rgba = "none"; g_free (hinting);
} g_free (antialiasing);
g_free (rgba_order);
g_free (hinting);
g_free (antialiasing);
} }
static void static void
gnome_xft_settings_set_xsettings (GnomeXftSettings *settings) gnome_xft_settings_set_xsettings (GnomeXftSettings *settings)
{ {
int i; int i;
for (i = 0; managers [i]; i++) for (i = 0; managers [i]; i++) {
{ xsettings_manager_set_int (managers [i], "Xft/Antialias", settings->antialias);
xsettings_manager_set_int (managers [i], "Xft/Antialias", settings->antialias); xsettings_manager_set_int (managers [i], "Xft/Hinting", settings->hinting);
xsettings_manager_set_int (managers [i], "Xft/Hinting", settings->hinting); xsettings_manager_set_string (managers [i], "Xft/HintStyle", settings->hintstyle);
xsettings_manager_set_string (managers [i], "Xft/HintStyle", settings->hintstyle); xsettings_manager_set_int (managers [i], "Xft/DPI", settings->dpi);
xsettings_manager_set_int (managers [i], "Xft/DPI", settings->dpi); xsettings_manager_set_string (managers [i], "Xft/RGBA", settings->rgba);
xsettings_manager_set_string (managers [i], "Xft/RGBA", settings->rgba); }
}
} }
static void static void
gnome_xft_settings_set_xresources (GnomeXftSettings *settings) gnome_xft_settings_set_xresources (GnomeXftSettings *settings)
{ {
char *add[] = { "xrdb", "-nocpp", "-merge", NULL }; char *add[] = { "xrdb", "-nocpp", "-merge", NULL };
GString *add_string = g_string_new (NULL); GString *add_string = g_string_new (NULL);
char *old_locale = g_strdup (setlocale (LC_NUMERIC, NULL)); char *old_locale = g_strdup (setlocale (LC_NUMERIC, NULL));
setlocale (LC_NUMERIC, "C"); setlocale (LC_NUMERIC, "C");
g_string_append_printf (add_string, g_string_append_printf (add_string,
"Xft.dpi: %f\n", settings->dpi / 1024.); "Xft.dpi: %f\n", settings->dpi / 1024.);
g_string_append_printf (add_string, g_string_append_printf (add_string,
"Xft.antialias: %d\n", settings->antialias); "Xft.antialias: %d\n", settings->antialias);
g_string_append_printf (add_string, g_string_append_printf (add_string,
"Xft.hinting: %d\n", settings->hinting); "Xft.hinting: %d\n", settings->hinting);
g_string_append_printf (add_string, g_string_append_printf (add_string,
"Xft.hintstyle: %s\n", settings->hintstyle); "Xft.hintstyle: %s\n", settings->hintstyle);
g_string_append_printf (add_string, g_string_append_printf (add_string,
"Xft.rgba: %s\n", settings->rgba); "Xft.rgba: %s\n", settings->rgba);
gnome_settings_spawn_with_input (add, add_string->str); gnome_settings_spawn_with_input (add, add_string->str);
g_string_free (add_string, TRUE); g_string_free (add_string, TRUE);
setlocale (LC_NUMERIC, old_locale); setlocale (LC_NUMERIC, old_locale);
g_free (old_locale); g_free (old_locale);
} }
/* We mirror the Xft properties both through XSETTINGS and through /* We mirror the Xft properties both through XSETTINGS and through
@ -491,54 +548,59 @@ gnome_xft_settings_set_xresources (GnomeXftSettings *settings)
static void static void
gnome_settings_update_xft (GConfClient *client) gnome_settings_update_xft (GConfClient *client)
{ {
GnomeXftSettings settings; GnomeXftSettings settings;
gnome_xft_settings_get (client, &settings); gnome_xft_settings_get (client, &settings);
gnome_xft_settings_set_xsettings (&settings); gnome_xft_settings_set_xsettings (&settings);
gnome_xft_settings_set_xresources (&settings); gnome_xft_settings_set_xresources (&settings);
} }
#endif /* HAVE_XFT2 */ #endif /* HAVE_XFT2 */
void static gboolean
gnome_settings_xsettings_load (GConfClient *client) gnome_settings_module_xsettings_start (GnomeSettingsModule *module)
{ {
int i; GConfClient *client = gnome_settings_module_get_config_client (module);
int i;
i = 0; i = 0;
while (i < G_N_ELEMENTS (translations)) while (i < G_N_ELEMENTS (translations)) {
{ GConfValue *val;
GConfValue *val; GError *err;
GError *err;
err = NULL; err = NULL;
val = gconf_client_get (client, val = gconf_client_get (client,
translations[i].gconf_key, translations[i].gconf_key,
&err); &err);
if (err != NULL) if (err != NULL) {
{ fprintf (stderr, "Error getting value for %s: %s\n",
fprintf (stderr, "Error getting value for %s: %s\n", translations[i].gconf_key, err->message);
translations[i].gconf_key, err->message); g_error_free (err);
g_error_free (err); } else {
} process_value (&translations[i], val);
else if (val != NULL)
{ gconf_value_free (val);
process_value (&translations[i], val); }
if (val != NULL)
gconf_value_free (val);
}
++i; ++i;
} }
#ifdef HAVE_XFT2 #ifdef HAVE_XFT2
gnome_settings_update_xft (client); gnome_settings_update_xft (client);
#endif /* HAVE_XFT */ #endif /* HAVE_XFT */
for (i = 0; managers [i]; i++) for (i = 0; managers [i]; i++)
xsettings_manager_set_string (managers [i], "Net/FallbackIconTheme", xsettings_manager_set_string (managers [i], "Net/FallbackIconTheme",
"gnome"); "gnome");
for (i = 0; managers [i]; i++) for (i = 0; managers [i]; i++)
xsettings_manager_notify (managers [i]); xsettings_manager_notify (managers [i]);
return TRUE;
}
static gboolean
gnome_settings_module_xsettings_stop (GnomeSettingsModule *module)
{
return TRUE;
} }

View file

@ -1,33 +0,0 @@
/*
* Copyright 2001 Red Hat, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation, and that the name of Red Hat not be used in advertising or
* publicity pertaining to distribution of the software without specific,
* written prior permission. Red Hat makes no representations about the
* suitability of this software for any purpose. It is provided "as is"
* without express or implied warranty.
*
* RED HAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL RED HAT
* BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* Authors: Jonathan Blandford
*/
#ifndef GNOME_SETTINGS_XSETTINGS_H
#define GNOME_SETTINGS_XSETTINGS_H
#include <gconf/gconf.h>
void gnome_settings_xsettings_init (GConfClient *client);
void gnome_settings_xsettings_load (GConfClient *client);
#endif /* GNOME_SETTINGS_XSETTINGS_H */