summaryrefslogtreecommitdiff
path: root/src/xsettings.c
diff options
context:
space:
mode:
authorJan Djärv <jan.h.d@swipnet.se>2011-06-30 16:00:26 +0200
committerJan Djärv <jan.h.d@swipnet.se>2011-06-30 16:00:26 +0200
commit9851bfc58dcf38d05e469112790c514c3fd6fbf7 (patch)
tree1931ced33d357c5100d1ce73a3e0a07e28eb7b98 /src/xsettings.c
parent656e1aab13d416dc06ca1138997e6396317321bc (diff)
downloademacs-9851bfc58dcf38d05e469112790c514c3fd6fbf7.tar.gz
Add GSettings support (GConf is going away).
* configure.in (gsettings): New option and check for GSettings. * src/Makefile.in (SETTINGS_CFLAGS, SETTINGS_LIBS): Renamed from GCONF_CFLAGS/LIBS. * src/xsettings.c: Include glib.h if HAVE_GSETTINGS. Let HAVE_GSETTINGS override HAVE_GCONF. (store_monospaced_changed): New function. (EMACS_SETTINGS): A new type derived from GObject to handle GSettings notifications. (emacs_settings_constructor, emacs_settings_get_property) (emacs_settings_set_property, emacs_settings_class_init): New functions. (gsettings_client, gsettings_obj): New variables. (GSETTINGS_SCHEMA): New define. (something_changedCB): Call store_monospaced_changed. (init_gsettings): New function. (xsettings_initialize): Call init_gsettings. (syms_of_xsettings): Initialize gsettings_client, gsettings_obj to NULL.
Diffstat (limited to 'src/xsettings.c')
-rw-r--r--src/xsettings.c242
1 files changed, 217 insertions, 25 deletions
diff --git a/src/xsettings.c b/src/xsettings.c
index 5412cf426f8..09a5d31d01f 100644
--- a/src/xsettings.c
+++ b/src/xsettings.c
@@ -34,9 +34,15 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
#include <X11/Xproto.h>
+#define HAVE_GSETTINGS
+#ifdef HAVE_GSETTINGS
+#include <glib.h>
+#else
#ifdef HAVE_GCONF
#include <gconf/gconf-client.h>
#endif
+#endif
+
#ifdef HAVE_XFT
#include <X11/Xft/Xft.h>
#endif
@@ -48,11 +54,6 @@ static Lisp_Object Qmonospace_font_name, Qfont_name, Qfont_render,
Qtool_bar_style;
static Lisp_Object current_tool_bar_style;
-#ifdef HAVE_GCONF
-static GConfClient *gconf_client;
-#endif
-
-
static void
store_config_changed_event (Lisp_Object arg, Lisp_Object display_name)
{
@@ -64,6 +65,159 @@ store_config_changed_event (Lisp_Object arg, Lisp_Object display_name)
kbd_buffer_store_event (&event);
}
+static void
+store_monospaced_changed (void)
+{
+ if (first_dpyinfo != NULL)
+ {
+ /* Check if display still open */
+ struct x_display_info *dpyinfo;
+ int found = 0;
+ for (dpyinfo = x_display_list; !found && dpyinfo; dpyinfo = dpyinfo->next)
+ found = dpyinfo == first_dpyinfo;
+
+ if (found && use_system_font)
+ store_config_changed_event (Qmonospace_font_name,
+ XCAR (first_dpyinfo->name_list_element));
+ }
+}
+
+
+#ifdef HAVE_GSETTINGS
+
+#define EMACS_TYPE_SETTINGS (emacs_settings_get_type ())
+#define EMACS_SETTINGS(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST ((obj), EMACS_TYPE_SETTINGS, EmacsSettings))
+#define EMACS_IS_SETTINGS(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EMACS_TYPE_SETTINGS))
+#define EMACS_SETTINGS_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST ((klass), EMACS_TYPE_SETTINGS, EmacsSettingsClass))
+#define EMACS_IS_SETTINGS_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE ((klass), EMACS_TYPE_SETTINGS))
+#define EMACS_SETTINGS_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), EMACS_TYPE_SETTINGS, EmacsSettingsClass))
+
+typedef struct _EmacsSettings EmacsSettings;
+typedef struct _EmacsSettingsClass EmacsSettingsClass;
+
+struct _EmacsSettings
+{
+ GObject parent_instance;
+};
+
+struct _EmacsSettingsClass
+{
+ GObjectClass parent_class;
+};
+
+/* will create emacs_settings_get_type and set emacs_settings_parent_class */
+G_DEFINE_TYPE (EmacsSettings, emacs_settings, G_TYPE_OBJECT);
+
+static GObject *
+emacs_settings_constructor (GType gtype,
+ guint n_properties,
+ GObjectConstructParam *properties)
+{
+ GObject *obj;
+
+ /* Always chain up to the parent constructor */
+ obj = G_OBJECT_CLASS (emacs_settings_parent_class)
+ ->constructor (gtype, n_properties, properties);
+
+ /* update the object state depending on constructor properties */
+
+ return obj;
+}
+
+enum { PROP_MONO = 1, PROP_FONT };
+
+static void
+emacs_settings_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ switch (property_id)
+ {
+ case PROP_MONO:
+ g_value_set_string (value, current_mono_font);
+ break;
+ case PROP_FONT:
+ g_value_set_string (value, current_font);
+ break;
+ }
+}
+
+static void
+emacs_settings_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ const char *newfont;
+ switch (property_id)
+ {
+ case PROP_MONO:
+ xfree (current_mono_font);
+ newfont = g_value_get_string (value);
+ if (current_mono_font != NULL && strcmp (newfont, current_mono_font) == 0)
+ return; /* No change. */
+
+ current_mono_font = xstrdup (newfont);
+ store_monospaced_changed ();
+ break;
+
+ case PROP_FONT:
+ xfree (current_font);
+ current_font = xstrdup (g_value_get_string (value));
+ break;
+ }
+}
+
+static void
+emacs_settings_class_init (EmacsSettingsClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+ gobject_class->constructor = emacs_settings_constructor;
+ gobject_class->set_property = emacs_settings_set_property;
+ gobject_class->get_property = emacs_settings_get_property;
+
+ g_object_class_install_property
+ (gobject_class,
+ PROP_MONO,
+ g_param_spec_string ("monospace-font",
+ "Monospace-font",
+ "System monospace font",
+ "",
+ G_PARAM_READWRITE));
+ g_object_class_install_property
+ (gobject_class,
+ PROP_FONT,
+ g_param_spec_string ("font",
+ "Font",
+ "System font",
+ "",
+ G_PARAM_READWRITE));
+
+}
+
+static void
+emacs_settings_init (EmacsSettings *self)
+{
+}
+
+
+static GSettings *gsettings_client;
+static EmacsSettings *gsettings_obj;
+
+#else
+#ifdef HAVE_GCONF
+static GConfClient *gconf_client;
+#endif
+#endif
+
+
#define XSETTINGS_FONT_NAME "Gtk/FontName"
#define XSETTINGS_TOOL_BAR_STYLE "Gtk/ToolbarStyle"
@@ -91,10 +245,15 @@ struct xsettings
unsigned seen;
};
-#ifdef HAVE_GCONF
+#ifdef HAVE_GSETTINGS
+#define GSETTINGS_SCHEMA "org.gnome.desktop.interface"
+#define SYSTEM_MONO_FONT "monospace-font-name"
+#define SYSTEM_FONT "font-name"
-#define SYSTEM_MONO_FONT "/desktop/gnome/interface/monospace_font_name"
-#define SYSTEM_FONT "/desktop/gnome/interface/font_name"
+#else
+#ifdef HAVE_GCONF
+#define SYSTEM_MONO_FONT "/desktop/gnome/interface/monospace_font_name"
+#define SYSTEM_FONT "/desktop/gnome/interface/font_name"
/* Callback called when something changed in GConf that we care about,
that is SYSTEM_MONO_FONT. */
@@ -116,23 +275,12 @@ something_changedCB (GConfClient *client,
xfree (current_mono_font);
current_mono_font = xstrdup (value);
- }
-
-
- if (first_dpyinfo != NULL)
- {
- /* Check if display still open */
- struct x_display_info *dpyinfo;
- int found = 0;
- for (dpyinfo = x_display_list; !found && dpyinfo; dpyinfo = dpyinfo->next)
- found = dpyinfo == first_dpyinfo;
-
- if (found && use_system_font)
- store_config_changed_event (Qmonospace_font_name,
- XCAR (first_dpyinfo->name_list_element));
+ store_monospaced_changed ();
}
}
+
#endif /* HAVE_GCONF */
+#endif /* ! HAVE_GSETTINGS */
#ifdef HAVE_XFT
@@ -632,9 +780,47 @@ xft_settings_event (struct x_display_info *dpyinfo, XEvent *event)
static void
+init_gsettings (void)
+{
+#ifdef HAVE_GSETTINGS
+ GVariant *val;
+#ifdef HAVE_G_TYPE_INIT
+ g_type_init ();
+#endif
+
+ gsettings_client = g_settings_new (GSETTINGS_SCHEMA);
+ if (!gsettings_client) return;
+ g_object_ref_sink (G_OBJECT (gsettings_client));
+
+ gsettings_obj = g_object_new (EMACS_TYPE_SETTINGS, NULL);
+ if (!gsettings_obj)
+ {
+ g_object_unref (G_OBJECT (gsettings_client));
+ return;
+ }
+ g_object_ref_sink (G_OBJECT (gsettings_obj));
+
+ val = g_settings_get_value (gsettings_client, SYSTEM_MONO_FONT);
+ if (val)
+ {
+ g_variant_ref_sink (val);
+ if (g_variant_is_of_type (val, G_VARIANT_TYPE_STRING))
+ current_mono_font = xstrdup (g_variant_get_string (val, NULL));
+ g_variant_unref (val);
+ }
+
+ g_settings_bind (gsettings_client, SYSTEM_MONO_FONT, gsettings_obj,
+ "monospace-font", G_SETTINGS_BIND_GET);
+ g_settings_bind (gsettings_client, SYSTEM_FONT, gsettings_obj,
+ "font", G_SETTINGS_BIND_GET);
+#endif /* HAVE_GSETTINGS */
+}
+
+
+static void
init_gconf (void)
{
-#if defined (HAVE_GCONF) && defined (HAVE_XFT)
+#if defined (HAVE_GCONF) && defined (HAVE_XFT) && ! defined (HAVE_GSETTINGS)
char *s;
#ifdef HAVE_G_TYPE_INIT
@@ -662,7 +848,7 @@ init_gconf (void)
SYSTEM_MONO_FONT,
something_changedCB,
NULL, NULL, NULL);
-#endif /* HAVE_GCONF && HAVE_XFT */
+#endif /* HAVE_GCONF && HAVE_XFT && ! HAVE_GSETTINGS */
}
static void
@@ -687,6 +873,7 @@ void
xsettings_initialize (struct x_display_info *dpyinfo)
{
if (first_dpyinfo == NULL) first_dpyinfo = dpyinfo;
+ init_gsettings ();
init_gconf ();
init_xsettings (dpyinfo);
}
@@ -746,9 +933,14 @@ syms_of_xsettings (void)
current_mono_font = NULL;
current_font = NULL;
first_dpyinfo = NULL;
+#ifdef HAVE_GSETTINGS
+ gsettings_client = NULL;
+ gsettings_obj = NULL;
+#else
#ifdef HAVE_GCONF
gconf_client = NULL;
#endif
+#endif
DEFSYM (Qmonospace_font_name, "monospace-font-name");
DEFSYM (Qfont_name, "font-name");
@@ -769,7 +961,7 @@ If this variable is nil, Emacs ignores system font changes. */);
#ifdef HAVE_XFT
Fprovide (intern_c_string ("font-render-setting"), Qnil);
-#ifdef HAVE_GCONF
+#if defined (HAVE_GCONF) || defined (HAVE_GSETTINGS)
Fprovide (intern_c_string ("system-font-setting"), Qnil);
#endif
#endif