/[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 262 by astrand, Mon Nov 18 15:37:20 2002 UTC revision 311 by jsorg71, Wed Feb 5 14:16:33 2003 UTC
# Line 31  extern BOOL fullscreen; Line 31  extern BOOL fullscreen;
31  extern BOOL grab_keyboard;  extern BOOL grab_keyboard;
32  extern BOOL hide_decorations;  extern BOOL hide_decorations;
33  extern char title[];  extern char title[];
34    extern int server_bpp;
35  BOOL enable_compose = False;  BOOL enable_compose = False;
36  BOOL focused;  BOOL focused;
37  BOOL mouse_in_wnd;  BOOL mouse_in_wnd;
# Line 47  static XIM IM; Line 48  static XIM IM;
48  static XIC IC;  static XIC IC;
49  static XModifierKeymap *mod_map;  static XModifierKeymap *mod_map;
50  static Cursor current_cursor;  static Cursor current_cursor;
51    static Atom protocol_atom, kill_atom;
52    
53  /* endianness */  /* endianness */
54  static BOOL host_be;  static BOOL host_be;
# Line 61  static Pixmap backstore; Line 63  static Pixmap backstore;
63  #define PROP_MOTIF_WM_HINTS_ELEMENTS    5  #define PROP_MOTIF_WM_HINTS_ELEMENTS    5
64  typedef struct  typedef struct
65  {  {
66          unsigned long flags;          uint32 flags;
67          unsigned long functions;          uint32 functions;
68          unsigned long decorations;          uint32 decorations;
69          long inputMode;          sint32 inputMode;
70          unsigned long status;          uint32 status;
71  }  }
72  PropMotifWmHints;  PropMotifWmHints;
73    
# Line 77  PropMotifWmHints; Line 79  PropMotifWmHints;
79                  XFillRectangle(display, backstore, gc, x, y, cx, cy); \                  XFillRectangle(display, backstore, gc, x, y, cx, cy); \
80  }  }
81    
82    #define FILL_RECTANGLE_BACKSTORE(x,y,cx,cy)\
83    { \
84            XFillRectangle(display, ownbackstore ? backstore : wnd, gc, x, y, cx, cy); \
85    }
86    
87  /* colour maps */  /* colour maps */
88    BOOL owncolmap = False;
89  static Colormap xcolmap;  static Colormap xcolmap;
90  static uint32 *colmap;  static uint32 *colmap;
91    
92  #define SET_FOREGROUND(col)     XSetForeground(display, gc, translate_colour(colmap[col]));  #define TRANSLATE(col)          ( server_bpp != 8 ? translate_colour(col) : owncolmap ? col : translate_colour(colmap[col]) )
93  #define SET_BACKGROUND(col)     XSetBackground(display, gc, translate_colour(colmap[col]));  #define SET_FOREGROUND(col)     XSetForeground(display, gc, TRANSLATE(col));
94    #define SET_BACKGROUND(col)     XSetBackground(display, gc, TRANSLATE(col));
95    
96  static int rop2_map[] = {  static int rop2_map[] = {
97          GXclear,                /* 0 */          GXclear,                /* 0 */
# Line 120  mwm_hide_decorations(void) Line 129  mwm_hide_decorations(void)
129          hintsatom = XInternAtom(display, "_MOTIF_WM_HINTS", False);          hintsatom = XInternAtom(display, "_MOTIF_WM_HINTS", False);
130          if (!hintsatom)          if (!hintsatom)
131          {          {
132                  error("Failed to get atom _MOTIF_WM_HINTS\n");                  warning("Failed to get atom _MOTIF_WM_HINTS: probably your window manager does not support MWM hints\n");
133                  return;                  return;
134          }          }
135    
# Line 128  mwm_hide_decorations(void) Line 137  mwm_hide_decorations(void)
137                          (unsigned char *) &motif_hints, PROP_MOTIF_WM_HINTS_ELEMENTS);                          (unsigned char *) &motif_hints, PROP_MOTIF_WM_HINTS_ELEMENTS);
138  }  }
139    
140    uint32
141    colour16to24(uint32 colour)
142    {
143            int r;
144            int g;
145            int b;
146            r = (colour & 0xf800) >> 11;
147            r = (r * 0xff) / 0x1f;
148            g = (colour & 0x07e0) >> 5;
149            g = (g * 0xff) / 0x3f;
150            b = (colour & 0x001f);
151            b = (b * 0xff) / 0x1f;
152            return (r << 16) | (g << 8) | b;
153    }
154    
155    uint32
156    colour16to32(uint32 colour)
157    {
158            return colour16to24(colour);
159    }
160    
161    uint32
162    colour24to32(uint32 colour)
163    {
164            return colour;
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 (server_bpp)
176            {
177                    case 16:
178                            switch (bpp)
179                            {
180                                    case 16:
181                                            break;
182                                    case 24:
183                                            colour = colour16to24(colour);
184                                            break;
185                                    case 32:
186                                            colour = colour16to32(colour);
187                                            break;
188                            }
189                            break;
190                    case 24:
191                            switch (bpp)
192                            {
193                                    case 24:
194                                            break;
195                                    case 32:
196                                            colour = colour24to32(colour);
197                                            break;
198                            }
199                            break;
200            }
201            switch (bpp)
202            {
203                    case 16:
204                            if (host_be != xserver_be)
205                                    BSWAP16(colour);
206                            break;
207    
208                    case 24:
209                            if (xserver_be)
210                                    BSWAP24(colour);
211                            break;
212    
213                    case 32:
214                            if (host_be != xserver_be)
215                                    BSWAP32(colour);
216                            break;
217            }
218    
219            return colour;
220    }
221    
222  static void  static void
223  translate8(uint8 * data, uint8 * out, uint8 * end)  translate8to8(uint8 * data, uint8 * out, uint8 * end)
224  {  {
225          while (out < end)          while (out < end)
226                  *(out++) = (uint8) colmap[*(data++)];                  *(out++) = (uint8) colmap[*(data++)];
227  }  }
228    
229  static void  static void
230  translate16(uint8 * data, uint16 * out, uint16 * end)  translate8to16(uint8 * data, uint16 * out, uint16 * end)
231  {  {
232          while (out < end)          while (out < end)
233                  *(out++) = (uint16) colmap[*(data++)];                  *(out++) = (uint16) colmap[*(data++)];
234  }  }
235    
236    static void
237    translate16to16(uint16 * data, uint16 * out, uint16 * end)
238    {
239            while (out < end)
240                    *(out++) = (uint16) translate_colour(*(data++));
241    }
242    
243  /* little endian - conversion happens when colourmap is built */  /* little endian - conversion happens when colourmap is built */
244  static void  static void
245  translate24(uint8 * data, uint8 * out, uint8 * end)  translate8to24(uint8 * data, uint8 * out, uint8 * end)
246  {  {
247          uint32 value;          uint32 value;
248    
# Line 158  translate24(uint8 * data, uint8 * out, u Line 256  translate24(uint8 * data, uint8 * out, u
256  }  }
257    
258  static void  static void
259  translate32(uint8 * data, uint32 * out, uint32 * end)  translate16to24(uint16 * data, uint8 * out, uint8 * end)
260    {
261            uint32 value;
262    
263            while (out < end)
264            {
265                    value = translate_colour(*(data++));
266                    *(out++) = value;
267                    *(out++) = value >> 8;
268                    *(out++) = value >> 16;
269            }
270    }
271    
272    static void
273    translate8to32(uint8 * data, uint32 * out, uint32 * end)
274  {  {
275          while (out < end)          while (out < end)
276                  *(out++) = colmap[*(data++)];                  *(out++) = colmap[*(data++)];
277  }  }
278    
279    static void
280    translate16to32(uint16 * data, uint32 * out, uint32 * end)
281    {
282            while (out < end)
283                    *(out++) = translate_colour(*(data++));
284    }
285    
286  static uint8 *  static uint8 *
287  translate_image(int width, int height, uint8 * data)  translate_image(int width, int height, uint8 * data)
288  {  {
# Line 171  translate_image(int width, int height, u Line 290  translate_image(int width, int height, u
290          uint8 *out = xmalloc(size);          uint8 *out = xmalloc(size);
291          uint8 *end = out + size;          uint8 *end = out + size;
292    
293            if (server_bpp == 16)
294            {
295                    if (bpp == 16)
296                            translate16to16((uint16 *) data, (uint16 *) out, (uint16 *) end);
297                    else if (bpp == 24)
298                            translate16to24((uint16 *) data, out, end); /* todo, check this one */
299                    else if (bpp == 32)
300                            translate16to32((uint16 *) data, (uint32 *) out, (uint32 *) end);
301                    return out;
302            }
303            /* todo needs server_bpp == 24 */
304          switch (bpp)          switch (bpp)
305          {          {
306                  case 8:                  case 8:
307                          translate8(data, out, end);                          translate8to8(data, out, end);
308                          break;                          break;
309    
310                  case 16:                  case 16:
311                          translate16(data, (uint16 *) out, (uint16 *) end);                          translate8to16(data, (uint16 *) out, (uint16 *) end);
312                          break;                          break;
313    
314                  case 24:                  case 24:
315                          translate24(data, out, end);                          translate8to24(data, out, end);
316                          break;                          break;
317    
318                  case 32:                  case 32:
319                          translate32(data, (uint32 *) out, (uint32 *) end);                          translate8to32(data, (uint32 *) out, (uint32 *) end);
320                          break;                          break;
321          }          }
322    
323          return out;          return out;
324  }  }
325    
 #define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); }  
 #define BSWAP24(x) { x = (((x & 0xff) << 16) | (x >> 16) | ((x >> 8) & 0xff00)); }  
 #define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \  
                         x = (x << 16) | (x >> 16); }  
   
 static uint32  
 translate_colour(uint32 colour)  
 {  
         switch (bpp)  
         {  
                 case 16:  
                         if (host_be != xserver_be)  
                                 BSWAP16(colour);  
                         break;  
   
                 case 24:  
                         if (xserver_be)  
                                 BSWAP24(colour);  
                         break;  
   
                 case 32:  
                         if (host_be != xserver_be)  
                                 BSWAP32(colour);  
                         break;  
         }  
   
         return colour;  
 }  
   
