/[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 543 by astrand, Mon Nov 3 13:33:35 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;
# Line 183  xkeymap_read(char *mapname) Line 186  xkeymap_read(char *mapname)
186                          MASK_ADD_BITS(modifiers, MapLeftShiftMask);                          MASK_ADD_BITS(modifiers, MapLeftShiftMask);
187                  }                  }
188    
                 if (strstr(line_rest, "numlock"))  
                 {  
                         MASK_ADD_BITS(modifiers, MapNumLockMask);  
                 }  
   
189                  if (strstr(line_rest, "localstate"))                  if (strstr(line_rest, "localstate"))
190                  {                  {
191                          MASK_ADD_BITS(modifiers, MapLocalStateMask);                          MASK_ADD_BITS(modifiers, MapLocalStateMask);
# Line 448  get_ksname(uint32 keysym) Line 446  get_ksname(uint32 keysym)
446          return ksname;          return ksname;
447  }  }
448    
449    static BOOL
450    is_modifier(uint8 scancode)
451    {
452            switch (scancode)
453            {
454                    case SCANCODE_CHAR_LSHIFT:
455                    case SCANCODE_CHAR_RSHIFT:
456                    case SCANCODE_CHAR_LCTRL:
457                    case SCANCODE_CHAR_RCTRL:
458                    case SCANCODE_CHAR_LALT:
459                    case SCANCODE_CHAR_RALT:
460                    case SCANCODE_CHAR_LWIN:
461                    case SCANCODE_CHAR_RWIN:
462                    case SCANCODE_CHAR_NUMLOCK:
463                            return True;
464                    default:
465                            break;
466            }
467            return False;
468    }
469    
470  void  void
471  save_remote_modifiers()  save_remote_modifiers(uint8 scancode)
472  {  {
473            if (is_modifier(scancode))
474                    return;
475    
476          saved_remote_modifier_state = remote_modifier_state;          saved_remote_modifier_state = remote_modifier_state;
477  }  }
478    
479  void  void
480  restore_remote_modifiers(uint32 ev_time)  restore_remote_modifiers(uint32 ev_time, uint8 scancode)
481  {  {
482          key_translation dummy;          key_translation dummy;
483    
484            if (is_modifier(scancode))
485                    return;
486    
487          dummy.scancode = 0;          dummy.scancode = 0;
488          dummy.modifiers = saved_remote_modifier_state;          dummy.modifiers = saved_remote_modifier_state;
489          ensure_remote_modifiers(ev_time, dummy);          ensure_remote_modifiers(ev_time, dummy);
# Line 468  void Line 493  void
493  ensure_remote_modifiers(uint32 ev_time, key_translation tr)  ensure_remote_modifiers(uint32 ev_time, key_translation tr)
494  {  {
495          /* If this key is a modifier, do nothing */          /* If this key is a modifier, do nothing */
496          switch (tr.scancode)          if (is_modifier(tr.scancode))
497          {                  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;  
         }  
   
         /* NumLock */  
         if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask)  
             != MASK_HAS_BITS(remote_modifier_state, MapNumLockMask))  
         {  
                 /* The remote modifier state is not correct */  
                 uint16 new_remote_state;  
   
                 if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask))  
                 {  
                         DEBUG_KBD(("Remote NumLock state is incorrect, activating NumLock.\n"));  
                         new_remote_state = KBD_FLAG_NUMLOCK;  
                         remote_modifier_state = MapNumLockMask;  
                 }  
                 else  
                 {  
                         DEBUG_KBD(("Remote NumLock state is incorrect, deactivating NumLock.\n"));  
                         new_remote_state = 0;  
                         remote_modifier_state = 0;  
                 }  
   
                 rdp_send_input(0, RDP_INPUT_SYNCHRONIZE, 0, new_remote_state, 0);  
         }  
498    
499          /* 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. */
500          if (MASK_HAS_BITS(tr.modifiers, MapShiftMask)          if (MASK_HAS_BITS(tr.modifiers, MapShiftMask)
# Line 555  ensure_remote_modifiers(uint32 ev_time, Line 544  ensure_remote_modifiers(uint32 ev_time,
544  }  }
545    
546    
547    unsigned int
548    read_keyboard_state()
549    {
550            unsigned int state;
551            Window wdummy;
552            int dummy;
553    
554            XQueryPointer(g_display, g_wnd, &wdummy, &wdummy, &dummy, &dummy, &dummy, &dummy, &state);
555            return state;
556    }
557    
558    
559    uint16
560    ui_get_numlock_state(unsigned int state)
561    {
562            uint16 numlock_state = 0;
563    
564            if (get_key_state(state, XK_Num_Lock))
565                    numlock_state = KBD_FLAG_NUMLOCK;
566    
567            return numlock_state;
568    }
569    
570    
571  void  void
572  reset_modifier_keys(unsigned int state)  reset_modifier_keys()
573  {  {
574            unsigned int state = read_keyboard_state();
575    
576          /* reset keys */          /* reset keys */
577          uint32 ev_time;          uint32 ev_time;
578          ev_time = time(NULL);          ev_time = time(NULL);
# Line 584  reset_modifier_keys(unsigned int state) Line 599  reset_modifier_keys(unsigned int state)
599          if (MASK_HAS_BITS(remote_modifier_state, MapRightAltMask) &&          if (MASK_HAS_BITS(remote_modifier_state, MapRightAltMask) &&
600              !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))
601                  rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RALT);                  rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RALT);
602    
603            rdp_send_input(ev_time, RDP_INPUT_SYNCHRONIZE, 0, ui_get_numlock_state(state), 0);
604  }  }
605    
606    
# Line 622  update_modifier_state(uint8 scancode, BO Line 639  update_modifier_state(uint8 scancode, BO
639                  case SCANCODE_CHAR_RWIN:                  case SCANCODE_CHAR_RWIN:
640                          MASK_CHANGE_BIT(remote_modifier_state, MapRightWinMask, pressed);                          MASK_CHANGE_BIT(remote_modifier_state, MapRightWinMask, pressed);
641                          break;                          break;
                 case SCANCODE_CHAR_NUMLOCK:  
                         /* KeyReleases for NumLocks are sent immediately. Toggle the  
                            modifier state only on Keypress */  
                         if (pressed)  
                         {  
                                 BOOL newNumLockState;  
                                 newNumLockState =  
                                         (MASK_HAS_BITS  
                                          (remote_modifier_state, MapNumLockMask) == False);  
                                 MASK_CHANGE_BIT(remote_modifier_state,  
                                                 MapNumLockMask, newNumLockState);  
                         }  
                         break;  
642          }          }
643    
644  #ifdef WITH_DEBUG_KBD  #ifdef WITH_DEBUG_KBD

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

  ViewVC Help
Powered by ViewVC 1.1.26