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

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

revision 64 by astrand, Thu Jul 18 16:38:31 2002 UTC revision 185 by n-ki, Wed Sep 18 12:13:08 2002 UTC
# Line 20  Line 20 
20    
21  #include <X11/Xlib.h>  #include <X11/Xlib.h>
22  #include <X11/Xutil.h>  #include <X11/Xutil.h>
 #include <X11/XKBlib.h>  
23  #include <time.h>  #include <time.h>
24  #include <errno.h>  #include <errno.h>
25    #define XK_MISCELLANY
26    #include <X11/keysymdef.h>
27  #include "rdesktop.h"  #include "rdesktop.h"
28    #include "scancodes.h"
29    
 extern char keymapname[16];  
 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    extern BOOL grab_keyboard;
35    extern char title[];
36    
37  Display *display;  Display *display;
 XkbDescPtr xkb;  
38  static int x_socket;  static int x_socket;
39    static Screen *screen;
40  static Window wnd;  static Window wnd;
41  static GC gc;  static GC gc;
42  static Visual *visual;  static Visual *visual;
# Line 49  static BOOL xserver_be; Line 51  static BOOL xserver_be;
51  static BOOL ownbackstore;  static BOOL ownbackstore;
52  static Pixmap backstore;  static Pixmap backstore;
53    
 /* needed to keep track of the modifiers */  
 static unsigned int numlock_modifier_mask = 0;  
 static unsigned int key_down_state = 0;  
   
   
 #define DShift1Mask   (1<<0)  
 #define DLockMask     (1<<1)  
 #define DControl1Mask (1<<2)  
 #define DMod1Mask     (1<<3)  
 #define DMod2Mask     (1<<4)  
 #define DMod3Mask     (1<<5)  
 #define DMod4Mask     (1<<6)  
 #define DMod5Mask     (1<<7)  
 #define DShift2Mask   (1<<8)  
 #define DControl2Mask (1<<9)  
 #define DNumLockMask  (1<<10)  
   
54  #define FILL_RECTANGLE(x,y,cx,cy)\  #define FILL_RECTANGLE(x,y,cx,cy)\
55  { \  { \
56          XFillRectangle(display, wnd, gc, x, y, cx, cy); \          XFillRectangle(display, wnd, gc, x, y, cx, cy); \
# Line 74  static unsigned int key_down_state = 0; Line 59  static unsigned int key_down_state = 0;
59  }  }
60    
61  /* colour maps */  /* colour maps */
 static BOOL owncolmap;  
62  static Colormap xcolmap;  static Colormap xcolmap;
 static uint32 white;  
