From 53e5c184aacdefcb690ce1722a8820ee31dd66b7 Mon Sep 17 00:00:00 2001 From: Ivan Frederiks Date: Thu, 26 Sep 2013 14:49:02 +0400 Subject: [PATCH] Changed text size selection to full-featured font selection --- panel-plugin/xfce4-xkb-plugin.c | 7 +++--- panel-plugin/xfce4-xkb-plugin.h | 9 ++------ panel-plugin/xkb-cairo.c | 33 +++++----------------------- panel-plugin/xkb-cairo.h | 4 ++-- panel-plugin/xkb-callbacks.c | 4 ++-- panel-plugin/xkb-settings-dialog.c | 45 ++++++++++++++++++++++++++------------ 6 files changed, 47 insertions(+), 55 deletions(-) diff --git a/panel-plugin/xfce4-xkb-plugin.c b/panel-plugin/xfce4-xkb-plugin.c index 52a1e96..3ea6be9 100644 --- a/panel-plugin/xfce4-xkb-plugin.c +++ b/panel-plugin/xfce4-xkb-plugin.c @@ -262,6 +262,7 @@ xkb_free (t_xkb *xkb) gtk_widget_destroy (xkb->layout_image); gtk_widget_destroy (xkb->btn); xkb_destroy_popup_menu (xkb); + g_free (xkb->display_font); panel_slice_free (t_xkb, xkb); } @@ -288,7 +289,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->group_policy); xfce_rc_close (rcfile); @@ -304,7 +305,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_LARGE); + xkb->display_font = g_strdup(xfce_rc_read_entry (rcfile, "display_font", XKB_PREFERRED_FONT)); xkb->group_policy = xfce_rc_read_int_entry (rcfile, "group_policy", GROUP_POLICY_PER_APPLICATION); xfce_rc_close (rcfile); @@ -319,7 +320,7 @@ static void xkb_load_default (t_xkb *xkb) { xkb->display_type = DISPLAY_TYPE_IMAGE; - xkb->display_textsize = DISPLAY_TEXTSIZE_LARGE; + xkb->display_font = g_strdup(XKB_PREFERRED_FONT); xkb->group_policy = GROUP_POLICY_PER_APPLICATION; } diff --git a/panel-plugin/xfce4-xkb-plugin.h b/panel-plugin/xfce4-xkb-plugin.h index 68f6c8a..2b0ee45 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_group_policy group_policy; /* per-app/window/global policy */ gint button_state; /* gtk state of the button */ diff --git a/panel-plugin/xkb-cairo.c b/panel-plugin/xkb-cairo.c index 27ad119..ff11331 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 = layoutx + width - 12 + x; \ yy = layouty + height - 12 + y; \ @@ -59,7 +57,7 @@ xkb_cairo_draw_flag (cairo_t *cr, gint width, gint height, gint variant_markers_count, - gint textsize, + const gchar *font_str, GdkColor fgcolor) { gchar *filename; @@ -86,7 +84,7 @@ xkb_cairo_draw_flag (cairo_t *cr, actual_width, actual_height, width, height, variant_markers_count, - textsize, + font_str, fgcolor); return; } @@ -136,7 +134,7 @@ xkb_cairo_draw_label (cairo_t *cr, const gint width, const gint height, const gint variant_markers_count, - const gint textsize, + const gchar *font_str, const GdkColor fgcolor) { gchar *normalized_group_name; @@ -168,7 +166,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_str ); pango_layout_set_font_description (layout, desc); pango_font_description_free (desc); @@ -176,35 +174,16 @@ xkb_cairo_draw_label (cairo_t *cr, pango_layout_get_pixel_size (layout, &pango_width, &pango_height); DBG ("pango_width/height: %d/%d", pango_width, pango_height); - switch (textsize){ - case DISPLAY_TEXTSIZE_SMALL: - default: /* catch misconfiguration */ - scalex = scaley = 0.475; - break; - case DISPLAY_TEXTSIZE_MEDIUM: - scalex = scaley = 0.7; - break; - case DISPLAY_TEXTSIZE_LARGE: - scalex = scaley = 1; - break; - } - - DBG ("txt size scale x/y: %.2f/%.2f", scalex, scaley); - - text_height = actual_height * scaley; + text_height = actual_height; scaley = text_height / pango_height; radius = (text_height < 32) ? 1.2 : 2.5; diameter = 2 * radius; - text_width = actual_width * scalex; + text_width = actual_width; if (actual_width - text_width < 3 + variant_markers_count * diameter) { text_width = actual_width - 3 - (variant_markers_count) * diameter; } - else if (textsize == DISPLAY_TEXTSIZE_LARGE) - { - text_width -= 3; - } scalex = text_width/pango_width; diff --git a/panel-plugin/xkb-cairo.h b/panel-plugin/xkb-cairo.h index 4be2b24..a9a0c67 100644 --- a/panel-plugin/xkb-cairo.h +++ b/panel-plugin/xkb-cairo.h @@ -41,7 +41,7 @@ void xkb_cairo_draw_flag (cairo_t *cr, gint width, gint height, gint variant_markers_count, - gint textsize, + const gchar *font_str, GdkColor fgcolor); void xkb_cairo_draw_label (cairo_t *cr, @@ -52,7 +52,7 @@ void xkb_cairo_draw_label (cairo_t *cr, const gint width, const gint height, const gint variant_markers_count, - const gint textsize, + const gchar *font_str, const GdkColor fgcolor); #endif diff --git a/panel-plugin/xkb-callbacks.c b/panel-plugin/xkb-callbacks.c index 179276d..fee9eaf 100644 --- a/panel-plugin/xkb-callbacks.c +++ b/panel-plugin/xkb-callbacks.c @@ -137,7 +137,7 @@ xkb_plugin_layout_image_exposed (GtkWidget *widget, actual_hsize, actual_vsize, xkb->hsize, vsize, xkb_config_variant_index_for_group (-1), - xkb->display_textsize, + xkb->display_font, fgcolor ); } @@ -148,7 +148,7 @@ xkb_plugin_layout_image_exposed (GtkWidget *widget, actual_hsize, actual_vsize, xkb->hsize, 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 d155bdb..41146e2 100644 --- a/panel-plugin/xkb-settings-dialog.c +++ b/panel-plugin/xkb-settings-dialog.c @@ -86,9 +86,30 @@ on_display_type_changed (GtkComboBox *cb, t_xkb *xkb) } static void -on_display_textsize_changed (GtkComboBox *cb, t_xkb *xkb) +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); } @@ -105,7 +126,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; xfce_panel_plugin_block_menu (plugin); @@ -130,16 +151,13 @@ xfce_xkb_configure (XfcePanelPlugin *plugin, 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); @@ -159,12 +177,11 @@ 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->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); gtk_widget_show (settings_dialog); } -- 1.8.4