static void xfce_keyboard_layout_helper_init (XfceKeyboardLayoutHelper *helper) { /* init */ helper->channel = NULL; /* open the channel */ helper->channel = xfconf_channel_get ("keyboard-layout"); helper->xkb_disable_settings = xfconf_channel_get_bool (helper->channel, "/Default/XkbDisable", TRUE); #ifdef HAVE_LIBXKLAVIER /* monitor channel changes */ g_signal_connect (G_OBJECT (helper->channel), "property-changed", G_CALLBACK (xfce_keyboard_layout_helper_channel_property_changed), helper); helper->engine = xkl_engine_get_instance (GDK_DISPLAY ()); helper->config = xkl_config_rec_new (); xkl_config_rec_get_from_server (helper->config, helper->engine); helper->system_keyboard_model = g_strdup (helper->config->model); gdk_window_add_filter (NULL, (GdkFilterFunc) handle_xevent, helper); g_signal_connect (helper->engine, "X-new-device", G_CALLBACK (xfce_keyboard_layout_reset_xkl_config), helper); xkl_engine_start_listen (helper->engine, XKLL_TRACK_KEYBOARD_STATE); /* load settings */ xfce_keyboard_layout_helper_set_model (helper); xfce_keyboard_layout_helper_set_layout (helper); xfce_keyboard_layout_helper_set_variant (helper); xfce_keyboard_layout_helper_set_grpkey (helper); xfce_keyboard_layout_helper_set_composekey (helper); #endif /* HAVE_LIBXKLAVIER */ xfce_keyboard_layout_helper_process_xmodmap (); }
void mdm_layout_activate (const char *layout) { #ifdef HAVE_LIBXKLAVIER XklConfigRec *config; char *p; int ii, ic; init_xkl (); config = xkl_config_rec_new (); config->model = g_strdup (initial_config->model); if (layout == NULL) { config->layouts = g_strdupv (initial_config->layouts); config->variants = g_strdupv (initial_config->variants); config->options = g_strdupv (initial_config->options); } else { config->layouts = g_new0 (char *, g_strv_length (initial_config->layouts) + 2); config->variants = g_new0 (char *, g_strv_length (initial_config->variants) + 2); config->layouts[0] = g_strdup (layout); p = strchr (config->layouts[0], '\t'); if (p != NULL) { config->layouts[0][p - config->layouts[0]] = 0; config->variants[0] = g_strdup (p + 1); } else { config->variants[0] = g_strdup (""); } /* append other layouts from the initial configuration, so that * the session gets all of them */ ic = 1; for (ii = 0; ii < g_strv_length (initial_config->layouts); ++ii) { if (g_strcmp0 (config->layouts[0], initial_config->layouts[ii]) || strcmp_null_empty (config->variants[0], initial_config->variants[ii])) { config->layouts[ic] = g_strdup (initial_config->layouts[ii]); if (initial_config->variants[ii] != NULL) config->variants[ic] = g_strdup (initial_config->variants[ii]); else config->variants[ic] = g_strdup (""); ++ic; } } config->options = g_strdupv (initial_config->options); } xkl_config_rec_activate (config, engine); g_object_unref (config); #endif }
void xkb_layout_preview_set_drawing_layout (GtkWidget * kbdraw, const gchar * id) { #ifdef HAVE_X11_EXTENSIONS_XKB_H if (kbdraw != NULL) { if (id != NULL) { XklConfigRec *data; char **p, *layout, *variant; XkbComponentNamesRec component_names; data = xkl_config_rec_new (); if (xkl_config_rec_get_from_server (data, engine)) { if ((p = data->layouts) != NULL) g_strfreev (data->layouts); if ((p = data->variants) != NULL) g_strfreev (data->variants); data->layouts = g_new0 (char *, 2); data->variants = g_new0 (char *, 2); if (matekbd_keyboard_config_split_items (id, &layout, &variant) && variant != NULL) { data->layouts[0] = (layout == NULL) ? NULL : g_strdup (layout); data->variants[0] = (variant == NULL) ? NULL : g_strdup (variant); } else { data->layouts[0] = (id == NULL) ? NULL : g_strdup (id); data->variants[0] = NULL; } if (xkl_xkb_config_native_prepare (engine, data, &component_names)) { matekbd_keyboard_drawing_set_keyboard (MATEKBD_KEYBOARD_DRAWING (kbdraw), &component_names); xkl_xkb_config_native_cleanup (engine, &component_names); } } g_object_unref (G_OBJECT (data)); } else
static void init_xkl (void) { if (config_registry == NULL) { engine = xkl_engine_get_instance (GDK_DISPLAY ()); config_registry = xkl_config_registry_get_instance (engine); xkl_config_registry_load (config_registry, FALSE); initial_config = xkl_config_rec_new (); if (!xkl_config_rec_get_from_server (initial_config, engine)) { g_warning ("failed to load XKB configuration"); initial_config->model = g_strdup ("pc105"); } } }
static void popup_menu_show_layout () { static GkbdKeyboardDrawingGroupLevel groupsLevels[] = { { 0, 1}, { 0, 3}, { 0, 0}, { 0, 2} }; static GkbdKeyboardDrawingGroupLevel *pGroupsLevels[] = { groupsLevels, groupsLevels + 1, groupsLevels + 2, groupsLevels + 3 }; GtkBuilder *builder; GtkWidget *dialog, *kbdraw; XkbComponentNamesRec component_names; XklConfigRec *xkl_data; GdkRectangle *rect; GError *error = NULL; XklEngine *engine = xkl_engine_get_instance (GDK_DISPLAY ()); XklState *xkl_state = xkl_engine_get_current_state (engine); gchar **group_names = gkbd_status_get_group_names (); gpointer p = g_hash_table_lookup (preview_dialogs, GINT_TO_POINTER (xkl_state->group)); if (p != NULL) { /* existing window */ gtk_window_present (GTK_WINDOW (p)); return; } builder = gtk_builder_new (); gtk_builder_add_from_file (builder, DATADIR "/show-layout.ui", &error); if (error) { g_error ("building ui from %s failed: %s", DATADIR "/show-layout.ui", error->message); g_clear_error (&error); } dialog = GTK_WIDGET (gtk_builder_get_object (builder, "gswitchit_layout_view")); kbdraw = gkbd_keyboard_drawing_new (); if (xkl_state->group >= 0 && xkl_state->group < g_strv_length (group_names)) { char title[128] = ""; snprintf (title, sizeof (title), _("Keyboard Layout \"%s\""), group_names[xkl_state->group]); gtk_window_set_title (GTK_WINDOW (dialog), title); g_object_set_data_full (G_OBJECT (dialog), "group_name", g_strdup (group_names [xkl_state->group]), g_free); } gkbd_keyboard_drawing_set_groups_levels (GKBD_KEYBOARD_DRAWING (kbdraw), pGroupsLevels); xkl_data = xkl_config_rec_new (); if (xkl_config_rec_get_from_server (xkl_data, engine)) { int num_layouts = g_strv_length (xkl_data->layouts); int num_variants = g_strv_length (xkl_data->variants); if (xkl_state->group >= 0 && xkl_state->group < num_layouts && xkl_state->group < num_variants) { char *l = g_strdup (xkl_data->layouts[xkl_state->group]); char *v = g_strdup (xkl_data->variants [xkl_state->group]); char **p; int i; if ((p = xkl_data->layouts) != NULL) for (i = num_layouts; --i >= 0;) g_free (*p++); if ((p = xkl_data->variants) != NULL) for (i = num_variants; --i >= 0;) g_free (*p++); xkl_data->layouts = g_realloc (xkl_data->layouts, sizeof (char *) * 2); xkl_data->variants = g_realloc (xkl_data->variants, sizeof (char *) * 2); xkl_data->layouts[0] = l; xkl_data->variants[0] = v; xkl_data->layouts[1] = xkl_data->variants[1] = NULL; } if (xkl_xkb_config_native_prepare (engine, xkl_data, &component_names)) { gkbd_keyboard_drawing_set_keyboard (GKBD_KEYBOARD_DRAWING (kbdraw), &component_names); xkl_xkb_config_native_cleanup (engine, &component_names); } } g_object_unref (G_OBJECT (xkl_data)); g_object_set_data (G_OBJECT (dialog), "builderData", builder); g_signal_connect (GTK_OBJECT (dialog), "destroy", G_CALLBACK (show_layout_destroy), GINT_TO_POINTER (xkl_state->group)); g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK (show_layout_response), NULL); rect = gkbd_preview_load_position (); if (rect != NULL) { gtk_window_move (GTK_WINDOW (dialog), rect->x, rect->y); gtk_window_resize (GTK_WINDOW (dialog), rect->width, rect->height); g_free (rect); } else gtk_window_resize (GTK_WINDOW (dialog), 700, 400); gtk_window_set_resizable (GTK_WINDOW (dialog), TRUE); gtk_container_add (GTK_CONTAINER (gtk_builder_get_object (builder, "preview_vbox")), kbdraw); g_object_set_data (G_OBJECT (dialog), "kbdraw", kbdraw); g_hash_table_insert (preview_dialogs, GINT_TO_POINTER (xkl_state->group), dialog); gtk_widget_show_all (GTK_WIDGET (dialog)); }