/[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 310 by astrand, Tue Feb 4 15:54:58 2003 UTC revision 470 by astrand, Mon Sep 15 08:03:30 2003 UTC
# Line 1  Line 1 
1  /*  /*
2     rdesktop: A Remote Desktop Protocol client.     rdesktop: A Remote Desktop Protocol client.
3     User interface services - X keyboard mapping     User interface services - X keyboard mapping
4    
5     Copyright (C) Matthew Chapman 1999-2002     Copyright (C) Matthew Chapman 1999-2002
6       Copyright (C) Peter Astrand <peter@cendio.se> 2003
7        
8     This program is free software; you can redistribute it and/or modify     This program is free software; you can redistribute it and/or modify
9     it under the terms of the GNU General Public License as published by     it under the terms of the GNU General Public License as published by
# Line 12  Line 14 
14     but WITHOUT ANY WARRANTY; without even the implied warranty of     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16     GNU General Public License for more details.     GNU General Public License for more details.
17      
18     You should have received a copy of the GNU General Public License     You should have received a copy of the GNU General Public License
19     along with this program; if not, write to the Free Software     along with this program; if not, write to the Free Software
20     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */  */
22    
23    #ifdef RDP2VNC
24    #include "vnc/x11stubs.h"
25    #else
26  #include <X11/Xlib.h>  #include <X11/Xlib.h>
27  #define XK_MISCELLANY  #include <X11/keysym.h>
28  #include <X11/keysymdef.h>  #endif
29    
30  #include <ctype.h>  #include <ctype.h>
31  #include <limits.h>  #include <limits.h>
32  #include <time.h>  #include <time.h>
# Line 31  Line 37 
37  #define KEYMAP_MASK 0xffff  #define KEYMAP_MASK 0xffff
38  #define KEYMAP_MAX_LINE_LENGTH 80  #define KEYMAP_MAX_LINE_LENGTH 80
39    
40  extern Display *display;  extern Display *g_display;
41  extern char keymapname[16];  extern char keymapname[16];
42  extern int keylayout;  extern int keylayout;
43  extern BOOL enable_compose;  extern int g_win_button_size;
44    extern BOOL g_enable_compose;
45    extern BOOL g_use_rdp5;
46    
47  static BOOL keymap_loaded;  static BOOL keymap_loaded;
48  static key_translation keymap[KEYMAP_SIZE];  static key_translation keymap[KEYMAP_SIZE];
49  static int min_keycode;  static int min_keycode;
50  static uint16 remote_modifier_state = 0;  static uint16 remote_modifier_state = 0;
51    static uint16 saved_remote_modifier_state = 0;
52    
53  static void update_modifier_state(uint8 scancode, BOOL pressed);  static void update_modifier_state(uint8 scancode, BOOL pressed);
54    
# Line 51  add_to_keymap(char *keyname, uint8 scanc Line 60  add_to_keymap(char *keyname, uint8 scanc
60          keysym = XStringToKeysym(keyname);          keysym = XStringToKeysym(keyname);
61          if (keysym == NoSymbol)          if (keysym == NoSymbol)
62          {          {
63                  warning("Bad keysym %s in keymap %s\n", keyname, mapname);                  DEBUG_KBD(("Bad keysym \"%s\" in keymap %s (ignoring)\n", keyname, mapname));
64                  return;                  return;
65          }          }
66    
# Line 135  xkeymap_read(char *mapname) Line 144  xkeymap_read(char *mapname)
144                  if (strncmp(line, "enable_compose", 15) == 0)                  if (strncmp(line, "enable_compose", 15) == 0)
145                  {                  {
146                          DEBUG_KBD(("Enabling compose handling\n"));                          DEBUG_KBD(("Enabling compose handling\n"));
147                          enable_compose = True;                          g_enable_compose = True;
148                          continue;                          continue;
149                  }                  }
150    
# Line 198  xkeymap_read(char *mapname) Line 207  xkeymap_read(char *mapname)
207                          /* Automatically add uppercase key, with same modifiers                          /* Automatically add uppercase key, with same modifiers
208                             plus shift */                             plus shift */
209                          for (p = keyname; *p; p++)                          for (p = keyname; *p; p++)
210                                  *p = toupper((int)*p);                                  *p = toupper((int) *p);
211                          MASK_ADD_BITS(modifiers, MapLeftShiftMask);                          MASK_ADD_BITS(modifiers, MapLeftShiftMask);
212                          add_to_keymap(keyname, scancode, modifiers, mapname);                          add_to_keymap(keyname, scancode, modifiers, mapname);
213                  }                  }
# Line 220  xkeymap_init(void) Line 229  xkeymap_init(void)
229          mapname_ptr = keymapname;          mapname_ptr = keymapname;
230          while (*mapname_ptr)          while (*mapname_ptr)
231          {          {
232                  *mapname_ptr = tolower((int)*mapname_ptr);                  *mapname_ptr = tolower((int) *mapname_ptr);
233                  mapname_ptr++;                  mapname_ptr++;
234          }          }
235    
# Line 230  xkeymap_init(void) Line 239  xkeymap_init(void)
239                          keymap_loaded = True;                          keymap_loaded = True;
240          }          }
241    
242          XDisplayKeycodes(display, &min_keycode, (int *) &max_keycode);          XDisplayKeycodes(g_display, &min_keycode, (int *) &max_keycode);
243    }
244    
245    static void
246    send_winkey(uint32 ev_time, BOOL pressed, BOOL leftkey)
247    {
248            uint8 winkey;
249    
250            if (leftkey)
251                    winkey = SCANCODE_CHAR_LWIN;
252            else
253                    winkey = SCANCODE_CHAR_RWIN;
254    
255            if (pressed)
256            {
257                    if (g_use_rdp5)
258                    {
259                            rdp_send_scancode(ev_time, RDP_KEYPRESS, winkey);
260                    }
261                    else
262                    {
263                            /* RDP4 doesn't support winkey. Fake with Ctrl-Esc */
264                            rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_LCTRL);
265                            rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_ESC);
266                    }
267            }
268            else
269            {
270                    /* key released */
271                    if (g_use_rdp5)
272                    {
273                            rdp_send_scancode(ev_time, RDP_KEYRELEASE, winkey);
274                    }
275                    else
276                    {
277                            rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_ESC);
278                            rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LCTRL);
279                    }
280            }
281  }  }
282    
283  /* Handles, for example, multi-scancode keypresses (which is not  /* Handles, for example, multi-scancode keypresses (which is not
# Line 293  handle_special_keys(uint32 keysym, unsig Line 340  handle_special_keys(uint32 keysym, unsig
340                  case XK_Meta_L: /* Windows keys */                  case XK_Meta_L: /* Windows keys */
341                  case XK_Super_L:                  case XK_Super_L:
342                  case XK_Hyper_L:                  case XK_Hyper_L:
343                            send_winkey(ev_time, pressed, True);
344                            return True;
345    
346                  case XK_Meta_R:                  case XK_Meta_R:
347                  case XK_Super_R:                  case XK_Super_R:
348                  case XK_Hyper_R:                  case XK_Hyper_R:
349                          if (pressed)                          send_winkey(ev_time, pressed, False);
                         {  
                                 rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_LCTRL);  
                                 rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_ESC);  
                         }  
                         else  
                         {  
                                 rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_ESC);  
                                 rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LCTRL);  
                         }  
