/[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 28 by matty, Wed Jun 20 13:54:48 2001 UTC revision 164 by astrand, Mon Sep 16 13:19:54 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-2000     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 21  Line 21 
21  #include <X11/Xlib.h>  #include <X11/Xlib.h>
22  #include <X11/Xutil.h>  #include <X11/Xutil.h>
23  #include <time.h>  #include <time.h>
24    #include <errno.h>
25    #define XK_MISCELLANY
26    #include <X11/keysymdef.h>
27  #include "rdesktop.h"  #include "rdesktop.h"
28    #include "scancodes.h"
29    
30  extern int width;  extern int width;
31  extern int height;  extern int height;
32  extern BOOL motion;  extern BOOL sendmotion;
 extern BOOL grab_keyboard;  
33  extern BOOL fullscreen;  extern BOOL fullscreen;
34  extern int private_colormap;  extern BOOL grab_keyboard;
35    extern char title[];
36    
37  static int bpp;  Display *display;
38  static int depth;  static int x_socket;
39  static Display *display;  static Screen *screen;
40  static Window wnd;  static Window wnd;
41  static GC gc;  static GC gc;
42  static Visual *visual;  static Visual *visual;
43  static uint32 *colmap;  static int depth;
44    static int bpp;
 #define Ctrans(col) ( private_colormap ? col : colmap[col])  
45    
46  #define L_ENDIAN  /* endianness */
47  int screen_msbfirst = 0;  static BOOL host_be;
48    static BOOL xserver_be;
49    
50    /* software backing store */
51    static BOOL ownbackstore;
52    static Pixmap backstore;
53    
54    #define FILL_RECTANGLE(x,y,cx,cy)\
55    { \
56            XFillRectangle(display, wnd, gc, x, y, cx, cy); \
57            if (ownbackstore) \
58                    XFillRectangle(display, backstore, gc, x, y, cx, cy); \
59    }
60    
61    /* colour maps */
62    static BOOL owncolmap;
63    static Colormap xcolmap;
64    static uint32 *colmap;
65    
66  static uint8 *translate(int width, int height, uint8 *data);  /* Compose support */
67    BOOL enable_compose = False;
68    static XIM IM = NULL;
69    static XIC IC = NULL;
70    
71    /* toggle fullscreen globals */
72    static unsigned long input_mask;
73    
74    #define TRANSLATE(col)          ( owncolmap ? col : translate_colour(colmap[col]) )
75    #define SET_FOREGROUND(col)     XSetForeground(display, gc, TRANSLATE(col));
76    #define SET_BACKGROUND(col)     XSetBackground(display, gc, TRANSLATE(col));
77    
78  static int rop2_map[] = {  static int rop2_map[] = {
79          GXclear,                /* 0 */          GXclear,                /* 0 */
# Line 64  static int rop2_map[] = { Line 94  static int rop2_map[] = {
94          GXset                   /* 1 */          GXset                   /* 1 */
95  };  };
96    
97    #define SET_FUNCTION(rop2)      { if (rop2 != ROP2_COPY) XSetFunction(display, gc, rop2_map[rop2]); }
98    #define RESET_FUNCTION(rop2)    { if (rop2 != ROP2_COPY) XSetFunction(display, gc, GXcopy); }
99    
100  static void  static void
101  xwin_set_function(uint8 rop2)  translate8(uint8 * data, uint8 * out, uint8 * end)
102  {  {
103          static uint8 last_rop2 = ROP2_COPY;          while (out < end)
104                    *(out++) = (uint8) colmap[*(data++)];
105    }
106    
107          if (last_rop2 != rop2)  static void
108    translate16(uint8 * data, uint16 * out, uint16 * end)
109    {
110            while (out < end)
111                    *(out++) = (uint16) colmap[*(data++)];
112    }
113    
114    /* little endian - conversion happens when colourmap is built */
115    static void
116    translate24(uint8 * data, uint8 * out, uint8 * end)
117    {
118            uint32 value;
119    
120            while (out < end)
121          {          {
122                  XSetFunction(display, gc, rop2_map[rop2]);                  value = colmap[*(data++)];
123                  last_rop2 = rop2;                  *(out++) = value;
124                    *(out++) = value >> 8;
125                    *(out++) = value >> 16;
126          }          }
127  }  }
128    
129  static void  static void
130  xwin_grab_keyboard()  translate32(uint8 * data, uint32 * out, uint32 * end)
131    {
132            while (out < end)
133                    *(out++) = colmap[*(data++)];
134    }
135    
136    static uint8 *
137    translate_image(int width, int height, uint8 * data)
138    {
139            int size = width * height * bpp / 8;
140            uint8 *out = xmalloc(size);
141            uint8 *end = out + size;
142    
143            switch (bpp)
144            {
145                    case 8:
146                            translate8(data, out, end);
147                            break;
148    
149                    case 16:
150                            translate16(data, (uint16 *) out, (uint16 *) end);
151                            break;
152    
153                    case 24:
154                            translate24(data, out, end);
155                            break;
156    
157                    case 32:
158                            translate32(data, (uint32 *) out, (uint32 *) end);
159                            break;
160            }
161    
162            return out;
163    }
164    
165    #define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); }
166    #define BSWAP24(x) { x = (((x & 0xff) << 16) | (x >> 16) | ((x >> 8) & 0xff00)); }
167    #define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \
168                            x = (x << 16) | (x >> 16); }
169    
170    static uint32
171    translate_colour(uint32 colour)
172  {  {
173          XGrabKeyboard(display, wnd, True, GrabModeAsync, GrabModeAsync,          switch (bpp)
174                        CurrentTime);          {
175                    case 16:
176                            if (host_be != xserver_be)
177                                    BSWAP16(colour);
178                            break;
179    
180                    case 24:
181                            if (xserver_be)
182                                    BSWAP24(colour);
183                            break;
184    
185                    case 32:
186                            if (host_be != xserver_be)
187                                    BSWAP32(colour);
188                            break;
189            }
190    
191            return colour;
192    }
193    
194    static unsigned long
195    init_inputmethod(void)
196    {
197            unsigned long filtered_events = 0;
198    
199            IM = XOpenIM(display, NULL, NULL, NULL);
200            if (IM == NULL)
201            {
202                    error("Failed to open input method\n");
203            }
204    
205            if (IM != NULL)
206            {
207                    /* Must be done after XCreateWindow */
208                    IC = XCreateIC(IM, XNInputStyle,
209                                   (XIMPreeditNothing | XIMStatusNothing),
210                                   XNClientWindow, wnd, XNFocusWindow, wnd, NULL);
211    
212                    if (IC == NULL)
213                    {
214                            error("Failed to create input context\n");
215                            XCloseIM(IM);
216                            IM = NULL;
217                    }
218            }
219    
220            /* For correct Multi_key/Compose processing, I guess.
221               It seems to work alright anyway, though. */
222            if (IC != NULL)
223            {
224                    if (XGetICValues(IC, XNFilterEvents, &filtered_events, NULL) != NULL)
225                    {
226                            error("Failed to obtain XNFilterEvents value from IC\n");
227                            filtered_events = 0;
228                    }
229            }
230            return filtered_events;
231  }  }
232    
233  static void  static void
234  xwin_ungrab_keyboard()  close_inputmethod(void)
235  {  {
236          XUngrabKeyboard(display, CurrentTime);          if (IC != NULL)
237            {
238                    XDestroyIC(IC);
239                    if (IM != NULL)
240                    {
241                            XCloseIM(IM);
242                            IM = NULL;
243                    }
244            }
245  }  }
246    
247  BOOL  BOOL
248  ui_create_window(char *title)  get_key_state(int keysym)
249    {
250            int keysymMask = 0, modifierpos, key;
251            Window wDummy1, wDummy2;
252            int iDummy3, iDummy4, iDummy5, iDummy6;
253            unsigned int current_state;
254            int offset;
255    
256            XModifierKeymap *map = XGetModifierMapping(display);
257            KeyCode keycode = XKeysymToKeycode(display, keysym);
258    
259            if (keycode == NoSymbol)
260                    return False;
261    
262            for (modifierpos = 0; modifierpos < 8; modifierpos++)
263            {
264                    offset = map->max_keypermod * modifierpos;
265    
266                    for (key = 0; key < map->max_keypermod; key++)
267                    {
268                            if (map->modifiermap[offset + key] == keycode)
269                                    keysymMask = 1 << modifierpos;
270                    }
271            }
272    
273            XQueryPointer(display, DefaultRootWindow(display), &wDummy1,
274                          &wDummy2, &iDummy3, &iDummy4, &iDummy5, &iDummy6, &current_state);
275    
276            XFreeModifiermap(map);
277    
278            return (current_state & keysymMask) ? True : False;
279    }
280    
281    static void
282    xwin_map_window()
283    {
284            XEvent xevent;
285    
286            XMapWindow(display, wnd);
287    
288            /* wait for VisibilityChange */
289            XMaskEvent(display, VisibilityChangeMask, &xevent);
290    
291            if (fullscreen)
292                    XSetInputFocus(display, wnd, RevertToPointerRoot, CurrentTime);
293    }
294    
295    BOOL
296    ui_init()
297  {  {
         XSetWindowAttributes attribs;  
         XClassHint *classhints;  
         XSizeHints *sizehints;  
         unsigned long input_mask;  
298          XPixmapFormatValues *pfm;          XPixmapFormatValues *pfm;
299          int count;          uint16 test;
300            int i;
301    
302          display = XOpenDisplay(NULL);          display = XOpenDisplay(NULL);
303          if (display == NULL)          if (display == NULL)
304          {          {
305                  ERROR("Failed to open display\n");                  error("Failed to open display\n");
306                  return False;                  return False;
307          }          }
308    
309          visual = DefaultVisual(display, DefaultScreen(display));          x_socket = ConnectionNumber(display);
310          depth = DefaultDepth(display, DefaultScreen(display));          screen = DefaultScreenOfDisplay(display);
311          pfm = XListPixmapFormats(display, &count);          visual = DefaultVisualOfScreen(screen);
312            depth = DefaultDepthOfScreen(screen);
313    
314            pfm = XListPixmapFormats(display, &i);
315          if (pfm != NULL)          if (pfm != NULL)
316          {          {
317                  while (count--)                  /* Use maximum bpp for this depth - this is generally
318                       desirable, e.g. 24 bits->32 bits. */
319                    while (i--)
320                  {                  {
321                          if ((pfm + count)->depth == depth                          if ((pfm[i].depth == depth) && (pfm[i].bits_per_pixel > bpp))
                             && (pfm + count)->bits_per_pixel > bpp)  
322                          {                          {
323                                  bpp = (pfm + count)->bits_per_pixel;                                  bpp = pfm[i].bits_per_pixel;
324                          }                          }
325                  }                  }
326                  XFree(pfm);                  XFree(pfm);
# Line 124  ui_create_window(char *title) Line 328  ui_create_window(char *title)
328    
329          if (bpp < 8)          if (bpp < 8)
330          {          {
331                  ERROR("Less than 8 bpp not currently supported.\n");                  error("Less than 8 bpp not currently supported.\n");
332                  XCloseDisplay(display);                  XCloseDisplay(display);
333                  return False;                  return False;
334          }          }
335    
336          width &= ~3; /* make width nicely divisible */          if (depth <= 8)
337                    owncolmap = True;
338            else
339                    xcolmap = DefaultColormapOfScreen(screen);
340    
341            if (DoesBackingStore(screen) == NotUseful)
342                    ownbackstore = True;
343    
344          attribs.background_pixel = BlackPixel(display, DefaultScreen(display));          test = 1;
345          attribs.backing_store = Always;          host_be = !(BOOL) (*(uint8 *) (&test));
346            xserver_be = (ImageByteOrder(display) == MSBFirst);
347    
348          if (fullscreen)          if (fullscreen)
349          {          {
350                  attribs.override_redirect = True;                  width = WidthOfScreen(screen);
351                  width = WidthOfScreen(DefaultScreenOfDisplay(display));                  height = HeightOfScreen(screen);
                 height = HeightOfScreen(DefaultScreenOfDisplay(display));  
                 XSetInputFocus(display, PointerRoot, RevertToPointerRoot,  
                                CurrentTime);  
         }  
         else  
         {  
                 attribs.override_redirect = False;  
352          }          }
353    
354          wnd = XCreateWindow(display, DefaultRootWindow(display),          /* make sure width is a multiple of 4 */
355                              0, 0, width, height, 0, CopyFromParent,          width = (width + 3) & ~3;
356                              InputOutput, CopyFromParent,  
357                              CWBackingStore | CWBackPixel | CWOverrideRedirect,          xkeymap_init();
358                              &attribs);          return True;
359    }
360    
361    BOOL
362    ui_create_window()
363    {
364            XSetWindowAttributes attribs;
365            XClassHint *classhints;
366            XSizeHints *sizehints;
367            XEvent xevent;
368    
369            attribs.background_pixel = BlackPixelOfScreen(screen);
370            attribs.backing_store = ownbackstore ? NotUseful : Always;
371            attribs.override_redirect = fullscreen;
372            wnd = XCreateWindow(display, RootWindowOfScreen(screen), 0, 0, width, height,
373                                0, CopyFromParent, InputOutput, CopyFromParent,
374                                CWBackPixel | CWBackingStore | CWOverrideRedirect, &attribs);
375    
376            if (ownbackstore)
377                    backstore = XCreatePixmap(display, wnd, width, height, depth);
378    
379          XStoreName(display, wnd, title);          XStoreName(display, wnd, title);
380    
381          classhints = XAllocClassHint();          classhints = XAllocClassHint();
382          if (classhints != NULL)          if (classhints != NULL)
   
383          {          {
384                  classhints->res_name = "rdesktop";                  classhints->res_name = classhints->res_class = "rdesktop";
                 classhints->res_class = "rdesktop";  
385                  XSetClassHint(display, wnd, classhints);                  XSetClassHint(display, wnd, classhints);
386                  XFree(classhints);                  XFree(classhints);
387          }          }
# Line 168  ui_create_window(char *title) Line 389  ui_create_window(char *title)
389          sizehints = XAllocSizeHints();          sizehints = XAllocSizeHints();
390          if (sizehints)          if (sizehints)
391          {          {
392                  sizehints->flags =                  sizehints->flags = PMinSize | PMaxSize;
393                          PPosition | PSize | PMinSize | PMaxSize | PBaseSize;                  sizehints->min_width = sizehints->max_width = width;
394                  sizehints->min_width = width;                  sizehints->min_height = sizehints->max_height = height;
                 sizehints->max_width = width;  
                 sizehints->min_height = height;  
                 sizehints->max_height = height;  
                 sizehints->base_width = width;  
                 sizehints->base_height = height;  
395                  XSetWMNormalHints(display, wnd, sizehints);                  XSetWMNormalHints(display, wnd, sizehints);
396                  XFree(sizehints);                  XFree(sizehints);
397          }          }
398    
399          input_mask = KeyPressMask | KeyReleaseMask;          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
400          input_mask |= ButtonPressMask | ButtonReleaseMask;                  VisibilityChangeMask | FocusChangeMask;
401          if (motion)  
                 input_mask |= PointerMotionMask;  
402          if (grab_keyboard)          if (grab_keyboard)
403                  input_mask |= EnterWindowMask | LeaveWindowMask;                  input_mask |= EnterWindowMask | LeaveWindowMask;
404            if (sendmotion)
405                    input_mask |= PointerMotionMask;
406            if (ownbackstore)
407                    input_mask |= ExposureMask;
408            if (enable_compose)
409                    input_mask |= init_inputmethod();
410    
411          XSelectInput(display, wnd, input_mask);          XSelectInput(display, wnd, input_mask);
412    
413            xwin_map_window();
414    
415            /* clear the window so that cached data is not seen */
416          gc = XCreateGC(display, wnd, 0, NULL);          gc = XCreateGC(display, wnd, 0, NULL);
417            XSetForeground(display, gc, 0);
418            FILL_RECTANGLE(0, 0, width, height);
419    
         XMapWindow(display, wnd);  
420          return True;          return True;
421  }  }
422    
423  void  void
424  ui_destroy_window()  ui_destroy_window()
425  {  {
426            if (ownbackstore)
427                    XFreePixmap(display, backstore);
428    
429          XFreeGC(display, gc);          XFreeGC(display, gc);
430    
431            close_inputmethod();
432    
433          XDestroyWindow(display, wnd);          XDestroyWindow(display, wnd);
434          XCloseDisplay(display);          XCloseDisplay(display);
435          display = NULL;          display = NULL;
436  }  }
437    
438  static uint8  static void
439  xwin_translate_key(unsigned long key)  xwin_reset_keys()
440  {  {
441          DEBUG("KEY(code=0x%lx)\n", key);          /* reset keys */
442            uint32 ev_time;
443            ev_time = time(NULL);
444            rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LCTRL);
445            rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LALT);
446            rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LSHIFT);
447            rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RCTRL);
448            rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RALT);
449            rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RSHIFT);
450    }
451    
452          if ((key > 8) && (key <= 0x60))  void
453                  return (key - 8);  xwin_toggle_fullscreen()
454    {
455            XEvent xevent;
456            XSetWindowAttributes attribs;
457            int newwidth, newheight;
458    
459          switch (key)          fullscreen = !fullscreen;
460          {          newwidth = fullscreen ? WidthOfScreen(screen) : width;
461                  case 0x61:      /* home */          newheight = fullscreen ? HeightOfScreen(screen) : height;
                         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;  
 }  
   
 void  
 ui_process_events()  
 {  
         XEvent event;  
         uint8 scancode;  
         uint16 button;  
         uint32 ev_time;  
462    
463          if (display == NULL)          XUnmapWindow(display, wnd);
464                  return;          attribs.override_redirect = fullscreen;
465            XMoveResizeWindow(display, wnd, 0, 0, newwidth, newheight);
466            XChangeWindowAttributes(display, wnd, CWOverrideRedirect, &attribs);
467            xwin_map_window();
468    }
469    
470          while (XCheckWindowEvent(display, wnd, ~0, &event))  /* Process all events in Xlib queue */
471    static void
472    xwin_process_events()
473    {
474            XEvent xevent;
475            KeySym keysym;
476            uint16 button, flags;
477            uint32 ev_time;
478            key_translation tr;
479            char *ksname = NULL;
480            char str[256];
481            Status status;
482    
483            while (XPending(display) > 0)
484          {          {
485                    XNextEvent(display, &xevent);
486    
487                    if (enable_compose && (XFilterEvent(&xevent, None) == True))
488                    {
489                            DEBUG_KBD(("Filtering event\n"));
490                            continue;
491                    }
492    
493                  ev_time = time(NULL);                  ev_time = time(NULL);
494                    flags = 0;
495    
496                  switch (event.type)                  switch (xevent.type)
497                  {                  {
498                          case KeyPress:                          case KeyPress:
499                                  scancode = xwin_translate_key(event.xkey.keycode);                                  if (IC != NULL)
500                                  if (scancode == 0)                                          /* Multi_key compatible version */
501                                    {
502                                            XmbLookupString(IC,
503                                                            (XKeyPressedEvent *) &
504                                                            xevent, str, sizeof(str), &keysym, &status);
505                                            if (!((status == XLookupKeySym) || (status == XLookupBoth)))
506                                            {
507                                                    error("XmbLookupString failed with status 0x%x\n",
508                                                          status);
509                                                    break;
510                                            }
511                                    }
512                                    else
513                                    {
514                                            /* Plain old XLookupString */
515                                            DEBUG_KBD(("No input context, using XLookupString\n"));
516                                            XLookupString((XKeyEvent *) & xevent,
517                                                          str, sizeof(str), &keysym, NULL);
518                                    }
519    
520                                    ksname = get_ksname(keysym);
521                                    DEBUG_KBD(("\nKeyPress for (keysym 0x%lx, %s)\n", keysym, ksname));
522    
523                                    if (handle_special_keys(keysym, ev_time, True))
524                                          break;                                          break;
525    
526                                  rdp_send_input(ev_time, RDP_INPUT_SCANCODE, 0,                                  tr = xkeymap_translate_key(keysym,
527                                                 scancode, 0);                                                             xevent.xkey.keycode, xevent.xkey.state);
                                 break;  
528    
529                          case KeyRelease:                                  if (tr.scancode == 0)
                                 scancode = xwin_translate_key(event.xkey.keycode);  
                                 if (scancode == 0)  
530                                          break;                                          break;
531    
532                                  rdp_send_input(ev_time, RDP_INPUT_SCANCODE,                                  ensure_remote_modifiers(ev_time, tr);
533                                                 KBD_FLAG_DOWN | KBD_FLAG_UP,  
534                                                 scancode, 0);                                  rdp_send_scancode(ev_time, RDP_KEYPRESS, tr.scancode);
535                                  break;                                  break;
536                            case KeyRelease:
537                                    XLookupString((XKeyEvent *) & xevent, str,
538                                                  sizeof(str), &keysym, NULL);
539    
540                          case ButtonPress:                                  ksname = get_ksname(keysym);
541                                  button = xwin_translate_mouse(event.xbutton.button);                                  DEBUG_KBD(("\nKeyRelease for (keysym 0x%lx, %s)\n", keysym,
542                                  if (button == 0)                                             ksname));
543    
544                                    if (handle_special_keys(keysym, ev_time, False))
545                                          break;                                          break;
546    
547                                  rdp_send_input(ev_time, RDP_INPUT_MOUSE,                                  tr = xkeymap_translate_key(keysym,
548                                                 button | MOUSE_FLAG_DOWN,                                                             xevent.xkey.keycode, xevent.xkey.state);
549                                                 event.xbutton.x,  
550                                                 event.xbutton.y);                                  if (tr.scancode == 0)
551                                            break;
552    
553                                    rdp_send_scancode(ev_time, RDP_KEYRELEASE, tr.scancode);
554                                  break;                                  break;
555    
556                            case ButtonPress:
557                                    flags = MOUSE_FLAG_DOWN;
558                                    /* fall through */
559    
560                          case ButtonRelease:                          case ButtonRelease:
561                                  button = xwin_translate_mouse(event.xbutton.button);                                  button = xkeymap_translate_button(xevent.xbutton.button);
562                                  if (button == 0)                                  if (button == 0)
563                                          break;                                          break;
564    
565                                  rdp_send_input(ev_time, RDP_INPUT_MOUSE,                                  rdp_send_input(ev_time, RDP_INPUT_MOUSE,
566                                                 button,                                                 flags | button, xevent.xbutton.x, xevent.xbutton.y);
                                                event.xbutton.x,  
                                                event.xbutton.y);  
567                                  break;                                  break;
568    
569                          case MotionNotify:                          case MotionNotify:
570                                  rdp_send_input(ev_time, RDP_INPUT_MOUSE,                                  rdp_send_input(ev_time, RDP_INPUT_MOUSE,
571                                                 MOUSE_FLAG_MOVE,                                                 MOUSE_FLAG_MOVE, xevent.xmotion.x, xevent.xmotion.y);
                                                event.xmotion.x,  
                                                event.xmotion.y);  
572                                  break;                                  break;
573    
574                          case EnterNotify:                          case EnterNotify:
575                                  if (grab_keyboard)                                  if (grab_keyboard)
576                                          xwin_grab_keyboard();                                          XGrabKeyboard(display, wnd, True,
577                                                          GrabModeAsync, GrabModeAsync, CurrentTime);
578                                  break;                                  break;
579    
580                          case LeaveNotify:                          case LeaveNotify:
581                                  if (grab_keyboard)                                  if (grab_keyboard)
582                                          xwin_ungrab_keyboard();                                          XUngrabKeyboard(display, CurrentTime);
583                                    break;
584    
585                            case FocusOut:
586                                    xwin_reset_keys();
587                                    break;
588    
589                            case Expose:
590                                    XCopyArea(display, backstore, wnd, gc,
591                                              xevent.xexpose.x, xevent.xexpose.y,
592                                              xevent.xexpose.width,
593                                              xevent.xexpose.height,
594                                              xevent.xexpose.x, xevent.xexpose.y);
595                                  break;                                  break;
596    
597                            case MappingNotify:
598                                    /* Refresh keyboard mapping if it has changed. This is important for
599                                       Xvnc, since it allocates keycodes dynamically */
600                                    if (xevent.xmapping.request == MappingKeyboard
601                                        || xevent.xmapping.request == MappingModifier)
602                                            XRefreshKeyboardMapping(&xevent.xmapping);
603                                    break;
604    
605                  }                  }
606          }          }
607  }  }
608    
609  void  void
610    ui_select(int rdp_socket)
611    {
612            int n = (rdp_socket > x_socket) ? rdp_socket + 1 : x_socket + 1;
613            fd_set rfds;
614    
615            FD_ZERO(&rfds);
616    
617            while (True)
618            {
619                    /* Process any events already waiting */
620                    xwin_process_events();
621    
622                    FD_ZERO(&rfds);
623                    FD_SET(rdp_socket, &rfds);
624                    FD_SET(x_socket, &rfds);
625    
626                    switch (select(n, &rfds, NULL, NULL, NULL))
627                    {
628                            case -1:
629                                    error("select: %s\n", strerror(errno));
630    
631                            case 0:
632                                    continue;
633                    }
634    
635                    if (FD_ISSET(rdp_socket, &rfds))
636                            return;
637            }
638    }
639    
640    void
641  ui_move_pointer(int x, int y)  ui_move_pointer(int x, int y)
642  {  {
643          XWarpPointer(display, wnd, wnd, 0, 0, 0, 0, x, y);          XWarpPointer(display, wnd, wnd, 0, 0, 0, 0, x, y);
644  }  }
645    
646  HBITMAP  HBITMAP
647  ui_create_bitmap(int width, int height, uint8 *data)  ui_create_bitmap(int width, int height, uint8 * data)
648  {  {
649          XImage *image;          XImage *image;
650          Pixmap bitmap;          Pixmap bitmap;
651          uint8 *tdata;          uint8 *tdata;
652          tdata = (private_colormap ? data : translate(width, height, data));  
653            tdata = (owncolmap ? data : translate_image(width, height, data));
654          bitmap = XCreatePixmap(display, wnd, width, height, depth);          bitmap = XCreatePixmap(display, wnd, width, height, depth);
655          image =          image = XCreateImage(display, visual, depth, ZPixmap, 0,
656                  XCreateImage(display, visual,                               (char *) tdata, width, height, 8, 0);
                              depth, ZPixmap,  
                              0, tdata, width, height, BitmapPad(display), 0);  
657    
         xwin_set_function(ROP2_COPY);  
658          XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height);          XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height);
659    
660          XFree(image);          XFree(image);
661          if (!private_colormap)          if (!owncolmap)
662                  xfree(tdata);                  xfree(tdata);
663          return (HBITMAP) bitmap;          return (HBITMAP) bitmap;
664  }  }
665    
666  void  void
667  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)  
668  {  {
669          XImage *image;          XImage *image;
670          uint8 *tdata =          uint8 *tdata;
                 (private_colormap ? data : translate(width, height, data));  
         image =  
                 XCreateImage(display, visual, depth, ZPixmap, 0, tdata, width,  
                              height, BitmapPad(display), 0);  
   
         xwin_set_function(ROP2_COPY);  
   
         /* Window */  
         XPutImage(display, wnd, gc, image, 0, 0, x, y, cx, cy);  
         XFree(image);  
         if (!private_colormap)  
                 xfree(tdata);  
 }  
   
 void  
 ui_destroy_bitmap(HBITMAP bmp)  
 {  
         XFreePixmap(display, (Pixmap) bmp);  
 }  
671    
672  HCURSOR          tdata = (owncolmap ? data : translate_image(width, height, data));
673  ui_create_cursor(unsigned int x, unsigned int y, int width,          image = XCreateImage(display, visual, depth, ZPixmap, 0,
674                   int height, uint8 *mask, uint8 *data)                               (char *) tdata, width, height, 8, 0);
 {  
         XImage *imagecursor;  
         XImage *imagemask;  
         Pixmap maskbitmap, cursorbitmap;  
         Cursor cursor;  
         XColor bg, fg;  
         GC lgc;  
         int i, x1, y1, scanlinelen;  
         uint8 *cdata, *cmask;  
         uint8 c;  
         cdata = (uint8 *) malloc(sizeof(uint8) * width * height);  
         if (!cdata)  
                 return NULL;  
         scanlinelen = (width + 7) >> 3;  
         cmask = (uint8 *) malloc(sizeof(uint8) * scanlinelen * height);  
         if (!cmask)  
         {  
                 free(cdata);  
                 return NULL;  
         }  
         i = (height - 1) * scanlinelen;  
675    
676          if (!screen_msbfirst)          if (ownbackstore)
677          {          {
678                  while (i >= 0)                  XPutImage(display, backstore, gc, image, 0, 0, x, y, cx, cy);
679                  {                  XCopyArea(display, backstore, wnd, gc, x, y, cx, cy, x, y);
                         for (x1 = 0; x1 < scanlinelen; x1++)  
                         {  
                                 c = *(mask++);  
                                 cmask[i + x1] =  
                                         ((c & 0x1) << 7) | ((c & 0x2) << 5) |  
                                         ((c & 0x4) << 3) | ((c & 0x8) << 1) |  
                                         ((c & 0x10) >> 1) | ((c & 0x20) >> 3)  
                                         | ((c & 0x40) >> 5) | ((c & 0x80) >>  
                                                                7);  
                         }  
                         i -= scanlinelen;  
                 }  
680          }          }
681          else          else
682          {          {
683                  while (i >= 0)                  XPutImage(display, wnd, gc, image, 0, 0, x, y, cx, cy);
                 {  
                         for (x1 = 0; x1 < scanlinelen; x1++)  
                         {  
                                 cmask[i + x1] = *(mask++);  
                         }  
                         i -= scanlinelen;  
                 }  
684          }          }
685    
686            XFree(image);
687          fg.red = 0;          if (!owncolmap)
688          fg.blue = 0;                  xfree(tdata);
         fg.green = 0;  
         fg.flags = DoRed | DoBlue | DoGreen;  
         bg.red = 65535;  
         bg.blue = 65535;  
         bg.green = 65535;  
         bg.flags = DoRed | DoBlue | DoGreen;  
         maskbitmap = XCreatePixmap(display, wnd, width, height, 1);  
         cursorbitmap = XCreatePixmap(display, wnd, width, height, 1);  
         lgc = XCreateGC(display, maskbitmap, 0, NULL);  
         XSetFunction(display, lgc, GXcopy);  
         imagemask =  
                 XCreateImage(display, visual, 1, XYBitmap, 0, cmask, width,  
                              height, 8, 0);  
         imagecursor =  
                 XCreateImage(display, visual, 1, XYBitmap, 0, cdata, width,  
                              height, 8, 0);  
         for (y1 = height - 1; y1 >= 0; y1--)  
                 for (x1 = 0; x1 < width; x1++)  
                 {  
                         if (data[0] >= 0x80 || data[1] >= 0x80  
                             || data[2] >= 0x80)  
                                 if (XGetPixel(imagemask, x1, y1))  
   
                                 {  
                                         XPutPixel(imagecursor, x1, y1, 0);  
                                         XPutPixel(imagemask, x1, y1, 0);        /* mask is blank for text cursor! */  
                                 }  
   
                                 else  
                                         XPutPixel(imagecursor, x1, y1, 1);  
   
                         else  
                                 XPutPixel(imagecursor, x1, y1,  
                                           XGetPixel(imagemask, x1, y1));  
                         data += 3;  
                 }  
         XPutImage(display, maskbitmap, lgc, imagemask, 0, 0, 0, 0, width,  
                   height);  
         XPutImage(display, cursorbitmap, lgc, imagecursor, 0, 0, 0, 0, width,  
                   height); XFree(imagemask);  
         XFree(imagecursor);  
         free(cmask);  
         free(cdata);  
         XFreeGC(display, lgc);  
         cursor =  
                 XCreatePixmapCursor(display, cursorbitmap, maskbitmap, &fg,  
                                     &bg, x, y);  
         XFreePixmap(display, maskbitmap);  
         XFreePixmap(display, cursorbitmap);  
         return (HCURSOR) cursor;  
 }  
   
 void  
 ui_set_cursor(HCURSOR cursor)  
 {  
         XDefineCursor(display, wnd, (Cursor) cursor);  
689  }  }
690    
691  void  void
692  ui_destroy_cursor(HCURSOR cursor)  ui_destroy_bitmap(HBITMAP bmp)
693  {  {
694          XFreeCursor(display, (Cursor) cursor);          XFreePixmap(display, (Pixmap) bmp);
695  }  }
696    
697  HGLYPH  HGLYPH
698  ui_create_glyph(int width, int height, uint8 *data)  ui_create_glyph(int width, int height, uint8 * data)
699  {  {
700          XImage *image;          XImage *image;
701          Pixmap bitmap;          Pixmap bitmap;
# Line 538  ui_create_glyph(int width, int height, u Line 707  ui_create_glyph(int width, int height, u
707          bitmap = XCreatePixmap(display, wnd, width, height, 1);          bitmap = XCreatePixmap(display, wnd, width, height, 1);
708          gc = XCreateGC(display, bitmap, 0, NULL);          gc = XCreateGC(display, bitmap, 0, NULL);
709    
710          image = XCreateImage(display, visual, 1, ZPixmap, 0,          image = XCreateImage(display, visual, 1, ZPixmap, 0, (char *) data,
711                               data, width, height, 8, scanline);                               width, height, 8, scanline);
712          image->byte_order = MSBFirst;          image->byte_order = MSBFirst;
713          image->bitmap_bit_order = MSBFirst;          image->bitmap_bit_order = MSBFirst;
714          XInitImage(image);          XInitImage(image);
715    
         XSetFunction(display, gc, GXcopy);  
716          XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height);          XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height);
717    
718          XFree(image);          XFree(image);
719          XFreeGC(display, gc);          XFreeGC(display, gc);
   