326  BOOL  BOOL
327  get_key_state(unsigned int state, uint32 keysym)  get_key_state(unsigned int state, uint32 keysym)
328  {  {
# Line 288  ui_init(void) Line 389  ui_init(void)
389                  return False;                  return False;
390          }          }
391    
392          xcolmap = DefaultColormapOfScreen(screen);          if (owncolmap != True)
393            {
394                    xcolmap = DefaultColormapOfScreen(screen);
395                    if (depth <= 8)
396                            warning("Screen depth is 8 bits or lower: you may want to use -C for a private colourmap\n");
397            }
398    
399          gc = XCreateGC(display, RootWindowOfScreen(screen), 0, NULL);          gc = XCreateGC(display, RootWindowOfScreen(screen), 0, NULL);
400    
401          if (DoesBackingStore(screen) != Always)          if (DoesBackingStore(screen) != Always)
# Line 298  ui_init(void) Line 405  ui_init(void)
405          host_be = !(BOOL) (*(uint8 *) (&test));          host_be = !(BOOL) (*(uint8 *) (&test));
406          xserver_be = (ImageByteOrder(display) == MSBFirst);          xserver_be = (ImageByteOrder(display) == MSBFirst);
407    
408            if ((width == 0) || (height == 0))
409            {
410                    /* Fetch geometry from _NET_WORKAREA */
411                    uint32 x, y, cx, cy;
412    
413                    if (get_current_workarea(&x, &y, &cx, &cy) == 0)
414                    {
415                            width = cx;
416                            height = cy;
417                    }
418                    else
419                    {
420                            warning("Failed to get workarea: probably your window manager does not support extended hints\n");
421                            width = 800;
422                            height = 600;
423                    }
424            }
425    
426          if (fullscreen)          if (fullscreen)
427          {          {
428                  width = WidthOfScreen(screen);                  width = WidthOfScreen(screen);
# Line 421  ui_create_window(void) Line 546  ui_create_window(void)
546          focused = False;          focused = False;
547          mouse_in_wnd = False;          mouse_in_wnd = False;
548    
549            /* handle the WM_DELETE_WINDOW protocol */
550            protocol_atom = XInternAtom(display, "WM_PROTOCOLS", True);
551            kill_atom = XInternAtom(display, "WM_DELETE_WINDOW", True);
552            XSetWMProtocols(display, wnd, &kill_atom, 1);
553    
554          return True;          return True;
555  }  }
556    
# Line 458  xwin_toggle_fullscreen(void) Line 588  xwin_toggle_fullscreen(void)
588          }          }
589  }  }
590    
591  /* Process all events in Xlib queue */  /* Process all events in Xlib queue
592  static void     Returns 0 after user quit, 1 otherwise */
593    static int
594  xwin_process_events(void)  xwin_process_events(void)
595  {  {
596          XEvent xevent;          XEvent xevent;
# Line 487  xwin_process_events(void) Line 618  xwin_process_events(void)
618    
619                  switch (xevent.type)                  switch (xevent.type)
620                  {                  {
621                            case ClientMessage:
622                                    /* the window manager told us to quit */
623                                    if ((xevent.xclient.message_type == protocol_atom)
624                                        && (xevent.xclient.data.l[0] == kill_atom))
625                                            /* Quit */
626                                            return 0;
627                                    break;
628    
629                          case KeyPress:                          case KeyPress:
630                                  if (IC != NULL)                                  if (IC != NULL)
631                                          /* Multi_key compatible version */                                          /* Multi_key compatible version */
# Line 561  xwin_process_events(void) Line 700  xwin_process_events(void)
700                                  break;                                  break;
701    
702                          case MotionNotify:                          case MotionNotify:
703                                    if (fullscreen && !focused)
704                                            XSetInputFocus(display, wnd, RevertToPointerRoot,
705                                                           CurrentTime);
706                                  rdp_send_input(time(NULL), RDP_INPUT_MOUSE,                                  rdp_send_input(time(NULL), RDP_INPUT_MOUSE,
707                                                 MOUSE_FLAG_MOVE, xevent.xmotion.x, xevent.xmotion.y);                                                 MOUSE_FLAG_MOVE, xevent.xmotion.x, xevent.xmotion.y);
708                                  break;                                  break;
# Line 630  xwin_process_events(void) Line 772  xwin_process_events(void)
772    
773                  }                  }
774          }          }
775            /* Keep going */
776            return 1;
777  }  }
778    
779  void  /* Returns 0 after user quit, 1 otherwise */
780    int
781  ui_select(int rdp_socket)  ui_select(int rdp_socket)
782  {  {
783          int n = (rdp_socket > x_socket) ? rdp_socket + 1 : x_socket + 1;          int n = (rdp_socket > x_socket) ? rdp_socket + 1 : x_socket + 1;
# Line 643  ui_select(int rdp_socket) Line 788  ui_select(int rdp_socket)
788          while (True)          while (True)
789          {          {
790                  /* Process any events already waiting */                  /* Process any events already waiting */
791                  xwin_process_events();                  if (!xwin_process_events())
792                            /* User quit */
793                            return 0;
794    
795                  FD_ZERO(&rfds);                  FD_ZERO(&rfds);
796                  FD_SET(rdp_socket, &rfds);                  FD_SET(rdp_socket, &rfds);
# Line 659  ui_select(int rdp_socket) Line 806  ui_select(int rdp_socket)
806                  }                  }
807    
808                  if (FD_ISSET(rdp_socket, &rfds))                  if (FD_ISSET(rdp_socket, &rfds))
809                          return;                          return 1;
810          }          }
811  }  }
812    
# Line 676  ui_create_bitmap(int width, int height, Line 823  ui_create_bitmap(int width, int height,
823          Pixmap bitmap;          Pixmap bitmap;
824          uint8 *tdata;          uint8 *tdata;
825    
826          tdata = translate_image(width, height, data);          tdata = (owncolmap ? data : translate_image(width, height, data));
827          bitmap = XCreatePixmap(display, wnd, width, height, depth);          bitmap = XCreatePixmap(display, wnd, width, height, depth);
828          image = XCreateImage(display, visual, depth, ZPixmap, 0,          image = XCreateImage(display, visual, depth, ZPixmap, 0,
829                               (char *) tdata, width, height, 8, 0);                               (char *) tdata, width, height, server_bpp == 8 ? 8 : bpp, 0);
830    
831          XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height);          XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height);
832    
833          XFree(image);          XFree(image);
834          xfree(tdata);          if (!owncolmap)
835                    xfree(tdata);
836          return (HBITMAP) bitmap;          return (HBITMAP) bitmap;
837  }  }
838    
# Line 693  ui_paint_bitmap(int x, int y, int cx, in Line 841  ui_paint_bitmap(int x, int y, int cx, in
841  {  {
842          XImage *image;          XImage *image;
843          uint8 *tdata;          uint8 *tdata;
844            tdata = (owncolmap ? data : translate_image(width, height, data));
         tdata = translate_image(width, height, data);  
845          image = XCreateImage(display, visual, depth, ZPixmap, 0,          image = XCreateImage(display, visual, depth, ZPixmap, 0,
846                               (char *) tdata, width, height, 8, 0);                               (char *) tdata, width, height, server_bpp == 8 ? 8 : bpp, 0);
847    
848          if (ownbackstore)          if (ownbackstore)
849          {          {
# Line 709  ui_paint_bitmap(int x, int y, int cx, in Line 856  ui_paint_bitmap(int x, int y, int cx, in
856          }          }
857    
858          XFree(image);          XFree(image);
859          xfree(tdata);          if (!owncolmap)
860                    xfree(tdata);
861  }  }
862    
863  void  void
# Line 840  ui_destroy_cursor(HCURSOR cursor) Line 988  ui_destroy_cursor(HCURSOR cursor)
988                  (xc)->blue  = ((c)->blue  << 8) | (c)->blue; \                  (xc)->blue  = ((c)->blue  << 8) | (c)->blue; \
989                  (xc)->flags = DoRed | DoGreen | DoBlue;                  (xc)->flags = DoRed | DoGreen | DoBlue;
990    
991    
992  HCOLOURMAP  HCOLOURMAP
993  ui_create_colourmap(COLOURMAP * colours)  ui_create_colourmap(COLOURMAP * colours)
994  {  {
995          COLOURENTRY *entry;          COLOURENTRY *entry;
996          int i, ncolours = colours->ncolours;          int i, ncolours = colours->ncolours;
997          uint32 *map = xmalloc(sizeof(*colmap) * ncolours);          if (!owncolmap)
         XColor xentry;  
         XColor xc_cache[256];  
         uint32 colour;  
         int colLookup = 256;  
         for (i = 0; i < ncolours; i++)  
998          {          {
999                  entry = &colours->colours[i];                  uint32 *map = xmalloc(sizeof(*colmap) * ncolours);
1000                  MAKE_XCOLOR(&xentry, entry);                  XColor xentry;
1001                    XColor xc_cache[256];
1002                  if (XAllocColor(display, xcolmap, &xentry) == 0)                  uint32 colour;
1003                    int colLookup = 256;
1004                    for (i = 0; i < ncolours; i++)
1005                  {                  {
1006                          /* Allocation failed, find closest match. */                          entry = &colours->colours[i];
1007                          int j = 256;                          MAKE_XCOLOR(&xentry, entry);
                         int nMinDist = 3 * 256 * 256;  
                         long nDist = nMinDist;  
1008    
1009                          /* only get the colors once */                          if (XAllocColor(display, xcolmap, &xentry) == 0)
                         while (colLookup--)  
1010                          {                          {
1011                                  xc_cache[colLookup].pixel = colLookup;                                  /* Allocation failed, find closest match. */
1012                                  xc_cache[colLookup].red = xc_cache[colLookup].green =                                  int j = 256;
1013                                          xc_cache[colLookup].blue = 0;                                  int nMinDist = 3 * 256 * 256;
1014                                  xc_cache[colLookup].flags = 0;                                  long nDist = nMinDist;
                                 XQueryColor(display,  
                                             DefaultColormap(display, DefaultScreen(display)),  
                                             &xc_cache[colLookup]);  
                         }  
                         colLookup = 0;  
1015    
1016                          /* approximate the pixel */                                  /* only get the colors once */
1017                          while (j--)                                  while (colLookup--)
                         {  
                                 if (xc_cache[j].flags)  
1018                                  {                                  {
1019                                          nDist = ((long) (xc_cache[j].red >> 8) -                                          xc_cache[colLookup].pixel = colLookup;
1020                                                   (long) (xentry.red >> 8)) *                                          xc_cache[colLookup].red = xc_cache[colLookup].green =
1021                                                  ((long) (xc_cache[j].red >> 8) -                                                  xc_cache[colLookup].blue = 0;
1022                                                   (long) (xentry.red >> 8)) +                                          xc_cache[colLookup].flags = 0;
1023                                                  ((long) (xc_cache[j].green >> 8) -                                          XQueryColor(display,
1024                                                   (long) (xentry.green >> 8)) *                                                      DefaultColormap(display,
1025                                                  ((long) (xc_cache[j].green >> 8) -                                                                      DefaultScreen(display)),
1026                                                   (long) (xentry.green >> 8)) +                                                      &xc_cache[colLookup]);
                                                 ((long) (xc_cache[j].blue >> 8) -  
                                                  (long) (xentry.blue >> 8)) *  
                                                 ((long) (xc_cache[j].blue >> 8) -  
                                                  (long) (xentry.blue >> 8));  
1027                                  }                                  }
1028                                  if (nDist < nMinDist)                                  colLookup = 0;
1029    
1030                                    /* approximate the pixel */
1031                                    while (j--)
1032                                  {                                  {
1033                                          nMinDist = nDist;                                          if (xc_cache[j].flags)
1034                                          xentry.pixel = j;                                          {
1035                                                    nDist = ((long) (xc_cache[j].red >> 8) -
1036                                                             (long) (xentry.red >> 8)) *
1037                                                            ((long) (xc_cache[j].red >> 8) -
1038                                                             (long) (xentry.red >> 8)) +
1039                                                            ((long) (xc_cache[j].green >> 8) -
1040                                                             (long) (xentry.green >> 8)) *
1041                                                            ((long) (xc_cache[j].green >> 8) -
1042                                                             (long) (xentry.green >> 8)) +
1043                                                            ((long) (xc_cache[j].blue >> 8) -
1044                                                             (long) (xentry.blue >> 8)) *
1045                                                            ((long) (xc_cache[j].blue >> 8) -
1046                                                             (long) (xentry.blue >> 8));
1047                                            }
1048                                            if (nDist < nMinDist)
1049                                            {
1050                                                    nMinDist = nDist;
1051                                                    xentry.pixel = j;
1052                                            }
1053                                  }                                  }
1054                          }                          }
1055                            colour = xentry.pixel;
1056    
1057                            /* update our cache */
1058                            if (xentry.pixel < 256)
1059                            {
1060                                    xc_cache[xentry.pixel].red = xentry.red;
1061                                    xc_cache[xentry.pixel].green = xentry.green;
1062                                    xc_cache[xentry.pixel].blue = xentry.blue;
1063    
1064                            }
1065    
1066    
1067                            /* byte swap here to make translate_image faster */
1068                            map[i] = translate_colour(colour);
1069                  }                  }
1070                  colour = xentry.pixel;                  return map;
1071            }
1072            else
1073            {
1074                    XColor *xcolours, *xentry;
1075                    Colormap map;
1076    
1077                  /* update our cache */                  xcolours = xmalloc(sizeof(XColor) * ncolours);
1078                  if (xentry.pixel < 256)                  for (i = 0; i < ncolours; i++)
1079                  {                  {
1080                          xc_cache[xentry.pixel].red = xentry.red;                          entry = &colours->colours[i];
1081                          xc_cache[xentry.pixel].green = xentry.green;                          xentry = &xcolours[i];
1082                          xc_cache[xentry.pixel].blue = xentry.blue;                          xentry->pixel = i;
1083                            MAKE_XCOLOR(xentry, entry);
1084                  }                  }
1085    
1086                    map = XCreateColormap(display, wnd, visual, AllocAll);
1087                    XStoreColors(display, map, xcolours, ncolours);
1088    
1089                  /* byte swap here to make translate_image faster */                  xfree(xcolours);
1090                  map[i] = translate_colour(colour);                  return (HCOLOURMAP) map;
1091          }          }
   
         return map;  
1092  }  }
1093    
1094  void  void
1095  ui_destroy_colourmap(HCOLOURMAP map)  ui_destroy_colourmap(HCOLOURMAP map)
1096  {  {
1097          xfree(map);          if (!owncolmap)
1098                    xfree(map);
1099            else
1100                    XFreeColormap(display, (Colormap) map);
1101  }  }
1102    
1103  void  void
1104  ui_set_colourmap(HCOLOURMAP map)  ui_set_colourmap(HCOLOURMAP map)
1105  {  {
1106          colmap = map;          if (!owncolmap)
1107                    colmap = map;
1108            else
1109                    XSetWindowColormap(display, wnd, (Colormap) map);
1110  }  }
1111    
1112  void  void
# Line 1091  ui_rect( Line 1269  ui_rect(
1269          FILL_RECTANGLE(x, y, cx, cy);          FILL_RECTANGLE(x, y, cx, cy);
1270  }  }
1271    
1272    /* warning, this function only draws on wnd or backstore, not both */
1273  void  void
1274  ui_draw_glyph(int mixmode,  ui_draw_glyph(int mixmode,
1275                /* dest */ int x, int y, int cx, int cy,                /* dest */ int x, int y, int cx, int cy,
# Line 1105  ui_draw_glyph(int mixmode, Line 1284  ui_draw_glyph(int mixmode,
1284          XSetStipple(display, gc, (Pixmap) glyph);          XSetStipple(display, gc, (Pixmap) glyph);
1285          XSetTSOrigin(display, gc, x, y);          XSetTSOrigin(display, gc, x, y);
1286    
1287          FILL_RECTANGLE(x, y, cx, cy);          FILL_RECTANGLE_BACKSTORE(x, y, cx, cy);
1288    
1289          XSetFillStyle(display, gc, FillSolid);          XSetFillStyle(display, gc, FillSolid);
1290  }  }
# Line 1134  ui_draw_glyph(int mixmode, Line 1313  ui_draw_glyph(int mixmode,
1313      }\      }\
1314    if (glyph != NULL)\    if (glyph != NULL)\
1315      {\      {\
1316        ui_draw_glyph (mixmode, x + (short) glyph->offset,\        ui_draw_glyph (mixmode, x + glyph->offset,\
1317                       y + (short) glyph->baseline,\                       y + glyph->baseline,\
1318                       glyph->width, glyph->height,\                       glyph->width, glyph->height,\
1319                       glyph->pixmap, 0, 0, bgcolour, fgcolour);\                       glyph->pixmap, 0, 0, bgcolour, fgcolour);\
1320        if (flags & TEXT2_IMPLICIT_X)\        if (flags & TEXT2_IMPLICIT_X)\
# Line 1157  ui_draw_text(uint8 font, uint8 flags, in Line 1336  ui_draw_text(uint8 font, uint8 flags, in
1336    
1337          if (boxcx > 1)          if (boxcx > 1)
1338          {          {
1339                  FILL_RECTANGLE(boxx, boxy, boxcx, boxcy);                  FILL_RECTANGLE_BACKSTORE(boxx, boxy, boxcx, boxcy);
1340          }          }
1341          else if (mixmode == MIX_OPAQUE)          else if (mixmode == MIX_OPAQUE)
1342          {          {
1343                  FILL_RECTANGLE(clipx, clipy, clipcx, clipcy);                  FILL_RECTANGLE_BACKSTORE(clipx, clipy, clipcx, clipcy);
1344          }          }
1345    
1346          /* Paint text, character by character */          /* Paint text, character by character */
# Line 1175  ui_draw_text(uint8 font, uint8 flags, in Line 1354  ui_draw_text(uint8 font, uint8 flags, in
1354                                  else                                  else
1355                                  {                                  {
1356                                          error("this shouldn't be happening\n");                                          error("this shouldn't be happening\n");
1357                                          break;                                          exit(1);
1358                                  }                                  }
1359                                  /* this will move pointer from start to first character after FF command */                                  /* this will move pointer from start to first character after FF command */
1360                                  length -= i + 3;                                  length -= i + 3;
# Line 1195  ui_draw_text(uint8 font, uint8 flags, in Line 1374  ui_draw_text(uint8 font, uint8 flags, in
1374                                                  else                                                  else
1375                                                          x += text[i + 2];                                                          x += text[i + 2];
1376                                          }                                          }
                                         if (i + 2 < length)  
                                                 i += 3;  
                                         else  
                                                 i += 2;  
                                         length -= i;  
                                         /* this will move pointer from start to first character after FE command */  
                                         text = &(text[i]);  
                                         i = 0;  
