From 74b8297ee3b80b0f1fb45fc9b43947127005ad13 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 6 Jun 2008 16:39:37 +0000 Subject: [PATCH] =?UTF-8?q?Bug=20536185=20=E2=80=93=20monitor=20font=20con?= =?UTF-8?q?figuration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 2008-06-06 Behdad Esfahbod Bug 536185 – monitor font configuration * configure.in: * gdk/x11/gdksettings.c: * gtk/gtksettings.c (gtk_settings_class_init), (gtk_settings_notify), (settings_update_fontconfig): Monitor xsettings key Fontconfig/Timestamp and upon change, reread fontconfig configuration, clear Pango's caches, and redraw all widgets. svn path=/trunk/; revision=20324 --- ChangeLog | 12 +++++++++ configure.in | 3 +++ gdk/x11/gdksettings.c | 6 +++-- gtk/gtksettings.c | 59 ++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 77 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 015934280c..722f97eedc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2008-06-06 Behdad Esfahbod + + Bug 536185 – monitor font configuration + + * configure.in: + * gdk/x11/gdksettings.c: + * gtk/gtksettings.c (gtk_settings_class_init), + (gtk_settings_notify), (settings_update_fontconfig): + Monitor xsettings key Fontconfig/Timestamp and upon change, + reread fontconfig configuration, clear Pango's caches, and + redraw all widgets. + 2008-06-06 Ross Burton * gtk/gtkwindow.c: diff --git a/configure.in b/configure.in index f1487993de..e11c0cddde 100644 --- a/configure.in +++ b/configure.in @@ -1677,6 +1677,9 @@ else fi GTK_PACKAGES="atk cairo gio-2.0" +if test "x$gdktarget" = "xx11"; then + GTK_PACKAGES="$GTK_PACKAGES pangoft2" +fi GTK_EXTRA_LIBS= GTK_EXTRA_CFLAGS= GTK_DEP_LIBS="$GDK_EXTRA_LIBS $GTK_DEP_LIBS_FOR_X `$PKG_CONFIG --libs $GDK_PIXBUF_PACKAGES $PANGO_PACKAGES $GTK_PACKAGES_FOR_X $GTK_PACKAGES` $GTK_EXTRA_LIBS $GDK_PIXBUF_EXTRA_LIBS" diff --git a/gdk/x11/gdksettings.c b/gdk/x11/gdksettings.c index 6ef672e2ff..22878ab253 100644 --- a/gdk/x11/gdksettings.c +++ b/gdk/x11/gdksettings.c @@ -69,7 +69,8 @@ static const char gdk_settings_names[] = "Gtk/EnableAccels\0" "gtk-enable-accels\0" "Gtk/EnableMnemonics\0" "gtk-enable-mnemonics\0" "Gtk/ScrolledWindowPlacement\0" "gtk-scrolled-window-placement\0" - "Gtk/IMModule\0" "gtk-im-module\0"; + "Gtk/IMModule\0" "gtk-im-module\0" + "Fontconfig/Timestamp\0" "gtk-fontconfig-timestamp\0"; static const struct @@ -116,5 +117,6 @@ static const struct { 1326, 1343 }, { 1361, 1381 }, { 1402, 1430 }, - { 1460, 1473 } + { 1460, 1473 }, + { 1487, 1508 } }; diff --git a/gtk/gtksettings.c b/gtk/gtksettings.c index 3ce2046ebc..e0a6d72f98 100644 --- a/gtk/gtksettings.c +++ b/gtk/gtksettings.c @@ -16,6 +16,8 @@ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#define PANGO_ENABLE_BACKEND /* for pango_fc_font_map_cache_clear() */ + #include #include @@ -30,6 +32,7 @@ #ifdef GDK_WINDOWING_X11 #include "x11/gdkx.h" +#include #endif #define DEFAULT_TIMEOUT_INITIAL 200 @@ -108,7 +111,8 @@ enum { PROP_ENABLE_ACCELS, PROP_RECENT_FILES_LIMIT, PROP_IM_MODULE, - PROP_RECENT_FILES_MAX_AGE + PROP_RECENT_FILES_MAX_AGE, + PROP_FONTCONFIG_TIMESTAMP }; @@ -134,6 +138,7 @@ static void settings_update_modules (GtkSettings *setting static void settings_update_cursor_theme (GtkSettings *settings); static void settings_update_resolution (GtkSettings *settings); static void settings_update_font_options (GtkSettings *settings); +static gboolean settings_update_fontconfig (GtkSettings *settings); #endif static void settings_update_color_scheme (GtkSettings *settings); @@ -841,6 +846,17 @@ gtk_settings_class_init (GtkSettingsClass *class) GTK_PARAM_READWRITE), NULL); g_assert (result == PROP_RECENT_FILES_MAX_AGE); + + result = settings_install_property_parser (class, + g_param_spec_int ("gtk-fontconfig-timestamp", + P_("Fontconfig configuration timestamp"), + P_("Timestamp of current fontconfig configuration"), + G_MININT, G_MAXINT, 0, + GTK_PARAM_READWRITE), + NULL); + + g_assert (result == PROP_FONTCONFIG_TIMESTAMP); + } static void @@ -1054,6 +1070,10 @@ gtk_settings_notify (GObject *object, settings_update_font_options (settings); gtk_rc_reset_styles (GTK_SETTINGS (object)); break; + case PROP_FONTCONFIG_TIMESTAMP: + if (settings_update_fontconfig (settings)) + gtk_rc_reset_styles (GTK_SETTINGS (object)); + break; case PROP_CURSOR_THEME_NAME: case PROP_CURSOR_THEME_SIZE: settings_update_cursor_theme (settings); @@ -1951,6 +1971,43 @@ settings_update_font_options (GtkSettings *settings) cairo_font_options_destroy (options); } +#ifdef GDK_WINDOWING_X11 +static gboolean +settings_update_fontconfig (GtkSettings *settings) +{ + static guint last_update_timestamp; + static gboolean last_update_needed; + + gint timestamp; + + g_object_get (settings, + "gtk-fontconfig-timestamp", ×tamp, + NULL); + + /* if timestamp is the same as last_update_timestamp, we already have + * updated fontconig on this timestamp (another screen requested it perhaps?), + * just return the cached result.*/ + + if (timestamp != last_update_timestamp) + { + PangoFontMap *fontmap = pango_cairo_font_map_get_default (); + gboolean update_needed = FALSE; + + if (PANGO_IS_FC_FONT_MAP (fontmap) && + !FcConfigUptoDate (NULL) && FcInitReinitialize ()) + { + update_needed = TRUE; + pango_fc_font_map_cache_clear (PANGO_FC_FONT_MAP (fontmap)); + } + + last_update_timestamp = timestamp; + last_update_needed = update_needed; + } + + return last_update_needed; +} +#endif /* GDK_WINDOWING_X11 */ + static void settings_update_resolution (GtkSettings *settings) {