350                          return True;                          return True;
351    
352                    case XK_space:
353                            /* Prevent access to the Windows system menu in single app mode */
354                            if (g_win_button_size
355                                && (get_key_state(state, XK_Alt_L) || get_key_state(state, XK_Alt_R)))
356                                    return True;
357    
358          }          }
359          return False;          return False;
360  }  }
# Line 347  xkeymap_translate_key(uint32 keysym, uns Line 395  xkeymap_translate_key(uint32 keysym, uns
395                  warning("No translation for (keysym 0x%lx, %s)\n", keysym, get_ksname(keysym));                  warning("No translation for (keysym 0x%lx, %s)\n", keysym, get_ksname(keysym));
396    
397          /* not in keymap, try to interpret the raw scancode */          /* not in keymap, try to interpret the raw scancode */
398          if ((keycode >= min_keycode) && (keycode <= 0x60))          if (((int) keycode >= min_keycode) && (keycode <= 0x60))
399          {          {
400                  tr.scancode = keycode - min_keycode;                  tr.scancode = keycode - min_keycode;
401    
# Line 402  get_ksname(uint32 keysym) Line 450  get_ksname(uint32 keysym)
450          return ksname;          return ksname;
451  }  }
452    
453    static BOOL
454  void  is_modifier(uint8 scancode)
 ensure_remote_modifiers(uint32 ev_time, key_translation tr)  
455  {  {
456          /* If this key is a modifier, do nothing */          switch (scancode)
         switch (tr.scancode)  
457          {          {
458                  case SCANCODE_CHAR_LSHIFT:                  case SCANCODE_CHAR_LSHIFT:
459                  case SCANCODE_CHAR_RSHIFT:                  case SCANCODE_CHAR_RSHIFT:
# Line 418  ensure_remote_modifiers(uint32 ev_time, Line 464  ensure_remote_modifiers(uint32 ev_time,
464                  case SCANCODE_CHAR_LWIN:                  case SCANCODE_CHAR_LWIN:
465                  case SCANCODE_CHAR_RWIN:                  case SCANCODE_CHAR_RWIN:
466                  case SCANCODE_CHAR_NUMLOCK:                  case SCANCODE_CHAR_NUMLOCK:
467                          return;                          return True;
468                  default:                  default:
469                          break;                          break;
470          }          }
471            return False;
472    }
473    
474    void
475    save_remote_modifiers(uint8 scancode)
476    {
477            if (is_modifier(scancode))
478                    return;
479    
480            saved_remote_modifier_state = remote_modifier_state;
481    }
482    
483    void
484    restore_remote_modifiers(uint32 ev_time, uint8 scancode)
485    {
486            key_translation dummy;
487    
488            if (is_modifier(scancode))
489                    return;
490    
491            dummy.scancode = 0;
492            dummy.modifiers = saved_remote_modifier_state;
493            ensure_remote_modifiers(ev_time, dummy);
494    }
495    
496    void
497    ensure_remote_modifiers(uint32 ev_time, key_translation tr)
498    {
499            /* If this key is a modifier, do nothing */
500            if (is_modifier(tr.scancode))
501                    return;
502    
503          /* NumLock */          /* NumLock */
504          if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask)          if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask)

Legend:
Removed from v.310  
changed lines
  Added in v.470

  ViewVC Help
Powered by ViewVC 1.1.26