/[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 452 by astrand, Sun Aug 31 19:45:56 2003 UTC revision 553 by astrand, Mon Dec 8 15:28:24 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 36  Line 38 
38  #define KEYMAP_MAX_LINE_LENGTH 80  #define KEYMAP_MAX_LINE_LENGTH 80
39    
40  extern Display *g_display;  extern Display *g_display;
41    extern Window g_wnd;
42  extern char keymapname[16];  extern char keymapname[16];
43  extern int keylayout;  extern int keylayout;
44  extern int g_win_button_size;  extern int g_win_button_size;
45  extern BOOL g_enable_compose;  extern BOOL g_enable_compose;
46  extern BOOL g_use_rdp5;  extern BOOL g_use_rdp5;
47    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];
# Line 278  send_winkey(uint32 ev_time, BOOL pressed Line 282  send_winkey(uint32 ev_time, BOOL pressed
282          }          }
283  }  }
284    
285    static void
286    reset_winkey(uint32 ev_time)
287    {
288            if (g_use_rdp5)
289            {
290                    /* For some reason, it seems to suffice to release
291                     *either* the left or right winkey. */
292                    rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LWIN);
293            }
294    }
295    
296  /* Handles, for example, multi-scancode keypresses (which is not  /* Handles, for example, multi-scancode keypresses (which is not
297     possible via keymap-files) */     possible via keymap-files) */
298  BOOL  BOOL
# Line 308  handle_special_keys(uint32 keysym, unsig Line 323  handle_special_keys(uint32 keysym, unsig
323                          }                          }
324                          /* No release sequence */                          /* No release sequence */
325                          return True;                          return True;
326                            break;
327    
328                  case XK_Pause:                  case XK_Pause:
329                          /* According to MS Keyboard Scan Code                          /* According to MS Keyboard Scan Code
# Line 334  handle_special_keys(uint32 keysym, unsig Line 350  handle_special_keys(uint32 keysym, unsig
350                                                 0x1d, 0);                                                 0x1d, 0);
351                          }                          }
352                          return True;                          return True;
353                            break;
354    
355                  case XK_Meta_L: /* Windows keys */                  case XK_Meta_L: /* Windows keys */
356                  case XK_Super_L:                  case XK_Super_L:
357                  case XK_Hyper_L:                  case XK_Hyper_L:
358                          send_winkey(ev_time, pressed, True);                          send_winkey(ev_time, pressed, True);
359                          return True;                          return True;
360                            break;
361    
362                  case XK_Meta_R:                  case XK_Meta_R:
363                  case XK_Super_R:                  case XK_Super_R:
364                  case XK_Hyper_R:                  case XK_Hyper_R:
365                          send_winkey(ev_time, pressed, False);                          send_winkey(ev_time, pressed, False);
366                          return True;                          return True;
367                            break;
368    
369                  case XK_space:                  case XK_space:
370                          /* Prevent access to the Windows system menu in single app mode */                          /* Prevent access to the Windows system menu in single app mode */
371                          if (g_win_button_size                          if (g_win_button_size
372                              && (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)))
373                                  return True;                                  return True;
374                            break;
375                    case XK_Num_Lock:
376                            /* FIXME: We might want to do RDP_INPUT_SYNCHRONIZE here, if g_numlock_sync */
377                            if (!g_numlock_sync)
378                                    /* Inhibit */
379                                    return True;
380                            break;
381    
382          }          }
383          return False;          return False;
# Line 448  get_ksname(uint32 keysym) Line 474  get_ksname(uint32 keysym)
474          return ksname;          return ksname;
475  }  }
476    
477    static BOOL
478    is_modifier(uint8 scancode)
479    {
480            switch (scancode)
481            {
482                    case SCANCODE_CHAR_LSHIFT:
483                    case SCANCODE_CHAR_RSHIFT:
484                    case SCANCODE_CHAR_LCTRL:
485                    case SCANCODE_CHAR_RCTRL:
486                    case SCANCODE_CHAR_LALT:
487                    case SCANCODE_CHAR_RALT:
488                    case SCANCODE_CHAR_LWIN:
489                    case SCANCODE_CHAR_RWIN:
490                    case SCANCODE_CHAR_NUMLOCK:
491                            return True;
492                    default:
493                            break;
494            }
495            return False;
496    }
497    
498  void  void
499  save_remote_modifiers()  save_remote_modifiers(uint8 scancode)
500  {  {
501            if (is_modifier(scancode))
502                    return;
503    
504          saved_remote_modifier_state = remote_modifier_state;          saved_remote_modifier_state = remote_modifier_state;
505  }  }
506    
507  void  void
508  restore_remote_modifiers(uint32 ev_time)  restore_remote_modifiers(uint32 ev_time, uint8 scancode)
509  {  {
510          key_translation dummy;          key_translation dummy;
511    
512            if (is_modifier(scancode))
513                    return;
514    
515          dummy.scancode = 0;          dummy.scancode = 0;
516          dummy.modifiers = saved_remote_modifier_state;          dummy.modifiers = saved_remote_modifier_state;
517          ensure_remote_modifiers(ev_time, dummy);          ensure_remote_modifiers(ev_time, dummy);
# Line 468  void Line 521  void
521  ensure_remote_modifiers(uint32 ev_time, key_translation tr)  ensure_remote_modifiers(uint32 ev_time, key_translation tr)
522  {  {
523          /* If this key is a modifier, do nothing */          /* If this key is a modifier, do nothing */
524          switch (tr.scancode)          if (is_modifier(tr.scancode))
525          {                  return;
                 case SCANCODE_CHAR_LSHIFT:  
                 case SCANCODE_CHAR_RSHIFT:  
                 case SCANCODE_CHAR_LCTRL:  
                 case SCANCODE_CHAR_RCTRL:  
                 case SCANCODE_CHAR_LALT:  
                 case SCANCODE_CHAR_RALT:  
                 case SCANCODE_CHAR_LWIN:  
                 case SCANCODE_CHAR_RWIN:  
                 case SCANCODE_CHAR_NUMLOCK:  
                         return;  
                 default:  
                         break;  
         }  
526    
527          /* NumLock */          if (!g_numlock_sync)
         if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask)  
             != MASK_HAS_BITS(remote_modifier_state, MapNumLockMask))  
528          {          {
529                  /* The remote modifier state is not correct */                  /* NumLock */
530                  uint16 new_remote_state;                  if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask)
531                        != MASK_HAS_BITS(remote_modifier_state, MapNumLockMask))
                 if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask))  