63  static uint32 *colmap;  static uint32 *colmap;
64    
65  #define TRANSLATE(col)          ( owncolmap ? col : translate_colour(colmap[col]) )  /* Compose support */
66  #define SET_FOREGROUND(col)     XSetForeground(display, gc, TRANSLATE(col));  BOOL enable_compose = False;
67  #define SET_BACKGROUND(col)     XSetBackground(display, gc, TRANSLATE(col));  static XIM IM = NULL;
68    static XIC IC = NULL;
69    
70    /* toggle fullscreen globals */
71    static unsigned long input_mask;
72    
73    #define SET_FOREGROUND(col)     XSetForeground(display, gc, translate_colour(colmap[col]));
74    #define SET_BACKGROUND(col)     XSetBackground(display, gc, translate_colour(colmap[col]));
75    
76  static int rop2_map[] = {  static int rop2_map[] = {
77          GXclear,                /* 0 */          GXclear,                /* 0 */
# Line 105  static int rop2_map[] = { Line 95  static int rop2_map[] = {
95  #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]); }
96  #define RESET_FUNCTION(rop2)    { if (rop2 != ROP2_COPY) XSetFunction(display, gc, GXcopy); }  #define RESET_FUNCTION(rop2)    { if (rop2 != ROP2_COPY) XSetFunction(display, gc, GXcopy); }
97    
 void xwin_get_numlock_mask();  
 void xwin_mod_update(uint32 state, uint32 ev_time);  
 void xwin_mod_release(uint32 state, uint32 ev_time, uint32 scancode);  
 void xwin_mod_press(uint32 state, uint32 ev_time, uint32 scancode);  
   
98  static void  static void
99  translate8(uint8 * data, uint8 * out, uint8 * end)  translate8(uint8 * data, uint8 * out, uint8 * end)
100  {  {
# Line 204  translate_colour(uint32 colour) Line 189  translate_colour(uint32 colour)
189          return colour;          return colour;
190  }  }
191    
192  BOOL  static unsigned long
193  ui_create_window(char *title)  init_inputmethod(void)
194  {  {
195          XSetWindowAttributes attribs;          unsigned long filtered_events = 0;
         XClassHint *classhints;  
         XSizeHints *sizehints;  
         unsigned long input_mask;  
         XPixmapFormatValues *pfm;  
         Screen *screen;  
         uint16 test;  
         int i;  
196    
197          int xkb_minor, xkb_major;          IM = XOpenIM(display, NULL, NULL, NULL);
198          int xkb_event, xkb_error, xkb_reason;          if (IM == NULL)
199            {
200                    error("Failed to open input method\n");
201            }
202    
203          /* compare compiletime libs with runtime libs. */          if (IM != NULL)
         xkb_major = XkbMajorVersion;  
         xkb_minor = XkbMinorVersion;  
         if (XkbLibraryVersion(&xkb_major, &xkb_minor) == False)  
204          {          {
205                  error("please re-compile rdesktop\ncompile time version of xkb is not compatible with\nyour runtime version of the library\n");                  /* Must be done after XCreateWindow */
206                  return False;                  IC = XCreateIC(IM, XNInputStyle,
207                                   (XIMPreeditNothing | XIMStatusNothing),
208                                   XNClientWindow, wnd, XNFocusWindow, wnd, NULL);
209    
210                    if (IC == NULL)
211                    {
212                            error("Failed to create input context\n");
213                            XCloseIM(IM);
214                            IM = NULL;
215                    }
216          }          }
217    
218            /* For correct Multi_key/Compose processing, I guess.
219               It seems to work alright anyway, though. */
220            if (IC != NULL)
221            {
222                    if (XGetICValues(IC, XNFilterEvents, &filtered_events, NULL) != NULL)
223                    {
224                            error("Failed to obtain XNFilterEvents value from IC\n");
225                            filtered_events = 0;
226                    }
227            }
228            return filtered_events;
229    }
230    
231          display =  static void
232                  XkbOpenDisplay(NULL, &xkb_event, &xkb_error, &xkb_major,  close_inputmethod(void)
233                                 &xkb_minor, &xkb_reason);  {
234          switch (xkb_reason)          if (IC != NULL)
235          {          {
236                  case XkbOD_BadLibraryVersion:                  XDestroyIC(IC);
237                          error("XkbOD_BadLibraryVersion: XKB extensions in server and the library rdesktop is linked against aren't compatible with each other.\n");                  if (IM != NULL)
238                          break;                  {
239                  case XkbOD_ConnectionRefused:                          XCloseIM(IM);
240                          error("XkbOD_ConnectionRefused\n");                          IM = NULL;
241                          break;                  }
242                  case XkbOD_BadServerVersion:          }
243                          error("XkbOD_BadServerVersion\n");  }
244                          break;  
245                  case XkbOD_NonXkbServer:  BOOL
246                          error("XkbOD_NonXkbServer: XKB extension not present in server\nupdate your X server.\n");  get_key_state(int keysym)
247                          break;  {
248                  case XkbOD_Success:          int keysymMask = 0, modifierpos, key;
249                          DEBUG("XkbOD_Success: Connection established with display\n");          Window wDummy1, wDummy2;
250                          break;          int iDummy3, iDummy4, iDummy5, iDummy6;
251            unsigned int current_state;
252            int offset;
253    
254            XModifierKeymap *map = XGetModifierMapping(display);
255            KeyCode keycode = XKeysymToKeycode(display, keysym);
256    
257            if (keycode == NoSymbol)
258                    return False;
259    
260            for (modifierpos = 0; modifierpos < 8; modifierpos++)
261            {
262                    offset = map->max_keypermod * modifierpos;
263    
264                    for (key = 0; key < map->max_keypermod; key++)
265                    {
266                            if (map->modifiermap[offset + key] == keycode)
267                                    keysymMask = 1 << modifierpos;
268                    }
269          }          }
270    
271            XQueryPointer(display, DefaultRootWindow(display), &wDummy1,
272                          &wDummy2, &iDummy3, &iDummy4, &iDummy5, &iDummy6, &current_state);
273    
274            XFreeModifiermap(map);
275    
276            return (current_state & keysymMask) ? True : False;
277    }
278    
279    static void
280    xwin_map_window()
281    {
282            XEvent xevent;
283    
284            XMapWindow(display, wnd);
285    
286            /* wait for VisibilityChange */
287            XMaskEvent(display, VisibilityChangeMask, &xevent);
288    
289            if (fullscreen)
290                    XSetInputFocus(display, wnd, RevertToPointerRoot, CurrentTime);
291    }
292    
293    BOOL
294    ui_init()
295    {
296            XPixmapFormatValues *pfm;
297            uint16 test;
298            int i;
299    
300            display = XOpenDisplay(NULL);
301          if (display == NULL)          if (display == NULL)
302          {          {
303                  error("Failed to open display\n");                  error("Failed to open display\n");
# Line 269  ui_create_window(char *title) Line 316  ui_create_window(char *title)
316                     desirable, e.g. 24 bits->32 bits. */                     desirable, e.g. 24 bits->32 bits. */
317                  while (i--)                  while (i--)
318                  {                  {
319                          if ((pfm[i].depth == depth)                          if ((pfm[i].depth == depth) && (pfm[i].bits_per_pixel > bpp))
                             && (pfm[i].bits_per_pixel > bpp))  
320                          {                          {
321                                  bpp = pfm[i].bits_per_pixel;                                  bpp = pfm[i].bits_per_pixel;
322                          }                          }
# Line 285  ui_create_window(char *title) Line 331  ui_create_window(char *title)
331                  return False;                  return False;
332          }          }
333    
334          if (depth <= 8)          xcolmap = DefaultColormapOfScreen(screen);
335                  owncolmap = True;  
336          else          if (DoesBackingStore(screen) == NotUseful)
337                  xcolmap = DefaultColormapOfScreen(screen);                  ownbackstore = True;
338    
339          test = 1;          test = 1;
340          host_be = !(BOOL) (*(uint8 *) (&test));          host_be = !(BOOL) (*(uint8 *) (&test));
341          xserver_be = (ImageByteOrder(display) == MSBFirst);          xserver_be = (ImageByteOrder(display) == MSBFirst);
342    
         white = WhitePixelOfScreen(screen);  
         attribs.background_pixel = BlackPixelOfScreen(screen);  
         attribs.backing_store = DoesBackingStore(screen);  
   
         if (attribs.backing_store == NotUseful)  
                 ownbackstore = True;  
   
343          if (fullscreen)          if (fullscreen)
344          {          {
                 attribs.override_redirect = True;  
345                  width = WidthOfScreen(screen);                  width = WidthOfScreen(screen);
346                  height = HeightOfScreen(screen);                  height = HeightOfScreen(screen);
347          }          }
         else  
         {  
                 attribs.override_redirect = False;  
         }  
348    
349          width = (width + 3) & ~3;       /* make width a multiple of 32 bits */          /* make sure width is a multiple of 4 */
350            width = (width + 3) & ~3;
351    
352          wnd = XCreateWindow(display, RootWindowOfScreen(screen),          xkeymap_init();
353                              0, 0, width, height, 0, CopyFromParent,          return True;
354                              InputOutput, CopyFromParent,  }
355                              CWBackingStore | CWBackPixel | CWOverrideRedirect,  
356                              &attribs);  BOOL
357    ui_create_window()
358    {
359            XSetWindowAttributes attribs;
360            XClassHint *classhints;
361            XSizeHints *sizehints;
362            XEvent xevent;
363    
364            attribs.background_pixel = BlackPixelOfScreen(screen);
365            attribs.backing_store = ownbackstore ? NotUseful : Always;
366            attribs.override_redirect = fullscreen;
367            wnd = XCreateWindow(display, RootWindowOfScreen(screen), 0, 0, width, height,
368                                0, CopyFromParent, InputOutput, CopyFromParent,
369                                CWBackPixel | CWBackingStore | CWOverrideRedirect, &attribs);
370    
371            if (ownbackstore)
372                    backstore = XCreatePixmap(display, wnd, width, height, depth);
373    
374          XStoreName(display, wnd, title);          XStoreName(display, wnd, title);
375    
# Line 340  ui_create_window(char *title) Line 391  ui_create_window(char *title)
391                  XFree(sizehints);                  XFree(sizehints);
392          }          }
393    
394          xkeymap_init();          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
395                    VisibilityChangeMask | FocusChangeMask;
396    
397          input_mask = KeyPressMask | KeyReleaseMask |          if (grab_keyboard)
398                  ButtonPressMask | ButtonReleaseMask |                  input_mask |= EnterWindowMask | LeaveWindowMask;
                 EnterWindowMask | LeaveWindowMask;  
399          if (sendmotion)          if (sendmotion)
400                  input_mask |= PointerMotionMask;                  input_mask |= PointerMotionMask;
   
401          if (ownbackstore)          if (ownbackstore)
402                  input_mask |= ExposureMask;                  input_mask |= ExposureMask;
403            if (enable_compose)
404                    input_mask |= init_inputmethod();
405    
406          XSelectInput(display, wnd, input_mask);          XSelectInput(display, wnd, input_mask);
         gc = XCreateGC(display, wnd, 0, NULL);  
   
         if (ownbackstore)  
                 backstore = XCreatePixmap(display, wnd, width, height, depth);  
   
         XMapWindow(display, wnd);  
   
         /* TODO: error texts... make them friendly. */  
         xkb = XkbGetKeyboard(display, XkbAllComponentsMask, XkbUseCoreKbd);  
         if ((int) xkb == BadAlloc || xkb == NULL)  
         {  
                 error("XkbGetKeyboard failed.\n");  
                 exit(0);  
         }  
407    
408          /* TODO: error texts... make them friendly. */          xwin_map_window();
         if (XkbSelectEvents  
             (display, xkb->device_spec, XkbAllEventsMask,  
              XkbAllEventsMask) == False)  
         {  
                 error("XkbSelectEvents failed.\n");  
                 exit(0);  
         }  
409    
410          xwin_get_numlock_mask();          /* clear the window so that cached data is not seen */
411            gc = XCreateGC(display, wnd, 0, NULL);
412            XSetForeground(display, gc, 0);
413            FILL_RECTANGLE(0, 0, width, height);
414    
415          return True;          return True;
416  }  }
417    
418  void  void
419  xwin_get_numlock_mask()  ui_destroy_window()
420  {  {
421          KeyCode numlockcode;          if (ownbackstore)
422          KeyCode *keycode;                  XFreePixmap(display, backstore);
         XModifierKeymap *modmap;  
         int i, j;  
423    
424          /* Find out if numlock is already defined as a modifier key, and if so where */          XFreeGC(display, gc);
         numlockcode = XKeysymToKeycode(display, 0xFF7F);        /* XF_Num_Lock = 0xFF7F */  
         if (numlockcode)  
         {  
                 modmap = XGetModifierMapping(display);  
                 if (modmap)  
                 {  
                         keycode = modmap->modifiermap;  
                         for (i = 0; i < 8; i++)  
                                 for (j = modmap->max_keypermod; j--;)  
                                 {  
                                         if (*keycode == numlockcode)  
                                         {  
                                                 numlock_modifier_mask =  
                                                         (1 << i);  
                                                 i = 8;  
                                                 break;  
                                         }  
                                         keycode++;  
                                 }  
                         if (!numlock_modifier_mask)  
                         {  
                                 modmap->modifiermap[7 *  
                                                     modmap->max_keypermod] =  
                                         numlockcode;  
                                 if (XSetModifierMapping(display, modmap) ==  
                                     MappingSuccess)  
                                         numlock_modifier_mask = (1 << 7);  
                                 else  
                                         printf("XSetModifierMapping failed!\n");  
                         }  
                         XFreeModifiermap(modmap);  
                 }  
         }  
425    
426          if (!numlock_modifier_mask)          close_inputmethod();
                 printf("WARNING: Failed to get a numlock modifier mapping.\n");  
427    
428            XDestroyWindow(display, wnd);
429            XCloseDisplay(display);
430            display = NULL;
431  }  }
432    
433    
434  void  void
435  ui_destroy_window()  xwin_toggle_fullscreen()
436  {  {
437          if (xkb != NULL)          XEvent xevent;
438                  XkbFreeKeyboard(xkb, XkbAllControlsMask, True);          XSetWindowAttributes attribs;
439            int newwidth, newheight;
440    
441          if (ownbackstore)          fullscreen = !fullscreen;
442                  XFreePixmap(display, backstore);          newwidth = fullscreen ? WidthOfScreen(screen) : width;
443            newheight = fullscreen ? HeightOfScreen(screen) : height;
444    
445          XFreeGC(display, gc);          XUnmapWindow(display, wnd);
446          XDestroyWindow(display, wnd);          attribs.override_redirect = fullscreen;
447          XCloseDisplay(display);          XMoveResizeWindow(display, wnd, 0, 0, newwidth, newheight);
448          display = NULL;          XChangeWindowAttributes(display, wnd, CWOverrideRedirect, &attribs);
449            xwin_map_window();
450  }  }
451    
452    /* Process all events in Xlib queue */
453  static void  static void
454  xwin_process_events()  xwin_process_events()
455  {  {
456          XEvent xevent;          XEvent xevent;
   
457          KeySym keysym;          KeySym keysym;
         uint8 scancode;  
458          uint16 button, flags;          uint16 button, flags;
459          uint32 ev_time;          uint32 ev_time;
460          uint32 tmpmods;          key_translation tr;
461            char *ksname = NULL;
462            char str[256];
463            Status status;
464    
465          while (XCheckMaskEvent(display, ~0, &xevent))          while (XPending(display) > 0)
466          {          {
467                    XNextEvent(display, &xevent);
468    
469                    if (enable_compose && (XFilterEvent(&xevent, None) == True))
470                    {
471                            DEBUG_KBD(("Filtering event\n"));
472                            continue;
473                    }
474    
475                  ev_time = time(NULL);                  ev_time = time(NULL);
476                  flags = 0;                  flags = 0;
477    
478                  switch (xevent.type)                  switch (xevent.type)
479                  {                  {
                         case KeyRelease:  
                                 flags = KBD_FLAG_DOWN | KBD_FLAG_UP;  
                                 /* fall through */  
480                          case KeyPress:                          case KeyPress:
481                                  if (XkbTranslateKeyCode                                  if (IC != NULL)
482                                      (xkb, xevent.xkey.keycode,                                          /* Multi_key compatible version */
483                                       xevent.xkey.state, &tmpmods,                                  {
484                                       &keysym) == False)                                          XmbLookupString(IC,
485                                                            (XKeyPressedEvent *) &
486                                                            xevent, str, sizeof(str), &keysym, &status);
487                                            if (!((status == XLookupKeySym) || (status == XLookupBoth)))
488                                            {
489                                                    error("XmbLookupString failed with status 0x%x\n",
490                                                          status);
491                                                    break;
492                                            }
493                                    }
494                                    else
495                                    {
496                                            /* Plain old XLookupString */
497                                            DEBUG_KBD(("\nNo input context, using XLookupString\n"));
498                                            XLookupString((XKeyEvent *) & xevent,
499                                                          str, sizeof(str), &keysym, NULL);
500                                    }
501    
502                                    ksname = get_ksname(keysym);
503                                    DEBUG_KBD(("KeyPress for (keysym 0x%lx, %s)\n", keysym, ksname));
504    
505                                    if (handle_special_keys(keysym, ev_time, True))
506                                            break;
507    
508                                    tr = xkeymap_translate_key(keysym,
509                                                               xevent.xkey.keycode, xevent.xkey.state);
510    
511                                    if (tr.scancode == 0)
512                                          break;                                          break;
                                 scancode =  
                                         xkeymap_translate_key(keysym,  
                                                               xevent.xkey.  
                                                               keycode,  
                                                               &flags);  
513    
514                                  if (scancode == 0)                                  ensure_remote_modifiers(ev_time, tr);
515    
516                                    rdp_send_scancode(ev_time, RDP_KEYPRESS, tr.scancode);
517                                    break;
518                            case KeyRelease:
519                                    XLookupString((XKeyEvent *) & xevent, str,
520                                                  sizeof(str), &keysym, NULL);
521    
522                                    ksname = get_ksname(keysym);
523                                    DEBUG_KBD(("\nKeyRelease for (keysym 0x%lx, %s)\n", keysym,
524                                               ksname));
525    
526                                    if (handle_special_keys(keysym, ev_time, False))
527                                          break;                                          break;
528    
529                                  /* keep track of the modifiers -- needed for stickykeys... */                                  tr = xkeymap_translate_key(keysym,
530                                  if (xevent.type == KeyPress)                                                             xevent.xkey.keycode, xevent.xkey.state);
531                                          xwin_mod_press(xevent.xkey.state,  
532                                                         ev_time, scancode);                                  if (tr.scancode == 0)
533                                            break;
                                 rdp_send_input(ev_time, RDP_INPUT_SCANCODE,  
                                                flags, scancode, 0);  
   
                                 if (xevent.type == KeyRelease)  
                                         xwin_mod_release(xevent.xkey.state,  
                                                          ev_time, scancode);  
534    
535                                    rdp_send_scancode(ev_time, RDP_KEYRELEASE, tr.scancode);
536                                  break;                                  break;
537    
538                          case ButtonPress:                          case ButtonPress:
# Line 499  xwin_process_events() Line 540  xwin_process_events()
540                                  /* fall through */                                  /* fall through */
541    
542                          case ButtonRelease:                          case ButtonRelease:
543                                  button = xkeymap_translate_button(xevent.                                  button = xkeymap_translate_button(xevent.xbutton.button);
                                                                   xbutton.  
                                                                   button);  
544                                  if (button == 0)                                  if (button == 0)
545                                          break;                                          break;
546    
547                                  rdp_send_input(ev_time, RDP_INPUT_MOUSE,                                  rdp_send_input(ev_time, RDP_INPUT_MOUSE,
548                                                 flags | button,                                                 flags | button, xevent.xbutton.x, xevent.xbutton.y);
                                                xevent.xbutton.x,  
                                                xevent.xbutton.y);  
549                                  break;                                  break;
550    
551                          case MotionNotify:                          case MotionNotify:
552                                  rdp_send_input(ev_time, RDP_INPUT_MOUSE,                                  rdp_send_input(ev_time, RDP_INPUT_MOUSE,
553                                                 MOUSE_FLAG_MOVE,                                                 MOUSE_FLAG_MOVE, xevent.xmotion.x, xevent.xmotion.y);
                                                xevent.xmotion.x,  
                                                xevent.xmotion.y);  
554                                  break;                                  break;
555    
556                          case EnterNotify:                          case EnterNotify:
557                                  XGrabKeyboard(display, wnd, True,                                  if (grab_keyboard)
558                                                GrabModeAsync, GrabModeAsync,                                          XGrabKeyboard(display, wnd, True,
559                                                CurrentTime);                                                        GrabModeAsync, GrabModeAsync, CurrentTime);
   
                                 xwin_mod_update(xevent.xcrossing.state,  
                                                 ev_time);  
560                                  break;                                  break;
561    
562                          case LeaveNotify:                          case LeaveNotify:
563                                  XUngrabKeyboard(display, CurrentTime);                                  if (grab_keyboard)
564                                            XUngrabKeyboard(display, CurrentTime);
565                                    break;
566    
567                            case FocusIn:
568                                    reset_modifier_keys();
569                                  break;                                  break;
570    
571                          case Expose:                          case Expose:
# Line 538  xwin_process_events() Line 575  xwin_process_events()
575                                            xevent.xexpose.height,                                            xevent.xexpose.height,
576                                            xevent.xexpose.x, xevent.xexpose.y);                                            xevent.xexpose.x, xevent.xexpose.y);
577                                  break;                                  break;
                 }  
         }  
 }  
   
 void  
 xwin_mod_update(uint32 state, uint32 ev_time)  
 {  
         xwin_mod_press(state, ev_time, 0);  
         xwin_mod_release(state, ev_time, 0);  
 }  
   
 void  
 xwin_mod_release(uint32 state, uint32 ev_time, uint32 scancode)  
 {  
         switch (scancode)  
         {  
                 case 0x2a:  
                         key_down_state &= ~DShift1Mask;  
                         break;  
                 case 0x36:  
                         key_down_state &= ~DShift2Mask;  
                         break;  
                 case 0x1d:  
                         key_down_state &= ~DControl1Mask;  
                         break;  
                 case 0x9d:  
                         key_down_state &= ~DControl2Mask;  
                         break;  
                 case 0x38:  
                         key_down_state &= ~DMod1Mask;  
                         break;  
                 case 0xb8:  
                         key_down_state &= ~DMod2Mask;  
                         break;  
         }  
   
         if (!(numlock_modifier_mask & state)  
             && (key_down_state & DNumLockMask))  
         {  
                 rdp_send_input(ev_time, RDP_INPUT_SCANCODE, 0, 0x45, 0);  
                 rdp_send_input(ev_time, RDP_INPUT_SCANCODE,  
                                KBD_FLAG_DOWN | KBD_FLAG_UP, 0x45, 0);  
                 key_down_state &= ~DNumLockMask;  
         }  
   
         if (!(LockMask & state) && (key_down_state & DLockMask))  
         {  
                 rdp_send_input(ev_time, RDP_INPUT_SCANCODE, 0, 0x3a, 0);  
                 rdp_send_input(ev_time, RDP_INPUT_SCANCODE,  
                                KBD_FLAG_DOWN | KBD_FLAG_UP, 0x3a, 0);  
                 key_down_state &= ~DLockMask;  
   
         }  
   
   
         if (!(ShiftMask & state) && (key_down_state & DShift1Mask))  
         {  
                 rdp_send_input(ev_time, RDP_INPUT_SCANCODE, KBD_FLAG_UP, 0x2a,  
                                0);  
                 key_down_state &= ~DShift1Mask;  
   
         }  
   
         if (!(ControlMask & state) && (key_down_state & DControl1Mask))  
         {  
                 rdp_send_input(ev_time, RDP_INPUT_SCANCODE, KBD_FLAG_UP, 0x1d,  
                                0);  
                 key_down_state &= ~DControl1Mask;  
   
         }  
   
         if (!(Mod1Mask & state) && (key_down_state & DMod1Mask))  
         {  
                 rdp_send_input(ev_time, RDP_INPUT_SCANCODE, KBD_FLAG_UP, 0x38,  
                                0);  
                 key_down_state &= ~DMod1Mask;  
   
         }  
   
         if (!(Mod2Mask & state) && (key_down_state & DMod2Mask))  
         {  
                 rdp_send_input(ev_time, RDP_INPUT_SCANCODE, KBD_FLAG_UP, 0xb8,  
                                0);  
                 key_down_state &= ~DMod2Mask;  
         }  
 }  
   
   
 void  
 xwin_mod_press(uint32 state, uint32 ev_time, uint32 scancode)  
 {  
   
         switch (scancode)  
         {  
                 case 0x2a:  
                         key_down_state |= DShift1Mask;  
                         break;  
                 case 0x36:  
                         key_down_state |= DShift2Mask;  
                         break;  
                 case 0x1d:  
                         key_down_state |= DControl1Mask;  
                         break;  
                 case 0x9d:  
                         key_down_state |= DControl2Mask;  
                         break;  
                 case 0x3a:  
                         key_down_state ^= DLockMask;  
                         break;  
                 case 0x45:  
                         key_down_state ^= DNumLockMask;  
                         break;  
                 case 0x38:  
                         key_down_state |= DMod1Mask;  
                         break;  
                 case 0xb8:  
                         key_down_state |= DMod2Mask;  
                         break;  
         }  
   
         if ((numlock_modifier_mask && state)  
             && !(key_down_state & DNumLockMask))  
         {  
                 rdp_send_input(ev_time, RDP_INPUT_SCANCODE, 0, 0x45, 0);  
                 rdp_send_input(ev_time, RDP_INPUT_SCANCODE,  
                                KBD_FLAG_DOWN | KBD_FLAG_UP, 0x45, 0);  
                 key_down_state |= DNumLockMask;  
         }  
   
         if ((LockMask & state) && !(key_down_state & DLockMask))  
         {  
                 rdp_send_input(ev_time, RDP_INPUT_SCANCODE, 0, 0x3a, 0);  
                 rdp_send_input(ev_time, RDP_INPUT_SCANCODE,  
                                KBD_FLAG_DOWN | KBD_FLAG_UP, 0x3a, 0);  
                 key_down_state |= DLockMask;  
   
         }  
   
   
         if ((ShiftMask & state)  
             && !((key_down_state & DShift1Mask)  
                  || (key_down_state & DShift2Mask)))  
         {  
                 rdp_send_input(ev_time, RDP_INPUT_SCANCODE, KBD_FLAG_DOWN,  
                                0x2a, 0);  
                 key_down_state |= DShift1Mask;  
   
         }  
   
         if ((ControlMask & state)  
             && !((key_down_state & DControl1Mask)  
                  || (key_down_state & DControl2Mask)))  
         {  
                 rdp_send_input(ev_time, RDP_INPUT_SCANCODE, KBD_FLAG_DOWN,  
                                0x1d, 0);  
                 key_down_state |= DControl1Mask;  
   
         }  
   
         if ((Mod1Mask & state) && !(key_down_state & DMod1Mask))  
         {  
                 rdp_send_input(ev_time, RDP_INPUT_SCANCODE, KBD_FLAG_DOWN,  
                                0x38, 0);  
                 key_down_state |= DMod1Mask;  
   
         }  
578    
579          if ((Mod2Mask & state) && !(key_down_state & DMod2Mask))                          case MappingNotify:
580          {                                  /* Refresh keyboard mapping if it has changed. This is important for
581                  rdp_send_input(ev_time, RDP_INPUT_SCANCODE, KBD_FLAG_DOWN,                                     Xvnc, since it allocates keycodes dynamically */
582                                 0xb8, 0);                                  if (xevent.xmapping.request == MappingKeyboard
583                  key_down_state |= DMod2Mask;                                      || xevent.xmapping.request == MappingModifier)
584                                            XRefreshKeyboardMapping(&xevent.xmapping);
585                                    break;
586    
587                    }
588          }          }
589  }  }
590    
# Line 724  ui_select(int rdp_socket) Line 598  ui_select(int rdp_socket)
598    
599          while (True)          while (True)
600          {          {
601                    /* Process any events already waiting */
602                    xwin_process_events();
603    
604                  FD_ZERO(&rfds);                  FD_ZERO(&rfds);
605                  FD_SET(rdp_socket, &rfds);                  FD_SET(rdp_socket, &rfds);
606                  if (display != NULL)                  FD_SET(x_socket, &rfds);
                 {  
                         FD_SET(x_socket, &rfds);  
                         XFlush(display);  
                 }  
607    
608                  switch (select(n, &rfds, NULL, NULL, NULL))                  switch (select(n, &rfds, NULL, NULL, NULL))
609                  {                  {
# Line 741  ui_select(int rdp_socket) Line 614  ui_select(int rdp_socket)
614                                  continue;                                  continue;
615                  }                  }
616    
                 if (FD_ISSET(x_socket, &rfds))  
                         xwin_process_events();  
   
617                  if (FD_ISSET(rdp_socket, &rfds))                  if (FD_ISSET(rdp_socket, &rfds))
618                          return;                          return;
619          }          }
# Line 762  ui_create_bitmap(int width, int height, Line 632  ui_create_bitmap(int width, int height,
632          Pixmap bitmap;          Pixmap bitmap;
633          uint8 *tdata;          uint8 *tdata;
634    
635          tdata = (owncolmap ? data : translate_image(width, height, data));          tdata = translate_image(width, height, data);
636          bitmap = XCreatePixmap(display, wnd, width, height, depth);          bitmap = XCreatePixmap(display, wnd, width, height, depth);
637          image = XCreateImage(display, visual, depth, ZPixmap,          image = XCreateImage(display, visual, depth, ZPixmap, 0,
638                               0, tdata, width, height, 8, 0);                               (char *) tdata, width, height, 8, 0);
639    
640          XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height);          XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height);
641    
642          XFree(image);          XFree(image);
643          if (!owncolmap)          xfree(tdata);
                 xfree(tdata);  
