/[rdesktop]/jpeg/rdesktop/trunk/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 /jpeg/rdesktop/trunk/xkeymap.c

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

revision 910 by astrand, Tue Jun 7 11:21:53 2005 UTC revision 949 by astrand, Tue Aug 2 15:07:35 2005 UTC
# Line 47  extern BOOL g_use_rdp5; Line 47  extern BOOL g_use_rdp5;
47  extern BOOL g_numlock_sync;  extern BOOL g_numlock_sync;
48    
49  static BOOL keymap_loaded;  static BOOL keymap_loaded;
50  static key_translation keymap[KEYMAP_SIZE];  static key_translation *keymap[KEYMAP_SIZE];
51  static int min_keycode;  static int min_keycode;
52  static uint16 remote_modifier_state = 0;  static uint16 remote_modifier_state = 0;
53  static uint16 saved_remote_modifier_state = 0;  static uint16 saved_remote_modifier_state = 0;
# Line 58  static void Line 58  static void
58  add_to_keymap(char *keyname, uint8 scancode, uint16 modifiers, char *mapname)  add_to_keymap(char *keyname, uint8 scancode, uint16 modifiers, char *mapname)
59  {  {
60          KeySym keysym;          KeySym keysym;
61            key_translation *tr;
62    
63          keysym = XStringToKeysym(keyname);          keysym = XStringToKeysym(keyname);
64          if (keysym == NoSymbol)          if (keysym == NoSymbol)
# Line 69  add_to_keymap(char *keyname, uint8 scanc Line 70  add_to_keymap(char *keyname, uint8 scanc
70          DEBUG_KBD(("Adding translation, keysym=0x%x, scancode=0x%x, "          DEBUG_KBD(("Adding translation, keysym=0x%x, scancode=0x%x, "
71                     "modifiers=0x%x\n", (unsigned int) keysym, scancode, modifiers));                     "modifiers=0x%x\n", (unsigned int) keysym, scancode, modifiers));
72    
73          keymap[keysym & KEYMAP_MASK].scancode = scancode;          tr = (key_translation *) xmalloc(sizeof(key_translation));
74          keymap[keysym & KEYMAP_MASK].modifiers = modifiers;          memset(tr, 0, sizeof(key_translation));
75            tr->scancode = scancode;
76            tr->modifiers = modifiers;
77            keymap[keysym & KEYMAP_MASK] = tr;
78    
79          return;          return;
80  }  }
81    
82    static void
83    add_sequence(char *rest, char *mapname)
84    {
85            KeySym keysym;
86            key_translation *tr, **prev_next;
87            size_t chars;
88            char keyname[KEYMAP_MAX_LINE_LENGTH];
89    
90            /* Skip over whitespace after the sequence keyword */
91            chars = strspn(rest, " \t");
92            rest += chars;
93    
94            /* Fetch the keysym name */
95            chars = strcspn(rest, " \t\0");
96            STRNCPY(keyname, rest, chars + 1);
97            rest += chars;
98    
99            keysym = XStringToKeysym(keyname);
100            if (keysym == NoSymbol)
101            {
102                    DEBUG_KBD(("Bad keysym \"%s\" in keymap %s (ignoring line)\n", keyname, mapname));
103                    return;
104            }
105    
106    
107            DEBUG_KBD(("Adding sequence for keysym (0x%lx, %s) -> ", keysym, keyname));
108    
109            prev_next = &keymap[keysym & KEYMAP_MASK];
110    
111            while (*rest)
112            {
113                    /* Skip whitespace */
114                    chars = strspn(rest, " \t");
115                    rest += chars;
116    
117                    /* Fetch the keysym name */
118                    chars = strcspn(rest, " \t\0");
119                    STRNCPY(keyname, rest, chars + 1);
120                    rest += chars;
121    
122                    keysym = XStringToKeysym(keyname);
123                    if (keysym == NoSymbol)
124                    {
125                            DEBUG_KBD(("Bad keysym \"%s\" in keymap %s (ignoring line)\n", keyname,
126                                       mapname));
127                            return;
128                    }
129    
130                    /* Allocate space for key_translation structure */
131                    tr = (key_translation *) xmalloc(sizeof(key_translation));
132                    memset(tr, 0, sizeof(key_translation));
133                    *prev_next = tr;
134                    prev_next = &tr->next;
135                    tr->seq_keysym = keysym;
136    
137                    DEBUG_KBD(("0x%x, ", (unsigned int) keysym));
138            }
139            DEBUG_KBD(("\n"));
140    }
141    
142    
143  static BOOL  static BOOL
144  xkeymap_read(char *mapname)  xkeymap_read(char *mapname)
# Line 150  xkeymap_read(char *mapname) Line 214  xkeymap_read(char *mapname)
214                          continue;                          continue;
215                  }                  }
216    
217                    /* sequence */
218                    if (strncmp(line, "sequence", 8) == 0)
219                    {
220                            add_sequence(line + 8, mapname);
221                            continue;
222                    }
223    
224                  /* Comment */                  /* Comment */
225                  if (line[0] == '#')                  if (line[0] == '#')
226                  {                  {
# Line 391  handle_special_keys(uint32 keysym, unsig Line 462  handle_special_keys(uint32 keysym, unsig
462  key_translation  key_translation
463  xkeymap_translate_key(uint32 keysym, unsigned int keycode, unsigned int state)  xkeymap_translate_key(uint32 keysym, unsigned int keycode, unsigned int state)
464  {  {
465          key_translation tr = { 0, 0 };          key_translation tr = { 0, 0, 0, 0 };
466            key_translation *ptr;
         tr = keymap[keysym & KEYMAP_MASK];  
   
         if (tr.modifiers & MapInhibitMask)  
         {  
                 DEBUG_KBD(("Inhibiting key\n"));  
                 tr.scancode = 0;  
                 return tr;  
         }  
467    
468          if (tr.modifiers & MapLocalStateMask)          ptr = keymap[keysym & KEYMAP_MASK];
469            if (ptr)
470          {          {
471                  /* The modifiers to send for this key should be obtained                  tr = *ptr;
472                     from the local state. Currently, only shift is implemented. */                  if (tr.seq_keysym == 0) /* Normal scancode translation */
                 if (state & ShiftMask)  
473                  {                  {
474                          tr.modifiers = MapLeftShiftMask;                          if (tr.modifiers & MapInhibitMask)
475                            {
476                                    DEBUG_KBD(("Inhibiting key\n"));
477                                    tr.scancode = 0;
478                                    return tr;
479                            }
480    
481                            if (tr.modifiers & MapLocalStateMask)
482                            {
483                                    /* The modifiers to send for this key should be obtained
484                                       from the local state. Currently, only shift is implemented. */
485                                    if (state & ShiftMask)
486                                    {
487                                            tr.modifiers = MapLeftShiftMask;
488                                    }
489                            }
490    
491                            if ((tr.modifiers & MapLeftShiftMask)
492                                && ((remote_modifier_state & MapLeftCtrlMask)
493                                    || (remote_modifier_state & MapRightCtrlMask))
494                                && get_key_state(state, XK_Caps_Lock))
495                            {
496                                    DEBUG_KBD(("CapsLock + Ctrl pressed, releasing LeftShift\n"));
497                                    tr.modifiers ^= MapLeftShiftMask;
498                            }
499    
500                            DEBUG_KBD(("Found scancode translation, scancode=0x%x, modifiers=0x%x\n",
501                                       tr.scancode, tr.modifiers));
502                  }                  }
503          }          }
504            else
         if ((tr.modifiers & MapLeftShiftMask) && ((remote_modifier_state & MapLeftCtrlMask)  
                                                   || (remote_modifier_state & MapRightCtrlMask))  
             && get_key_state(state, XK_Caps_Lock))  
505          {          {
506                  DEBUG_KBD(("CapsLock + Ctrl pressed, releasing LeftShift\n"));                  if (keymap_loaded)
507                  tr.modifiers ^= MapLeftShiftMask;                          warning("No translation for (keysym 0x%lx, %s)\n", keysym,
508          }                                  get_ksname(keysym));
509    
510                    /* not in keymap, try to interpret the raw scancode */
511                    if (((int) keycode >= min_keycode) && (keycode <= 0x60))
512                    {
513                            tr.scancode = keycode - min_keycode;
514    
515                            /* The modifiers to send for this key should be
516                               obtained from the local state. Currently, only
517                               shift is implemented. */
518                            if (state & ShiftMask)
519                            {
520                                    tr.modifiers = MapLeftShiftMask;
521                            }
522    
523          if (tr.scancode != 0)                          DEBUG_KBD(("Sending guessed scancode 0x%x\n", tr.scancode));
524          {                  }
525                  DEBUG_KBD(("Found key translation, scancode=0x%x, modifiers=0x%x\n",                  else
526                             tr.scancode, tr.modifiers));                  {
527                  return tr;                          DEBUG_KBD(("No good guess for keycode 0x%x found\n", keycode));
528                    }
529          }          }
530    
531          if (keymap_loaded)          return tr;
532                  warning("No translation for (keysym 0x%lx, %s)\n", keysym, get_ksname(keysym));  }
533    
534    void
535    xkeymap_send_keys(uint32 keysym, unsigned int keycode, unsigned int state, uint32 ev_time,
536                      BOOL pressed)
537    {
538            key_translation tr, *ptr;
539            tr = xkeymap_translate_key(keysym, keycode, state);
540    
541          /* not in keymap, try to interpret the raw scancode */          if (tr.seq_keysym == 0)
         if (((int) keycode >= min_keycode) && (keycode <= 0x60))  
542          {          {
543                  tr.scancode = keycode - min_keycode;                  /* Scancode translation */
544                    if (tr.scancode == 0)
545                            return;
546    
547                  /* The modifiers to send for this key should be                  if (pressed)
                    obtained from the local state. Currently, only  
                    shift is implemented. */  
                 if (state & ShiftMask)  
548                  {                  {
549                          tr.modifiers = MapLeftShiftMask;                          save_remote_modifiers(tr.scancode);
550                            ensure_remote_modifiers(ev_time, tr);
551                            rdp_send_scancode(ev_time, RDP_KEYPRESS, tr.scancode);
552                            restore_remote_modifiers(ev_time, tr.scancode);
553                  }                  }
554                    else
555                  DEBUG_KBD(("Sending guessed scancode 0x%x\n", tr.scancode));                  {
556                            rdp_send_scancode(ev_time, RDP_KEYRELEASE, tr.scancode);
557                    }
558                    return;
559          }          }
560          else  
561            /* Sequence, only on key down */
562            if (pressed)
563          {          {
564                  DEBUG_KBD(("No good guess for keycode 0x%x found\n", keycode));                  ptr = &tr;
565                    do
566                    {
567                            DEBUG_KBD(("Handling sequence element, keysym=0x%x\n",
568                                       (unsigned int) ptr->seq_keysym));
569                            xkeymap_send_keys(ptr->seq_keysym, keycode, state, ev_time, True);
570                            xkeymap_send_keys(ptr->seq_keysym, keycode, state, ev_time, False);
571                            ptr = ptr->next;
572                    }
573                    while (ptr);
574          }          }
   
         return tr;  
575  }  }
576    
577  uint16  uint16

Legend:
Removed from v.910  
changed lines
  Added in v.949

  ViewVC Help
Powered by ViewVC 1.1.26