xkb: choose model dialog with clickable columns
[lxde/lxpanel.git] / src / plugins / xkb / xkb-plugin.c
CommitLineData
438d9fdb
MJ
1/**
2 * Copyright (c) 2010 LxDE Developers, see the file AUTHORS for details.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19/* Originally derived from xfce4-xkb-plugin, Copyright 2004 Alexander Iliev,
20 * which credits Michael Glickman. */
22242ed4 21
4496e880
JL
22/* Modified by Giuseppe Penone <giuspen@gmail.com> starting from 2012-07 and lxpanel 0.5.10 */
23
22242ed4
HJYP
24#ifdef HAVE_CONFIG_H
25#include <config.h>
26#endif
27
28#include <glib/gi18n.h>
29
30#include <stdio.h>
45bd719e 31#include <stdlib.h>
22242ed4
HJYP
32#include <ctype.h>
33
34#include "xkb.h"
35
4496e880
JL
36enum
37{
38 COLUMN_ICON,
39 COLUMN_LAYOUT,
40 COLUMN_VARIANT,
41 NUM_COLUMNS
42};
43
44enum
45{
46 COLUMN_ADD_ICON,
47 COLUMN_ADD_LAYOUT,
48 COLUMN_ADD_DESC,
49 NUM_ADD_COLUMNS
50};
51
52enum
53{
54 COLUMN_MODEL_NAME,
55 COLUMN_MODEL_DESC,
56 NUM_MODEL_COLUMNS
57};
58
59enum
60{
61 COLUMN_CHANGE_NAME,
62 COLUMN_CHANGE_DESC,
63 NUM_CHANGE_COLUMNS
64};
65
18ecfe2a 66void panel_config_save(Panel * panel); /* defined in configurator.c */
67
4496e880
JL
68static int xkb_constructor(Plugin * p_plugin, char ** fp);
69static void xkb_destructor(Plugin * p_plugin);
70static void xkb_configure(Plugin * p, GtkWindow * parent);
71static void xkb_save_configuration(Plugin * p, FILE * fp);
72static void xkb_panel_configuration_changed(Plugin * p);
73static void xkb_settings_fill_layout_tree_model_with_config(XkbPlugin *p_xkb);
4496e880
JL
74static void xkb_update_layouts_n_variants(XkbPlugin *p_xkb);
75static void xkb_add_layout(XkbPlugin *p_xkb, gchar *layout, gchar*variant);
76static int xkb_get_flag_size(XkbPlugin *p_xkb);
77
895da737 78static void on_xkb_fbev_active_window_event(FbEv *ev, gpointer p_data);
4496e880
JL
79static gboolean on_xkb_button_scroll_event(GtkWidget * widget, GdkEventScroll * event, gpointer p_data);
80static gboolean on_xkb_button_press_event(GtkWidget * widget, GdkEventButton * event, gpointer p_data);
81static void on_radiobutton_disp_type_image_toggled(GtkToggleButton *p_radiobutton, gpointer p_data);
82static void on_radiobutton_disp_type_image_cust_toggled(GtkToggleButton *p_radiobutton, gpointer p_data);
83static void on_radiobutton_disp_type_text_toggled(GtkToggleButton *p_radiobutton, gpointer p_data);
895da737 84static void on_xkb_checkbutton_per_app_toggled(GtkToggleButton *tb, gpointer p_data);
4496e880
JL
85static void on_dialog_config_response(GtkDialog *p_dialog, gint response, gpointer p_data);
86
87static unsigned char user_active = FALSE;
88static const gchar flag_filepath_generator[] = "%s/%s.png";
89
90static int xkb_get_flag_size(XkbPlugin *p_xkb)
91{
92 int size = p_xkb->p_plugin->panel->icon_size;
93 switch(p_xkb->flag_size)
94 {
95 case 1: return size*0.5;
96 case 2: return size*0.6;
97 case 3: return size*0.7;
98 case 4: return size*0.8;
895da737 99 case 5: return size*0.9;
4496e880
JL
100 default: break;
101 }
895da737 102 return size;
4496e880 103}
d862b520 104
105/* Redraw the graphics. */
4496e880 106void xkb_redraw(XkbPlugin *p_xkb)
22242ed4 107{
d862b520 108 /* Set the image. */
109 gboolean valid_image = FALSE;
4496e880
JL
110 int size = xkb_get_flag_size(p_xkb);
111 if( (p_xkb->display_type == DISP_TYPE_IMAGE) || (p_xkb->display_type == DISP_TYPE_IMAGE_CUST) )
22242ed4 112 {
4496e880
JL
113 char * group_name = (char *)xkb_get_current_symbol_name_lowercase(p_xkb);
114 if(group_name != NULL)
d862b520 115 {
4496e880
JL
116 gchar *flag_filepath = NULL;
117 gchar *flags_dir = (p_xkb->cust_dir_exists && (p_xkb->display_type == DISP_TYPE_IMAGE_CUST)) ? g_strdup(FLAGSCUSTDIR):g_strdup(FLAGSDIR);
118 if(strchr(group_name, '/') != NULL)
119 {
120 gchar *layout_mod = g_strdup(group_name);
121 layout_mod = g_strdelimit(layout_mod, "/", '-');
122 flag_filepath = g_strdup_printf(flag_filepath_generator, flags_dir, layout_mod);
123 g_free(layout_mod);
124 }
125 else
126 {
127 flag_filepath = g_strdup_printf(flag_filepath_generator, flags_dir, group_name);
128 }
129 GdkPixbuf * unscaled_pixbuf = gdk_pixbuf_new_from_file(flag_filepath, NULL);
130 g_free(flag_filepath);
131 g_free(flags_dir);
438d9fdb
MJ
132 g_free(group_name);
133
4496e880 134 if(unscaled_pixbuf != NULL)
d862b520 135 {
438d9fdb
MJ
136 /* Loaded successfully. */
137 int width = gdk_pixbuf_get_width(unscaled_pixbuf);
138 int height = gdk_pixbuf_get_height(unscaled_pixbuf);
139 GdkPixbuf * pixbuf = gdk_pixbuf_scale_simple(unscaled_pixbuf, size * width / height, size, GDK_INTERP_BILINEAR);
4496e880 140 if(pixbuf != NULL)
438d9fdb 141 {
4496e880 142 gtk_image_set_from_pixbuf(GTK_IMAGE(p_xkb->p_image), pixbuf);
438d9fdb 143 g_object_unref(G_OBJECT(pixbuf));
4496e880
JL
144 gtk_widget_hide(p_xkb->p_label);
145 gtk_widget_show(p_xkb->p_image);
146 gtk_widget_set_tooltip_text(p_xkb->p_plugin->pwid, xkb_get_current_group_name(p_xkb));
438d9fdb
MJ
147 valid_image = TRUE;
148 }
149 g_object_unref(unscaled_pixbuf);
22242ed4
HJYP
150 }
151 }
152 }
153
d862b520 154 /* Set the label. */
4496e880 155 if( (p_xkb->display_type == DISP_TYPE_TEXT) || ( ! valid_image) )
d862b520 156 {
4496e880 157 char *group_name = (char *)xkb_get_current_symbol_name(p_xkb);
438d9fdb
MJ
158 if (group_name != NULL)
159 {
4496e880 160 GString *p_gstring_markup = g_string_new("");
895da737
JL
161 g_string_printf(p_gstring_markup,
162 "<span font='%u' weight='heavy' color=\"#%06x\">%s</span>",
163 size/2, gcolor2rgb24(&p_xkb->p_plugin->panel->gfontcolor), group_name);
4496e880
JL
164 gtk_label_set_markup(GTK_LABEL(p_xkb->p_label), p_gstring_markup->str);
165 g_string_free(p_gstring_markup, TRUE/*free also gstring->str*/);
166 gtk_widget_hide(p_xkb->p_image);
167 gtk_widget_show(p_xkb->p_label);
168 gtk_widget_set_tooltip_text(p_xkb->p_plugin->pwid, xkb_get_current_group_name(p_xkb));
d862b520 169 }
170 }
22242ed4
HJYP
171}
172
895da737
JL
173/* Handler for "active_window" event on root window listener. */
174static void on_xkb_fbev_active_window_event(FbEv * ev, gpointer p_data)
175{
176 XkbPlugin * xkb = (XkbPlugin *)p_data;
177 if (xkb->enable_perwin)
178 {
179 Window * win = fb_ev_active_window(ev);
180 if (*win != None)
181 {
182 xkb_active_window_changed(xkb, *win);
183 xkb_redraw(xkb);
184 }
185 }
186}
187
d862b520 188/* Handler for "scroll-event" on drawing area. */
4496e880 189static gboolean on_xkb_button_scroll_event(GtkWidget * widget, GdkEventScroll * event, gpointer p_data)
22242ed4 190{
4496e880 191 XkbPlugin * xkb = (XkbPlugin *)p_data;
22242ed4 192
d862b520 193 /* Change to next or previous group. */
194 xkb_change_group(xkb,
195 (((event->direction == GDK_SCROLL_UP) || (event->direction == GDK_SCROLL_RIGHT)) ? 1 : -1));
196 return TRUE;
22242ed4
HJYP
197}
198
d862b520 199/* Handler for button-press-event on top level widget. */
4496e880 200static gboolean on_xkb_button_press_event(GtkWidget * widget, GdkEventButton * event, gpointer p_data)
22242ed4 201{
4496e880 202 XkbPlugin * xkb = (XkbPlugin *)p_data;
22242ed4 203
d862b520 204 /* Standard right-click handling. */
4496e880 205 if (plugin_button_press_event(widget, event, xkb->p_plugin))
d862b520 206 return TRUE;
22242ed4 207
d862b520 208 /* Change to next group. */
209 xkb_change_group(xkb, 1);
18ecfe2a 210 return TRUE;
22242ed4
HJYP
211}
212
d862b520 213/* Plugin constructor. */
4496e880 214static int xkb_constructor(Plugin * p_plugin, char ** fp)
22242ed4 215{
d862b520 216 /* Allocate plugin context and set into Plugin private data pointer. */
4496e880
JL
217 XkbPlugin * p_xkb = g_new0(XkbPlugin, 1);
218 p_xkb->p_plugin = p_plugin;
219 p_plugin->priv = p_xkb;
d862b520 220
221 /* Initialize to defaults. */
4496e880 222 p_xkb->display_type = DISP_TYPE_IMAGE;
895da737 223 p_xkb->enable_perwin = FALSE;
4496e880
JL
224 p_xkb->kbd_model = NULL;
225 p_xkb->kbd_layouts = NULL;
226 p_xkb->kbd_variants = NULL;
227 p_xkb->kbd_change_option = NULL;
228 p_xkb->flag_size = 3;
229 p_xkb->cust_dir_exists = g_file_test(FLAGSCUSTDIR, G_FILE_TEST_IS_DIR);
d862b520 230
231 /* Load parameters from the configuration file. */
232 line s;
233 s.len = 256;
234 if (fp != NULL)
235 {
236 while (lxpanel_get_line(fp, &s) != LINE_BLOCK_END)
237 {
238 if (s.type == LINE_NONE)
239 {
240 ERR( "xkb: illegal token %s\n", s.str);
241 return 0;
242 }
243 if (s.type == LINE_VAR)
244 {
4496e880
JL
245 if(g_ascii_strcasecmp(s.t[0], "DisplayType") == 0)
246 {
247 p_xkb->display_type = atoi(s.t[1]);
248 }
895da737
JL
249 else if(g_ascii_strcasecmp(s.t[0], "PerWinLayout") == 0)
250 {
251 p_xkb->enable_perwin = str2num(bool_pair, s.t[1], 0);
252 }
4496e880
JL
253 else if(g_ascii_strcasecmp(s.t[0], "Model") == 0)
254 {
255 p_xkb->kbd_model = g_strdup(s.t[1]);
256 }
257 else if(g_ascii_strcasecmp(s.t[0], "LayoutsList") == 0)
258 {
259 p_xkb->kbd_layouts = g_strdup(s.t[1]);
260 }
261 else if(g_ascii_strcasecmp(s.t[0], "VariantsList") == 0)
262 {
263 p_xkb->kbd_variants = g_strdup(s.t[1]);
264 }
265 else if(g_ascii_strcasecmp(s.t[0], "ToggleOpt") == 0)
266 {
267 p_xkb->kbd_change_option = g_strdup(s.t[1]);
268 }
269 else if(g_ascii_strcasecmp(s.t[0], "FlagSize") == 0)
270 {
271 p_xkb->flag_size = atoi(s.t[1]);
272 }
d862b520 273 else
274 ERR( "xkb: unknown var %s\n", s.t[0]);
275 }
276 else
277 {
278 ERR( "xkb: illegal in this context %s\n", s.str);
279 return 0;
280 }
281 }
282 }
2918994e 283
d862b520 284 /* Allocate top level widget and set into Plugin widget pointer. */
4496e880
JL
285 p_plugin->pwid = gtk_event_box_new();
286 gtk_widget_add_events(p_plugin->pwid, GDK_BUTTON_PRESS_MASK);
d862b520 287
288 /* Create a horizontal box as the child of the button. */
289 GtkWidget * hbox = gtk_hbox_new(FALSE, 0);
4496e880
JL
290 gtk_container_set_border_width(GTK_CONTAINER(hbox), 1);
291 gtk_container_add(GTK_CONTAINER(p_xkb->p_plugin->pwid), hbox);
d862b520 292 gtk_widget_show(hbox);
293
294 /* Create a label and an image as children of the horizontal box.
295 * Only one of these is visible at a time, controlled by user preference
296 * and the successful loading of the image. */
4496e880
JL
297 p_xkb->p_label = gtk_label_new("");
298 gtk_container_add(GTK_CONTAINER(hbox), p_xkb->p_label);
299 p_xkb->p_image = gtk_image_new();
300 gtk_container_add(GTK_CONTAINER(hbox), p_xkb->p_image);
d862b520 301
895da737
JL
302 /* Chech for first run */
303 if( (p_xkb->kbd_model == NULL) || (p_xkb->kbd_layouts == NULL) ||
304 (p_xkb->kbd_variants == NULL) || (p_xkb->kbd_change_option == NULL) )
305 {
306 /* This is a first run, read the current layout */
307 xkb_mechanism_constructor(p_xkb);
308
309 if(p_xkb->kbd_model != NULL) g_free(p_xkb->kbd_model);
310 if(p_xkb->kbd_layouts != NULL) g_free(p_xkb->kbd_layouts);
311 if(p_xkb->kbd_variants != NULL) g_free(p_xkb->kbd_variants);
312 if(p_xkb->kbd_change_option != NULL) g_free(p_xkb->kbd_change_option);
313
314 p_xkb->kbd_model = g_strdup("pc105");
315 gchar *symbol_name_lowercase = (char *)xkb_get_current_symbol_name_lowercase(p_xkb);
316 p_xkb->kbd_layouts = g_strdup(symbol_name_lowercase);
317 g_free(symbol_name_lowercase);
318 p_xkb->kbd_variants = g_strdup(",");
319 p_xkb->kbd_change_option = g_strdup("shift_caps_toggle");
320
321 xkb_mechanism_destructor(p_xkb);
322 }
323
d862b520 324 /* Initialize the XKB interface. */
895da737 325 xkb_setxkbmap(p_xkb);
4496e880 326 xkb_mechanism_constructor(p_xkb);
d862b520 327
d862b520 328 /* Connect signals. */
4496e880
JL
329 g_signal_connect(p_plugin->pwid, "button-press-event", G_CALLBACK(on_xkb_button_press_event), p_xkb);
330 g_signal_connect(p_plugin->pwid, "scroll-event", G_CALLBACK(on_xkb_button_scroll_event), p_xkb);
895da737 331 g_signal_connect(G_OBJECT(fbev), "active_window", G_CALLBACK(on_xkb_fbev_active_window_event), p_xkb);
d862b520 332
333 /* Show the widget and return. */
4496e880
JL
334 xkb_redraw(p_xkb);
335 gtk_widget_show(p_plugin->pwid);
d862b520 336 return 1;
22242ed4
HJYP
337}
338
d862b520 339/* Plugin destructor. */
4496e880 340static void xkb_destructor(Plugin * p_plugin)
22242ed4 341{
4496e880 342 XkbPlugin *p_xkb = (XkbPlugin *)p_plugin->priv;
22242ed4 343
895da737
JL
344 /* Disconnect root window event handler. */
345 g_signal_handlers_disconnect_by_func(G_OBJECT(fbev), on_xkb_fbev_active_window_event, p_xkb);
346
d862b520 347 /* Disconnect from the XKB mechanism. */
4496e880
JL
348 g_source_remove(p_xkb->source_id);
349 xkb_mechanism_destructor(p_xkb);
22242ed4 350
d862b520 351 /* Ensure that the configuration dialog is dismissed. */
4496e880
JL
352 if(p_xkb->p_dialog_config != NULL)
353 gtk_widget_destroy(p_xkb->p_dialog_config);
22242ed4 354
d862b520 355 /* Deallocate all memory. */
4496e880
JL
356 g_free(p_xkb->kbd_model);
357 g_free(p_xkb->kbd_layouts);
358 g_free(p_xkb->kbd_variants);
359 g_free(p_xkb->kbd_change_option);
360 g_free(p_xkb);
361}
362
895da737
JL
363/* Handler for "toggled" event on per-application check box of configuration dialog. */
364static void on_xkb_checkbutton_per_app_toggled(GtkToggleButton *tb, gpointer p_data)
365{
366 if(user_active == TRUE)
367 {
368 /* Fetch the new value and redraw. */
369 XkbPlugin * xkb = (XkbPlugin *)p_data;
370 xkb->enable_perwin = gtk_toggle_button_get_active(tb);
371 if(!xkb->enable_perwin)
372 {
373 /* at deactivation clear the hash table */
374 if(xkb->p_hash_table_group != NULL)
375 g_hash_table_destroy(xkb->p_hash_table_group);
376 xkb->p_hash_table_group = g_hash_table_new(g_direct_hash, NULL);
377 }
378 xkb_redraw(xkb);
379 }
380}
381
4496e880
JL
382static void on_radiobutton_flag_size_1_toggled(GtkToggleButton *p_radiobutton, gpointer p_data)
383{
384 if( (user_active == TRUE) && gtk_toggle_button_get_active(p_radiobutton) )
385 {
386 XkbPlugin * p_xkb = (XkbPlugin *)p_data;
387 p_xkb->flag_size = 1;
388 xkb_redraw(p_xkb);
389 }
390}
391
392static void on_radiobutton_flag_size_2_toggled(GtkToggleButton *p_radiobutton, gpointer p_data)
393{
394 if( (user_active == TRUE) && gtk_toggle_button_get_active(p_radiobutton) )
395 {
396 XkbPlugin * p_xkb = (XkbPlugin *)p_data;
397 p_xkb->flag_size = 2;
398 xkb_redraw(p_xkb);
399 }
22242ed4
HJYP
400}
401
4496e880 402static void on_radiobutton_flag_size_3_toggled(GtkToggleButton *p_radiobutton, gpointer p_data)
22242ed4 403{
4496e880
JL
404 if( (user_active == TRUE) && gtk_toggle_button_get_active(p_radiobutton) )
405 {
406 XkbPlugin * p_xkb = (XkbPlugin *)p_data;
407 p_xkb->flag_size = 3;
408 xkb_redraw(p_xkb);
409 }
22242ed4
HJYP
410}
411
4496e880 412static void on_radiobutton_flag_size_4_toggled(GtkToggleButton *p_radiobutton, gpointer p_data)
22242ed4 413{
4496e880
JL
414 if( (user_active == TRUE) && gtk_toggle_button_get_active(p_radiobutton) )
415 {
416 XkbPlugin * p_xkb = (XkbPlugin *)p_data;
417 p_xkb->flag_size = 4;
418 xkb_redraw(p_xkb);
419 }
22242ed4
HJYP
420}
421
4496e880 422static void on_radiobutton_flag_size_5_toggled(GtkToggleButton *p_radiobutton, gpointer p_data)
22242ed4 423{
4496e880
JL
424 if( (user_active == TRUE) && gtk_toggle_button_get_active(p_radiobutton) )
425 {
426 XkbPlugin * p_xkb = (XkbPlugin *)p_data;
427 p_xkb->flag_size = 5;
428 xkb_redraw(p_xkb);
429 }
430}
431
895da737
JL
432static void on_radiobutton_flag_size_6_toggled(GtkToggleButton *p_radiobutton, gpointer p_data)
433{
434 if( (user_active == TRUE) && gtk_toggle_button_get_active(p_radiobutton) )
435 {
436 XkbPlugin * p_xkb = (XkbPlugin *)p_data;
437 p_xkb->flag_size = 6;
438 xkb_redraw(p_xkb);
439 }
440}
441
4496e880
JL
442/* Handler for "toggled" event on display type image radiobutton of configuration dialog. */
443static void on_radiobutton_disp_type_image_toggled(GtkToggleButton *p_radiobutton, gpointer p_data)
444{
445 if( (user_active == TRUE) && gtk_toggle_button_get_active(p_radiobutton) )
446 {
447 /* Fetch the new value and redraw. */
448 XkbPlugin * p_xkb = (XkbPlugin *)p_data;
449 p_xkb->display_type = DISP_TYPE_IMAGE;
450 xkb_redraw(p_xkb);
451 }
452}
453
454/* Handler for "toggled" event on display type image radiobutton of configuration dialog. */
455static void on_radiobutton_disp_type_image_cust_toggled(GtkToggleButton *p_radiobutton, gpointer p_data)
456{
457 if( (user_active == TRUE) && gtk_toggle_button_get_active(p_radiobutton) )
458 {
459 /* Fetch the new value and redraw. */
460 XkbPlugin * p_xkb = (XkbPlugin *)p_data;
461 p_xkb->display_type = DISP_TYPE_IMAGE_CUST;
462 xkb_redraw(p_xkb);
463 }
464}
465
466/* Handler for "toggled" event on display type image radiobutton of configuration dialog. */
467static void on_radiobutton_disp_type_text_toggled(GtkToggleButton *p_radiobutton, gpointer p_data)
468{
469 if( (user_active == TRUE) && gtk_toggle_button_get_active(p_radiobutton) )
470 {
471 /* Fetch the new value and redraw. */
472 XkbPlugin * p_xkb = (XkbPlugin *)p_data;
473 p_xkb->display_type = DISP_TYPE_TEXT;
474 xkb_redraw(p_xkb);
475 }
22242ed4
HJYP
476}
477
d862b520 478/* Handler for "response" event on configuration dialog. */
4496e880 479static void on_dialog_config_response(GtkDialog *p_dialog, gint response, gpointer data)
22242ed4 480{
4496e880 481 XkbPlugin * p_xkb = (XkbPlugin *)data;
22242ed4 482
d862b520 483 /* Save the new configuration and redraw the plugin. */
4496e880
JL
484 panel_config_save(p_xkb->p_plugin->panel);
485 xkb_redraw(p_xkb);
22242ed4 486
d862b520 487 /* Destroy the dialog. */
4496e880
JL
488 gtk_widget_destroy(p_xkb->p_dialog_config);
489 p_xkb->p_dialog_config = NULL;
490}
491
895da737
JL
492static gboolean on_treeviews_lists_button_press_event(GtkWidget *p_widget,
493 GdkEventButton *p_event,
494 gpointer p_data)
4496e880 495{
895da737
JL
496 if(p_event->button == 1)
497 {
498 if(p_event->type == GDK_2BUTTON_PRESS)
499 {
500 GtkButton *p_button_ok = (GtkButton *)p_data;
501 gtk_button_clicked(p_button_ok);
502 }
503 }
504 return FALSE;
4496e880
JL
505}
506
507static void on_button_kbd_model_clicked(GtkButton *p_button, gpointer *p_data)
508{
509 XkbPlugin *p_xkb = (XkbPlugin *)p_data;
510
511 // dialog
512 GtkWidget *p_dialog = gtk_dialog_new_with_buttons(_("Select Keyboard Model"),
513 GTK_WINDOW(p_xkb->p_dialog_config),
514 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
515 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
516 GTK_STOCK_OK, GTK_RESPONSE_OK,
517 NULL);
518
519 // scrolledwindow
520 GtkWidget * p_scrolledwindow_kbd_model = gtk_scrolled_window_new(NULL, NULL);
521 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(p_scrolledwindow_kbd_model),
522 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
523 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(p_dialog)->vbox), p_scrolledwindow_kbd_model, TRUE, TRUE, 2);
524
525 // liststore
526 GtkListStore *p_liststore_kbd_model = gtk_list_store_new(NUM_MODEL_COLUMNS, G_TYPE_STRING, G_TYPE_STRING);
527 GtkWidget *p_treeview_kbd_model = gtk_tree_view_new_with_model(GTK_TREE_MODEL(p_liststore_kbd_model));
528 g_object_unref(G_OBJECT(p_liststore_kbd_model));
529 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(p_treeview_kbd_model), TRUE);
530 gtk_container_add(GTK_CONTAINER(p_scrolledwindow_kbd_model), p_treeview_kbd_model);
531 GtkCellRenderer *p_renderer;
532 GtkTreeViewColumn *p_column;
533 // model
534 p_renderer = gtk_cell_renderer_text_new();
535 p_column = gtk_tree_view_column_new_with_attributes(_("Model"), p_renderer, "text", COLUMN_CHANGE_NAME, NULL);
e03d81df 536 gtk_tree_view_column_set_sort_column_id(p_column, COLUMN_CHANGE_NAME);
4496e880
JL
537 gtk_tree_view_append_column(GTK_TREE_VIEW(p_treeview_kbd_model), p_column);
538 // desc
539 p_renderer = gtk_cell_renderer_text_new();
540 p_column = gtk_tree_view_column_new_with_attributes(_("Description"), p_renderer, "text", COLUMN_CHANGE_DESC, NULL);
e03d81df 541 gtk_tree_view_column_set_sort_column_id(p_column, COLUMN_CHANGE_DESC);
4496e880
JL
542 gtk_tree_view_append_column(GTK_TREE_VIEW(p_treeview_kbd_model), p_column);
543
544 // populate model
545 GKeyFile *p_keyfile = g_key_file_new();
546 gchar *xkbcfg_filepath = g_strdup_printf("%s/models.cfg", XKBCONFDIR);
547 if(g_key_file_load_from_file(p_keyfile, xkbcfg_filepath, 0, NULL))
548 {
549 gchar **keys_models = g_key_file_get_keys(p_keyfile, "MODELS", NULL, NULL);
550 guint model_idx = 0;
551 GtkTreeIter tree_iter;
552 gchar *p_model_desc;
553 while(keys_models[model_idx] != NULL)
554 {
555 p_model_desc = g_key_file_get_string(p_keyfile, "MODELS", keys_models[model_idx], NULL);
556 gtk_list_store_append(p_liststore_kbd_model, &tree_iter);
557 gtk_list_store_set(p_liststore_kbd_model, &tree_iter,
558 COLUMN_MODEL_NAME, keys_models[model_idx],
559 COLUMN_MODEL_DESC, p_model_desc,
560 -1);
561 g_free(p_model_desc);
562 model_idx++;
563 }
564 g_strfreev(keys_models);
565 g_key_file_free(p_keyfile);
566 }
567 g_free(xkbcfg_filepath);
568
569 // callback for double click
4496e880 570 g_signal_connect(p_treeview_kbd_model, "button-press-event",
895da737
JL
571 G_CALLBACK(on_treeviews_lists_button_press_event),
572 gtk_dialog_get_widget_for_response(GTK_DIALOG(p_dialog), GTK_RESPONSE_OK));
e03d81df
GP
573 // sort for description
574 gtk_tree_view_column_clicked(p_column);
575
576 gtk_widget_set_size_request(p_dialog, 700, 500);
4496e880
JL
577 gtk_widget_show_all(GTK_WIDGET(p_scrolledwindow_kbd_model));
578 gint response = gtk_dialog_run(GTK_DIALOG(p_dialog));
579 if(response == GTK_RESPONSE_OK)
580 {
581 GtkTreeIter tree_iter_sel;
582 GtkTreeSelection *p_treeselection_kbd_model = gtk_tree_view_get_selection(GTK_TREE_VIEW(p_treeview_kbd_model));
583 if(gtk_tree_selection_get_selected(p_treeselection_kbd_model,
584 (GtkTreeModel **)(&p_liststore_kbd_model),
585 &tree_iter_sel))
586 {
587 gchar *kbd_model_new;
588 gtk_tree_model_get(GTK_TREE_MODEL(p_liststore_kbd_model),
589 &tree_iter_sel, COLUMN_MODEL_NAME, &kbd_model_new, -1);
590 g_free(p_xkb->kbd_model);
591 p_xkb->kbd_model = g_strdup(kbd_model_new);
592 gtk_button_set_label(GTK_BUTTON(p_xkb->p_button_kbd_model), p_xkb->kbd_model);
593 g_free(kbd_model_new);
594 xkb_setxkbmap(p_xkb);
595 xkb_redraw(p_xkb);
596 }
597 }
598 gtk_widget_destroy(p_dialog);
599}
600
601static void on_button_kbd_change_layout_clicked(GtkButton *p_button, gpointer *p_data)
602{
603 XkbPlugin *p_xkb = (XkbPlugin *)p_data;
604
605 // dialog
606 GtkWidget *p_dialog = gtk_dialog_new_with_buttons(_("Select Layout Change Type"),
607 GTK_WINDOW(p_xkb->p_dialog_config),
608 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
609 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
610 GTK_STOCK_OK, GTK_RESPONSE_OK,
611 NULL);
612
613 // scrolledwindow
614 GtkWidget * p_scrolledwindow_kbd_change = gtk_scrolled_window_new(NULL, NULL);
615 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(p_scrolledwindow_kbd_change),
616 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
617 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(p_dialog)->vbox), p_scrolledwindow_kbd_change, TRUE, TRUE, 2);
618
619 // liststore
620 GtkListStore *p_liststore_kbd_change = gtk_list_store_new(NUM_CHANGE_COLUMNS, G_TYPE_STRING, G_TYPE_STRING);
621 GtkWidget *p_treeview_kbd_change = gtk_tree_view_new_with_model(GTK_TREE_MODEL(p_liststore_kbd_change));
622 g_object_unref(G_OBJECT(p_liststore_kbd_change));
623 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(p_treeview_kbd_change), TRUE);
624 gtk_container_add(GTK_CONTAINER(p_scrolledwindow_kbd_change), p_treeview_kbd_change);
625 GtkCellRenderer *p_renderer;
626 GtkTreeViewColumn *p_column;
627 // model
628 p_renderer = gtk_cell_renderer_text_new();
629 p_column = gtk_tree_view_column_new_with_attributes(_("Change Type"), p_renderer, "text", COLUMN_CHANGE_NAME, NULL);
630 gtk_tree_view_append_column(GTK_TREE_VIEW(p_treeview_kbd_change), p_column);
631 // desc
632 p_renderer = gtk_cell_renderer_text_new();
633 p_column = gtk_tree_view_column_new_with_attributes(_("Description"), p_renderer, "text", COLUMN_CHANGE_DESC, NULL);
634 gtk_tree_view_append_column(GTK_TREE_VIEW(p_treeview_kbd_change), p_column);
635
636 // populate model
637 GKeyFile *p_keyfile = g_key_file_new();
638 gchar *xkbcfg_filepath = g_strdup_printf("%s/toggle.cfg", XKBCONFDIR);
639 if(g_key_file_load_from_file(p_keyfile, xkbcfg_filepath, 0, NULL))
640 {
641 gchar **keys_changes = g_key_file_get_keys(p_keyfile, "TOGGLE", NULL, NULL);
642 guint change_idx = 0;
643 GtkTreeIter tree_iter;
644 gchar *p_change_desc;
645 while(keys_changes[change_idx] != NULL)
646 {
647 p_change_desc = g_key_file_get_string(p_keyfile, "TOGGLE", keys_changes[change_idx], NULL);
648 gtk_list_store_append(p_liststore_kbd_change, &tree_iter);
649 gtk_list_store_set(p_liststore_kbd_change, &tree_iter,
650 COLUMN_CHANGE_NAME, keys_changes[change_idx],
651 COLUMN_CHANGE_DESC, p_change_desc,
652 -1);
653 g_free(p_change_desc);
654 change_idx++;
655 }
656 g_strfreev(keys_changes);
657 g_key_file_free(p_keyfile);
658 }
659 g_free(xkbcfg_filepath);
660
661 // callback for double click
4496e880 662 g_signal_connect(p_treeview_kbd_change, "button-press-event",
895da737
JL
663 G_CALLBACK(on_treeviews_lists_button_press_event),
664 gtk_dialog_get_widget_for_response(GTK_DIALOG(p_dialog), GTK_RESPONSE_OK));
e03d81df 665 gtk_widget_set_size_request(p_dialog, 700, 500);
4496e880
JL
666 gtk_widget_show_all(GTK_WIDGET(p_scrolledwindow_kbd_change));
667 gint response = gtk_dialog_run(GTK_DIALOG(p_dialog));
668 if(response == GTK_RESPONSE_OK)
669 {
670 GtkTreeIter tree_iter_sel;
671 GtkTreeSelection *p_treeselection_kbd_change = gtk_tree_view_get_selection(GTK_TREE_VIEW(p_treeview_kbd_change));
672 if(gtk_tree_selection_get_selected(p_treeselection_kbd_change,
673 (GtkTreeModel **)(&p_liststore_kbd_change),
674 &tree_iter_sel))
675 {
676 gchar *kbd_change_new;
677 gtk_tree_model_get(GTK_TREE_MODEL(p_liststore_kbd_change),
678 &tree_iter_sel, COLUMN_CHANGE_NAME, &kbd_change_new, -1);
679 g_free(p_xkb->kbd_change_option);
680 p_xkb->kbd_change_option = g_strdup(kbd_change_new);
681 gtk_button_set_label(GTK_BUTTON(p_xkb->p_button_change_layout), p_xkb->kbd_change_option);
682 g_free(kbd_change_new);
683 xkb_setxkbmap(p_xkb);
684 xkb_redraw(p_xkb);
685 }
686 }
687 gtk_widget_destroy(p_dialog);
688}
689
690static void on_button_up_layout_clicked(GtkButton *p_button, gpointer *p_data)
691{
692 XkbPlugin *p_xkb = (XkbPlugin *)p_data;
693 GtkTreeIter tree_iter_sel;
694 GtkTreeIter tree_iter_prev;
695 if(gtk_tree_selection_get_selected(p_xkb->p_treeselection_layout,
696 (GtkTreeModel **)(&p_xkb->p_liststore_layout),
697 &tree_iter_sel))
698 {
699 GtkTreePath *p_tree_path = gtk_tree_model_get_path(GTK_TREE_MODEL(p_xkb->p_liststore_layout),
700 &tree_iter_sel);
701 if( (gtk_tree_path_prev(p_tree_path)) &&
702 (gtk_tree_model_get_iter(GTK_TREE_MODEL(p_xkb->p_liststore_layout),
703 &tree_iter_prev,
704 p_tree_path)))
705 {
706 gtk_list_store_swap(p_xkb->p_liststore_layout, &tree_iter_sel, &tree_iter_prev);
707 xkb_update_layouts_n_variants(p_xkb);
708 }
709 gtk_tree_path_free(p_tree_path);
710 }
711}
712
713static void on_button_down_layout_clicked(GtkButton *p_button, gpointer *p_data)
714{
715 XkbPlugin *p_xkb = (XkbPlugin *)p_data;
716 GtkTreeIter tree_iter_sel;
717 GtkTreeIter tree_iter_next;
718 if(gtk_tree_selection_get_selected(p_xkb->p_treeselection_layout,
719 (GtkTreeModel **)(&p_xkb->p_liststore_layout),
720 &tree_iter_sel))
721 {
722 tree_iter_next = tree_iter_sel;
723 if(gtk_tree_model_iter_next(GTK_TREE_MODEL(p_xkb->p_liststore_layout),
724 &tree_iter_next))
725 {
726 gtk_list_store_swap(p_xkb->p_liststore_layout, &tree_iter_sel, &tree_iter_next);
727 xkb_update_layouts_n_variants(p_xkb);
728 }
729 }
730}
731
732static void on_button_rm_layout_clicked(GtkButton *p_button, gpointer *p_data)
733{
734 XkbPlugin *p_xkb = (XkbPlugin *)p_data;
735 GtkTreeIter tree_iter_sel;
736 if(gtk_tree_selection_get_selected(p_xkb->p_treeselection_layout,
737 (GtkTreeModel **)(&p_xkb->p_liststore_layout),
738 &tree_iter_sel))
739 {
740 gtk_list_store_remove(p_xkb->p_liststore_layout, &tree_iter_sel);
741 xkb_update_layouts_n_variants(p_xkb);
742 gtk_widget_set_sensitive(p_xkb->p_button_rm_layout, p_xkb->num_layouts > 1);
743 }
744}
745
746static void on_button_add_layout_clicked(GtkButton *p_button, gpointer *p_data)
747{
748 XkbPlugin *p_xkb = (XkbPlugin *)p_data;
749
750 // dialog
751 GtkWidget *p_dialog = gtk_dialog_new_with_buttons(_("Add Keyboard Layout"),
752 GTK_WINDOW(p_xkb->p_dialog_config),
753 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
754 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
755 GTK_STOCK_OK, GTK_RESPONSE_OK,
756 NULL);
757
758 // scrolledwindow
759 GtkWidget * p_scrolledwindow_add_layout = gtk_scrolled_window_new(NULL, NULL);
760 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(p_scrolledwindow_add_layout),
761 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
762 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(p_dialog)->vbox), p_scrolledwindow_add_layout, TRUE, TRUE, 2);
763
764 // treestore
765 GtkTreeStore *p_treestore_add_layout = gtk_tree_store_new(NUM_ADD_COLUMNS, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING);
766 GtkWidget *p_treeview_add_layout = gtk_tree_view_new_with_model(GTK_TREE_MODEL(p_treestore_add_layout));
767 g_object_unref(G_OBJECT(p_treestore_add_layout));
768 gtk_tree_view_set_enable_tree_lines(GTK_TREE_VIEW(p_treeview_add_layout), TRUE);
769 gtk_container_add(GTK_CONTAINER(p_scrolledwindow_add_layout), p_treeview_add_layout);
770 GtkCellRenderer *p_renderer;
895da737 771 GtkTreeViewColumn *p_column, *p_column_desc;
4496e880
JL
772 // icon
773 p_renderer = gtk_cell_renderer_pixbuf_new();
895da737
JL
774 p_column = gtk_tree_view_column_new_with_attributes(_("Flag"), p_renderer, "pixbuf", COLUMN_ADD_ICON, NULL);
775 gtk_tree_view_column_set_sort_column_id(p_column, COLUMN_ADD_DESC);
4496e880
JL
776 gtk_tree_view_append_column(GTK_TREE_VIEW(p_treeview_add_layout), p_column);
777 // layout
778 p_renderer = gtk_cell_renderer_text_new();
895da737
JL
779 p_column = gtk_tree_view_column_new_with_attributes(_("Layout"), p_renderer, "text", COLUMN_ADD_LAYOUT, NULL);
780 gtk_tree_view_column_set_sort_column_id(p_column, COLUMN_ADD_LAYOUT);
4496e880
JL
781 gtk_tree_view_append_column(GTK_TREE_VIEW(p_treeview_add_layout), p_column);
782 // desc
783 p_renderer = gtk_cell_renderer_text_new();
895da737
JL
784 p_column_desc = gtk_tree_view_column_new_with_attributes(_("Description"), p_renderer, "text", COLUMN_ADD_DESC, NULL);
785 gtk_tree_view_column_set_sort_column_id(p_column_desc, COLUMN_ADD_DESC);
786 gtk_tree_view_append_column(GTK_TREE_VIEW(p_treeview_add_layout), p_column_desc);
787 // search column
788 gtk_tree_view_set_search_column(GTK_TREE_VIEW(p_treeview_add_layout), COLUMN_ADD_DESC);
4496e880
JL
789
790 // populate model
791 GKeyFile *p_keyfile = g_key_file_new();
792 gchar *xkbcfg_filepath = g_strdup_printf("%s/layouts.cfg", XKBCONFDIR);
793 if(g_key_file_load_from_file(p_keyfile, xkbcfg_filepath, 0, NULL))
794 {
795 gchar **keys_layouts = g_key_file_get_keys(p_keyfile, "LAYOUTS", NULL, NULL);
796 guint layout_idx = 0;
797 GtkTreeIter tree_top, tree_child;
798 gchar *p_layout_desc;
799 while(keys_layouts[layout_idx] != NULL)
800 {
801 p_layout_desc = g_key_file_get_string(p_keyfile, "LAYOUTS", keys_layouts[layout_idx], NULL);
802 if(strchr(keys_layouts[layout_idx], '(') == NULL)
803 {
804 gchar *flag_filepath = NULL;
805 gchar *flags_dir = (p_xkb->cust_dir_exists && (p_xkb->display_type == DISP_TYPE_IMAGE_CUST)) ? g_strdup(FLAGSCUSTDIR):g_strdup(FLAGSDIR);
806 if(strchr(keys_layouts[layout_idx], '/') != NULL)
807 {
808 gchar *layout_mod = g_strdup(keys_layouts[layout_idx]);
809 layout_mod = g_strdelimit(layout_mod, "/", '-');
810 flag_filepath = g_strdup_printf(flag_filepath_generator, flags_dir, layout_mod);
811 g_free(layout_mod);
812 }
813 else
814 {
815 flag_filepath = g_strdup_printf(flag_filepath_generator, flags_dir, keys_layouts[layout_idx]);
816 }
817 GdkPixbuf *p_pixbuf = gdk_pixbuf_new_from_file_at_size(flag_filepath, -1, 16, NULL);
818 gtk_tree_store_append(p_treestore_add_layout, &tree_top, NULL);
819 if(p_pixbuf != NULL)
820 {
821 gtk_tree_store_set(p_treestore_add_layout, &tree_top,
822 COLUMN_ADD_ICON, p_pixbuf,
823 COLUMN_ADD_LAYOUT, keys_layouts[layout_idx],
824 COLUMN_ADD_DESC, p_layout_desc,
825 -1);
826 g_object_unref(G_OBJECT(p_pixbuf));
827 }
828 else
829 {
830 gtk_tree_store_set(p_treestore_add_layout, &tree_top,
831 COLUMN_ADD_LAYOUT, keys_layouts[layout_idx],
832 COLUMN_ADD_DESC, p_layout_desc,
833 -1);
834 }
835 g_free(flag_filepath);
836 g_free(flags_dir);
837 }
838 else
839 {
840
841 gtk_tree_store_append(p_treestore_add_layout, &tree_child, &tree_top);
842 gtk_tree_store_set(p_treestore_add_layout, &tree_child,
843 COLUMN_ADD_LAYOUT, keys_layouts[layout_idx],
844 COLUMN_ADD_DESC, p_layout_desc,
845 -1);
846 }
847 g_free(p_layout_desc);
848 layout_idx++;
849 }
850 g_strfreev(keys_layouts);
851 g_key_file_free(p_keyfile);
852 }
853 g_free(xkbcfg_filepath);
854
855 // callback for double click
4496e880 856 g_signal_connect(p_treeview_add_layout, "button-press-event",
895da737
JL
857 G_CALLBACK(on_treeviews_lists_button_press_event),
858 gtk_dialog_get_widget_for_response(GTK_DIALOG(p_dialog), GTK_RESPONSE_OK));
859 // sort for description
860 gtk_tree_view_column_clicked(p_column_desc);
861
e03d81df 862 gtk_widget_set_size_request(p_dialog, 700, 500);
4496e880
JL
863 gtk_widget_show_all(GTK_WIDGET(p_scrolledwindow_add_layout));
864 gint response = gtk_dialog_run(GTK_DIALOG(p_dialog));
865 if(response == GTK_RESPONSE_OK)
866 {
867 GtkTreeIter tree_iter_sel;
868 GtkTreeSelection *p_treeselection_add_layout = gtk_tree_view_get_selection(GTK_TREE_VIEW(p_treeview_add_layout));
869 if(gtk_tree_selection_get_selected(p_treeselection_add_layout,
870 (GtkTreeModel **)(&p_treestore_add_layout),
871 &tree_iter_sel))
872 {
873 gchar *layout_add;
874 GString *p_gstring_new_layout = g_string_new("");
875 GString *p_gstring_new_variant = g_string_new("");
876 gtk_tree_model_get(GTK_TREE_MODEL(p_treestore_add_layout),
877 &tree_iter_sel, COLUMN_ADD_LAYOUT, &layout_add, -1);
878
879 if(strchr(layout_add, '(') == NULL)
880 {
881 g_string_append(p_gstring_new_layout, layout_add);
882 }
883 else
884 {
885 gboolean parsing_variant = FALSE;
886 guchar i;
887 for(i=0; layout_add[i]; i++)
888 {
889 if(!parsing_variant)
890 {
891 if(layout_add[i] == '(')
892 parsing_variant = TRUE;
893 else
894 g_string_append_c(p_gstring_new_layout, layout_add[i]);
895 }
896 else
897 {
898 if(layout_add[i] == ')')
899 break;
900 else
901 g_string_append_c(p_gstring_new_variant, layout_add[i]);
902 }
903 }
904 }
905 xkb_add_layout(p_xkb, p_gstring_new_layout->str, p_gstring_new_variant->str);
906 xkb_update_layouts_n_variants(p_xkb);
907
908 gtk_widget_set_sensitive(p_xkb->p_button_rm_layout, p_xkb->num_layouts > 1);
909
910 g_free(layout_add);
911 g_string_free(p_gstring_new_layout, TRUE/*free also gstring->str*/);
912 g_string_free(p_gstring_new_variant, TRUE/*free also gstring->str*/);
913 }
914 }
915 gtk_widget_destroy(p_dialog);
916}
917
047cf801 918void xkb_setxkbmap(XkbPlugin *p_xkb)
4496e880
JL
919{
920 GString *p_gstring_syscmd = g_string_new("");
921 g_string_printf(p_gstring_syscmd,
922 "setxkbmap -model %s -layout %s -variant %s -option grp:%s",
923 p_xkb->kbd_model, p_xkb->kbd_layouts, p_xkb->kbd_variants, p_xkb->kbd_change_option);
895da737
JL
924 if(system("setxkbmap -option")) // reset options
925 {
926 ERR("xkb: system(setxkbmap -option)\n");
927 }
928 if(system(p_gstring_syscmd->str)) // set new map
929 {
930 ERR("xkb: system(%s)\n", p_gstring_syscmd->str);
931 }
4496e880
JL
932 //g_printf("\n%s\n", p_gstring_syscmd->str);
933 g_string_free(p_gstring_syscmd, TRUE/*free also gstring->str*/);
934}
935
936static gboolean layouts_tree_model_foreach(GtkTreeModel *p_model,
937 GtkTreePath *p_path,
938 GtkTreeIter *p_iter,
939 gpointer p_data)
940{
941 XkbPlugin *p_xkb = (XkbPlugin *)p_data;
942 gchar *layout_val;
943 gchar *variant_val;
944
945 gtk_tree_model_get(p_model, p_iter, COLUMN_LAYOUT, &layout_val, -1);
946 gtk_tree_model_get(p_model, p_iter, COLUMN_VARIANT, &variant_val, -1);
947
948 if(strlen(p_xkb->p_gstring_layouts_partial->str))
949 {
950 g_string_append_c(p_xkb->p_gstring_layouts_partial, ',');
951 g_string_append_c(p_xkb->p_gstring_variants_partial, ',');
952 }
953 g_string_append(p_xkb->p_gstring_layouts_partial, layout_val);
954 g_string_append(p_xkb->p_gstring_variants_partial, variant_val);
955
895da737
JL
956 //g_printf("\npartial layouts = '%s'\n", p_xkb->p_gstring_layouts_partial->str);
957 //g_printf("partial variants = '%s'\n", p_xkb->p_gstring_variants_partial->str);
4496e880
JL
958
959 g_free(layout_val);
960 g_free(variant_val);
961 p_xkb->num_layouts++;
962 return FALSE;
963}
964
965static void xkb_update_layouts_n_variants(XkbPlugin *p_xkb)
966{
967 p_xkb->p_gstring_layouts_partial = g_string_new("");
968 p_xkb->p_gstring_variants_partial = g_string_new("");
969 p_xkb->num_layouts = 0;
970 gtk_tree_model_foreach(GTK_TREE_MODEL(p_xkb->p_liststore_layout),
971 layouts_tree_model_foreach,
972 p_xkb);
973 if(!strlen(p_xkb->p_gstring_variants_partial->str))
974 {
975 g_string_append_c(p_xkb->p_gstring_variants_partial, ',');
976 }
977 g_free(p_xkb->kbd_layouts);
978 g_free(p_xkb->kbd_variants);
979 p_xkb->kbd_layouts = g_strdup(p_xkb->p_gstring_layouts_partial->str);
980 p_xkb->kbd_variants = g_strdup(p_xkb->p_gstring_variants_partial->str);
981 g_string_free(p_xkb->p_gstring_layouts_partial, TRUE/*free also gstring->str*/);
982 g_string_free(p_xkb->p_gstring_variants_partial, TRUE/*free also gstring->str*/);
983 xkb_setxkbmap(p_xkb);
984 xkb_mechanism_destructor(p_xkb);
985 xkb_mechanism_constructor(p_xkb);
986 xkb_redraw(p_xkb);
987}
988
989static void xkb_add_layout(XkbPlugin *p_xkb, gchar *layout, gchar*variant)
990{
991 GtkTreeIter tree_iter;
992 gtk_list_store_append(p_xkb->p_liststore_layout, &tree_iter);
993 gchar *flag_filepath = NULL;
994 gchar *flags_dir = (p_xkb->cust_dir_exists && (p_xkb->display_type == DISP_TYPE_IMAGE_CUST)) ? g_strdup(FLAGSCUSTDIR):g_strdup(FLAGSDIR);
995 if(strchr(layout, '/') != NULL)
996 {
997 gchar *layout_mod = g_strdup(layout);
998 layout_mod = g_strdelimit(layout_mod, "/", '-');
999 flag_filepath = g_strdup_printf(flag_filepath_generator, flags_dir, layout_mod);
1000 g_free(layout_mod);
1001 }
1002 else
1003 {
1004 flag_filepath = g_strdup_printf(flag_filepath_generator, flags_dir, layout);
1005 }
1006 GdkPixbuf *p_pixbuf = gdk_pixbuf_new_from_file_at_size(flag_filepath, -1, 20, NULL);
1007 if(p_pixbuf != NULL)
1008 {
1009 gtk_list_store_set(p_xkb->p_liststore_layout, &tree_iter,
1010 COLUMN_ICON, p_pixbuf,
1011 COLUMN_LAYOUT, layout,
1012 COLUMN_VARIANT, variant,
1013 -1);
1014 g_object_unref(G_OBJECT(p_pixbuf));
1015 }
1016 else
1017 {
1018 gtk_list_store_set(p_xkb->p_liststore_layout, &tree_iter,
1019 COLUMN_LAYOUT, layout,
1020 COLUMN_VARIANT, variant,
1021 -1);
1022 }
1023 g_free(flag_filepath);
1024 g_free(flags_dir);
1025}
1026
1027static void xkb_settings_fill_layout_tree_model_with_config(XkbPlugin *p_xkb)
1028{
1029 p_xkb->num_layouts = 0;
1030 if(strlen(p_xkb->kbd_layouts) && strlen(p_xkb->kbd_variants))
1031 {
1032 char **layouts = g_strsplit_set(p_xkb->kbd_layouts, ",", 0);
1033 char **variants = g_strsplit_set(p_xkb->kbd_variants, ",", 0);
1034
1035 while(layouts[p_xkb->num_layouts] != NULL)
1036 {
1037 xkb_add_layout(p_xkb, layouts[p_xkb->num_layouts], variants[p_xkb->num_layouts]);
1038 p_xkb->num_layouts++;
1039 }
1040 gtk_widget_set_sensitive(p_xkb->p_button_rm_layout, p_xkb->num_layouts > 1);
1041
1042 g_strfreev(layouts);
1043 g_strfreev(variants);
1044 }
22242ed4
HJYP
1045}
1046
d862b520 1047/* Callback when the configuration dialog is to be shown. */
1048static void xkb_configure(Plugin * p, GtkWindow * parent)
22242ed4 1049{
4496e880
JL
1050 XkbPlugin * p_xkb = (XkbPlugin *)p->priv;
1051 gchar markup_str[MAX_MARKUP_LEN];
1052
1053 user_active = FALSE;
d862b520 1054
4496e880 1055 // configuration dialog
d862b520 1056 GtkWidget * dlg = gtk_dialog_new_with_buttons(
4496e880 1057 _("Keyboard Layout Handler"),
d862b520 1058 NULL,
1059 GTK_DIALOG_NO_SEPARATOR,
4496e880 1060 GTK_STOCK_CLOSE,
d862b520 1061 GTK_RESPONSE_OK,
1062 NULL);
4496e880 1063 p_xkb->p_dialog_config = dlg;
d862b520 1064 panel_apply_icon(GTK_WINDOW(dlg));
1065
4496e880
JL
1066 // main vbox of the config dialog
1067 GtkWidget * p_vbox_main = gtk_vbox_new(FALSE, 0);
1068 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dlg)->vbox), p_vbox_main);
1069
1070
1071 // 'KEYBOARD MODEL' frame
1072 GtkWidget * p_frame_kbd_model = gtk_frame_new(NULL);
1073 GtkWidget * p_label_kbd_model = gtk_label_new(NULL);
1074 snprintf(markup_str, MAX_MARKUP_LEN, "<b>%s</b>", _("Keyboard Model"));
1075 gtk_label_set_markup(GTK_LABEL(p_label_kbd_model), markup_str);
1076 gtk_misc_set_padding(GTK_MISC(p_label_kbd_model), 1, 0);
1077 gtk_frame_set_label_widget(GTK_FRAME(p_frame_kbd_model), p_label_kbd_model);
1078 gtk_frame_set_shadow_type(GTK_FRAME(p_frame_kbd_model), GTK_SHADOW_NONE);
1079 gtk_box_pack_start(GTK_BOX(p_vbox_main), p_frame_kbd_model, TRUE, TRUE, 2);
1080 gtk_container_set_border_width(GTK_CONTAINER(p_frame_kbd_model), 3);
1081
1082 // frame alignment
1083 GtkWidget * p_alignment_kbd_model = gtk_alignment_new(0.5, 0.5, 1, 1);
1084 gtk_container_add(GTK_CONTAINER(p_frame_kbd_model), p_alignment_kbd_model);
1085 gtk_alignment_set_padding(GTK_ALIGNMENT(p_alignment_kbd_model), 4, 4, 10, 10);
1086 p_xkb->p_button_kbd_model = gtk_button_new_with_label(p_xkb->kbd_model);
1087 g_signal_connect(p_xkb->p_button_kbd_model, "clicked", G_CALLBACK(on_button_kbd_model_clicked), p_xkb);
1088 gtk_container_add(GTK_CONTAINER(p_alignment_kbd_model), p_xkb->p_button_kbd_model);
1089
1090
1091 // 'KEYBOARD LAYOUTS' frame
1092 GtkWidget * p_frame_kbd_layouts = gtk_frame_new(NULL);
1093 GtkWidget * p_label_kbd_layouts = gtk_label_new(NULL);
1094 snprintf(markup_str, MAX_MARKUP_LEN, "<b>%s</b>", _("Keyboard Layouts"));
1095 gtk_label_set_markup(GTK_LABEL(p_label_kbd_layouts), markup_str);
1096 gtk_misc_set_padding(GTK_MISC(p_label_kbd_layouts), 1, 0);
1097 gtk_frame_set_label_widget(GTK_FRAME(p_frame_kbd_layouts), p_label_kbd_layouts);
1098 gtk_frame_set_shadow_type(GTK_FRAME(p_frame_kbd_layouts), GTK_SHADOW_NONE);
1099 gtk_box_pack_start(GTK_BOX(p_vbox_main), p_frame_kbd_layouts, TRUE, TRUE, 2);
1100 gtk_container_set_border_width(GTK_CONTAINER(p_frame_kbd_layouts), 3);
1101 gtk_widget_set_size_request(GTK_WIDGET(p_frame_kbd_layouts), -1, 180);
1102
1103 // frame alignment
1104 GtkWidget * p_alignment_kbd_layouts = gtk_alignment_new(0.5, 0.5, 1, 1);
1105 gtk_container_add(GTK_CONTAINER(p_frame_kbd_layouts), p_alignment_kbd_layouts);
1106 gtk_alignment_set_padding(GTK_ALIGNMENT(p_alignment_kbd_layouts), 4, 4, 10, 10);
1107 GtkWidget * p_hbox_kbd_layouts = gtk_hbox_new(FALSE, 0);
1108 gtk_container_add(GTK_CONTAINER(p_alignment_kbd_layouts), p_hbox_kbd_layouts);
1109
1110 // scrolledwindow and buttons
1111 GtkWidget * p_scrolledwindow_kbd_layouts = gtk_scrolled_window_new(NULL, NULL);
1112 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(p_scrolledwindow_kbd_layouts),
1113 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1114 gtk_box_pack_start(GTK_BOX(p_hbox_kbd_layouts), p_scrolledwindow_kbd_layouts, TRUE, TRUE, 2);
1115 GtkWidget * p_vbox_kbd_layouts = gtk_vbox_new(FALSE, 2);
1116 gtk_box_pack_start(GTK_BOX(p_hbox_kbd_layouts), p_vbox_kbd_layouts, FALSE, TRUE, 4);
1117 GtkWidget * p_button_add_layout = gtk_button_new_from_stock(GTK_STOCK_ADD);
1118 GtkWidget * p_button_up_layout = gtk_button_new_from_stock(GTK_STOCK_GO_UP);
1119 GtkWidget * p_button_down_layout = gtk_button_new_from_stock(GTK_STOCK_GO_DOWN);
1120 p_xkb->p_button_rm_layout = gtk_button_new_from_stock(GTK_STOCK_REMOVE);
1121 g_signal_connect(p_button_add_layout, "clicked", G_CALLBACK(on_button_add_layout_clicked), p_xkb);
1122 g_signal_connect(p_xkb->p_button_rm_layout, "clicked", G_CALLBACK(on_button_rm_layout_clicked), p_xkb);
1123 g_signal_connect(p_button_up_layout, "clicked", G_CALLBACK(on_button_up_layout_clicked), p_xkb);
1124 g_signal_connect(p_button_down_layout, "clicked", G_CALLBACK(on_button_down_layout_clicked), p_xkb);
1125 gtk_box_pack_start(GTK_BOX(p_vbox_kbd_layouts), p_button_add_layout, FALSE, TRUE, 0);
1126 gtk_box_pack_start(GTK_BOX(p_vbox_kbd_layouts), p_xkb->p_button_rm_layout, FALSE, TRUE, 0);
1127 gtk_box_pack_start(GTK_BOX(p_vbox_kbd_layouts), p_button_up_layout, FALSE, TRUE, 0);
1128 gtk_box_pack_start(GTK_BOX(p_vbox_kbd_layouts), p_button_down_layout, FALSE, TRUE, 0);
1129
1130 // liststore
1131 p_xkb->p_liststore_layout = gtk_list_store_new(NUM_COLUMNS, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING);
1132 p_xkb->p_treeview_layout = gtk_tree_view_new_with_model(GTK_TREE_MODEL(p_xkb->p_liststore_layout));
1133 g_object_unref(G_OBJECT(p_xkb->p_liststore_layout));
1134 p_xkb->p_treeselection_layout = gtk_tree_view_get_selection(GTK_TREE_VIEW(p_xkb->p_treeview_layout));
1135 gtk_container_add(GTK_CONTAINER(p_scrolledwindow_kbd_layouts), p_xkb->p_treeview_layout);
1136 GtkCellRenderer *p_renderer;
1137 GtkTreeViewColumn *p_column;
1138 // icon
1139 p_renderer = gtk_cell_renderer_pixbuf_new();
1140 p_column = gtk_tree_view_column_new_with_attributes(_("Flag"), p_renderer, "pixbuf", COLUMN_ICON, NULL);
1141 gtk_tree_view_append_column(GTK_TREE_VIEW(p_xkb->p_treeview_layout), p_column);
1142 // layout
1143 p_renderer = gtk_cell_renderer_text_new();
1144 p_column = gtk_tree_view_column_new_with_attributes(_("Layout"), p_renderer, "text", COLUMN_LAYOUT, NULL);
1145 gtk_tree_view_append_column(GTK_TREE_VIEW(p_xkb->p_treeview_layout), p_column);
1146 // variant
1147 p_renderer = gtk_cell_renderer_text_new();
1148 p_column = gtk_tree_view_column_new_with_attributes(_("Variant"), p_renderer, "text", COLUMN_VARIANT, NULL);
1149 gtk_tree_view_append_column(GTK_TREE_VIEW(p_xkb->p_treeview_layout), p_column);
1150 xkb_settings_fill_layout_tree_model_with_config(p_xkb);
1151
1152
1153 // 'CHANGE LAYOUT OPTION' frame
1154 GtkWidget * p_frame_change_layout = gtk_frame_new(NULL);
1155 GtkWidget * p_label_change_layout = gtk_label_new(NULL);
1156 snprintf(markup_str, MAX_MARKUP_LEN, "<b>%s</b>", _("Change Layout Option"));
1157 gtk_label_set_markup(GTK_LABEL(p_label_change_layout), markup_str);
1158 gtk_misc_set_padding(GTK_MISC(p_label_change_layout), 1, 0);
1159 gtk_frame_set_label_widget(GTK_FRAME(p_frame_change_layout), p_label_change_layout);
1160 gtk_frame_set_shadow_type(GTK_FRAME(p_frame_change_layout), GTK_SHADOW_NONE);
1161 gtk_box_pack_start(GTK_BOX(p_vbox_main), p_frame_change_layout, TRUE, TRUE, 2);
1162 gtk_container_set_border_width(GTK_CONTAINER(p_frame_change_layout), 3);
1163
1164 // frame alignment
1165 GtkWidget * p_alignment_change_layout = gtk_alignment_new(0.5, 0.5, 1, 1);
1166 gtk_container_add(GTK_CONTAINER(p_frame_change_layout), p_alignment_change_layout);
1167 gtk_alignment_set_padding(GTK_ALIGNMENT(p_alignment_change_layout), 4, 4, 10, 10);
1168 p_xkb->p_button_change_layout = gtk_button_new_with_label(p_xkb->kbd_change_option);
1169 g_signal_connect(p_xkb->p_button_change_layout, "clicked", G_CALLBACK(on_button_kbd_change_layout_clicked), p_xkb);
1170 gtk_container_add(GTK_CONTAINER(p_alignment_change_layout), p_xkb->p_button_change_layout);
1171
1172
895da737
JL
1173 // 'PER WINDOW SETTINGS' frame
1174 GtkWidget * p_frame_perapp_layout = gtk_frame_new(NULL);
1175 GtkWidget * p_label_perapp_layout = gtk_label_new(NULL);
1176 snprintf(markup_str, MAX_MARKUP_LEN, "<b>%s</b>", _("Per Window Settings"));
1177 gtk_label_set_markup(GTK_LABEL(p_label_perapp_layout), markup_str);
1178 gtk_misc_set_padding(GTK_MISC(p_label_perapp_layout), 1, 0);
1179 gtk_frame_set_label_widget(GTK_FRAME(p_frame_perapp_layout), p_label_perapp_layout);
1180 gtk_frame_set_shadow_type(GTK_FRAME(p_frame_perapp_layout), GTK_SHADOW_NONE);
1181 gtk_box_pack_start(GTK_BOX(p_vbox_main), p_frame_perapp_layout, TRUE, TRUE, 2);
1182 gtk_container_set_border_width(GTK_CONTAINER(p_frame_perapp_layout), 3);
1183
1184 // frame alignment
1185 GtkWidget * p_alignment_perapp_layout = gtk_alignment_new(0.5, 0.5, 1, 1);
1186 gtk_container_add(GTK_CONTAINER(p_frame_perapp_layout), p_alignment_perapp_layout);
1187 gtk_alignment_set_padding(GTK_ALIGNMENT(p_alignment_perapp_layout), 4, 4, 10, 10);
1188 GtkWidget *p_checkbutton_per_app = gtk_check_button_new_with_mnemonic(_("_Remember layout for each window"));
1189 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(p_checkbutton_per_app), p_xkb->enable_perwin);
1190 g_signal_connect(p_checkbutton_per_app, "toggled", G_CALLBACK(on_xkb_checkbutton_per_app_toggled), p_xkb);
1191 gtk_container_add(GTK_CONTAINER(p_alignment_perapp_layout), p_checkbutton_per_app);
1192
1193
4496e880
JL
1194 // 'SHOW LAYOUT AS' frame
1195 GtkWidget * p_frame_display_type = gtk_frame_new(NULL);
1196 GtkWidget * p_label_show_layout_as = gtk_label_new(NULL);
1197 snprintf(markup_str, MAX_MARKUP_LEN, "<b>%s</b>", _("Show Layout as"));
1198 gtk_label_set_markup(GTK_LABEL(p_label_show_layout_as), markup_str);
1199 gtk_misc_set_padding(GTK_MISC(p_label_show_layout_as), 1, 0);
1200 gtk_frame_set_label_widget(GTK_FRAME(p_frame_display_type), p_label_show_layout_as);
1201 gtk_frame_set_shadow_type(GTK_FRAME(p_frame_display_type), GTK_SHADOW_NONE);
1202 gtk_box_pack_start(GTK_BOX(p_vbox_main), p_frame_display_type, TRUE, TRUE, 2);
1203 gtk_container_set_border_width(GTK_CONTAINER(p_frame_display_type), 3);
1204
1205 // frame alignment
1206 GtkWidget * p_alignment_display_type = gtk_alignment_new(0.5, 0.5, 1, 1);
1207 gtk_container_add(GTK_CONTAINER(p_frame_display_type), p_alignment_display_type);
1208 gtk_alignment_set_padding(GTK_ALIGNMENT(p_alignment_display_type), 4, 4, 10, 10);
1209 GtkWidget *p_table = gtk_table_new(3, 2, FALSE);
1210 gtk_table_set_col_spacings(GTK_TABLE(p_table), 10);
1211 gtk_container_add(GTK_CONTAINER(p_alignment_display_type), p_table);
1212
1213 // radiobuttons
1214 GtkWidget * p_image_disp_type_image = gtk_image_new();
1215 GtkWidget * p_image_disp_type_image_cust = NULL;
1216 gchar *symbol_name_lowercase = (char *)xkb_get_current_symbol_name_lowercase(p_xkb);
1217 gchar *flag_filepath = NULL;
1218 gchar *flag_filepath_cust = NULL;
1219 if(strchr(symbol_name_lowercase, '/') != NULL)
1220 {
1221 gchar *layout_mod = g_strdup(symbol_name_lowercase);
1222 layout_mod = g_strdelimit(layout_mod, "/", '-');
1223 flag_filepath = g_strdup_printf(flag_filepath_generator, FLAGSDIR, layout_mod);
1224 if(p_xkb->cust_dir_exists)
1225 flag_filepath_cust = g_strdup_printf(flag_filepath_generator, FLAGSCUSTDIR, layout_mod);
1226 g_free(layout_mod);
1227 }
1228 else
1229 {
1230 flag_filepath = g_strdup_printf(flag_filepath_generator, FLAGSDIR, symbol_name_lowercase);
1231 if(p_xkb->cust_dir_exists)
1232 flag_filepath_cust = g_strdup_printf(flag_filepath_generator, FLAGSCUSTDIR, symbol_name_lowercase);
1233 }
1234 GdkPixbuf *p_pixbuf = gdk_pixbuf_new_from_file_at_size(flag_filepath, -1, 16, NULL);
1235 if(p_pixbuf != NULL)
1236 {
1237 gtk_image_set_from_pixbuf(GTK_IMAGE(p_image_disp_type_image), p_pixbuf);
1238 g_object_unref(G_OBJECT(p_pixbuf));
1239 }
1240 if(flag_filepath_cust != NULL)
1241 {
1242 p_image_disp_type_image_cust = gtk_image_new();
1243 GdkPixbuf *p_pixbuf_cust = gdk_pixbuf_new_from_file_at_size(flag_filepath_cust, -1, 16, NULL);
1244 if(p_pixbuf_cust != NULL)
1245 {
1246 gtk_image_set_from_pixbuf(GTK_IMAGE(p_image_disp_type_image_cust), p_pixbuf_cust);
1247 g_object_unref(G_OBJECT(p_pixbuf_cust));
1248 }
1249 }
1250 g_free(flag_filepath);
1251 if(flag_filepath_cust != NULL)
1252 g_free(flag_filepath_cust);
1253 g_free(symbol_name_lowercase);
1254 GtkWidget * p_label_disp_type_text = gtk_label_new(NULL);
1255 snprintf(markup_str, MAX_MARKUP_LEN, "<span font='%d' font_weight='heavy'>%s</span>", 16, xkb_get_current_symbol_name(p_xkb));
1256 gtk_label_set_markup(GTK_LABEL(p_label_disp_type_text), markup_str);
895da737 1257 GtkWidget * p_radiobutton_disp_type_image = gtk_radio_button_new_with_label(NULL, (const gchar *)_("Image"));
4496e880
JL
1258 GtkWidget * p_radiobutton_disp_type_image_cust = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(p_radiobutton_disp_type_image), (const gchar *)_("Custom Image"));
1259 GtkWidget * p_radiobutton_disp_type_text = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(p_radiobutton_disp_type_image), (const gchar *)_("Text"));
1260
1261 gtk_table_attach(GTK_TABLE(p_table), p_image_disp_type_image, 0, 1, 0, 1, GTK_FILL, GTK_FILL, 0, 0);
1262 gtk_table_attach(GTK_TABLE(p_table), p_radiobutton_disp_type_image, 1, 2, 0, 1, GTK_FILL, GTK_FILL, 0, 0);
1263 if(p_xkb->cust_dir_exists)
1264 {
1265 gtk_table_attach(GTK_TABLE(p_table), p_image_disp_type_image_cust, 0, 1, 1, 2, GTK_FILL, GTK_FILL, 0, 0);
1266 gtk_table_attach(GTK_TABLE(p_table), p_radiobutton_disp_type_image_cust, 1, 2, 1, 2, GTK_FILL, GTK_FILL, 0, 0);
1267 }
1268 gtk_table_attach(GTK_TABLE(p_table), p_label_disp_type_text, 0, 1, 2, 3, GTK_FILL, GTK_FILL, 0, 0);
1269 gtk_table_attach(GTK_TABLE(p_table), p_radiobutton_disp_type_text, 1, 2, 2, 3, GTK_FILL, GTK_FILL, 0, 0);
1270
1271 g_signal_connect(p_radiobutton_disp_type_image, "toggled", G_CALLBACK(on_radiobutton_disp_type_image_toggled), p_xkb);
1272 if(p_xkb->cust_dir_exists)
1273 g_signal_connect(p_radiobutton_disp_type_image_cust, "toggled", G_CALLBACK(on_radiobutton_disp_type_image_cust_toggled), p_xkb);
1274 g_signal_connect(p_radiobutton_disp_type_text, "toggled", G_CALLBACK(on_radiobutton_disp_type_text_toggled), p_xkb);
1275 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(p_radiobutton_disp_type_image), (p_xkb->display_type == DISP_TYPE_IMAGE) ||
1276 ( (p_xkb->display_type == DISP_TYPE_IMAGE_CUST) && (!p_xkb->cust_dir_exists) ) );
1277 if(p_xkb->cust_dir_exists)
1278 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(p_radiobutton_disp_type_image_cust), p_xkb->display_type == DISP_TYPE_IMAGE_CUST);
1279 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(p_radiobutton_disp_type_text), p_xkb->display_type == DISP_TYPE_TEXT);
1280
1281
1282 // 'PANEL ICON SIZE' frame
1283 GtkWidget * p_frame_flag_size = gtk_frame_new(NULL);
1284 GtkWidget * p_label_flag_size = gtk_label_new(NULL);
1285 snprintf(markup_str, MAX_MARKUP_LEN, "<b>%s</b>", _("Panel Icon Size"));
1286 gtk_label_set_markup(GTK_LABEL(p_label_flag_size), markup_str);
1287 gtk_misc_set_padding(GTK_MISC(p_label_flag_size), 1, 0);
1288 gtk_frame_set_label_widget(GTK_FRAME(p_frame_flag_size), p_label_flag_size);
1289 gtk_frame_set_shadow_type(GTK_FRAME(p_frame_flag_size), GTK_SHADOW_NONE);
1290 gtk_box_pack_start(GTK_BOX(p_vbox_main), p_frame_flag_size, TRUE, TRUE, 2);
1291 gtk_container_set_border_width(GTK_CONTAINER(p_frame_flag_size), 3);
1292
1293 // frame alignment
1294 GtkWidget * p_alignment_flag_size = gtk_alignment_new(0.5, 0.5, 1, 1);
1295 gtk_container_add(GTK_CONTAINER(p_frame_flag_size), p_alignment_flag_size);
1296 gtk_alignment_set_padding(GTK_ALIGNMENT(p_alignment_flag_size), 4, 4, 10, 10);
1297 GtkWidget *p_hbox_flag_size = gtk_hbox_new(FALSE, 2);
1298 gtk_container_add(GTK_CONTAINER(p_alignment_flag_size), p_hbox_flag_size);
1299
1300 GtkWidget *p_radiobutton_flag_size_1 = gtk_radio_button_new_with_label(NULL, "1");
1301 GtkWidget *p_radiobutton_flag_size_2 = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(p_radiobutton_flag_size_1), "2");
1302 GtkWidget *p_radiobutton_flag_size_3 = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(p_radiobutton_flag_size_1), "3");
1303 GtkWidget *p_radiobutton_flag_size_4 = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(p_radiobutton_flag_size_1), "4");
1304 GtkWidget *p_radiobutton_flag_size_5 = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(p_radiobutton_flag_size_1), "5");
895da737 1305 GtkWidget *p_radiobutton_flag_size_6 = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(p_radiobutton_flag_size_1), "6");
4496e880
JL
1306 g_signal_connect(p_radiobutton_flag_size_1, "toggled", G_CALLBACK(on_radiobutton_flag_size_1_toggled), p_xkb);
1307 g_signal_connect(p_radiobutton_flag_size_2, "toggled", G_CALLBACK(on_radiobutton_flag_size_2_toggled), p_xkb);
1308 g_signal_connect(p_radiobutton_flag_size_3, "toggled", G_CALLBACK(on_radiobutton_flag_size_3_toggled), p_xkb);
1309 g_signal_connect(p_radiobutton_flag_size_4, "toggled", G_CALLBACK(on_radiobutton_flag_size_4_toggled), p_xkb);
1310 g_signal_connect(p_radiobutton_flag_size_5, "toggled", G_CALLBACK(on_radiobutton_flag_size_5_toggled), p_xkb);
895da737 1311 g_signal_connect(p_radiobutton_flag_size_6, "toggled", G_CALLBACK(on_radiobutton_flag_size_6_toggled), p_xkb);
4496e880
JL
1312 gtk_box_pack_start(GTK_BOX(p_hbox_flag_size), p_radiobutton_flag_size_1, TRUE, TRUE, 2);
1313 gtk_box_pack_start(GTK_BOX(p_hbox_flag_size), p_radiobutton_flag_size_2, TRUE, TRUE, 2);
1314 gtk_box_pack_start(GTK_BOX(p_hbox_flag_size), p_radiobutton_flag_size_3, TRUE, TRUE, 2);
1315 gtk_box_pack_start(GTK_BOX(p_hbox_flag_size), p_radiobutton_flag_size_4, TRUE, TRUE, 2);
1316 gtk_box_pack_start(GTK_BOX(p_hbox_flag_size), p_radiobutton_flag_size_5, TRUE, TRUE, 2);
895da737 1317 gtk_box_pack_start(GTK_BOX(p_hbox_flag_size), p_radiobutton_flag_size_6, TRUE, TRUE, 2);
4496e880
JL
1318 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(p_radiobutton_flag_size_1), p_xkb->flag_size == 1);
1319 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(p_radiobutton_flag_size_2), p_xkb->flag_size == 2);
1320 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(p_radiobutton_flag_size_3), p_xkb->flag_size == 3);
1321 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(p_radiobutton_flag_size_4), p_xkb->flag_size == 4);
1322 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(p_radiobutton_flag_size_5), p_xkb->flag_size == 5);
895da737 1323 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(p_radiobutton_flag_size_6), p_xkb->flag_size == 6);
22242ed4 1324
d862b520 1325 /* Connect signals. */
4496e880 1326 g_signal_connect(p_xkb->p_dialog_config, "response", G_CALLBACK(on_dialog_config_response), p_xkb);
22242ed4 1327
d862b520 1328 /* Display the dialog. */
4496e880
JL
1329 gtk_widget_set_size_request(p_xkb->p_dialog_config, 350, -1);
1330 gtk_widget_show_all(p_xkb->p_dialog_config);
1331 gtk_window_present(GTK_WINDOW(p_xkb->p_dialog_config));
1332
1333 user_active = TRUE;
22242ed4
HJYP
1334}
1335
8f9e6256 1336/* Callback when the configuration is to be saved. */
1337static void xkb_save_configuration(Plugin * p, FILE * fp)
1338{
4496e880
JL
1339 XkbPlugin * p_xkb = (XkbPlugin *)p->priv;
1340 lxpanel_put_int(fp, "DisplayType", p_xkb->display_type);
895da737 1341 lxpanel_put_int(fp, "PerWinLayout", p_xkb->enable_perwin);
4496e880
JL
1342 lxpanel_put_str(fp, "Model", p_xkb->kbd_model);
1343 lxpanel_put_str(fp, "LayoutsList", p_xkb->kbd_layouts);
1344 lxpanel_put_str(fp, "VariantsList", p_xkb->kbd_variants);
1345 lxpanel_put_str(fp, "ToggleOpt", p_xkb->kbd_change_option);
1346 lxpanel_put_int(fp, "FlagSize", p_xkb->flag_size);
8f9e6256 1347}
1348
1349/* Callback when panel configuration changes. */
1350static void xkb_panel_configuration_changed(Plugin * p)
1351{
1352 /* Do a full redraw. */
4496e880
JL
1353 XkbPlugin * p_xkb = (XkbPlugin *)p->priv;
1354 xkb_redraw(p_xkb);
8f9e6256 1355}
22242ed4 1356
d862b520 1357/* Plugin descriptor. */
22242ed4 1358PluginClass xkb_plugin_class = {
2918994e 1359
1360 PLUGINCLASS_VERSIONING,
22242ed4
HJYP
1361
1362 type : "xkb",
4496e880
JL
1363 name : N_("Keyboard Layout Handler"),
1364 version: "2.0",
1365 description : N_("Handle keyboard layouts"),
22242ed4
HJYP
1366
1367 constructor : xkb_constructor,
1368 destructor : xkb_destructor,
8f9e6256 1369 config : xkb_configure,
1370 save : xkb_save_configuration,
1371 panel_configuration_changed : xkb_panel_configuration_changed
d862b520 1372
22242ed4 1373};