644          return (HBITMAP) bitmap;          return (HBITMAP) bitmap;
645  }  }
646    
647  void  void
648  ui_paint_bitmap(int x, int y, int cx, int cy,  ui_paint_bitmap(int x, int y, int cx, int cy, int width, int height, uint8 * data)
                 int width, int height, uint8 * data)  
649  {  {
650          XImage *image;          XImage *image;
651          uint8 *tdata;          uint8 *tdata;
652    
653          tdata = (owncolmap ? data : translate_image(width, height, data));          tdata = translate_image(width, height, data);
654          image = XCreateImage(display, visual, depth, ZPixmap,          image = XCreateImage(display, visual, depth, ZPixmap, 0,
655                               0, tdata, width, height, 8, 0);                               (char *) tdata, width, height, 8, 0);
656    
657          if (ownbackstore)          if (ownbackstore)
658          {          {
# Line 797  ui_paint_bitmap(int x, int y, int cx, in Line 665  ui_paint_bitmap(int x, int y, int cx, in
665          }          }
666    
667          XFree(image);          XFree(image);
668          if (!owncolmap)          xfree(tdata);
                 xfree(tdata);  
669  }  }
670    
671  void  void
# Line 820  ui_create_glyph(int width, int height, u Line 687  ui_create_glyph(int width, int height, u
687          bitmap = XCreatePixmap(display, wnd, width, height, 1);          bitmap = XCreatePixmap(display, wnd, width, height, 1);
688          gc = XCreateGC(display, bitmap, 0, NULL);          gc = XCreateGC(display, bitmap, 0, NULL);
689    
690          image = XCreateImage(display, visual, 1, ZPixmap, 0,          image = XCreateImage(display, visual, 1, ZPixmap, 0, (char *) data,
691                               data, width, height, 8, scanline);                               width, height, 8, scanline);
692          image->byte_order = MSBFirst;          image->byte_order = MSBFirst;
693          image->bitmap_bit_order = MSBFirst;          image->bitmap_bit_order = MSBFirst;
694          XInitImage(image);          XInitImage(image);
# Line 840  ui_destroy_glyph(HGLYPH glyph) Line 707  ui_destroy_glyph(HGLYPH glyph)
707  }  }
708    
709  HCURSOR  HCURSOR
710  ui_create_cursor(unsigned int x, unsigned int y, int width,  ui_create_cursor(unsigned int x, unsigned int y, int width, int height,
711                   int height, uint8 * andmask, uint8 * xormask)                   uint8 * andmask, uint8 * xormask)
712  {  {
713          HGLYPH maskglyph, cursorglyph;          HGLYPH maskglyph, cursorglyph;
714          XColor bg, fg;          XColor bg, fg;
# Line 899  ui_create_cursor(unsigned int x, unsigne Line 766  ui_create_cursor(unsigned int x, unsigne
766          cursorglyph = ui_create_glyph(width, height, cursor);          cursorglyph = ui_create_glyph(width, height, cursor);
767          maskglyph = ui_create_glyph(width, height, mask);          maskglyph = ui_create_glyph(width, height, mask);
768    
769          xcursor = XCreatePixmapCursor(display, (Pixmap) cursorglyph,          xcursor =
770                                        (Pixmap) maskglyph, &fg, &bg, x, y);                  XCreatePixmapCursor(display, (Pixmap) cursorglyph,
771                                        (Pixmap) maskglyph, &fg, &bg, x, y);
772    
773          ui_destroy_glyph(maskglyph);          ui_destroy_glyph(maskglyph);
774          ui_destroy_glyph(cursorglyph);          ui_destroy_glyph(cursorglyph);
# Line 932  ui_create_colourmap(COLOURMAP * colours) Line 800  ui_create_colourmap(COLOURMAP * colours)
800  {  {
801          COLOURENTRY *entry;          COLOURENTRY *entry;
802          int i, ncolours = colours->ncolours;          int i, ncolours = colours->ncolours;
803            uint32 *map = xmalloc(sizeof(*colmap) * ncolours);
804          if (owncolmap)          XColor xentry;
805            XColor xc_cache[256];
806            uint32 colour;
807            int colLookup = 256;
808            for (i = 0; i < ncolours; i++)
809          {          {
810                  XColor *xcolours, *xentry;                  entry = &colours->colours[i];
811                  Colormap map;                  MAKE_XCOLOR(&xentry, entry);
812    
813                  xcolours = xmalloc(sizeof(XColor) * ncolours);                  if (XAllocColor(display, xcolmap, &xentry) == 0)
                 for (i = 0; i < ncolours; i++)  
814                  {                  {
815                          entry = &colours->colours[i];                          /* Allocation failed, find closest match. */
816                          xentry = &xcolours[i];                          int j = 256;
817                          xentry->pixel = i;                          int nMinDist = 3 * 256 * 256;
818                          MAKE_XCOLOR(xentry, entry);                          long nDist = nMinDist;
819                  }  
820                            /* only get the colors once */
821                  map = XCreateColormap(display, wnd, visual, AllocAll);                          while( colLookup-- ){
822                  XStoreColors(display, map, xcolours, ncolours);                                  xc_cache[colLookup].pixel = colLookup;
823                                    xc_cache[colLookup].red = xc_cache[colLookup].green = xc_cache[colLookup].blue = 0;
824                  xfree(xcolours);                                  xc_cache[colLookup].flags = 0;
825                  return (HCOLOURMAP) map;                                  XQueryColor(display, DefaultColormap(display, DefaultScreen(display)), &xc_cache[colLookup]);
826          }                          }
827          else                          colLookup = 0;
         {  
                 uint32 *map = xmalloc(sizeof(*colmap) * ncolours);  
                 XColor xentry;  
                 uint32 colour;  
828    
829                  for (i = 0; i < ncolours; i++)                          /* approximate the pixel */
830                  {                          while( j-- ){
831                          entry = &colours->colours[i];                                  if( xc_cache[j].flags ){
832                          MAKE_XCOLOR(&xentry, entry);                                          nDist =
833                                            ((long) (xc_cache[j].red >> 8) - (long) (xentry.red >> 8)) *
834                                            ((long) (xc_cache[j].red >> 8) - (long) (xentry.red >> 8)) +
835                                            ((long) (xc_cache[j].green >> 8) - (long) (xentry.green >> 8)) *
836                                            ((long) (xc_cache[j].green >> 8) - (long) (xentry.green >> 8)) +
837                                            ((long) (xc_cache[j].blue >> 8) - (long) (xentry.blue >> 8)) *
838                                            ((long) (xc_cache[j].blue >> 8) - (long) (xentry.blue >> 8));
839                                    }
840                                    if( nDist < nMinDist ){
841                                            nMinDist = nDist;
842                                            xentry.pixel = j;
843                                    }
844                            }
845                    }
846                    colour = xentry.pixel;
847    
848                          if (XAllocColor(display, xcolmap, &xentry) != 0)                  /* update our cache */
849                                  colour = xentry.pixel;                  if( xentry.pixel < 256 ){
850                          else                          xc_cache[xentry.pixel].red = xentry.red;
851                                  colour = white;                          xc_cache[xentry.pixel].green = xentry.green;
852                            xc_cache[xentry.pixel].blue = xentry.blue;
853    
                         /* byte swap here to make translate_image faster */  
                         map[i] = translate_colour(colour);  
854                  }                  }
855    
856                  return map;  
857                    /* byte swap here to make translate_image faster */
858                    map[i] = translate_colour(colour);
859          }          }
860    
861            return map;
862  }  }
863    
864  void  void
865  ui_destroy_colourmap(HCOLOURMAP map)  ui_destroy_colourmap(HCOLOURMAP map)
866  {  {
867          if (owncolmap)          xfree(map);
                 XFreeColormap(display, (Colormap) map);  
         else  
                 xfree(map);  
868  }  }
869    
870  void  void
871  ui_set_colourmap(HCOLOURMAP map)  ui_set_colourmap(HCOLOURMAP map)
872  {  {
873          if (owncolmap)          colmap = map;
                 XSetWindowColormap(display, wnd, (Colormap) map);  
         else  
                 colmap = map;  
874  }  }
875    
876  void  void
# Line 1060  ui_patblt(uint8 opcode, Line 938  ui_patblt(uint8 opcode,
938                          SET_BACKGROUND(fgcolour);                          SET_BACKGROUND(fgcolour);
939                          XSetFillStyle(display, gc, FillOpaqueStippled);                          XSetFillStyle(display, gc, FillOpaqueStippled);
940                          XSetStipple(display, gc, fill);                          XSetStipple(display, gc, fill);
941                          XSetTSOrigin(display, gc, brush->xorigin,                          XSetTSOrigin(display, gc, brush->xorigin, brush->yorigin);
                                      brush->yorigin);  
942    
943                          FILL_RECTANGLE(x, y, cx, cy);                          FILL_RECTANGLE(x, y, cx, cy);
944    
945                          XSetFillStyle(display, gc, FillSolid);                          XSetFillStyle(display, gc, FillSolid);
946                            XSetTSOrigin(display, gc, 0, 0);
947                          ui_destroy_glyph((HGLYPH) fill);                          ui_destroy_glyph((HGLYPH) fill);
948                          break;                          break;
949    
# Line 1084  ui_screenblt(uint8 opcode, Line 962  ui_screenblt(uint8 opcode,
962          SET_FUNCTION(opcode);          SET_FUNCTION(opcode);
963          XCopyArea(display, wnd, wnd, gc, srcx, srcy, cx, cy, x, y);          XCopyArea(display, wnd, wnd, gc, srcx, srcy, cx, cy, x, y);
964          if (ownbackstore)          if (ownbackstore)
965                  XCopyArea(display, backstore, backstore, gc, srcx, srcy,                  XCopyArea(display, backstore, backstore, gc, srcx, srcy, cx, cy, x, y);
                           cx, cy, x, y);  
966          RESET_FUNCTION(opcode);          RESET_FUNCTION(opcode);
967  }  }
968    
# Line 1097  ui_memblt(uint8 opcode, Line 974  ui_memblt(uint8 opcode,
974          SET_FUNCTION(opcode);          SET_FUNCTION(opcode);
975          XCopyArea(display, (Pixmap) src, wnd, gc, srcx, srcy, cx, cy, x, y);          XCopyArea(display, (Pixmap) src, wnd, gc, srcx, srcy, cx, cy, x, y);
976          if (ownbackstore)          if (ownbackstore)
977                  XCopyArea(display, (Pixmap) src, backstore, gc, srcx, srcy,                  XCopyArea(display, (Pixmap) src, backstore, gc, srcx, srcy, cx, cy, x, y);
                           cx, cy, x, y);  
