Commit cca2a858 authored by Guido Gunther's avatar Guido Gunther
Browse files

Merge branch 'gsettings' into 'master'

Gsettings controls keyboard layouts

Closes #7

See merge request !25
parents da6ae011 925c4f94
Pipeline #2223 passed with stage
in 52 seconds
......@@ -86,11 +86,21 @@ 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;
};
/// Modifiers passed to the virtual_keyboard protocol.
/// They are based on wayland's wl_keyboard, which doesn't document them.
enum key_modifier_type {
modifier_none = 0,
modifier_shift = 1,
modifier_capslock = 2,
modifier_ctrl = 4,
modifier_altgr = 128,
};
enum key_type {
keytype_default,
keytype_backspace,
......@@ -112,6 +122,7 @@ struct key {
char *label;
char *uppercase;
char *symbol;
char *symbol_upper;
unsigned keycode;
unsigned int width;
......@@ -121,163 +132,234 @@ struct layout {
const struct key *keys;
uint32_t count;
const char *keymap_str;
uint32_t columns;
uint32_t rows;
const char *language;
uint32_t text_direction;
bool has_symbol_upper;
};
static const struct key normal_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, "?123", "?123", "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}
{ keytype_default, "q", "Q", "1", NULL, KEY_Q, 1},
{ keytype_default, "w", "W", "2", NULL, KEY_W, 1},
{ keytype_default, "e", "E", "3", NULL, KEY_E, 1},
{ keytype_default, "r", "R", "4", NULL, KEY_R, 1},
{ keytype_default, "t", "T", "5", NULL, KEY_T, 1},
{ keytype_default, "y", "Y", "6", NULL, KEY_Y, 1},
{ keytype_default, "u", "U", "7", NULL, KEY_U, 1},
{ keytype_default, "i", "I", "8", NULL, KEY_I, 1},
{ keytype_default, "o", "O", "9", NULL, KEY_O, 1},
{ keytype_default, "p", "P", "0", NULL, KEY_P, 1},
{ keytype_backspace, "⌫", "⌫", "⌫", NULL, 0, 2},
{ keytype_tab, "⇥", "⇥", "⇥", NULL, 0, 1},
{ keytype_default, "a", "A", "-", NULL, KEY_A, 1},
{ keytype_default, "s", "S", "@", NULL, KEY_S, 1},
{ keytype_default, "d", "D", "*", NULL, KEY_D, 1},
{ keytype_default, "f", "F", "^", NULL, KEY_F, 1},
{ keytype_default, "g", "G", ":", NULL, KEY_G, 1},
{ keytype_default, "h", "H", ";", NULL, KEY_H, 1},
{ keytype_default, "j", "J", "(", NULL, KEY_J, 1},
{ keytype_default, "k", "K", ")", NULL, KEY_K, 1},
{ keytype_default, "l", "L", "~", NULL, KEY_L, 1},
{ keytype_enter, "↵", "↵", "↵", NULL, 0, 2},
{ keytype_caps, "ABC", "abc", "ABC", NULL, 0, 2},
{ keytype_default, "z", "Z", "/", NULL, KEY_Z, 1},
{ keytype_default, "x", "X", "\'", NULL, KEY_X, 1},
{ keytype_default, "c", "C", "\"", NULL, KEY_C, 1},
{ keytype_default, "v", "V", "+", NULL, KEY_V, 1},
{ keytype_default, "b", "B", "=", NULL, KEY_B, 1},
{ keytype_default, "n", "N", "?", NULL, KEY_N, 1},
{ keytype_default, "m", "M", "!", NULL, KEY_M, 1},
{ keytype_default, ",", ",", "\\", NULL, KEY_COMMA, 1},
{ keytype_default, ".", ".", "|", NULL, KEY_DOT, 1},
{ keytype_caps, "ABC", "abc", "ABC", NULL, 0, 1},
{ keytype_altgr, "?123", "?123", "abc", NULL, 0, 1},
{ keytype_space, "", "", "", NULL, 0, 5},
{ keytype_arrow_up, "↑", "↑", "↑", NULL, 0, 1},
{ keytype_arrow_left, "←", "←", "←", NULL, 0, 1},
{ keytype_arrow_right, "→", "→", "→", NULL, 0, 1},
{ keytype_arrow_down, "↓", "↓", "↓", NULL, 0, 1},
{ keytype_ctrl, "Ctrl", "Ctrl", "Ctrl", NULL, 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, "⌫", "⌫", "⌫", NULL, 0, 2},
{ keytype_tab, "⇥", "⇥", "⇥", NULL, 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, "↵", "↵", "↵", NULL, 0, 2},
{ keytype_caps, "ABC", "abc", "abc", NULL, 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", NULL, 0, 1},
{ keytype_altgr, "ą7?", "ą7?", "Ą%^", "ą7?", 0, 1},
{ keytype_space, "", "", "", NULL, 0, 5},
{ keytype_arrow_up, "↑", "↑", "↑", NULL, 0, 1},
{ keytype_arrow_left, "←", "←", "←", NULL, 0, 1},
{ keytype_arrow_right, "→", "→", "→", NULL, 0, 1},
{ keytype_arrow_down, "↓", "↓", "↓", NULL, 0, 1},
{ keytype_ctrl, "Ctrl", "Ctrl", "Ctrl", NULL, 0, 2}
};
static const struct key numeric_keys[] = {
{ keytype_default, "1", "1", "1", 0, 1},
{ keytype_default, "2", "2", "2", 0, 1},
{ keytype_default, "3", "3", "3", 0, 1},
{ keytype_default, "4", "4", "4", 0, 1},
{ keytype_default, "5", "5", "5", 0, 1},
{ keytype_default, "6", "6", "6", 0, 1},
{ keytype_default, "7", "7", "7", 0, 1},
{ keytype_default, "8", "8", "8", 0, 1},
{ keytype_default, "9", "9", "9", 0, 1},
{ keytype_default, "0", "0", "0", 0, 1},
{ keytype_backspace, "<--", "<--", "<--", 0, 2},
{ keytype_space, "", "", "", 0, 4},
{ keytype_enter, "Enter", "Enter", "Enter", 0, 2},
{ keytype_arrow_up, "/\\", "/\\", "/\\", 0, 1},
{ keytype_arrow_left, "<", "<", "<", 0, 1},
{ keytype_arrow_right, ">", ">", ">", 0, 1},
{ keytype_arrow_down, "\\/", "\\/", "\\/", 0, 1},
//{ keytype_style, "", "", "", 0, 2}
{ keytype_default, "1", "1", "1", NULL, 0, 1},
{ keytype_default, "2", "2", "2", NULL, 0, 1},
{ keytype_default, "3", "3", "3", NULL, 0, 1},
{ keytype_default, "4", "4", "4", NULL, 0, 1},
{ keytype_default, "5", "5", "5", NULL, 0, 1},
{ keytype_default, "6", "6", "6", NULL, 0, 1},
{ keytype_default, "7", "7", "7", NULL, 0, 1},
{ keytype_default, "8", "8", "8", NULL, 0, 1},
{ keytype_default, "9", "9", "9", NULL, 0, 1},
{ keytype_default, "0", "0", "0", NULL, 0, 1},
{ keytype_backspace, "<--", "<--", "<--", NULL, 0, 2},
{ keytype_space, "", "", "", NULL, 0, 4},
{ keytype_enter, "Enter", "Enter", "Enter", NULL, 0, 2},
{ keytype_arrow_up, "/\\", "/\\", "/\\", NULL, 0, 1},
{ keytype_arrow_left, "<", "<", "<", NULL, 0, 1},
{ keytype_arrow_right, ">", ">", ">", NULL, 0, 1},
{ keytype_arrow_down, "\\/", "\\/", "\\/", NULL, 0, 1},
};
static const struct key arabic_keys[] = {
{ keytype_default, "ض", "ﹶ", "۱",0, 1},
{ keytype_default, "ص", "ﹰ", "۲",0, 1},
{ keytype_default, "ث", "ﹸ", "۳",0, 1},
{ keytype_default, "ق", "ﹲ", "۴",0, 1},
{ keytype_default, "ف", "ﻹ", "۵",0, 1},
{ keytype_default, "غ", "ﺇ", "۶",0, 1},
{ keytype_default, "ع", "`", "۷",0, 1},
{ keytype_default, "ه", "٪", "۸",0, 1},
{ keytype_default, "خ", ">", "۹",0, 1},
{ keytype_default, "ح", "<", "۰",0, 1},
{ keytype_backspace, "-->", "-->", "-->", 0, 2},
{ keytype_tab, "->|", "->|", "->|", 0, 1},
{ keytype_default, "ش", "ﹺ", "ﹼ",0, 1},
{ keytype_default, "س", "ﹴ", "!",0, 1},
{ keytype_default, "ي", "[", "@",0, 1},
{ keytype_default, "ب", "]", "#",0, 1},
{ keytype_default, "ل", "ﻷ", "$",0, 1},
{ keytype_default, "ا", "أ", "%",0, 1},
{ keytype_default, "ت", "-", "^",0, 1},
{ keytype_default, "ن", "x", "&", 0, 1},
{ keytype_default, "م", "/", "*",0, 1},
{ keytype_default, "ك", ":", "_",0, 1},
{ keytype_default, "د", "\"", "+",0, 1},
{ keytype_enter, "Enter", "Enter", "Enter", 0, 2},
{ keytype_caps, "Shift", "Base", "Shift", 0, 2},
{ keytype_default, "ئ", "~", ")",0, 1},
{ keytype_default, "ء", "°", "(",0, 1},
{ keytype_default, "ؤ", "{", "\"",0, 1},
{ keytype_default, "ر", "}", "\'",0, 1},
{ keytype_default, "ى", "ﺁ", "؟",0, 1},
{ keytype_default, "ة", "'", "!",0, 1},
{ keytype_default, "و", ",", ";",0, 1},
{ keytype_default, "ﺯ", ".", "\\",0, 1},
{ keytype_default, "ظ", "؟", "=",0, 1},
{ keytype_caps, "Shift", "Base", "Shift", 0, 2},
{ keytype_altgr, "؟٣٢١", "؟٣٢١", "Base", 0, 1},
{ keytype_default, "ﻻ", "ﻵ", "|",0, 1},
{ keytype_default, ",", "،", "،", 0, 1},
{ keytype_space, "", "", "", 0, 6},
{ keytype_default, ".", "ذ", "]",0, 1},
{ keytype_default, "ط", "ﺝ", "[",0, 1},
//{ keytype_style, "", "", "", 0, 2}
{ keytype_default, "ض", "ﹶ", "۱", NULL, 0, 1},
{ keytype_default, "ص", "ﹰ", "۲", NULL, 0, 1},
{ keytype_default, "ث", "ﹸ", "۳", NULL, 0, 1},
{ keytype_default, "ق", "ﹲ", "۴", NULL, 0, 1},
{ keytype_default, "ف", "ﻹ", "۵", NULL, 0, 1},
{ keytype_default, "غ", "ﺇ", "۶", NULL, 0, 1},
{ keytype_default, "ع", "`", "۷", NULL, 0, 1},
{ keytype_default, "ه", "٪", "۸", NULL, 0, 1},
{ keytype_default, "خ", ">", "۹", NULL, 0, 1},
{ keytype_default, "ح", "<", "۰", NULL, 0, 1},
{ keytype_backspace, "-->", "-->", "-->", NULL, 0, 2},
{ keytype_tab, "->|", "->|", "->|", NULL, 0, 1},
{ keytype_default, "ش", "ﹺ", "ﹼ", NULL, 0, 1},
{ keytype_default, "س", "ﹴ", "!", NULL, 0, 1},
{ keytype_default, "ي", "[", "@", NULL, 0, 1},
{ keytype_default, "ب", "]", "#", NULL, 0, 1},
{ keytype_default, "ل", "ﻷ", "$", NULL, 0, 1},
{ keytype_default, "ا", "أ", "%", NULL, 0, 1},
{ keytype_default, "ت", "-", "^", NULL, 0, 1},
{ keytype_default, "ن", "x", "&", NULL, 0, 1},
{ keytype_default, "م", "/", "*", NULL, 0, 1},
{ keytype_default, "ك", ":", "_", NULL, 0, 1},
{ keytype_default, "د", "\"", "+", NULL, 0, 1},
{ keytype_enter, "Enter", "Enter", "Enter", NULL, 0, 2},
{ keytype_caps, "Shift", "Base", "Shift", NULL, 0, 2},
{ keytype_default, "ئ", "~", ")", NULL, 0, 1},
{ keytype_default, "ء", "°", "(", NULL, 0, 1},
{ keytype_default, "ؤ", "{", "\"", NULL, 0, 1},
{ keytype_default, "ر", "}", "\'", NULL, 0, 1},
{ keytype_default, "ى", "ﺁ", "؟", NULL, 0, 1},
{ keytype_default, "ة", "'", "!", NULL, 0, 1},
{ keytype_default, "و", ",", ";", NULL, 0, 1},
{ keytype_default, "ﺯ", ".", "\\", NULL, 0, 1},
{ keytype_default, "ظ", "؟", "=", NULL, 0, 1},
{ keytype_caps, "Shift", "Base", "Shift", NULL, 0, 2},
{ keytype_altgr, "؟٣٢١", "؟٣٢١", "Base", NULL, 0, 1},
{ keytype_default, "ﻻ", "ﻵ", "|", NULL, 0, 1},
{ keytype_default, ",", "،", "،", NULL, 0, 1},
{ keytype_space, "", "", "", NULL, 0, 6},
{ keytype_default, ".", "ذ", "]", NULL, 0, 1},
{ keytype_default, "ط", "ﺝ", "[", NULL, 0, 1},
};
static const struct layout normal_layout = {
normal_keys,
sizeof(normal_keys) / sizeof(*normal_keys),
keymap_normal,
12,
4,
"en",
0
false,
};
static const struct layout numeric_layout = {
numeric_keys,
sizeof(numeric_keys) / sizeof(*numeric_keys),
NULL,
12,
2,
"en",
0
false,
};
static const struct layout arabic_layout = {
arabic_keys,
sizeof(arabic_keys) / sizeof(*arabic_keys),
NULL,
13,
4,
"ar",
0
false,
};
static const struct layout polish_layout = {
polish_keys,
sizeof(polish_keys) / sizeof(*polish_keys),
keymap_polish,
12,
4,
"pl",
true,
};
static const struct layout* layouts[] = {
&normal_layout,
&polish_layout,
&arabic_layout,
};
static const unsigned layouts_count = sizeof(layouts) / sizeof (*layouts);
static const char* default_keymap_str = keymap_normal;
static const double key_width = 60;
static const double key_height = 50;
enum keyboard_state {
KEYBOARD_STATE_DEFAULT,
KEYBOARD_STATE_UPPERCASE,
KEYBOARD_STATE_SYMBOLS
KEYBOARD_STATE_SYMBOLS,
KEYBOARD_STATE_SYMBOLS_UPPER,
};
struct keyboard {
......@@ -302,6 +384,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, ...)
......@@ -335,8 +418,10 @@ label_from_key(struct keyboard *keyboard,
return key->uppercase;
case KEYBOARD_STATE_SYMBOLS:
return key->symbol;
case KEYBOARD_STATE_SYMBOLS_UPPER:
return key->symbol_upper ? key->symbol_upper : key->symbol;
default:
return "";
dbg("Keyboard state invalid\n");
}
return "";
......@@ -396,12 +481,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;
}
}
}
......@@ -585,17 +674,19 @@ append(char *s1, const char *s2)
}
static void keyboard_update_mods(struct keyboard *keyboard) {
unsigned mods = keyboard->ctrl_on << 2;
unsigned mods = keyboard->ctrl_on ? modifier_ctrl : modifier_none;
unsigned locked = 0;
switch(keyboard->state) {
case KEYBOARD_STATE_DEFAULT:
break;
case KEYBOARD_STATE_UPPERCASE:
locked |= 2;
locked |= modifier_capslock;
break;
case KEYBOARD_STATE_SYMBOLS:
mods |= 128;
mods |= modifier_altgr;
break;
case KEYBOARD_STATE_SYMBOLS_UPPER:
mods |= modifier_altgr | modifier_shift;
default:
break;
}
......@@ -604,23 +695,12 @@ static void keyboard_update_mods(struct keyboard *keyboard) {
}
static void
keyboard_handle_key(struct keyboard *keyboard, uint32_t time, const struct key *key, struct input *input, enum wl_pointer_button_state state)
keyboard_handle_key(struct keyboard *keyboard, const struct layout *layout,
uint32_t time, const struct key *key,
struct input *input,
enum wl_pointer_button_state state)
{
const char *label = NULL;
switch(keyboard->state) {
case KEYBOARD_STATE_DEFAULT :
label = key->label;
break;
case KEYBOARD_STATE_UPPERCASE :
label = key->uppercase;
break;
case KEYBOARD_STATE_SYMBOLS :
label = key->symbol;
break;
default:
dbg("Keyboard state invalid\n");
}
const char *label = label_from_key(keyboard, key);
uint32_t key_state = (state == WL_POINTER_BUTTON_STATE_PRESSED) ? WL_KEYBOARD_KEY_STATE_PRESSED : WL_KEYBOARD_KEY_STATE_RELEASED;
......@@ -700,6 +780,9 @@ keyboard_handle_key(struct keyboard *keyboard, uint32_t time, const struct key *
case KEYBOARD_STATE_SYMBOLS:
keyboard->state = KEYBOARD_STATE_UPPERCASE;
break;
case KEYBOARD_STATE_SYMBOLS_UPPER:
keyboard->state = KEYBOARD_STATE_DEFAULT;
break;
default:
dbg("Keyboard state invalid\n");
}
......@@ -716,7 +799,14 @@ keyboard_handle_key(struct keyboard *keyboard, uint32_t time, const struct key *
keyboard->state = KEYBOARD_STATE_SYMBOLS;
break;
case KEYBOARD_STATE_SYMBOLS:
keyboard->state = KEYBOARD_STATE_DEFAULT;
if (layout->has_symbol_upper) {
keyboard->state = KEYBOARD_STATE_SYMBOLS_UPPER;
} else {
keyboard->state = KEYBOARD_STATE_DEFAULT;
}
break;
case KEYBOARD_STATE_SYMBOLS_UPPER:
keyboard->state = KEYBOARD_STATE_SYMBOLS;
break;
default:
dbg("Keyboard state invalid\n");
......@@ -775,21 +865,36 @@ keyboard_handle_key(struct keyboard *keyboard, uint32_t time, const struct key *
}
}
static void
make_virtual_keyboard(struct virtual_keyboard *virtual_keyboard) {
struct zwp_virtual_keyboard_v1 *vkeyboard;
vkeyboard = zwp_virtual_keyboard_manager_v1_create_virtual_keyboard(
virtual_keyboard->keyboard_manager,
virtual_keyboard->seat);
const char *keymap_str = keymap_data;
static int
update_keymap(struct virtual_keyboard *virtual_keyboard)
{
const char *keymap_str = default_keymap_str;
for (unsigned i = 0; i < layouts_count; i++) {
if (strcmp(layouts[i]->language,
virtual_keyboard->preferred_layout) == 0) {
keymap_str = layouts[i]->keymap_str;
break;
}
}
#ifdef KEYMAP_FILE
// Testing only
char fname[80];
snprintf(fname, 79, "./keymap_%s",
virtual_keyboard->preferred_layout
? virtual_keyboard->preferred_layout : "en");
int ffd;
struct stat sb;
ffd = open("./keymap", O_RDONLY);
ffd = open(fname, O_RDONLY);
if (ffd < 0) {
return -1;
}
fstat(ffd, &sb);
keymap_str = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, ffd, 0);
if (!keymap_str) {
close(ffd);
return -1;
}
#endif
size_t keymap_size = strlen(keymap_str) + 1;
......@@ -797,20 +902,31 @@ make_virtual_keyboard(struct virtual_keyboard *virtual_keyboard) {
if (keymap_fd < 0) {
goto err;
}
// TODO: save those inside layouts
void *ptr = mmap(NULL, keymap_size, PROT_READ | PROT_WRITE, MAP_SHARED,
keymap_fd, 0);
if (ptr == (void*)-1) {
goto err2;
}
strcpy(ptr, keymap_str);
zwp_virtual_keyboard_v1_keymap(vkeyboard, WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1,
keymap_fd, keymap_size);
virtual_keyboard->virtual_keyboard = vkeyboard;
return;
zwp_virtual_keyboard_v1_keymap(virtual_keyboard->virtual_keyboard,
WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1,
keymap_fd, keymap_size);
return 0;
err2:
close(keymap_fd);
err:
return;
return 1;
}
static void
make_virtual_keyboard(struct virtual_keyboard *virtual_keyboard)
{
struct zwp_virtual_keyboard_v1 *vkeyboard;
vkeyboard = zwp_virtual_keyboard_manager_v1_create_virtual_keyboard(
virtual_keyboard->keyboard_manager,
virtual_keyboard->seat);
virtual_keyboard->virtual_keyboard = vkeyboard;
}
......@@ -848,7 +964,10 @@ button_handler(struct widget *widget, struct input *input, uint32_t time,
for (i = 0; i < layout->count; ++i) {
col -= layout->keys[i].width;
if (col < 0) {
keyboard_handle_key(keyboard, time, &layout->keys[i], input, state);
keyboard_handle_key(keyboard, layout,
time, &layout->keys[i],
input,
state);
break;
}
}
......@@ -885,8 +1004,10 @@ touch_handler(struct input *input, uint32_t time,
for (i = 0; i < layout->count; ++i) {
col -= layout->keys[i].width;
if (col < 0) {
keyboard_handle_key(keyboard, time,