From 64dc12ad3fbc874839c16600601b6bc705584f43 Mon Sep 17 00:00:00 2001 From: Anton Danilkin Date: Fri, 15 Apr 2016 13:19:56 +0300 Subject: [PATCH] Add font selector --- panel-plugin/xfce4-xkb-plugin.c | 10 ++++++++-- panel-plugin/xfce4-xkb-plugin.h | 1 + panel-plugin/xkb-cairo.c | 13 +++++++------ panel-plugin/xkb-cairo.h | 6 ++++-- panel-plugin/xkb-callbacks.c | 6 ++++-- panel-plugin/xkb-settings-dialog.c | 19 +++++++++++++++++++ 6 files changed, 43 insertions(+), 12 deletions(-) diff --git a/panel-plugin/xfce4-xkb-plugin.c b/panel-plugin/xfce4-xkb-plugin.c index 2d24f4e..9db94da 100644 --- a/panel-plugin/xfce4-xkb-plugin.c +++ b/panel-plugin/xfce4-xkb-plugin.c @@ -42,8 +42,9 @@ #include "xkb-cairo.h" #include "xkb-callbacks.h" -#define DISPLAY_TEXTSCALE_LARGE 100 -#define DISPLAY_IMGSCALE_LARGE 100 +#define DISPLAY_TEXTSCALE_LARGE 50 +#define DISPLAY_IMGSCALE_LARGE 50 +#define DISPLAY_FONT "Bitstream Vera Sans Roman 8" /* ------------------------------------------------------------------ * * Panel Plugin Interface * @@ -291,6 +292,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_entry (rcfile, "display_font", xkb->display_font); xfce_rc_write_int_entry (rcfile, "display_textscale", xkb->display_text_scale); xfce_rc_write_int_entry (rcfile, "display_imgscale", xkb->display_img_scale); xfce_rc_write_int_entry (rcfile, "group_policy", xkb->group_policy); @@ -310,6 +312,9 @@ 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); + const gchar *val; + val = xfce_rc_read_entry (rcfile, "display_font", DISPLAY_FONT); + xkb->display_font = g_strdup(val); text_scale = xfce_rc_read_int_entry (rcfile, "display_textscale", -1); if (text_scale < 0) { @@ -345,6 +350,7 @@ static void xkb_load_default (t_xkb *xkb) { xkb->display_type = DISPLAY_TYPE_IMAGE; + xkb->display_font = DISPLAY_FONT; xkb->display_text_scale = DISPLAY_TEXTSCALE_LARGE; xkb->display_img_scale = DISPLAY_IMGSCALE_LARGE; xkb->group_policy = GROUP_POLICY_PER_APPLICATION; diff --git a/panel-plugin/xfce4-xkb-plugin.h b/panel-plugin/xfce4-xkb-plugin.h index 372a27a..54c7bf2 100644 --- a/panel-plugin/xfce4-xkb-plugin.h +++ b/panel-plugin/xfce4-xkb-plugin.h @@ -60,6 +60,7 @@ typedef struct gint button_vsize; /* read allocated button size - see below */ t_display_type display_type; /* display layout as image ot text */ + gchar *display_font; guint display_text_scale; /* text scale % for text layout */ guint display_img_scale; /* image scale % for flag layout */ t_group_policy group_policy; /* per-app/window/global policy */ diff --git a/panel-plugin/xkb-cairo.c b/panel-plugin/xkb-cairo.c index 27454f3..05371bc 100644 --- a/panel-plugin/xkb-cairo.c +++ b/panel-plugin/xkb-cairo.c @@ -31,8 +31,6 @@ #include #endif -#define XKB_PREFERRED_FONT "Courier New, Courier 10 Pitch, Monospace Bold" - #define xkb_cairo_arc_for_flag(cr, x, y, r, a1, a2) \ xx = x; yy = y; \ cairo_device_to_user (cr, &xx, &yy); \ @@ -61,7 +59,8 @@ xkb_cairo_draw_flag (cairo_t *cr, guint max_variant_markers_count, guint img_scale, guint text_scale, - GdkColor fgcolor) + GdkColor fgcolor, + const gchar *font) { gchar *filename; RsvgHandle *handle; @@ -90,7 +89,8 @@ xkb_cairo_draw_flag (cairo_t *cr, width, height, variant_markers_count, text_scale, - fgcolor); + fgcolor, + font); return; } @@ -193,7 +193,8 @@ xkb_cairo_draw_label (cairo_t *cr, const gint height, const gint variant_markers_count, const guint text_scale, - const GdkColor fgcolor) + const GdkColor fgcolor, + const gchar *font) { gchar *normalized_group_name; gint pango_width, pango_height; @@ -224,7 +225,7 @@ xkb_cairo_draw_label (cairo_t *cr, pango_layout_set_text (layout, normalized_group_name, -1); - desc = pango_font_description_from_string ( XKB_PREFERRED_FONT ); + desc = pango_font_description_from_string ( font ); pango_layout_set_font_description (layout, desc); pango_font_description_free (desc); diff --git a/panel-plugin/xkb-cairo.h b/panel-plugin/xkb-cairo.h index fbac467..c37ecec 100644 --- a/panel-plugin/xkb-cairo.h +++ b/panel-plugin/xkb-cairo.h @@ -44,7 +44,8 @@ void xkb_cairo_draw_flag (cairo_t *cr, guint max_variant_markers_count, guint img_scale, guint text_scale, - GdkColor fgcolor); + GdkColor fgcolor, + const gchar *font); void xkb_cairo_draw_label (cairo_t *cr, const gchar *group_name, @@ -55,7 +56,8 @@ void xkb_cairo_draw_label (cairo_t *cr, const gint height, const gint variant_markers_count, const guint text_scale, - const GdkColor fgcolor); + const GdkColor fgcolor, + const gchar *font); #endif diff --git a/panel-plugin/xkb-callbacks.c b/panel-plugin/xkb-callbacks.c index 3453c62..651e3a9 100644 --- a/panel-plugin/xkb-callbacks.c +++ b/panel-plugin/xkb-callbacks.c @@ -140,7 +140,8 @@ xkb_plugin_layout_image_exposed (GtkWidget *widget, xkb_config_get_max_group_count (), xkb->display_img_scale, xkb->display_text_scale, - fgcolor + fgcolor, + xkb->display_font ); } else @@ -151,7 +152,8 @@ xkb_plugin_layout_image_exposed (GtkWidget *widget, xkb->hsize, vsize, xkb_config_variant_index_for_group (-1), xkb->display_text_scale, - fgcolor + fgcolor, + xkb->display_font ); } diff --git a/panel-plugin/xkb-settings-dialog.c b/panel-plugin/xkb-settings-dialog.c index 2431773..6e4f5e1 100644 --- a/panel-plugin/xkb-settings-dialog.c +++ b/panel-plugin/xkb-settings-dialog.c @@ -86,6 +86,13 @@ on_display_type_changed (GtkComboBox *cb, t_xkb *xkb) } static void +on_display_font_changed (GtkFontButton *button, t_xkb *xkb) +{ + xkb->display_font = g_strdup (gtk_font_button_get_font_name (button)); + xkb_refresh_gui (xkb); +} + +static void on_display_textsize_changed (GtkHScale *scale, t_xkb *xkb) { xkb->display_text_scale = gtk_range_get_value (GTK_RANGE (scale)); @@ -112,6 +119,7 @@ xfce_xkb_configure (XfcePanelPlugin *plugin, { GtkWidget *display_type_optmenu, *group_policy_combo; GtkWidget *vbox, *display_type_frame, *group_policy_frame, *bin; + GtkWidget *display_font_frame, *display_font_button; GtkWidget *display_textsize_frame, *display_textsize_scale; GtkWidget *display_imgsize_frame, *display_imgsize_scale; @@ -137,6 +145,15 @@ xfce_xkb_configure (XfcePanelPlugin *plugin, gtk_widget_set_size_request (display_type_optmenu, 230, -1); gtk_container_add (GTK_CONTAINER (bin), display_type_optmenu); + /* font option */ + display_font_frame = xfce_gtk_frame_box_new (_("Font:"), &bin); + gtk_widget_show (display_font_frame); + gtk_box_pack_start (GTK_BOX (vbox), display_font_frame, TRUE, TRUE, 2); + + display_font_button = gtk_font_button_new (); + gtk_widget_set_size_request (display_font_button, 230, -1); + gtk_container_add (GTK_CONTAINER (bin), display_font_button); + /* text size option */ display_textsize_frame = xfce_gtk_frame_box_new (_("Text size:"), &bin); gtk_widget_show (display_textsize_frame); @@ -177,12 +194,14 @@ 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_font_button_set_font_name (GTK_FONT_BUTTON (display_font_button), xkb->display_font); gtk_range_set_value (GTK_RANGE (display_textsize_scale), xkb->display_text_scale); gtk_range_set_value (GTK_RANGE (display_imgsize_scale), xkb->display_img_scale); gtk_combo_box_set_active (GTK_COMBO_BOX (group_policy_combo), xkb->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_font_button, "font-set", G_CALLBACK (on_display_font_changed), xkb); g_signal_connect (display_textsize_scale, "value_changed", G_CALLBACK (on_display_textsize_changed), xkb); g_signal_connect (display_imgsize_scale, "value_changed", G_CALLBACK (on_display_imgsize_changed), xkb); -- 2.8.0