978          RESET_FUNCTION(opcode);          RESET_FUNCTION(opcode);
979  }  }
980    
# Line 1115  ui_triblt(uint8 opcode, Line 991  ui_triblt(uint8 opcode,
991          {          {
992                  case 0x69:      /* PDSxxn */                  case 0x69:      /* PDSxxn */
993                          ui_memblt(ROP2_XOR, x, y, cx, cy, src, srcx, srcy);                          ui_memblt(ROP2_XOR, x, y, cx, cy, src, srcx, srcy);
994                          ui_patblt(ROP2_NXOR, x, y, cx, cy,                          ui_patblt(ROP2_NXOR, x, y, cx, cy, brush, bgcolour, fgcolour);
                                   brush, bgcolour, fgcolour);  
995                          break;                          break;
996    
997                  case 0xb8:      /* PSDPxax */                  case 0xb8:      /* PSDPxax */
998                          ui_patblt(ROP2_XOR, x, y, cx, cy,                          ui_patblt(ROP2_XOR, x, y, cx, cy, brush, bgcolour, fgcolour);
                                   brush, bgcolour, fgcolour);  
999                          ui_memblt(ROP2_AND, x, y, cx, cy, src, srcx, srcy);                          ui_memblt(ROP2_AND, x, y, cx, cy, src, srcx, srcy);
1000                          ui_patblt(ROP2_XOR, x, y, cx, cy,                          ui_patblt(ROP2_XOR, x, y, cx, cy, brush, bgcolour, fgcolour);
                                   brush, bgcolour, fgcolour);  
1001                          break;                          break;
1002    
1003                  case 0xc0:      /* PSa */                  case 0xc0:      /* PSa */
1004                          ui_memblt(ROP2_COPY, x, y, cx, cy, src, srcx, srcy);                          ui_memblt(ROP2_COPY, x, y, cx, cy, src, srcx, srcy);
1005                          ui_patblt(ROP2_AND, x, y, cx, cy, brush, bgcolour,                          ui_patblt(ROP2_AND, x, y, cx, cy, brush, bgcolour, fgcolour);
                                   fgcolour);  
1006                          break;                          break;
1007    
1008                  default:                  default:
# Line 1164  ui_rect( Line 1036  ui_rect(
1036  void  void
1037  ui_draw_glyph(int mixmode,  ui_draw_glyph(int mixmode,
1038                /* dest */ int x, int y, int cx, int cy,                /* dest */ int x, int y, int cx, int cy,
1039                /* src */ HGLYPH glyph, int srcx, int srcy, int bgcolour,                /* src */ HGLYPH glyph, int srcx, int srcy,
1040                int fgcolour)                int bgcolour, int fgcolour)
1041  {  {
1042          SET_FOREGROUND(fgcolour);          SET_FOREGROUND(fgcolour);
1043          SET_BACKGROUND(bgcolour);          SET_BACKGROUND(bgcolour);
1044    
1045          XSetFillStyle(display, gc, (mixmode == MIX_TRANSPARENT)          XSetFillStyle(display, gc,
1046                        ? FillStippled : FillOpaqueStippled);                        (mixmode == MIX_TRANSPARENT) ? FillStippled : FillOpaqueStippled);
1047          XSetStipple(display, gc, (Pixmap) glyph);          XSetStipple(display, gc, (Pixmap) glyph);
1048          XSetTSOrigin(display, gc, x, y);          XSetTSOrigin(display, gc, x, y);
1049    
# Line 1189  ui_draw_glyph(int mixmode, Line 1061  ui_draw_glyph(int mixmode,
1061        if ((xyoffset & 0x80))\        if ((xyoffset & 0x80))\
1062          {\          {\
1063            if (flags & TEXT2_VERTICAL) \            if (flags & TEXT2_VERTICAL) \
1064              y += ttext[++idx] | (ttext[++idx] << 8);\              y += ttext[idx+1] | (ttext[idx+2] << 8);\
1065            else\            else\
1066              x += ttext[++idx] | (ttext[++idx] << 8);\              x += ttext[idx+1] | (ttext[idx+2] << 8);\
1067              idx += 2;\
1068          }\          }\
1069        else\        else\
1070          {\          {\
# Line 1214  ui_draw_glyph(int mixmode, Line 1087  ui_draw_glyph(int mixmode,
1087    
1088  void  void
1089  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,
1090               int clipx, int clipy, int clipcx, int clipcy, int boxx,               int clipx, int clipy, int clipcx, int clipcy,
1091               int boxy, int boxcx, int boxcy, int bgcolour,               int boxx, int boxy, int boxcx, int boxcy, int bgcolour,
1092               int fgcolour, uint8 * text, uint8 length)               int fgcolour, uint8 * text, uint8 length)
1093  {  {
1094          FONTGLYPH *glyph;          FONTGLYPH *glyph;
# Line 1240  ui_draw_text(uint8 font, uint8 flags, in Line 1113  ui_draw_text(uint8 font, uint8 flags, in
1113                  {                  {
1114                          case 0xff:                          case 0xff:
1115                                  if (i + 2 < length)                                  if (i + 2 < length)
1116                                          cache_put_text(text[i + 1], text,                                          cache_put_text(text[i + 1], text, text[i + 2]);
                                                        text[i + 2]);  
1117                                  else                                  else
1118                                  {                                  {
1119                                          error("this shouldn't be happening\n");                                          error("this shouldn't be happening\n");
# Line 1258  ui_draw_text(uint8 font, uint8 flags, in Line 1130  ui_draw_text(uint8 font, uint8 flags, in
1130                                  if (entry != NULL)                                  if (entry != NULL)
1131                                  {                                  {
1132                                          if ((((uint8 *) (entry->data))[1] ==                                          if ((((uint8 *) (entry->data))[1] ==
1133                                               0)                                               0) && (!(flags & TEXT2_IMPLICIT_X)))
                                             && (!(flags & TEXT2_IMPLICIT_X)))  
1134                                          {                                          {
1135                                                  if (flags & TEXT2_VERTICAL)                                                  if (flags & TEXT2_VERTICAL)
1136                                                          y += text[i + 2];                                                          y += text[i + 2];
# Line 1275  ui_draw_text(uint8 font, uint8 flags, in Line 1146  ui_draw_text(uint8 font, uint8 flags, in
1146                                          text = &(text[i]);                                          text = &(text[i]);
1147                                          i = 0;                                          i = 0;
1148                                          for (j = 0; j < entry->size; j++)                                          for (j = 0; j < entry->size; j++)
1149                                                  DO_GLYPH(((uint8 *) (entry->                                                  DO_GLYPH(((uint8 *) (entry->data)), j);
                                                                      data)),  
                                                          j);  
1150                                  }                                  }
1151                                  break;                                  break;
1152    
# Line 1299  ui_desktop_save(uint32 offset, int x, in Line 1168  ui_desktop_save(uint32 offset, int x, in
1168    
1169          if (ownbackstore)          if (ownbackstore)
1170          {          {
1171                  image = XGetImage(display, backstore, x, y, cx, cy, AllPlanes,                  image = XGetImage(display, backstore, x, y, cx, cy, AllPlanes, ZPixmap);
                                   ZPixmap);  
1172          }          }
1173          else          else
1174          {          {
1175                  pix = XCreatePixmap(display, wnd, cx, cy, depth);                  pix = XCreatePixmap(display, wnd, cx, cy, depth);
1176                  XCopyArea(display, wnd, pix, gc, x, y, cx, cy, 0, 0);                  XCopyArea(display, wnd, pix, gc, x, y, cx, cy, 0, 0);
1177                  image = XGetImage(display, pix, 0, 0, cx, cy, AllPlanes,                  image = XGetImage(display, pix, 0, 0, cx, cy, AllPlanes, ZPixmap);
                                   ZPixmap);  
1178                  XFreePixmap(display, pix);                  XFreePixmap(display, pix);
1179          }          }
1180    
1181          offset *= bpp / 8;          offset *= bpp / 8;
1182          cache_put_desktop(offset, cx, cy, image->bytes_per_line,          cache_put_desktop(offset, cx, cy, image->bytes_per_line, bpp / 8, (uint8 *) image->data);
                           bpp / 8, (uint8 *) image->data);  
1183    
1184          XDestroyImage(image);          XDestroyImage(image);
1185  }  }
# Line 1329  ui_desktop_restore(uint32 offset, int x, Line 1195  ui_desktop_restore(uint32 offset, int x,
1195          if (data == NULL)          if (data == NULL)
1196                  return;                  return;
1197    
1198          image = XCreateImage(display, visual, depth, ZPixmap,          image = XCreateImage(display, visual, depth, ZPixmap, 0,
1199                               0, data, cx, cy, BitmapPad(display),                               (char *) data, cx, cy, BitmapPad(display), cx * bpp / 8);
                              cx * bpp / 8);  
1200    
1201          if (ownbackstore)          if (ownbackstore)
1202          {          {

Legend:
Removed from v.64  
changed lines
  Added in v.185

  ViewVC Help
Powered by ViewVC 1.1.26