/[rdesktop]/sourceforge.net/trunk/rdesktop/xkeymap.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /sourceforge.net/trunk/rdesktop/xkeymap.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 64 - (show annotations)
Thu Jul 18 16:38:31 2002 UTC (21 years, 10 months ago) by astrand
File MIME type: text/plain
File size: 4306 byte(s)
Fixed indentation with indent

1 /*
2 rdesktop: A Remote Desktop Protocol client.
3 User interface services - X keyboard mapping
4 Copyright (C) Matthew Chapman 1999-2001
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
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., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #include <X11/Xlib.h>
22 #include <X11/keysym.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <limits.h>
27 #include "rdesktop.h"
28
29 #define KEYMAP_SIZE 4096
30 #define KEYMAP_MASK (KEYMAP_SIZE - 1)
31
32 extern Display *display;
33 extern char keymapname[16];
34 extern int keylayout;
35
36 static uint8 keymap[KEYMAP_SIZE];
37 static unsigned int min_keycode;
38
39 static BOOL
40 xkeymap_read(char *mapname)
41 {
42 FILE *fp;
43 char line[PATH_MAX], path[PATH_MAX];
44 char *keyname, *p;
45 KeySym keysym;
46 unsigned char keycode;
47
48 strcpy(path, KEYMAP_PATH);
49 strncat(path, mapname, sizeof(path) - sizeof(KEYMAP_PATH));
50
51 fp = fopen(path, "r");
52 if (fp == NULL)
53 {
54 error("Failed to open keymap %s\n", path);
55 return False;
56 }
57
58 while (fgets(line, sizeof(line), fp) != NULL)
59 {
60 p = strchr(line, '\n');
61 if (p != NULL)
62 *p = 0;
63
64 keycode = strtol(line, &keyname, 16);
65 if ((keycode != 0) && (*keyname == ' '))
66 {
67 do
68 {
69 keyname++;
70 p = strchr(keyname, ' ');
71 if (p != NULL)
72 *p = 0;
73
74 keysym = XStringToKeysym(keyname);
75 if (keysym == NoSymbol)
76 error("Bad keysym %s in keymap %s\n",
77 keyname, mapname);
78
79 keymap[keysym & KEYMAP_MASK] = keycode;
80 keyname = p;
81
82 }
83 while (keyname != NULL);
84 }
85 else if (strncmp(line, "include ", 8) == 0)
86 {
87 if (!xkeymap_read(line + 8))
88 return False;
89 }
90 else if (strncmp(line, "map ", 4) == 0)
91 {
92 keylayout = strtol(line + 4, NULL, 16);
93 }
94 else if (line[0] != '#')
95 {
96 error("Malformed line in keymap %s\n", mapname);
97 }
98 }
99
100 fclose(fp);
101 return True;
102 }
103
104 void
105 xkeymap_init(void)
106 {
107 unsigned int max_keycode;
108
109 XDisplayKeycodes(display, &min_keycode, &max_keycode);
110
111 if (strcmp(keymapname, "none"))
112 xkeymap_read(keymapname);
113 }
114
115 uint8
116 xkeymap_translate_key(unsigned int keysym, unsigned int keycode,
117 uint16 * flags)
118 {
119 uint8 scancode;
120
121 scancode = keymap[keysym & KEYMAP_MASK];
122 if (scancode != 0)
123 {
124 if (scancode & 0x80)
125 *flags |= KBD_FLAG_EXT;
126
127 return (scancode & 0x7f);
128 }
129
130 /* not in keymap, try to interpret the raw scancode */
131
132 if ((keycode >= min_keycode) && (keycode <= 0x60))
133 return (uint8) (keycode - min_keycode);
134
135 *flags |= KBD_FLAG_EXT;
136
137 switch (keycode)
138 {
139 case 0x61: /* home */
140 return 0x47;
141 case 0x62: /* up arrow */
142 return 0x48;
143 case 0x63: /* page up */
144 return 0x49;
145 case 0x64: /* left arrow */
146 return 0x4b;
147 case 0x66: /* right arrow */
148 return 0x4d;
149 case 0x67: /* end */
150 return 0x4f;
151 case 0x68: /* down arrow */
152 return 0x50;
153 case 0x69: /* page down */
154 return 0x51;
155 case 0x6a: /* insert */
156 return 0x52;
157 case 0x6b: /* delete */
158 return 0x53;
159 case 0x6c: /* keypad enter */
160 return 0x1c;
161 case 0x6d: /* right ctrl */
162 return 0x1d;
163 case 0x6f: /* ctrl - print screen */
164 return 0x37;
165 case 0x70: /* keypad '/' */
166 return 0x35;
167 case 0x71: /* right alt */
168 return 0x38;
169 case 0x72: /* ctrl break */
170 return 0x46;
171 case 0x73: /* left window key */
172 return 0x5b;
173 case 0x74: /* right window key */
174 return 0x5c;
175 case 0x75: /* menu key */
176 return 0x5d;
177 }
178
179 return 0;
180 }
181
182 uint16
183 xkeymap_translate_button(unsigned int button)
184 {
185 switch (button)
186 {
187 case Button1: /* left */
188 return MOUSE_FLAG_BUTTON1;
189 case Button2: /* middle */
190 return MOUSE_FLAG_BUTTON3;
191 case Button3: /* right */
192 return MOUSE_FLAG_BUTTON2;
193 case Button4: /* wheel up */
194 return MOUSE_FLAG_BUTTON4;
195 case Button5: /* wheel down */
196 return MOUSE_FLAG_BUTTON5;
197 }
198
199 return 0;
200 }

  ViewVC Help
Powered by ViewVC 1.1.26