/[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 77 by astrand, Mon Jul 29 20:17:10 2002 UTC revision 115 by astrand, Wed Sep 11 09:52:30 2002 UTC
# Line 41  static key_translation keymap[KEYMAP_SIZ Line 41  static key_translation keymap[KEYMAP_SIZ
41  static int min_keycode;  static int min_keycode;
42  static uint16 remote_modifier_state = 0;  static uint16 remote_modifier_state = 0;
43    
44    static void update_modifier_state(uint16 modifiers, BOOL pressed);
45    
46  static void  static void
47  add_to_keymap(char *keyname, uint8 scancode, uint16 modifiers, char *mapname)  add_to_keymap(char *keyname, uint8 scancode, uint16 modifiers, char *mapname)
48  {  {
# Line 53  add_to_keymap(char *keyname, uint8 scanc Line 55  add_to_keymap(char *keyname, uint8 scanc
55                  return;                  return;
56          }          }
57    
58          DEBUG_KBD("Adding translation, keysym=0x%x, scancode=0x%x, "          DEBUG_KBD(("Adding translation, keysym=0x%x, scancode=0x%x, "
59                    "modifiers=0x%x\n", (unsigned int) keysym, scancode,                     "modifiers=0x%x\n", (unsigned int) keysym, scancode, modifiers));
                   modifiers);  
60    
61          keymap[keysym & KEYMAP_MASK].scancode = scancode;          keymap[keysym & KEYMAP_MASK].scancode = scancode;
62          keymap[keysym & KEYMAP_MASK].modifiers = modifiers;          keymap[keysym & KEYMAP_MASK].modifiers = modifiers;
# Line 117  xkeymap_read(char *mapname) Line 118  xkeymap_read(char *mapname)
118                  if (strncmp(line, "map ", 4) == 0)                  if (strncmp(line, "map ", 4) == 0)
119                  {                  {
120                          keylayout = strtol(line + 4, NULL, 16);                          keylayout = strtol(line + 4, NULL, 16);
121                          DEBUG_KBD("Keylayout 0x%x\n", keylayout);                          DEBUG_KBD(("Keylayout 0x%x\n", keylayout));
122                          continue;                          continue;
123                  }                  }
124    
125                  /* compose */                  /* compose */
126                  if (strncmp(line, "enable_compose", 15) == 0)                  if (strncmp(line, "enable_compose", 15) == 0)
127                  {                  {
128                          DEBUG_KBD("Enabling compose handling\n");                          DEBUG_KBD(("Enabling compose handling\n"));
129                          enable_compose = True;                          enable_compose = True;
130                          continue;                          continue;
131                  }                  }
# Line 140  xkeymap_read(char *mapname) Line 141  xkeymap_read(char *mapname)
141                  p = strchr(line, ' ');                  p = strchr(line, ' ');
142                  if (p == NULL)                  if (p == NULL)
143                  {                  {
144                          error("Bad line %d in keymap %s\n", line_num,                          error("Bad line %d in keymap %s\n", line_num, mapname);
                               mapname);  
145                          continue;                          continue;
146                  }                  }
147                  else                  else
# Line 244  xkeymap_translate_key(KeySym keysym, uns Line 244  xkeymap_translate_key(KeySym keysym, uns
244          if (tr.scancode != 0)          if (tr.scancode != 0)
245          {          {
246                  DEBUG_KBD                  DEBUG_KBD
247                          ("Found key translation, scancode=0x%x, modifiers=0x%x\n",                          (("Found key translation, scancode=0x%x, modifiers=0x%x\n",
248                           tr.scancode, tr.modifiers);                            tr.scancode, tr.modifiers));
249                  return tr;                  return tr;
250          }          }
251    
252          printf("No translation for (keysym 0x%lx, %s)\n", keysym,          fprintf(stderr, "No translation for (keysym 0x%lx, %s)\n", keysym, get_ksname(keysym));
                get_ksname(keysym));  
253    
254          /* not in keymap, try to interpret the raw scancode */          /* not in keymap, try to interpret the raw scancode */
255          if ((keycode >= min_keycode) && (keycode <= 0x60))          if ((keycode >= min_keycode) && (keycode <= 0x60))
256          {          {
257                  tr.scancode = keycode - min_keycode;                  tr.scancode = keycode - min_keycode;
258                  printf("Sending guessed scancode 0x%x\n", tr.scancode);                  fprintf(stderr, "Sending guessed scancode 0x%x\n", tr.scancode);
259          }          }
260          else          else
261          {          {
262                  printf("No good guess for keycode 0x%x found\n", keycode);                  fprintf(stderr, "No good guess for keycode 0x%x found\n", keycode);
263          }          }
264    
265          return tr;          return tr;
# Line 310  inhibit_key(KeySym keysym) Line 309  inhibit_key(KeySym keysym)
309                  case XK_Multi_key:                  case XK_Multi_key:
310                          return True;                          return True;
311                          break;                          break;
312                    case XK_Num_Lock:
313                            return True;
314                            break;
315                  default:                  default:
316                          break;                          break;
317          }          }
# Line 344  ensure_remote_modifiers(uint32 ev_time, Line 346  ensure_remote_modifiers(uint32 ev_time,
346                  if (MASK_HAS_BITS(tr.modifiers, MapShiftMask))                  if (MASK_HAS_BITS(tr.modifiers, MapShiftMask))
347                  {                  {
348                          /* Needs this modifier. Send down. */                          /* Needs this modifier. Send down. */
349                          rdp_send_scancode(ev_time, RDP_KEYPRESS,                          rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_LSHIFT);
                                           SCANCODE_CHAR_LSHIFT);  
350                  }                  }
351                  else                  else
352                  {                  {
353                          /* Should not use this modifier. Send up. */                          /* Should not use this modifier. Send up. */
354                          rdp_send_scancode(ev_time, RDP_KEYRELEASE,                          rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LSHIFT);
                                           SCANCODE_CHAR_LSHIFT);  
355                  }                  }
356          }          }
357    
# Line 363  ensure_remote_modifiers(uint32 ev_time, Line 363  ensure_remote_modifiers(uint32 ev_time,
363                  if (MASK_HAS_BITS(tr.modifiers, MapAltGrMask))                  if (MASK_HAS_BITS(tr.modifiers, MapAltGrMask))
364                  {                  {
365                          /* Needs this modifier. Send down. */                          /* Needs this modifier. Send down. */
366                          rdp_send_scancode(ev_time, RDP_KEYPRESS,                          rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_RALT);
                                           SCANCODE_CHAR_RALT);  
367                  }                  }
368                  else                  else
369                  {                  {
370                          /* Should not use this modifier. Send up. */                          /* Should not use this modifier. Send up. */
371                          rdp_send_scancode(ev_time, RDP_KEYRELEASE,                          rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RALT);
                                           SCANCODE_CHAR_RALT);  
372                  }                  }
373          }          }
374    
# Line 379  ensure_remote_modifiers(uint32 ev_time, Line 377  ensure_remote_modifiers(uint32 ev_time,
377              != MASK_HAS_BITS(remote_modifier_state, MapNumLockMask))              != MASK_HAS_BITS(remote_modifier_state, MapNumLockMask))
378          {          {
379                  /* The remote modifier state is not correct */                  /* The remote modifier state is not correct */
380                  DEBUG_KBD("Remote NumLock state is incorrect. Toggling\n");                  uint16 new_remote_state = 0;
381    
382                  if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask))                  if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask))
383                  {                  {
384                          /* Needs this modifier. Toggle */                          DEBUG_KBD(("Remote NumLock state is incorrect, activating NumLock.\n"));
385                          rdp_send_scancode(ev_time, RDP_KEYPRESS,                          new_remote_state |= KBD_FLAG_NUMLOCK;
                                           SCANCODE_CHAR_NUMLOCK);  
                         rdp_send_scancode(ev_time, RDP_KEYRELEASE,  
                                           SCANCODE_CHAR_NUMLOCK);  
386                  }                  }
387                  else                  else
388                  {                  {
389                          /* Should not use this modifier. Toggle */                          DEBUG_KBD(("Remote NumLock state is incorrect, deactivating NumLock.\n"));
                         rdp_send_scancode(ev_time, RDP_KEYPRESS,  
                                           SCANCODE_CHAR_NUMLOCK);  
                         rdp_send_scancode(ev_time, RDP_KEYRELEASE,  
                                           SCANCODE_CHAR_NUMLOCK);  
390                  }                  }
         }  
