Added keysym to unicode translation mechanisms.
[libguac-client-rdp.git] / src / unicode_convtable.c
1 /**
2  * Copyright (C) 2012 Ulteo SAS
3  * http://www.ulteo.com
4  * Author Jocelyn DELALANDE <j.delalande@ulteo.com> 2012
5  *
6  * This program is free software; you can redistribute it and/or 
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; version 2
9  * of the License.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19  **/
20
21
22 #include "unicode_convtable.h"
23
24 int keysym2uni(int keysym) {
25         init_unicode_tables();
26         /* Default: no exception */
27         int exception = 0;
28
29         if (keysym < 0x100000) {
30                 // Look for a 4-digits-form exception
31                 exception =  keysym2uni_base[keysym];
32         } else {
33                 // Look for a 7-digits-form exception
34                 /* Switch to look for 0x1001XXX 0x1002XXX or 0x1002XXX 
35                    the tables only indexes on XXX
36                  */
37                 switch(keysym & 0xFFFF000) {
38                 case 0x1000000:
39                         exception = keysym2uni_ext0[keysym & 0x0000FFF];
40                         break;
41                 case 0x1001000:
42                         exception = keysym2uni_ext1[keysym & 0x0000FFF];
43                         break;
44                 case 0x1002000:
45                         exception = keysym2uni_ext2[keysym & 0x0000FFF];
46                         break;
47                 }
48
49                 /* If the keysym is not within exceptions, keysym = unicode */
50         }
51         if (exception != 0) {
52                 return exception;
53         } else {
54                 return keysym;
55         }
56 }