File: 01-font_selection.patch

package info (click to toggle)
xfce4-xkb-plugin 1:0.7.1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, stretch
  • size: 4,096 kB
  • ctags: 376
  • sloc: sh: 11,379; ansic: 1,537; makefile: 168
file content (286 lines) | stat: -rw-r--r-- 11,524 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
Author: Ivan Frederiks <idfred@gmail.com>
Date: Thu, 26 Sep 2013 14:49:02 +0400
Description: Changed text size selection to full-featured font selection
 Makes the xkb plugin change font with the rest of the system
Bug: https://bugzilla.xfce.org/show_bug.cgi?id=8446
Bug-Debian: http://bugs.debian.org/576072
Bug-Ubuntu: https://launchpad.net/bugs/733563

---
 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 |   47 +++++++++++++++++++++++++------------
 6 files changed, 48 insertions(+), 56 deletions(-)

--- 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 *p
     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
         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;
 }
 
--- 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 */
--- a/panel-plugin/xkb-cairo.c
+++ b/panel-plugin/xkb-cairo.c
@@ -31,8 +31,6 @@
 #include <librsvg/rsvg-cairo.h>
 #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;
 
--- a/panel-plugin/xkb-cairo.h
+++ b/panel-plugin/xkb-cairo.h
@@ -41,7 +41,7 @@ void        xkb_cairo_draw_flag     (cai
                                      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    (cai
                                      const gint width,
                                      const gint height,
                                      const gint variant_markers_count,
-                                     const gint textsize,
+                                     const gchar *font_str,
                                      const GdkColor fgcolor);
 
 #endif
--- a/panel-plugin/xkb-callbacks.c
+++ b/panel-plugin/xkb-callbacks.c
@@ -137,7 +137,7 @@ xkb_plugin_layout_image_exposed (GtkWidg
                 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 (GtkWidg
                 actual_hsize, actual_vsize,
                 xkb->hsize, vsize,
                 xkb_config_variant_index_for_group (-1),
-                xkb->display_textsize,
+                xkb->display_font,
                 fgcolor
         );
     }
--- a/panel-plugin/xkb-settings-dialog.c
+++ b/panel-plugin/xkb-settings-dialog.c
@@ -86,9 +86,30 @@ on_display_type_changed (GtkComboBox *cb
 }
 
 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 *plu
 {
     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 *plu
     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_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_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_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 *plu
             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);
 }