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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 39 by matthewc, Fri Apr 5 07:57:43 2002 UTC revision 64 by astrand, Thu Jul 18 16:38:31 2002 UTC
# Line 29  Line 29 
29  #define KEYMAP_SIZE 4096  #define KEYMAP_SIZE 4096
30  #define KEYMAP_MASK (KEYMAP_SIZE - 1)  #define KEYMAP_MASK (KEYMAP_SIZE - 1)
31    
32    extern Display *display;
33  extern char keymapname[16];  extern char keymapname[16];
34  extern int keylayout;  extern int keylayout;
35    
36  static uint8 keymap[KEYMAP_SIZE];  static uint8 keymap[KEYMAP_SIZE];
37  static unsigned int min_keycode;  static unsigned int min_keycode;
38    
39  static BOOL xkeymap_read(char *mapname)  static BOOL
40    xkeymap_read(char *mapname)
41  {  {
42          FILE *fp;          FILE *fp;
43          char line[PATH_MAX], path[PATH_MAX];          char line[PATH_MAX], path[PATH_MAX];
44          char *keyname, *p;          char *keyname, *p;
45          KeySym keysym;          KeySym keysym;
46          unsigned char keycode;          unsigned char keycode;
         unsigned int mapcode = 0;  
47    
48          strcpy(path, KEYMAP_PATH);          strcpy(path, KEYMAP_PATH);
49          strncat(path, mapname, sizeof(path) - sizeof(KEYMAP_PATH));          strncat(path, mapname, sizeof(path) - sizeof(KEYMAP_PATH));
# Line 72  static BOOL xkeymap_read(char *mapname) Line 73  static BOOL xkeymap_read(char *mapname)
73    
74                                  keysym = XStringToKeysym(keyname);                                  keysym = XStringToKeysym(keyname);
75                                  if (keysym == NoSymbol)                                  if (keysym == NoSymbol)
76                                          error("Bad keysym %s in keymap %s\n", keyname, mapname);                                          error("Bad keysym %s in keymap %s\n",
77                                                  keyname, mapname);
78    
79                                  keymap[keysym & KEYMAP_MASK] = keycode;                                  keymap[keysym & KEYMAP_MASK] = keycode;
80                                  keyname = p;                                  keyname = p;
81    
82                          } while (keyname != NULL);                          }
83                            while (keyname != NULL);
84                  }                  }
85                  else if (strncmp(line, "include ", 8) == 0)                  else if (strncmp(line, "include ", 8) == 0)
86                  {                  {
87                          if (!xkeymap_read(line+8))                          if (!xkeymap_read(line + 8))
88                                  return False;                                  return False;
89                  }                  }
90                  else if (strncmp(line, "map ", 4) == 0)                  else if (strncmp(line, "map ", 4) == 0)
91                  {                  {
92                          keylayout = strtol(line+4, NULL, 16);                          keylayout = strtol(line + 4, NULL, 16);
93                  }                  }
94                  else if (line[0] != '#')                  else if (line[0] != '#')
95                  {                  {
# Line 98  static BOOL xkeymap_read(char *mapname) Line 101  static BOOL xkeymap_read(char *mapname)
101          return True;          return True;
102  }  }
103    
104  void xkeymap_init(Display *display)  void
105    xkeymap_init(void)
106  {  {
107          unsigned int max_keycode;          unsigned int max_keycode;
108    
# Line 108  void xkeymap_init(Display *display) Line 112  void xkeymap_init(Display *display)
112                  xkeymap_read(keymapname);                  xkeymap_read(keymapname);
113  }  }
114    
115  uint8 xkeymap_translate_key(KeySym keysym, unsigned int keycode)  uint8
116    xkeymap_translate_key(unsigned int keysym, unsigned int keycode,
117                          uint16 * flags)
118  {  {
119          uint8 scancode;          uint8 scancode;
120    
121          scancode = keymap[keysym & KEYMAP_MASK];          scancode = keymap[keysym & KEYMAP_MASK];
122          if (scancode != 0)          if (scancode != 0)
123                  return scancode;          {
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 */          /* not in keymap, try to interpret the raw scancode */
131    
132          if ((keycode >= min_keycode) && (keycode <= 0x60))          if ((keycode >= min_keycode) && (keycode <= 0x60))
133                  return (uint8)(keycode - min_keycode);                  return (uint8) (keycode - min_keycode);
134    
135            *flags |= KBD_FLAG_EXT;
136    
137          switch (keycode)          switch (keycode)
138          {          {
139                  case 0x61:      /* home */                  case 0x61:      /* home */
140                          return 0x47 | 0x80;                          return 0x47;
141                  case 0x62:      /* up arrow */                  case 0x62:      /* up arrow */
142                          return 0x48 | 0x80;                          return 0x48;
143                  case 0x63:      /* page up */                  case 0x63:      /* page up */
144                          return 0x49 | 0x80;                          return 0x49;
145                  case 0x64:      /* left arrow */                  case 0x64:      /* left arrow */
146                          return 0x4b | 0x80;                          return 0x4b;
147                  case 0x66:      /* right arrow */                  case 0x66:      /* right arrow */
148                          return 0x4d | 0x80;                          return 0x4d;
149                  case 0x67:      /* end */                  case 0x67:      /* end */
150                          return 0x4f | 0x80;                          return 0x4f;
151                  case 0x68:      /* down arrow */                  case 0x68:      /* down arrow */
152                          return 0x50 | 0x80;                          return 0x50;
153                  case 0x69:      /* page down */                  case 0x69:      /* page down */
154                          return 0x51 | 0x80;                          return 0x51;
155                  case 0x6a:      /* insert */                  case 0x6a:      /* insert */
156                          return 0x52 | 0x80;                          return 0x52;
157                  case 0x6b:      /* delete */                  case 0x6b:      /* delete */
158                          return 0x53 | 0x80;                          return 0x53;
159                  case 0x6c:      /* keypad enter */                  case 0x6c:      /* keypad enter */
160                          return 0x1c | 0x80;                          return 0x1c;
161                  case 0x6d:      /* right ctrl */                  case 0x6d:      /* right ctrl */
162                          return 0x1d | 0x80;                          return 0x1d;
163                  case 0x6f:      /* ctrl - print screen */                  case 0x6f:      /* ctrl - print screen */
164                          return 0x37 | 0x80;                          return 0x37;
165                  case 0x70:      /* keypad '/' */                  case 0x70:      /* keypad '/' */
166                          return 0x35 | 0x80;                          return 0x35;
167                  case 0x71:      /* right alt */                  case 0x71:      /* right alt */
168                          return 0x38 | 0x80;                          return 0x38;
169                  case 0x72:      /* ctrl break */                  case 0x72:      /* ctrl break */
170                          return 0x46 | 0x80;                          return 0x46;
171                  case 0x73:      /* left window key */                  case 0x73:      /* left window key */
172                          return 0x5b | 0x80;                          return 0x5b;
173                  case 0x74:      /* right window key */                  case 0x74:      /* right window key */
174                          return 0x5c | 0x80;                          return 0x5c;
175                  case 0x75:      /* menu key */                  case 0x75:      /* menu key */
176                          return 0x5d | 0x80;                          return 0x5d;
177          }          }
178    
179          return 0;          return 0;
180  }  }
181    
182  uint16 xkeymap_translate_button(unsigned int button)  uint16
183    xkeymap_translate_button(unsigned int button)
184  {  {
185          switch (button)          switch (button)
186          {          {
187                  case Button1:   /* left */                  case Button1:   /* left */
188                          return MOUSE_FLAG_BUTTON1;                          return MOUSE_FLAG_BUTTON1;
189                  case Button2:   /* middle */                  case Button2:   /* middle */
190                          return MOUSE_FLAG_BUTTON3;                          return MOUSE_FLAG_BUTTON3;
191                  case Button3:   /* right */                  case Button3:   /* right */
192                          return MOUSE_FLAG_BUTTON2;                          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;          return 0;

Legend:
Removed from v.39  
changed lines
  Added in v.64

  ViewVC Help
Powered by ViewVC 1.1.26