69
57
/* one instance for ALL widgets */
70
58
static gki_globals globals;
72
#define ForAllIndicators() \
75
for (cur = globals.widget_instances; cur != NULL; cur = cur->next) { \
76
GkbdStatus * gki = (GkbdStatus*)cur->data;
77
#define NextIndicator() \
81
60
G_DEFINE_TYPE (GkbdStatus, gkbd_status, GTK_TYPE_STATUS_ICON)
83
63
gkbd_status_global_init (void);
85
65
gkbd_status_global_term (void);
87
gkbd_status_prepare_drawing (GkbdStatus * gki, int group);
67
gkbd_status_prepare_drawing (int group);
89
69
gkbd_status_set_current_page_for_group (GkbdStatus * gki, int group);
91
71
gkbd_status_set_current_page (GkbdStatus * gki);
93
gkbd_status_global_cleanup (GkbdStatus * gki);
95
gkbd_status_global_fill (GkbdStatus * gki);
73
gkbd_status_reinit_globals (void);
75
gkbd_status_cleanup_icons (void);
77
gkbd_status_fill_icons (void);
97
79
gkbd_status_set_tooltips (GkbdStatus * gki, const char *str);
161
130
cairo_font_options_t *fo;
162
131
static GHashTable *ln2cnt_map = NULL;
133
GkbdIndicatorConfig *ind_cfg =
134
gkbd_configuration_get_indicator_config (globals.config);
164
136
xkl_debug (160, "Rendering cairo for group %d\n", group);
165
if (globals.ind_cfg.background_color != NULL &&
166
globals.ind_cfg.background_color[0] != 0) {
137
if (ind_cfg->background_color != NULL &&
138
ind_cfg->background_color[0] != 0) {
168
(globals.ind_cfg.background_color, "%lg %lg %lg", &r,
140
(ind_cfg->background_color, "%lg %lg %lg", &r,
170
142
cairo_set_source_rgb (cr, r, g, b);
171
143
cairo_rectangle (cr, 0, 0, globals.current_width,
177
if (globals.ind_cfg.foreground_color != NULL &&
178
globals.ind_cfg.foreground_color[0] != 0) {
149
if (ind_cfg->foreground_color != NULL &&
150
ind_cfg->foreground_color[0] != 0) {
180
(globals.ind_cfg.foreground_color, "%lg %lg %lg", &r,
152
(ind_cfg->foreground_color, "%lg %lg %lg", &r,
182
154
cairo_set_source_rgb (cr, r, g, b);
186
if (globals.ind_cfg.font_family != NULL &&
187
globals.ind_cfg.font_family[0] != 0) {
188
cairo_select_font_face (cr, globals.ind_cfg.font_family,
158
if (ind_cfg->font_family != NULL && ind_cfg->font_family[0] != 0) {
159
cairo_select_font_face (cr, ind_cfg->font_family,
189
160
CAIRO_FONT_SLANT_NORMAL,
190
161
CAIRO_FONT_WEIGHT_NORMAL);
193
164
pfd = pango_font_description_new ();
194
pango_font_description_set_family (pfd,
195
globals.ind_cfg.font_family);
165
pango_font_description_set_family (pfd, ind_cfg->font_family);
196
166
pango_font_description_set_style (pfd, PANGO_STYLE_NORMAL);
197
167
pango_font_description_set_weight (pfd, PANGO_WEIGHT_NORMAL);
198
168
pango_font_description_set_size (pfd,
199
globals.ind_cfg.font_size *
169
ind_cfg->font_size * PANGO_SCALE);
202
171
pcc = pango_cairo_create_context (cr);
397
365
gkbd_status_update_tooltips (GkbdStatus * gki)
399
XklState *state = xkl_engine_get_current_state (globals.engine);
401
if (state == NULL || state->group < 0
402
|| state->group >= g_strv_length (globals.full_group_names))
405
buf = g_strdup_printf (globals.tooltips_format,
406
globals.full_group_names[state->group]);
408
gkbd_status_set_tooltips (gki, buf);
368
gkbd_configuration_get_current_tooltip (globals.config);
370
gkbd_status_set_tooltips (gki, buf);
376
gkbd_status_reinit_globals ()
378
gkbd_status_cleanup_icons ();
379
gkbd_status_fill_icons ();
413
383
gkbd_status_reinit_ui (GkbdStatus * gki)
415
gkbd_status_global_cleanup (gki);
416
gkbd_status_global_fill (gki);
418
385
gkbd_status_set_current_page (gki);
421
388
/* Should be called once for all widgets */
423
gkbd_status_cfg_changed (GConfClient * client,
424
guint cnxn_id, GConfEntry * entry)
427
"General configuration changed in GConf - reiniting...\n");
428
gkbd_desktop_config_load_from_gconf (&globals.cfg);
429
gkbd_desktop_config_activate (&globals.cfg);
430
ForAllIndicators () {
431
gkbd_status_reinit_ui (gki);
435
/* Should be called once for all widgets */
437
gkbd_status_ind_cfg_changed (GConfClient * client,
438
guint cnxn_id, GConfEntry * entry)
441
"Applet configuration changed in GConf - reiniting...\n");
442
gkbd_indicator_config_load_from_gconf (&globals.ind_cfg);
444
gkbd_indicator_config_free_image_filenames (&globals.ind_cfg);
445
gkbd_indicator_config_load_image_filenames (&globals.ind_cfg,
448
gkbd_indicator_config_activate (&globals.ind_cfg);
450
ForAllIndicators () {
451
gkbd_status_reinit_ui (gki);
456
gkbd_status_load_group_names (const gchar ** layout_ids,
457
const gchar ** variant_ids)
459
if (!gkbd_desktop_config_load_group_descriptions
460
(&globals.cfg, globals.registry, layout_ids, variant_ids,
461
&globals.short_group_names, &globals.full_group_names)) {
462
/* We just populate no short names (remain NULL) -
463
* full names are going to be used anyway */
464
gint i, total_groups =
465
xkl_engine_get_num_groups (globals.engine);
466
xkl_debug (150, "group descriptions loaded: %d!\n",
468
globals.full_group_names =
469
g_new0 (char *, total_groups + 1);
471
if (xkl_engine_get_features (globals.engine) &
472
XKLF_MULTIPLE_LAYOUTS_SUPPORTED) {
473
GSList *lst = globals.kbd_cfg.layouts_variants;
474
for (i = 0; lst; lst = lst->next, i++) {
475
globals.full_group_names[i] =
476
g_strdup ((char *) lst->data);
479
for (i = total_groups; --i >= 0;) {
480
globals.full_group_names[i] =
481
g_strdup_printf ("Group %d", i);
487
/* Should be called once for all widgets */
489
gkbd_status_kbd_cfg_callback (GkbdStatus * gki)
491
XklConfigRec *xklrec = xkl_config_rec_new ();
493
"XKB configuration changed on X Server - reiniting...\n");
495
gkbd_keyboard_config_load_from_x_current (&globals.kbd_cfg,
498
gkbd_indicator_config_free_image_filenames (&globals.ind_cfg);
499
gkbd_indicator_config_load_image_filenames (&globals.ind_cfg,
502
g_strfreev (globals.full_group_names);
503
globals.full_group_names = NULL;
505
if (globals.short_group_names != NULL) {
506
g_strfreev (globals.short_group_names);
507
globals.short_group_names = NULL;
510
gkbd_status_load_group_names ((const gchar **) xklrec->layouts,
511
(const gchar **) xklrec->variants);
513
ForAllIndicators () {
514
gkbd_status_reinit_ui (gki);
516
g_object_unref (G_OBJECT (xklrec));
390
gkbd_status_cfg_callback (GkbdConfiguration * configuration)
392
xkl_debug (150, "Config changed: reinit ui\n");
393
gkbd_status_reinit_globals ();
394
ForAllObjects (configuration) {
395
gkbd_status_reinit_ui (GKBD_STATUS (gki));
519
399
/* Should be called once for all applets */
521
gkbd_status_state_callback (XklEngine * engine,
522
XklEngineStateChange changeType,
523
gint group, gboolean restore)
401
gkbd_status_state_callback (GkbdConfiguration * configuration, gint group)
525
xkl_debug (150, "group is now %d, restore: %d\n", group, restore);
527
if (changeType == GROUP_CHANGED) {
528
ForAllIndicators () {
529
xkl_debug (200, "do repaint\n");
530
gkbd_status_set_current_page_for_group (gki,
403
xkl_debug (150, "Set page to group %d\n", group);
404
ForAllObjects (configuration) {
405
xkl_debug (150, "do repaint for icon %p\n", gki);
406
gkbd_status_set_current_page_for_group (GKBD_STATUS (gki),
539
413
gkbd_status_set_current_page (GkbdStatus * gki)
542
cur_state = xkl_engine_get_current_state (globals.engine);
416
gkbd_configuration_get_xkl_engine (globals.config);
417
XklState *cur_state = xkl_engine_get_current_state (engine);
543
418
if (cur_state->group >= 0)
544
419
gkbd_status_set_current_page_for_group (gki,
545
420
cur_state->group);
643
if (!g_slist_length (globals.widget_instances))
523
if (!gkbd_configuration_if_any_object_exists (globals.config))
644
524
gkbd_status_global_init ();
646
526
gki->priv = g_new0 (GkbdStatusPrivate, 1);
648
/* This should give NA a hint about the order */
528
/* This should give Notification Area a hint about the order of icons */
649
529
gtk_status_icon_set_name (GTK_STATUS_ICON (gki), "keyboard");
651
xkl_debug (100, "Initiating the widget startup process for %p\n",
531
xkl_debug (100, "The status icon startup process for %p started\n",
654
if (globals.engine == NULL) {
534
if (gkbd_configuration_get_xkl_engine (globals.config) == NULL) {
655
535
gkbd_status_set_tooltips (gki,
656
536
_("XKB initialization error"));
660
gkbd_status_set_tooltips (gki, NULL);
662
gkbd_status_global_fill (gki);
663
gkbd_status_set_current_page (gki);
665
540
/* append AFTER all initialization work is finished */
666
globals.widget_instances =
667
g_slist_append (globals.widget_instances, gki);
541
gkbd_configuration_append_object (globals.config, G_OBJECT (gki));
669
543
g_signal_connect (gki, "size-changed",
670
544
G_CALLBACK (gkbd_status_size_changed), NULL);
720
597
xkl_debug (100, "*** Last GkbdStatus instance *** \n");
721
598
gkbd_status_stop_listen ();
723
gkbd_desktop_config_stop_listen (&globals.cfg);
724
gkbd_indicator_config_stop_listen (&globals.ind_cfg);
726
gkbd_indicator_config_term (&globals.ind_cfg);
727
gkbd_keyboard_config_term (&globals.kbd_cfg);
728
gkbd_desktop_config_term (&globals.cfg);
730
if (g_signal_handler_is_connected
731
(globals.engine, globals.state_changed_handler)) {
732
g_signal_handler_disconnect (globals.engine,
733
globals.state_changed_handler);
734
globals.state_changed_handler = 0;
736
if (g_signal_handler_is_connected
737
(globals.engine, globals.config_changed_handler)) {
738
g_signal_handler_disconnect (globals.engine,
739
globals.config_changed_handler);
740
globals.config_changed_handler = 0;
743
g_object_unref (G_OBJECT (globals.registry));
744
globals.registry = NULL;
745
g_object_unref (G_OBJECT (globals.engine));
746
globals.engine = NULL;
600
g_object_unref (globals.config);
601
globals.config = NULL;
747
603
xkl_debug (100, "*** Terminated globals *** \n");
757
613
memset (&globals, 0, sizeof (globals));
759
/* Initing some global vars */
760
globals.tooltips_format = "%s";
762
615
/* Initing vtable */
763
616
object_class->finalize = gkbd_status_finalize;
769
620
gkbd_status_global_init (void)
771
GConfClient *gconf_client;
772
XklConfigRec *xklrec = xkl_config_rec_new ();
774
globals.engine = xkl_engine_get_instance (GDK_DISPLAY ());
775
if (globals.engine == NULL) {
776
xkl_debug (0, "Libxklavier initialization error");
780
gconf_client = gconf_client_get_default ();
782
globals.state_changed_handler =
783
g_signal_connect (globals.engine, "X-state-changed",
784
G_CALLBACK (gkbd_status_state_callback),
786
globals.config_changed_handler =
787
g_signal_connect (globals.engine, "X-config-changed",
788
G_CALLBACK (gkbd_status_kbd_cfg_callback),
791
gkbd_desktop_config_init (&globals.cfg, gconf_client,
793
gkbd_keyboard_config_init (&globals.kbd_cfg, gconf_client,
795
gkbd_indicator_config_init (&globals.ind_cfg, gconf_client,
798
g_object_unref (gconf_client);
800
gkbd_desktop_config_load_from_gconf (&globals.cfg);
801
gkbd_desktop_config_activate (&globals.cfg);
804
xkl_config_registry_get_instance (globals.engine);
805
xkl_config_registry_load (globals.registry,
806
globals.cfg.load_extra_items);
808
gkbd_keyboard_config_load_from_x_current (&globals.kbd_cfg,
811
gkbd_indicator_config_load_from_gconf (&globals.ind_cfg);
813
gkbd_indicator_config_load_image_filenames (&globals.ind_cfg,
816
gkbd_indicator_config_activate (&globals.ind_cfg);
818
gkbd_status_load_group_names ((const gchar **) xklrec->layouts,
819
(const gchar **) xklrec->variants);
820
g_object_unref (G_OBJECT (xklrec));
822
gkbd_desktop_config_start_listen (&globals.cfg,
823
(GConfClientNotifyFunc)
824
gkbd_status_cfg_changed, NULL);
825
gkbd_indicator_config_start_listen (&globals.ind_cfg,
826
(GConfClientNotifyFunc)
827
gkbd_status_ind_cfg_changed,
622
globals.config = gkbd_configuration_get ();
624
g_signal_connect (globals.config, "group-changed",
625
G_CALLBACK (gkbd_status_state_callback), NULL);
626
g_signal_connect (globals.config, "changed",
627
G_CALLBACK (gkbd_status_cfg_callback), NULL);
829
629
gkbd_status_start_listen ();
831
631
xkl_debug (100, "*** Inited globals *** \n");