Change the type of gsettings key "keyboard" from s to as.

Also rename it to "keyboards".
This commit is contained in:
Daiki Ueno
2011-09-12 15:33:20 +09:00
parent 362b210a31
commit ef3ea618d2
5 changed files with 76 additions and 50 deletions

View File

@ -1,10 +1,10 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<schemalist> <schemalist>
<schema id="org.fedorahosted.eekboard" path="/org/fedorahosted/eekboard/"> <schema id="org.fedorahosted.eekboard" path="/org/fedorahosted/eekboard/">
<key name="keyboard" type="s"> <key name="keyboards" type="as">
<default>'us'</default> <default>['us']</default>
<summary>Keyboard types</summary> <summary>Keyboard types</summary>
<description>keyboard types (comma separated).</description> <description>keyboard types.</description>
</key> </key>
<key name="ui-toolkit" type="s"> <key name="ui-toolkit" type="s">
<default>'gtk'</default> <default>'gtk'</default>

View File

@ -103,17 +103,19 @@ enum FocusListenerType {
}; };
static gboolean static gboolean
set_keyboard (Client *client, set_keyboards (Client *client,
const gchar *keyboard) gchar **keyboards)
{ {
if (g_strcmp0 (keyboard, "system") == 0) { if (g_strv_length (keyboards) == 0) {
if (!client_enable_xkl (client)) { if (!client_enable_xkl (client)) {
g_printerr ("Can't register xklavier event listeners\n"); g_printerr ("Can't register xklavier event listeners\n");
return FALSE; return FALSE;
} }
} else { } else {
if (!client_set_keyboard (client, keyboard)) { if (!client_set_keyboards (client, keyboards)) {
g_printerr ("Can't set keyboard \"%s\"\n", keyboard); gchar *str = g_strjoinv (", ", keyboards);
g_printerr ("Can't set keyboards \"%s\"\n", str);
g_free (str);
return FALSE; return FALSE;
} }
} }
@ -133,7 +135,7 @@ main (int argc, char **argv)
GMainLoop *loop = NULL; GMainLoop *loop = NULL;
gint focus; gint focus;
GSettings *settings = NULL; GSettings *settings = NULL;
gchar *keyboard; gchar **keyboards;
gint retval = 0; gint retval = 0;
if (!gtk_init_check (&argc, &argv)) { if (!gtk_init_check (&argc, &argv)) {
@ -312,13 +314,13 @@ main (int argc, char **argv)
G_CALLBACK(on_destroyed), loop); G_CALLBACK(on_destroyed), loop);
g_object_unref (eekboard); g_object_unref (eekboard);
keyboard = g_settings_get_string (settings, "keyboard"); keyboards = g_settings_get_strv (settings, "keyboards");
if (!set_keyboard (client, keyboard)) { if (!set_keyboards (client, keyboards)) {
g_free (keyboard); g_strfreev (keyboards);
retval = 1; retval = 1;
goto out; goto out;
} }
g_free (keyboard); g_strfreev (keyboards);
g_main_loop_run (loop); g_main_loop_run (loop);

View File

@ -127,12 +127,13 @@ static void focus_listener_cb (const AtspiEvent *event,
static gboolean keystroke_listener_cb (const AtspiDeviceEvent *stroke, static gboolean keystroke_listener_cb (const AtspiDeviceEvent *stroke,
void *user_data); void *user_data);
#endif /* HAVE_ATSPI */ #endif /* HAVE_ATSPI */
static gboolean set_keyboard (Client *client, static gboolean set_keyboards (Client *client,
const gchar *keyboard); const gchar **keyboard);
static gboolean set_keyboard_from_xkl (Client *client); static gboolean set_keyboards_from_xkl
(Client *client);
#ifdef HAVE_XTEST #ifdef HAVE_XTEST
static void update_modifier_keycodes static void update_modifier_keycodes
(Client *client); (Client *client);
#endif /* HAVE_XTEST */ #endif /* HAVE_XTEST */
static void static void
@ -297,11 +298,11 @@ client_init (Client *client)
} }
gboolean gboolean
client_set_keyboard (Client *client, client_set_keyboards (Client *client,
const gchar *keyboard) const gchar **keyboards)
{ {
gboolean retval; gboolean retval;
retval = set_keyboard (client, keyboard); retval = set_keyboards (client, keyboards);
if (retval && IS_KEYBOARD_VISIBLE (client)) if (retval && IS_KEYBOARD_VISIBLE (client))
eekboard_context_show_keyboard (client->context, NULL); eekboard_context_show_keyboard (client->context, NULL);
return retval; return retval;
@ -343,7 +344,7 @@ client_enable_xkl (Client *client)
xkl_engine_start_listen (client->xkl_engine, XKLL_TRACK_KEYBOARD_STATE); xkl_engine_start_listen (client->xkl_engine, XKLL_TRACK_KEYBOARD_STATE);
retval = set_keyboard_from_xkl (client); retval = set_keyboards_from_xkl (client);
if (IS_KEYBOARD_VISIBLE (client)) if (IS_KEYBOARD_VISIBLE (client))
eekboard_context_show_keyboard (client->context, NULL); eekboard_context_show_keyboard (client->context, NULL);
@ -697,7 +698,7 @@ on_xkl_config_changed (XklEngine *xklengine,
Client *client = user_data; Client *client = user_data;
gboolean retval; gboolean retval;
retval = set_keyboard_from_xkl (client); retval = set_keyboards_from_xkl (client);
g_return_if_fail (retval); g_return_if_fail (retval);
#ifdef HAVE_XTEST #ifdef HAVE_XTEST
@ -706,46 +707,39 @@ on_xkl_config_changed (XklEngine *xklengine,
} }
static gboolean static gboolean
set_keyboard (Client *client, set_keyboards (Client *client,
const gchar *keyboard) const gchar **keyboards)
{ {
GSList *keyboards = NULL; guint keyboard_id;
gchar **strv, **p; gchar **p;
GSList *head = NULL;
g_return_val_if_fail (keyboard != NULL, FALSE);
g_return_val_if_fail (*keyboard != '\0', FALSE);
if (client->keyboards) if (client->keyboards)
g_slist_free (client->keyboards); g_slist_free (client->keyboards);
strv = g_strsplit (keyboard, ",", -1); for (p = keyboards; *p != NULL; p++) {
for (p = strv; *p != NULL; p++) { keyboard_id = eekboard_context_add_keyboard (client->context, *p, NULL);
guint keyboard_id; if (keyboard_id == 0) {
g_slist_free (head);
keyboard_id = eekboard_context_add_keyboard (client->context,
*p,
NULL);
if (keyboard_id == 0)
return FALSE; return FALSE;
keyboards = g_slist_prepend (keyboards,
GUINT_TO_POINTER(keyboard_id));
} }
g_strfreev (strv); head = g_slist_prepend (head, GUINT_TO_POINTER(keyboard_id));
}
/* make a cycle */ /* make a cycle */
keyboards = g_slist_reverse (keyboards); head = g_slist_reverse (head);
g_slist_last (keyboards)->next = keyboards; g_slist_last (head)->next = head;
client->keyboards = keyboards; client->keyboards = head;
/* select the first keyboard */ /* select the first keyboard */
eekboard_context_set_keyboard (client->context, eekboard_context_set_keyboard (client->context,
GPOINTER_TO_UINT(keyboards->data), GPOINTER_TO_UINT(head->data),
NULL); NULL);
return TRUE; return TRUE;
} }
static gboolean static gboolean
set_keyboard_from_xkl (Client *client) set_keyboards_from_xkl (Client *client)
{ {
XklConfigRec *rec; XklConfigRec *rec;
gchar *layout, *keyboard; gchar *layout, *keyboard;

View File

@ -33,8 +33,8 @@ typedef struct _Client Client;
Client *client_new (GDBusConnection *connection); Client *client_new (GDBusConnection *connection);
gboolean client_set_keyboard (Client *client, gboolean client_set_keyboards (Client *client,
const gchar *keyboard); const gchar **keyboard);
gboolean client_enable_xkl (Client *client); gboolean client_enable_xkl (Client *client);
void client_disable_xkl (Client *client); void client_disable_xkl (Client *client);

View File

@ -62,6 +62,35 @@ set_rate (const GValue *value,
return g_variant_new_uint32 (msecs); return g_variant_new_uint32 (msecs);
} }
static gboolean
get_strv (GValue *value,
GVariant *variant,
gpointer user_data)
{
gchar *strv = g_variant_get_strv (variant, NULL);
gchar *text = g_strjoinv (", ", strv);
g_free (strv);
g_value_set_string (value, text);
return TRUE;
}
static GVariant *
set_strv (const GValue *value,
const GVariantType *expected_type,
gpointer user_data)
{
gchar *text = g_value_get_string (value);
gchar **strv = g_strsplit (text, ",", -1), **p;
GVariant *variant;
for (p = strv; *p != NULL; p++)
g_strstrip (*p);
variant = g_variant_new_strv (strv, -1);
g_strfreev (strv);
return variant;
}
PreferencesDialog * PreferencesDialog *
preferences_dialog_new (void) preferences_dialog_new (void)
{ {
@ -138,9 +167,10 @@ preferences_dialog_new (void)
gtk_builder_get_object (builder, "keyboard_entry"); gtk_builder_get_object (builder, "keyboard_entry");
dialog->keyboard_entry = GTK_WIDGET(object); dialog->keyboard_entry = GTK_WIDGET(object);
g_settings_bind (dialog->settings, "keyboard", g_settings_bind_with_mapping (dialog->settings, "keyboards",
GTK_ENTRY(dialog->keyboard_entry), "text", GTK_ENTRY(dialog->keyboard_entry), "text",
G_SETTINGS_BIND_DEFAULT); G_SETTINGS_BIND_DEFAULT,
get_strv, set_strv, NULL, NULL);
return dialog; return dialog;
} }