Codebase list xapp / 3ae9703
Rework XAppKbdLayoutController: - Only supply icon names, labels, and duplicate ids - it is up to the individual client to supply flag images. Add api to retrieve pre-set labels based on country code or layout name. - remove packaged flags. - provide cairo snippit for clients to render duplicate ids on their icons. Michael Webster 7 years ago
258 changed file(s) with 318 addition(s) and 307 deletion(s). Raw diff Collapse all Expand all
1717 override_dh_strip:
1818 dh_strip --dbg-package=libxapp-dbg
1919
20 override_dh_scour:
21 # disabled
22
2023 override_dh_install:
2124 sed 's@DEB_PKG_CONFIG_LIBDIR@${DEB_PKG_CONFIG_LIBDIR}@' debian/gir1.2-xapp-1.0.install.in > debian/gir1.2-xapp-1.0.install
2225 dh_install --list-missing
33 usr/share/locale
44 usr/bin/
55 usr/share/icons
6 usr/share/xapps
6
files/usr/share/xapps/flags/aa.png less more
Binary diff not shown
files/usr/share/xapps/flags/ad.png less more
Binary diff not shown
files/usr/share/xapps/flags/ae.png less more
Binary diff not shown
files/usr/share/xapps/flags/af.png less more
Binary diff not shown
files/usr/share/xapps/flags/ag.png less more
Binary diff not shown
files/usr/share/xapps/flags/ai.png less more
Binary diff not shown
files/usr/share/xapps/flags/al.png less more
Binary diff not shown
files/usr/share/xapps/flags/am.png less more
Binary diff not shown
files/usr/share/xapps/flags/ao.png less more
Binary diff not shown
files/usr/share/xapps/flags/aq.png less more
Binary diff not shown
files/usr/share/xapps/flags/ar.png less more
Binary diff not shown
files/usr/share/xapps/flags/ara.png less more
Binary diff not shown
files/usr/share/xapps/flags/as.png less more
Binary diff not shown
files/usr/share/xapps/flags/at.png less more
Binary diff not shown
files/usr/share/xapps/flags/au.png less more
Binary diff not shown
files/usr/share/xapps/flags/aw.png less more
Binary diff not shown
files/usr/share/xapps/flags/ax.png less more
Binary diff not shown
files/usr/share/xapps/flags/az.png less more
Binary diff not shown
files/usr/share/xapps/flags/ba.png less more
Binary diff not shown
files/usr/share/xapps/flags/bb.png less more
Binary diff not shown
files/usr/share/xapps/flags/bd.png less more
Binary diff not shown
files/usr/share/xapps/flags/be.png less more
Binary diff not shown
files/usr/share/xapps/flags/bf.png less more
Binary diff not shown
files/usr/share/xapps/flags/bg.png less more
Binary diff not shown
files/usr/share/xapps/flags/bh.png less more
Binary diff not shown
files/usr/share/xapps/flags/bi.png less more
Binary diff not shown
files/usr/share/xapps/flags/bj.png less more
Binary diff not shown
files/usr/share/xapps/flags/bl.png less more
Binary diff not shown
files/usr/share/xapps/flags/bm.png less more
Binary diff not shown
files/usr/share/xapps/flags/bn.png less more
Binary diff not shown
files/usr/share/xapps/flags/bo.png less more
Binary diff not shown
files/usr/share/xapps/flags/bq.png less more
Binary diff not shown
files/usr/share/xapps/flags/br.png less more
Binary diff not shown
files/usr/share/xapps/flags/brl.png less more
Binary diff not shown
files/usr/share/xapps/flags/bs.png less more
Binary diff not shown
files/usr/share/xapps/flags/bt.png less more
Binary diff not shown
files/usr/share/xapps/flags/bv.png less more
Binary diff not shown
files/usr/share/xapps/flags/bw.png less more
Binary diff not shown
files/usr/share/xapps/flags/by.png less more
Binary diff not shown
files/usr/share/xapps/flags/bz.png less more
Binary diff not shown
files/usr/share/xapps/flags/ca.png less more
Binary diff not shown
files/usr/share/xapps/flags/cc.png less more
Binary diff not shown
files/usr/share/xapps/flags/cd.png less more
Binary diff not shown
files/usr/share/xapps/flags/cf.png less more
Binary diff not shown
files/usr/share/xapps/flags/cg.png less more
Binary diff not shown
files/usr/share/xapps/flags/ch.png less more
Binary diff not shown
files/usr/share/xapps/flags/ci.png less more
Binary diff not shown
files/usr/share/xapps/flags/ck.png less more
Binary diff not shown
files/usr/share/xapps/flags/cl.png less more
Binary diff not shown
files/usr/share/xapps/flags/cm.png less more
Binary diff not shown
files/usr/share/xapps/flags/cn.png less more
Binary diff not shown
files/usr/share/xapps/flags/co.png less more
Binary diff not shown
files/usr/share/xapps/flags/cr.png less more
Binary diff not shown
files/usr/share/xapps/flags/cu.png less more
Binary diff not shown
files/usr/share/xapps/flags/cv.png less more
Binary diff not shown
files/usr/share/xapps/flags/cw.png less more
Binary diff not shown
files/usr/share/xapps/flags/cx.png less more
Binary diff not shown
files/usr/share/xapps/flags/cy.png less more
Binary diff not shown
files/usr/share/xapps/flags/cz.png less more
Binary diff not shown
files/usr/share/xapps/flags/de.png less more
Binary diff not shown
files/usr/share/xapps/flags/dj.png less more
Binary diff not shown
files/usr/share/xapps/flags/dk.png less more
Binary diff not shown
files/usr/share/xapps/flags/dm.png less more
Binary diff not shown
files/usr/share/xapps/flags/do.png less more
Binary diff not shown
files/usr/share/xapps/flags/dz.png less more
Binary diff not shown
files/usr/share/xapps/flags/ec.png less more
Binary diff not shown
files/usr/share/xapps/flags/ee.png less more
Binary diff not shown
files/usr/share/xapps/flags/eg.png less more
Binary diff not shown
files/usr/share/xapps/flags/eh.png less more
Binary diff not shown
files/usr/share/xapps/flags/eo.png less more
Binary diff not shown
files/usr/share/xapps/flags/er.png less more
Binary diff not shown
files/usr/share/xapps/flags/es.png less more
Binary diff not shown
files/usr/share/xapps/flags/et.png less more
Binary diff not shown
files/usr/share/xapps/flags/fi.png less more
Binary diff not shown
files/usr/share/xapps/flags/fj.png less more
Binary diff not shown
files/usr/share/xapps/flags/fk.png less more
Binary diff not shown
files/usr/share/xapps/flags/fm.png less more
Binary diff not shown
files/usr/share/xapps/flags/fo.png less more
Binary diff not shown
files/usr/share/xapps/flags/fr.png less more
Binary diff not shown
files/usr/share/xapps/flags/ga.png less more
Binary diff not shown
files/usr/share/xapps/flags/gb.png less more
Binary diff not shown
files/usr/share/xapps/flags/gd.png less more
Binary diff not shown
files/usr/share/xapps/flags/ge.png less more
Binary diff not shown
files/usr/share/xapps/flags/gf.png less more
Binary diff not shown
files/usr/share/xapps/flags/gg.png less more
Binary diff not shown
files/usr/share/xapps/flags/gh.png less more
Binary diff not shown
files/usr/share/xapps/flags/gi.png less more
Binary diff not shown
files/usr/share/xapps/flags/gl.png less more
Binary diff not shown
files/usr/share/xapps/flags/gm.png less more
Binary diff not shown
files/usr/share/xapps/flags/gn.png less more
Binary diff not shown
files/usr/share/xapps/flags/gp.png less more
Binary diff not shown
files/usr/share/xapps/flags/gq.png less more
Binary diff not shown
files/usr/share/xapps/flags/gr.png less more
Binary diff not shown
files/usr/share/xapps/flags/gs.png less more
Binary diff not shown
files/usr/share/xapps/flags/gt.png less more
Binary diff not shown
files/usr/share/xapps/flags/gu.png less more
Binary diff not shown
files/usr/share/xapps/flags/gw.png less more
Binary diff not shown
files/usr/share/xapps/flags/gy.png less more
Binary diff not shown
files/usr/share/xapps/flags/hk.png less more
Binary diff not shown
files/usr/share/xapps/flags/hm.png less more
Binary diff not shown
files/usr/share/xapps/flags/hn.png less more
Binary diff not shown
files/usr/share/xapps/flags/hr.png less more
Binary diff not shown
files/usr/share/xapps/flags/ht.png less more
Binary diff not shown
files/usr/share/xapps/flags/hu.png less more
Binary diff not shown
files/usr/share/xapps/flags/id.png less more
Binary diff not shown
files/usr/share/xapps/flags/ie.png less more
Binary diff not shown
files/usr/share/xapps/flags/il.png less more
Binary diff not shown
files/usr/share/xapps/flags/im.png less more
Binary diff not shown
files/usr/share/xapps/flags/in.png less more
Binary diff not shown
files/usr/share/xapps/flags/io.png less more
Binary diff not shown
files/usr/share/xapps/flags/iq.png less more
Binary diff not shown
files/usr/share/xapps/flags/ir.png less more
Binary diff not shown
files/usr/share/xapps/flags/is.png less more
Binary diff not shown
files/usr/share/xapps/flags/it.png less more
Binary diff not shown
files/usr/share/xapps/flags/je.png less more
Binary diff not shown
files/usr/share/xapps/flags/jm.png less more
Binary diff not shown
files/usr/share/xapps/flags/jo.png less more
Binary diff not shown
files/usr/share/xapps/flags/jp.png less more
Binary diff not shown
files/usr/share/xapps/flags/ke.png less more
Binary diff not shown
files/usr/share/xapps/flags/kg.png less more
Binary diff not shown
files/usr/share/xapps/flags/kh.png less more
Binary diff not shown
files/usr/share/xapps/flags/ki.png less more
Binary diff not shown
files/usr/share/xapps/flags/km.png less more
Binary diff not shown
files/usr/share/xapps/flags/kn.png less more
Binary diff not shown
files/usr/share/xapps/flags/kp.png less more
Binary diff not shown
files/usr/share/xapps/flags/kr.png less more
Binary diff not shown
files/usr/share/xapps/flags/kw.png less more
Binary diff not shown
files/usr/share/xapps/flags/ky.png less more
Binary diff not shown
files/usr/share/xapps/flags/kz.png less more
Binary diff not shown
files/usr/share/xapps/flags/la.png less more
Binary diff not shown
files/usr/share/xapps/flags/lb.png less more
Binary diff not shown
files/usr/share/xapps/flags/lc.png less more
Binary diff not shown
files/usr/share/xapps/flags/li.png less more
Binary diff not shown
files/usr/share/xapps/flags/lk.png less more
Binary diff not shown
files/usr/share/xapps/flags/lr.png less more
Binary diff not shown
files/usr/share/xapps/flags/ls.png less more
Binary diff not shown
files/usr/share/xapps/flags/lt.png less more
Binary diff not shown
files/usr/share/xapps/flags/lu.png less more
Binary diff not shown
files/usr/share/xapps/flags/lv.png less more
Binary diff not shown
files/usr/share/xapps/flags/ly.png less more
Binary diff not shown
files/usr/share/xapps/flags/ma.png less more
Binary diff not shown
files/usr/share/xapps/flags/mc.png less more
Binary diff not shown
files/usr/share/xapps/flags/md.png less more
Binary diff not shown
files/usr/share/xapps/flags/me.png less more
Binary diff not shown
files/usr/share/xapps/flags/mf.png less more
Binary diff not shown
files/usr/share/xapps/flags/mg.png less more
Binary diff not shown
files/usr/share/xapps/flags/mh.png less more
Binary diff not shown
files/usr/share/xapps/flags/mk.png less more
Binary diff not shown
files/usr/share/xapps/flags/ml.png less more
Binary diff not shown
files/usr/share/xapps/flags/mm.png less more
Binary diff not shown
files/usr/share/xapps/flags/mn.png less more
Binary diff not shown
files/usr/share/xapps/flags/mo.png less more
Binary diff not shown
files/usr/share/xapps/flags/mp.png less more
Binary diff not shown
files/usr/share/xapps/flags/mq.png less more
Binary diff not shown
files/usr/share/xapps/flags/mr.png less more
Binary diff not shown
files/usr/share/xapps/flags/ms.png less more
Binary diff not shown
files/usr/share/xapps/flags/mt.png less more
Binary diff not shown
files/usr/share/xapps/flags/mu.png less more
Binary diff not shown
files/usr/share/xapps/flags/mv.png less more
Binary diff not shown
files/usr/share/xapps/flags/mw.png less more
Binary diff not shown
files/usr/share/xapps/flags/mx.png less more
Binary diff not shown
files/usr/share/xapps/flags/my.png less more
Binary diff not shown
files/usr/share/xapps/flags/mz.png less more
Binary diff not shown
files/usr/share/xapps/flags/na.png less more
Binary diff not shown
files/usr/share/xapps/flags/nc.png less more
Binary diff not shown
files/usr/share/xapps/flags/ne.png less more
Binary diff not shown
files/usr/share/xapps/flags/nf.png less more
Binary diff not shown
files/usr/share/xapps/flags/ng.png less more
Binary diff not shown
files/usr/share/xapps/flags/ni.png less more
Binary diff not shown
files/usr/share/xapps/flags/nl.png less more
Binary diff not shown
files/usr/share/xapps/flags/no.png less more
Binary diff not shown
files/usr/share/xapps/flags/np.png less more
Binary diff not shown
files/usr/share/xapps/flags/nr.png less more
Binary diff not shown
files/usr/share/xapps/flags/nu.png less more
Binary diff not shown
files/usr/share/xapps/flags/nz.png less more
Binary diff not shown
files/usr/share/xapps/flags/om.png less more
Binary diff not shown
files/usr/share/xapps/flags/pa.png less more
Binary diff not shown
files/usr/share/xapps/flags/pe.png less more
Binary diff not shown
files/usr/share/xapps/flags/pf.png less more
Binary diff not shown
files/usr/share/xapps/flags/pg.png less more
Binary diff not shown
files/usr/share/xapps/flags/ph.png less more
Binary diff not shown
files/usr/share/xapps/flags/pk.png less more
Binary diff not shown
files/usr/share/xapps/flags/pl.png less more
Binary diff not shown
files/usr/share/xapps/flags/pm.png less more
Binary diff not shown
files/usr/share/xapps/flags/pn.png less more
Binary diff not shown
files/usr/share/xapps/flags/pr.png less more
Binary diff not shown
files/usr/share/xapps/flags/ps.png less more
Binary diff not shown
files/usr/share/xapps/flags/pt.png less more
Binary diff not shown
files/usr/share/xapps/flags/pw.png less more
Binary diff not shown
files/usr/share/xapps/flags/py.png less more
Binary diff not shown
files/usr/share/xapps/flags/qa.png less more
Binary diff not shown
files/usr/share/xapps/flags/re.png less more
Binary diff not shown
files/usr/share/xapps/flags/ro.png less more
Binary diff not shown
files/usr/share/xapps/flags/rs.png less more
Binary diff not shown
files/usr/share/xapps/flags/ru.png less more
Binary diff not shown
files/usr/share/xapps/flags/rw.png less more
Binary diff not shown
files/usr/share/xapps/flags/sa.png less more
Binary diff not shown
files/usr/share/xapps/flags/sb.png less more
Binary diff not shown
files/usr/share/xapps/flags/sc.png less more
Binary diff not shown
files/usr/share/xapps/flags/sd.png less more
Binary diff not shown
files/usr/share/xapps/flags/se.png less more
Binary diff not shown
files/usr/share/xapps/flags/sg.png less more
Binary diff not shown
files/usr/share/xapps/flags/sh.png less more
Binary diff not shown
files/usr/share/xapps/flags/si.png less more
Binary diff not shown
files/usr/share/xapps/flags/sj.png less more
Binary diff not shown
files/usr/share/xapps/flags/sk.png less more
Binary diff not shown
files/usr/share/xapps/flags/sl.png less more
Binary diff not shown
files/usr/share/xapps/flags/sm.png less more
Binary diff not shown
files/usr/share/xapps/flags/sn.png less more
Binary diff not shown
files/usr/share/xapps/flags/so.png less more
Binary diff not shown
files/usr/share/xapps/flags/sr.png less more
Binary diff not shown
files/usr/share/xapps/flags/ss.png less more
Binary diff not shown
files/usr/share/xapps/flags/st.png less more
Binary diff not shown
files/usr/share/xapps/flags/sv.png less more
Binary diff not shown
files/usr/share/xapps/flags/sx.png less more
Binary diff not shown
files/usr/share/xapps/flags/sy.png less more
Binary diff not shown
files/usr/share/xapps/flags/sz.png less more
Binary diff not shown
files/usr/share/xapps/flags/tc.png less more
Binary diff not shown
files/usr/share/xapps/flags/td.png less more
Binary diff not shown
files/usr/share/xapps/flags/tf.png less more
Binary diff not shown
files/usr/share/xapps/flags/tg.png less more
Binary diff not shown
files/usr/share/xapps/flags/th.png less more
Binary diff not shown
files/usr/share/xapps/flags/tj.png less more
Binary diff not shown
files/usr/share/xapps/flags/tk.png less more
Binary diff not shown
files/usr/share/xapps/flags/tl.png less more
Binary diff not shown
files/usr/share/xapps/flags/tm.png less more
Binary diff not shown
files/usr/share/xapps/flags/tn.png less more
Binary diff not shown
files/usr/share/xapps/flags/to.png less more
Binary diff not shown
files/usr/share/xapps/flags/tr.png less more
Binary diff not shown
files/usr/share/xapps/flags/tt.png less more
Binary diff not shown
files/usr/share/xapps/flags/tv.png less more
Binary diff not shown
files/usr/share/xapps/flags/tw.png less more
Binary diff not shown
files/usr/share/xapps/flags/tz.png less more
Binary diff not shown
files/usr/share/xapps/flags/ua.png less more
Binary diff not shown
files/usr/share/xapps/flags/ug.png less more
Binary diff not shown
files/usr/share/xapps/flags/um.png less more
Binary diff not shown
files/usr/share/xapps/flags/us.png less more
Binary diff not shown
files/usr/share/xapps/flags/uy.png less more
Binary diff not shown
files/usr/share/xapps/flags/uz.png less more
Binary diff not shown
files/usr/share/xapps/flags/va.png less more
Binary diff not shown
files/usr/share/xapps/flags/vc.png less more
Binary diff not shown
files/usr/share/xapps/flags/ve.png less more
Binary diff not shown
files/usr/share/xapps/flags/vg.png less more
Binary diff not shown
files/usr/share/xapps/flags/vi.png less more
Binary diff not shown
files/usr/share/xapps/flags/vn.png less more
Binary diff not shown
files/usr/share/xapps/flags/vu.png less more
Binary diff not shown
files/usr/share/xapps/flags/wf.png less more
Binary diff not shown
files/usr/share/xapps/flags/ws.png less more
Binary diff not shown
files/usr/share/xapps/flags/ye.png less more
Binary diff not shown
files/usr/share/xapps/flags/yt.png less more
Binary diff not shown
files/usr/share/xapps/flags/za.png less more
Binary diff not shown
files/usr/share/xapps/flags/zm.png less more
Binary diff not shown
files/usr/share/xapps/flags/zw.png less more
Binary diff not shown
88 #include <glib/gstdio.h>
99 #include <gdk/gdk.h>
1010 #include <gtk/gtk.h>
11 #include <cairo.h>
1211
1312 #include <libgnomekbd/gkbd-configuration.h>
1413
1817 {
1918 PROP_0,
2019
21 PROP_ENABLED,
22 PROP_USE_CAPS,
20 PROP_ENABLED
2321 };
2422
2523 enum
3230
3331 static guint signals[LAST_SIGNAL] = { 0, };
3432
33 typedef struct
34 {
35 gchar *group_name;
36 gchar *variant_name;
37
38 gchar *group_label;
39 gint group_dupe_id;
40
41 gchar *variant_label;
42 gint variant_dupe_id;
43 } GroupData;
44
45 #define GROUP_DATA(ptr, idx) ((GroupData *) g_ptr_array_index (ptr, idx))
46
47 static void
48 group_data_free (GroupData *data)
49 {
50 g_clear_pointer (&data->group_name, g_free);
51 g_clear_pointer (&data->group_label, g_free);
52 g_clear_pointer (&data->variant_label, g_free);
53 data->group_dupe_id = 0;
54 data->variant_dupe_id = 0;
55
56 g_slice_free (GroupData, data);
57 }
58
3559 struct _XAppKbdLayoutControllerPrivate
3660 {
3761 GkbdConfiguration *config;
3862
3963 gint num_groups;
40 gchar *flag_dir;
41 gchar *temp_flag_theme_dir;
42
43 gchar *icon_names[4];
44 gchar *text_store[4];
64
65 GPtrArray *group_data;
4566
4667 gulong changed_id;
4768 gulong group_changed_id;
5374 G_DEFINE_TYPE (XAppKbdLayoutController, xapp_kbd_layout_controller, G_TYPE_OBJECT);
5475
5576 static void
56 initialize_flag_dir (XAppKbdLayoutController *controller)
57 {
58 XAppKbdLayoutControllerPrivate *priv = controller->priv;
59 gint i;
60
61 const char * const * data_dirs;
62
63 data_dirs = g_get_system_data_dirs ();
64
65 for (i = 0; data_dirs[i] != NULL; i++)
66 {
67 gchar *try_path = g_build_filename (data_dirs[i], "xapps", "flags", NULL);
68
69 if (g_file_test (try_path, G_FILE_TEST_EXISTS))
70 {
71 priv->flag_dir = g_strdup (try_path);
72 break;
73 }
74
75 g_free (try_path);
76 }
77 }
78
79 static void
80 initialize_icon_theme (XAppKbdLayoutController *controller)
81 {
82 XAppKbdLayoutControllerPrivate *priv = controller->priv;
83
84 const gchar *cache_dir = g_get_user_cache_dir ();
85
86 gchar *path = g_build_filename (cache_dir, "xapp-kbd-layout-controller", NULL);
87
88 g_mkdir_with_parents (path, 0700);
89
90 priv->temp_flag_theme_dir = path;
91
92 gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (), path);
93 }
94
95 static void
9677 clear_stores (XAppKbdLayoutController *controller)
9778 {
9879 XAppKbdLayoutControllerPrivate *priv = controller->priv;
9980
100 gint i;
101
102 for (i = 0; i < 4; i++)
103 {
104 g_clear_pointer (&priv->text_store[i], g_free);
105 g_clear_pointer (&priv->icon_names[i], g_free);
106 }
107 }
108
109 typedef struct
110 {
111 gchar *group;
112 gint id;
113 } GroupData;
114
115 static void
116 group_data_free (GroupData *data)
117 {
118 g_clear_pointer (&data->group, g_free);
119 data->id = 0;
120
121 g_slice_free (GroupData, data);
81 g_clear_pointer (&priv->group_data, g_ptr_array_unref);
12282 }
12383
12484 static gchar *
125 create_text (XAppKbdLayoutController *controller,
126 const gchar *name,
127 gint id)
85 create_label (XAppKbdLayoutController *controller,
86 const gchar *name,
87 gint dupe_id)
12888 {
12989 if (g_utf8_validate (name, -1, NULL))
13090 {
13999
140100 g_free (utf8_cased);
141101
142 if (id > 0)
102 if (dupe_id > 0)
143103 {
144 string = g_string_append_unichar (string, 0x2080 + id);
104 string = g_string_append_unichar (string, 0x2080 + dupe_id);
145105 }
146106
147107 return g_string_free (string, FALSE);
148108 }
149109
150110 return NULL;
151 }
152
153 static GdkPixbuf *
154 add_notation (GdkPixbuf *original, gint id)
155 {
156 gint width, height;
157 cairo_surface_t *surface;
158 cairo_t *cr;
159
160 width = gdk_pixbuf_get_width (original);
161 height = gdk_pixbuf_get_height (original);
162
163 surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
164
165 if (surface == NULL)
166 {
167 return original;
168 }
169
170 cr = cairo_create (surface);
171
172 gdk_cairo_set_source_pixbuf (cr, original, 0, 0);
173 cairo_paint (cr);
174
175 gint rx, ry, rw, rh;
176
177 rx = rw = width / 2;
178 ry = rh = height / 2;
179
180 cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, .5);
181 cairo_rectangle (cr, rx, ry, rw, rh);
182 cairo_fill (cr);
183
184 cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, .8);
185 cairo_rectangle (cr, rx - 1, ry - 1, rw, rh);
186 cairo_fill (cr);
187
188 cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 1.0);
189
190 gchar *num_string = g_strdup_printf ("%d", id);
191 cairo_select_font_face (cr, "sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
192 cairo_set_font_size (cr, height / 2);
193
194 cairo_text_extents_t ext;
195 cairo_text_extents (cr, num_string, &ext);
196
197 cairo_move_to (cr, rx + (rw / 2) - (ext.width / 2) - 1, ry + (rh / 2) + (ext.height / 2) - 1);
198
199 cairo_show_text (cr, num_string);
200 g_free (num_string);
201
202 GdkPixbuf *ret = gdk_pixbuf_get_from_surface (surface, 0, 0, width, height);
203
204 cairo_surface_destroy (surface);
205 cairo_destroy (cr);
206
207 if (ret == NULL)
208 {
209 return original;
210 }
211
212 g_object_unref (original);
213
214 return ret;
215 }
216
217 static gchar *
218 create_pixbuf (XAppKbdLayoutController *controller,
219 guint group,
220 const gchar *name,
221 gint id)
222 {
223 XAppKbdLayoutControllerPrivate *priv = controller->priv;
224 GdkPixbuf *pixbuf = NULL;
225
226 GdkPixbuf *flag_pixbuf;
227
228 gchar *filename = g_strdup_printf ("%s.png", name);
229 gchar *full_path = g_build_filename (priv->flag_dir, filename, NULL);
230
231 flag_pixbuf = gdk_pixbuf_new_from_file (full_path, NULL);
232
233 g_free (filename);
234 g_free (full_path);
235
236 if (flag_pixbuf != NULL)
237 {
238 if (id == 0)
239 {
240 pixbuf = flag_pixbuf;
241 }
242 else
243 {
244 pixbuf = add_notation (flag_pixbuf, id);
245 }
246 }
247
248 if (flag_pixbuf != NULL)
249 {
250 gchar *save_name = g_strdup_printf ("xapp-kbd-layout-%d.png", group);
251
252 gchar *path = g_build_filename (priv->temp_flag_theme_dir, save_name, NULL);
253 g_remove (path);
254
255 gdk_pixbuf_save (pixbuf,
256 path,
257 "png",
258 NULL,
259 NULL);
260
261 g_object_unref (pixbuf);
262
263 g_free (save_name);
264 g_free (path);
265 }
266 else
267 {
268 return NULL;
269 }
270
271 return g_strdup_printf ("xapp-kbd-layout-%d", group);
272111 }
273112
274113 static void
288127
289128 priv->enabled = TRUE;
290129
291 /* Make a list of [name, id] tuples, where name is the group/flag name,
292 * and id is either 0, or, if a flag name is duplicated, a 1, 2, 3, etc...
293 */
294 gint i, j, id;
130 /* Populate the GroupData pointer array */
131
132 gint i, j, group_dupe_id, variant_dupe_id;
295133 GPtrArray *list = g_ptr_array_new_with_free_func ((GDestroyNotify) group_data_free);
296134
297135 for (i = 0; i < priv->num_groups; i++)
298136 {
299137 GroupData *data = g_slice_new0 (GroupData);
300138
301 gchar *name = gkbd_configuration_get_group_name (priv->config, i);
302 id = 0;
139 /* Iterate through group names, figure out subscript values for duplicates */
140
141 gchar *group_name = gkbd_configuration_get_group_name (priv->config, i);
142 group_dupe_id = 0;
303143
304144 for (j = 0; j < list->len; j++)
305145 {
306146 GroupData *iter = g_ptr_array_index (list, j);
307147
308 if (g_strcmp0 (name, iter->group) == 0)
148 if (g_strcmp0 (group_name, iter->group_name) == 0)
309149 {
310 id++;
311 iter->id = id;
150 group_dupe_id++;
151 iter->group_dupe_id = group_dupe_id;
312152 }
313153 }
314154
315 if (id > 0)
155 if (group_dupe_id > 0)
316156 {
317 id++;
157 group_dupe_id++;
318158 }
319159
320 data->group = name;
321 data->id = id;
322
160 data->group_name = group_name;
161 data->group_dupe_id = group_dupe_id;
162
163 /* Iterate through layout/variant names, figure out subscript values for duplicates */
164
165 gchar *variant_name = gkbd_configuration_extract_layout_name (priv->config, i);
166 variant_dupe_id = 0;
167
168 for (j = 0; j < list->len; j++)
169 {
170 GroupData *iter = g_ptr_array_index (list, j);
171
172 if (g_strcmp0 (variant_name, iter->variant_name) == 0)
173 {
174 variant_dupe_id++;
175 iter->variant_dupe_id = variant_dupe_id;
176 }
177 }
178
179 if (variant_dupe_id > 0)
180 {
181 variant_dupe_id++;
182 }
183
184 data->variant_name = variant_name;
185 data->variant_dupe_id = variant_dupe_id;
186
187 /* Finally, add the GroupData slice to the array */
323188 g_ptr_array_add (list, data);
324189 }
325190
326 for (i = 0; i < list->len; i++)
191 for (i = 0; i < priv->num_groups; i++)
327192 {
328193 GroupData *data = g_ptr_array_index (list, i);
329194
330 priv->icon_names[i] = create_pixbuf (controller, i, data->group, data->id);
331 priv->text_store[i] = create_text (controller, data->group, data->id);
332 }
333
334 gtk_icon_theme_rescan_if_needed (gtk_icon_theme_get_default ());
335
336 g_ptr_array_unref (list);
195 /* Now generate labels for group names and for variant names. This is done
196 * in its own loop after the initial run, because previous dupe ids could have
197 * changed later in the loop.
198 */
199
200 data->group_label = create_label (controller, data->group_name, data->group_dupe_id);
201 data->variant_label = create_label (controller, data->variant_name, data->variant_dupe_id);
202 }
203
204 priv->group_data = list;
337205 }
338206
339207 static gboolean
388256
389257 priv->config = gkbd_configuration_get ();
390258 priv->enabled = FALSE;
391 priv->flag_dir = NULL;
392 priv->temp_flag_theme_dir = NULL;
393259 priv->idle_changed_id = 0;
260
261 priv->group_data = NULL;
394262 }
395263
396264 static void
400268
401269 XAppKbdLayoutController *controller = XAPP_KBD_LAYOUT_CONTROLLER (object);
402270 XAppKbdLayoutControllerPrivate *priv = controller->priv;
403
404 initialize_flag_dir (controller);
405
406 initialize_icon_theme (controller);
407271
408272 gkbd_configuration_start_listen (priv->config);
409273
478342 XAppKbdLayoutControllerPrivate *priv = controller->priv;
479343
480344 g_clear_object (&priv->config);
481 g_clear_pointer (&priv->flag_dir, g_free);
482 g_clear_pointer (&priv->temp_flag_theme_dir, g_free);
483345
484346 G_OBJECT_CLASS (xapp_kbd_layout_controller_parent_class)->finalize (object);
485347 }
621483 /**
622484 * xapp_kbd_layout_controller_get_current_icon_name:
623485 *
624 * Returns the icon name to use for the current layout
486 * Returns the icon file name (no path or extension) to use for the current layout
625487 *
626488 * Returns: (transfer full): a new string with the icon name.
627489 */
634496
635497 guint current = gkbd_configuration_get_current_group (priv->config);
636498
637 return g_strdup (priv->icon_names[current]);
638 }
639
499 return g_strdup (GROUP_DATA (priv->group_data, current)->group_name);
500 }
640501
641502 /**
642503 * xapp_kbd_layout_controller_get_icon_name_for_group:
643504 *
644 * Returns the icon name to use for the specified layout.
505 * Returns the icon file name (no path or extension) to use for the specified layout.
645506 *
646507 * Returns: (transfer full): a new string with the icon name.
647508 */
648509 gchar *
649 xapp_kbd_layout_controller_get_icon_name_for_group (XAppKbdLayoutController *controller, guint group)
510 xapp_kbd_layout_controller_get_icon_name_for_group (XAppKbdLayoutController *controller,
511 guint group)
650512 {
651513 g_return_val_if_fail (controller->priv->enabled, NULL);
652514 g_return_val_if_fail (group <= controller->priv->num_groups, NULL);
653515
654516 XAppKbdLayoutControllerPrivate *priv = controller->priv;
655517
656 return g_strdup (priv->icon_names[group]);
657 }
658
659 /**
660 * xapp_kbd_layout_controller_get_current_short_name:
661 *
662 * Returns the short name (and subscript, if any) of the current layout
518 return g_strdup (GROUP_DATA (priv->group_data, group)->group_name);
519 }
520
521 /**
522 * xapp_kbd_layout_controller_get_current_flag_id:
523 *
524 * Returns the duplicate id for the current layout
525 *
526 * Returns: the id
527 */
528 gint
529 xapp_kbd_layout_controller_get_current_flag_id (XAppKbdLayoutController *controller)
530 {
531 g_return_val_if_fail (controller->priv->enabled, 0);
532
533 XAppKbdLayoutControllerPrivate *priv = controller->priv;
534
535 guint current = gkbd_configuration_get_current_group (priv->config);
536
537 return GROUP_DATA (priv->group_data, current)->group_dupe_id;
538 }
539
540
541 /**
542 * xapp_kbd_layout_controller_flag_id_for_group:
543 *
544 * Returns the duplicate id for the specified layout
545 *
546 * Returns: the id
547 */
548 gint
549 xapp_kbd_layout_controller_get_flag_id_for_group (XAppKbdLayoutController *controller,
550 guint group)
551 {
552 g_return_val_if_fail (controller->priv->enabled, 0);
553 g_return_val_if_fail (group < controller->priv->num_groups, 0);
554
555 XAppKbdLayoutControllerPrivate *priv = controller->priv;
556
557 return GROUP_DATA (priv->group_data, group)->group_dupe_id;
558 }
559
560 /**
561 * xapp_kbd_layout_controller_get_current_short_group_label:
562 *
563 * Returns the short group label (and subscript, if any) of the current layout
663564 *
664565 * Returns: (transfer full): a new string or NULL.
665566 */
666567 gchar *
667 xapp_kbd_layout_controller_get_short_name (XAppKbdLayoutController *controller)
568 xapp_kbd_layout_controller_get_current_short_group_label (XAppKbdLayoutController *controller)
668569 {
669570 g_return_val_if_fail (controller->priv->enabled, NULL);
670571
672573
673574 guint current = gkbd_configuration_get_current_group (priv->config);
674575
675 return g_strdup (priv->text_store[current]);
676 }
677
678 /**
679 * xapp_kbd_layout_controller_get_short_name_for_group:
680 *
681 * Returns the short name and subscript of the specified group.
576 return g_strdup (GROUP_DATA (priv->group_data, current)->group_label);
577 }
578
579 /**
580 * xapp_kbd_layout_controller_get_short_group_label_for_group:
581 *
582 * Returns the short group label and subscript of the specified layout.
682583 *
683584 * Returns: (transfer full): a new string or NULL.
684585 */
685586 gchar *
686 xapp_kbd_layout_controller_get_short_name_for_group (XAppKbdLayoutController *controller,
687 guint group)
688 {
689 g_return_val_if_fail (controller->priv->enabled, NULL);
690
691 XAppKbdLayoutControllerPrivate *priv = controller->priv;
692
587 xapp_kbd_layout_controller_get_short_group_label_for_group (XAppKbdLayoutController *controller,
588 guint group)
589 {
590 g_return_val_if_fail (controller->priv->enabled, NULL);
693591 g_return_val_if_fail (group < controller->priv->num_groups, NULL);
694592
695 return g_strdup (priv->text_store[group]);
696 }
593 XAppKbdLayoutControllerPrivate *priv = controller->priv;
594
595
596 return g_strdup (GROUP_DATA (priv->group_data, group)->group_label);
597 }
598
599 /**
600 * xapp_kbd_layout_controller_get_current_variant_label:
601 *
602 * Returns the variant label (and subscript, if any) of the current layout
603 *
604 * Returns: (transfer full): a new string or NULL.
605 */
606 gchar *
607 xapp_kbd_layout_controller_get_current_variant_label (XAppKbdLayoutController *controller)
608 {
609 g_return_val_if_fail (controller->priv->enabled, NULL);
610
611 XAppKbdLayoutControllerPrivate *priv = controller->priv;
612
613 guint current = gkbd_configuration_get_current_group (priv->config);
614
615 return g_strdup (GROUP_DATA (priv->group_data, current)->variant_label);
616 }
617
618 /**
619 * xapp_kbd_layout_controller_get_variant_label_for_group:
620 *
621 * Returns the variant label and subscript of the specified layout.
622 *
623 * Returns: (transfer full): a new string or NULL.
624 */
625 gchar *
626 xapp_kbd_layout_controller_get_variant_label_for_group (XAppKbdLayoutController *controller,
627 guint group)
628 {
629 g_return_val_if_fail (controller->priv->enabled, NULL);
630
631 XAppKbdLayoutControllerPrivate *priv = controller->priv;
632
633 g_return_val_if_fail (group < controller->priv->num_groups, NULL);
634
635 return g_strdup (GROUP_DATA (priv->group_data, group)->variant_label);
636 }
637
638 void
639 xapp_kbd_layout_controller_render_cairo_subscript (cairo_t *cr,
640 gdouble x,
641 gdouble y,
642 gdouble width,
643 gdouble height,
644 gint subscript)
645 {
646 if (subscript == 0)
647 {
648 return;
649 }
650
651 cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, .5);
652 cairo_rectangle (cr, x, y, width, height);
653 cairo_fill (cr);
654
655 cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, .8);
656 cairo_rectangle (cr, x + 1, y + 1, width - 2, height - 2);
657 cairo_fill (cr);
658
659 cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 1.0);
660
661 gchar *num_string = g_strdup_printf ("%d", subscript);
662 cairo_select_font_face (cr, "sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
663 cairo_set_font_size (cr, height - 2.0);
664
665 cairo_text_extents_t ext;
666 cairo_text_extents (cr, num_string, &ext);
667
668 cairo_move_to (cr,
669 (x + (width / 2.0) - (ext.width / 2.0)),
670 (y + (height / 2.0) + (ext.height / 2.0)));
671
672 cairo_show_text (cr, num_string);
673 g_free (num_string);
674 }
675
44 #include <gdk-pixbuf/gdk-pixbuf.h>
55
66 #include <glib-object.h>
7 #include <cairo.h>
78
89 G_BEGIN_DECLS
910
3031 GObjectClass parent_class;
3132 };
3233
33 GType xapp_kbd_layout_controller_get_type (void);
34 XAppKbdLayoutController *xapp_kbd_layout_controller_new (void);
35 gboolean xapp_kbd_layout_controller_get_enabled (XAppKbdLayoutController *controller);
36 guint xapp_kbd_layout_controller_get_current_group (XAppKbdLayoutController *controller);
37 void xapp_kbd_layout_controller_set_current_group (XAppKbdLayoutController *controller,
38 guint group);
39 void xapp_kbd_layout_controller_next_group (XAppKbdLayoutController *controller);
40 void xapp_kbd_layout_controller_previous_group (XAppKbdLayoutController *controller);
41 gchar *xapp_kbd_layout_controller_get_current_name (XAppKbdLayoutController *controller);
42 gchar **xapp_kbd_layout_controller_get_all_names (XAppKbdLayoutController *controller);
43 gchar *xapp_kbd_layout_controller_get_current_icon_name (XAppKbdLayoutController *controller);
44 gchar *xapp_kbd_layout_controller_get_icon_name_for_group (XAppKbdLayoutController *controller,
45 guint group);
46 gchar *xapp_kbd_layout_controller_get_short_name (XAppKbdLayoutController *controller);
47 gchar *xapp_kbd_layout_controller_get_short_name_for_group (XAppKbdLayoutController *controller,
48 guint group);
34 GType xapp_kbd_layout_controller_get_type (void);
35 XAppKbdLayoutController *xapp_kbd_layout_controller_new (void);
36 gboolean xapp_kbd_layout_controller_get_enabled (XAppKbdLayoutController *controller);
37 guint xapp_kbd_layout_controller_get_current_group (XAppKbdLayoutController *controller);
38 void xapp_kbd_layout_controller_set_current_group (XAppKbdLayoutController *controller,
39 guint group);
40 void xapp_kbd_layout_controller_next_group (XAppKbdLayoutController *controller);
41 void xapp_kbd_layout_controller_previous_group (XAppKbdLayoutController *controller);
42 gchar *xapp_kbd_layout_controller_get_current_name (XAppKbdLayoutController *controller);
43 gchar **xapp_kbd_layout_controller_get_all_names (XAppKbdLayoutController *controller);
44
45 gchar *xapp_kbd_layout_controller_get_current_icon_name (XAppKbdLayoutController *controller);
46 gchar *xapp_kbd_layout_controller_get_icon_name_for_group (XAppKbdLayoutController *controller,
47 guint group);
48 gint xapp_kbd_layout_controller_get_current_flag_id (XAppKbdLayoutController *controller);
49 gint xapp_kbd_layout_controller_get_flag_id_for_group (XAppKbdLayoutController *controller,
50 guint group);
51 gchar *xapp_kbd_layout_controller_get_current_short_group_label (XAppKbdLayoutController *controller);
52 gchar *xapp_kbd_layout_controller_get_short_group_label_for_group (XAppKbdLayoutController *controller,
53 guint group);
54 gchar *xapp_kbd_layout_controller_get_current_variant_label (XAppKbdLayoutController *controller);
55
56 gchar *xapp_kbd_layout_controller_get_variant_label_for_group (XAppKbdLayoutController *controller,
57 guint group);
58
59 /* Class function */
60 void xapp_kbd_layout_controller_render_cairo_subscript (cairo_t *cr,
61 gdouble x,
62 gdouble y,
63 gdouble width,
64 gdouble height,
65 gint subscript);
4966
5067 G_END_DECLS
5168
1010 gi.require_version('Gtk', '3.0')
1111 gi.require_version('XApp', '1.0')
1212
13 from gi.repository import Gtk, XApp, GObject
13 from gi.repository import Gtk, XApp, GObject, Gkbd, GdkPixbuf
1414
1515 signal.signal(signal.SIGINT, signal.SIG_DFL)
1616
1818 def __init__(self):
1919 win = Gtk.Window()
2020 frame = Gtk.Frame()
21 frame.set_margin_start(6)
22 frame.set_margin_end(6)
23 frame.set_margin_top(6)
24 frame.set_margin_bottom(6)
21 frame.set_margin_start(2)
22 frame.set_margin_end(2)
23 frame.set_margin_top(2)
24 frame.set_margin_bottom(2)
2525
2626 win.add(frame)
2727
2828 box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
29 box.set_margin_start(2)
30 box.set_margin_end(2)
31 box.set_margin_top(2)
32 box.set_margin_bottom(2)
33
2934 frame.add(box)
3035
31 self.show_flags = False
3236 self.use_caps = False
3337
3438 self.controller = XApp.KbdLayoutController()
3539 self.controller.connect("layout-changed", self.on_layout_changed)
3640 self.controller.connect("config-changed", self.on_config_changed)
3741
38 hbox = Gtk.HBox()
39 box.pack_start(hbox, True, True, 4)
40
41 self.button = Gtk.Button()
42 self.button.set_size_request(48, 48)
43 self.button.connect("clicked", self.on_button_clicked)
44 hbox.pack_start(self.button, False, False, 4)
45
4642 self.label = Gtk.Label()
4743 self.label.set_text(self.controller.get_current_name())
48 hbox.pack_start(self.label, True, True, 4)
44 box.pack_start(self.label, True, True, 4)
4945
50 check = Gtk.CheckButton.new_with_label("Show flags")
51 check.connect("toggled", self.on_flag_toggled)
52 box.pack_start(check, True, True, 4)
46 self.flag_button = Gtk.Button()
47 box.pack_start(self.flag_button, True, True, 4)
48 self.flag_button.connect("clicked", self.on_button_clicked)
49
50 self.group_button = Gtk.Button()
51 box.pack_start(self.group_button, True, True, 4)
52 self.group_button.connect("clicked", self.on_button_clicked)
53
54 self.variant_button = Gtk.Button()
55 box.pack_start(self.variant_button, True, True, 4)
56 self.variant_button.connect("clicked", self.on_button_clicked)
5357
5458 check = Gtk.CheckButton.new_with_label("Use caps")
5559 check.connect("toggled", self.on_caps_toggled)
6569
6670 Gtk.main()
6771
68 def on_flag_toggled(self, widget):
69 self.show_flags = widget.get_active()
70 self.on_layout_changed(self.controller)
71
7272 def on_caps_toggled(self, widget):
7373 self.use_caps = widget.get_active()
7474 self.on_layout_changed(self.controller)
7878
7979 def on_layout_changed(self, controller, group=None):
8080 handled = False
81 if self.show_flags:
82 name = self.controller.get_current_icon_name()
83 if name != None:
84 image = Gtk.Image.new_from_icon_name(name, Gtk.IconSize.DIALOG)
85 self.button.set_image(image)
86 handled = True
81
82 name = self.controller.get_current_icon_name()
83 if name != None:
84 filename = "/usr/share/flags/iso-4x3-svg/%s.svgz" % name
85
86 valid, width, height = Gtk.IconSize.lookup(Gtk.IconSize.BUTTON)
87 pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(filename, -1, height)
88
89 image = Gtk.Image.new_from_pixbuf(pixbuf)
90 self.flag_button.set_image(image)
91 handled = True
8792
8893 if not handled:
89 name = self.controller.get_short_name()
90 if self.use_caps:
91 name = name.upper()
92 label = Gtk.Label(name)
93 label.show()
94 self.button.set_image(label)
94 name = self.controller.get_current_short_group_label()
95 self.flag_button.set_label(name.upper())
96 self.flag_button.set_image(None)
9597
9698 self.label.set_text(self.controller.get_current_name())
99
100 group_label = self.controller.get_current_short_group_label()
101 variant_label = self.controller.get_current_variant_label()
102
103 if self.use_caps:
104 group_label = group_label.upper()
105 variant_label = variant_label.upper()
106
107 self.group_button.set_label(group_label)
108 self.variant_button.set_label(variant_label)
97109
98110 def on_config_changed(self, controller):
99111 GObject.idle_add(self.on_layout_changed, controller)