720          return (HGLYPH) bitmap;          return (HGLYPH) bitmap;
721  }  }
722    
# Line 558  ui_destroy_glyph(HGLYPH glyph) Line 726  ui_destroy_glyph(HGLYPH glyph)
726          XFreePixmap(display, (Pixmap) glyph);          XFreePixmap(display, (Pixmap) glyph);
727  }  }
728    
729  HCOLOURMAP  HCURSOR
730  ui_create_colourmap(COLOURMAP *colours)  ui_create_cursor(unsigned int x, unsigned int y, int width, int height,
731                     uint8 * andmask, uint8 * xormask)
732  {  {
733          if (!private_colormap)          HGLYPH maskglyph, cursorglyph;
734            XColor bg, fg;
735            Cursor xcursor;
736            uint8 *cursor, *pcursor;
737            uint8 *mask, *pmask;
738            uint8 nextbit;
739            int scanline, offset;
740            int i, j;
741    
742            scanline = (width + 7) / 8;
743            offset = scanline * height;
744    
745            cursor = xmalloc(offset);
746            memset(cursor, 0, offset);
747    
748            mask = xmalloc(offset);
749            memset(mask, 0, offset);
750    
751            /* approximate AND and XOR masks with a monochrome X pointer */
752            for (i = 0; i < height; i++)
753          {          {
754                  COLOURENTRY *entry;                  offset -= scanline;
755                  int i, ncolours = colours->ncolours;                  pcursor = &cursor[offset];
756                  uint32 *nc = xmalloc(sizeof(*colmap) * ncolours);                  pmask = &mask[offset];
757                  for (i = 0; i < ncolours; i++)  
758                    for (j = 0; j < scanline; j++)
759                  {                  {
760                          XColor xc;                          for (nextbit = 0x80; nextbit != 0; nextbit >>= 1)
761                          entry = &colours->colours[i];                          {
762                          xc.red = entry->red << 8;                                  if (xormask[0] || xormask[1] || xormask[2])
763                          xc.green = entry->green << 8;                                  {
764                          xc.blue = entry->blue << 8;                                          *pcursor |= (~(*andmask) & nextbit);
765                          XAllocColor(display,                                          *pmask |= nextbit;
766                                      DefaultColormap(display,                                  }
767                                                      DefaultScreen(display)),                                  else
768                                      &xc);                                  {
769                          /* XXX Check return value */                                          *pcursor |= ((*andmask) & nextbit);
770                          nc[i] = xc.pixel;                                          *pmask |= (~(*andmask) & nextbit);
771                                    }
772    
773                                    xormask += 3;
774                            }
775    
776                            andmask++;
777                            pcursor++;
778                            pmask++;
779                  }                  }
                 return nc;  
780          }          }
781          else  
782            fg.red = fg.blue = fg.green = 0xffff;
783            bg.red = bg.blue = bg.green = 0x0000;
784            fg.flags = bg.flags = DoRed | DoBlue | DoGreen;
785    
786            cursorglyph = ui_create_glyph(width, height, cursor);
787            maskglyph = ui_create_glyph(width, height, mask);
788    
789            xcursor =
790                    XCreatePixmapCursor(display, (Pixmap) cursorglyph,
791                                        (Pixmap) maskglyph, &fg, &bg, x, y);
792    
793            ui_destroy_glyph(maskglyph);
794            ui_destroy_glyph(cursorglyph);
795            xfree(mask);
796            xfree(cursor);
797            return (HCURSOR) xcursor;
798    }
799    
800    void
801    ui_set_cursor(HCURSOR cursor)
802    {
803            XDefineCursor(display, wnd, (Cursor) cursor);
804    }
805    
806    void
807    ui_destroy_cursor(HCURSOR cursor)
808    {
809            XFreeCursor(display, (Cursor) cursor);
810    }
811    
812    #define MAKE_XCOLOR(xc,c) \
813                    (xc)->red   = ((c)->red   << 8) | (c)->red; \
814                    (xc)->green = ((c)->green << 8) | (c)->green; \
815                    (xc)->blue  = ((c)->blue  << 8) | (c)->blue; \
816                    (xc)->flags = DoRed | DoGreen | DoBlue;
817    
818    HCOLOURMAP
819    ui_create_colourmap(COLOURMAP * colours)
820    {
821            COLOURENTRY *entry;
822            int i, ncolours = colours->ncolours;
823    
824            if (owncolmap)
825          {          {
                 COLOURENTRY *entry;  
826                  XColor *xcolours, *xentry;                  XColor *xcolours, *xentry;
827                  Colormap map;                  Colormap map;
828                  int i, ncolours = colours->ncolours;  
829                  xcolours = xmalloc(sizeof(XColor) * ncolours);                  xcolours = xmalloc(sizeof(XColor) * ncolours);
830                  for (i = 0; i < ncolours; i++)                  for (i = 0; i < ncolours; i++)
831                  {                  {
832                          entry = &colours->colours[i];                          entry = &colours->colours[i];
833                          xentry = &xcolours[i];                          xentry = &xcolours[i];
   
834                          xentry->pixel = i;                          xentry->pixel = i;
835                          xentry->red = entry->red << 8;                          MAKE_XCOLOR(xentry, entry);
                         xentry->blue = entry->blue << 8;  
                         xentry->green = entry->green << 8;  
                         xentry->flags = DoRed | DoBlue | DoGreen;  
836                  }                  }
837    
838                  map = XCreateColormap(display, wnd, visual, AllocAll);                  map = XCreateColormap(display, wnd, visual, AllocAll);
# Line 607  ui_create_colourmap(COLOURMAP *colours) Line 841  ui_create_colourmap(COLOURMAP *colours)
841                  xfree(xcolours);                  xfree(xcolours);
842                  return (HCOLOURMAP) map;                  return (HCOLOURMAP) map;
843          }          }
844            else
845            {
846                    uint32 *map = xmalloc(sizeof(*colmap) * ncolours);
847                    XColor xentry;
848                    uint32 colour;
849    
850                    for (i = 0; i < ncolours; i++)
851                    {
852                            entry = &colours->colours[i];
853                            MAKE_XCOLOR(&xentry, entry);
854    
855                            if (XAllocColor(display, xcolmap, &xentry) != 0)
856                                    colour = xentry.pixel;
857                            else
858                                    colour = WhitePixelOfScreen(screen);
859    
860                            /* byte swap here to make translate_image faster */
861                            map[i] = translate_colour(colour);
862                    }
863    
864                    return map;
865            }
866  }  }
867    
868  void  void
869  ui_destroy_colourmap(HCOLOURMAP map)  ui_destroy_colourmap(HCOLOURMAP map)
870  {  {
871          XFreeColormap(display, (Colormap) map);          if (owncolmap)
872                    XFreeColormap(display, (Colormap) map);
873            else
874                    xfree(map);
875  }  }
876    
877  void  void
878  ui_set_colourmap(HCOLOURMAP map)  ui_set_colourmap(HCOLOURMAP map)
879  {  {
880            if (owncolmap)
         /* XXX, change values of all pixels on the screen if the new colmap  
          * doesn't have the same values as the old one? */  
         if (!private_colormap)  
                 colmap = map;  
         else  
         {  
881                  XSetWindowColormap(display, wnd, (Colormap) map);                  XSetWindowColormap(display, wnd, (Colormap) map);
882                  if (fullscreen)          else
883                          XInstallColormap(display, (Colormap) map);                  colmap = map;
         }  
884  }  }
885    
886  void  void
# Line 665  void Line 917  void
917  ui_destblt(uint8 opcode,  ui_destblt(uint8 opcode,
918             /* dest */ int x, int y, int cx, int cy)             /* dest */ int x, int y, int cx, int cy)
919  {  {
920          xwin_set_function(opcode);          SET_FUNCTION(opcode);
921            FILL_RECTANGLE(x, y, cx, cy);
922          XFillRectangle(display, wnd, gc, x, y, cx, cy);          RESET_FUNCTION(opcode);
923  }  }
924    
925  void  void
926  ui_patblt(uint8 opcode,  ui_patblt(uint8 opcode,
927            /* dest */ int x, int y, int cx, int cy,            /* dest */ int x, int y, int cx, int cy,
928            /* brush */ BRUSH *brush, int bgcolour, int fgcolour)            /* brush */ BRUSH * brush, int bgcolour, int fgcolour)
929  {  {
         Display *dpy = display;  
930          Pixmap fill;          Pixmap fill;
931          uint8 i, ipattern[8];          uint8 i, ipattern[8];
932    
933          xwin_set_function(opcode);          SET_FUNCTION(opcode);
934    
935          switch (brush->style)          switch (brush->style)
936          {          {
937                  case 0: /* Solid */                  case 0: /* Solid */
938                          XSetForeground(dpy, gc, Ctrans(fgcolour));                          SET_FOREGROUND(fgcolour);
939                          XFillRectangle(dpy, wnd, gc, x, y, cx, cy);                          FILL_RECTANGLE(x, y, cx, cy);
940                          break;                          break;
941    
942                  case 3: /* Pattern */                  case 3: /* Pattern */
943                          for (i = 0; i != 8; i++)                          for (i = 0; i != 8; i++)
944                                  ipattern[i] = ~brush->pattern[i];                                  ipattern[7 - i] = brush->pattern[i];
945                          fill = (Pixmap) ui_create_glyph(8, 8, ipattern);                          fill = (Pixmap) ui_create_glyph(8, 8, ipattern);
946    
947                          XSetForeground(dpy, gc, Ctrans(fgcolour));                          SET_FOREGROUND(bgcolour);
948                          XSetBackground(dpy, gc, Ctrans(bgcolour));                          SET_BACKGROUND(fgcolour);
949                          XSetFillStyle(dpy, gc, FillOpaqueStippled);                          XSetFillStyle(display, gc, FillOpaqueStippled);
950                          XSetStipple(dpy, gc, fill);                          XSetStipple(display, gc, fill);
951                            XSetTSOrigin(display, gc, brush->xorigin, brush->yorigin);
952    
953                          XFillRectangle(dpy, wnd, gc, x, y, cx, cy);                          FILL_RECTANGLE(x, y, cx, cy);
954    
955                          XSetFillStyle(dpy, gc, FillSolid);                          XSetFillStyle(display, gc, FillSolid);
956                            XSetTSOrigin(display, gc, 0, 0);
957                          ui_destroy_glyph((HGLYPH) fill);                          ui_destroy_glyph((HGLYPH) fill);
958                          break;                          break;
959    
960                  default:                  default:
961                          NOTIMP("brush %d\n", brush->style);                          unimpl("brush %d\n", brush->style);
962          }          }
963    
964            RESET_FUNCTION(opcode);
965  }  }
966    
967  void  void
# Line 714  ui_screenblt(uint8 opcode, Line 969  ui_screenblt(uint8 opcode,
969               /* dest */ int x, int y, int cx, int cy,               /* dest */ int x, int y, int cx, int cy,
970               /* src */ int srcx, int srcy)               /* src */ int srcx, int srcy)
971  {  {
972          xwin_set_function(opcode);          SET_FUNCTION(opcode);
   
973          XCopyArea(display, wnd, wnd, gc, srcx, srcy, cx, cy, x, y);          XCopyArea(display, wnd, wnd, gc, srcx, srcy, cx, cy, x, y);
974            if (ownbackstore)
975                    XCopyArea(display, backstore, backstore, gc, srcx, srcy, cx, cy, x, y);
976            RESET_FUNCTION(opcode);
977  }  }
978    
979  void  void
# Line 724  ui_memblt(uint8 opcode, Line 981  ui_memblt(uint8 opcode,
981            /* dest */ int x, int y, int cx, int cy,            /* dest */ int x, int y, int cx, int cy,
982            /* src */ HBITMAP src, int srcx, int srcy)            /* src */ HBITMAP src, int srcx, int srcy)
983  {  {
984          xwin_set_function(opcode);          SET_FUNCTION(opcode);
   
985          XCopyArea(display, (Pixmap) src, wnd, gc, srcx, srcy, cx, cy, x, y);          XCopyArea(display, (Pixmap) src, wnd, gc, srcx, srcy, cx, cy, x, y);
986            if (ownbackstore)
987                    XCopyArea(display, (Pixmap) src, backstore, gc, srcx, srcy, cx, cy, x, y);
988            RESET_FUNCTION(opcode);
989  }  }
990    
991  void  void
992  ui_triblt(uint8 opcode,  ui_triblt(uint8 opcode,
993            /* dest */ int x, int y, int cx, int cy,            /* dest */ int x, int y, int cx, int cy,
994            /* src */ HBITMAP src, int srcx, int srcy,            /* src */ HBITMAP src, int srcx, int srcy,
995            /* brush */ BRUSH *brush, int bgcolour, int fgcolour)            /* brush */ BRUSH * brush, int bgcolour, int fgcolour)
996  {  {
997          /* This is potentially difficult to do in general. Until someone          /* This is potentially difficult to do in general. Until someone
998             comes up with a more efficient way of doing it I am using cases. */             comes up with a more efficient way of doing it I am using cases. */
# Line 742  ui_triblt(uint8 opcode, Line 1001  ui_triblt(uint8 opcode,
1001          {          {
1002                  case 0x69:      /* PDSxxn */                  case 0x69:      /* PDSxxn */
1003                          ui_memblt(ROP2_XOR, x, y, cx, cy, src, srcx, srcy);                          ui_memblt(ROP2_XOR, x, y, cx, cy, src, srcx, srcy);
1004                          ui_patblt(ROP2_NXOR, x, y, cx, cy,                          ui_patblt(ROP2_NXOR, x, y, cx, cy, brush, bgcolour, fgcolour);
                                   brush, bgcolour, fgcolour);  
1005                          break;                          break;
1006    
1007                  case 0xb8:      /* PSDPxax */                  case 0xb8:      /* PSDPxax */
1008                          ui_patblt(ROP2_XOR, x, y, cx, cy,                          ui_patblt(ROP2_XOR, x, y, cx, cy, brush, bgcolour, fgcolour);
                                   brush, bgcolour, fgcolour);  
1009                          ui_memblt(ROP2_AND, x, y, cx, cy, src, srcx, srcy);                          ui_memblt(ROP2_AND, x, y, cx, cy, src, srcx, srcy);
1010                          ui_patblt(ROP2_XOR, x, y, cx, cy,                          ui_patblt(ROP2_XOR, x, y, cx, cy, brush, bgcolour, fgcolour);
                                   brush, bgcolour, fgcolour);  
1011                          break;                          break;
1012    
1013                  case 0xc0:                  case 0xc0:      /* PSa */
1014                          ui_memblt(ROP2_COPY, x, y, cx, cy, src, srcx, srcy);                          ui_memblt(ROP2_COPY, x, y, cx, cy, src, srcx, srcy);
1015                          ui_patblt(ROP2_AND, x, y, cx, cy, brush, bgcolour,                          ui_patblt(ROP2_AND, x, y, cx, cy, brush, bgcolour, fgcolour);
                                   fgcolour);  
1016                          break;                          break;
1017    
1018                  default:                  default:
1019                          NOTIMP("triblt 0x%x\n", opcode);                          unimpl("triblt 0x%x\n", opcode);
1020                          ui_memblt(ROP2_COPY, x, y, cx, cy, src, srcx, srcy);                          ui_memblt(ROP2_COPY, x, y, cx, cy, src, srcx, srcy);
1021          }          }
1022  }  }
# Line 769  ui_triblt(uint8 opcode, Line 1024  ui_triblt(uint8 opcode,
1024  void  void
1025  ui_line(uint8 opcode,  ui_line(uint8 opcode,
1026          /* dest */ int startx, int starty, int endx, int endy,          /* dest */ int startx, int starty, int endx, int endy,
1027          /* pen */ PEN *pen)          /* pen */ PEN * pen)
1028  {  {
1029          xwin_set_function(opcode);          SET_FUNCTION(opcode);
1030            SET_FOREGROUND(pen->colour);
         XSetForeground(display, gc, Ctrans(pen->colour));  
1031          XDrawLine(display, wnd, gc, startx, starty, endx, endy);          XDrawLine(display, wnd, gc, startx, starty, endx, endy);
1032            if (ownbackstore)
1033                    XDrawLine(display, backstore, gc, startx, starty, endx, endy);
1034            RESET_FUNCTION(opcode);
1035  }  }
1036    
1037  void  void
# Line 782  ui_rect( Line 1039  ui_rect(
1039                 /* dest */ int x, int y, int cx, int cy,                 /* dest */ int x, int y, int cx, int cy,
1040                 /* brush */ int colour)                 /* brush */ int colour)
1041  {  {
1042          xwin_set_function(ROP2_COPY);          SET_FOREGROUND(colour);
1043            FILL_RECTANGLE(x, y, cx, cy);
         XSetForeground(display, gc, Ctrans(colour));  
         XFillRectangle(display, wnd, gc, x, y, cx, cy);  
1044  }  }
1045    
1046  void  void
1047  ui_draw_glyph(int mixmode,  ui_draw_glyph(int mixmode,
1048                /* dest */ int x, int y, int cx, int cy,                /* dest */ int x, int y, int cx, int cy,
1049                /* src */ HGLYPH glyph, int srcx, int srcy, int bgcolour,                /* src */ HGLYPH glyph, int srcx, int srcy,
1050                int fgcolour)                int bgcolour, int fgcolour)
1051  {  {
1052          Pixmap pixmap = (Pixmap) glyph;          SET_FOREGROUND(fgcolour);
1053            SET_BACKGROUND(bgcolour);
         xwin_set_function(ROP2_COPY);  
   
   
         XSetForeground(display, gc, Ctrans(fgcolour));  
         switch (mixmode)  
         {  
                 case MIX_TRANSPARENT:  
                         XSetStipple(display, gc, pixmap);  
                         XSetFillStyle(display, gc, FillStippled);  
                         XSetTSOrigin(display, gc, x, y);  
                         XFillRectangle(display, wnd, gc, x, y, cx, cy);  
                         XSetFillStyle(display, gc, FillSolid);  
                         break;  
   
                 case MIX_OPAQUE:  
                         XSetBackground(display, gc, Ctrans(bgcolour));  
 /*      XCopyPlane (display, pixmap, back_pixmap, back_gc, srcx, srcy, cx, cy, x, y, 1); */  
                         XSetStipple(display, gc, pixmap);  
                         XSetFillStyle(display, gc, FillOpaqueStippled);  
                         XSetTSOrigin(display, gc, x, y);  
                         XFillRectangle(display, wnd, gc, x, y, cx, cy);  
                         XSetFillStyle(display, gc, FillSolid);  
                         break;  
1054    
1055                  default:          XSetFillStyle(display, gc,
1056                          NOTIMP("mix %d\n", mixmode);                        (mixmode == MIX_TRANSPARENT) ? FillStippled : FillOpaqueStippled);
1057          }          XSetStipple(display, gc, (Pixmap) glyph);
1058            XSetTSOrigin(display, gc, x, y);
1059    
1060            FILL_RECTANGLE(x, y, cx, cy);
1061    
1062            XSetFillStyle(display, gc, FillSolid);
1063    }
1064    
1065    #define DO_GLYPH(ttext,idx) \
1066    {\
1067      glyph = cache_get_font (font, ttext[idx]);\
1068      if (!(flags & TEXT2_IMPLICIT_X))\
1069        {\
1070          xyoffset = ttext[++idx];\
1071          if ((xyoffset & 0x80))\
1072            {\
1073              if (flags & TEXT2_VERTICAL) \
1074                y += ttext[idx+1] | (ttext[idx+2] << 8);\
1075              else\
1076                x += ttext[idx+1] | (ttext[idx+2] << 8);\
1077              idx += 2;\
1078            }\
1079          else\
1080            {\
1081              if (flags & TEXT2_VERTICAL) \
1082                y += xyoffset;\
1083              else\
1084                x += xyoffset;\
1085            }\
1086        }\
1087      if (glyph != NULL)\
1088        {\
1089          ui_draw_glyph (mixmode, x + (short) glyph->offset,\
1090                         y + (short) glyph->baseline,\
1091                         glyph->width, glyph->height,\
1092                         glyph->pixmap, 0, 0, bgcolour, fgcolour);\
1093          if (flags & TEXT2_IMPLICIT_X)\
1094            x += glyph->width;\
1095        }\
1096  }  }
1097    
1098  void  void
1099  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,
1100               int clipx, int clipy, int clipcx, int clipcy,               int clipx, int clipy, int clipcx, int clipcy,
1101               int boxx, int boxy, int boxcx, int boxcy,               int boxx, int boxy, int boxcx, int boxcy, int bgcolour,
1102               int bgcolour, int fgcolour, uint8 *text, uint8 length)               int fgcolour, uint8 * text, uint8 length)
1103  {  {
1104          FONTGLYPH *glyph;          FONTGLYPH *glyph;
1105          int i, xyoffset;          int i, j, xyoffset;
1106            DATABLOB *entry;
1107    
1108          xwin_set_function(ROP2_COPY);          SET_FOREGROUND(bgcolour);
         XSetForeground(display, gc, Ctrans(bgcolour));  
1109    
1110          if (boxcx > 1)          if (boxcx > 1)
1111                  XFillRectangle(display, wnd, gc, boxx, boxy, boxcx, boxcy);          {
1112                    FILL_RECTANGLE(boxx, boxy, boxcx, boxcy);
1113            }
1114          else if (mixmode == MIX_OPAQUE)          else if (mixmode == MIX_OPAQUE)
1115                  XFillRectangle(display, wnd, gc, clipx, clipy, clipcx, clipcy);          {
1116                    FILL_RECTANGLE(clipx, clipy, clipcx, clipcy);
1117            }
1118    
1119          /* Paint text, character by character */          /* Paint text, character by character */
1120          for (i = 0; i < length; i++)          for (i = 0; i < length;)
1121          {          {
1122                  glyph = cache_get_font(font, text[i]);                  switch (text[i])
   
                 if (!(flags & TEXT2_IMPLICIT_X))  
   
1123                  {                  {
1124                          xyoffset = text[++i];                          case 0xff:
1125                          if ((xyoffset & 0x80))                                  if (i + 2 < length)
1126                          {                                          cache_put_text(text[i + 1], text, text[i + 2]);
                                 if (flags & 0x04)       /* vertical text */  
                                         y += text[++i] | (text[++i] << 8);  
                                 else  
                                         x += text[++i] | (text[++i] << 8);  
                         }  
                         else  
                         {  
                                 if (flags & 0x04)       /* vertical text */  
                                         y += xyoffset;  
1127                                  else                                  else
1128                                          x += xyoffset;                                  {
1129                          }                                          error("this shouldn't be happening\n");
1130                                            break;
1131                                    }
1132                                    /* this will move pointer from start to first character after FF command */
1133                                    length -= i + 3;
1134                                    text = &(text[i + 3]);
1135                                    i = 0;
1136                                    break;
1137    
1138                  }                          case 0xfe:
1139                  if (glyph != NULL)                                  entry = cache_get_text(text[i + 1]);
1140                  {                                  if (entry != NULL)
1141                          ui_draw_glyph(mixmode, x + (short) glyph->offset,                                  {
1142                                        y + (short) glyph->baseline,                                          if ((((uint8 *) (entry->data))[1] ==
1143                                        glyph->width, glyph->height,                                               0) && (!(flags & TEXT2_IMPLICIT_X)))
1144                                        glyph->pixmap, 0, 0,                                          {
1145                                        bgcolour, fgcolour);                                                  if (flags & TEXT2_VERTICAL)
1146                                                            y += text[i + 2];
1147                                                    else
1148                                                            x += text[i + 2];
1149                                            }
1150                                            if (i + 2 < length)
1151                                                    i += 3;
1152                                            else
1153                                                    i += 2;
1154                                            length -= i;
1155                                            /* this will move pointer from start to first character after FE command */
1156                                            text = &(text[i]);
1157                                            i = 0;
1158                                            for (j = 0; j < entry->size; j++)
1159                                                    DO_GLYPH(((uint8 *) (entry->data)), j);
1160                                    }
1161                                    break;
1162    
1163                          if (flags & TEXT2_IMPLICIT_X)                          default:
1164                                  x += glyph->width;                                  DO_GLYPH(text, i);
1165                                    i++;
1166                                    break;
1167                  }                  }
1168          }          }
1169    
1170    
1171  }  }
1172    
1173  void  void
# Line 887  ui_desktop_save(uint32 offset, int x, in Line 1176  ui_desktop_save(uint32 offset, int x, in
1176          Pixmap pix;          Pixmap pix;
1177          XImage *image;          XImage *image;
1178    
1179          pix = XCreatePixmap(display, wnd, cx, cy, depth);          if (ownbackstore)
1180          xwin_set_function(ROP2_COPY);          {
1181                    image = XGetImage(display, backstore, x, y, cx, cy, AllPlanes, ZPixmap);
1182          XCopyArea(display, wnd, pix, gc, x, y, cx, cy, 0, 0);          }
1183          image = XGetImage(display, pix, 0, 0, cx, cy, AllPlanes, ZPixmap);          else
1184            {
1185                    pix = XCreatePixmap(display, wnd, cx, cy, depth);
1186                    XCopyArea(display, wnd, pix, gc, x, y, cx, cy, 0, 0);
1187                    image = XGetImage(display, pix, 0, 0, cx, cy, AllPlanes, ZPixmap);
1188                    XFreePixmap(display, pix);
1189            }
1190    
1191          offset *= bpp/8;          offset *= bpp / 8;
1192          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, image->data);  
1193    
1194          XDestroyImage(image);          XDestroyImage(image);
         XFreePixmap(display, pix);  
