Hook up cursor code.

Tue Feb 19 23:52:17 2002  Jonathan Blandford  <jrb@redhat.com>

	* gnome-mouse-properties.c (cursor_font_changed): Hook up cursor code.

Tue Feb 19 23:53:06 2002  Jonathan Blandford  <jrb@redhat.com>

	* gnome-settings-font.c: set the font path and handle cursors.
This commit is contained in:
Jonathan Blandford 2002-02-20 05:11:10 +00:00 committed by Jonathan Blandford
parent 57cb400a75
commit 03509906b6
12 changed files with 419 additions and 13 deletions

View file

@ -1,3 +1,7 @@
Tue Feb 19 23:52:17 2002 Jonathan Blandford <jrb@redhat.com>
* gnome-mouse-properties.c (cursor_font_changed): Hook up cursor code.
Fri Feb 8 01:41:40 2002 Jonathan Blandford <jrb@redhat.com>
* Makefile.am (pixmap_DATA): install cursor images.

View file

@ -17,6 +17,13 @@ pixmap_DATA = \
mouse-cursor-normal-large.png \
mouse-cursor-white-large.png
cursorfontdir = $(datadir)/gnome/cursor-fonts
cursorfont_DATA = \
cursor-large.pcf.gz \
cursor-white.pcf.gz \
cursor-large-white.pcf.gz
Gladedir = $(GNOMECC_GLADE_DIR)
Glade_DATA = gnome-mouse-properties.glade
@ -32,5 +39,5 @@ desktop_DATA = $(Desktop_in_files:.desktop.in=.desktop)
INCLUDES = $(GNOMECC_CAPPLETS_CFLAGS)
CLEANFILES = $(GNOMECC_CAPPLETS_CLEANFILES)
EXTRA_DIST = $(Glade_DATA) $(icons_DATA) $(Desktop_in_files) $(pixmap_DATA)
EXTRA_DIST = $(Glade_DATA) $(icons_DATA) $(Desktop_in_files) $(pixmap_DATA) $(cursorfont_DATA)

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -34,6 +34,9 @@
#include "capplet-util.h"
#include "gconf-property-editor.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
enum
{
@ -46,6 +49,7 @@ enum
{
COLUMN_PIXBUF,
COLUMN_TEXT,
COLUMN_FONT_PATH,
N_COLUMNS
};
@ -53,7 +57,7 @@ enum
* define the macro */
#define DOUBLE_CLICK_KEY "/desktop/gnome/peripherals/mouse/double_click"
#define CURSOR_FONT_KEY "/desktop/gnome/peripherals/mouse/cursor_font"
/* Write-once data; global for convenience. Set only by load_pixbufs */
GdkPixbuf *left_handed_pixbuf;
@ -318,13 +322,128 @@ load_pixbufs (void)
called = TRUE;
}
/* Set up the property editors in the dialog. */
static gchar *
read_cursor_font (void)
{
DIR *dir;
gchar *dir_name;
struct dirent *file_dirent;
dir_name = g_build_path (G_DIR_SEPARATOR_S, g_get_home_dir (), ".gnome/share/cursor-fonts", NULL);
if (! g_file_test (dir_name, G_FILE_TEST_EXISTS))
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);
return retval;
}
}
g_free (link_name);
}
return NULL;
}
static void
cursor_font_changed (GConfClient *client,
guint cnxn_id,
GConfEntry *entry,
gpointer user_data)
{
GtkTreeView *tree_view;
gchar *cursor_font;
gchar *cursor_text;
GtkTreeIter iter;
GtkTreeModel *model;
GtkTreeSelection *selection;
tree_view = GTK_TREE_VIEW (user_data);
selection = gtk_tree_view_get_selection (tree_view);
model = gtk_tree_view_get_model (tree_view);
cursor_font = gconf_client_get_string (client, CURSOR_FONT_KEY, NULL);
gtk_tree_model_get_iter_root (model, &iter);
do {
gchar *temp_cursor_font;
gtk_tree_model_get (model, &iter,
COLUMN_FONT_PATH, &temp_cursor_font,
-1);
if ((temp_cursor_font == NULL && cursor_font == NULL) ||
((temp_cursor_font != NULL && cursor_font != NULL) &&
(!strcmp (cursor_font, temp_cursor_font)))) {
if (!gtk_tree_selection_iter_is_selected (selection, &iter))
gtk_tree_selection_select_iter (selection, &iter);
g_free (temp_cursor_font);
g_free (cursor_font);
return;
}
g_free (temp_cursor_font);
} while (gtk_tree_model_iter_next (model, &iter));
/* we didn't find it; we add it to the end. */
gtk_list_store_append (GTK_LIST_STORE (model), &iter);
cursor_text = g_strdup_printf (_("<b>Unknown Cursor</b>\n%s"), cursor_font);
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
COLUMN_TEXT, cursor_text,
COLUMN_FONT_PATH, cursor_font,
-1);
gtk_tree_selection_select_iter (selection, &iter);
g_free (cursor_font);
g_free (cursor_text);
}
static void
cursor_changed (GtkTreeSelection *selection,
gpointer data)
{
GtkTreeModel *model = NULL;
GtkTreeIter iter;
gchar *cursor_font = NULL;
if (! gtk_tree_selection_get_selected (selection, &model, &iter))
return;
gtk_tree_model_get (model, &iter,
COLUMN_FONT_PATH, &cursor_font,
-1);
if (cursor_font != NULL)
gconf_client_set_string (gconf_client_get_default (),
CURSOR_FONT_KEY, cursor_font, NULL);
else
gconf_client_unset (gconf_client_get_default (),
CURSOR_FONT_KEY, NULL);
}
/* Set up the property editors in the dialog. */
static void
setup_dialog (GladeXML *dialog, GConfChangeSet *changeset)
{
GObject *peditor;
GtkWidget *tree_view;
GtkTreeSelection *selection;
GtkTreeModel *model;
GtkCellRenderer *renderer;
GtkTreeViewColumn *column;
@ -332,10 +451,15 @@ setup_dialog (GladeXML *dialog, GConfChangeSet *changeset)
GConfValue *value;
gchar *filename;
GdkPixbuf *pixbuf;
GnomeProgram *program;
GnomeProgram *program;
gchar *cursor_font;
gchar *font_path;
gchar *cursor_string;
gboolean found_default;
program = gnome_program_get ();
found_default = FALSE;
/* Buttons page */
/* Left-handed toggle */
peditor = gconf_peditor_new_boolean
@ -352,8 +476,13 @@ setup_dialog (GladeXML *dialog, GConfChangeSet *changeset)
/* Cursors page */
tree_view = WID ("cursor_tree");
model = (GtkTreeModel *) gtk_list_store_new (N_COLUMNS, GDK_TYPE_PIXBUF, G_TYPE_STRING);
cursor_font = read_cursor_font ();
model = (GtkTreeModel *) gtk_list_store_new (N_COLUMNS, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING);
gtk_tree_view_set_model (GTK_TREE_VIEW (tree_view), model);
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view));
gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
g_signal_connect (G_OBJECT (selection), "changed", G_CALLBACK (cursor_changed), NULL);
column = gtk_tree_view_column_new ();
renderer = gtk_cell_renderer_pixbuf_new ();
gtk_tree_view_column_pack_start (column, renderer, FALSE);
@ -366,44 +495,91 @@ setup_dialog (GladeXML *dialog, GConfChangeSet *changeset)
"markup", COLUMN_TEXT,
NULL);
/* Default cursor */
filename = gnome_program_locate_file (program, GNOME_FILE_DOMAIN_APP_PIXMAP, "mouse-cursor-normal.png", TRUE, NULL);
pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
g_free (filename);
gtk_list_store_append (GTK_LIST_STORE (model), &iter);
if (cursor_font == NULL) {
cursor_string = _("<b>Default Cursor - Current</b>\nThe default cursor that ships with X");
found_default = TRUE;
} else {
cursor_string = _("<b>Default Cursor</b>\nThe default cursor that ships with X");
}
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
COLUMN_PIXBUF, pixbuf,
COLUMN_TEXT, "<b>Default Cursor</b>\nThe default cursor that ships with X",
COLUMN_TEXT, cursor_string,
COLUMN_FONT_PATH, NULL,
-1);
/* Inverted cursor */
filename = gnome_program_locate_file (program, GNOME_FILE_DOMAIN_APP_PIXMAP, "mouse-cursor-white.png", TRUE, NULL);
pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
g_free (filename);
font_path = gnome_program_locate_file (program, GNOME_FILE_DOMAIN_DATADIR, "gnome/cursor-fonts/cursor-white.pcf.gz", FALSE, NULL);
gtk_list_store_append (GTK_LIST_STORE (model), &iter);
if (cursor_font && ! strcmp (cursor_font, font_path)) {
cursor_string = _("<b>White Cursor - Current</b>\nThe default cursor inverted");
found_default = TRUE;
} else {
cursor_string = _("<b>White Cursor</b>\nThe default cursor inverted");
}
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
COLUMN_PIXBUF, pixbuf,
COLUMN_TEXT, "<b>White Cursor</b>\nThe default cursor inverted",
COLUMN_TEXT, cursor_string,
COLUMN_FONT_PATH, font_path,
-1);
g_free (font_path);
/* Large cursor */
filename = gnome_program_locate_file (program, GNOME_FILE_DOMAIN_APP_PIXMAP, "mouse-cursor-normal-large.png", TRUE, NULL);
pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
g_free (filename);
font_path = gnome_program_locate_file (program, GNOME_FILE_DOMAIN_DATADIR, "gnome/cursor-fonts/cursor-large.pcf.gz", FALSE, NULL);
gtk_list_store_append (GTK_LIST_STORE (model), &iter);
if (cursor_font && ! strcmp (cursor_font, font_path)) {
cursor_string = _("<b>Large Cursor - Current</b>\nLarge version of normal cursor");
found_default = TRUE;
} else {
cursor_string = _("<b>Large Cursor</b>\nLarge version of normal cursor");
}
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
COLUMN_PIXBUF, pixbuf,
COLUMN_TEXT, "<b>Large Cursor</b>\nLarge version of normal cursor",
COLUMN_TEXT, cursor_string,
COLUMN_FONT_PATH, font_path,
-1);
g_free (font_path);
/* Large inverted cursor */
filename = gnome_program_locate_file (program, GNOME_FILE_DOMAIN_APP_PIXMAP, "mouse-cursor-white-large.png", TRUE, NULL);
pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
g_free (filename);
font_path = gnome_program_locate_file (program, GNOME_FILE_DOMAIN_DATADIR, "gnome/cursor-fonts/cursor-large-white.pcf.gz", FALSE, NULL);
gtk_list_store_append (GTK_LIST_STORE (model), &iter);
if (cursor_font && ! strcmp (cursor_font, font_path)) {
cursor_string = _("<b>Large White Cursor - Current</b>\nLarge version of white cursor");
found_default = TRUE;
} else {
cursor_string = _("<b>Large White Cursor</b>\nLarge version of white cursor");
}
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
COLUMN_PIXBUF, pixbuf,
COLUMN_TEXT, "<b>Large White Cursor</b>\nLarge version of white cursor",
COLUMN_TEXT, cursor_string,
COLUMN_FONT_PATH, font_path,
-1);
g_free (font_path);
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);
gconf_peditor_new_boolean
(changeset, "/desktop/gnome/peripherals/mouse/locate_pointer_id", WID ("locate_pointer_toggle"), NULL);
/* Motion page */
@ -432,6 +608,15 @@ setup_dialog (GladeXML *dialog, GConfChangeSet *changeset)
"conv-to-widget-cb", threshold_from_gconf,
"conv-from-widget-cb", gconf_value_float_to_int,
NULL);
/* listen to cursors changing */
gconf_client_notify_add (gconf_client_get_default (),
CURSOR_FONT_KEY, /* dir or key to listen to */
cursor_font_changed,
tree_view, NULL, NULL);
/* and set it up initially... */
cursor_font_changed (gconf_client_get_default (), 0, NULL, tree_view);
}
/* Construct the dialog */

