diff --git a/data/keyboards/geometry/compact.xml b/data/keyboards/geometry/compact.xml index 128e047c..d2ef4914 100644 --- a/data/keyboards/geometry/compact.xml +++ b/data/keyboards/geometry/compact.xml @@ -44,9 +44,9 @@
- + - +
diff --git a/data/keyboards/geometry/extended.xml b/data/keyboards/geometry/extended.xml new file mode 100644 index 00000000..f855cebc --- /dev/null +++ b/data/keyboards/geometry/extended.xml @@ -0,0 +1,126 @@ + + + + +
+ + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + +
+
+ + + + + + + + + + + +
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/data/keyboards/keyboards.xml b/data/keyboards/keyboards.xml index 8b71cb48..87ad1843 100644 --- a/data/keyboards/keyboards.xml +++ b/data/keyboards/keyboards.xml @@ -24,6 +24,9 @@ + diff --git a/data/keyboards/keymaps/nb.xkb b/data/keyboards/keymaps/nb.xkb new file mode 100644 index 00000000..26036f89 --- /dev/null +++ b/data/keyboards/keymaps/nb.xkb @@ -0,0 +1,308 @@ +xkb_keymap { + + xkb_keycodes "squeekboard" { + minimum = 8; + maximum = 255; + = 9; + = 10; + = 11; + = 12; + = 13; + = 14; + = 15; + = 16; + = 17; + = 18; + = 19; + = 20; + = 21; + = 22; + = 23; + = 24; + = 25; + = 26; + = 27; + = 28; + = 29; + = 30; + = 31; + = 32; + = 33; + = 34; + = 35; + = 36; + = 37; + = 38; + = 39; + = 40; + = 41; + = 42; + = 43; + = 44; + = 45; + = 46; + = 47; + = 48; + = 49; + = 50; + = 51; + = 52; + = 53; + = 54; + = 55; + = 56; + = 57; + = 58; + = 59; + = 60; + = 61; + = 62; + = 63; + = 64; + = 65; + = 66; + = 67; + = 68; + = 69; + = 70; + = 71; + = 72; + = 73; + = 74; + = 75; + = 76; + = 77; + = 78; + = 79; + = 80; + = 81; + = 82; + = 83; + = 84; + = 85; + = 86; + = 87; + = 88; + = 89; + = 90; + = 91; + = 92; + = 94; + = 95; + = 96; + = 97; + = 98; + = 99; + = 100; + = 101; + = 102; + = 103; + = 104; + = 105; + = 106; + = 107; + = 108; + = 109; + = 110; + = 111; + = 112; + = 113; + = 114; + = 115; + = 116; + = 117; + = 118; + = 119; + = 120; + = 121; + = 122; + = 123; + = 124; + = 125; + = 126; + = 127; + = 128; + = 129; + = 130; + = 131; + = 132; + = 133; + = 134; + = 135; + = 136; + = 137; + = 138; + = 139; + = 140; + = 141; + = 142; + = 143; + = 144; + = 145; + = 146; + = 147; + = 148; + = 149; + = 150; + = 151; + = 152; + = 153; + = 154; + = 155; + = 156; + = 157; + = 158; + = 159; + = 160; + = 161; + = 162; + = 163; + = 164; + = 165; + = 166; + = 167; + = 168; + = 169; + = 170; + = 171; + = 172; + = 173; + = 174; + = 175; + = 176; + = 177; + = 178; + = 179; + = 180; + = 181; + = 182; + = 183; + = 184; + = 185; + = 186; + = 187; + = 188; + = 189; + = 190; + = 191; + = 192; + = 193; + = 194; + = 195; + = 196; + = 197; + = 198; + = 199; + = 200; + = 201; + = 202; + = 203; + = 204; + = 205; + = 206; + = 207; + = 208; + = 209; + = 210; + = 211; + = 212; + = 213; + = 214; + = 215; + = 216; + = 217; + = 218; + = 219; + = 220; + = 221; + = 222; + = 223; + = 224; + = 225; + = 226; + = 227; + = 228; + = 229; + = 230; + = 231; + = 232; + = 233; + = 234; + = 235; + = 236; + = 237; + = 238; + = 239; + = 240; + = 241; + = 242; + = 243; + = 244; + = 245; + = 246; + = 247; + = 248; + = 249; + = 250; + = 251; + = 252; + = 253; + = 254; + = 255; + }; + + xkb_symbols "squeekboard" { + + name[Group1] = "Letters"; + name[Group2] = "Numbers/Symbols"; + + key { [ q, Q ], [ 1, asciitilde ] }; + key { [ w, W ], [ 2, quoteleft ] }; + key { [ e, E ], [ 3, bar ] }; + key { [ r, R ], [ 4, U00B7 ] }; + key { [ t, T ], [ 5, squareroot ] }; + key { [ y, Y ], [ 6, Greek_pi ] }; + key { [ u, U ], [ 7, division ] }; + key { [ i, I ], [ 8, multiply ] }; + key { [ o, O ], [ 9, paragraph ] }; + key { [ p, P ], [ 0, U25B3 ] }; + key { [ aring, Aring ], [ U00B1, U00A7 ] }; + key { [ a, A ], [ at, copyright ] }; + key { [ s, S ], [ numbersign, U00AE ] }; + key { [ d, D ], [ dollar, U00A3 ] }; + key { [ f, F ], [ percent, EuroSign ] }; + key { [ g, G ], [ ampersand, U00A5 ] }; + key { [ h, H ], [ minus, underscore ] }; + key { [ j, J ], [ plus, equal ] }; + key { [ k, K ], [ U00FC, asciicircum ] }; + key { [ l, L ], [ U00F6, degree ] }; + key { [ oslash, Oslash ], [ parenleft, braceleft ] }; + key { [ ae, AE ], [ parenright, braceright ] }; + key { [ Return, Return ], [ Return, Return ] }; + key { [ Shift_L, Shift_L ], [ Shift_L, Shift_L ] }; + key { [ z, Z ], [ comma, backslash ] }; + key { [ x, X ], [ quotedbl, slash ] }; + key { [ c, C ], [ quoteright, less ] }; + key { [ v, V ], [ colon, greater ] }; + key { [ b, B ], [ semicolon, equal ] }; + key { [ n, N ], [ exclam, bracketleft ] }; + key { [ m, M ], [ question, bracketright ] }; + key { [ period, period ], [ period, period ] }; + key { [ preferences, preferences ], [ preferences, preferences ] }; + key { [ space, space ], [ space, space ] }; + key { [ BackSpace, BackSpace ], [ BackSpace, BackSpace ] }; + }; + + xkb_types "squeekboard" { + + type "TWO_LEVEL" { + modifiers = Shift; + map[Shift] = Level2; + level_name[Level1] = "Base"; + level_name[Level2] = "Shift"; + }; + }; + + xkb_compatibility "squeekboard" { + }; +}; diff --git a/data/keyboards/keymaps/us.xkb b/data/keyboards/keymaps/us.xkb new file mode 100644 index 00000000..44efcbb7 --- /dev/null +++ b/data/keyboards/keymaps/us.xkb @@ -0,0 +1,305 @@ +xkb_keymap { + + xkb_keycodes "squeekboard" { + minimum = 8; + maximum = 255; + = 9; + = 10; + = 11; + = 12; + = 13; + = 14; + = 15; + = 16; + = 17; + = 18; + = 19; + = 20; + = 21; + = 22; + = 23; + = 24; + = 25; + = 26; + = 27; + = 28; + = 29; + = 30; + = 31; + = 32; + = 33; + = 34; + = 35; + = 36; + = 37; + = 38; + = 39; + = 40; + = 41; + = 42; + = 43; + = 44; + = 45; + = 46; + = 47; + = 48; + = 49; + = 50; + = 51; + = 52; + = 53; + = 54; + = 55; + = 56; + = 57; + = 58; + = 59; + = 60; + = 61; + = 62; + = 63; + = 64; + = 65; + = 66; + = 67; + = 68; + = 69; + = 70; + = 71; + = 72; + = 73; + = 74; + = 75; + = 76; + = 77; + = 78; + = 79; + = 80; + = 81; + = 82; + = 83; + = 84; + = 85; + = 86; + = 87; + = 88; + = 89; + = 90; + = 91; + = 92; + = 94; + = 95; + = 96; + = 97; + = 98; + = 99; + = 100; + = 101; + = 102; + = 103; + = 104; + = 105; + = 106; + = 107; + = 108; + = 109; + = 110; + = 111; + = 112; + = 113; + = 114; + = 115; + = 116; + = 117; + = 118; + = 119; + = 120; + = 121; + = 122; + = 123; + = 124; + = 125; + = 126; + = 127; + = 128; + = 129; + = 130; + = 131; + = 132; + = 133; + = 134; + = 135; + = 136; + = 137; + = 138; + = 139; + = 140; + = 141; + = 142; + = 143; + = 144; + = 145; + = 146; + = 147; + = 148; + = 149; + = 150; + = 151; + = 152; + = 153; + = 154; + = 155; + = 156; + = 157; + = 158; + = 159; + = 160; + = 161; + = 162; + = 163; + = 164; + = 165; + = 166; + = 167; + = 168; + = 169; + = 170; + = 171; + = 172; + = 173; + = 174; + = 175; + = 176; + = 177; + = 178; + = 179; + = 180; + = 181; + = 182; + = 183; + = 184; + = 185; + = 186; + = 187; + = 188; + = 189; + = 190; + = 191; + = 192; + = 193; + = 194; + = 195; + = 196; + = 197; + = 198; + = 199; + = 200; + = 201; + = 202; + = 203; + = 204; + = 205; + = 206; + = 207; + = 208; + = 209; + = 210; + = 211; + = 212; + = 213; + = 214; + = 215; + = 216; + = 217; + = 218; + = 219; + = 220; + = 221; + = 222; + = 223; + = 224; + = 225; + = 226; + = 227; + = 228; + = 229; + = 230; + = 231; + = 232; + = 233; + = 234; + = 235; + = 236; + = 237; + = 238; + = 239; + = 240; + = 241; + = 242; + = 243; + = 244; + = 245; + = 246; + = 247; + = 248; + = 249; + = 250; + = 251; + = 252; + = 253; + = 254; + = 255; + }; + + xkb_symbols "squeekboard" { + + name[Group1] = "Letters"; + name[Group2] = "Numbers/Symbols"; + + key { [ q, Q ], [ 1, asciitilde ] }; + key { [ w, W ], [ 2, quoteleft ] }; + key { [ e, E ], [ 3, bar ] }; + key { [ r, R ], [ 4, U00B7 ] }; + key { [ t, T ], [ 5, squareroot ] }; + key { [ y, Y ], [ 6, Greek_pi ] }; + key { [ u, U ], [ 7, division ] }; + key { [ i, I ], [ 8, multiply ] }; + key { [ o, O ], [ 9, paragraph ] }; + key { [ p, P ], [ 0, U25B3 ] }; + key { [ a, A ], [ at, copyright ] }; + key { [ s, S ], [ numbersign, U00AE ] }; + key { [ d, D ], [ dollar, U00A3 ] }; + key { [ f, F ], [ percent, EuroSign ] }; + key { [ g, G ], [ ampersand, U00A5 ] }; + key { [ h, H ], [ minus, underscore ] }; + key { [ j, J ], [ plus, equal ] }; + key { [ k, K ], [ U00FC, asciicircum ] }; + key { [ l, L ], [ U00F6, degree ] }; + key { [ Return, Return ], [ Return, Return ] }; + key { [ Shift_L, Shift_L ], [ Shift_L, Shift_L ] }; + key { [ z, Z ], [ comma, backslash ] }; + key { [ x, X ], [ quotedbl, slash ] }; + key { [ c, C ], [ quoteright, less ] }; + key { [ v, V ], [ colon, greater ] }; + key { [ b, B ], [ semicolon, equal ] }; + key { [ n, N ], [ exclam, bracketleft ] }; + key { [ m, M ], [ question, bracketright ] }; + key { [ period, period ], [ period, period ] }; + key { [ preferences, preferences ], [ preferences, preferences ] }; + key { [ space, space ], [ space, space ] }; + key { [ BackSpace, BackSpace ], [ BackSpace, BackSpace ] }; + }; + + xkb_types "squeekboard" { + + type "TWO_LEVEL" { + modifiers = Shift; + map[Shift] = Level2; + level_name[Level1] = "Base"; + level_name[Level2] = "Shift"; + }; + }; + + xkb_compatibility "squeekboard" { + }; +}; diff --git a/data/keyboards/symbols/nb.xml b/data/keyboards/symbols/nb.xml new file mode 100644 index 00000000..00a2ca3e --- /dev/null +++ b/data/keyboards/symbols/nb.xml @@ -0,0 +1,204 @@ + + + + q + Q + 1 + asciitilde + + + w + W + 2 + quoteleft + + + e + E + 3 + bar + + + r + R + 4 + U00B7 + + + t + T + 5 + squareroot + + + y + Y + 6 + Greek_pi + + + u + U + 7 + division + + + i + I + 8 + multiply + + + o + O + 9 + paragraph + + + p + P + 0 + U25B3 + + + aring + Aring + U00B1 + U00A7 + + + a + A + at + copyright + + + s + S + numbersign + U00AE + + + d + D + dollar + U00A3 + + + f + F + percent + EuroSign + + + g + G + ampersand + U00A5 + + + h + H + minus + underscore + + + j + J + plus + equal + + + k + K + U00FC + asciicircum + + + l + L + U00F6 + degree + + + oslash + Oslash + parenleft + braceleft + + + ae + AE + parenright + braceright + + + Return + + + Shift_L + Shift_L + Shift_L + Shift_L + + + z + Z + comma + backslash + + + x + X + quotedbl + slash + + + c + C + quoteright + less + + + v + V + colon + greater + + + b + B + semicolon + equal + + + n + N + exclam + bracketleft + + + m + M + question + bracketright + + + period + + + show-numbers + show-numbers + show-letters + show-letters + + + preferences + + + space + + + BackSpace + + diff --git a/data/keyboards/symbols/us.xml b/data/keyboards/symbols/us.xml index db6ef5f1..047e968d 100644 --- a/data/keyboards/symbols/us.xml +++ b/data/keyboards/symbols/us.xml @@ -1,276 +1,186 @@ - + - - Escape + + q + Q + 1 + asciitilde - - F1 + + w + W + 2 + quoteleft - - F2 + + e + E + 3 + bar - - F3 + + r + R + 4 + U00B7 - - F4 + + t + T + 5 + squareroot - - F5 + + y + Y + 6 + Greek_pi - - F6 + + u + U + 7 + division - - F7 + + i + I + 8 + multiply - - F8 + + o + O + 9 + paragraph - - F9 + + p + P + 0 + U25B3 - - F10 + + a + A + at + copyright - - F11 + + s + S + numbersign + U00AE - - F12 + + d + D + dollar + U00A3 - - backspace + + f + F + percent + EuroSign - - Tab - ISO_Left_Tab + + g + G + ampersand + U00A5 - - q - Q - 1 - asciitilde + + h + H + minus + underscore - - w - W - 2 - quoteleft + + j + J + plus + equal - - e - E - 3 - bar + + k + K + parenleft + braceleft - - r - R - 4 - middledot + + l + L + parenright + braceright - - t - T - 5 + + Return - - y - Y - 6 - - - u - U - 7 - - - i - I - 8 - - - o - O - 9 - - - p - P - 0 - - - bracketleft - braceleft - - - bracketright - braceright - - - backslash - bar - - - show-numbers - show-numbers - show-letters - show-letters - - - a - A - at - copyright - - - s - S - numbersign - registeredtrademark - - - d - D - dollar - poundsign - - - f - F - percent - - - - g - G - ampersand - yensign - - - h - H - minus - asciicircum - - - j - J - plus - degreesign - - - k - K - parenleft - braceleft - - - l - L - parenright - braceright - - - semicolon - colon - - - quoteright - quotedbl - - - Return - - + Shift_L Shift_L Shift_L Shift_L - - z - Z - comma - backslash + + z + Z + comma + backslash - - x - X - quotedbl - slash + + x + X + quotedbl + slash - - c - C - quoteright - less + + c + C + quoteright + less - - v - V - colon - greater + + v + V + colon + greater - - b - B - semicolon - equal + + b + B + semicolon + equal - - n - N - exclam - bracketleft + + n + N + exclam + bracketleft - - m - M - question - bracketright + + m + M + question + bracketright - - comma - less + + period - - period + + show-numbers + show-numbers + show-letters + show-letters - - slash - question + + preferences - - Shift_R + + space - - cycle-keyboard - - - preferences - - - Control_L - - - Alt_L - Meta_L - - - space - - - Left - - - Up - - - Down - - - Right + + backspace diff --git a/data/squeekboard.gresources.xml b/data/squeekboard.gresources.xml index 673c1033..b53dc6a1 100644 --- a/data/squeekboard.gresources.xml +++ b/data/squeekboard.gresources.xml @@ -3,7 +3,10 @@ style.css keyboards/geometry/compact.xml + keyboards/geometry/extended.xml keyboards/keyboards.xml + keyboards/keymaps/nb.xkb + keyboards/keymaps/us.xkb keyboards/symbols/ar.xml keyboards/symbols/as-inscript.xml keyboards/symbols/be.xml @@ -21,6 +24,7 @@ keyboards/symbols/ml-inscript.xml keyboards/symbols/mr-inscript.xml keyboards/symbols/my.xml + keyboards/symbols/nb.xml keyboards/symbols/or-inscript.xml keyboards/symbols/pa-inscript.xml keyboards/symbols/ru.xml diff --git a/eek/eek-keyboard.c b/eek/eek-keyboard.c index cded9354..8782dc5c 100644 --- a/eek/eek-keyboard.c +++ b/eek/eek-keyboard.c @@ -72,7 +72,7 @@ struct _EekKeyboardPrivate GList *pressed_keys; GList *locked_keys; GArray *outline_array; - GHashTable *keycodes; + GHashTable *names; /* modifiers dynamically assigned at run time */ EekModifierType num_lock_mask; @@ -127,9 +127,9 @@ section_child_added_cb (EekContainer *container, EekElement *element, EekKeyboard *keyboard) { - guint keycode = eek_key_get_keycode (EEK_KEY(element)); - g_hash_table_insert (keyboard->priv->keycodes, - GUINT_TO_POINTER(keycode), + const gchar *name = eek_element_get_name(element); + g_hash_table_insert (keyboard->priv->names, + (gpointer)name, element); } @@ -138,9 +138,9 @@ section_child_removed_cb (EekContainer *container, EekElement *element, EekKeyboard *keyboard) { - guint keycode = eek_key_get_keycode (EEK_KEY(element)); - g_hash_table_remove (keyboard->priv->keycodes, - GUINT_TO_POINTER(keycode)); + const gchar *name = eek_element_get_name(element); + g_hash_table_remove (keyboard->priv->names, + name); } static EekSection * @@ -219,7 +219,7 @@ set_level_from_modifiers (EekKeyboard *self, EekKey *key) gint level = priv->old_level & 2; /* Handle non-emitting keys */ - if (key && (eek_key_get_keycode(key) == 0)) { + if (key) { const gchar *name = eek_element_get_name(EEK_ELEMENT(key)); if (g_strcmp0(name, "ABC123") == 0) level ^= 2; @@ -400,7 +400,7 @@ eek_keyboard_finalize (GObject *object) g_list_free_full (priv->locked_keys, (GDestroyNotify) eek_modifier_key_free); - g_hash_table_destroy (priv->keycodes); + g_hash_table_destroy (priv->names); for (i = 0; i < priv->outline_array->len; i++) { EekOutline *outline = &g_array_index (priv->outline_array, @@ -528,7 +528,7 @@ eek_keyboard_init (EekKeyboard *self) self->priv = EEK_KEYBOARD_GET_PRIVATE(self); self->priv->modifier_behavior = EEK_MODIFIER_BEHAVIOR_NONE; self->priv->outline_array = g_array_new (FALSE, TRUE, sizeof (EekOutline)); - self->priv->keycodes = g_hash_table_new (g_direct_hash, g_direct_equal); + self->priv->names = g_hash_table_new (g_str_hash, g_str_equal); eek_element_set_symbol_index (EEK_ELEMENT(self), 0, 0); self->scale = 1.0; } @@ -549,20 +549,20 @@ eek_keyboard_create_section (EekKeyboard *keyboard) } /** - * eek_keyboard_find_key_by_keycode: + * eek_keyboard_find_key_by_name: * @keyboard: an #EekKeyboard - * @keycode: a keycode + * @name: a key name * - * Find an #EekKey whose keycode is @keycode. - * Return value: (transfer none): #EekKey whose keycode is @keycode + * Find an #EekKey whose name is @name. + * Return value: (transfer none): #EekKey whose name is @name */ EekKey * -eek_keyboard_find_key_by_keycode (EekKeyboard *keyboard, - guint keycode) +eek_keyboard_find_key_by_name (EekKeyboard *keyboard, + const gchar *name) { g_return_val_if_fail (EEK_IS_KEYBOARD(keyboard), NULL); - return g_hash_table_lookup (keyboard->priv->keycodes, - GUINT_TO_POINTER(keycode)); + return g_hash_table_lookup (keyboard->priv->names, + name); } /** diff --git a/eek/eek-keyboard.h b/eek/eek-keyboard.h index 38e277b9..dcf308c9 100644 --- a/eek/eek-keyboard.h +++ b/eek/eek-keyboard.h @@ -70,8 +70,8 @@ struct _EekKeyboard /** * EekKeyboardClass: * @create_section: virtual function for creating a section - * @find_key_by_keycode: virtual function for finding a key in the - * keyboard by keycode + * @find_key_by_name: virtual function for finding a key in the + * keyboard by name * @key_pressed: class handler for #EekKeyboard::key-pressed signal * @key_released: class handler for #EekKeyboard::key-released signal * @key_locked: class handler for #EekKeyboard::key-locked signal @@ -90,8 +90,8 @@ struct _EekKeyboardClass /*< public >*/ EekSection *(* create_section) (EekKeyboard *self); - EekKey *(* find_key_by_keycode) (EekKeyboard *self, - guint keycode); + EekKey *(* find_key_by_name) (EekKeyboard *self, + const gchar *name); /*< private >*/ /* obsolete members moved to EekElement */ @@ -156,9 +156,9 @@ EekModifierType eek_keyboard_get_modifiers EekSection *eek_keyboard_create_section (EekKeyboard *keyboard); -EekKey *eek_keyboard_find_key_by_keycode +EekKey *eek_keyboard_find_key_by_name (EekKeyboard *keyboard, - guint keycode); + const gchar *name); guint eek_keyboard_add_outline (EekKeyboard *keyboard, diff --git a/eek/eek-section.c b/eek/eek-section.c index 1dcfb13b..f0d13312 100644 --- a/eek/eek-section.c +++ b/eek/eek-section.c @@ -122,7 +122,8 @@ on_unlocked (EekKey *key, static EekKey * eek_section_real_create_key (EekSection *self, - guint keycode, + const gchar *name, + gint keycode, gint column_index, gint row_index) { @@ -140,6 +141,7 @@ eek_section_real_create_key (EekSection *self, row->num_columns = column_index + 1; key = g_object_new (EEK_TYPE_KEY, + "name", name, "keycode", keycode, "column", column_index, "row", row_index, @@ -461,6 +463,7 @@ eek_section_get_row (EekSection *section, /** * eek_section_create_key: * @section: an #EekSection + * @name: a name * @keycode: a keycode * @column: the column index of the key * @row: the row index of the key @@ -471,12 +474,14 @@ eek_section_get_row (EekSection *section, */ EekKey * eek_section_create_key (EekSection *section, - guint keycode, + const gchar *name, + gint keycode, gint column, gint row) { g_return_val_if_fail (EEK_IS_SECTION(section), NULL); return EEK_SECTION_GET_CLASS(section)->create_key (section, + name, keycode, column, row); diff --git a/eek/eek-section.h b/eek/eek-section.h index f4335ade..50baac80 100644 --- a/eek/eek-section.h +++ b/eek/eek-section.h @@ -62,7 +62,8 @@ struct _EekSectionClass EekOrientation *orientation); EekKey *(* create_key) (EekSection *self, - guint keycode, + const gchar *name, + gint keycode, gint row, gint column); @@ -99,7 +100,8 @@ void eek_section_get_row (EekSection *section, EekOrientation *orientation); EekKey *eek_section_create_key (EekSection *section, - guint keycode, + const gchar *name, + gint keycode, gint column, gint row); diff --git a/eek/eek-xml-layout.c b/eek/eek-xml-layout.c index aa41a7d8..23fb49ca 100644 --- a/eek/eek-xml-layout.c +++ b/eek/eek-xml-layout.c @@ -405,17 +405,23 @@ geometry_start_element_callback (GMarkupParseContext *pcontext, "no \"keycode\" attribute for \"key\""); return; } - keycode = strtoul (attribute, NULL, 10); - - data->key = eek_section_create_key (data->section, - keycode, - data->num_columns, - data->num_rows - 1); + keycode = strtol (attribute, NULL, 10); attribute = get_attribute (attribute_names, attribute_values, "name"); - if (attribute != NULL) - eek_element_set_name (EEK_ELEMENT(data->key), attribute); + if (attribute == NULL) { + g_set_error (error, + G_MARKUP_ERROR, + G_MARKUP_ERROR_MISSING_ATTRIBUTE, + "no \"name\" attribute for \"key\""); + return; + } + + data->key = eek_section_create_key (data->section, + g_strdup (attribute), + keycode, + data->num_columns, + data->num_rows - 1); attribute = get_attribute (attribute_names, attribute_values, "oref"); @@ -620,28 +626,25 @@ symbols_start_element_callback (GMarkupParseContext *pcontext, return; if (g_strcmp0 (element_name, "key") == 0) { - guint keycode; attribute = get_attribute (attribute_names, attribute_values, - "keycode"); + "name"); if (attribute == NULL) { g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_MISSING_ATTRIBUTE, - "no \"keycode\" attribute for \"key\""); + "no \"name\" attribute for \"key\""); return; } - keycode = strtoul (attribute, NULL, 10); - data->key = eek_keyboard_find_key_by_keycode (data->keyboard, - keycode); - /*if (data->key == NULL) { + data->key = eek_keyboard_find_key_by_name (data->keyboard, + attribute); + if (data->key == NULL) { g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, - "no such keycode %u", keycode); - return; - }*/ + "no such key %s", attribute); + } attribute = get_attribute (attribute_names, attribute_values, "groups"); diff --git a/eekboard/eekboard-context-service.c b/eekboard/eekboard-context-service.c index 9869676e..bfa219d9 100644 --- a/eekboard/eekboard-context-service.c +++ b/eekboard/eekboard-context-service.c @@ -28,6 +28,7 @@ #include "config.h" #include "eekboard/eekboard-context-service.h" +#include "keymap.h" #include #include @@ -83,6 +84,53 @@ struct _EekboardContextServicePrivate { G_DEFINE_TYPE_WITH_PRIVATE (EekboardContextService, eekboard_context_service, G_TYPE_OBJECT); /*static Display *display = NULL; */ +gchar * +get_keymap_from_resource(const gchar *keyboard_type, gboolean fallback) +{ + g_autoptr (GFile) file = NULL; + g_autoptr (GFileInfo) info = NULL; + g_autoptr (GFileInputStream) stream = NULL; + goffset size = 0; + gsize bytes_read = 0; + g_autofree gchar *contents = NULL; + g_autofree gchar *path = NULL; + GError *error = NULL; + + if (fallback) + g_debug ("falling back to loading a %s keymap", keyboard_type); + + path = g_strconcat ("resource:///sm/puri/squeekboard/keyboards/keymaps/", + keyboard_type, ".xkb", NULL); + file = g_file_new_for_uri (path); + stream = g_file_read (file, NULL, &error); + + if (!stream) + goto keymap_error; + + info = g_file_input_stream_query_info (stream, + G_FILE_ATTRIBUTE_STANDARD_SIZE, + NULL, + &error); + + if (!info) + goto keymap_error; + + size = g_file_info_get_size (info); + contents = g_malloc0 (size); + + if (!g_input_stream_read_all (G_INPUT_STREAM(stream), contents, size, + &bytes_read, NULL, &error)) + goto keymap_error; + + return g_utf8_make_valid (contents, -1); + +keymap_error: + if (fallback) + g_error ("failed to load keymap from resource: %s", error->message); + + g_error_free (error); + return NULL; +} static EekKeyboard * eekboard_context_service_real_create_keyboard (EekboardContextService *self, @@ -143,18 +191,28 @@ eekboard_context_service_real_create_keyboard (EekboardContextService *self, if (!context) { g_error("No context created"); } - +/* struct xkb_rule_names rules = { 0 }; rules.layout = strdup(keyboard_type); - struct xkb_keymap *keymap = xkb_keymap_new_from_names(context, &rules, - XKB_KEYMAP_COMPILE_NO_FLAGS); +*/ + char *keymap_str = get_keymap_from_resource(keyboard_type, FALSE); + if (!keymap_str) + keymap_str = get_keymap_from_resource("us", TRUE); + + struct xkb_keymap *keymap = xkb_keymap_new_from_string(context, keymap_str, + XKB_KEYMAP_FORMAT_TEXT_V1, XKB_KEYMAP_COMPILE_NO_FLAGS); + + free(keymap_str); + xkb_context_unref(context); if (!keymap) { g_error("Bad keymap"); } keyboard->keymap = keymap; - char *keymap_str = xkb_keymap_get_as_string(keymap, XKB_KEYMAP_FORMAT_TEXT_V1); + + keymap_str = xkb_keymap_get_as_string(keymap, XKB_KEYMAP_FORMAT_TEXT_V1); keyboard->keymap_len = strlen(keymap_str) + 1; + g_autofree char *path = strdup("/eek_keymap-XXXXXX"); char *r = &path[strlen(path) - 6]; getrandom(r, 6, GRND_NONBLOCK); @@ -287,6 +345,7 @@ settings_update_layout(EekboardContextService *context) g_autofree gchar *keyboard_type = NULL; g_autofree gchar *keyboard_layout = NULL; settings_get_layout(context->priv->settings, &keyboard_type, &keyboard_layout); + g_debug("type=%s, layout=%s", keyboard_type, keyboard_layout); if (!keyboard_type) { keyboard_type = g_strdup("us"); diff --git a/eekboard/key-emitter.c b/eekboard/key-emitter.c index 539c2331..d960c223 100644 --- a/eekboard/key-emitter.c +++ b/eekboard/key-emitter.c @@ -143,8 +143,8 @@ int send_virtual_keyboard_key( static void send_fake_modifiers_events (SeatEmitter *emitter, - EekModifierType modifiers, - uint32_t timestamp) + EekModifierType modifiers, + uint32_t timestamp) { (void)timestamp; @@ -284,6 +284,26 @@ update_modifier_info (SeatEmitter *client) }*/ } +static void +send_fake_key (SeatEmitter *emitter, + EekKeyboard *keyboard, + guint keycode, + guint keyboard_modifiers, + gboolean pressed, + uint32_t timestamp) +{ + uint32_t proto_modifiers = 0; + guint level = eek_element_get_level(EEK_ELEMENT(keyboard)); + uint32_t group = (level / 2); + + if (keyboard_modifiers & EEK_SHIFT_MASK) + proto_modifiers |= 1<virtual_keyboard, proto_modifiers, 0, 0, group); + send_virtual_keyboard_key (emitter->virtual_keyboard, keycode - 8, (unsigned)pressed, timestamp); + zwp_virtual_keyboard_v1_modifiers(emitter->virtual_keyboard, proto_modifiers, 0, 0, group); +} + void emit_key_activated (EekboardContextService *manager, EekKeyboard *keyboard, @@ -324,5 +344,5 @@ emit_key_activated (EekboardContextService *manager, emitter.virtual_keyboard = manager->virtual_keyboard; emitter.keymap = keyboard->keymap; update_modifier_info (&emitter); - send_fake_key_events (&emitter, symbol, modifiers, pressed, timestamp); + send_fake_key (&emitter, keyboard, keycode, modifiers, pressed, timestamp); }