Sat Dec 8 21:33:10 2001 Jonathan Blandford <jrb@redhat.com> * gnome-settings-daemon/gnome-settings-daemon.c (main): Import from gconf-xsettings module. Cleaned up a bunch, and made to work with mouse properties too. * schemas/peripherals.schemas: New location for schemas. Need to write many more.
180 lines
4.7 KiB
C
180 lines
4.7 KiB
C
/*
|
|
* 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: Owen Taylor, Havoc Pennington
|
|
*/
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
#include <gtk/gtk.h>
|
|
#include <gdk/gdkx.h>
|
|
|
|
#include <gconf/gconf.h>
|
|
|
|
#include "xsettings-manager.h"
|
|
#include "gnome-settings-daemon.h"
|
|
|
|
static GSList *directories = NULL;
|
|
XSettingsManager *manager;
|
|
|
|
typedef struct DirElement
|
|
{
|
|
char *dir;
|
|
GSList *callbacks;
|
|
} DirElement;
|
|
|
|
void
|
|
gnome_settings_daemon_register_callback (const char *dir,
|
|
KeyCallbackFunc func)
|
|
{
|
|
GSList *list;
|
|
gboolean dir_found = FALSE;
|
|
|
|
for (list = directories; list; list = list->next)
|
|
{
|
|
DirElement *dir_element = list->data;
|
|
|
|
if (! strcmp (dir_element->dir, dir))
|
|
{
|
|
dir_element->callbacks = g_slist_prepend (dir_element->callbacks, func);
|
|
dir_found = TRUE;
|
|
break;
|
|
}
|
|
}
|
|
if (! dir_found)
|
|
{
|
|
DirElement *dir_element = g_new0 (DirElement, 1);
|
|
|
|
dir_element->dir = g_strdup (dir);
|
|
dir_element->callbacks = g_slist_prepend (dir_element->callbacks, func);
|
|
directories = g_slist_prepend (directories, dir_element);
|
|
}
|
|
}
|
|
|
|
static void
|
|
config_notify (GConfEngine *client,
|
|
guint cnxn_id,
|
|
GConfEntry *entry,
|
|
gpointer user_data)
|
|
{
|
|
GSList *list;
|
|
|
|
for (list = directories; list; list = list->next)
|
|
{
|
|
DirElement *dir_element = list->data;
|
|
|
|
if (! strncmp (dir_element->dir, entry->key, strlen (dir_element->dir)))
|
|
{
|
|
GSList *func_list;
|
|
for (func_list = dir_element->callbacks; func_list; func_list = func_list->next)
|
|
{
|
|
((KeyCallbackFunc) func_list->data) (entry);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
static void
|
|
terminate_cb (void *data)
|
|
{
|
|
gboolean *terminated = data;
|
|
|
|
*terminated = TRUE;
|
|
gtk_main_quit ();
|
|
}
|
|
|
|
static GdkFilterReturn
|
|
manager_event_filter (GdkXEvent *xevent,
|
|
GdkEvent *event,
|
|
gpointer data)
|
|
{
|
|
if (xsettings_manager_process_event (manager, (XEvent *)xevent))
|
|
return GDK_FILTER_REMOVE;
|
|
else
|
|
return GDK_FILTER_CONTINUE;
|
|
}
|
|
|
|
int
|
|
main (int argc, char **argv)
|
|
{
|
|
gboolean terminated = FALSE;
|
|
GConfEngine *engine;
|
|
GSList *list;
|
|
gtk_init (&argc, &argv);
|
|
|
|
if (xsettings_manager_check_running (gdk_display, DefaultScreen (gdk_display)))
|
|
{
|
|
fprintf (stderr, "You can only run one xsettings manager at a time; exiting");
|
|
exit (1);
|
|
}
|
|
|
|
if (!terminated)
|
|
{
|
|
manager = xsettings_manager_new (gdk_display, DefaultScreen (gdk_display),
|
|
terminate_cb, &terminated);
|
|
if (!manager)
|
|
{
|
|
fprintf (stderr, "Could not create xsettings manager!");
|
|
exit (1);
|
|
}
|
|
}
|
|
|
|
gconf_init (argc, argv, NULL); /* exits w/ message on failure */
|
|
|
|
/* We use GConfEngine not GConfClient because a cache isn't useful
|
|
* for us
|
|
*/
|
|
engine = gconf_engine_get_default ();
|
|
gnome_settings_xsettings_init (engine);
|
|
gnome_settings_mouse_init (engine);
|
|
|
|
for (list = directories; list; list = list->next)
|
|
{
|
|
GError *error = NULL;
|
|
DirElement *dir_element = list->data;
|
|
|
|
gconf_engine_notify_add (engine,
|
|
dir_element->dir,
|
|
config_notify,
|
|
NULL,
|
|
&error);
|
|
|
|
if (error)
|
|
{
|
|
fprintf (stderr, "Could not listen for changes to configuration in '%s': %s\n",
|
|
dir_element->dir, error->message);
|
|
g_error_free (error);
|
|
}
|
|
}
|
|
|
|
gdk_window_add_filter (NULL, manager_event_filter, NULL);
|
|
|
|
gnome_settings_xsettings_load (engine);
|
|
gnome_settings_mouse_load (engine);
|
|
|
|
if (!terminated)
|
|
gtk_main ();
|
|
|
|
xsettings_manager_destroy (manager);
|
|
gconf_engine_unref (engine);
|
|
|
|
return 0;
|
|
}
|