1195  }  }
1196    
1197  void  void
# Line 907  ui_desktop_restore(uint32 offset, int x, Line 1200  ui_desktop_restore(uint32 offset, int x,
1200          XImage *image;          XImage *image;
1201          uint8 *data;          uint8 *data;
1202    
1203          offset *= bpp/8;          offset *= bpp / 8;
1204          data = cache_get_desktop(offset, cx, cy, bpp/8);          data = cache_get_desktop(offset, cx, cy, bpp / 8);
1205          if (data == NULL)          if (data == NULL)
1206                  return;                  return;
         image =  
                 XCreateImage(display, visual,  
                              depth, ZPixmap,  
                              0, data, cx, cy, BitmapPad(display),  
                              cx * bpp/8);  
         xwin_set_function(ROP2_COPY);  
         XPutImage(display, wnd, gc, image, 0, 0, x, y, cx, cy);  
         XFree(image);  
 }  
1207    
1208  /* unroll defines, used to make the loops a bit more readable... */          image = XCreateImage(display, visual, depth, ZPixmap, 0,
1209  #define unroll8Expr(uexp) uexp uexp uexp uexp uexp uexp uexp uexp                               (char *) data, cx, cy, BitmapPad(display), cx * bpp / 8);
 #define unroll8Lefts(uexp) case 7: uexp \  
         case 6: uexp \  
         case 5: uexp \  
         case 4: uexp \  
         case 3: uexp \  
         case 2: uexp \  
         case 1: uexp  
   
 static uint8 *  
 translate(int width, int height, uint8 *data)  
 {  
         uint32 i;  
         uint32 size = width * height;  
         uint8 *d2 = xmalloc(size * bpp/8);  
         uint8 *d3 = d2;  
         uint32 pix;  
         i = (size & ~0x7);  
   
         /* XXX: where are the bits swapped??? */  
 #ifdef L_ENDIAN                 /* little-endian */  
         /* big-endian screen */  
         if (screen_msbfirst)  
         {  
                 switch (bpp)  
                 {  
                         case 32:  
                                 while (i)  
                                 {  
                                         unroll8Expr(pix = colmap[*data++];  
                                                     *d3++ = pix >> 24;  
                                                     *d3++ = pix >> 16;  
                                                     *d3++ = pix >> 8;  
                                                     *d3++ = pix;) i -= 8;  
                                 }  
                                 i = (size & 0x7);  
                                 if (i != 0)  
                                         switch (i)  
                                         {  
                                                         unroll8Lefts(pix =  
                                                                      colmap  
                                                                      [*data++];  
                                                                      *d3++ =  
                                                                      pix >>  
                                                                      24;  
                                                                      *d3++ =  
                                                                      pix >>  
                                                                      16;  
                                                                      *d3++ =  
                                                                      pix >> 8;  
                                                                      *d3++ =  
                                                                      pix;)}  
                                 break;  
                         case 24:  
                                 while (i)  
                                 {  
                                         unroll8Expr(pix = colmap[*data++];  
                                                     *d3++ = pix >> 16;  
                                                     *d3++ = pix >> 8;  
                                                     *d3++ = pix;) i -= 8;  
                                 }  
                                 i = (size & 0x7);  
                                 if (i != 0)  
                                         switch (i)  
                                         {  
                                                         unroll8Lefts(pix =  
                                                                      colmap  
                                                                      [*data++];  
                                                                      *d3++ =  
                                                                      pix >>  
                                                                      16;  
                                                                      *d3++ =  
                                                                      pix >> 8;  
                                                                      *d3++ =  
                                                                      pix;)}  
                                 break;  
                         case 16:  
                                 while (i)  
                                 {  
                                         unroll8Expr(pix = colmap[*data++];  
                                                     *d3++ = pix >> 8;  
                                                     *d3++ = pix;) i -= 8;  
                                 }  
                                 i = (size & 0x7);  
                                 if (i != 0)  
                                         switch (i)  
                                         {  
                                                         unroll8Lefts(pix =  
                                                                      colmap  
                                                                      [*data++];  
                                                                      *d3++ =  
                                                                      pix >> 8;  
                                                                      *d3++ =  
                                                                      pix;)}  
                                 break;  
                         case 8:  
                                 while (i)  
                                 {  
                                         unroll8Expr(pix = colmap[*data++];  
                                                     *d3++ = pix;  
                                                 )i -= 8;  
                                 }  
                                 i = (size & 0x7);  
                                 if (i != 0)  
                                         switch (i)  
                                         {  
                                                         unroll8Lefts(pix =  
                                                                      colmap  
                                                                      [*data++];  
                                                                      *d3++ =  
                                                                      pix;)}  
                                 break;  
                 }  
         }  
         else  
         {                       /* little-endian screen */  
                 switch (bpp)  
                 {  
                         case 32:  
                                 while (i)  
                                 {  
                                         unroll8Expr(*((uint32 *) d3) =  
                                                     colmap[*data++];  
                                                     d3 += sizeof(uint32);  
                                                 )i -= 8;  
                                 }  
                                 i = (size & 0x7);  
                                 if (i != 0)  
                                         switch (i)  
                                         {  
                                                         unroll8Lefts(*  
                                                                      ((uint32  
                                                                        *) d3)  
 = colmap[*data++];  
 d3 += sizeof(uint32);  
                                         )}  
                                 break;  
                         case 24:  
                                 while (i)  
                                 {  
                                         unroll8Expr(pix = colmap[*data++];  
                                                     *d3++ = pix;  
                                                     *d3++ = pix >> 8;  
                                                     *d3++ = pix >> 16;  
                                                 )i -= 8;  
                                 }  
                                 i = (size & 0x7);  
                                 if (i != 0)  
                                         switch (i)  
                                         {  
                                                         unroll8Lefts(pix =  
                                                                      colmap  
                                                                      [*data++];  
                                                                      *d3++ =  
                                                                      pix;  
                                                                      *d3++ =  
                                                                      pix >> 8;  
                                                                      *d3++ =  
                                                                      pix >>  
                                                                      16;)}  
                                 break;  
                         case 16:  
                                 while (i)  
                                 {  
                                         unroll8Expr(pix = colmap[*data++];  
                                                     *d3++ = pix;  
                                                     *d3++ = pix >> 8;  
                                                 )i -= 8;  
                                 }  
                                 i = (size & 0x7);  
                                 if (i != 0)  
                                         switch (i)  
                                         {  
                                                         unroll8Lefts(pix =  
                                                                      colmap  
                                                                      [*data++];  
                                                                      *d3++ =  
                                                                      pix;  
                                                                      *d3++ =  
                                                                      pix >> 8;  
                                         )}  
                                 break;  
                         case 8:  
                                 while (i)  
                                 {  
                                         unroll8Expr(pix = colmap[*data++];  
                                                     *d3++ = pix;  
                                                 )i -= 8;  
                                 }  
                                 i = (size & 0x7);  
                                 if (i != 0)  
                                         switch (i)  
                                         {  
                                                         unroll8Lefts(pix =  
                                                                      colmap  
                                                                      [*data++];  
                                                                      *d3++ =  
                                                                      pix;)}  
                 }  
         }  
1210    
1211  #else /* bigendian-compiled */          if (ownbackstore)
         if (screen_msbfirst)  
1212          {          {
1213                  /* big-endian screen */                  XPutImage(display, backstore, gc, image, 0, 0, x, y, cx, cy);
1214                  switch (bpp)                  XCopyArea(display, backstore, wnd, gc, x, y, cx, cy, x, y);
                 {  
                         case 32:  
                                 while (i)  
                                 {  
                                         unroll8Expr(*((uint32 *) d3) =  
                                                     colmap[*data++];  
                                                     d3 += sizeof(uint32);  
                                                 )i -= 8;  
                                 }  
                                 i = (size & 0x7);  
                                 if (i != 0)  
                                         switch (i)  
                                         {  
                                                         unroll8Lefts(*  
                                                                      ((uint32  
                                                                        *) d3)  
 = colmap[*data++];  
 d3 += sizeof(uint32);  
                                         )}  
                                 break;  
                         case 24:  
                                 while (i)  
                                 {  
                                         unroll8Expr(pix = colmap[*data++];  
                                                     *d3++ = pix;  
                                                     *d3++ = pix >> 8;  
                                                     *d3++ = pix >> 16;  
                                                 )i -= 8;  
                                 }  
                                 i = (size & 0x7);  
                                 if (i != 0)  
                                         switch (i)  
                                         {  
                                                         unroll8Lefts(pix =  
                                                                      colmap  
                                                                      [*data++];  
                                                                      *d3++ =  
                                                                      pix;  
                                                                      *d3++ =  
                                                                      pix >> 8;  
                                                                      *d3++ =  
                                                                      pix >>  
                                                                      16;)}  
                                 break;  
                         case 16:  
                                 while (i)  
                                 {  
                                         unroll8Expr(pix = colmap[*data++];  
                                                     *d3++ = pix;  
                                                     *d3++ = pix >> 8;  
                                                 )i -= 8;  
                                 }  
                                 i = (size & 0x7);  
                                 if (i != 0)  
                                         switch (i)  
                                         {  
                                                         unroll8Lefts(pix =  
                                                                      colmap  
                                                                      [*data++];  
                                                                      *d3++ =  
                                                                      pix;  
                                                                      *d3++ =  
                                                                      pix >> 8;  
                                         )}  
                                 break;  
                         case 8:  
                                 while (i)  
                                 {  
                                         unroll8Expr(pix = colmap[*data++];  
                                                     *d3++ = pix;  
                                                 )i -= 8;  
                                 }  
                                 i = (size & 0x7);  
                                 if (i != 0)  
                                         switch (i)  
                                         {  
                                                         unroll8Lefts(pix =  
                                                                      colmap  
                                                                      [*data++];  
                                                                      *d3++ =  
                                                                      pix;)}  
                 }  
1215          }          }
1216          else          else
1217          {          {
1218                  /* little-endian screen */                  XPutImage(display, wnd, gc, image, 0, 0, x, y, cx, cy);
                 switch (bpp)  
                 {  
                         case 32:  
                                 while (i)  
                                 {  
                                         unroll8Expr(pix = colmap[*data++];  
                                                     *d3++ = pix;  
                                                     *d3++ = pix >> 8;  
                                                     *d3++ = pix >> 16;  
                                                     *d3++ = pix >> 24;  
                                                 )i -= 8;  
                                 }  
                                 i = (size & 0x7);  
                                 if (i != 0)  
                                         switch (i)  
                                         {  
                                                         unroll8Lefts(pix =  
                                                                      colmap  
                                                                      [*data++];  
                                                                      *d3++ =  
                                                                      pix;  
                                                                      *d3++ =  
                                                                      pix >> 8;  
                                                                      *d3++ =  
                                                                      pix >>  
                                                                      16;  
                                                                      *d3++ =  
                                                                      pix >>  
                                                                      24;)}  
                                 break;  
                         case 24:  
                                 while (i)  
                                 {  
                                         unroll8Expr(pix = colmap[*data++];  
                                                     *d3++ = pix;  
                                                     *d3++ = pix >> 8;  
                                                     *d3++ = pix >> 16;  
                                                 )i -= 8;  
                                 }  
                                 i = (size & 0x7);  
                                 if (i != 0)  
                                         switch (i)  
                                         {  
                                                         unroll8Lefts(pix =  
                                                                      colmap  
                                                                      [*data++];  
                                                                      *d3++ =  
                                                                      pix;  
                                                                      *d3++ =  
                                                                      pix >> 8;  
                                                                      *d3++ =  
                                                                      pix >>  
                                                                      16;)}  
                                 break;  
                         case 16:  
                                 while (i)  
                                 {  
                                         unroll8Expr(pix = colmap[*data++];  
                                                     *d3++ = pix;  
                                                     *d3++ = pix >> 8;  
                                                 )i -= 8;  
                                 }  
                                 i = (size & 0x7);  
                                 if (i != 0)  
                                         switch (i)  
                                         {  
                                                         unroll8Lefts(pix =  
                                                                      colmap  
                                                                      [*data++];  
                                                                      *d3++ =  
                                                                      pix;  
                                                                      *d3++ =  
                                                                      pix >> 8;  
                                         )}  
                                 break;  
                         case 8:  
                                 while (i)  
                                 {  
                                         unroll8Expr(pix = colmap[*data++];  
                                                     *d3++ = pix;  
                                                 )i -= 8;  
                                 }  
                                 i = (size & 0x7);  
                                 if (i != 0)  
                                         switch (i)  
                                         {  
                                                         unroll8Lefts(pix =  
                                                                      colmap  
                                                                      [*data++];  
                                                                      *d3++ =  
                                                                      pix;)}  
                 }  
1219          }          }
 #endif  
1220    
1221          return d2;          XFree(image);
1222  }  }

Legend:
Removed from v.28  
changed lines
  Added in v.164

  ViewVC Help
Powered by ViewVC 1.1.26