1377                                          for (j = 0; j < entry->size; j++)                                          for (j = 0; j < entry->size; j++)
1378                                                  DO_GLYPH(((uint8 *) (entry->data)), j);                                                  DO_GLYPH(((uint8 *) (entry->data)), j);
1379                                  }                                  }
1380                                    if (i + 2 < length)
1381                                            i += 3;
1382                                    else
1383                                            i += 2;
1384                                    length -= i;
1385                                    /* this will move pointer from start to first character after FE command */
1386                                    text = &(text[i]);
1387                                    i = 0;
1388                                  break;                                  break;
1389    
1390                          default:                          default:
# Line 1214  ui_draw_text(uint8 font, uint8 flags, in Line 1393  ui_draw_text(uint8 font, uint8 flags, in
1393                                  break;                                  break;
1394                  }                  }
1395          }          }
1396            if (ownbackstore)
1397            {
1398                    if (boxcx > 1)
1399                            XCopyArea(display, backstore, wnd, gc, boxx,
1400                                      boxy, boxcx, boxcy, boxx, boxy);
1401                    else
1402                            XCopyArea(display, backstore, wnd, gc, clipx,
1403                                      clipy, clipcx, clipcy, clipx, clipy);
1404            }
1405  }  }
1406    
1407  void  void

Legend:
Removed from v.262  
changed lines
  Added in v.311

  ViewVC Help
Powered by ViewVC 1.1.26