View file

@ -352,7 +352,9 @@
</child>
<child>
<widget class="GtkLabel" id="label19">
<property name="label" translatable="yes">&lt;b&gt;Note:&lt;/b&gt; You will need to logout for this setting to take effect.</property>
<property name="label"
translatable="yes">&lt;b&gt;Note:&lt;/b&gt;
You will need to logout and log back in for this setting to take effect.</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">yes</property>
<property name="use_markup">yes</property>

View file

@ -1,3 +1,7 @@
Tue Feb 19 23:53:06 2002 Jonathan Blandford <jrb@redhat.com>
* gnome-settings-font.c: set the font path and handle cursors.
2002-02-13 Lauris Kaplinski <lauris@ximian.com>
* gnome-settings-xsettings.c: #include <string.h> to kill warning

View file

@ -5,6 +5,8 @@ bin_PROGRAMS=gnome2-settings-daemon
gnome2_settings_daemon_SOURCES = \
gnome-settings-daemon.h \
gnome-settings-daemon.c \
gnome-settings-font.h \
gnome-settings-font.c \
gnome-settings-mouse.h \
gnome-settings-mouse.c \
gnome-settings-keyboard.h \

View file

@ -36,6 +36,7 @@
#include "gnome-settings-daemon.h"
#include "gnome-settings-xsettings.h"
#include "gnome-settings-font.h"
#include "gnome-settings-mouse.h"
#include "gnome-settings-keyboard.h"
#include "gnome-settings-background.h"
@ -168,6 +169,7 @@ main (int argc, char **argv)
*/
client = gconf_client_get_default ();
gnome_settings_xsettings_init (client);
gnome_settings_font_init (client);
gnome_settings_mouse_init (client);
gnome_settings_keyboard_init (client);
gnome_settings_background_init (client);
@ -200,6 +202,7 @@ main (int argc, char **argv)
gdk_window_add_filter (NULL, manager_event_filter, NULL);
gnome_settings_xsettings_load (client);
gnome_settings_font_load (client);
gnome_settings_mouse_load (client);
gnome_settings_sound_load (client);
gnome_settings_background_load (client);

