[Xfce4-commits] <xfce4-embed-plugin:master> Added label font customization.
David Schneider
noreply at xfce.org
Sun Jan 1 21:44:36 CET 2012
Updating branch refs/heads/master
to 657eb5a95ff6a03a5218cea935972835be00f923 (commit)
from 7605929763dfb967cb842bdc03793a9cb7ac25e6 (commit)
commit 657eb5a95ff6a03a5218cea935972835be00f923
Author: David Schneider <dnschneid at gmail.com>
Date: Fri Dec 30 19:39:02 2011 -0500
Added label font customization.
TODO | 1 -
panel-plugin/embed-dialogs.c | 30 ++++++++++++++++++++++++++++--
panel-plugin/embed.c | 26 ++++++++++++++++++++++++++
panel-plugin/embed.h | 3 +++
4 files changed, 57 insertions(+), 3 deletions(-)
diff --git a/TODO b/TODO
index aa8d12a..0dd630d 100644
--- a/TODO
+++ b/TODO
@@ -8,4 +8,3 @@ Fake socket no longer necessary?
to work.
* Might be worth doing for simplicity, but not high priority
Option to enable click-to-activate keyboard input
-Label font
diff --git a/panel-plugin/embed-dialogs.c b/panel-plugin/embed-dialogs.c
index cd93e7e..acddb99 100644
--- a/panel-plugin/embed-dialogs.c
+++ b/panel-plugin/embed-dialogs.c
@@ -142,6 +142,16 @@ embed_label_fmt_changed (GtkEditable *edit, EmbedPlugin *embed)
static void
+embed_label_font_changed (GtkFontButton *font_button, EmbedPlugin *embed)
+{
+ g_free (embed->label_font);
+ embed->label_font = g_strdup (gtk_font_button_get_font_name (font_button));
+ embed_update_label_font (embed);
+}
+
+
+
+static void
embed_min_size_changed (GtkSpinButton *spin, EmbedPlugin *embed)
{
embed->min_size = gtk_spin_button_get_value_as_int (spin);
@@ -200,6 +210,17 @@ embed_configure (XfcePanelPlugin *plugin, EmbedPlugin *embed)
gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5f); \
gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget); \
ADD(label, row, 0); ADD(widget, row, 1)
+#define FONTBUTTON(row, labeltext, tooltiptext, value, callback) \
+ label = gtk_label_new_with_mnemonic (labeltext); \
+ widget = gtk_font_button_new (); \
+ if (value) \
+ gtk_font_button_set_font_name (GTK_FONT_BUTTON (widget), value); \
+ g_signal_connect (G_OBJECT (widget), "font-set", \
+ G_CALLBACK (callback), embed); \
+ TOOLTIP2(label, widget, tooltiptext); \
+ gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5f); \
+ gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget); \
+ ADD(label, row, 0); ADD(widget, row, 1)
#define SPIN(row, labeltext, tooltiptext, value, callback) \
label = gtk_label_new_with_mnemonic (labeltext); \
widget = gtk_spin_button_new_with_range (0, G_MAXINT, 1); \
@@ -248,8 +269,12 @@ embed_configure (XfcePanelPlugin *plugin, EmbedPlugin *embed)
EMBED_LABEL_FMT_TITLE " expands to the embedded window's title"),
embed->label_fmt, embed_label_fmt_changed);
+ /* label font */
+ FONTBUTTON(1, _("Label _font"), _("Choose the label font"),
+ embed->label_font, embed_label_font_changed);
+
/* min_size */
- SPIN(1, _("Minimum _size (px)"),
+ SPIN(2, _("Minimum _size (px)"),
_("Minimum size of the embedded window\n"
"Set to 0 to keep the original window size"),
embed->min_size, embed_min_size_changed);
@@ -260,11 +285,12 @@ embed_configure (XfcePanelPlugin *plugin, EmbedPlugin *embed)
g_signal_connect (G_OBJECT (widget), "toggled",
G_CALLBACK (embed_expand_toggled), embed);
gtk_widget_set_tooltip_text (widget, _("Use up all available panel space"));
- ADD(widget, 2, 1);
+ ADD(widget, 3, 1);
#undef ADD
#undef TOOLTIP2
#undef ENTRY
+#undef FONTBUTTON
#undef SPIN
#undef START_FRAME
diff --git a/panel-plugin/embed.c b/panel-plugin/embed.c
index c6c17ab..fae5de4 100644
--- a/panel-plugin/embed.c
+++ b/panel-plugin/embed.c
@@ -38,6 +38,7 @@
#define DEFAULT_WINDOW_REGEX NULL
#define DEFAULT_WINDOW_CLASS NULL
#define DEFAULT_LABEL_FMT _("Embed")
+#define DEFAULT_LABEL_FONT NULL
#define DEFAULT_POLL_DELAY 0
#define DEFAULT_MIN_SIZE EMBED_MIN_SIZE_MATCH_WINDOW
#define DEFAULT_EXPAND TRUE
@@ -91,6 +92,8 @@ embed_save (XfcePanelPlugin *plugin, EmbedPlugin *embed)
xfce_rc_write_entry (rc, "window_class", embed->window_class);
if (embed->label_fmt)
xfce_rc_write_entry (rc, "label_fmt", embed->label_fmt);
+ if (embed->label_font)
+ xfce_rc_write_entry (rc, "label_font", embed->label_font);
xfce_rc_write_int_entry (rc, "poll_delay", embed->poll_delay);
xfce_rc_write_int_entry (rc, "min_size", embed->min_size);
xfce_rc_write_bool_entry (rc, "expand", embed->expand);
@@ -129,6 +132,8 @@ embed_read (EmbedPlugin *embed)
"window_class", DEFAULT_WINDOW_CLASS));
embed->label_fmt = g_strdup (xfce_rc_read_entry (rc,
"label_fmt", DEFAULT_LABEL_FMT));
+ embed->label_font = g_strdup (xfce_rc_read_entry (rc,
+ "label_font", DEFAULT_LABEL_FONT));
embed->poll_delay = xfce_rc_read_int_entry (rc,
"poll_delay", DEFAULT_POLL_DELAY);
embed->min_size = xfce_rc_read_int_entry (rc,
@@ -151,6 +156,7 @@ embed_read (EmbedPlugin *embed)
embed->window_regex = g_strdup (DEFAULT_WINDOW_REGEX);
embed->window_class = g_strdup (DEFAULT_WINDOW_CLASS);
embed->label_fmt = g_strdup (DEFAULT_LABEL_FMT);
+ embed->label_font = g_strdup (DEFAULT_LABEL_FONT);
embed->poll_delay = DEFAULT_POLL_DELAY;
embed->min_size = DEFAULT_MIN_SIZE;
embed->expand = DEFAULT_EXPAND;
@@ -214,6 +220,7 @@ embed_new (XfcePanelPlugin *plugin)
embed->label = gtk_label_new (NULL);
gtk_box_pack_start (GTK_BOX (embed->hvbox), embed->label, FALSE, FALSE, 0);
embed_update_label (embed);
+ embed_update_label_font (embed);
/* socket */
embed_add_socket (embed, FALSE);
@@ -256,6 +263,7 @@ embed_free (XfcePanelPlugin *plugin, EmbedPlugin *embed)
g_free (embed->window_regex);
g_free (embed->window_class);
g_free (embed->label_fmt);
+ g_free (embed->label_font);
/* Close the X11 display */
XCloseDisplay (embed->disp);
@@ -382,6 +390,24 @@ embed_update_label (EmbedPlugin *embed)
+/* Updates the font of the label, using label_font. */
+void
+embed_update_label_font (EmbedPlugin *embed)
+{
+ PangoFontDescription *font;
+ PangoAttrList *attr_list;
+ if (embed->label_font) {
+ font = pango_font_description_from_string (embed->label_font);
+ attr_list = pango_attr_list_new ();
+ pango_attr_list_insert (attr_list, pango_attr_font_desc_new (font));
+ pango_font_description_free (font);
+ gtk_label_set_attributes (GTK_LABEL (embed->label), attr_list);
+ pango_attr_list_unref (attr_list);
+ }
+}
+
+
+
/* Performs a single pass through the windows managed by the window manager,
* searching for the first window that meets all of the criteria.
* If one is found, it embeds it.
diff --git a/panel-plugin/embed.h b/panel-plugin/embed.h
index 3180b00..5a919a2 100644
--- a/panel-plugin/embed.h
+++ b/panel-plugin/embed.h
@@ -58,6 +58,7 @@ typedef struct
gchar *window_regex;
gchar *window_class;
gchar *label_fmt;
+ gchar *label_font;
gint poll_delay;
gint min_size;
gboolean expand;
@@ -77,6 +78,8 @@ embed_stop_search (EmbedPlugin *embed);
void
embed_update_label (EmbedPlugin *embed);
void
+embed_update_label_font (EmbedPlugin *embed);
+void
embed_size_changed_simple (EmbedPlugin *embed);
void
embed_save (XfcePanelPlugin *plugin, EmbedPlugin *embed);
More information about the Xfce4-commits
mailing list