Re-add basic support for cursor themes for X servers without the Xcursor

2007-07-26  Denis Washington <denisw@svn.gnome.org>

	* 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
This commit is contained in:
Denis Washington 2007-07-26 16:15:35 +00:00 committed by Denis Washington
parent 03b9c9b1e1
commit 78b4743519
10 changed files with 230 additions and 5 deletions

View file

@ -1,3 +1,14 @@
2007-07-26 Denis Washington <denisw@svn.gnome.org>
* 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 <thos@gnome.org>
Patch by: Dennis Cranston <dennis_cranston@yahoo.com>

View file

@ -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 ("<small><i>%s</i></small>", 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 ("<small><i>%s</i></small>", 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 */

View file

@ -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 *

View file

@ -2277,11 +2277,45 @@ Text only</property>
</packing>
</child>
<child>
<widget class="GtkVBox" id="vbox32">
<widget class="GtkVBox" id="cursor_vbox">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="border_width">12</property>
<property name="spacing">6</property>
<child>
<widget class="GtkHBox" id="cursor_message_hbox">
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="spacing">6</property>
<property name="no_show_all">True</property>
<child>
<widget class="GtkImage" id="image3">
<property name="visible">True</property>
<property name="stock">gtk-dialog-info</property>
<property name="icon_size">5</property>
</widget>
<packing>
<property name="expand">False</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label5">
<property name="width_request">280</property>
<property name="visible">True</property>
<property name="label" translatable="yes">Changing your cursor theme takes effect the next time you log in.</property>
<property name="wrap">True</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkScrolledWindow" id="scrolledwindow8">
<property name="visible">True</property>
@ -2302,12 +2336,12 @@ Text only</property>
</widget>
</child>
<child>
<widget class="GtkHBox" id="hbox6">
<widget class="GtkHBox" id="cursor_size_hbox">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="spacing">12</property>
<child>
<widget class="GtkLabel" id="label5">
<widget class="GtkLabel" id="cursor_size_label">
<property name="label" translatable="yes">Size:</property>
</widget>
<packing>

View file

@ -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);
}

View file

@ -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"

View file

@ -1,3 +1,12 @@
2007-07-25 Denis Washington <denisw@svn.gnome.org>
* 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 <denisw@svn.gnome.org>
* gnome-theme-info.h:

View file

@ -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);
}

View file

@ -1,6 +1,9 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
#include <X11/Xcursor/Xcursor.h>
#include <libgnomevfs/gnome-vfs-init.h>
#include <libgnomevfs/gnome-vfs-ops.h>
#include <libgnomevfs/gnome-vfs-utils.h>
@ -10,6 +13,10 @@
#include "gnome-theme-info.h"
#include "gtkrc-utils.h"
#ifdef HAVE_XCURSOR
#include <X11/Xcursor/Xcursor.h>
#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;

View file

@ -23,6 +23,8 @@
#ifndef GNOME_THEME_INFO_H
#define GNOME_THEME_INFO_H
#include <config.h>
#include <glib.h>
#include <libgnomevfs/gnome-vfs.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
@ -75,6 +77,9 @@ struct _GnomeThemeCursorInfo {
gint priority;
GArray *sizes;
GdkPixbuf *thumbnail;
#ifndef HAVE_XCURSOR
gchar *label;
#endif
};
typedef struct _GnomeThemeMetaInfo GnomeThemeMetaInfo;