/[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 35 by matty, Sat Sep 15 14:01:45 2001 UTC revision 59 by jsorg71, Sun Jul 14 04:20:25 2002 UTC
# Line 1  Line 1 
1  /*  /*
2     rdesktop: A Remote Desktop Protocol client.     rdesktop: A Remote Desktop Protocol client.
3     User interface services - X-Windows     User interface services - X Window System
4     Copyright (C) Matthew Chapman 1999-2001     Copyright (C) Matthew Chapman 1999-2001
5      
6     This program is free software; you can redistribute it and/or modify     This program is free software; you can redistribute it and/or modify
7     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
8     the Free Software Foundation; either version 2 of the License, or     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.     (at your option) any later version.
10      
11     This program is distributed in the hope that it will be useful,     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.     GNU General Public License for more details.
15      
16     You should have received a copy of the GNU General Public License     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software     along with this program; if not, write to the Free Software
18     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
# Line 20  Line 20 
20    
21  #include <X11/Xlib.h>  #include <X11/Xlib.h>
22  #include <X11/Xutil.h>  #include <X11/Xutil.h>
23    #include <X11/XKBlib.h>
24  #include <time.h>  #include <time.h>
25  #include <errno.h>  #include <errno.h>
26  #include "rdesktop.h"  #include "rdesktop.h"
27    
28    extern char keymapname[16];
29    extern int keylayout;
30  extern int width;  extern int width;
31  extern int height;  extern int height;
32  extern BOOL sendmotion;  extern BOOL sendmotion;
33  extern BOOL fullscreen;  extern BOOL fullscreen;
34    
35  static Display *display;  Display *display;
36    XkbDescPtr xkb;
37  static int x_socket;  static int x_socket;
38  static Window wnd;  static Window wnd;
39  static GC gc;  static GC gc;
# Line 45  static BOOL xserver_be; Line 49  static BOOL xserver_be;
49  static BOOL ownbackstore;  static BOOL ownbackstore;
50  static Pixmap backstore;  static Pixmap backstore;
51    
52    /* needed to keep track of the modifiers */
53    static unsigned int numlock_modifier_mask = 0;
54    static unsigned int key_down_state = 0;
55    
56    
57    #define DShift1Mask   (1<<0)
58    #define DLockMask     (1<<1)
59    #define DControl1Mask (1<<2)
60    #define DMod1Mask     (1<<3)
61    #define DMod2Mask     (1<<4)
62    #define DMod3Mask     (1<<5)
63    #define DMod4Mask     (1<<6)
64    #define DMod5Mask     (1<<7)
65    #define DShift2Mask   (1<<8)
66    #define DControl2Mask (1<<9)
67    #define DNumLockMask  (1<<10)
68    
69  #define FILL_RECTANGLE(x,y,cx,cy)\  #define FILL_RECTANGLE(x,y,cx,cy)\
70  { \  { \
71          XFillRectangle(display, wnd, gc, x, y, cx, cy); \          XFillRectangle(display, wnd, gc, x, y, cx, cy); \
# Line 84  static int rop2_map[] = { Line 105  static int rop2_map[] = {
105  #define SET_FUNCTION(rop2)      { if (rop2 != ROP2_COPY) XSetFunction(display, gc, rop2_map[rop2]); }  #define SET_FUNCTION(rop2)      { if (rop2 != ROP2_COPY) XSetFunction(display, gc, rop2_map[rop2]); }
106  #define RESET_FUNCTION(rop2)    { if (rop2 != ROP2_COPY) XSetFunction(display, gc, GXcopy); }  #define RESET_FUNCTION(rop2)    { if (rop2 != ROP2_COPY) XSetFunction(display, gc, GXcopy); }
107    
108    void xwin_get_numlock_mask();
109    void xwin_mod_update(uint32 state, uint32 ev_time );
110    void xwin_mod_release(uint32 state, uint32 ev_time, uint32 scancode);
111    void xwin_mod_press(uint32 state, uint32 ev_time, uint32 scancode);
112    
113  static void  static void
114  translate8(uint8 *data, uint8 *out, uint8 *end)  translate8(uint8 *data, uint8 *out, uint8 *end)
115  {  {
# Line 189  ui_create_window(char *title) Line 215  ui_create_window(char *title)
215          Screen *screen;          Screen *screen;
216          uint16 test;          uint16 test;
217          int i;          int i;
218            
219            int xkb_minor, xkb_major;
220            int xkb_event, xkb_error, xkb_reason;
221    
222            /* compare compiletime libs with runtime libs. */
223            xkb_major = XkbMajorVersion;
224            xkb_minor = XkbMinorVersion;
225            if( XkbLibraryVersion( &xkb_major, &xkb_minor ) == False )
226            {
227                    error("please re-compile rdesktop\ncompile time version of xkb is not compatible with\nyour runtime version of the library\n");
228                    return False;
229            }
230    
231    
232            display = XkbOpenDisplay( NULL, &xkb_event, &xkb_error, &xkb_major, &xkb_minor, &xkb_reason );
233            switch(xkb_reason)
234            {
235                    case XkbOD_BadLibraryVersion:
236                            error("XkbOD_BadLibraryVersion: XKB extensions in server and the library rdesktop is linked against aren't compatible with each other.\n");
237                            break;
238                    case XkbOD_ConnectionRefused:
239                            error("XkbOD_ConnectionRefused\n");
240                            break;
241                    case XkbOD_BadServerVersion:
242                            error("XkbOD_BadServerVersion\n");
243                            break;
244                    case XkbOD_NonXkbServer:
245                            error("XkbOD_NonXkbServer: XKB extension not present in server\nupdate your X server.\n");
246                            break;
247                    case XkbOD_Success:
248                            DEBUG("XkbOD_Success: Connection established with display\n");
249                            break;
250            }
251    
         display = XOpenDisplay(NULL);  
252          if (display == NULL)          if (display == NULL)
253          {          {
254                  error("Failed to open display\n");                  error("Failed to open display\n");
# Line 201  ui_create_window(char *title) Line 259  ui_create_window(char *title)
259          screen = DefaultScreenOfDisplay(display);          screen = DefaultScreenOfDisplay(display);
260          visual = DefaultVisualOfScreen(screen);          visual = DefaultVisualOfScreen(screen);
261          depth = DefaultDepthOfScreen(screen);          depth = DefaultDepthOfScreen(screen);
262            
263          pfm = XListPixmapFormats(display, &i);          pfm = XListPixmapFormats(display, &i);
264          if (pfm != NULL)          if (pfm != NULL)
265          {          {
# Line 280  ui_create_window(char *title) Line 338  ui_create_window(char *title)
338                  XFree(sizehints);                  XFree(sizehints);
339          }          }
340    
341          input_mask = KeyPressMask | KeyReleaseMask          xkeymap_init();
                         | ButtonPressMask | ButtonReleaseMask  
                         | EnterWindowMask | LeaveWindowMask;  
342    
343            input_mask = KeyPressMask | KeyReleaseMask |
344                             ButtonPressMask | ButtonReleaseMask |
345                             EnterWindowMask | LeaveWindowMask;
346          if (sendmotion)          if (sendmotion)
347                  input_mask |= PointerMotionMask;                  input_mask |= PointerMotionMask;
348    
# Line 297  ui_create_window(char *title) Line 356  ui_create_window(char *title)
356                  backstore = XCreatePixmap(display, wnd, width, height, depth);                  backstore = XCreatePixmap(display, wnd, width, height, depth);
357    
358          XMapWindow(display, wnd);          XMapWindow(display, wnd);
359    
360            /* TODO: error texts... make them friendly. */
361            xkb = XkbGetKeyboard(display, XkbAllComponentsMask, XkbUseCoreKbd);
362            if ((int)xkb == BadAlloc || xkb == NULL)
363            {
364                            error( "XkbGetKeyboard failed.\n");
365                            exit(0);
366            }
367    
368            /* TODO: error texts... make them friendly. */
369            if( XkbSelectEvents(display, xkb->device_spec, XkbAllEventsMask, XkbAllEventsMask) == False )
370            {
371                            error( "XkbSelectEvents failed.\n");
372                            exit(0);
373            }
374            
375            xwin_get_numlock_mask();
376    
377          return True;          return True;
378  }  }
379    
380  void  void
381    xwin_get_numlock_mask()
382    {
383            KeyCode numlockcode;
384            KeyCode* keycode;
385            XModifierKeymap *modmap;
386            int i,j;
387    
388            /* Find out if numlock is already defined as a modifier key, and if so where */
389            numlockcode = XKeysymToKeycode(display, 0xFF7F);        /* XF_Num_Lock = 0xFF7F */
390            if (numlockcode) {
391                    modmap = XGetModifierMapping(display);
392                    if (modmap) {
393                            keycode = modmap->modifiermap;
394                            for (i = 0; i < 8; i++)
395                                    for (j = modmap->max_keypermod; j--;) {
396                                            if (*keycode == numlockcode) {
397                                                    numlock_modifier_mask = (1 << i);
398                                                    i = 8;
399                                                    break;
400                                            }
401                                            keycode++;
402                                    }
403                    if (!numlock_modifier_mask) {
404                                    modmap->modifiermap[7 * modmap->max_keypermod] = numlockcode;
405                                    if (XSetModifierMapping(display, modmap) == MappingSuccess)
406                                            numlock_modifier_mask = (1 << 7);
407                                    else
408                                            printf("XSetModifierMapping failed!\n");
409                            }
410                            XFreeModifiermap(modmap);
411                    }
412            }
413    
414            if (!numlock_modifier_mask)
415                    printf("WARNING: Failed to get a numlock modifier mapping.\n");
416                    
417    }
418    
419    void
420  ui_destroy_window()  ui_destroy_window()
421  {  {
422            if( xkb != NULL )
423                    XkbFreeKeyboard(xkb, XkbAllControlsMask, True);
424    
425          if (ownbackstore)          if (ownbackstore)
426                  XFreePixmap(display, backstore);                  XFreePixmap(display, backstore);
427    
# Line 312  ui_destroy_window() Line 431  ui_destroy_window()
431          display = NULL;          display = NULL;
432  }  }
433    
 static uint8  
 xwin_translate_key(unsigned long key)  
 {  
         DEBUG(("KEY(code=0x%lx)\n", key));  
   
         if ((key > 8) && (key <= 0x60))  
                 return (key - 8);  
   
         switch (key)  
         {  
                 case 0x61:      /* home */  
                         return 0x47 | 0x80;  
                 case 0x62:      /* up arrow */  
                         return 0x48 | 0x80;  
                 case 0x63:      /* page up */  
                         return 0x49 | 0x80;  
                 case 0x64:      /* left arrow */  
                         return 0x4b | 0x80;  
                 case 0x66:      /* right arrow */  
                         return 0x4d | 0x80;  
                 case 0x67:      /* end */  
                         return 0x4f | 0x80;  
                 case 0x68:      /* down arrow */  
                         return 0x50 | 0x80;  
                 case 0x69:      /* page down */  
                         return 0x51 | 0x80;  
                 case 0x6a:      /* insert */  
                         return 0x52 | 0x80;  
                 case 0x6b:      /* delete */  
                         return 0x53 | 0x80;  
                 case 0x6c:      /* keypad enter */  
                         return 0x1c | 0x80;  
                 case 0x6d:      /* right ctrl */  
                         return 0x1d | 0x80;  
                 case 0x6f:      /* ctrl - print screen */  
                         return 0x37 | 0x80;  
                 case 0x70:      /* keypad '/' */  
                         return 0x35 | 0x80;  
                 case 0x71:      /* right alt */  
                         return 0x38 | 0x80;  
                 case 0x72:      /* ctrl break */  
                         return 0x46 | 0x80;  
                 case 0x73:      /* left window key */  
                         return 0xff;    /* real scancode is 5b */  
                 case 0x74:      /* right window key */  
                         return 0xff;    /* real scancode is 5c */  
                 case 0x75:      /* menu key */  
                         return 0x5d | 0x80;  
         }  
   
         return 0;  
 }  
   
 static uint16  
 xwin_translate_mouse(unsigned long button)  
 {  
         switch (button)  
         {  
                 case Button1:   /* left */  
                         return MOUSE_FLAG_BUTTON1;  
                 case Button2:   /* middle */  
                         return MOUSE_FLAG_BUTTON3;  
                 case Button3:   /* right */  
                         return MOUSE_FLAG_BUTTON2;  
         }  
   
         return 0;  
 }  
   
434  static void  static void
435  xwin_process_events()  xwin_process_events()
436  {  {
437          XEvent event;          XEvent xevent;
438    
439            KeySym keysym;
440          uint8 scancode;          uint8 scancode;
441          uint16 button;          uint16 button, flags;
442          uint32 ev_time;          uint32 ev_time;
443            uint32 tmpmods;
444    
445          if (display == NULL)          while (XCheckMaskEvent(display, ~0, &xevent))
                 return;  
   
         while (XCheckWindowEvent(display, wnd, ~0, &event))  
446          {          {
447                  ev_time = time(NULL);                  ev_time = time(NULL);
448                    flags = 0;
449    
450                  switch (event.type)                  switch (xevent.type)
451                  {                  {
452                            case KeyRelease:
453                                    flags = KBD_FLAG_DOWN | KBD_FLAG_UP;
454                                    /* fall through */
455                          case KeyPress:                          case KeyPress:
456                                  scancode = xwin_translate_key(event.xkey.keycode);                                  if( XkbTranslateKeyCode(xkb, xevent.xkey.keycode, xevent.xkey.state, &tmpmods, &keysym) == False )
                                 if (scancode == 0)  
457                                          break;                                          break;
458                                    scancode = xkeymap_translate_key(keysym, xevent.xkey.keycode, &flags);
459    
460                                  rdp_send_input(ev_time, RDP_INPUT_SCANCODE, 0,                                  if (scancode == 0 )
                                                scancode, 0);  
                                 break;  
   
                         case KeyRelease:  
                                 scancode = xwin_translate_key(event.xkey.keycode);  
                                 if (scancode == 0)  
461                                          break;                                          break;
462    
463                                  rdp_send_input(ev_time, RDP_INPUT_SCANCODE,                                  /* keep track of the modifiers -- needed for stickykeys... */
464                                                 KBD_FLAG_DOWN | KBD_FLAG_UP,                                  if( xevent.type == KeyPress )
465                                                 scancode, 0);                                          xwin_mod_press( xevent.xkey.state, ev_time, scancode );
                                 break;  
466    
467                          case ButtonPress:                                  rdp_send_input(ev_time, RDP_INPUT_SCANCODE, flags, scancode, 0);
468                                  button = xwin_translate_mouse(event.xbutton.button);  
469                                  if (button == 0)                                  if( xevent.type == KeyRelease )
470                                          break;                                          xwin_mod_release( xevent.xkey.state, ev_time, scancode );
471    
                                 rdp_send_input(ev_time, RDP_INPUT_MOUSE,  
                                                button | MOUSE_FLAG_DOWN,  
                                                event.xbutton.x,  
                                                event.xbutton.y);  
472                                  break;                                  break;
473    
474                            case ButtonPress:
475                                    flags = MOUSE_FLAG_DOWN;
476                                    /* fall through */
477    
478                          case ButtonRelease:                          case ButtonRelease:
479                                  button = xwin_translate_mouse(event.xbutton.button);                                  button = xkeymap_translate_button(xevent.xbutton.button);
480                                  if (button == 0)                                  if (button == 0)
481                                          break;                                          break;
482    
483                                  rdp_send_input(ev_time, RDP_INPUT_MOUSE,                                  rdp_send_input(ev_time, RDP_INPUT_MOUSE,
484                                                 button,                                                 flags | button,
485                                                 event.xbutton.x,                                                 xevent.xbutton.x,
486                                                 event.xbutton.y);                                                 xevent.xbutton.y);
487                                  break;                                  break;
488    
489                          case MotionNotify:                          case MotionNotify:
490                                  rdp_send_input(ev_time, RDP_INPUT_MOUSE,                                  rdp_send_input(ev_time, RDP_INPUT_MOUSE,
491                                                 MOUSE_FLAG_MOVE,                                                 MOUSE_FLAG_MOVE,
492                                                 event.xmotion.x,                                                 xevent.xmotion.x,
493                                                 event.xmotion.y);                                                 xevent.xmotion.y);
494                                  break;                                  break;
495    
496                          case EnterNotify:                          case EnterNotify:
497                                  XGrabKeyboard(display, wnd, True, GrabModeAsync,                                  XGrabKeyboard(display, wnd, True, GrabModeAsync,
498                                                GrabModeAsync, CurrentTime);                                                GrabModeAsync, CurrentTime);
499    
500                                     xwin_mod_update( xevent.xcrossing.state, ev_time );
501                                  break;                                  break;
502    
503                          case LeaveNotify:                          case LeaveNotify:
# Line 457  xwin_process_events() Line 506  xwin_process_events()
506    
507                          case Expose:                          case Expose:
508                                  XCopyArea(display, backstore, wnd, gc,                                  XCopyArea(display, backstore, wnd, gc,
509                                            event.xexpose.x, event.xexpose.y,                                            xevent.xexpose.x, xevent.xexpose.y,
510                                            event.xexpose.width, event.xexpose.height,                                            xevent.xexpose.width, xevent.xexpose.height,
511                                            event.xexpose.x, event.xexpose.y);                                            xevent.xexpose.x, xevent.xexpose.y);
512                                  break;                                  break;
513                  }                  }
514          }          }
515  }  }
516    
517  void  void
518    xwin_mod_update(uint32 state, uint32 ev_time )
519    {
520            xwin_mod_press(state, ev_time, 0);
521            xwin_mod_release(state, ev_time, 0);
522    }
523    
524    void
525    xwin_mod_release(uint32 state, uint32 ev_time, uint32 scancode)
526    {
527            switch (scancode) {
528            case 0x2a:
529                    key_down_state &= ~DShift1Mask;
530                    break;
531            case 0x36:
532                    key_down_state &= ~DShift2Mask;
533                    break;
534            case 0x1d:
535                    key_down_state &= ~DControl1Mask;
536                    break;
537            case 0x9d:
538                    key_down_state &= ~DControl2Mask;
539                    break;
540            case 0x38:
541                    key_down_state &= ~DMod1Mask;
542                    break;
543            case 0xb8:
544                    key_down_state &= ~DMod2Mask;
545                    break;
546            }
547    
548            if( !(numlock_modifier_mask & state) && (key_down_state & DNumLockMask) )
549            {
550                    rdp_send_input(ev_time, RDP_INPUT_SCANCODE, 0, 0x45, 0);
551                    rdp_send_input(ev_time, RDP_INPUT_SCANCODE, KBD_FLAG_DOWN | KBD_FLAG_UP, 0x45, 0);
552                    key_down_state &= ~DNumLockMask;
553            }
554    
555            if( !(LockMask & state) && (key_down_state & DLockMask))
556            {
557                    rdp_send_input(ev_time, RDP_INPUT_SCANCODE, 0, 0x3a, 0);
558                    rdp_send_input(ev_time, RDP_INPUT_SCANCODE, KBD_FLAG_DOWN | KBD_FLAG_UP, 0x3a, 0);
559                    key_down_state &= ~DLockMask;
560    
561            }
562    
563    
564            if( !(ShiftMask & state) && (key_down_state & DShift1Mask))
565            {
566                    rdp_send_input(ev_time, RDP_INPUT_SCANCODE, KBD_FLAG_UP, 0x2a, 0);
567                    key_down_state &= ~DShift1Mask;
568    
569            }
570    
571            if( !(ControlMask & state) && (key_down_state & DControl1Mask))
572            {
573                    rdp_send_input(ev_time, RDP_INPUT_SCANCODE, KBD_FLAG_UP, 0x1d, 0);
574                    key_down_state &= ~DControl1Mask;
575    
576            }
577    
578            if( !(Mod1Mask & state) && (key_down_state & DMod1Mask))
579            {
580                    rdp_send_input(ev_time, RDP_INPUT_SCANCODE, KBD_FLAG_UP, 0x38, 0);
581                    key_down_state &= ~DMod1Mask;
582    
583            }
584    
585            if( !(Mod2Mask & state) && (key_down_state & DMod2Mask))
586            {
587                    rdp_send_input(ev_time, RDP_INPUT_SCANCODE, KBD_FLAG_UP, 0xb8, 0);
588                    key_down_state &= ~DMod2Mask;
589            }
590    }
591    
592    
593    void
594    xwin_mod_press(uint32 state, uint32 ev_time, uint32 scancode)
595    {
596    
597            switch (scancode) {
598            case 0x2a:
599                    key_down_state |= DShift1Mask;
600                    break;
601            case 0x36:
602                    key_down_state |= DShift2Mask;
603                    break;
604            case 0x1d:
605                    key_down_state |= DControl1Mask;
606                    break;
607            case 0x9d:
608                    key_down_state |= DControl2Mask;
609                    break;
610            case 0x3a:
611                    key_down_state ^= DLockMask;
612                    break;
613            case 0x45:
614                    key_down_state ^= DNumLockMask;
615                    break;
616            case 0x38:
617                    key_down_state |= DMod1Mask;
618                    break;
619            case 0xb8:
620                    key_down_state |= DMod2Mask;
621                    break;
622            }
623    
624            if( (numlock_modifier_mask && state) && !(key_down_state & DNumLockMask) )
625            {
626                    rdp_send_input(ev_time, RDP_INPUT_SCANCODE, 0, 0x45, 0);
627                    rdp_send_input(ev_time, RDP_INPUT_SCANCODE, KBD_FLAG_DOWN | KBD_FLAG_UP, 0x45, 0);
628                    key_down_state |= DNumLockMask;
629            }
630    
631            if( (LockMask & state) && !(key_down_state & DLockMask))
632            {
633                    rdp_send_input(ev_time, RDP_INPUT_SCANCODE, 0, 0x3a, 0);
634                    rdp_send_input(ev_time, RDP_INPUT_SCANCODE, KBD_FLAG_DOWN | KBD_FLAG_UP, 0x3a, 0);
635                    key_down_state |= DLockMask;
636    
637            }
638    
639    
640            if( (ShiftMask & state) && !((key_down_state & DShift1Mask) || (key_down_state & DShift2Mask)))
641            {
642                    rdp_send_input(ev_time, RDP_INPUT_SCANCODE, KBD_FLAG_DOWN, 0x2a, 0);
643                    key_down_state |= DShift1Mask;
644    
645            }
646    
647            if( (ControlMask & state) && !((key_down_state & DControl1Mask) || (key_down_state & DControl2Mask)))
648            {
649                    rdp_send_input(ev_time, RDP_INPUT_SCANCODE, KBD_FLAG_DOWN, 0x1d, 0);
650                    key_down_state |= DControl1Mask;
651    
652            }
653    
654            if( (Mod1Mask & state) && !(key_down_state & DMod1Mask))
655            {
656                    rdp_send_input(ev_time, RDP_INPUT_SCANCODE, KBD_FLAG_DOWN, 0x38, 0);
657                    key_down_state |= DMod1Mask;
658    
659            }
660    
661            if( (Mod2Mask & state) && !(key_down_state & DMod2Mask))
662            {
663                    rdp_send_input(ev_time, RDP_INPUT_SCANCODE, KBD_FLAG_DOWN, 0xb8, 0);
664                    key_down_state |= DMod2Mask;
665    
666            }
667    }
668    
669    void
670  ui_select(int rdp_socket)  ui_select(int rdp_socket)
671  {  {
672          int n = (rdp_socket > x_socket) ? rdp_socket+1 : x_socket+1;          int n = (rdp_socket > x_socket) ? rdp_socket+1 : x_socket+1;
673          fd_set rfds;          fd_set rfds;
674    
         XFlush(display);  
   
675          FD_ZERO(&rfds);          FD_ZERO(&rfds);
676    
677          while (True)          while (True)
678          {          {
679                  FD_ZERO(&rfds);                  FD_ZERO(&rfds);
680                  FD_SET(rdp_socket, &rfds);                  FD_SET(rdp_socket, &rfds);
681                  FD_SET(x_socket, &rfds);                  if (display != NULL)
682                    {
683                            FD_SET(x_socket, &rfds);
684                            XFlush(display);
685                    }
686    
687                  switch (select(n, &rfds, NULL, NULL, NULL))                  switch (select(n, &rfds, NULL, NULL, NULL))
688                  {                  {
# Line 789  ui_patblt(uint8 opcode, Line 992  ui_patblt(uint8 opcode,
992            /* brush */ BRUSH *brush, int bgcolour, int fgcolour)            /* brush */ BRUSH *brush, int bgcolour, int fgcolour)
993  {  {
994          Pixmap fill;          Pixmap fill;
995            uint8 i, ipattern[8];
996    
997          SET_FUNCTION(opcode);          SET_FUNCTION(opcode);
998    
# Line 800  ui_patblt(uint8 opcode, Line 1004  ui_patblt(uint8 opcode,
1004                          break;                          break;
1005    
1006                  case 3: /* Pattern */                  case 3: /* Pattern */
1007                          fill = (Pixmap)ui_create_glyph(8, 8, brush->pattern);                          for (i = 0; i != 8; i++)
1008                                    ipattern[7 - i] = brush->pattern[i];
1009                            fill = (Pixmap) ui_create_glyph(8, 8, ipattern);
1010    
1011                          SET_FOREGROUND(bgcolour);                          SET_FOREGROUND(bgcolour);
1012                          SET_BACKGROUND(fgcolour);                          SET_BACKGROUND(fgcolour);
# Line 925  ui_draw_glyph(int mixmode, Line 1131  ui_draw_glyph(int mixmode,
1131          XSetFillStyle(display, gc, FillSolid);          XSetFillStyle(display, gc, FillSolid);
1132  }  }
1133    
1134    #define DO_GLYPH(ttext,idx) \
1135    {\
1136      glyph = cache_get_font (font, ttext[idx]);\
1137      if (!(flags & TEXT2_IMPLICIT_X))\
1138        {\
1139          xyoffset = ttext[++idx];\
1140          if ((xyoffset & 0x80))\
1141            {\
1142              if (flags & TEXT2_VERTICAL) \
1143                y += ttext[++idx] | (ttext[++idx] << 8);\
1144              else\
1145                x += ttext[++idx] | (ttext[++idx] << 8);\
1146            }\
1147          else\
1148            {\
1149              if (flags & TEXT2_VERTICAL) \
1150                y += xyoffset;\
1151              else\
1152                x += xyoffset;\
1153            }\
1154        }\
1155      if (glyph != NULL)\
1156        {\
1157          ui_draw_glyph (mixmode, x + (short) glyph->offset,\
1158                         y + (short) glyph->baseline,\
1159                         glyph->width, glyph->height,\
1160                         glyph->pixmap, 0, 0, bgcolour, fgcolour);\
1161          if (flags & TEXT2_IMPLICIT_X)\
1162            x += glyph->width;\
1163        }\
1164    }
1165    
1166  void  void
1167  ui_draw_text(uint8 font, uint8 flags, int mixmode, int x, int y,  ui_draw_text(uint8 font, uint8 flags, int mixmode, int x, int y,
1168               int clipx, int clipy, int clipcx, int clipcy,               int clipx, int clipy, int clipcx, int clipcy, int boxx,
1169               int boxx, int boxy, int boxcx, int boxcy,               int boxy, int boxcx, int boxcy, int bgcolour,
1170               int bgcolour, int fgcolour, uint8 *text, uint8 length)               int fgcolour, uint8 * text, uint8 length)
1171  {  {
1172          FONTGLYPH *glyph;          FONTGLYPH *glyph;
1173          int i, offset;          int i, j, xyoffset;
1174            DATABLOB *entry;
1175    
1176          SET_FOREGROUND(bgcolour);          SET_FOREGROUND(bgcolour);
1177    
# Line 946  ui_draw_text(uint8 font, uint8 flags, in Line 1185  ui_draw_text(uint8 font, uint8 flags, in
1185          }          }
1186    
1187          /* Paint text, character by character */          /* Paint text, character by character */
1188          for (i = 0; i < length; i++)          for (i = 0; i < length;) {
1189          {                  switch (text[i]) {
1190                  glyph = cache_get_font(font, text[i]);                  case 0xff:
1191                            if (i + 2 < length)
1192                                    cache_put_text(text[i + 1], text, text[i + 2]);
1193                            else {
1194                                    error("this shouldn't be happening\n");
1195                                    break;
1196                            }
1197                            /* this will move pointer from start to first character after FF command */
1198                            length -= i + 3;
1199                            text = &(text[i + 3]);
1200                            i = 0;
1201                            break;
1202    
1203                  if (!(flags & TEXT2_IMPLICIT_X))                  case 0xfe:
1204                  {                          entry = cache_get_text(text[i + 1]);
1205                          offset = text[++i];                          if (entry != NULL) {
1206                          if (offset & 0x80)                                  if ((((uint8 *) (entry->data))[1] == 0)
1207                                  offset = ((offset & 0x7f) << 8) | text[++i];                                      && (!(flags & TEXT2_IMPLICIT_X))) {
1208                                            if (flags & TEXT2_VERTICAL)
1209                                                    y += text[i + 2];
1210                                            else
1211                                                    x += text[i + 2];
1212                                    }
1213                                    if (i + 2 < length)
1214                                            i += 3;
1215                                    else
1216                                            i += 2;
1217                                    length -= i;
1218                                    /* this will move pointer from start to first character after FE command */
1219                                    text = &(text[i]);
1220                                    i = 0;
1221                                    for (j = 0; j < entry->size; j++)
1222                                            DO_GLYPH(((uint8 *) (entry->data)), j);
1223                            }
1224                            break;
1225    
1226                          if (flags & TEXT2_VERTICAL)                  default:
1227                                  y += offset;                          DO_GLYPH(text, i);
1228                          else                          i++;
1229                                  x += offset;                          break;
1230                  }                  }
1231            }
1232    
                 if (glyph != NULL)  
                 {  
                         ui_draw_glyph(mixmode, x + (short) glyph->offset,  
                                       y + (short) glyph->baseline,  
                                       glyph->width, glyph->height,  
                                       glyph->pixmap, 0, 0,  
                                       bgcolour, fgcolour);  
1233    
                         if (flags & TEXT2_IMPLICIT_X)  
                                 x += glyph->width;  
                 }  
         }  
1234  }  }
1235    
1236  void  void
# Line 998  ui_desktop_save(uint32 offset, int x, in Line 1255  ui_desktop_save(uint32 offset, int x, in
1255    
1256          offset *= bpp/8;          offset *= bpp/8;
1257          cache_put_desktop(offset, cx, cy, image->bytes_per_line,          cache_put_desktop(offset, cx, cy, image->bytes_per_line,
1258                            bpp/8, image->data);                            bpp/8, (uint8 *)image->data);
1259    
1260          XDestroyImage(image);          XDestroyImage(image);
1261  }  }

Legend:
Removed from v.35  
changed lines
  Added in v.59

  ViewVC Help
Powered by ViewVC 1.1.26