Initial commit - from Precise source
[freerdp-ubuntu-pcb-backport.git] / libfreerdp-kbd / locales.c
1 /**
2  * FreeRDP: A Remote Desktop Protocol Client
3  * XKB-based Keyboard Mapping to Microsoft Keyboard System
4  *
5  * Copyright 2009 Marc-Andre Moreau <marcandre.moreau@gmail.com>
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include "libkbd.h"
24
25 #include <freerdp/kbd/locales.h>
26
27 typedef struct
28 {
29         /* Two or three letter language code */
30         char language[4];
31
32         /* Two or three letter country code (Sometimes with Cyrl_ prefix) */
33         char country[10];
34
35         /* 32-bit unsigned integer corresponding to the locale */
36         unsigned int code;
37
38 } locale;
39
40 /*
41  * Refer to MSDN article "Locale Identifier Constants and Strings":
42  * http://msdn.microsoft.com/en-us/library/ms776260.aspx
43  */
44
45 static const locale locales[] =
46 {
47         {  "af", "ZA", AFRIKAANS }, /* Afrikaans (South Africa) */
48         {  "sq", "AL", ALBANIAN }, /* Albanian (Albania) */
49         { "gsw", "FR", ALSATIAN }, /* Windows Vista and later: Alsatian (France) */
50         {  "am", "ET", AMHARIC }, /* Windows Vista and later: Amharic (Ethiopia) */
51         {  "ar", "DZ", ARABIC_ALGERIA }, /* Arabic (Algeria) */
52         {  "ar", "BH", ARABIC_BAHRAIN }, /* Arabic (Bahrain) */
53         {  "ar", "EG", ARABIC_EGYPT }, /* Arabic (Egypt) */
54         {  "ar", "IQ", ARABIC_IRAQ }, /* Arabic (Iraq) */
55         {  "ar", "JO", ARABIC_JORDAN }, /* Arabic (Jordan) */
56         {  "ar", "KW", ARABIC_KUWAIT }, /* Arabic (Kuwait) */
57         {  "ar", "LB", ARABIC_LEBANON }, /* Arabic (Lebanon) */
58         {  "ar", "LY", ARABIC_LIBYA }, /* Arabic (Libya) */
59         {  "ar", "MA", ARABIC_MOROCCO }, /* Arabic (Morocco) */
60         {  "ar", "OM", ARABIC_OMAN }, /* Arabic (Oman) */
61         {  "ar", "QA", ARABIC_QATAR }, /* Arabic (Qatar) */
62         {  "ar", "SA", ARABIC_SAUDI_ARABIA }, /* Arabic (Saudi Arabia) */
63         {  "ar", "SY", ARABIC_SYRIA }, /* Arabic (Syria) */
64         {  "ar", "TN", ARABIC_TUNISIA }, /* Arabic (Tunisia) */
65         {  "ar", "AE", ARABIC_UAE }, /* Arabic (U.A.E.) */
66         {  "ar", "YE", ARABIC_YEMEN }, /* Arabic (Yemen) */
67         {  "az", "AZ", AZERI_LATIN }, /* Azeri (Latin) */
68         {  "az", "Cyrl_AZ", AZERI_CYRILLIC }, /* Azeri (Cyrillic) */
69         {  "hy", "AM", ARMENIAN }, /* Windows 2000 and later: Armenian (Armenia) */
70         {  "as", "IN", ASSAMESE }, /* Windows Vista and later: Assamese (India) */
71         {  "ba", "RU", BASHKIR }, /* Windows Vista and later: Bashkir (Russia) */
72         {  "eu", "ES", BASQUE }, /* Basque (Basque) */
73         {  "be", "BY", BELARUSIAN }, /* Belarusian (Belarus) */
74         {  "bn", "IN", BENGALI_INDIA }, /* Windows XP SP2 and later: Bengali (India) */
75         {  "br", "FR", BRETON }, /* Breton (France) */
76         {  "bs", "BA", BOSNIAN_LATIN }, /* Bosnian (Latin) */
77         {  "bg", "BG", BULGARIAN }, /* Bulgarian (Bulgaria) */
78         {  "ca", "ES", CATALAN }, /* Catalan (Catalan) */
79         {  "zh", "HK", CHINESE_HONG_KONG }, /* Chinese (Hong Kong SAR, PRC) */
80         {  "zh", "MO", CHINESE_MACAU }, /* Windows 98/Me, Windows XP and later: Chinese (Macao SAR) */
81         {  "zh", "CN", CHINESE_PRC }, /* Chinese (PRC) */
82         {  "zh", "SG", CHINESE_SINGAPORE }, /* Chinese (Singapore) */
83         {  "zh", "TW", CHINESE_TAIWAN }, /* Chinese (Taiwan) */
84         {  "hr", "BA", CROATIAN_BOSNIA_HERZEGOVINA }, /* Windows XP SP2 and later: Croatian (Bosnia and Herzegovina, Latin) */
85         {  "hr", "HR", CROATIAN }, /* Croatian (Croatia) */
86         {  "cs", "CZ", CZECH }, /* Czech (Czech Republic) */
87         {  "da", "DK", DANISH }, /* Danish (Denmark) */
88         { "prs", "AF", DARI }, /* Windows XP and later: Dari (Afghanistan) */
89         {  "dv", "MV", DIVEHI }, /* Windows XP and later: Divehi (Maldives) */
90         {  "nl", "BE", DUTCH_BELGIAN }, /* Dutch (Belgium) */
91         {  "nl", "NL", DUTCH_STANDARD }, /* Dutch (Netherlands) */
92         {  "en", "AU", ENGLISH_AUSTRALIAN }, /* English (Australia) */
93         {  "en", "BZ", ENGLISH_BELIZE }, /* English (Belize) */
94         {  "en", "CA", ENGLISH_CANADIAN }, /* English (Canada) */
95         {  "en", "CB", ENGLISH_CARIBBEAN }, /* English (Carribean) */
96         {  "en", "IN", ENGLISH_INDIA }, /* Windows Vista and later: English (India) */
97         {  "en", "IE", ENGLISH_IRELAND }, /* English (Ireland) */
98         {  "en", "JM", ENGLISH_JAMAICA }, /* English (Jamaica) */
99         {  "en", "MY", ENGLISH_MALAYSIA }, /* Windows Vista and later: English (Malaysia) */
100         {  "en", "NZ", ENGLISH_NEW_ZEALAND }, /* English (New Zealand) */
101         {  "en", "PH", ENGLISH_PHILIPPINES }, /* Windows 98/Me, Windows 2000 and later: English (Philippines) */
102         {  "en", "SG", ENGLISH_SINGAPORE }, /* Windows Vista and later: English (Singapore) */
103         {  "en", "ZA", ENGLISH_SOUTH_AFRICA }, /* English (South Africa) */
104         {  "en", "TT", ENGLISH_TRINIDAD }, /* English (Trinidad and Tobago) */
105         {  "en", "GB", ENGLISH_UNITED_KINGDOM }, /* English (United Kingdom) */
106         {  "en", "US", ENGLISH_UNITED_STATES }, /* English (United States) */
107         {  "en", "ZW", ENGLISH_ZIMBABWE }, /* Windows 98/Me, Windows 2000 and later: English (Zimbabwe) */
108         {  "et", "EE", ESTONIAN }, /* Estonian (Estonia) */
109         {  "fo", "FO", FAEROESE }, /* Faroese (Faroe Islands) */
110         { "fil", "PH", FILIPINO }, /* Windows XP SP2 and later (downloadable); Windows Vista and later: Filipino (Philippines) */
111         {  "fi", "FI", FINNISH }, /* Finnish (Finland) */
112         {  "fr", "BE", FRENCH_BELGIAN }, /* French (Belgium) */
113         {  "fr", "CA", FRENCH_CANADIAN }, /* French (Canada) */
114         {  "fr", "FR", FRENCH_STANDARD }, /* French (France) */
115         {  "fr", "LU", FRENCH_LUXEMBOURG }, /* French (Luxembourg) */
116         {  "fr", "MC", FRENCH_MONACO }, /* French (Monaco) */
117         {  "fr", "CH", FRENCH_SWISS }, /* French (Switzerland) */
118         {  "fy", "NL", FRISIAN }, /* Windows XP SP2 and later (downloadable); Windows Vista and later: Frisian (Netherlands) */
119         {  "gl", "ES", GALICIAN }, /* Windows XP and later: Galician (Spain) */
120         {  "ka", "GE", GEORGIAN }, /* Windows 2000 and later: Georgian (Georgia) */
121         {  "de", "AT", GERMAN_AUSTRIAN }, /* German (Austria) */
122         {  "de", "DE", GERMAN_STANDARD }, /* German (Germany) */
123         {  "de", "LI", GERMAN_LIECHTENSTEIN }, /* German (Liechtenstein) */
124         {  "de", "LU", GERMAN_LUXEMBOURG }, /* German (Luxembourg) */
125         {  "de", "CH", GERMAN_SWISS }, /* German (Switzerland) */
126         {  "el", "GR", GREEK }, /* Greek (Greece) */
127         {  "kl", "GL", GREENLANDIC }, /* Windows Vista and later: Greenlandic (Greenland) */
128         {  "gu", "IN", GUJARATI }, /* Windows XP and later: Gujarati (India) */
129         {  "he", "IL", HEBREW }, /* Hebrew (Israel) */
130         {  "hi", "IN", HINDI }, /* Windows 2000 and later: Hindi (India) */
131         {  "hu", "HU", HUNGARIAN }, /* Hungarian (Hungary) */
132         {  "is", "IS", ICELANDIC }, /* Icelandic (Iceland) */
133         {  "ig", "NG", IGBO }, /* Igbo (Nigeria) */
134         {  "id", "ID", INDONESIAN }, /* Indonesian (Indonesia) */
135         {  "ga", "IE", IRISH }, /* Windows XP SP2 and later (downloadable); Windows Vista and later: Irish (Ireland) */
136         {  "it", "IT", ITALIAN_STANDARD }, /* Italian (Italy) */
137         {  "it", "CH", ITALIAN_SWISS }, /* Italian (Switzerland) */
138         {  "ja", "JP", JAPANESE }, /* Japanese (Japan) */
139         {  "kn", "IN", KANNADA }, /* Windows XP and later: Kannada (India) */
140         {  "kk", "KZ", KAZAKH }, /* Windows 2000 and later: Kazakh (Kazakhstan) */
141         {  "kh", "KH", KHMER }, /* Windows Vista and later: Khmer (Cambodia) */
142         { "qut", "GT", KICHE }, /* Windows Vista and later: K'iche (Guatemala) */
143         {  "rw", "RW", KINYARWANDA }, /* Windows Vista and later: Kinyarwanda (Rwanda) */
144         { "kok", "IN", KONKANI }, /* Windows 2000 and later: Konkani (India) */
145         {  "ko", "KR", KOREAN }, /* Korean (Korea) */
146         {  "ky", "KG", KYRGYZ }, /* Windows XP and later: Kyrgyz (Kyrgyzstan) */
147         {  "lo", "LA", LAO }, /* Windows Vista and later: Lao (Lao PDR) */
148         {  "lv", "LV", LATVIAN }, /* Latvian (Latvia) */
149         {  "lt", "LT", LITHUANIAN }, /* Lithuanian (Lithuania) */
150         { "dsb", "DE", LOWER_SORBIAN }, /* Windows Vista and later: Lower Sorbian (Germany) */
151         {  "lb", "LU", LUXEMBOURGISH }, /* Windows XP SP2 and later (downloadable); Windows Vista and later: Luxembourgish (Luxembourg) */
152         {  "mk", "MK", MACEDONIAN }, /* Windows 2000 and later: Macedonian (Macedonia, FYROM) */
153         {  "ms", "BN", MALAY_BRUNEI_DARUSSALAM }, /* Windows 2000 and later: Malay (Brunei Darussalam) */
154         {  "ms", "MY", MALAY_MALAYSIA }, /* Windows 2000 and later: Malay (Malaysia) */
155         {  "ml", "IN", MALAYALAM }, /* Windows XP SP2 and later: Malayalam (India) */
156         {  "mt", "MT", MALTESE }, /* Windows XP SP2 and later: Maltese (Malta) */
157         {  "mi", "NZ", MAORI }, /* Windows XP SP2 and later: Maori (New Zealand) */
158         { "arn", "CL", MAPUDUNGUN }, /* Windows XP SP2 and later (downloadable); Windows Vista and later: Mapudungun (Chile) */
159         {  "mr", "IN", MARATHI }, /* Windows 2000 and later: Marathi (India) */
160         { "moh", "CA", MOHAWK }, /* Windows XP SP2 and later (downloadable); Windows Vista and later: Mohawk (Canada) */
161         {  "mn", "MN", MONGOLIAN }, /* Mongolian */
162         {  "ne", "NP", NEPALI }, /* Windows XP SP2 and later (downloadable); Windows Vista and later: Nepali (Nepal) */
163         {  "nb", "NO", NORWEGIAN_BOKMAL }, /* Norwegian (Bokmal, Norway) */
164         {  "nn", "NO", NORWEGIAN_NYNORSK }, /* Norwegian (Nynorsk, Norway) */
165         {  "oc", "FR", OCCITAN }, /* Occitan (France) */
166         {  "or", "IN", ORIYA }, /* Oriya (India) */
167         {  "ps", "AF", PASHTO }, /* Windows XP SP2 and later (downloadable); Windows Vista and later: Pashto (Afghanistan) */
168         {  "fa", "IR", FARSI }, /* Persian (Iran) */
169         {  "pl", "PL", POLISH }, /* Polish (Poland) */
170         {  "pt", "BR", PORTUGUESE_BRAZILIAN }, /* Portuguese (Brazil) */
171         {  "pt", "PT", PORTUGUESE_STANDARD }, /* Portuguese (Portugal) */
172         {  "pa", "IN", PUNJABI }, /* Windows XP and later: Punjabi (India) */
173         { "quz", "BO", QUECHUA_BOLIVIA }, /* Windows XP SP2 and later: Quechua (Bolivia) */
174         { "quz", "EC", QUECHUA_ECUADOR }, /* Windows XP SP2 and later: Quechua (Ecuador) */
175         { "quz", "PE", QUECHUA_PERU }, /* Windows XP SP2 and later: Quechua (Peru) */
176         {  "ro", "RO", ROMANIAN }, /* Romanian (Romania) */
177         {  "rm", "CH", ROMANSH }, /* Windows XP SP2 and later (downloadable); Windows Vista and later: Romansh (Switzerland) */
178         {  "ru", "RU", RUSSIAN }, /* Russian (Russia) */
179         { "smn", "FI", SAMI_INARI }, /* Windows XP SP2 and later: Sami (Inari, Finland) */
180         { "smj", "NO", SAMI_LULE_NORWAY }, /* Windows XP SP2 and later: Sami (Lule, Norway) */
181         { "smj", "SE", SAMI_LULE_SWEDEN }, /* Windows XP SP2 and later: Sami (Lule, Sweden) */
182         {  "se", "FI", SAMI_NORTHERN_FINLAND }, /* Windows XP SP2 and later: Sami (Northern, Finland) */
183         {  "se", "NO", SAMI_NORTHERN_NORWAY }, /* Windows XP SP2 and later: Sami (Northern, Norway) */
184         {  "se", "SE", SAMI_NORTHERN_SWEDEN }, /* Windows XP SP2 and later: Sami (Northern, Sweden) */
185         { "sms", "FI", SAMI_SKOLT }, /* Windows XP SP2 and later: Sami (Skolt, Finland) */
186         { "sma", "NO", SAMI_SOUTHERN_NORWAY }, /* Windows XP SP2 and later: Sami (Southern, Norway) */
187         { "sma", "SE", SAMI_SOUTHERN_SWEDEN }, /* Windows XP SP2 and later: Sami (Southern, Sweden) */
188         {  "sa", "IN", SANSKRIT }, /* Windows 2000 and later: Sanskrit (India) */
189         {  "sr", "SP", SERBIAN_LATIN }, /* Serbian (Latin) */
190         {  "sr", "SIH", SERBIAN_LATIN_BOSNIA_HERZEGOVINA }, /* Serbian (Latin) (Bosnia and Herzegovina) */
191         {  "sr", "Cyrl_SP", SERBIAN_CYRILLIC }, /* Serbian (Cyrillic) */
192         {  "sr", "Cyrl_SIH", SERBIAN_CYRILLIC_BOSNIA_HERZEGOVINA }, /* Serbian (Cyrillic) (Bosnia and Herzegovina) */
193         {  "ns", "ZA", SESOTHO_SA_LEBOA }, /* Windows XP SP2 and later: Sesotho sa Leboa/Northern Sotho (South Africa) */
194         {  "tn", "ZA", TSWANA }, /* Windows XP SP2 and later: Setswana/Tswana (South Africa) */
195         {  "si", "LK", SINHALA }, /* Windows Vista and later: Sinhala (Sri Lanka) */
196         {  "sk", "SK", SLOVAK }, /* Slovak (Slovakia) */
197         {  "sl", "SI", SLOVENIAN }, /* Slovenian (Slovenia) */
198         {  "es", "AR", SPANISH_ARGENTINA }, /* Spanish (Argentina) */
199         {  "es", "BO", SPANISH_BOLIVIA }, /* Spanish (Bolivia) */
200         {  "es", "CL", SPANISH_CHILE }, /* Spanish (Chile) */
201         {  "es", "CO", SPANISH_COLOMBIA }, /* Spanish (Colombia) */
202         {  "es", "CR", SPANISH_COSTA_RICA }, /* Spanish (Costa Rica) */
203         {  "es", "DO", SPANISH_DOMINICAN_REPUBLIC }, /* Spanish (Dominican Republic) */
204         {  "es", "EC", SPANISH_ECUADOR }, /* Spanish (Ecuador) */
205         {  "es", "SV", SPANISH_EL_SALVADOR }, /* Spanish (El Salvador) */
206         {  "es", "GT", SPANISH_GUATEMALA }, /* Spanish (Guatemala) */
207         {  "es", "HN", SPANISH_HONDURAS }, /* Spanish (Honduras) */
208         {  "es", "MX", SPANISH_MEXICAN }, /* Spanish (Mexico) */
209         {  "es", "NI", SPANISH_NICARAGUA }, /* Spanish (Nicaragua) */
210         {  "es", "PA", SPANISH_PANAMA }, /* Spanish (Panama) */
211         {  "es", "PY", SPANISH_PARAGUAY }, /* Spanish (Paraguay) */
212         {  "es", "PE", SPANISH_PERU }, /* Spanish (Peru) */
213         {  "es", "PR", SPANISH_PUERTO_RICO }, /* Spanish (Puerto Rico) */
214         {  "es", "ES", SPANISH_MODERN_SORT }, /* Spanish (Spain) */
215         {  "es", "ES", SPANISH_TRADITIONAL_SORT }, /* Spanish (Spain, Traditional Sort) */
216         {  "es", "US", SPANISH_UNITED_STATES }, /* Windows Vista and later: Spanish (United States) */
217         {  "es", "UY", SPANISH_URUGUAY }, /* Spanish (Uruguay) */
218         {  "es", "VE", SPANISH_VENEZUELA }, /* Spanish (Venezuela) */
219         {  "sw", "KE", SWAHILI }, /* Windows 2000 and later: Swahili (Kenya) */
220         {  "sv", "FI", SWEDISH_FINLAND }, /* Swedish (Finland) */
221         {  "sv", "SE", SWEDISH }, /* Swedish (Sweden) */
222         { "syr", "SY", SYRIAC }, /* Windows XP and later: Syriac (Syria) */
223         {  "ta", "IN", TAMIL }, /* Windows 2000 and later: Tamil (India) */
224         {  "tt", "RU", TATAR }, /* Windows XP and later: Tatar (Russia) */
225         {  "te", "IN", TELUGU }, /* Windows XP and later: Telugu (India) */
226         {  "th", "TH", THAI }, /* Thai (Thailand) */
227         {  "bo", "BT", TIBETAN_BHUTAN }, /* Windows Vista and later: Tibetan (Bhutan) */
228         {  "bo", "CN", TIBETAN_PRC }, /* Windows Vista and later: Tibetan (PRC) */
229         {  "tr", "TR", TURKISH }, /* Turkish (Turkey) */
230         {  "tk", "TM", TURKMEN }, /* Windows Vista and later: Turkmen (Turkmenistan) */
231         {  "ug", "CN", UIGHUR }, /* Windows Vista and later: Uighur (PRC) */
232         {  "uk", "UA", UKRAINIAN }, /* Ukrainian (Ukraine) */
233         { "wen", "DE", UPPER_SORBIAN }, /* Windows Vista and later: Upper Sorbian (Germany) */
234         {  "tr", "IN", URDU_INDIA }, /* Urdu (India) */
235         {  "ur", "PK", URDU }, /* Windows 98/Me, Windows 2000 and later: Urdu (Pakistan) */
236         {  "uz", "UZ", UZBEK_LATIN }, /* Uzbek (Latin) */
237         {  "uz", "Cyrl_UZ", UZBEK_CYRILLIC }, /* Uzbek (Cyrillic) */
238         {  "vi", "VN", VIETNAMESE }, /* Windows 98/Me, Windows NT 4.0 and later: Vietnamese (Vietnam) */
239         {  "cy", "GB", WELSH }, /* Windows XP SP2 and later: Welsh (United Kingdom) */
240         {  "wo", "SN", WOLOF }, /* Windows Vista and later: Wolof (Senegal) */
241         {  "xh", "ZA", XHOSA }, /* Windows XP SP2 and later: Xhosa/isiXhosa (South Africa) */
242         { "sah", "RU", YAKUT }, /* Windows Vista and later: Yakut (Russia) */
243         {  "ii", "CN", YI }, /* Windows Vista and later: Yi (PRC) */
244         {  "yo", "NG", YORUBA }, /* Windows Vista and later: Yoruba (Nigeria) */
245         {  "zu", "ZA", ZULU } /* Windows XP SP2 and later: Zulu/isiZulu (South Africa) */
246 };
247
248
249 typedef struct
250 {
251         /* Locale ID */
252         unsigned int locale;
253
254         /* Array of associated keyboard layouts */
255         unsigned int keyboardLayouts[5];
256
257 } localeAndKeyboardLayout;
258
259 /* TODO: Use KBD_* defines instead of hardcoded values */
260
261 static const localeAndKeyboardLayout defaultKeyboardLayouts[] =
262 {
263         { AFRIKAANS,                            { 0x00000409, 0x00000409, 0x0, 0x0, 0x0 } },
264         { ALBANIAN,                             { 0x0000041c, 0x00000409, 0x0, 0x0, 0x0 } },
265         { ARABIC_SAUDI_ARABIA,                  { 0x00000409, 0x00000401, 0x0, 0x0, 0x0 } },
266         { ARABIC_IRAQ,                          { 0x00000409, 0x00000401, 0x0, 0x0, 0x0 } },
267         { ARABIC_EGYPT,                         { 0x00000409, 0x00000401, 0x0, 0x0, 0x0 } },
268         { ARABIC_LIBYA,                         { 0x0000040c, 0x00020401, 0x0, 0x0, 0x0 } },
269         { ARABIC_ALGERIA,                       { 0x0000040c, 0x00020401, 0x0, 0x0, 0x0 } },
270         { ARABIC_MOROCCO,                       { 0x0000040c, 0x00020401, 0x0, 0x0, 0x0 } },
271         { ARABIC_TUNISIA,                       { 0x0000040c, 0x00020401, 0x0, 0x0, 0x0 } },
272         { ARABIC_OMAN,                          { 0x00000409, 0x00000401, 0x0, 0x0, 0x0 } },
273         { ARABIC_YEMEN,                         { 0x00000409, 0x00000401, 0x0, 0x0, 0x0 } },
274         { ARABIC_SYRIA,                         { 0x00000409, 0x00000401, 0x0, 0x0, 0x0 } },
275         { ARABIC_JORDAN,                        { 0x00000409, 0x00000401, 0x0, 0x0, 0x0 } },
276         { ARABIC_LEBANON,                       { 0x00000409, 0x00000401, 0x0, 0x0, 0x0 } },
277         { ARABIC_KUWAIT,                        { 0x00000409, 0x00000401, 0x0, 0x0, 0x0 } },
278         { ARABIC_UAE,                           { 0x00000409, 0x00000401, 0x0, 0x0, 0x0 } },
279         { ARABIC_BAHRAIN,                       { 0x00000409, 0x00000401, 0x0, 0x0, 0x0 } },
280         { ARABIC_QATAR,                         { 0x00000409, 0x00000401, 0x0, 0x0, 0x0 } },
281         { ARMENIAN,                             { 0x0000042b, 0x00000409, 0x00000419, 0x0, 0x0 } },
282         { AZERI_LATIN,                          { 0x0000042c, 0x0000082c, 0x00000419, 0x0, 0x0 } },
283         { AZERI_CYRILLIC,                       { 0x0000082c, 0x0000042c, 0x00000419, 0x0, 0x0 } },
284         { BASQUE,                               { 0x0000040a, 0x00000409, 0x0, 0x0, 0x0 } },
285         { BELARUSIAN,                           { 0x00000423, 0x00000409, 0x00000419, 0x0, 0x0 } },
286         { BENGALI_INDIA,                        { 0x00000445, 0x00000409, 0x0, 0x0, 0x0 } },
287         { BOSNIAN_LATIN,                        { 0x0000141A, 0x00000409, 0x0, 0x0, 0x0 } },
288         { BULGARIAN,                            { 0x00000402, 0x00000409, 0x0, 0x0, 0x0 } },
289         { CATALAN,                              { 0x0000040a, 0x00000409, 0x0, 0x0, 0x0 } },
290         { CHINESE_TAIWAN,                       { 0x00000404, 0xe0080404, 0xE0010404, 0x0, 0x0 } },
291         { CHINESE_PRC,                          { 0x00000804, 0xe00e0804, 0xe0010804, 0xe0030804, 0xe0040804 } },
292         { CHINESE_HONG_KONG,                    { 0x00000409, 0xe0080404, 0x0, 0x0, 0x0 } },
293         { CHINESE_SINGAPORE,                    { 0x00000409, 0xe00e0804, 0xe0010804, 0xe0030804, 0xe0040804 } },
294         { CHINESE_MACAU,                        { 0x00000409, 0xe00e0804, 0xe0020404, 0xe0080404 } },
295         { CROATIAN,                             { 0x0000041a, 0x00000409, 0x0, 0x0, 0x0 } },
296         { CROATIAN_BOSNIA_HERZEGOVINA,          { 0x0000041a, 0x00000409, 0x0, 0x0, 0x0 } },
297         { CZECH,                                { 0x00000405, 0x00000409, 0x0, 0x0, 0x0 } },
298         { DANISH,                               { 0x00000406, 0x00000409, 0x0, 0x0, 0x0 } },
299         { DIVEHI,                               { 0x00000409, 0x00000465, 0x0, 0x0, 0x0 } },
300         { DUTCH_STANDARD,                       { 0x00020409, 0x00000413, 0x00000409, 0x0, 0x0 } },
301         { DUTCH_BELGIAN,                        { 0x00000813, 0x00000409, 0x0, 0x0, 0x0 } },
302         { ENGLISH_UNITED_STATES,                { 0x00000409, 0x0, 0x0, 0x0, 0x0 } },
303         { ENGLISH_UNITED_KINGDOM,               { 0x00000809, 0x0, 0x0, 0x0, 0x0 } },
304         { ENGLISH_AUSTRALIAN,                   { 0x00000409, 0x0, 0x0, 0x0, 0x0 } },
305         { ENGLISH_CANADIAN,                     { 0x00000409, 0x00011009, 0x00001009, 0x0, 0x0 } },
306         { ENGLISH_NEW_ZEALAND,                  { 0x00000409, 0x0, 0x0, 0x0, 0x0 } },
307         { ENGLISH_IRELAND,                      { 0x00001809, 0x00011809, 0x0, 0x0, 0x0 } },
308         { ENGLISH_SOUTH_AFRICA,                 { 0x00000409, 0x0, 0x0, 0x0, 0x0 } },
309         { ENGLISH_JAMAICA,                      { 0x00000409, 0x0, 0x0, 0x0, 0x0 } },
310         { ENGLISH_CARIBBEAN,                    { 0x00000409, 0x0, 0x0, 0x0, 0x0 } },
311         { ENGLISH_BELIZE,                       { 0x00000409, 0x0, 0x0, 0x0, 0x0 } },
312         { ENGLISH_TRINIDAD,                     { 0x00000409, 0x0, 0x0, 0x0, 0x0 } },
313         { ENGLISH_ZIMBABWE,                     { 0x00000409, 0x0, 0x0, 0x0, 0x0 } },
314         { ENGLISH_PHILIPPINES,                  { 0x00000409, 0x0, 0x0, 0x0, 0x0 } },
315         { ESTONIAN,                             { 0x00000425, 0x0, 0x0, 0x0, 0x0 } },
316         { FAEROESE,                             { 0x00000406, 0x00000409, 0x0, 0x0, 0x0 } },
317         { FARSI,                                { 0x00000409, 0x00000429, 0x00000401, 0x0, 0x0 } },
318         { FINNISH,                              { 0x0000040b, 0x00000409, 0x0, 0x0, 0x0 } },
319         { FRENCH_STANDARD,                      { 0x0000040c, 0x00000409, 0x0, 0x0, 0x0 } },
320         { FRENCH_BELGIAN,                       { 0x0000080c, 0x00000409, 0x0, 0x0, 0x0 } },
321         { FRENCH_CANADIAN,                      { 0x00000C0C, 0x00011009, 0x00000409, 0x0, 0x0 } },
322         { FRENCH_SWISS,                         { 0x0000100c, 0x00000409, 0x0, 0x0, 0x0 } },
323         { FRENCH_LUXEMBOURG,                    { 0x0000040c, 0x00000409, 0x0, 0x0, 0x0 } },
324         { FRENCH_MONACO,                        { 0x0000040c, 0x00000409, 0x0, 0x0, 0x0 } },
325         { GEORGIAN,                             { 0x00000437, 0x00000409, 0x00000419, 0x0, 0x0 } },
326         { GALICIAN,                             { 0x0000040a, 0x00000409, 0x0, 0x0, 0x0 } },
327         { GERMAN_STANDARD,                      { 0x00000407, 0x00000409, 0x0, 0x0, 0x0 } },
328         { GERMAN_SWISS,                         { 0x00000807, 0x00000409, 0x0, 0x0, 0x0 } },
329         { GERMAN_AUSTRIAN,                      { 0x00000407, 0x00000409, 0x0, 0x0, 0x0 } },
330         { GERMAN_LUXEMBOURG,                    { 0x00000407, 0x00000409, 0x0, 0x0, 0x0 } },
331         { GERMAN_LIECHTENSTEIN,                 { 0x00000407, 0x00000409, 0x0, 0x0, 0x0 } },
332         { GREEK,                                { 0x00000408, 0x00000409, 0x0, 0x0, 0x0 } },
333         { GUJARATI,                             { 0x00000409, 0x00000447, 0x00010439, 0x0, 0x0 } },
334         { HEBREW,                               { 0x00000409, 0x0000040d, 0x0, 0x0, 0x0 } },
335         { HINDI,                                { 0x00000409, 0x00010439, 0x00000439, 0x0, 0x0 } },
336         { HUNGARIAN,                            { 0x0000040e, 0x00000409, 0x0, 0x0, 0x0 } },
337         { ICELANDIC,                            { 0x0000040f, 0x00000409, 0x0, 0x0, 0x0 } },
338         { INDONESIAN,                           { 0x00000409, 0x00000409, 0x0, 0x0, 0x0 } },
339         { ITALIAN_STANDARD,                     { 0x00000410, 0x00000409, 0x0, 0x0, 0x0 } },
340         { ITALIAN_SWISS,                        { 0x00000410, 0x00000409, 0x0, 0x0, 0x0 } },
341         { JAPANESE,                             { 0xe0010411, 0x0, 0x0, 0x0, 0x0 } },
342         { KANNADA,                              { 0x00000409, 0x0000044b, 0x00010439, 0x0, 0x0 } },
343         { KAZAKH,                               { 0x0000043f, 0x00000409, 0x00000419, 0x0, 0x0 } },
344         { KONKANI,                              { 0x00000409, 0x00000439, 0x0, 0x0, 0x0 } },
345         { KOREAN,                               { 0xE0010412, 0x0, 0x0, 0x0, 0x0 } },
346         { KYRGYZ,                               { 0x00000440, 0x00000409, 0x0, 0x0, 0x0 } },
347         { LATVIAN,                              { 0x00010426, 0x0, 0x0, 0x0, 0x0 } },
348         { LITHUANIAN,                           { 0x00010427, 0x0, 0x0, 0x0, 0x0 } },
349         { MACEDONIAN,                           { 0x0000042f, 0x00000409, 0x0, 0x0, 0x0 } },
350         { MALAY_MALAYSIA,                       { 0x00000409, 0x0, 0x0, 0x0, 0x0 } },
351         { MALAY_BRUNEI_DARUSSALAM,              { 0x00000409, 0x0, 0x0, 0x0, 0x0 } },
352         { MALAYALAM,                            { 0x00000409, 0x0000044c, 0x0, 0x0, 0x0 } },
353         { MALTESE,                              { 0x00000409, 0x0000043a, 0x0, 0x0, 0x0 } },
354         { MAORI,                                { 0x00000409, 0x00000481, 0x0, 0x0, 0x0 } },
355         { MARATHI,                              { 0x00000409, 0x0000044e, 0x00000439, 0x0, 0x0 } },
356         { MONGOLIAN,                            { 0x00000450, 0x00000409, 0x0, 0x0, 0x0 } },
357         { NORWEGIAN_BOKMAL,                     { 0x00000414, 0x00000409, 0x0, 0x0, 0x0 } },
358         { NORWEGIAN_NYNORSK,                    { 0x00000414, 0x00000409, 0x0, 0x0, 0x0 } },
359         { POLISH,                               { 0x00010415, 0x00000415, 0x00000409, 0x0, 0x0 } },
360         { PORTUGUESE_BRAZILIAN,                 { 0x00000416, 0x00000409, 0x0, 0x0, 0x0 } },
361         { PORTUGUESE_STANDARD,                  { 0x00000816, 0x00000409, 0x0, 0x0, 0x0 } },
362         { PUNJABI,                              { 0x00000409, 0x00000446, 0x00010439, 0x0, 0x0 } },
363         { QUECHUA_BOLIVIA,                      { 0x00000409, 0x0000080A, 0x0, 0x0, 0x0 } },
364         { QUECHUA_ECUADOR,                      { 0x00000409, 0x0000080A, 0x0, 0x0, 0x0 } },
365         { QUECHUA_PERU,                         { 0x00000409, 0x0000080A, 0x0, 0x0, 0x0 } },
366         { ROMANIAN,                             { 0x00000418, 0x00000409, 0x0, 0x0, 0x0 } },
367         { RUSSIAN,                              { 0x00000419, 0x00000409, 0x0, 0x0, 0x0 } },
368         { SAMI_INARI,                           { 0x0001083b, 0x00000409, 0x0, 0x0, 0x0 } },
369         { SAMI_LULE_NORWAY,                     { 0x0000043b, 0x00000409, 0x0, 0x0, 0x0 } },
370         { SAMI_LULE_SWEDEN,                     { 0x0000083b, 0x00000409, 0x0, 0x0, 0x0 } },
371         { SAMI_NORTHERN_FINLAND,                { 0x0001083b, 0x00000409, 0x0, 0x0, 0x0 } },
372         { SAMI_NORTHERN_NORWAY,                 { 0x0000043b, 0x00000409, 0x0, 0x0, 0x0 } },
373         { SAMI_NORTHERN_SWEDEN,                 { 0x0000083b, 0x00000409, 0x0, 0x0, 0x0 } },
374         { SAMI_SKOLT,                           { 0x0001083b, 0x00000409, 0x0, 0x0, 0x0 } },
375         { SAMI_SOUTHERN_NORWAY,                 { 0x0000043b, 0x00000409, 0x0, 0x0, 0x0 } },
376         { SAMI_SOUTHERN_SWEDEN,                 { 0x0000083b, 0x00000409, 0x0, 0x0, 0x0 } },
377         { SANSKRIT,                             { 0x00000409, 0x00000439, 0x0, 0x0, 0x0 } },
378         { SERBIAN_LATIN,                        { 0x0000081a, 0x00000409, 0x0, 0x0, 0x0 } },
379         { SERBIAN_LATIN_BOSNIA_HERZEGOVINA,     { 0x0000081a, 0x00000409, 0x0, 0x0, 0x0 } },
380         { SERBIAN_CYRILLIC,                     { 0x00000c1a, 0x00000409, 0x0, 0x0, 0x0 } },
381         { SERBIAN_CYRILLIC_BOSNIA_HERZEGOVINA,  { 0x00000c1a, 0x00000409, 0x0, 0x0, 0x0 } },
382         { SLOVAK,                               { 0x0000041b, 0x00000409, 0x0, 0x0, 0x0 } },
383         { SLOVENIAN,                            { 0x00000424, 0x00000409, 0x0, 0x0, 0x0 } },
384         { SPANISH_TRADITIONAL_SORT,             { 0x0000040a, 0x00000409, 0x0, 0x0, 0x0 } },
385         { SPANISH_MEXICAN,                      { 0x0000080a, 0x00000409, 0x0, 0x0, 0x0 } },
386         { SPANISH_MODERN_SORT,                  { 0x0000040a, 0x00000409, 0x0, 0x0, 0x0 } },
387         { SPANISH_GUATEMALA,                    { 0x0000080a, 0x00000409, 0x0, 0x0, 0x0 } },
388         { SPANISH_COSTA_RICA,                   { 0x0000080a, 0x00000409, 0x0, 0x0, 0x0 } },
389         { SPANISH_PANAMA,                       { 0x0000080a, 0x00000409, 0x0, 0x0, 0x0 } },
390         { SPANISH_DOMINICAN_REPUBLIC,           { 0x0000080a, 0x00000409, 0x0, 0x0, 0x0 } },
391         { SPANISH_VENEZUELA,                    { 0x0000080a, 0x00000409, 0x0, 0x0, 0x0 } },
392         { SPANISH_COLOMBIA,                     { 0x0000080a, 0x00000409, 0x0, 0x0, 0x0 } },
393         { SPANISH_PERU,                         { 0x0000080a, 0x00000409, 0x0, 0x0, 0x0 } },
394         { SPANISH_ARGENTINA,                    { 0x0000080a, 0x00000409, 0x0, 0x0, 0x0 } },
395         { SPANISH_ECUADOR,                      { 0x0000080a, 0x00000409, 0x0, 0x0, 0x0 } },
396         { SPANISH_CHILE,                        { 0x0000080a, 0x00000409, 0x0, 0x0, 0x0 } },
397         { SPANISH_URUGUAY,                      { 0x0000080a, 0x00000409, 0x0, 0x0, 0x0 } },
398         { SPANISH_PARAGUAY,                     { 0x0000080a, 0x00000409, 0x0, 0x0, 0x0 } },
399         { SPANISH_BOLIVIA,                      { 0x0000080a, 0x00000409, 0x0, 0x0, 0x0 } },
400         { SPANISH_EL_SALVADOR,                  { 0x0000080a, 0x00000409, 0x0, 0x0, 0x0 } },
401         { SPANISH_HONDURAS,                     { 0x0000080a, 0x00000409, 0x0, 0x0, 0x0 } },
402         { SPANISH_NICARAGUA,                    { 0x0000080a, 0x00000409, 0x0, 0x0, 0x0 } },
403         { SPANISH_PUERTO_RICO,                  { 0x0000080a, 0x00000409, 0x0, 0x0, 0x0 } },
404         { SWAHILI,                              { 0x00000409, 0x0, 0x0, 0x0, 0x0 } },
405         { SWEDISH,                              { 0x0000041d, 0x00000409, 0x0, 0x0, 0x0 } },
406         { SWEDISH_FINLAND,                      { 0x0000041d, 0x00000409, 0x0, 0x0, 0x0 } },
407         { SYRIAC,                               { 0x00000409, 0x0000045a, 0x0, 0x0, 0x0 } },
408         { TAMIL,                                { 0x00000409, 0x00000449, 0x0, 0x0, 0x0 } },
409         { TATAR,                                { 0x00000444, 0x00000409, 0x00000419, 0x0, 0x0 } },
410         { TELUGU,                               { 0x00000409, 0x0000044a, 0x00010439, 0x0, 0x0 } },
411         { THAI,                                 { 0x00000409, 0x0000041e, 0x0, 0x0, 0x0 } },
412         { TSWANA,                               { 0x00000409, 0x0000041f, 0x0, 0x0, 0x0 } },
413         { UKRAINIAN,                            { 0x00000422, 0x00000409, 0x0, 0x0, 0x0 } },
414         { TURKISH,                              { 0x0000041f, 0x0000041f, 0x0, 0x0, 0x0 } },
415         { UKRAINIAN,                            { 0x00000422, 0x00000409, 0x0, 0x0, 0x0 } },
416         { URDU,                                 { 0x00000401, 0x00000409, 0x0, 0x0, 0x0 } },
417         { UZBEK_LATIN,                          { 0x00000409, 0x00000843, 0x00000419, 0x0, 0x0 } },
418         { UZBEK_CYRILLIC,                       { 0x00000843, 0x00000409, 0x00000419, 0x0, 0x0 } },
419         { VIETNAMESE,                           { 0x00000409, 0x0000042a, 0x0, 0x0, 0x0 } },
420         { WELSH,                                { 0x00000452, 0x00000809, 0x0, 0x0, 0x0 } },
421         { XHOSA,                                { 0x00000409, 0x00000409, 0x0, 0x0, 0x0 } },
422 };
423
424 unsigned int detect_keyboard_layout_from_locale()
425 {
426         int dot;
427         int i, j, k;
428         int underscore;
429         char language[4];
430         char country[10];
431
432         /* LANG = <language>_<country>.<encoding> */
433         char* envLang = getenv("LANG"); /* Get locale from environment variable LANG */
434
435         if (envLang == NULL)
436                 return 0; /* LANG environment variable was not set */
437
438         underscore = strcspn(envLang, "_");
439
440         if (underscore > 3)
441                 return 0; /* The language name should not be more than 3 letters long */
442         else
443         {
444                 /* Get language code */
445                 strncpy(language, envLang, underscore);
446                 language[underscore] = '\0';
447         }
448
449         /*
450          * There is always the special case of "C" or "POSIX" as locale name
451          * In this case, use a U.S. keyboard and a U.S. keyboard layout
452          */
453
454         if ((strcmp(language, "C") == 0) || (strcmp(language, "POSIX") == 0))
455                 return ENGLISH_UNITED_STATES; /* U.S. Keyboard Layout */
456
457         dot = strcspn(envLang, ".");
458
459         /* Get country code */
460         if (dot > underscore)
461         {
462                 strncpy(country, &envLang[underscore + 1], dot - underscore - 1);
463                 country[dot - underscore - 1] = '\0';
464         }
465         else
466                 return 0; /* Invalid locale */
467
468         for (i = 0; i < sizeof(locales) / sizeof(locale); i++)
469         {
470                 if ((strcmp(language, locales[i].language) == 0) && (strcmp(country, locales[i].country) == 0))
471                         break;
472         }
473
474         DEBUG_KBD("Found locale : %s_%s", locales[i].language, locales[i].country);
475
476         for (j = 0; j < sizeof(defaultKeyboardLayouts) / sizeof(localeAndKeyboardLayout); j++)
477         {
478                 if (defaultKeyboardLayouts[j].locale == locales[i].code)
479                 {
480                         /* Locale found in list of default keyboard layouts */
481                         for (k = 0; k < 5; k++)
482                         {
483                                 if (defaultKeyboardLayouts[j].keyboardLayouts[k] == ENGLISH_UNITED_STATES)
484                                 {
485                                         continue; /* Skip, try to get a more localized keyboard layout */
486                                 }
487                                 else if (defaultKeyboardLayouts[j].keyboardLayouts[k] == 0)
488                                 {
489                                         break; /* No more keyboard layouts */
490                                 }
491                                 else
492                                 {
493                                         return defaultKeyboardLayouts[j].keyboardLayouts[k];
494                                 }
495                         }
496
497                         /*
498                          * If we skip the ENGLISH_UNITED_STATES keyboard layout but there are no
499                          * other possible keyboard layout for the locale, we end up here with k > 1
500                          */
501
502                         if (k >= 1)
503                                 return ENGLISH_UNITED_STATES;
504                         else
505                                 return 0;
506                 }
507         }
508
509         return 0; /* Could not detect the current keyboard layout from locale */
510 }