static void reset_to_defaults (GtkWidget * button, GtkBuilder * dialog) { GkbdKeyboardConfig empty_kbd_config; gkbd_keyboard_config_init (&empty_kbd_config, engine); gkbd_keyboard_config_save (&empty_kbd_config); gkbd_keyboard_config_term (&empty_kbd_config); g_settings_reset (xkb_desktop_settings, GKBD_DESKTOP_CONFIG_KEY_DEFAULT_GROUP); /* all the rest is g-s-d's business */ }
void enable_disable_restoring (GtkBuilder * dialog) { GkbdKeyboardConfig gswic; gboolean enable; gkbd_keyboard_config_init (&gswic, engine); gkbd_keyboard_config_load (&gswic, NULL); enable = !gkbd_keyboard_config_equals (&gswic, &initial_config); gkbd_keyboard_config_term (&gswic); gtk_widget_set_sensitive (WID ("xkb_reset_to_defaults"), enable); }
static void cleanup_xkb_tabs (GtkBuilder * dialog, GObject *where_the_object_wa) { gkbd_desktop_config_term (&desktop_config); gkbd_keyboard_config_term (&initial_config); g_object_unref (G_OBJECT (config_registry)); config_registry = NULL; /* Don't unref it here, or we'll crash if open the panel again */ engine = NULL; g_object_unref (G_OBJECT (xkb_keyboard_settings)); g_object_unref (G_OBJECT (xkb_desktop_settings)); xkb_keyboard_settings = NULL; xkb_desktop_settings = NULL; }
static void apply_xkb_settings (void) { GkbdKeyboardConfig current_sys_kbd_config; if (!inited_ok) return; gkbd_keyboard_config_init (¤t_sys_kbd_config, xkl_engine); gkbd_keyboard_config_load (¤t_kbd_config, &initial_sys_kbd_config); gkbd_keyboard_config_load_from_x_current (¤t_sys_kbd_config, NULL); if (!try_activating_xkb_config_if_new (¤t_sys_kbd_config)) { if (filter_xkb_config ()) { if (!try_activating_xkb_config_if_new (¤t_sys_kbd_config)) { g_warning ("Could not activate the filtered XKB configuration"); activation_error (); } } else { g_warning ("Could not activate the XKB configuration"); activation_error (); } } else xkl_debug (100, "Actual KBD configuration was not changed: redundant notification\n"); gkbd_keyboard_config_term (¤t_sys_kbd_config); show_hide_icon (); }
static void apply_xkb_settings (void) { GConfClient *conf_client; GkbdKeyboardConfig current_sys_kbd_config; int group_to_activate = -1; char *gdm_layout; char *s; if (!inited_ok) return; conf_client = gconf_client_get_default (); /* With GDM the user can already set a layout from the login * screen. Try to keep that setting. * We clear gdm_keyboard_layout early, so we don't risk * recursion from gconf notification. */ gdm_layout = g_strdup (gdm_keyboard_layout); gdm_keyboard_layout = NULL; /* gdm's configuration and $GDM_KEYBOARD_LAYOUT separates layout and * variant with a space, but gconf uses tabs; so convert to be robust * with both */ for (s = gdm_layout; s && *s; ++s) { if (*s == ' ') { *s = '\t'; } } if (gdm_layout != NULL) { GSList *layouts; GSList *found_node; int max_groups; max_groups = xkl_engine_get_max_num_groups (xkl_engine); layouts = gconf_client_get_list (conf_client, GKBD_KEYBOARD_CONFIG_KEY_LAYOUTS, GCONF_VALUE_STRING, NULL); /* Add the layout if it doesn't already exist. XKB limits the * total number of layouts. If we already have the maximum * number of layouts configured, we replace the last one. This * prevents the list from becoming full if the user has a habit * of selecting many different keyboard layouts in GDM. */ found_node = g_slist_find_custom (layouts, gdm_layout, (GCompareFunc) g_strcmp0); if (!found_node) { /* Insert at the last valid place, or at the end of * list, whichever comes first */ layouts = g_slist_insert (layouts, g_strdup (gdm_layout), max_groups - 1); if (g_slist_length (layouts) > max_groups) { GSList *last; GSList *free_layouts; last = g_slist_nth (layouts, max_groups - 1); free_layouts = last->next; last->next = NULL; g_slist_foreach (free_layouts, (GFunc) g_free, NULL); g_slist_free (free_layouts); } gconf_client_set_list (conf_client, GKBD_KEYBOARD_CONFIG_KEY_LAYOUTS, GCONF_VALUE_STRING, layouts, NULL); } g_slist_foreach (layouts, (GFunc) g_free, NULL); g_slist_free (layouts); } gkbd_keyboard_config_init (¤t_sys_kbd_config, conf_client, xkl_engine); gkbd_keyboard_config_load_from_gconf (¤t_kbd_config, &initial_sys_kbd_config); gkbd_keyboard_config_load_from_x_current (¤t_sys_kbd_config, NULL); if (!try_activating_xkb_config_if_new (¤t_sys_kbd_config)) { if (filter_xkb_config ()) { if (!try_activating_xkb_config_if_new (¤t_sys_kbd_config)) { g_warning ("Could not activate the filtered XKB configuration"); activation_error (); } } else { g_warning ("Could not activate the XKB configuration"); activation_error (); } } else xkl_debug (100, "Actual KBD configuration was not changed: redundant notification\n"); if (gdm_layout != NULL) { /* If there are multiple layouts, * try to find the one closest to the gdm layout */ GSList *l; int i; size_t len = strlen (gdm_layout); for (i = 0, l = current_kbd_config.layouts_variants; l; i++, l = l->next) { char *lv = l->data; if (strncmp (lv, gdm_layout, len) == 0 && (lv[len] == '\0' || lv[len] == '\t')) { group_to_activate = i; break; } } } g_free (gdm_layout); if (group_to_activate != -1) xkl_engine_lock_group (current_config.engine, group_to_activate); gkbd_keyboard_config_term (¤t_sys_kbd_config); }