From 78b4743519ed3499edd35c8683b3c77ae53fd864 Mon Sep 17 00:00:00 2001 From: Denis Washington Date: Thu, 26 Jul 2007 16:15:35 +0000 Subject: [PATCH] Re-add basic support for cursor themes for X servers without the Xcursor 2007-07-26 Denis Washington * appearance/data/appearance.glade: * appearance/appearance-style.c: * appearance/appearance-themes.c: (theme_load_from_gconf), (cursor_theme_changed), (prepare_list), (style_init): * appearance/theme-save.c: (write_theme_to_disk): * appearance/theme-util.h: * common/gnome-theme-apply.c: (gnome_meta_theme_set): * common/gnome-theme-info.c: (add_common_icon_theme_dir_monitor), (gnome_theme_init): * common/gnome-theme-info.h: Re-add basic support for cursor themes for X servers without the Xcursor extension, like the one on Solaris. svn path=/trunk/; revision=7890 --- capplets/appearance/ChangeLog | 11 ++ capplets/appearance/appearance-style.c | 23 ++++ capplets/appearance/appearance-themes.c | 6 +- capplets/appearance/data/appearance.glade | 40 ++++++- capplets/appearance/theme-save.c | 4 + capplets/appearance/theme-util.h | 1 + capplets/common/ChangeLog | 9 ++ capplets/common/gnome-theme-apply.c | 10 ++ capplets/common/gnome-theme-info.c | 126 +++++++++++++++++++++- capplets/common/gnome-theme-info.h | 5 + 10 files changed, 230 insertions(+), 5 deletions(-) diff --git a/capplets/appearance/ChangeLog b/capplets/appearance/ChangeLog index d2c24ae9f..8c1a05376 100644 --- a/capplets/appearance/ChangeLog +++ b/capplets/appearance/ChangeLog @@ -1,3 +1,14 @@ +2007-07-26 Denis Washington + + * data/appearance.glade: + * appearance-style.c: + * appearance-themes.c: (theme_load_from_gconf), (cursor_theme_changed), + (prepare_list), (style_init): + * theme-save.c: (write_theme_to_disk): + * theme-util.h: + Re-add basic support for cursor themes for X servers without the Xcursor + extension, like the one on Solaris. + 2007-07-25 Thomas Wood Patch by: Dennis Cranston diff --git a/capplets/appearance/appearance-style.c b/capplets/appearance/appearance-style.c index 7161780fb..9c760d35a 100644 --- a/capplets/appearance/appearance-style.c +++ b/capplets/appearance/appearance-style.c @@ -376,6 +376,7 @@ icon_theme_changed (GConfPropertyEditor *peditor, gnome_theme_is_writable (theme, GNOME_THEME_TYPE_ICON)); } +#ifdef HAVE_XCURSOR static void update_cursor_size_scale (GnomeThemeCursorInfo *theme, AppearanceData *data) @@ -440,6 +441,7 @@ update_cursor_size_scale (GnomeThemeCursorInfo *theme, gtk_range_set_value (GTK_RANGE (cursor_size_scale), (gdouble) g_array_index (theme->sizes, gint, theme->sizes->len - 1)); } } +#endif static void cursor_theme_changed (GConfPropertyEditor *peditor, @@ -453,7 +455,9 @@ cursor_theme_changed (GConfPropertyEditor *peditor, if (value && (name = gconf_value_get_string (value))) theme = gnome_theme_cursor_info_find (name); +#ifdef HAVE_XCURSOR update_cursor_size_scale (theme, data); +#endif gtk_widget_set_sensitive (glade_xml_get_widget (data->xml, "cursor_themes_delete"), gnome_theme_is_writable (theme, GNOME_THEME_TYPE_CURSOR)); @@ -515,6 +519,7 @@ icon_theme_delete_cb (GtkWidget *button, AppearanceData *data) generic_theme_delete ("icon_themes_list", THEME_TYPE_ICON, data); } +#ifdef HAVE_XCURSOR static void cursor_size_scale_value_changed_cb (GtkRange *range, AppearanceData *data) { @@ -535,6 +540,7 @@ cursor_size_scale_value_changed_cb (GtkRange *range, AppearanceData *data) gconf_client_set_int (data->client, CURSOR_SIZE_KEY, size, NULL); } } +#endif static void add_to_treeview (const gchar *tv_name, @@ -754,7 +760,11 @@ prepare_list (AppearanceData *data, GtkWidget *list, ThemeType type, GCallback c case THEME_TYPE_CURSOR: themes = gnome_theme_cursor_info_find_all (); thumbnail = NULL; +#ifdef HAVE_XCURSOR key = CURSOR_THEME_KEY; +#else + key = CURSOR_FONT_KEY; +#endif generator = NULL; thumb_cb = NULL; break; @@ -779,6 +789,9 @@ prepare_list (AppearanceData *data, GtkWidget *list, ThemeType type, GCallback c label = ((GnomeThemeIconInfo *) l->data)->readable_name; } else if (type == THEME_TYPE_CURSOR) { name = ((GnomeThemeCursorInfo *) l->data)->name; +#ifndef HAVE_XCURSOR + label = ((GnomeThemeCursorInfo *) l->data)->label; +#endif } if (!name) @@ -803,6 +816,7 @@ prepare_list (AppearanceData *data, GtkWidget *list, ThemeType type, GCallback c } g_list_free (themes); +#ifdef HAVE_XCURSOR if (type == THEME_TYPE_CURSOR) { GtkTreeIter i; gtk_list_store_insert_with_values (store, &i, 0, @@ -811,6 +825,7 @@ prepare_list (AppearanceData *data, GtkWidget *list, ThemeType type, GCallback c COL_THUMBNAIL, NULL, -1); } +#endif sort_model = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (store)); gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (sort_model), @@ -878,6 +893,7 @@ style_init (AppearanceData *data) settings = gtk_settings_get_default (); g_signal_connect (settings, "notify::gtk-color-scheme", (GCallback) color_scheme_changed, data); +#ifdef HAVE_XCURSOR w = glade_xml_get_widget (data->xml, "cursor_size_scale"); GTK_RANGE (w)->round_digits = 0; g_signal_connect (G_OBJECT (w), "value-changed", (GCallback) cursor_size_scale_value_changed_cb, data); @@ -888,6 +904,13 @@ style_init (AppearanceData *data) gtk_label_set_markup (GTK_LABEL (w), g_strdup_printf ("%s", gtk_label_get_text (GTK_LABEL (w)))); w = glade_xml_get_widget (data->xml, "cursor_size_large_label"); gtk_label_set_markup (GTK_LABEL (w), g_strdup_printf ("%s", gtk_label_get_text (GTK_LABEL (w)))); +#else + w = glade_xml_get_widget (data->xml, "cursor_size_hbox"); + gtk_widget_set_no_show_all (w, TRUE); + gtk_widget_hide (w); + gtk_widget_show (glade_xml_get_widget (data->xml, "cursor_message_hbox")); + gtk_box_set_spacing (GTK_BOX (glade_xml_get_widget (data->xml, "cursor_vbox")), 12); +#endif /* connect signals */ /* color buttons */ diff --git a/capplets/appearance/appearance-themes.c b/capplets/appearance/appearance-themes.c index bfb2384b9..2a7ebb5cc 100644 --- a/capplets/appearance/appearance-themes.c +++ b/capplets/appearance/appearance-themes.c @@ -139,9 +139,13 @@ theme_load_from_gconf (GConfClient *client, GnomeThemeMetaInfo *theme) theme->icon_theme_name = gconf_client_get_string (client, ICON_THEME_KEY, NULL); g_free (theme->cursor_theme_name); - theme->cursor_theme_name = gconf_client_get_string (client, CURSOR_THEME_KEY, NULL); +#ifdef HAVE_XCURSOR + theme->cursor_theme_name = gconf_client_get_string (client, CURSOR_THEME_KEY, NULL); theme->cursor_size = gconf_client_get_int (client, CURSOR_SIZE_KEY, NULL); +#else + theme->cursor_theme_name = gconf_client_get_string (client, CURSOR_FONT_KEY, NULL); +#endif } static gchar * diff --git a/capplets/appearance/data/appearance.glade b/capplets/appearance/data/appearance.glade index 98d06e9cb..af116b354 100644 --- a/capplets/appearance/data/appearance.glade +++ b/capplets/appearance/data/appearance.glade @@ -2277,11 +2277,45 @@ Text only - + True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK 12 6 + + + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 6 + True + + + True + gtk-dialog-info + 5 + + + False + + + + + 280 + True + Changing your cursor theme takes effect the next time you log in. + True + + + False + False + 1 + + + + + False + False + + True @@ -2302,12 +2336,12 @@ Text only - + True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK 12 - + Size: diff --git a/capplets/appearance/theme-save.c b/capplets/appearance/theme-save.c index 29ce914d4..c282ad2d6 100644 --- a/capplets/appearance/theme-save.c +++ b/capplets/appearance/theme-save.c @@ -231,10 +231,14 @@ write_theme_to_disk (GnomeThemeMetaInfo *theme_info, } if (theme_info->cursor_theme_name) { +#ifdef HAVE_XCURSOR str = g_strdup_printf ("CursorTheme=%s\n" "CursorSize=%i\n", theme_info->cursor_theme_name, theme_info->cursor_size); +#else + str = g_strdup_printf ("CursorFont=%s\n", theme_info->cursor_theme_name); +#endif gnome_vfs_write (handle, str, strlen (str), &bytes_written); g_free (str); } diff --git a/capplets/appearance/theme-util.h b/capplets/appearance/theme-util.h index bd093cc6d..6af9b0810 100644 --- a/capplets/appearance/theme-util.h +++ b/capplets/appearance/theme-util.h @@ -22,6 +22,7 @@ #define METACITY_THEME_KEY "/apps/metacity/general/theme" #define ICON_THEME_KEY "/desktop/gnome/interface/icon_theme" #define COLOR_SCHEME_KEY "/desktop/gnome/interface/gtk_color_scheme" +#define CURSOR_FONT_KEY "/desktop/gnome/peripherals/mouse/cursor_font" #define CURSOR_THEME_KEY "/desktop/gnome/peripherals/mouse/cursor_theme" #define CURSOR_SIZE_KEY "/desktop/gnome/peripherals/mouse/cursor_size" #define LOCKDOWN_KEY "/desktop/gnome/lockdown/disable_theme_settings" diff --git a/capplets/common/ChangeLog b/capplets/common/ChangeLog index 2036c805b..ff67bed68 100644 --- a/capplets/common/ChangeLog +++ b/capplets/common/ChangeLog @@ -1,3 +1,12 @@ +2007-07-25 Denis Washington + + * gnome-theme-apply.c: (gnome_meta_theme_set): + * gnome-theme-info.c: (add_common_icon_theme_dir_monitor), + (gnome_theme_init): + * gnome-theme-info.h: + Re-add basic support for cursor themes for X servers without the Xcursor + extension, like the one on Solaris. + 2007-07-25 Denis Washington * gnome-theme-info.h: diff --git a/capplets/common/gnome-theme-apply.c b/capplets/common/gnome-theme-apply.c index 03e984074..0fa0029fa 100644 --- a/capplets/common/gnome-theme-apply.c +++ b/capplets/common/gnome-theme-apply.c @@ -26,6 +26,7 @@ #define COLOR_SCHEME_KEY "/desktop/gnome/interface/gtk_color_scheme" #define ICON_THEME_KEY "/desktop/gnome/interface/icon_theme" #define FONT_KEY "/desktop/gnome/interface/font_name" +#define CURSOR_FONT_KEY "/desktop/gnome/peripherals/mouse/cursor_font" #define CURSOR_THEME_KEY "/desktop/gnome/peripherals/mouse/cursor_theme" #define CURSOR_SIZE_KEY "/desktop/gnome/peripherals/mouse/cursor_size" @@ -77,12 +78,21 @@ gnome_meta_theme_set (GnomeThemeMetaInfo *meta_theme_info) g_free (old_key); /* Set the cursor theme key */ +#ifdef HAVE_XCURSOR old_key = gconf_client_get_string (client, CURSOR_THEME_KEY, NULL); if (compare (old_key, meta_theme_info->cursor_theme_name)) { gconf_client_set_string (client, CURSOR_THEME_KEY, meta_theme_info->cursor_theme_name, NULL); gconf_client_set_int (client, CURSOR_SIZE_KEY, meta_theme_info->cursor_size, NULL); } +#else + old_key = gconf_client_get_string (client, CURSOR_FONT_KEY, NULL); + if (compare (old_key, meta_theme_info->cursor_theme_name)) + { + gconf_client_set_string (client, CURSOR_FONT_KEY, meta_theme_info->cursor_theme_name, NULL); + } +#endif + g_free (old_key); g_object_unref (client); } diff --git a/capplets/common/gnome-theme-info.c b/capplets/common/gnome-theme-info.c index aefbe63ad..4003e287a 100644 --- a/capplets/common/gnome-theme-info.c +++ b/capplets/common/gnome-theme-info.c @@ -1,6 +1,9 @@ +#include +#include +#include +#include #include #include -#include #include #include #include @@ -10,6 +13,10 @@ #include "gnome-theme-info.h" #include "gtkrc-utils.h" +#ifdef HAVE_XCURSOR +#include +#endif + #define THEME_NAME "X-GNOME-Metatheme/Name" #define THEME_COMMENT "X-GNOME-Metatheme/Comment" #define GTK_THEME_KEY "X-GNOME-Metatheme/GtkTheme" @@ -953,6 +960,7 @@ add_common_theme_dir_monitor (GnomeVFSURI *theme_dir_uri, return GNOME_VFS_OK; } +#ifdef HAVE_XCURSOR static GdkPixbuf * gdk_pixbuf_from_xcursor_image (XcursorImage *cursor) { GdkPixbuf *pixbuf; @@ -990,6 +998,7 @@ gdk_pixbuf_from_xcursor_image (XcursorImage *cursor) { return pixbuf; } + static void look_for_cursor_theme (const gchar *theme_dir) { @@ -1047,6 +1056,7 @@ look_for_cursor_theme (const gchar *theme_dir) g_free (cursors_dir); } +#endif /* HAVE_XCURSOR */ static GnomeVFSResult add_common_icon_theme_dir_monitor (GnomeVFSURI *theme_dir_uri, @@ -1062,8 +1072,10 @@ add_common_icon_theme_dir_monitor (GnomeVFSURI *theme_dir_uri uri_string = gnome_vfs_uri_to_string (theme_dir_uri, GNOME_VFS_URI_HIDE_TOPLEVEL_METHOD); +#ifdef HAVE_XCURSOR /* Look for cursor theme in the theme directory */ look_for_cursor_theme (uri_string); +#endif /* Add the handle for this directory */ index_uri = gnome_vfs_uri_append_file_name (theme_dir_uri, "index.theme"); @@ -1702,6 +1714,113 @@ gnome_theme_info_register_theme_change (ThemeChangedCallback func, callbacks = g_list_prepend (callbacks, callback_data); } +#ifndef HAVE_XCURSOR +static gchar * +read_current_cursor_font (void) +{ + DIR *dir; + gchar *dir_name; + struct dirent *file_dirent; + + dir_name = g_build_filename (g_get_home_dir (), ".gnome2/share/cursor-fonts", NULL); + if (! g_file_test (dir_name, G_FILE_TEST_EXISTS)) { + g_free (dir_name); + return NULL; + } + + dir = opendir (dir_name); + + while ((file_dirent = readdir (dir)) != NULL) { + struct stat st; + gchar *link_name; + + link_name = g_build_filename (dir_name, file_dirent->d_name, NULL); + if (lstat (link_name, &st)) { + g_free (link_name); + continue; + } + + if (S_ISLNK (st.st_mode)) { + gint length; + gchar target[256]; + + length = readlink (link_name, target, 255); + if (length > 0) { + gchar *retval; + target[length] = '\0'; + retval = g_strdup (target); + g_free (link_name); + closedir (dir); + return retval; + } + + } + g_free (link_name); + } + g_free (dir_name); + closedir (dir); + return NULL; +} + +static void +read_cursor_fonts (void) +{ + gchar* cursor_font; + gint i; + + static const gchar* builtins[][4] = { + { + "gnome/cursor-fonts/cursor-normal.pcf", + N_("Default Pointer"), + N_("Default Pointer - Current"), + "mouse-cursor-normal.png" + }, { + "gnome/cursor-fonts/cursor-white.pcf", + N_("White Pointer"), + N_("White Pointer - Current"), + "mouse-cursor-white.png" + }, { + "gnome/cursor-fonts/cursor-large.pcf", + N_("Large Pointer"), + N_("Large Pointer - Current"), + "mouse-cursor-normal-large.png" + }, { + "gnome/cursor-fonts/cursor-large-white.pcf", + N_("Large White Pointer - Current"), + N_("Large White Pointer"), + "mouse-cursor-white-large.png" + } + }; + + cursor_font = read_current_cursor_font(); + + if (!cursor_font) + cursor_font = g_strdup (builtins[0][0]); + + for (i = 0; i < G_N_ELEMENTS (builtins); i++) { + GnomeThemeCursorInfo *theme_info; + gchar *filename; + + theme_info = gnome_theme_cursor_info_new (); + theme_info->priority = 0; + + filename = g_build_filename (GNOMECC_DATA_DIR "/pixmaps", builtins[i][3], NULL); + theme_info->thumbnail = gdk_pixbuf_new_from_file (filename, NULL); + g_free (filename); + + theme_info->name = theme_info->path = g_build_filename (GNOMECC_DATA_DIR, builtins[i][0], NULL); + + if (!strcmp (theme_info->path, cursor_font)) + theme_info->label = g_strdup (builtins[i][2]); + else + theme_info->label = g_strdup (builtins[i][1]); + + g_hash_table_insert (cursor_theme_hash_by_uri, theme_info->path, theme_info); + add_data_to_hash_by_name (cursor_theme_hash_by_name, theme_info->name, theme_info); + } +} +#endif /* !HAVE_XCURSOR */ + void gnome_theme_init (gboolean *monitor_not_added) { @@ -1778,6 +1897,11 @@ gnome_theme_init (gboolean *monitor_not_added) result = add_top_icon_theme_dir_monitor (top_theme_dir_uri, &real_monitor_not_added, 0, NULL); gnome_vfs_uri_unref (top_theme_dir_uri); +#ifndef HAVE_XCURSOR + /* If we don't have Xcursor, use the built-in cursor fonts instead */ + read_cursor_fonts (); +#endif + /* done */ initted = TRUE; initting = FALSE; diff --git a/capplets/common/gnome-theme-info.h b/capplets/common/gnome-theme-info.h index 705978eae..0dfaafdb5 100644 --- a/capplets/common/gnome-theme-info.h +++ b/capplets/common/gnome-theme-info.h @@ -23,6 +23,8 @@ #ifndef GNOME_THEME_INFO_H #define GNOME_THEME_INFO_H +#include + #include #include #include @@ -75,6 +77,9 @@ struct _GnomeThemeCursorInfo { gint priority; GArray *sizes; GdkPixbuf *thumbnail; +#ifndef HAVE_XCURSOR + gchar *label; +#endif }; typedef struct _GnomeThemeMetaInfo GnomeThemeMetaInfo;