Skip to content

Instantly share code, notes, and snippets.

@jouyouyun
Created October 16, 2013 07:23
Show Gist options
  • Save jouyouyun/7003896 to your computer and use it in GitHub Desktop.
Save jouyouyun/7003896 to your computer and use it in GitHub Desktop.
static gboolean
set_layouts_from_gsettings (void)
{
gchar **kbd_layout = NULL;
GSettings *kbd_set = NULL;
guint len = 0;
gboolean is_ok;
kbd_set = g_settings_new ("org.gnome.libgnomekbd.keyboard");
kbd_layout = g_settings_get_strv (kbd_set, "layouts");
len = g_strv_length (kbd_layout);
g_debug ("cur kbd layout: %s\tlen: %u\n", kbd_layout[0], len);
if ( len < 1 ) {
g_debug ("default layout: %s\n", DEFAULT_LAYOUT);
gchar *tmp = g_strdup_printf ("%s;", DEFAULT_LAYOUT);
kbd_layout = g_strsplit (tmp, ";", -1);
g_free (tmp);
}
is_ok = g_settings_set_strv (kbd_set, "layouts",
(const gchar* const*)kbd_layout);
if ( !is_ok ) {
g_debug ("set layouts failed: %s", kbd_layout[0]);
return TRUE;
}
g_strfreev (kbd_layout);
g_settings_sync ();
g_object_unref (kbd_set);
return FALSE;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment