/[rdesktop]/sourceforge.net/trunk/rdesktop/xwin.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/xwin.c

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

revision 194 by matthewc, Tue Sep 24 12:25:21 2002 UTC revision 203 by matthewc, Thu Sep 26 14:04:30 2002 UTC
# Line 42  static int depth; Line 42  static int depth;
42  static int bpp;  static int bpp;
43  static XIM IM;  static XIM IM;
44  static XIC IC;  static XIC IC;
45    static XModifierKeymap *mod_map;
46  static Cursor current_cursor;  static Cursor current_cursor;
47    
48  /* endianness */  /* endianness */
# Line 183  translate_colour(uint32 colour) Line 184  translate_colour(uint32 colour)
184  }  }
185    
186  BOOL  BOOL
187  get_key_state(int keysym)  get_key_state(uint32 keysym, unsigned int state)
188  {  {
189          int keysymMask = 0, modifierpos, key;          int modifierpos, key, keysymMask = 0;
         Window wDummy1, wDummy2;  
         int iDummy3, iDummy4, iDummy5, iDummy6;  
         unsigned int current_state;  
190          int offset;          int offset;
191    
         XModifierKeymap *map = XGetModifierMapping(display);  
192          KeyCode keycode = XKeysymToKeycode(display, keysym);          KeyCode keycode = XKeysymToKeycode(display, keysym);
193    
194          if (keycode == NoSymbol)          if (keycode == NoSymbol)
# Line 199  get_key_state(int keysym) Line 196  get_key_state(int keysym)
196    
197          for (modifierpos = 0; modifierpos < 8; modifierpos++)          for (modifierpos = 0; modifierpos < 8; modifierpos++)
198          {          {
199                  offset = map->max_keypermod * modifierpos;                  offset = mod_map->max_keypermod * modifierpos;
200    
201                  for (key = 0; key < map->max_keypermod; key++)                  for (key = 0; key < mod_map->max_keypermod; key++)
202                  {                  {
203                          if (map->modifiermap[offset + key] == keycode)                          if (mod_map->modifiermap[offset + key] == keycode)
204                                  keysymMask = 1 << modifierpos;                                  keysymMask |= 1 << modifierpos;
205                  }                  }
206          }          }
207    
208          XQueryPointer(display, DefaultRootWindow(display), &wDummy1,          return (state & keysymMask) ? True : False;
                       &wDummy2, &iDummy3, &iDummy4, &iDummy5, &iDummy6, &current_state);  
   
         XFreeModifiermap(map);  
   
         return (current_state & keysymMask) ? True : False;  
209  }  }
210    
211  BOOL  BOOL
# Line 278  ui_init(void) Line 270  ui_init(void)
270    
271          if (ownbackstore)          if (ownbackstore)
272          {          {
273                  backstore = XCreatePixmap(display, RootWindowOfScreen(screen), width, height, depth);                  backstore =
274                            XCreatePixmap(display, RootWindowOfScreen(screen), width, height, depth);
275    
276                  /* clear to prevent rubbish being exposed at startup */                  /* clear to prevent rubbish being exposed at startup */
277                  XSetForeground(display, gc, BlackPixelOfScreen(screen));                  XSetForeground(display, gc, BlackPixelOfScreen(screen));
278                  XFillRectangle(display, backstore, gc, 0, 0, width, height);                  XFillRectangle(display, backstore, gc, 0, 0, width, height);
279          }          }
280    
281            mod_map = XGetModifierMapping(display);
282    
283          if (enable_compose)          if (enable_compose)
284                  IM = XOpenIM(display, NULL, NULL, NULL);                  IM = XOpenIM(display, NULL, NULL, NULL);
285    
# Line 298  ui_deinit(void) Line 293  ui_deinit(void)
293          if (IM != NULL)          if (IM != NULL)
294                  XCloseIM(IM);                  XCloseIM(IM);
295    
296            XFreeModifierMap(mod_map);
297    
298          if (ownbackstore)          if (ownbackstore)
299                  XFreePixmap(display, backstore);                  XFreePixmap(display, backstore);
300    
# Line 316  ui_create_window(void) Line 313  ui_create_window(void)
313          long input_mask, ic_input_mask;          long input_mask, ic_input_mask;
314          XEvent xevent;          XEvent xevent;
315    
316          wndwidth  = fullscreen ? WidthOfScreen(screen)  : width;          wndwidth = fullscreen ? WidthOfScreen(screen) : width;
317          wndheight = fullscreen ? HeightOfScreen(screen) : height;          wndheight = fullscreen ? HeightOfScreen(screen) : height;
318    
319          attribs.background_pixel = BlackPixelOfScreen(screen);          attribs.background_pixel = BlackPixelOfScreen(screen);
# Line 360  ui_create_window(void) Line 357  ui_create_window(void)
357                  IC = XCreateIC(IM, XNInputStyle, (XIMPreeditNothing | XIMStatusNothing),                  IC = XCreateIC(IM, XNInputStyle, (XIMPreeditNothing | XIMStatusNothing),
358                                 XNClientWindow, wnd, XNFocusWindow, wnd, NULL);                                 XNClientWindow, wnd, XNFocusWindow, wnd, NULL);
359    
360                  if ((IC != NULL) && (XGetICValues(IC, XNFilterEvents, &ic_input_mask, NULL) == NULL))                  if ((IC != NULL)
361                        && (XGetICValues(IC, XNFilterEvents, &ic_input_mask, NULL) == NULL))
362                          input_mask |= ic_input_mask;                          input_mask |= ic_input_mask;
363          }          }
364    
# Line 368  ui_create_window(void) Line 366  ui_create_window(void)
366          XMapWindow(display, wnd);          XMapWindow(display, wnd);
367    
368          /* wait for MapNotify */          /* wait for MapNotify */
369          do {          do
370            {
371                  XMaskEvent(display, StructureNotifyMask, &xevent);                  XMaskEvent(display, StructureNotifyMask, &xevent);
372          } while (xevent.type != MapNotify);          }
373            while (xevent.type != MapNotify);
374    
375          if (fullscreen)          if (fullscreen)
376                  XSetInputFocus(display, wnd, RevertToPointerRoot, CurrentTime);                  XSetInputFocus(display, wnd, RevertToPointerRoot, CurrentTime);
# Line 421  xwin_process_events(void) Line 421  xwin_process_events(void)
421          uint16 button, flags;          uint16 button, flags;
422          uint32 ev_time;          uint32 ev_time;
423          key_translation tr;          key_translation tr;
         char *ksname = NULL;  
424          char str[256];          char str[256];
425          Status status;          Status status;
426            unsigned int state;
427            Window wdummy;
428            int dummy;
429    
430          while (XPending(display) > 0)          while (XPending(display) > 0)
431          {          {
# Line 435  xwin_process_events(void) Line 437  xwin_process_events(void)
437                          continue;                          continue;
438                  }                  }
439    
                 ev_time = time(NULL);  
440                  flags = 0;                  flags = 0;
441    
442                  switch (xevent.type)                  switch (xevent.type)
# Line 462  xwin_process_events(void) Line 463  xwin_process_events(void)
463                                                        str, sizeof(str), &keysym, NULL);                                                        str, sizeof(str), &keysym, NULL);
464                                  }                                  }
465    
466                                  ksname = get_ksname(keysym);                                  DEBUG_KBD(("KeyPress for (keysym 0x%lx, %s)\n", keysym, get_ksname(keysym)));
                                 DEBUG_KBD(("KeyPress for (keysym 0x%lx, %s)\n", keysym, ksname));  
467    
468                                  if (handle_special_keys(keysym, ev_time, True))                                  ev_time = time(NULL);
469                                    if (handle_special_keys(keysym, xevent.xkey.state, ev_time, True))
470                                          break;                                          break;
471    
472                                  tr = xkeymap_translate_key(keysym,                                  tr = xkeymap_translate_key(keysym,
# Line 478  xwin_process_events(void) Line 479  xwin_process_events(void)
479    
480                                  rdp_send_scancode(ev_time, RDP_KEYPRESS, tr.scancode);                                  rdp_send_scancode(ev_time, RDP_KEYPRESS, tr.scancode);
481                                  break;                                  break;
482    
483                          case KeyRelease:                          case KeyRelease:
484                                  XLookupString((XKeyEvent *) & xevent, str,                                  XLookupString((XKeyEvent *) & xevent, str,
485                                                sizeof(str), &keysym, NULL);                                                sizeof(str), &keysym, NULL);
486    
                                 ksname = get_ksname(keysym);  
487                                  DEBUG_KBD(("\nKeyRelease for (keysym 0x%lx, %s)\n", keysym,                                  DEBUG_KBD(("\nKeyRelease for (keysym 0x%lx, %s)\n", keysym,
488                                             ksname));                                             get_ksname(keysym)));
489    
490                                  if (handle_special_keys(keysym, ev_time, False))                                  ev_time = time(NULL);
491                                    if (handle_special_keys(keysym, xevent.xkey.state, ev_time, False))
492                                          break;                                          break;
493    
494                                  tr = xkeymap_translate_key(keysym,                                  tr = xkeymap_translate_key(keysym,
# Line 507  xwin_process_events(void) Line 509  xwin_process_events(void)
509                                  if (button == 0)                                  if (button == 0)
510                                          break;                                          break;
511    
512                                  rdp_send_input(ev_time, RDP_INPUT_MOUSE,                                  rdp_send_input(time(NULL), RDP_INPUT_MOUSE,
513                                                 flags | button, xevent.xbutton.x, xevent.xbutton.y);                                                 flags | button, xevent.xbutton.x, xevent.xbutton.y);
514                                  break;                                  break;
515    
516                          case MotionNotify:                          case MotionNotify:
517                                  rdp_send_input(ev_time, RDP_INPUT_MOUSE,                                  rdp_send_input(time(NULL), RDP_INPUT_MOUSE,
518                                                 MOUSE_FLAG_MOVE, xevent.xmotion.x, xevent.xmotion.y);                                                 MOUSE_FLAG_MOVE, xevent.xmotion.x, xevent.xmotion.y);
519                                  break;                                  break;
520    
521                          case FocusIn:                          case FocusIn:
522                                  reset_modifier_keys();                                  XQueryPointer(display, wnd, &wdummy, &wdummy, &dummy, &dummy, &dummy, &dummy, &state);
523                                    reset_modifier_keys(state);
524                                  if (grab_keyboard)                                  if (grab_keyboard)
525                                          XGrabKeyboard(display, wnd, True,                                          XGrabKeyboard(display, wnd, True,
526                                                        GrabModeAsync, GrabModeAsync, CurrentTime);                                                        GrabModeAsync, GrabModeAsync, CurrentTime);
527                                  break;                                  break;
528    
529                          case FocusOut:                          case FocusOut:
530                                  if (grab_keyboard)                                  if (xevent.xfocus.mode == NotifyWhileGrabbed)
531                                          XUngrabKeyboard(display, CurrentTime);                                          XUngrabKeyboard(display, CurrentTime);
532                                  break;                                  break;
533    
# Line 542  xwin_process_events(void) Line 545  xwin_process_events(void)
545                                  if (xevent.xmapping.request == MappingKeyboard                                  if (xevent.xmapping.request == MappingKeyboard
546                                      || xevent.xmapping.request == MappingModifier)                                      || xevent.xmapping.request == MappingModifier)
547                                          XRefreshKeyboardMapping(&xevent.xmapping);                                          XRefreshKeyboardMapping(&xevent.xmapping);
548    
549                                    if (xevent.xmapping.request == MappingModifier)
550                                    {
551                                            XFreeModifierMap(mod_map);
552                                            mod_map = XGetModifierMapping(display);
553                                    }
554                                  break;                                  break;
555    
556                  }                  }
# Line 779  ui_create_colourmap(COLOURMAP * colours) Line 788  ui_create_colourmap(COLOURMAP * colours)
788                          long nDist = nMinDist;                          long nDist = nMinDist;
789    
790                          /* only get the colors once */                          /* only get the colors once */
791                          while( colLookup-- ){                          while (colLookup--)
792                            {
793                                  xc_cache[colLookup].pixel = colLookup;                                  xc_cache[colLookup].pixel = colLookup;
794                                  xc_cache[colLookup].red = xc_cache[colLookup].green = xc_cache[colLookup].blue = 0;                                  xc_cache[colLookup].red = xc_cache[colLookup].green =
795                                            xc_cache[colLookup].blue = 0;
796                                  xc_cache[colLookup].flags = 0;                                  xc_cache[colLookup].flags = 0;
797                                  XQueryColor(display, DefaultColormap(display, DefaultScreen(display)), &xc_cache[colLookup]);                                  XQueryColor(display,
798                                                DefaultColormap(display, DefaultScreen(display)),
799                                                &xc_cache[colLookup]);
800                          }                          }
801                          colLookup = 0;                          colLookup = 0;
802    
803                          /* approximate the pixel */                          /* approximate the pixel */
804                          while( j-- ){                          while (j--)
805                                  if( xc_cache[j].flags ){                          {
806                                          nDist =                                  if (xc_cache[j].flags)
807                                          ((long) (xc_cache[j].red >> 8) - (long) (xentry.red >> 8)) *                                  {
808                                          ((long) (xc_cache[j].red >> 8) - (long) (xentry.red >> 8)) +                                          nDist = ((long) (xc_cache[j].red >> 8) -
809                                          ((long) (xc_cache[j].green >> 8) - (long) (xentry.green >> 8)) *                                                   (long) (xentry.red >> 8)) *
810                                          ((long) (xc_cache[j].green >> 8) - (long) (xentry.green >> 8)) +                                                  ((long) (xc_cache[j].red >> 8) -
811                                          ((long) (xc_cache[j].blue >> 8) - (long) (xentry.blue >> 8)) *                                                   (long) (xentry.red >> 8)) +
812                                          ((long) (xc_cache[j].blue >> 8) - (long) (xentry.blue >> 8));                                                  ((long) (xc_cache[j].green >> 8) -
813                                                     (long) (xentry.green >> 8)) *
814                                                    ((long) (xc_cache[j].green >> 8) -
815                                                     (long) (xentry.green >> 8)) +
816                                                    ((long) (xc_cache[j].blue >> 8) -
817                                                     (long) (xentry.blue >> 8)) *
818                                                    ((long) (xc_cache[j].blue >> 8) -
819                                                     (long) (xentry.blue >> 8));
820                                  }                                  }
821                                  if( nDist < nMinDist ){                                  if (nDist < nMinDist)
822                                    {
823                                          nMinDist = nDist;                                          nMinDist = nDist;
824                                          xentry.pixel = j;                                          xentry.pixel = j;
825                                  }                                  }
# Line 807  ui_create_colourmap(COLOURMAP * colours) Line 828  ui_create_colourmap(COLOURMAP * colours)
828                  colour = xentry.pixel;                  colour = xentry.pixel;
829    
830                  /* update our cache */                  /* update our cache */
831                  if( xentry.pixel < 256 ){                  if (xentry.pixel < 256)
832                    {
833                          xc_cache[xentry.pixel].red = xentry.red;                          xc_cache[xentry.pixel].red = xentry.red;
834                          xc_cache[xentry.pixel].green = xentry.green;                          xc_cache[xentry.pixel].green = xentry.green;
835                          xc_cache[xentry.pixel].blue = xentry.blue;                          xc_cache[xentry.pixel].blue = xentry.blue;

Legend:
Removed from v.194  
changed lines
  Added in v.203

  ViewVC Help
Powered by ViewVC 1.1.26