View file

@ -0,0 +1,174 @@
#include <gdk/gdkx.h>
#include <gconf/gconf.h>
#include "gnome-settings-daemon.h"
#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <dirent.h>
#include <string.h>
static void
load_cursor (GConfClient *client)
{
DIR *dir;
gchar *font_dir_name;
gchar *dir_name;
struct dirent *file_dirent;
gchar *cursor_font;
gchar **font_path;
gchar **new_font_path;
gint n_fonts;
gint new_n_fonts;
gint i;
gchar *mkfontdir_cmd;
/* setting up the dir */
font_dir_name = g_build_path (G_DIR_SEPARATOR_S, g_get_home_dir (), ".gnome", NULL);
if (! g_file_test (font_dir_name, G_FILE_TEST_EXISTS))
mkdir (font_dir_name, 0755);
g_free (font_dir_name);
font_dir_name = g_build_path (G_DIR_SEPARATOR_S, g_get_home_dir (), ".gnome/share", NULL);
if (! g_file_test (font_dir_name, G_FILE_TEST_EXISTS))
mkdir (font_dir_name, 0755);
g_free (font_dir_name);
font_dir_name = g_build_path (G_DIR_SEPARATOR_S, g_get_home_dir (), ".gnome/share/fonts", NULL);
if (! g_file_test (font_dir_name, G_FILE_TEST_EXISTS))
mkdir (font_dir_name, 0755);
if (! g_file_test (font_dir_name, G_FILE_TEST_IS_DIR))
{
GtkWidget *dialog;
dialog = gtk_message_dialog_new (NULL,
0,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
"Cannot create the directory \"%s\".\n"\
"This is needed to allow changing cursors.",
font_dir_name);
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
g_free (font_dir_name);
return;
}
dir_name = g_build_path (G_DIR_SEPARATOR_S, g_get_home_dir (), ".gnome/share/cursor-fonts", NULL);
if (! g_file_test (dir_name, G_FILE_TEST_EXISTS))
mkdir (dir_name, 0755);
if (! g_file_test (dir_name, G_FILE_TEST_IS_DIR))
{
GtkWidget *dialog;
dialog = gtk_message_dialog_new (NULL,
0,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
"Cannot create the directory \"%s\".\n"\
"This is needed to allow changing cursors.",
dir_name);
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
g_free (dir_name);
return;
}
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))
unlink (link_name);
}
closedir (dir);
cursor_font = gconf_client_get_string (client,
"/desktop/gnome/peripherals/mouse/cursor_font",
NULL);
if ((cursor_font != NULL) &&
(g_file_test (cursor_font, G_FILE_TEST_IS_REGULAR)) &&
(g_path_is_absolute (cursor_font)))
{
gchar *newpath;
gchar *font_name;
font_name = strrchr (cursor_font, G_DIR_SEPARATOR);
newpath = g_build_filename (dir_name, font_name);
symlink (cursor_font, newpath);
g_free (newpath);
}
g_free (cursor_font);
/* run mkfontdir */
mkfontdir_cmd = g_strdup_printf ("mkfontdir %s %s", dir_name, font_dir_name);
g_spawn_command_line_async (mkfontdir_cmd, NULL);
g_free (mkfontdir_cmd);
/* Set the font path */
font_path = XGetFontPath (gdk_x11_get_default_xdisplay (), &n_fonts);
new_n_fonts = n_fonts;
if (n_fonts == 0 || strcmp (font_path[0], dir_name))
new_n_fonts++;
if (n_fonts == 0 || strcmp (font_path[n_fonts-1], font_dir_name))
new_n_fonts++;
new_font_path = g_new0 (gchar*, new_n_fonts);
if (n_fonts == 0 || strcmp (font_path[0], dir_name))
{
new_font_path[0] = dir_name;
for (i = 0; i < n_fonts; i++)
new_font_path [i+1] = font_path [i];
}
else
{
for (i = 0; i < n_fonts; i++)
new_font_path [i] = font_path [i];
}
if (n_fonts == 0 || strcmp (font_path[n_fonts-1], font_dir_name))
{
new_font_path[new_n_fonts-1] = font_dir_name;
}
gdk_error_trap_push ();
XSetFontPath (gdk_display, new_font_path, new_n_fonts);
gdk_flush ();
gdk_error_trap_pop ();
XFreeFontPath (font_path);
g_free (new_font_path);
g_free (font_dir_name);
g_free (dir_name);
}
void
gnome_settings_font_init (GConfClient *client)
{
load_cursor (client);
}
void
gnome_settings_font_load (GConfClient *client)
{
}

View file

@ -0,0 +1,25 @@
/*
* 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 FONT_SETTINGS_H
#define FONT_SETTINGS_H
#include <gconf/gconf.h>
void gnome_settings_font_init (GConfClient *client);
void gnome_settings_font_load (GConfClient *client);
#endif