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

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

  ViewVC Help
Powered by ViewVC 1.1.26