Commit 401417c7 authored by Dorota Czaplejewicz's avatar Dorota Czaplejewicz
Browse files

Change basic layout based on gsettings input source

Added Polish text-input layout to be able to see the change. The new layout does not have a new key map.
parent da6ae011
......@@ -86,7 +86,7 @@ struct virtual_keyboard {
struct text_input_state pending;
struct text_input_state current;
char *preferred_language; // FIXME: fetch from system settings or take from user
char *preferred_layout;
uint32_t buttons_held;
};
......@@ -125,7 +125,6 @@ struct layout {
uint32_t rows;
const char *language;
uint32_t text_direction;
};
static const struct key normal_keys[] = {
......@@ -174,6 +173,52 @@ static const struct key normal_keys[] = {
{ keytype_ctrl, "Ctrl", "Ctrl", "Ctrl", 0, 2}
};
static const struct key polish_keys[] = {
{ keytype_default, "q", "Q", "1", KEY_Q, 1},
{ keytype_default, "w", "W", "2", KEY_W, 1},
{ keytype_default, "e", "E", "3", KEY_E, 1},
{ keytype_default, "r", "R", "4", KEY_R, 1},
{ keytype_default, "t", "T", "5", KEY_T, 1},
{ keytype_default, "y", "Y", "6", KEY_Y, 1},
{ keytype_default, "u", "U", "7", KEY_U, 1},
{ keytype_default, "i", "I", "8", KEY_I, 1},
{ keytype_default, "o", "O", "9", KEY_O, 1},
{ keytype_default, "p", "P", "0", KEY_P, 1},
{ keytype_backspace, "⌫", "⌫", "⌫", 0, 2},
{ keytype_tab, "⇥", "⇥", "⇥", 0, 1},
{ keytype_default, "a", "A", "-", KEY_A, 1},
{ keytype_default, "s", "S", "@", KEY_S, 1},
{ keytype_default, "d", "D", "*", KEY_D, 1},
{ keytype_default, "f", "F", "^", KEY_F, 1},
{ keytype_default, "g", "G", ":", KEY_G, 1},
{ keytype_default, "h", "H", ";", KEY_H, 1},
{ keytype_default, "j", "J", "(", KEY_J, 1},
{ keytype_default, "k", "K", ")", KEY_K, 1},
{ keytype_default, "l", "L", "~", KEY_L, 1},
{ keytype_enter, "↵", "↵", "↵", 0, 2},
{ keytype_caps, "ABC", "abc", "ABC", 0, 2},
{ keytype_default, "z", "Z", "/", KEY_Z, 1},
{ keytype_default, "x", "X", "\'", KEY_X, 1},
{ keytype_default, "c", "C", "\"", KEY_C, 1},
{ keytype_default, "v", "V", "+", KEY_V, 1},
{ keytype_default, "b", "B", "=", KEY_B, 1},
{ keytype_default, "n", "N", "?", KEY_N, 1},
{ keytype_default, "m", "M", "!", KEY_M, 1},
{ keytype_default, ",", ",", "\\", KEY_COMMA, 1},
{ keytype_default, ".", ".", "|", KEY_DOT, 1},
{ keytype_caps, "ABC", "abc", "ABC", 0, 1},
{ keytype_altgr, "?ąć", "?ąć", "abc", 0, 1},
{ keytype_space, "", "", "", 0, 5},
{ keytype_arrow_up, "↑", "↑", "↑", 0, 1},
{ keytype_arrow_left, "←", "←", "←", 0, 1},
{ keytype_arrow_right, "→", "→", "→", 0, 1},
{ keytype_arrow_down, "↓", "↓", "↓", 0, 1},
{ keytype_ctrl, "Ctrl", "Ctrl", "Ctrl", 0, 2}
};
static const struct key numeric_keys[] = {
{ keytype_default, "1", "1", "1", 0, 1},
{ keytype_default, "2", "2", "2", 0, 1},
......@@ -249,8 +294,7 @@ static const struct layout normal_layout = {
sizeof(normal_keys) / sizeof(*normal_keys),
12,
4,
"en",
0
"en"
};
static const struct layout numeric_layout = {
......@@ -258,8 +302,7 @@ static const struct layout numeric_layout = {
sizeof(numeric_keys) / sizeof(*numeric_keys),
12,
2,
"en",
0
"en"
};
static const struct layout arabic_layout = {
......@@ -267,8 +310,15 @@ static const struct layout arabic_layout = {
sizeof(arabic_keys) / sizeof(*arabic_keys),
13,
4,
"ar",
0
"ar"
};
static const struct layout polish_layout = {
polish_keys,
sizeof(polish_keys) / sizeof(*polish_keys),
12,
4,
"pl"
};
static const double key_width = 60;
......@@ -302,6 +352,7 @@ static const char* dbus_path_name = "/sm/puri/OSK0";
static GDBusProxy *_proxy;
static SmPuriOSK0 *dbus_interface = NULL;
static GSettings *settings = NULL;
static void __attribute__ ((format (printf, 1, 2)))
dbg(const char *fmt, ...)
......@@ -396,12 +447,16 @@ get_current_layout(struct virtual_keyboard *keyboard)
case ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_DIGITS:
case ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_NUMBER:
return &numeric_layout;
default:
if (keyboard->preferred_language &&
strcmp(keyboard->preferred_language, "ar") == 0)
default: // TODO: iterate over a layout table instead
if (!keyboard->preferred_layout) {
return &normal_layout;
} else if (strcmp(keyboard->preferred_layout, "ar") == 0) {
return &arabic_layout;
else
} else if (strcmp(keyboard->preferred_layout, "pl") == 0) {
return &polish_layout;
} else {
return &normal_layout;
}
}
}
......@@ -1285,6 +1340,62 @@ dbus_osk_setup(struct virtual_keyboard *virtual_keyboard)
return 0;
}
static void
settings_set_layout(struct virtual_keyboard *virtual_keyboard)
{
GVariant *inputs = g_settings_get_value(settings, "sources");
guint32 index;
g_settings_get(settings, "current", "u", &index);
GVariantIter *iter;
g_variant_get(inputs, "a(ss)", &iter);
g_autofree char *type, *layout;
bool found = false;
for (unsigned i = 0;
g_variant_iter_loop(iter, "(ss)", &type, &layout);
i++) {
if (i == index) {
dbg("Found layout %s %s\n", type, layout);
found = true;
break;
}
}
g_variant_iter_free(iter);
if (found) {
virtual_keyboard->preferred_layout = strdup(layout);
}
}
static gboolean
settings_handle_layout_changed(GSettings *s,
gpointer keys, gint n_keys,
gpointer user_data)
{
struct virtual_keyboard *keyboard = user_data;
settings_set_layout(keyboard);
if (!keyboard->keyboard->window) {
return TRUE;
}
struct size size = keyboard_get_size(keyboard->keyboard);
window_schedule_resize(keyboard->keyboard->window, size.width, size.height);
widget_schedule_redraw(keyboard->keyboard->widget);
return TRUE;
}
static int
settings_listen(struct virtual_keyboard *virtual_keyboard)
{
settings = g_settings_new("org.gnome.desktop.input-sources");
gulong conn_id = g_signal_connect(settings, "change-event",
G_CALLBACK(settings_handle_layout_changed),
virtual_keyboard) == 0;
settings_set_layout(virtual_keyboard);
return conn_id;
}
int
main(int argc, char *argv[])
{
......@@ -1335,11 +1446,16 @@ main(int argc, char *argv[])
return -1;
}
//keyboard_create(&virtual_keyboard);
session_register();
if (settings_listen(&virtual_keyboard) != 0) {
fprintf(stderr, "Could not connect to gsettings updates, layout"
" changing unavailable\n");
}
display_run(virtual_keyboard.display);
g_object_unref(settings);
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment