Commit 3547b56d authored by Behdad Esfahbod's avatar Behdad Esfahbod Committed by Behdad Esfahbod

(Commit this again)

2008-06-07  Behdad Esfahbod  <behdad@gnome.org>

        (Commit this again)

        * configure.ac: Check for fontconfig instead of xft2.

        * plugins/xsettings/Makefile.am:
        * plugins/xsettings/gsd-xsettings-manager.c (fontconfig_callback),
        (gnome_xsettings_manager_start), (gnome_xsettings_manager_stop):
        Send a Fontconfig/Timestamp xsettings notification whenever
        fontconfig configurations change. (bug #490374)

        * plugins/xsettings/fontconfig-monitor.c:
        * plugins/xsettings/fontconfig-monitor.h:
        Monitor fontconfig configuration files using gio.


svn path=/trunk/; revision=370
parent b372974f
2008-06-07 Behdad Esfahbod <behdad@gnome.org>
(Commit this again)
* configure.ac: Check for fontconfig instead of xft2.
* plugins/xsettings/Makefile.am:
* plugins/xsettings/gsd-xsettings-manager.c (fontconfig_callback),
(gnome_xsettings_manager_start), (gnome_xsettings_manager_stop):
Send a Fontconfig/Timestamp xsettings notification whenever
fontconfig configurations change. (bug #490374)
* plugins/xsettings/fontconfig-monitor.c:
* plugins/xsettings/fontconfig-monitor.h:
Monitor fontconfig configuration files using gio.
==================== 2.23.3 ======================
2008-06-03 Jens Granseuer <jensgr@gmx.net>
......
......@@ -175,12 +175,15 @@ AC_CHECK_LIB(Xrandr, XRRUpdateConfiguration,
AC_SUBST(RANDR_LIBS)
dnl ---------------------------------------------------------------------------
dnl - XFT2
dnl - Fontconfig
dnl ---------------------------------------------------------------------------
if $PKG_CONFIG --exists xft; then
AC_DEFINE(HAVE_XFT2, 1, [Define if Xft functionality is available])
fi
have_fontconfig=no
PKG_CHECK_MODULES(FONTCONFIG, fontconfig,
[AC_DEFINE(HAVE_FONTCONFIG, 1, [Define if Fontconfig functionality is available])
have_fontconfig=yes],
AC_MSG_RESULT([no]))
AM_CONDITIONAL(HAVE_FONTCONFIG, test x"$have_fontconfig" = "xyes")
dnl ---------------------------------------------------------------------------
dnl - Keyboard plugin stuff
......
......@@ -32,6 +32,18 @@ libxsettings_la_LIBADD = \
$(SETTINGS_PLUGIN_LIBS) \
$(NULL)
if HAVE_FONTCONFIG
libxsettings_la_SOURCES += \
fontconfig-monitor.h \
fontconfig-monitor.c \
$(NULL)
libxsettings_la_CFLAGS += \
$(FONTCONFIG_CFLAGS)
libxsettings_la_LIBADD += \
$(FONTCONFIG_LIBS)
endif
plugin_in_files = \
xsettings.gnome-settings-plugin.in \
$(NULL)
......
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
*
* Copyright (C) 2008 Red Hat, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Author: Behdad Esfahbod, Red Hat, Inc.
*/
#include "fontconfig-monitor.h"
#include <gio/gio.h>
#include <fontconfig/fontconfig.h>
#define TIMEOUT_SECONDS 2
static void
stuff_changed (GFileMonitor *monitor,
GFile *file,
GFile *other_file,
GFileMonitorEvent event_type,
gpointer handle);
static void
monitor_files (GPtrArray *monitors,
FcStrList *list,
gpointer data)
{
const char *str;
while ((str = (const char *) FcStrListNext (list))) {
GFile *file;
GFileMonitor *monitor;
file = g_file_new_for_path (str);
if (g_file_test (str, G_FILE_TEST_IS_DIR))
monitor = g_file_monitor_directory (file, G_FILE_MONITOR_NONE, NULL, NULL);
else
monitor = g_file_monitor_file (file, G_FILE_MONITOR_NONE, NULL, NULL);
g_object_unref (file);
if (!monitor)
continue;
g_signal_connect (monitor, "changed", G_CALLBACK (stuff_changed), data);
g_ptr_array_add (monitors, monitor);
}
FcStrListDone (list);
}
struct _fontconfig_monitor_handle {
GPtrArray *monitors;
guint timeout;
GFunc notify_callback;
gpointer notify_data;
};
static GPtrArray *
monitors_create (gpointer data)
{
GPtrArray *monitors = g_ptr_array_new ();
monitor_files (monitors, FcConfigGetConfigFiles (NULL), data);
monitor_files (monitors, FcConfigGetFontDirs (NULL) , data);
return monitors;
}
static void
monitors_free (GPtrArray *monitors)
{
if (!monitors)
return;
g_ptr_array_foreach (monitors, (GFunc) g_object_unref, NULL);
g_ptr_array_free (monitors, TRUE);
}
static gboolean
update (gpointer data)
{
fontconfig_monitor_handle_t *handle = data;
gboolean notify = FALSE;
handle->timeout = 0;
if (!FcConfigUptoDate (NULL) && FcInitReinitialize ()) {
notify = TRUE;
monitors_free (handle->monitors);
handle->monitors = monitors_create (data);
}
/* we finish modifying handle before calling the notify callback,
* allowing the callback to free the monitor if it decides to. */
if (notify && handle->notify_callback)
handle->notify_callback (data, handle->notify_data);
return FALSE;
}
static void
stuff_changed (GFileMonitor *monitor G_GNUC_UNUSED,
GFile *file G_GNUC_UNUSED,
GFile *other_file G_GNUC_UNUSED,
GFileMonitorEvent event_type G_GNUC_UNUSED,
gpointer data)
{
fontconfig_monitor_handle_t *handle = data;
/* wait for quiescence */
if (handle->timeout)
g_source_remove (handle->timeout);
handle->timeout = g_timeout_add_seconds (TIMEOUT_SECONDS, update, data);
}
fontconfig_monitor_handle_t *
fontconfig_monitor_start (GFunc notify_callback,
gpointer notify_data)
{
fontconfig_monitor_handle_t *handle = g_slice_new0 (fontconfig_monitor_handle_t);
handle->notify_callback = notify_callback;
handle->notify_data = notify_data;
handle->monitors = monitors_create (handle);
return handle;
}
void
fontconfig_monitor_stop (fontconfig_monitor_handle_t *handle)
{
if (handle->timeout)
g_source_remove (handle->timeout);
handle->timeout = 0;
monitors_free (handle->monitors);
handle->monitors = NULL;
}
#ifdef FONTCONFIG_MONITOR_TEST
static void
yay (void)
{
g_message ("yay");
}
int
main (void)
{
GMainLoop *loop;
g_type_init ();
fontconfig_monitor_start ((GFunc) yay, NULL);
loop = g_main_loop_new (NULL, TRUE);
g_main_loop_run (loop);
return 0;
}
#endif
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
*
* Copyright (C) 2008 Red Hat, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Author: Behdad Esfahbod, Red Hat, Inc.
*/
#ifndef __FONTCONFIG_MONITOR_H
#define __FONTCONFIG_MONITOR_H
#include <glib.h>
G_BEGIN_DECLS
typedef struct _fontconfig_monitor_handle fontconfig_monitor_handle_t;
fontconfig_monitor_handle_t *
fontconfig_monitor_start (GFunc notify_callback,
gpointer notify_data);
void fontconfig_monitor_stop (fontconfig_monitor_handle_t *handle);
G_END_DECLS
#endif /* __FONTCONFIG_MONITOR_H */
......@@ -28,6 +28,7 @@
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <time.h>
#include <glib.h>
#include <glib/gi18n.h>
......@@ -40,6 +41,9 @@
#include "gnome-settings-profile.h"
#include "gsd-xsettings-manager.h"
#include "xsettings-manager.h"
#ifdef HAVE_FONTCONFIG
#include "fontconfig-monitor.h"
#endif /* HAVE_FONTCONFIG */
#define GNOME_XSETTINGS_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GNOME_TYPE_XSETTINGS_MANAGER, GnomeXSettingsManagerPrivate))
......@@ -47,7 +51,7 @@
#define GTK_SETTINGS_DIR "/desktop/gtk"
#define INTERFACE_SETTINGS_DIR "/desktop/gnome/interface"
#ifdef HAVE_XFT2
#ifdef HAVE_FONTCONFIG
#define FONT_RENDER_DIR "/desktop/gnome/font_rendering"
#define FONT_ANTIALIASING_KEY FONT_RENDER_DIR "/antialiasing"
#define FONT_HINTING_KEY FONT_RENDER_DIR "/hinting"
......@@ -68,7 +72,7 @@
#define DPI_LOW_REASONABLE_VALUE 50
#define DPI_HIGH_REASONABLE_VALUE 500
#endif /* HAVE_XFT2 */
#endif /* HAVE_FONTCONFIG */
typedef struct _TranslationEntry TranslationEntry;
typedef void (* TranslationFunc) (GnomeXSettingsManager *manager,
......@@ -87,6 +91,9 @@ struct GnomeXSettingsManagerPrivate
{
XSettingsManager **managers;
guint notify[4];
#ifdef HAVE_FONTCONFIG
fontconfig_monitor_handle_t *fontconfig_handle;
#endif /* HAVE_FONTCONFIG */
};
#define GSD_XSETTINGS_ERROR gsd_xsettings_error_quark ()
......@@ -207,7 +214,7 @@ static TranslationEntry translations [] = {
{ "/desktop/gnome/interface/show_unicode_menu", "Gtk/ShowUnicodeMenu", GCONF_VALUE_BOOL, translate_bool_int },
};
#ifdef HAVE_XFT2
#ifdef HAVE_FONTCONFIG
static double
dpi_from_pixels_and_mm (int pixels,
int mm)
......@@ -536,7 +543,23 @@ xft_callback (GConfClient *client,
}
}
#endif /* HAVE_XFT2 */
static void
fontconfig_callback (fontconfig_monitor_handle_t *handle,
GnomeXSettingsManager *manager)
{
int i;
int timestamp = time (NULL);
gnome_settings_profile_start (NULL);
for (i = 0; manager->priv->managers [i]; i++) {
xsettings_manager_set_int (manager->priv->managers [i], "Fontconfig/Timestamp", timestamp);
xsettings_manager_notify (manager->priv->managers [i]);
}
gnome_settings_profile_end (NULL);
}
#endif /* HAVE_FONTCONFIG */
static const char *
type_to_string (GConfValueType type)
......@@ -746,13 +769,15 @@ gnome_xsettings_manager_start (GnomeXSettingsManager *manager,
INTERFACE_SETTINGS_DIR,
(GConfClientNotifyFunc) xsettings_callback);
#ifdef HAVE_XFT2
#ifdef HAVE_FONTCONFIG
manager->priv->notify[3] =
register_config_callback (manager, client,
FONT_RENDER_DIR,
(GConfClientNotifyFunc) xft_callback);
update_xft_settings (manager, client);
#endif /* HAVE_XFT */
manager->priv->fontconfig_handle = fontconfig_monitor_start ((GFunc) fontconfig_callback, manager);
#endif /* HAVE_FONTCONFIG */
g_object_unref (client);
......@@ -793,9 +818,12 @@ gnome_xsettings_manager_stop (GnomeXSettingsManager *manager)
gconf_client_remove_dir (client, MOUSE_SETTINGS_DIR, NULL);
gconf_client_remove_dir (client, GTK_SETTINGS_DIR, NULL);
gconf_client_remove_dir (client, INTERFACE_SETTINGS_DIR, NULL);
#ifdef HAVE_XFT2
#ifdef HAVE_FONTCONFIG
gconf_client_remove_dir (client, FONT_RENDER_DIR, NULL);
#endif
fontconfig_monitor_stop (manager->priv->fontconfig_handle);
manager->priv->fontconfig_handle = NULL;
#endif /* HAVE_FONTCONFIG */
for (i = 0; i < G_N_ELEMENTS (p->notify); ++i) {
if (p->notify[i] != 0) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment