Change the type of gsettings key "keyboard" from s to as.
Also rename it to "keyboards".
This commit is contained in:
@ -1,10 +1,10 @@
|
||||
<?xml version="1.0"?>
|
||||
<schemalist>
|
||||
<schema id="org.fedorahosted.eekboard" path="/org/fedorahosted/eekboard/">
|
||||
<key name="keyboard" type="s">
|
||||
<default>'us'</default>
|
||||
<key name="keyboards" type="as">
|
||||
<default>['us']</default>
|
||||
<summary>Keyboard types</summary>
|
||||
<description>keyboard types (comma separated).</description>
|
||||
<description>keyboard types.</description>
|
||||
</key>
|
||||
<key name="ui-toolkit" type="s">
|
||||
<default>'gtk'</default>
|
||||
|
||||
@ -103,17 +103,19 @@ enum FocusListenerType {
|
||||
};
|
||||
|
||||
static gboolean
|
||||
set_keyboard (Client *client,
|
||||
const gchar *keyboard)
|
||||
set_keyboards (Client *client,
|
||||
gchar **keyboards)
|
||||
{
|
||||
if (g_strcmp0 (keyboard, "system") == 0) {
|
||||
if (g_strv_length (keyboards) == 0) {
|
||||
if (!client_enable_xkl (client)) {
|
||||
g_printerr ("Can't register xklavier event listeners\n");
|
||||
return FALSE;
|
||||
}
|
||||
} else {
|
||||
if (!client_set_keyboard (client, keyboard)) {
|
||||
g_printerr ("Can't set keyboard \"%s\"\n", keyboard);
|
||||
if (!client_set_keyboards (client, keyboards)) {
|
||||
gchar *str = g_strjoinv (", ", keyboards);
|
||||
g_printerr ("Can't set keyboards \"%s\"\n", str);
|
||||
g_free (str);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
@ -133,7 +135,7 @@ main (int argc, char **argv)
|
||||
GMainLoop *loop = NULL;
|
||||
gint focus;
|
||||
GSettings *settings = NULL;
|
||||
gchar *keyboard;
|
||||
gchar **keyboards;
|
||||
gint retval = 0;
|
||||
|
||||
if (!gtk_init_check (&argc, &argv)) {
|
||||
@ -312,13 +314,13 @@ main (int argc, char **argv)
|
||||
G_CALLBACK(on_destroyed), loop);
|
||||
g_object_unref (eekboard);
|
||||
|
||||
keyboard = g_settings_get_string (settings, "keyboard");
|
||||
if (!set_keyboard (client, keyboard)) {
|
||||
g_free (keyboard);
|
||||
keyboards = g_settings_get_strv (settings, "keyboards");
|
||||
if (!set_keyboards (client, keyboards)) {
|
||||
g_strfreev (keyboards);
|
||||
retval = 1;
|
||||
goto out;
|
||||
}
|
||||
g_free (keyboard);
|
||||
g_strfreev (keyboards);
|
||||
|
||||
g_main_loop_run (loop);
|
||||
|
||||
|
||||
58
src/client.c
58
src/client.c
@ -127,12 +127,13 @@ static void focus_listener_cb (const AtspiEvent *event,
|
||||
static gboolean keystroke_listener_cb (const AtspiDeviceEvent *stroke,
|
||||
void *user_data);
|
||||
#endif /* HAVE_ATSPI */
|
||||
static gboolean set_keyboard (Client *client,
|
||||
const gchar *keyboard);
|
||||
static gboolean set_keyboard_from_xkl (Client *client);
|
||||
static gboolean set_keyboards (Client *client,
|
||||
const gchar **keyboard);
|
||||
static gboolean set_keyboards_from_xkl
|
||||
(Client *client);
|
||||
#ifdef HAVE_XTEST
|
||||
static void update_modifier_keycodes
|
||||
(Client *client);
|
||||
(Client *client);
|
||||
#endif /* HAVE_XTEST */
|
||||
|
||||
static void
|
||||
@ -297,11 +298,11 @@ client_init (Client *client)
|
||||
}
|
||||
|
||||
gboolean
|
||||
client_set_keyboard (Client *client,
|
||||
const gchar *keyboard)
|
||||
client_set_keyboards (Client *client,
|
||||
const gchar **keyboards)
|
||||
{
|
||||
gboolean retval;
|
||||
retval = set_keyboard (client, keyboard);
|
||||
retval = set_keyboards (client, keyboards);
|
||||
if (retval && IS_KEYBOARD_VISIBLE (client))
|
||||
eekboard_context_show_keyboard (client->context, NULL);
|
||||
return retval;
|
||||
@ -343,7 +344,7 @@ client_enable_xkl (Client *client)
|
||||
|
||||
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))
|
||||
eekboard_context_show_keyboard (client->context, NULL);
|
||||
|
||||
@ -697,7 +698,7 @@ on_xkl_config_changed (XklEngine *xklengine,
|
||||
Client *client = user_data;
|
||||
gboolean retval;
|
||||
|
||||
retval = set_keyboard_from_xkl (client);
|
||||
retval = set_keyboards_from_xkl (client);
|
||||
g_return_if_fail (retval);
|
||||
|
||||
#ifdef HAVE_XTEST
|
||||
@ -706,46 +707,39 @@ on_xkl_config_changed (XklEngine *xklengine,
|
||||
}
|
||||
|
||||
static gboolean
|
||||
set_keyboard (Client *client,
|
||||
const gchar *keyboard)
|
||||
set_keyboards (Client *client,
|
||||
const gchar **keyboards)
|
||||
{
|
||||
GSList *keyboards = NULL;
|
||||
gchar **strv, **p;
|
||||
|
||||
g_return_val_if_fail (keyboard != NULL, FALSE);
|
||||
g_return_val_if_fail (*keyboard != '\0', FALSE);
|
||||
guint keyboard_id;
|
||||
gchar **p;
|
||||
GSList *head = NULL;
|
||||
|
||||
if (client->keyboards)
|
||||
g_slist_free (client->keyboards);
|
||||
|
||||
strv = g_strsplit (keyboard, ",", -1);
|
||||
for (p = strv; *p != NULL; p++) {
|
||||
guint keyboard_id;
|
||||
|
||||
keyboard_id = eekboard_context_add_keyboard (client->context,
|
||||
*p,
|
||||
NULL);
|
||||
if (keyboard_id == 0)
|
||||
for (p = keyboards; *p != NULL; p++) {
|
||||
keyboard_id = eekboard_context_add_keyboard (client->context, *p, NULL);
|
||||
if (keyboard_id == 0) {
|
||||
g_slist_free (head);
|
||||
return FALSE;
|
||||
keyboards = g_slist_prepend (keyboards,
|
||||
GUINT_TO_POINTER(keyboard_id));
|
||||
}
|
||||
head = g_slist_prepend (head, GUINT_TO_POINTER(keyboard_id));
|
||||
}
|
||||
g_strfreev (strv);
|
||||
|
||||
/* make a cycle */
|
||||
keyboards = g_slist_reverse (keyboards);
|
||||
g_slist_last (keyboards)->next = keyboards;
|
||||
client->keyboards = keyboards;
|
||||
head = g_slist_reverse (head);
|
||||
g_slist_last (head)->next = head;
|
||||
client->keyboards = head;
|
||||
|
||||
/* select the first keyboard */
|
||||
eekboard_context_set_keyboard (client->context,
|
||||
GPOINTER_TO_UINT(keyboards->data),
|
||||
GPOINTER_TO_UINT(head->data),
|
||||
NULL);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
set_keyboard_from_xkl (Client *client)
|
||||
set_keyboards_from_xkl (Client *client)
|
||||
{
|
||||
XklConfigRec *rec;
|
||||
gchar *layout, *keyboard;
|
||||
|
||||
@ -33,8 +33,8 @@ typedef struct _Client Client;
|
||||
|
||||
Client *client_new (GDBusConnection *connection);
|
||||
|
||||
gboolean client_set_keyboard (Client *client,
|
||||
const gchar *keyboard);
|
||||
gboolean client_set_keyboards (Client *client,
|
||||
const gchar **keyboard);
|
||||
|
||||
gboolean client_enable_xkl (Client *client);
|
||||
void client_disable_xkl (Client *client);
|
||||
|
||||
@ -62,6 +62,35 @@ set_rate (const GValue *value,
|
||||
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 *
|
||||
preferences_dialog_new (void)
|
||||
{
|
||||
@ -138,9 +167,10 @@ preferences_dialog_new (void)
|
||||
gtk_builder_get_object (builder, "keyboard_entry");
|
||||
dialog->keyboard_entry = GTK_WIDGET(object);
|
||||
|
||||
g_settings_bind (dialog->settings, "keyboard",
|
||||
GTK_ENTRY(dialog->keyboard_entry), "text",
|
||||
G_SETTINGS_BIND_DEFAULT);
|
||||
g_settings_bind_with_mapping (dialog->settings, "keyboards",
|
||||
GTK_ENTRY(dialog->keyboard_entry), "text",
|
||||
G_SETTINGS_BIND_DEFAULT,
|
||||
get_strv, set_strv, NULL, NULL);
|
||||
|
||||
return dialog;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user