Hi there!
I made another patch based on Rinat's one and on xfce4-datetime-plugin.
It allows to select arbitrary font. Please check it out.
This patch was also mailed to Azamat H. Hackimov (plugin maintainer).
From a6b56359d7eb6cc88d596542a639079e322f16fd Mon Sep 17 00:00:00 2001
From: Ivan Frederiks <[email protected]>
Date: Thu, 15 Dec 2011 18:01:17 +0100
Subject: [PATCH] Changed text size selection to full-featured font selection
---
panel-plugin/xfce4-xkb-plugin.c | 8 +++--
panel-plugin/xfce4-xkb-plugin.h | 9 +-----
panel-plugin/xkb-cairo.c | 20 ++------------
panel-plugin/xkb-cairo.h | 3 +-
panel-plugin/xkb-callbacks.c | 3 +-
panel-plugin/xkb-settings-dialog.c | 48 ++++++++++++++++++++++++------------
6 files changed, 46 insertions(+), 45 deletions(-)
diff --git a/panel-plugin/xfce4-xkb-plugin.c b/panel-plugin/xfce4-xkb-plugin.c
index 6a0635a..e19284a 100644
--- a/panel-plugin/xfce4-xkb-plugin.c
+++ b/panel-plugin/xfce4-xkb-plugin.c
@@ -225,6 +225,8 @@ xkb_free (t_xkb *xkb)
{
xkb_config_finalize ();
+ g_free (xkb->display_font);
+
if (xkb->settings->kbd_config)
kbd_config_free (xkb->settings->kbd_config);
@@ -261,7 +263,7 @@ xfce_xkb_save_config (XfcePanelPlugin *plugin, t_xkb *xkb)
xfce_rc_set_group (rcfile, NULL);
xfce_rc_write_int_entry (rcfile, "display_type", xkb->display_type);
- xfce_rc_write_int_entry (rcfile, "display_textsize", xkb->display_textsize);
+ xfce_rc_write_entry (rcfile, "display_font", xkb->display_font);
xfce_rc_write_int_entry (rcfile, "group_policy", xkb->settings->group_policy);
xfce_rc_write_int_entry (rcfile, "default_group", xkb->settings->default_group);
xfce_rc_write_bool_entry (rcfile, "never_modify_config", xkb->settings->never_modify_config);
@@ -294,7 +296,7 @@ xkb_load_config (t_xkb *xkb, const gchar *filename)
xfce_rc_set_group (rcfile, NULL);
xkb->display_type = xfce_rc_read_int_entry (rcfile, "display_type", DISPLAY_TYPE_IMAGE);
- xkb->display_textsize = xfce_rc_read_int_entry (rcfile, "display_textsize", DISPLAY_TEXTSIZE_SMALL);
+ xkb->display_font = g_strdup(xfce_rc_read_entry (rcfile, "display_font", XKB_PREFERRED_FONT));
xkb->settings->group_policy = xfce_rc_read_int_entry (rcfile, "group_policy", GROUP_POLICY_PER_APPLICATION);
if (xkb->settings->group_policy != GROUP_POLICY_GLOBAL)
@@ -326,7 +328,7 @@ static void
xkb_load_default (t_xkb *xkb)
{
xkb->display_type = DISPLAY_TYPE_IMAGE;
- xkb->display_textsize = DISPLAY_TEXTSIZE_SMALL;
+ xkb->display_font = g_strdup(XKB_PREFERRED_FONT);
xkb->settings->group_policy = GROUP_POLICY_PER_APPLICATION;
xkb->settings->default_group = 0;
xkb->settings->kbd_config = NULL;
diff --git a/panel-plugin/xfce4-xkb-plugin.h b/panel-plugin/xfce4-xkb-plugin.h
index ef9b995..e806d74 100644
--- a/panel-plugin/xfce4-xkb-plugin.h
+++ b/panel-plugin/xfce4-xkb-plugin.h
@@ -42,12 +42,7 @@ typedef enum
DISPLAY_TYPE_TEXT = 1
} t_display_type;
-typedef enum
-{
- DISPLAY_TEXTSIZE_SMALL = 0,
- DISPLAY_TEXTSIZE_MEDIUM = 1,
- DISPLAY_TEXTSIZE_LARGE = 2
-} t_display_textsize;
+#define XKB_PREFERRED_FONT "Monospace Bold 16"
typedef struct
{
@@ -60,7 +55,7 @@ typedef struct
gint button_vsize; /* read allocated button size - see below */
t_display_type display_type; /* display layout as image ot text */
- t_display_textsize display_textsize; /* text size for text layout */
+ gchar *display_font; /* font for text layout */
t_xkb_settings *settings; /* per-app setting and default group */
gint button_state; /* gtk state of the button */
diff --git a/panel-plugin/xkb-cairo.c b/panel-plugin/xkb-cairo.c
index 3b828ec..6c198db 100644
--- a/panel-plugin/xkb-cairo.c
+++ b/panel-plugin/xkb-cairo.c
@@ -27,8 +27,6 @@
#include "xkb-util.h"
#include "xfce4-xkb-plugin.h"
-#define XKB_PREFERRED_FONT "Courier New, Courier 10 Pitch, Monospace Bold %d"
-
#define xkb_cairo_arc_for_flag(cr, x, y, r, a1, a2) \
xx = layoutx + width - 12 + x; \
yy = layouty + height - 12 + y; \
@@ -55,6 +53,7 @@ xkb_cairo_draw_flag (cairo_t *cr,
gint width,
gint height,
gint variant_markers_count,
+ gchar *font_str,
GdkColor fgcolor)
{
gchar *filename;
@@ -81,7 +80,7 @@ xkb_cairo_draw_flag (cairo_t *cr,
actual_width, actual_height,
width, height,
variant_markers_count,
- DISPLAY_TEXTSIZE_SMALL, // not used for flag layout
+ font_str,
fgcolor);
return;
}
@@ -135,11 +134,10 @@ xkb_cairo_draw_label (cairo_t *cr,
gint width,
gint height,
gint variant_markers_count,
- gint textsize,
+ gchar *font_str,
GdkColor fgcolor)
{
gchar *normalized_group_name;
- gchar font_str[80];
gint pango_width, pango_height;
gint layoutx, layouty;
double xx, yy;
@@ -161,18 +159,6 @@ xkb_cairo_draw_label (cairo_t *cr,
}
pango_layout_set_text (layout, normalized_group_name, -1);
- switch (textsize){
- case DISPLAY_TEXTSIZE_SMALL:
- default: /* catch misconfiguration */
- g_sprintf (font_str, XKB_PREFERRED_FONT, (int)(0.375 * panel_size) );
- break;
- case DISPLAY_TEXTSIZE_MEDIUM:
- g_sprintf (font_str, XKB_PREFERRED_FONT, (int)(0.600 * panel_size) );
- break;
- case DISPLAY_TEXTSIZE_LARGE:
- g_sprintf (font_str, XKB_PREFERRED_FONT, (int)(0.900 * panel_size) );
- break;
- }
desc = pango_font_description_from_string (font_str);
pango_layout_set_font_description (layout, desc);
diff --git a/panel-plugin/xkb-cairo.h b/panel-plugin/xkb-cairo.h
index a8ecf32..28233fd 100644
--- a/panel-plugin/xkb-cairo.h
+++ b/panel-plugin/xkb-cairo.h
@@ -42,6 +42,7 @@ void xkb_cairo_draw_flag (cairo_t *cr,
gint width,
gint height,
gint variant_markers_count,
+ gchar *font_str,
GdkColor fgcolor);
void xkb_cairo_draw_label (cairo_t *cr,
@@ -52,7 +53,7 @@ void xkb_cairo_draw_label (cairo_t *cr,
gint width,
gint height,
gint variant_markers_count,
- gint textsize,
+ gchar *font_str,
GdkColor fgcolor);
#endif
diff --git a/panel-plugin/xkb-callbacks.c b/panel-plugin/xkb-callbacks.c
index d12e086..27e396b 100644
--- a/panel-plugin/xkb-callbacks.c
+++ b/panel-plugin/xkb-callbacks.c
@@ -121,6 +121,7 @@ xkb_plugin_layout_image_exposed (GtkWidget *widget,
actual_hsize, actual_vsize,
xkb->hsize, xkb->vsize,
xkb_config_variant_index_for_group (-1),
+ xkb->display_font,
fgcolor
);
}
@@ -131,7 +132,7 @@ xkb_plugin_layout_image_exposed (GtkWidget *widget,
actual_hsize, actual_vsize,
xkb->hsize, xkb->vsize,
xkb_config_variant_index_for_group (-1),
- xkb->display_textsize,
+ xkb->display_font,
fgcolor
);
}
diff --git a/panel-plugin/xkb-settings-dialog.c b/panel-plugin/xkb-settings-dialog.c
index e792725..225da08 100644
--- a/panel-plugin/xkb-settings-dialog.c
+++ b/panel-plugin/xkb-settings-dialog.c
@@ -89,10 +89,30 @@ on_display_type_changed (GtkComboBox *cb, t_xkb *xkb)
xkb_refresh_gui (xkb);
}
-static void
-on_display_textsize_changed (GtkComboBox *cb, t_xkb *xkb)
+static void on_font_selection(GtkWidget *widget, t_xkb *xkb)
{
- xkb->display_textsize = gtk_combo_box_get_active (cb);
+ GtkWidget *dialog;
+ const gchar *group_name, *previewtext;
+ gint result;
+
+ group_name = xkb_config_get_group_name (-1);
+ previewtext = xkb_util_normalize_group_name (group_name);
+
+ dialog = gtk_font_selection_dialog_new(_("Select font"));
+ gtk_font_selection_dialog_set_font_name(GTK_FONT_SELECTION_DIALOG(dialog),
+ xkb->display_font);
+ gtk_font_selection_dialog_set_preview_text(GTK_FONT_SELECTION_DIALOG(dialog),
+ previewtext);
+
+ result = gtk_dialog_run(GTK_DIALOG(dialog));
+ if (result == GTK_RESPONSE_OK || result == GTK_RESPONSE_ACCEPT)
+ {
+ g_free(xkb->display_font);
+ xkb->display_font = gtk_font_selection_dialog_get_font_name(GTK_FONT_SELECTION_DIALOG(dialog));
+ gtk_button_set_label(GTK_BUTTON(widget), xkb->display_font);
+ }
+ gtk_widget_destroy(dialog);
+
xkb_refresh_gui (xkb);
}
@@ -502,7 +522,7 @@ xfce_xkb_configure (XfcePanelPlugin *plugin,
{
GtkWidget *display_type_optmenu, *group_policy_combo;
GtkWidget *vbox, *display_type_frame, *group_policy_frame, *bin;
- GtkWidget *display_textsize_frame, *display_textsize_optmenu;
+ GtkWidget *display_font_frame, *display_font_button;
GtkCellRenderer *renderer, *renderer2;
GtkWidget *vbox1, *vbox2, *hbox, *frame;
@@ -694,17 +714,13 @@ xfce_xkb_configure (XfcePanelPlugin *plugin,
gtk_widget_set_size_request (display_type_optmenu, 230, -1);
gtk_container_add (GTK_CONTAINER (bin), display_type_optmenu);
- /* text size option */
- display_textsize_frame = xfce_gtk_frame_box_new (_("Text size:"), &bin);
- gtk_widget_show (display_textsize_frame);
- gtk_box_pack_start (GTK_BOX (vbox), display_textsize_frame, TRUE, TRUE, 2);
+ display_font_frame = xfce_gtk_frame_box_new (_("Text font:"), &bin);
+ gtk_widget_show (display_font_frame);
+ gtk_box_pack_start (GTK_BOX (vbox), display_font_frame, TRUE, TRUE, 2);
- display_textsize_optmenu = gtk_combo_box_new_text ();
- gtk_combo_box_append_text (GTK_COMBO_BOX (display_textsize_optmenu), _("small"));
- gtk_combo_box_append_text (GTK_COMBO_BOX (display_textsize_optmenu), _("medium"));
- gtk_combo_box_append_text (GTK_COMBO_BOX (display_textsize_optmenu), _("large"));
- gtk_widget_set_size_request (display_textsize_optmenu, 230, -1);
- gtk_container_add (GTK_CONTAINER (bin), display_textsize_optmenu);
+ display_font_button = gtk_button_new_with_label (xkb->display_font);
+ gtk_widget_set_size_request (display_font_button, 230, -1);
+ gtk_container_add (GTK_CONTAINER (bin), display_font_button);
group_policy_frame = xfce_gtk_frame_box_new (_("Manage layout:"), &bin);
gtk_widget_show (group_policy_frame);
@@ -724,12 +740,12 @@ xfce_xkb_configure (XfcePanelPlugin *plugin,
G_CALLBACK (on_settings_close), xkb);
gtk_combo_box_set_active (GTK_COMBO_BOX (display_type_optmenu), xkb->display_type);
- gtk_combo_box_set_active (GTK_COMBO_BOX (display_textsize_optmenu), xkb->display_textsize);
+
gtk_combo_box_set_active (GTK_COMBO_BOX (group_policy_combo), xkb->settings->group_policy);
g_signal_connect (display_type_optmenu, "changed", G_CALLBACK (on_display_type_changed), xkb);
g_signal_connect (group_policy_combo, "changed", G_CALLBACK (on_group_policy_changed), xkb);
- g_signal_connect (display_textsize_optmenu, "changed", G_CALLBACK (on_display_textsize_changed), xkb);
+ g_signal_connect (display_font_button, "clicked", G_CALLBACK(on_font_selection), xkb);
g_signal_connect (xkb->add_layout_btn, "clicked", G_CALLBACK (xkb_settings_add_layout), xkb);
g_signal_connect (xkb->rm_layout_btn, "clicked", G_CALLBACK (xkb_settings_rm_layout), xkb);
--
1.7.4.1