From 1f239d9a037641897c589a5e545b4ca7b0ab6355 Mon Sep 17 00:00:00 2001 From: Jonathan Blandford Date: Thu, 6 Feb 2003 21:47:00 +0000 Subject: [PATCH] handle xcursor so that we support Xcursor files. Thu Feb 6 16:43:33 2003 Jonathan Blandford * gnome-settings-font.c (load_xcursor_theme): handle xcursor so that we support Xcursor files. * gnome-settings-daemon.c: move gnome_settings_daemon_spawn_with_input here so multiple modules can use it. --- gnome-settings-daemon/ChangeLog | 9 ++ gnome-settings-daemon/gnome-settings-daemon.c | 123 ++++++++++++++++++ gnome-settings-daemon/gnome-settings-daemon.h | 6 +- gnome-settings-daemon/gnome-settings-font.c | 35 ++++- .../gnome-settings-xsettings.c | 119 +---------------- 5 files changed, 170 insertions(+), 122 deletions(-) diff --git a/gnome-settings-daemon/ChangeLog b/gnome-settings-daemon/ChangeLog index 56a42b22a..95278447f 100644 --- a/gnome-settings-daemon/ChangeLog +++ b/gnome-settings-daemon/ChangeLog @@ -1,3 +1,12 @@ +Thu Feb 6 16:43:33 2003 Jonathan Blandford + + * gnome-settings-font.c (load_xcursor_theme): handle xcursor so + that we support Xcursor files. + + * gnome-settings-daemon.c: move + gnome_settings_daemon_spawn_with_input here so multiple modules + can use it. + Tue Feb 4 17:09:18 2003 Jonathan Blandford * Release 2.2.0.1 diff --git a/gnome-settings-daemon/gnome-settings-daemon.c b/gnome-settings-daemon/gnome-settings-daemon.c index e486b1bb7..3431b3c3d 100644 --- a/gnome-settings-daemon/gnome-settings-daemon.c +++ b/gnome-settings-daemon/gnome-settings-daemon.c @@ -31,6 +31,12 @@ #include #include #include + +#include +#include +#include +#include + #include "xsettings-manager.h" #include "gnome-settings-daemon.h" @@ -323,3 +329,120 @@ gnome_settings_daemon_new (void) return G_OBJECT (daemon); } + + +/* Helper functions */ + +/* + * Helper function for spawn_with_input() - wait for a child + * to exit. + */ +gboolean +wait_for_child (int pid, + int *status) +{ + gint ret; + + again: + ret = waitpid (pid, status, 0); + + if (ret < 0) + { + if (errno == EINTR) + goto again; + else + { + g_warning ("Unexpected error in waitpid() (%s)", + g_strerror (errno)); + return FALSE; + } + } + + return TRUE; +} + + +/* + * Helper function for spawn_with_input() - write an entire + * string to a fd. + */ +static gboolean +write_all (int fd, + const char *buf, + gsize to_write) +{ + while (to_write > 0) + { + gssize count = write (fd, buf, to_write); + if (count < 0) + { + if (errno != EINTR) + return FALSE; + } + else + { + to_write -= count; + buf += count; + } + } + + return TRUE; +} + +/** + * gnome_settings_daemon-spawn_with_input: + * @argv: command line to run + * @input: string to write to the child process. + * + * Spawns a child process specified by @argv, writes the text in + * @input to it, then waits for the child to exit. Any failures + * are output through g_warning(); if you wanted to use this in + * cases where errors need to be presented to the user, some + * modification would be needed. + **/ +void +gnome_settings_daemon_spawn_with_input (char **argv, + const char *input) +{ + int exit_status; + int child_pid; + int inpipe; + GError *err = NULL; + + if (!g_spawn_async_with_pipes (NULL /* working directory */, argv, NULL /* envp */, + G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD, + NULL, NULL, /* child setup and data */ + &child_pid, + &inpipe, NULL, NULL, /* stdin, stdout, stderr */ + &err)) + { + gchar *command = g_strjoinv (" ", argv); + g_warning ("Could not execute %s: %s", command, err->message); + g_error_free (err); + g_free (command); + + return; + } + + if (input) + { + if (!write_all (inpipe, input, strlen (input))) + { + gchar *command = g_strjoinv (" ", argv); + g_warning ("Could not write input to %s", command); + g_free (command); + } + + close (inpipe); + } + + wait_for_child (child_pid, &exit_status); + + if (!WIFEXITED (exit_status) || WEXITSTATUS (exit_status)) + { + gchar *command = g_strjoinv (" ", argv); + g_warning ("Command %s failed", command); + g_free (command); + } + +} diff --git a/gnome-settings-daemon/gnome-settings-daemon.h b/gnome-settings-daemon/gnome-settings-daemon.h index b9e1f872f..8908977ba 100644 --- a/gnome-settings-daemon/gnome-settings-daemon.h +++ b/gnome-settings-daemon/gnome-settings-daemon.h @@ -64,8 +64,10 @@ struct _GnomeSettingsDaemonClass POA_GNOME_SettingsDaemon__epv epv; }; -GType gnome_settings_daemon_get_type (void); -GObject *gnome_settings_daemon_new (void); +GType gnome_settings_daemon_get_type (void); +GObject *gnome_settings_daemon_new (void); +void gnome_settings_daemon_spawn_with_input (char **argv, + const char *input); G_END_DECLS diff --git a/gnome-settings-daemon/gnome-settings-font.c b/gnome-settings-daemon/gnome-settings-font.c index 868186a16..dd02c608d 100644 --- a/gnome-settings-daemon/gnome-settings-font.c +++ b/gnome-settings-daemon/gnome-settings-font.c @@ -11,6 +11,34 @@ #include +static void +load_xcursor_theme (GConfClient *client) +{ + gchar *cursor_theme; + gint size; + char *add[] = { "xrdb", "-merge", NULL }; + GString *add_string = g_string_new (NULL); + + cursor_theme = gconf_client_get_string (client, + "/desktop/gnome/peripherals/mouse/cursor_theme", + NULL); + size = gconf_client_get_int (client, + "/desktop/gnome/peripherals/mouse/cursor_size", + NULL); + if (cursor_theme == NULL || size <= 0) + return; + + g_string_append_printf (add_string, + "Xcursor.theme: %s\n", cursor_theme); + g_string_append (add_string, "Xcursor.theme_core: true\n"); + g_string_append_printf (add_string, + "Xcursor.size: %d\n", size); + + gnome_settings_daemon_spawn_with_input (add, add_string->str); + + g_string_free (add_string, TRUE); +} + static void load_cursor (GConfClient *client) { @@ -122,7 +150,9 @@ load_cursor (GConfClient *client) /* run mkfontdir */ mkfontdir_cmd = g_strdup_printf ("mkfontdir %s %s", dir_name, font_dir_name); - /* maybe check for error... */ + /* maybe check for error... + * also, it's not going to like that if there are spaces in dir_name/font_dir_name. + */ g_spawn_command_line_sync (mkfontdir_cmd, NULL, NULL, NULL, NULL); g_free (mkfontdir_cmd); @@ -167,7 +197,8 @@ load_cursor (GConfClient *client) void gnome_settings_font_init (GConfClient *client) { - load_cursor (client); + load_xcursor_theme (client); + load_cursor (client); } void diff --git a/gnome-settings-daemon/gnome-settings-xsettings.c b/gnome-settings-daemon/gnome-settings-xsettings.c index 17b971c5d..a19bdbcfa 100644 --- a/gnome-settings-daemon/gnome-settings-xsettings.c +++ b/gnome-settings-daemon/gnome-settings-xsettings.c @@ -4,11 +4,6 @@ #include #include -#include -#include -#include -#include - #include "gnome-settings-daemon.h" #include "gnome-settings-xsettings.h" #include "xsettings-manager.h" @@ -348,118 +343,6 @@ gnome_xft_settings_set_xsettings (GnomeXftSettings *settings) } } -/* - * Helper function for spawn_with_input() - write an entire - * string to a fd. - */ -static gboolean -write_all (int fd, - const char *buf, - gsize to_write) -{ - while (to_write > 0) - { - gssize count = write (fd, buf, to_write); - if (count < 0) - { - if (errno != EINTR) - return FALSE; - } - else - { - to_write -= count; - buf += count; - } - } - - return TRUE; -} - -/* - * Helper function for spawn_with_input() - wait for a child - * to exit. - */ -gboolean -wait_for_child (int pid, - int *status) -{ - gint ret; - - again: - ret = waitpid (pid, status, 0); - - if (ret < 0) - { - if (errno == EINTR) - goto again; - else - { - g_warning ("Unexpected error in waitpid() (%s)", - g_strerror (errno)); - return FALSE; - } - } - - return TRUE; -} - -/** - * spawn_with_input: - * @argv: command line to run - * @input: string to write to the child process. - * - * Spawns a child process specified by @argv, writes the text in - * @input to it, then waits for the child to exit. Any failures - * are output through g_warning(); if you wanted to use this in - * cases where errors need to be presented to the user, some - * modification would be needed. - **/ -static void -spawn_with_input (char **argv, - const char *input) -{ - int exit_status; - int child_pid; - int inpipe; - GError *err = NULL; - - if (!g_spawn_async_with_pipes (NULL /* working directory */, argv, NULL /* envp */, - G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD, - NULL, NULL, /* child setup and data */ - &child_pid, - &inpipe, NULL, NULL, /* stdin, stdout, stderr */ - &err)) - { - gchar *command = g_strjoinv (" ", argv); - g_warning ("Could not execute %s: %s", command, err->message); - g_error_free (err); - g_free (command); - - return; - } - - if (input) - { - if (!write_all (inpipe, input, strlen (input))) - { - gchar *command = g_strjoinv (" ", argv); - g_warning ("Could not write input to %s", command); - g_free (command); - } - - close (inpipe); - } - - wait_for_child (child_pid, &exit_status); - - if (!WIFEXITED (exit_status) || WEXITSTATUS (exit_status)) - { - gchar *command = g_strjoinv (" ", argv); - g_warning ("Command %s failed", command); - g_free (command); - } -} - static void gnome_xft_settings_set_xresources (GnomeXftSettings *settings) { @@ -477,7 +360,7 @@ gnome_xft_settings_set_xresources (GnomeXftSettings *settings) g_string_append_printf (add_string, "Xft.rgba: %s\n", settings->rgba); - spawn_with_input (add, add_string->str); + gnome_settings_daemon_spawn_with_input (add, add_string->str); g_string_free (add_string, TRUE); }