391    
392                    rdp_send_input(0, RDP_INPUT_SYNCHRONIZE, 0, new_remote_state, 0);
393                    update_modifier_state(SCANCODE_CHAR_NUMLOCK, True);
394            }
395  }  }
396    
397    
398  static void  static void
399  update_modifier_state(uint16 modifiers, BOOL pressed)  update_modifier_state(uint16 modifiers, BOOL pressed)
400  {  {
401    #ifdef WITH_DEBUG_KBD
402            uint16 old_modifier_state;
403    
404            old_modifier_state = remote_modifier_state;
405    #endif
406    
         DEBUG_KBD("Before updating modifier_state:0x%x, pressed=0x%x\n",  
                   remote_modifier_state, pressed);  
407          switch (modifiers)          switch (modifiers)
408          {          {
409                  case SCANCODE_CHAR_LSHIFT:                  case SCANCODE_CHAR_LSHIFT:
410                          MASK_CHANGE_BIT(remote_modifier_state,                          MASK_CHANGE_BIT(remote_modifier_state, MapLeftShiftMask, pressed);
                                         MapLeftShiftMask, pressed);  
411                          break;                          break;
412                  case SCANCODE_CHAR_RSHIFT:                  case SCANCODE_CHAR_RSHIFT:
413                          MASK_CHANGE_BIT(remote_modifier_state,                          MASK_CHANGE_BIT(remote_modifier_state, MapRightShiftMask, pressed);
                                         MapRightShiftMask, pressed);  
414                          break;                          break;
415                  case SCANCODE_CHAR_LCTRL:                  case SCANCODE_CHAR_LCTRL:
416                          MASK_CHANGE_BIT(remote_modifier_state,                          MASK_CHANGE_BIT(remote_modifier_state, MapLeftCtrlMask, pressed);
                                         MapLeftCtrlMask, pressed);  
417                          break;                          break;
418                  case SCANCODE_CHAR_RCTRL:                  case SCANCODE_CHAR_RCTRL:
419                          MASK_CHANGE_BIT(remote_modifier_state,                          MASK_CHANGE_BIT(remote_modifier_state, MapRightCtrlMask, pressed);
                                         MapRightCtrlMask, pressed);  
420                          break;                          break;
421                  case SCANCODE_CHAR_LALT:                  case SCANCODE_CHAR_LALT:
422                          MASK_CHANGE_BIT(remote_modifier_state, MapLeftAltMask,                          MASK_CHANGE_BIT(remote_modifier_state, MapLeftAltMask, pressed);
                                         pressed);  
423                          break;                          break;
424                  case SCANCODE_CHAR_RALT:                  case SCANCODE_CHAR_RALT:
425                          MASK_CHANGE_BIT(remote_modifier_state,                          MASK_CHANGE_BIT(remote_modifier_state, MapRightAltMask, pressed);
                                         MapRightAltMask, pressed);  
426                          break;                          break;
427                  case SCANCODE_CHAR_LWIN:                  case SCANCODE_CHAR_LWIN:
428                          MASK_CHANGE_BIT(remote_modifier_state, MapLeftWinMask,                          MASK_CHANGE_BIT(remote_modifier_state, MapLeftWinMask, pressed);
                                         pressed);  
429                          break;                          break;
430                  case SCANCODE_CHAR_RWIN:                  case SCANCODE_CHAR_RWIN:
431                          MASK_CHANGE_BIT(remote_modifier_state,                          MASK_CHANGE_BIT(remote_modifier_state, MapRightWinMask, pressed);
                                         MapRightWinMask, pressed);  
432                          break;                          break;
433                  case SCANCODE_CHAR_NUMLOCK:                  case SCANCODE_CHAR_NUMLOCK:
434                          /* KeyReleases for NumLocks are sent immediately. Toggle the                          /* KeyReleases for NumLocks are sent immediately. Toggle the
# Line 449  update_modifier_state(uint16 modifiers, Line 438  update_modifier_state(uint16 modifiers,
438                                  BOOL newNumLockState;                                  BOOL newNumLockState;
439                                  newNumLockState =                                  newNumLockState =
440                                          (MASK_HAS_BITS                                          (MASK_HAS_BITS
441                                           (remote_modifier_state,                                           (remote_modifier_state, MapNumLockMask) == False);
                                           MapNumLockMask) == False);  
442                                  MASK_CHANGE_BIT(remote_modifier_state,                                  MASK_CHANGE_BIT(remote_modifier_state,
443                                                  MapNumLockMask,                                                  MapNumLockMask, newNumLockState);
                                                 newNumLockState);  
444                          }                          }
445                          break;                          break;
446          }          }
447          DEBUG_KBD("After updating modifier_state:0x%x\n",  
448                    remote_modifier_state);  #ifdef WITH_DEBUG_KBD
449            if (old_modifier_state != remote_modifier_state)
450            {
451                    DEBUG_KBD(("Before updating modifier_state:0x%x, pressed=0x%x\n",
452                               old_modifier_state, pressed));
453                    DEBUG_KBD(("After updating modifier_state:0x%x\n", remote_modifier_state));
454            }
455    #endif
456    
457  }  }
458    
# Line 470  rdp_send_scancode(uint32 time, uint16 fl Line 464  rdp_send_scancode(uint32 time, uint16 fl
464    
465          if (scancode & SCANCODE_EXTENDED)          if (scancode & SCANCODE_EXTENDED)
466          {          {
467                  DEBUG_KBD("Sending extended scancode=0x%x, flags=0x%x\n",                  DEBUG_KBD(("Sending extended scancode=0x%x, flags=0x%x\n",
468                            scancode & ~SCANCODE_EXTENDED, flags);                             scancode & ~SCANCODE_EXTENDED, flags));
469                  rdp_send_input(time, RDP_INPUT_SCANCODE, flags | KBD_FLAG_EXT,                  rdp_send_input(time, RDP_INPUT_SCANCODE, flags | KBD_FLAG_EXT,
470                                 scancode & ~SCANCODE_EXTENDED, 0);                                 scancode & ~SCANCODE_EXTENDED, 0);
471          }          }
472          else          else
473          {          {
474                  DEBUG_KBD("Sending scancode=0x%x, flags=0x%x\n", scancode,                  DEBUG_KBD(("Sending scancode=0x%x, flags=0x%x\n", scancode, flags));
                           flags);  
475                  rdp_send_input(time, RDP_INPUT_SCANCODE, flags, scancode, 0);                  rdp_send_input(time, RDP_INPUT_SCANCODE, flags, scancode, 0);
476          }          }
477  }  }

Legend:
Removed from v.77  
changed lines
  Added in v.115

  ViewVC Help
Powered by ViewVC 1.1.26