/[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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 56 - (hide annotations)
Fri Jul 12 22:40:32 2002 UTC (21 years, 10 months ago) by jsorg71
File MIME type: text/plain
File size: 4288 byte(s)
added wheel mouse support

1 matthewc 38 /*
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 matthewc 39 #include <limits.h>
27 matthewc 38 #include "rdesktop.h"
28    
29     #define KEYMAP_SIZE 4096
30     #define KEYMAP_MASK (KEYMAP_SIZE - 1)
31    
32 matthewc 50 extern Display *display;
33 matthewc 38 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 xkeymap_read(char *mapname)
40     {
41     FILE *fp;
42 matthewc 39 char line[PATH_MAX], path[PATH_MAX];
43 matthewc 38 char *keyname, *p;
44     KeySym keysym;
45     unsigned char keycode;
46    
47     strcpy(path, KEYMAP_PATH);
48     strncat(path, mapname, sizeof(path) - sizeof(KEYMAP_PATH));
49    
50     fp = fopen(path, "r");
51     if (fp == NULL)
52     {
53     error("Failed to open keymap %s\n", path);
54     return False;
55     }
56    
57     while (fgets(line, sizeof(line), fp) != NULL)
58     {
59     p = strchr(line, '\n');
60     if (p != NULL)
61     *p = 0;
62    
63     keycode = strtol(line, &keyname, 16);
64     if ((keycode != 0) && (*keyname == ' '))
65     {
66     do
67     {
68     keyname++;
69     p = strchr(keyname, ' ');
70     if (p != NULL)
71     *p = 0;
72    
73     keysym = XStringToKeysym(keyname);
74     if (keysym == NoSymbol)
75     error("Bad keysym %s in keymap %s\n", keyname, mapname);
76    
77     keymap[keysym & KEYMAP_MASK] = keycode;
78     keyname = p;
79    
80     } while (keyname != NULL);
81     }
82     else if (strncmp(line, "include ", 8) == 0)
83     {
84     if (!xkeymap_read(line+8))
85     return False;
86     }
87     else if (strncmp(line, "map ", 4) == 0)
88     {
89     keylayout = strtol(line+4, NULL, 16);
90     }
91     else if (line[0] != '#')
92     {
93     error("Malformed line in keymap %s\n", mapname);
94     }
95     }
96    
97     fclose(fp);
98     return True;
99     }
100    
101 matthewc 50 void xkeymap_init(void)
102 matthewc 38 {
103     unsigned int max_keycode;
104    
105     XDisplayKeycodes(display, &min_keycode, &max_keycode);
106    
107     if (strcmp(keymapname, "none"))
108     xkeymap_read(keymapname);
109     }
110    
111 matthewc 50 uint8 xkeymap_translate_key(unsigned int keysym, unsigned int keycode, uint16 *flags)
112 matthewc 38 {
113     uint8 scancode;
114    
115     scancode = keymap[keysym & KEYMAP_MASK];
116     if (scancode != 0)
117 matthewc 50 {
118     if (scancode & 0x80)
119     *flags |= KBD_FLAG_EXT;
120 matthewc 38
121 matthewc 50 return (scancode & 0x7f);
122     }
123    
124 matthewc 38 /* not in keymap, try to interpret the raw scancode */
125    
126     if ((keycode >= min_keycode) && (keycode <= 0x60))
127     return (uint8)(keycode - min_keycode);
128    
129 matthewc 50 *flags |= KBD_FLAG_EXT;
130    
131 matthewc 38 switch (keycode)
132     {
133     case 0x61: /* home */
134 matthewc 50 return 0x47;
135 matthewc 38 case 0x62: /* up arrow */
136 matthewc 50 return 0x48;
137 matthewc 38 case 0x63: /* page up */
138 matthewc 50 return 0x49;
139 matthewc 38 case 0x64: /* left arrow */
140 matthewc 50 return 0x4b;
141 matthewc 38 case 0x66: /* right arrow */
142 matthewc 50 return 0x4d;
143 matthewc 38 case 0x67: /* end */
144 matthewc 50 return 0x4f;
145 matthewc 38 case 0x68: /* down arrow */
146 matthewc 50 return 0x50;
147 matthewc 38 case 0x69: /* page down */
148 matthewc 50 return 0x51;
149 matthewc 38 case 0x6a: /* insert */
150 matthewc 50 return 0x52;
151 matthewc 38 case 0x6b: /* delete */
152 matthewc 50 return 0x53;
153 matthewc 38 case 0x6c: /* keypad enter */
154 matthewc 50 return 0x1c;
155 matthewc 38 case 0x6d: /* right ctrl */
156 matthewc 50 return 0x1d;
157 matthewc 38 case 0x6f: /* ctrl - print screen */
158 matthewc 50 return 0x37;
159 matthewc 38 case 0x70: /* keypad '/' */
160 matthewc 50 return 0x35;
161 matthewc 38 case 0x71: /* right alt */
162 matthewc 50 return 0x38;
163 matthewc 38 case 0x72: /* ctrl break */
164 matthewc 50 return 0x46;
165 matthewc 38 case 0x73: /* left window key */
166 matthewc 50 return 0x5b;
167 matthewc 38 case 0x74: /* right window key */
168 matthewc 50 return 0x5c;
169 matthewc 38 case 0x75: /* menu key */
170 matthewc 50 return 0x5d;
171 matthewc 38 }
172    
173     return 0;
174     }
175    
176     uint16 xkeymap_translate_button(unsigned int button)
177     {
178     switch (button)
179     {
180     case Button1: /* left */
181     return MOUSE_FLAG_BUTTON1;
182     case Button2: /* middle */
183     return MOUSE_FLAG_BUTTON3;
184     case Button3: /* right */
185     return MOUSE_FLAG_BUTTON2;
186 jsorg71 56 case Button4: /* wheel up */
187     return MOUSE_FLAG_BUTTON4;
188     case Button5: /* wheel down */
189     return MOUSE_FLAG_BUTTON5;
190 matthewc 38 }
191    
192     return 0;
193     }

  ViewVC Help
Powered by ViewVC 1.1.26