/[rdesktop]/sourceforge.net/branches/seamlessrdp-branch/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/branches/seamlessrdp-branch/rdesktop/xkeymap.c

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

revision 828 by stargo, Sun Mar 6 21:11:18 2005 UTC revision 951 by astrand, Tue Aug 2 18:07:56 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;
54    
55  static void update_modifier_state(uint8 scancode, BOOL pressed);  static void update_modifier_state(uint8 scancode, BOOL pressed);
56    
57    /* Free key_translation structure, included linked list */
58    void
59    free_key_translation(key_translation * ptr)
60    {
61            key_translation *next;
62    
63            while (ptr)
64            {
65                    next = ptr->next;
66                    xfree(ptr);
67                    ptr = next;
68            }
69    }
70    
71  static void  static void
72  add_to_keymap(char *keyname, uint8 scancode, uint16 modifiers, char *mapname)  add_to_keymap(char *keyname, uint8 scancode, uint16 modifiers, char *mapname)
73  {  {
74          KeySym keysym;          KeySym keysym;
75            key_translation *tr;
76    
77          keysym = XStringToKeysym(keyname);          keysym = XStringToKeysym(keyname);
78          if (keysym == NoSymbol)          if (keysym == NoSymbol)
# Line 69  add_to_keymap(char *keyname, uint8 scanc Line 84  add_to_keymap(char *keyname, uint8 scanc
84          DEBUG_KBD(("Adding translation, keysym=0x%x, scancode=0x%x, "          DEBUG_KBD(("Adding translation, keysym=0x%x, scancode=0x%x, "
85                     "modifiers=0x%x\n", (unsigned int) keysym, scancode, modifiers));                     "modifiers=0x%x\n", (unsigned int) keysym, scancode, modifiers));
86    
87          keymap[keysym & KEYMAP_MASK].scancode = scancode;          tr = (key_translation *) xmalloc(sizeof(key_translation));
88          keymap[keysym & KEYMAP_MASK].modifiers = modifiers;          memset(tr, 0, sizeof(key_translation));
89            tr->scancode = scancode;
90            tr->modifiers = modifiers;
91            free_key_translation(keymap[keysym & KEYMAP_MASK]);
92            keymap[keysym & KEYMAP_MASK] = tr;
93    
94          return;          return;
95  }  }
96    
97    static void
98    add_sequence(char *rest, char *mapname)
99    {
100            KeySym keysym;
101            key_translation *tr, **prev_next;
102            size_t chars;
103            char keyname[KEYMAP_MAX_LINE_LENGTH];
104    
105            /* Skip over whitespace after the sequence keyword */
106            chars = strspn(rest, " \t");
107            rest += chars;
108    
109            /* Fetch the keysym name */
110            chars = strcspn(rest, " \t\0");
111            STRNCPY(keyname, rest, chars + 1);
112            rest += chars;
113    
114            keysym = XStringToKeysym(keyname);
115            if (keysym == NoSymbol)
116            {
117                    DEBUG_KBD(("Bad keysym \"%s\" in keymap %s (ignoring line)\n", keyname, mapname));
118                    return;
119            }
120    
121    
122            DEBUG_KBD(("Adding sequence for keysym (0x%lx, %s) -> ", keysym, keyname));
123    
124            free_key_translation(keymap[keysym & KEYMAP_MASK]);
125            prev_next = &keymap[keysym & KEYMAP_MASK];
126    
127            while (*rest)
128            {
129                    /* Skip whitespace */
130                    chars = strspn(rest, " \t");
131                    rest += chars;
132    
133                    /* Fetch the keysym name */
134                    chars = strcspn(rest, " \t\0");
135                    STRNCPY(keyname, rest, chars + 1);
136                    rest += chars;
137    
138                    keysym = XStringToKeysym(keyname);
139                    if (keysym == NoSymbol)
140                    {
141                            DEBUG_KBD(("Bad keysym \"%s\" in keymap %s (ignoring line)\n", keyname,
142                                       mapname));
143                            return;
144                    }
145    
146                    /* Allocate space for key_translation structure */
147                    tr = (key_translation *) xmalloc(sizeof(key_translation));
148                    memset(tr, 0, sizeof(key_translation));
149                    *prev_next = tr;
150                    prev_next = &tr->next;
151                    tr->seq_keysym = keysym;
152    
153                    DEBUG_KBD(("0x%x, ", (unsigned int) keysym));
154            }
155            DEBUG_KBD(("\n"));
156    }
157    
158  static BOOL  static BOOL
159  xkeymap_read(char *mapname)  xkeymap_read(char *mapname)
# Line 150  xkeymap_read(char *mapname) Line 229  xkeymap_read(char *mapname)
229                          continue;                          continue;
230                  }                  }
231    
232                    /* sequence */
233                    if (strncmp(line, "sequence", 8) == 0)
234                    {
235                            add_sequence(line + 8, mapname);
236                            continue;
237                    }
238    
239                  /* Comment */                  /* Comment */
240                  if (line[0] == '#')                  if (line[0] == '#')
241                  {                  {
# Line 372  handle_special_keys(uint32 keysym, unsig Line 458  handle_special_keys(uint32 keysym, unsig
458                              && (get_key_state(state, XK_Alt_L) || get_key_state(state, XK_Alt_R)))                              && (get_key_state(state, XK_Alt_L) || get_key_state(state, XK_Alt_R)))
459                                  return True;                                  return True;
460                          break;                          break;
461    
462                  case XK_Num_Lock:                  case XK_Num_Lock:
463                          /* FIXME: We might want to do RDP_INPUT_SYNCHRONIZE here, if g_numlock_sync */                          /* Synchronize on key release */
464                          if (!g_numlock_sync)                          if (g_numlock_sync && !pressed)
465                                  /* Inhibit */                                  rdp_send_input(0, RDP_INPUT_SYNCHRONIZE, 0,
466                                  return True;                                                 ui_get_numlock_state(read_keyboard_state()), 0);
467    
468                            /* Inhibit */
469                            return True;
470                          break;                          break;
471    
472          }          }
# Line 387  handle_special_keys(uint32 keysym, unsig Line 477  handle_special_keys(uint32 keysym, unsig
477  key_translation  key_translation
478  xkeymap_translate_key(uint32 keysym, unsigned int keycode, unsigned int state)  xkeymap_translate_key(uint32 keysym, unsigned int keycode, unsigned int state)
479  {  {
480          key_translation tr = { 0, 0 };          key_translation tr = { 0, 0, 0, 0 };
481            key_translation *ptr;
482    
483          tr = keymap[keysym & KEYMAP_MASK];          ptr = keymap[keysym & KEYMAP_MASK];
484            if (ptr)
         if (tr.modifiers & MapInhibitMask)  
485          {          {
486                  DEBUG_KBD(("Inhibiting key\n"));                  tr = *ptr;
487                  tr.scancode = 0;                  if (tr.seq_keysym == 0) /* Normal scancode translation */
                 return tr;  
         }  
   
         if (tr.modifiers & MapLocalStateMask)  
         {  
                 /* The modifiers to send for this key should be obtained  
                    from the local state. Currently, only shift is implemented. */  
                 if (state & ShiftMask)  
488                  {                  {
489                          tr.modifiers = MapLeftShiftMask;                          if (tr.modifiers & MapInhibitMask)
490                            {
491                                    DEBUG_KBD(("Inhibiting key\n"));
492                                    tr.scancode = 0;
493                                    return tr;
494                            }
495    
496                            if (tr.modifiers & MapLocalStateMask)
497                            {
498                                    /* The modifiers to send for this key should be obtained
499                                       from the local state. Currently, only shift is implemented. */
500                                    if (state & ShiftMask)
501                                    {
502                                            tr.modifiers = MapLeftShiftMask;
503                                    }
504                            }
505    
506                            if ((tr.modifiers & MapLeftShiftMask)
507                                && ((remote_modifier_state & MapLeftCtrlMask)
508                                    || (remote_modifier_state & MapRightCtrlMask))
509                                && get_key_state(state, XK_Caps_Lock))
510                            {
511                                    DEBUG_KBD(("CapsLock + Ctrl pressed, releasing LeftShift\n"));
512                                    tr.modifiers ^= MapLeftShiftMask;
513                            }
514    
515                            DEBUG_KBD(("Found scancode translation, scancode=0x%x, modifiers=0x%x\n",
516                                       tr.scancode, tr.modifiers));
517                  }                  }
518          }          }
519            else
         if (((remote_modifier_state & MapLeftCtrlMask)  
              || (remote_modifier_state & MapRightCtrlMask)) && get_key_state(state, XK_Caps_Lock))  
520          {          {
521                  DEBUG_KBD(("CapsLock + Ctrl pressed, releasing LeftShift\n"));                  if (keymap_loaded)
522                  tr.modifiers ^= MapLeftShiftMask;                          warning("No translation for (keysym 0x%lx, %s)\n", keysym,
523          }                                  get_ksname(keysym));
524    
525                    /* not in keymap, try to interpret the raw scancode */
526                    if (((int) keycode >= min_keycode) && (keycode <= 0x60))
527                    {
528                            tr.scancode = keycode - min_keycode;
529    
530                            /* The modifiers to send for this key should be
531                               obtained from the local state. Currently, only
532                               shift is implemented. */
533                            if (state & ShiftMask)
534                            {
535                                    tr.modifiers = MapLeftShiftMask;
536                            }
537    
538          if (tr.scancode != 0)                          DEBUG_KBD(("Sending guessed scancode 0x%x\n", tr.scancode));
539          {                  }
540                  DEBUG_KBD(("Found key translation, scancode=0x%x, modifiers=0x%x\n",                  else
541                             tr.scancode, tr.modifiers));                  {
542                  return tr;                          DEBUG_KBD(("No good guess for keycode 0x%x found\n", keycode));
543                    }
544          }          }
545    
546          if (keymap_loaded)          return tr;
547                  warning("No translation for (keysym 0x%lx, %s)\n", keysym, get_ksname(keysym));  }
548    
549    void
550    xkeymap_send_keys(uint32 keysym, unsigned int keycode, unsigned int state, uint32 ev_time,
551                      BOOL pressed)
552    {
553            key_translation tr, *ptr;
554            tr = xkeymap_translate_key(keysym, keycode, state);
555    
556          /* not in keymap, try to interpret the raw scancode */          if (tr.seq_keysym == 0)
         if (((int) keycode >= min_keycode) && (keycode <= 0x60))  
557          {          {
558                  tr.scancode = keycode - min_keycode;                  /* Scancode translation */
559                    if (tr.scancode == 0)
560                            return;
561    
562                  /* The modifiers to send for this key should be                  if (pressed)
                    obtained from the local state. Currently, only  
                    shift is implemented. */  
                 if (state & ShiftMask)  
563                  {                  {
564                          tr.modifiers = MapLeftShiftMask;                          save_remote_modifiers(tr.scancode);
565                            ensure_remote_modifiers(ev_time, tr);
566                            rdp_send_scancode(ev_time, RDP_KEYPRESS, tr.scancode);
567                            restore_remote_modifiers(ev_time, tr.scancode);
568                  }                  }
569                    else
570                  DEBUG_KBD(("Sending guessed scancode 0x%x\n", tr.scancode));                  {
571                            rdp_send_scancode(ev_time, RDP_KEYRELEASE, tr.scancode);
572                    }
573                    return;
574          }          }
575          else  
576            /* Sequence, only on key down */
577            if (pressed)
578          {          {
579                  DEBUG_KBD(("No good guess for keycode 0x%x found\n", keycode));                  ptr = &tr;
580                    do
581                    {
582                            DEBUG_KBD(("Handling sequence element, keysym=0x%x\n",
583                                       (unsigned int) ptr->seq_keysym));
584                            xkeymap_send_keys(ptr->seq_keysym, keycode, state, ev_time, True);
585                            xkeymap_send_keys(ptr->seq_keysym, keycode, state, ev_time, False);
586                            ptr = ptr->next;
587                    }
588                    while (ptr);
589          }          }
   
         return tr;  
590  }  }
591    
592  uint16  uint16

Legend:
Removed from v.828  
changed lines
  Added in v.951

  ViewVC Help
Powered by ViewVC 1.1.26