532                  {                  {
533                          DEBUG_KBD(("Remote NumLock state is incorrect, activating NumLock.\n"));                          /* The remote modifier state is not correct */
534                          new_remote_state = KBD_FLAG_NUMLOCK;                          uint16 new_remote_state;
                         remote_modifier_state = MapNumLockMask;  
                 }  
                 else  
                 {  
                         DEBUG_KBD(("Remote NumLock state is incorrect, deactivating NumLock.\n"));  
                         new_remote_state = 0;  
                         remote_modifier_state = 0;  
                 }  
535    
536                  rdp_send_input(0, RDP_INPUT_SYNCHRONIZE, 0, new_remote_state, 0);                          if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask))
537                            {
538                                    DEBUG_KBD(("Remote NumLock state is incorrect, activating NumLock.\n"));
539                                    new_remote_state = KBD_FLAG_NUMLOCK;
540                                    remote_modifier_state = MapNumLockMask;
541                            }
542                            else
543                            {
544                                    DEBUG_KBD(("Remote NumLock state is incorrect, deactivating NumLock.\n"));
545                                    new_remote_state = 0;
546                                    remote_modifier_state = 0;
547                            }
548    
549                            rdp_send_input(0, RDP_INPUT_SYNCHRONIZE, 0, new_remote_state, 0);
550                    }
551          }          }
552    
553    
554          /* Shift. Left shift and right shift are treated as equal; either is fine. */          /* Shift. Left shift and right shift are treated as equal; either is fine. */
555          if (MASK_HAS_BITS(tr.modifiers, MapShiftMask)          if (MASK_HAS_BITS(tr.modifiers, MapShiftMask)
556              != MASK_HAS_BITS(remote_modifier_state, MapShiftMask))              != MASK_HAS_BITS(remote_modifier_state, MapShiftMask))
# Line 555  ensure_remote_modifiers(uint32 ev_time, Line 599  ensure_remote_modifiers(uint32 ev_time,
599  }  }
600    
601    
602    unsigned int
603    read_keyboard_state()
604    {
605            unsigned int state;
606            Window wdummy;
607            int dummy;
608    
609            XQueryPointer(g_display, g_wnd, &wdummy, &wdummy, &dummy, &dummy, &dummy, &dummy, &state);
610            return state;
611    }
612    
613    
614    uint16
615    ui_get_numlock_state(unsigned int state)
616    {
617            uint16 numlock_state = 0;
618    
619            if (get_key_state(state, XK_Num_Lock))
620                    numlock_state = KBD_FLAG_NUMLOCK;
621    
622            return numlock_state;
623    }
624    
625    
626  void  void
627  reset_modifier_keys(unsigned int state)  reset_modifier_keys()
628  {  {
629            unsigned int state = read_keyboard_state();
630    
631          /* reset keys */          /* reset keys */
632          uint32 ev_time;          uint32 ev_time;
633          ev_time = time(NULL);          ev_time = time(NULL);
# Line 584  reset_modifier_keys(unsigned int state) Line 654  reset_modifier_keys(unsigned int state)
654          if (MASK_HAS_BITS(remote_modifier_state, MapRightAltMask) &&          if (MASK_HAS_BITS(remote_modifier_state, MapRightAltMask) &&
655              !get_key_state(state, XK_Alt_R) && !get_key_state(state, XK_Mode_switch))              !get_key_state(state, XK_Alt_R) && !get_key_state(state, XK_Mode_switch))
656                  rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RALT);                  rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RALT);
657    
658            reset_winkey(ev_time);
659    
660            if (g_numlock_sync)
661                    rdp_send_input(ev_time, RDP_INPUT_SYNCHRONIZE, 0, ui_get_numlock_state(state), 0);
662  }  }
663    
664    
# Line 625  update_modifier_state(uint8 scancode, BO Line 700  update_modifier_state(uint8 scancode, BO
700                  case SCANCODE_CHAR_NUMLOCK:                  case SCANCODE_CHAR_NUMLOCK:
701                          /* KeyReleases for NumLocks are sent immediately. Toggle the                          /* KeyReleases for NumLocks are sent immediately. Toggle the
702                             modifier state only on Keypress */                             modifier state only on Keypress */
703                          if (pressed)                          if (pressed && !g_numlock_sync)
704                          {                          {
705                                  BOOL newNumLockState;                                  BOOL newNumLockState;
706                                  newNumLockState =                                  newNumLockState =
# Line 634  update_modifier_state(uint8 scancode, BO Line 709  update_modifier_state(uint8 scancode, BO
709                                  MASK_CHANGE_BIT(remote_modifier_state,                                  MASK_CHANGE_BIT(remote_modifier_state,
710                                                  MapNumLockMask, newNumLockState);                                                  MapNumLockMask, newNumLockState);
711                          }                          }
                         break;  
712          }          }
713    
714  #ifdef WITH_DEBUG_KBD  #ifdef WITH_DEBUG_KBD

Legend:
Removed from v.452  
changed lines
  Added in v.553

  ViewVC Help
Powered by ViewVC 1.1.26