/[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 316 by jsorg71, Sun Feb 9 17:17:37 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    
74    typedef struct
75    {
76            uint32 red;
77            uint32 green;
78            uint32 blue;
79    }
80    PixelColour;
81    
82  #define FILL_RECTANGLE(x,y,cx,cy)\  #define FILL_RECTANGLE(x,y,cx,cy)\
83  { \  { \
# Line 77  PropMotifWmHints; Line 86  PropMotifWmHints;
86                  XFillRectangle(display, backstore, gc, x, y, cx, cy); \                  XFillRectangle(display, backstore, gc, x, y, cx, cy); \
87  }  }
88    
89    #define FILL_RECTANGLE_BACKSTORE(x,y,cx,cy)\
90    { \
91            XFillRectangle(display, ownbackstore ? backstore : wnd, gc, x, y, cx, cy); \
92    }
93    
94  /* colour maps */  /* colour maps */
95    BOOL owncolmap = False;
96  static Colormap xcolmap;  static Colormap xcolmap;
97  static uint32 *colmap;  static uint32 *colmap;
98    
99  #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]) )
100  #define SET_BACKGROUND(col)     XSetBackground(display, gc, translate_colour(colmap[col]));  #define SET_FOREGROUND(col)     XSetForeground(display, gc, TRANSLATE(col));
101    #define SET_BACKGROUND(col)     XSetBackground(display, gc, TRANSLATE(col));
102    
103  static int rop2_map[] = {  static int rop2_map[] = {
104          GXclear,                /* 0 */          GXclear,                /* 0 */
# Line 120  mwm_hide_decorations(void) Line 136  mwm_hide_decorations(void)
136          hintsatom = XInternAtom(display, "_MOTIF_WM_HINTS", False);          hintsatom = XInternAtom(display, "_MOTIF_WM_HINTS", False);
137          if (!hintsatom)          if (!hintsatom)
138          {          {
139                  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");
140                  return;                  return;
141          }          }
142    
# Line 128  mwm_hide_decorations(void) Line 144  mwm_hide_decorations(void)
144                          (unsigned char *) &motif_hints, PROP_MOTIF_WM_HINTS_ELEMENTS);                          (unsigned char *) &motif_hints, PROP_MOTIF_WM_HINTS_ELEMENTS);
145  }  }
146    
147    PixelColour
148    split_colour15(uint32 colour)
149    {
150            PixelColour rv;
151            rv.red = (colour & 0x7c00) >> 10;
152            rv.red = (rv.red * 0xff) / 0x1f;
153            rv.green = (colour & 0x03e0) >> 5;
154            rv.green = (rv.green * 0xff) / 0x1f;
155            rv.blue = (colour & 0x1f);
156            rv.blue = (rv.blue * 0xff) / 0x1f;
157            return rv;
158    }
159    
160    PixelColour
161    split_colour16(uint32 colour)
162    {
163            PixelColour rv;
164            rv.red = (colour & 0xf800) >> 11;
165            rv.red = (rv.red * 0xff) / 0x1f;
166            rv.green = (colour & 0x07e0) >> 5;
167            rv.green = (rv.green * 0xff) / 0x3f;
168            rv.blue = (colour & 0x001f);
169            rv.blue = (rv.blue * 0xff) / 0x1f;
170            return rv;
171    }
172    
173    PixelColour
174    split_colour24(uint32 colour)
175    {
176            PixelColour rv;
177            rv.blue = (colour & 0xff0000) >> 16;
178            rv.green = (colour & 0xff00) >> 8;
179            rv.red = (colour & 0xff);
180            return rv;
181    }
182    
183    uint32 make_colour16(PixelColour pc)
184    {
185            pc.red = (pc.red * 0x1f) / 0xff;
186            pc.green = (pc.green * 0x3f) / 0xff;
187            pc.blue = (pc.blue * 0x1f) / 0xff;
188            return (pc.red << 11) | (pc.green << 5) | pc.blue;
189    }
190    
191    uint32 make_colour24(PixelColour pc)
192    {
193            return (pc.red << 16) | (pc.green << 8) | pc.blue;
194    }
195    
196    uint32 make_colour32(PixelColour pc)
197    {
198            return (pc.red << 16) | (pc.green << 8) | pc.blue;
199    }
200    
201    #define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); }
202    #define BSWAP24(x) { x = (((x & 0xff) << 16) | (x >> 16) | ((x >> 8) & 0xff00)); }
203    #define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \
204                            x = (x << 16) | (x >> 16); }
205    
206    static uint32
207    translate_colour(uint32 colour)
208    {
209            switch (server_bpp)
210            {
211                    case 15:
212                            switch (bpp)
213                            {
214                                    case 16:
215                                            colour = make_colour16(split_colour15(colour));
216                                            break;
217                                    case 24:
218                                            colour = make_colour24(split_colour15(colour));
219                                            break;
220                                    case 32:
221                                            colour = make_colour32(split_colour15(colour));
222                                            break;
223                            }
224                            break;
225                    case 16:
226                            switch (bpp)
227                            {
228                                    case 16:
229                                            break;
230                                    case 24:
231                                            colour = make_colour24(split_colour16(colour));
232                                            break;
233                                    case 32:
234                                            colour = make_colour32(split_colour16(colour));
235                                            break;
236                            }
237                            break;
238                    case 24:
239                            switch (bpp)
240                            {
241                                    case 16:
242                                            colour = make_colour16(split_colour24(colour));
243                                            break;
244                                    case 24:
245                                            break;
246                                    case 32:
247                                            colour = make_colour32(split_colour24(colour));
248                                            break;
249                            }
250                            break;
251            }
252            switch (bpp)
253            {
254                    case 16:
255                            if (host_be != xserver_be)
256                                    BSWAP16(colour);
257                            break;
258    
259                    case 24:
260                            if (xserver_be)
261                                    BSWAP24(colour);
262                            break;
263    
264                    case 32:
265                            if (host_be != xserver_be)
266                                    BSWAP32(colour);
267                            break;
268            }
269    
270            return colour;
271    }
272    
273  static void  static void
274  translate8(uint8 * data, uint8 * out, uint8 * end)  translate8to8(uint8 * data, uint8 * out, uint8 * end)
275  {  {
276          while (out < end)          while (out < end)
277                  *(out++) = (uint8) colmap[*(data++)];                  *(out++) = (uint8) colmap[*(data++)];
278  }  }
279    
280  static void  static void
281  translate16(uint8 * data, uint16 * out, uint16 * end)  translate8to16(uint8 * data, uint16 * out, uint16 * end)
282  {  {
283          while (out < end)          while (out < end)
284                  *(out++) = (uint16) colmap[*(data++)];                  *(out++) = (uint16) colmap[*(data++)];
# Line 144  translate16(uint8 * data, uint16 * out, Line 286  translate16(uint8 * data, uint16 * out,
286    
287  /* little endian - conversion happens when colourmap is built */  /* little endian - conversion happens when colourmap is built */
288  static void  static void
289  translate24(uint8 * data, uint8 * out, uint8 * end)  translate8to24(uint8 * data, uint8 * out, uint8 * end)
290  {  {
291          uint32 value;          uint32 value;
292    
# Line 158  translate24(uint8 * data, uint8 * out, u Line 300  translate24(uint8 * data, uint8 * out, u
300  }  }
301    
302  static void  static void
303  translate32(uint8 * data, uint32 * out, uint32 * end)  translate8to32(uint8 * data, uint32 * out, uint32 * end)
304  {  {
305          while (out < end)          while (out < end)
306                  *(out++) = colmap[*(data++)];                  *(out++) = colmap[*(data++)];
307  }  }
308    
309  static uint8 *  /* todo the remaining translate function might need some big endian check ?? */
310  translate_image(int width, int height, uint8 * data)  
311    static void
312    translate15to16(uint16 * data, uint16 * out, uint16 * end)
313  {  {
314          int size = width * height * bpp / 8;          while (out < end)
315          uint8 *out = xmalloc(size);                  *(out++) = (uint16) make_colour16(split_colour15(*(data++)));
316          uint8 *end = out + size;  }
317    
318          switch (bpp)  static void
319    translate15to24(uint16 * data, uint8 * out, uint8 * end)
320    {
321            uint32 value;
322    
323            while (out < end)
324          {          {
325                  case 8:                  value = make_colour24(split_colour15(*(data++)));
326                          translate8(data, out, end);                  *(out++) = value;
327                          break;                  *(out++) = value >> 8;
328                    *(out++) = value >> 16;
329            }
330    }
331    
332                  case 16:  static void
333                          translate16(data, (uint16 *) out, (uint16 *) end);  translate15to32(uint16 * data, uint32 * out, uint32 * end)
334                          break;  {
335            while (out < end)
336                    *(out++) = make_colour32(split_colour15(*(data++)));
337    }
338    
339                  case 24:  static void
340                          translate24(data, out, end);  translate16to16(uint16 * data, uint16 * out, uint16 * end)
341                          break;  {
342            while (out < end)
343                    *(out++) = (uint16) (*(data++));
344    }
345    
346                  case 32:  
347                          translate32(data, (uint32 *) out, (uint32 *) end);  static void
348                          break;  translate16to24(uint16 * data, uint8 * out, uint8 * end)
349    {
350            uint32 value;
351    
352            while (out < end)
353            {
354                    value = make_colour24(split_colour16(*(data++)));
355                    *(out++) = value;
356                    *(out++) = value >> 8;
357                    *(out++) = value >> 16;
358          }          }
359    }
360    
361          return out;  static void
362    translate16to32(uint16 * data, uint32 * out, uint32 * end)
363    {
364            while (out < end)
365                    *(out++) = make_colour32(split_colour16(*(data++)));
366  }  }
367    
368  #define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); }  static void
369  #define BSWAP24(x) { x = (((x & 0xff) << 16) | (x >> 16) | ((x >> 8) & 0xff00)); }  translate24to16(uint8 * data, uint16 * out, uint16 * end)
370  #define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \  {
371                          x = (x << 16) | (x >> 16); }          uint32 pixel = 0;
372            while (out < end)
373            {
374                    pixel = *(data++) << 16;
375                    pixel |= *(data++) << 8;
376                    pixel |= *(data++);
377                    *(out++) = (uint16) make_colour16(split_colour24(pixel));
378            }
379    }
380    
381  static uint32  static void
382  translate_colour(uint32 colour)  translate24to24(uint8 * data, uint8 * out, uint8 * end)
383  {  {
384          switch (bpp)          while (out < end)
385          {          {
386                  case 16:                  *(out++) = (*(data++));
387                          if (host_be != xserver_be)          }
388                                  BSWAP16(colour);  }
389                          break;  
390    static void
391    translate24to32(uint8 * data, uint32 * out, uint32 * end)
392    {
393            uint32 pixel = 0;
394            while (out < end)
395            {
396                    memcpy(&pixel, data, 3);
397                    data += 3;
398                    *(out++) = pixel;
399            }
400    }
401    
402    static uint8 *
403    translate_image(int width, int height, uint8 * data)
404    {
405            int size = width * height * bpp / 8;
406            uint8 *out = xmalloc(size);
407            uint8 *end = out + size;
408    
409            switch (server_bpp)
410            {
411                  case 24:                  case 24:
412                          if (xserver_be)                          switch (bpp)
413                                  BSWAP24(colour);                          {
414                                    case 32:
415                                            translate24to32(data, (uint32 *) out, (uint32 *) end);
416                                            break;
417                                    case 24:
418                                            translate24to24(data, out, end);
419                                            break;
420                                    case 16:
421                                            translate24to16(data, (uint16 *) out, (uint16 *) end);
422                                            break;
423                            }
424                          break;                          break;
425                    case 16:
426                  case 32:                          switch (bpp)
427                          if (host_be != xserver_be)                          {
428                                  BSWAP32(colour);                                  case 32:
429                                            translate16to32((uint16 *) data, (uint32 *) out, (uint32 *) end);
430                                            break;
431                                    case 24:
432                                            translate16to24((uint16 *) data, out, end);
433                                            break;
434                                    case 16:
435                                            translate16to16((uint16 *) data, (uint16 *) out, (uint16 *) end);
436                                            break;
437                            }
438                            break;
439                    case 15:
440                            switch (bpp)
441                            {
442                                    case 32:
443                                            translate15to32((uint16 *) data, (uint32 *) out, (uint32 *) end);
444                                            break;
445                                    case 24:
446                                            translate15to24((uint16 *) data, out, end);
447                                            break;
448                                    case 16:
449                                            translate15to16((uint16 *) data, (uint16 *) out, (uint16 *) end);
450                                            break;
451                            }
452                            break;
453                    case 8:
454                            switch (bpp)
455                            {
456                                    case 8:
457                                            translate8to8(data, out, end);
458                                            break;
459                                    case 16:
460                                            translate8to16(data, (uint16 *) out, (uint16 *) end);
461                                            break;
462                                    case 24:
463                                            translate8to24(data, out, end);
464                                            break;
465                                    case 32:
466                                            translate8to32(data, (uint32 *) out, (uint32 *) end);
467                                            break;
468                            }
469                          break;                          break;
470          }          }
471            return out;
         return colour;  
472  }  }
473    
474  BOOL  BOOL
# Line 288  ui_init(void) Line 537  ui_init(void)
537                  return False;                  return False;
538          }          }
539    
540          xcolmap = DefaultColormapOfScreen(screen);          if (owncolmap != True)
541            {
542                    xcolmap = DefaultColormapOfScreen(screen);
543                    if (depth <= 8)
544                            warning("Screen depth is 8 bits or lower: you may want to use -C for a private colourmap\n");
545            }
546    
547          gc = XCreateGC(display, RootWindowOfScreen(screen), 0, NULL);          gc = XCreateGC(display, RootWindowOfScreen(screen), 0, NULL);
548    
549          if (DoesBackingStore(screen) != Always)          if (DoesBackingStore(screen) != Always)
# Line 298  ui_init(void) Line 553  ui_init(void)
553          host_be = !(BOOL) (*(uint8 *) (&test));          host_be = !(BOOL) (*(uint8 *) (&test));
554          xserver_be = (ImageByteOrder(display) == MSBFirst);          xserver_be = (ImageByteOrder(display) == MSBFirst);
555    
556            if ((width == 0) || (height == 0))
557            {
558                    /* Fetch geometry from _NET_WORKAREA */
559                    uint32 x, y, cx, cy;
560    
561                    if (get_current_workarea(&x, &y, &cx, &cy) == 0)
562                    {
563                            width = cx;
564                            height = cy;
565                    }
566                    else
567                    {
568                            warning("Failed to get workarea: probably your window manager does not support extended hints\n");
569                            width = 800;
570                            height = 600;
571                    }
572            }
573    
574          if (fullscreen)          if (fullscreen)
575          {          {
576                  width = WidthOfScreen(screen);                  width = WidthOfScreen(screen);
# Line 323  ui_init(void) Line 596  ui_init(void)
596                  IM = XOpenIM(display, NULL, NULL, NULL);                  IM = XOpenIM(display, NULL, NULL, NULL);
597    
598          xkeymap_init();          xkeymap_init();
599    
600            /* todo take this out when high colour is done */
601            printf("server bpp %d client bpp %d depth %d\n", server_bpp, bpp, depth);
602    
603          return True;          return True;
604  }  }
605    
# Line 421  ui_create_window(void) Line 698  ui_create_window(void)
698          focused = False;          focused = False;
699          mouse_in_wnd = False;          mouse_in_wnd = False;
700    
701            /* handle the WM_DELETE_WINDOW protocol */
702            protocol_atom = XInternAtom(display, "WM_PROTOCOLS", True);
703            kill_atom = XInternAtom(display, "WM_DELETE_WINDOW", True);
704            XSetWMProtocols(display, wnd, &kill_atom, 1);
705    
706          return True;          return True;
707  }  }
708    
# Line 458  xwin_toggle_fullscreen(void) Line 740  xwin_toggle_fullscreen(void)
740          }          }
741  }  }
742    
743  /* Process all events in Xlib queue */  /* Process all events in Xlib queue
744  static void     Returns 0 after user quit, 1 otherwise */
745    static int
746  xwin_process_events(void)  xwin_process_events(void)
747  {  {
748          XEvent xevent;          XEvent xevent;
# Line 487  xwin_process_events(void) Line 770  xwin_process_events(void)
770    
771                  switch (xevent.type)                  switch (xevent.type)
772                  {                  {
773                            case ClientMessage:
774                                    /* the window manager told us to quit */
775                                    if ((xevent.xclient.message_type == protocol_atom)
776                                        && (xevent.xclient.data.l[0] == kill_atom))
777                                            /* Quit */
778                                            return 0;
779                                    break;
780    
781                          case KeyPress:                          case KeyPress:
782                                  if (IC != NULL)                                  if (IC != NULL)
783                                          /* Multi_key compatible version */                                          /* Multi_key compatible version */
# Line 561  xwin_process_events(void) Line 852  xwin_process_events(void)
852                                  break;                                  break;
853    
854                          case MotionNotify:                          case MotionNotify:
855                                    if (fullscreen && !focused)
856                                            XSetInputFocus(display, wnd, RevertToPointerRoot,
857                                                           CurrentTime);
858                                  rdp_send_input(time(NULL), RDP_INPUT_MOUSE,                                  rdp_send_input(time(NULL), RDP_INPUT_MOUSE,
859                                                 MOUSE_FLAG_MOVE, xevent.xmotion.x, xevent.xmotion.y);                                                 MOUSE_FLAG_MOVE, xevent.xmotion.x, xevent.xmotion.y);
860                                  break;                                  break;
# Line 630  xwin_process_events(void) Line 924  xwin_process_events(void)
924    
925                  }                  }
926          }          }
927            /* Keep going */
928            return 1;
929  }  }
930    
931  void  /* Returns 0 after user quit, 1 otherwise */
932    int
933  ui_select(int rdp_socket)  ui_select(int rdp_socket)
934  {  {
935          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 940  ui_select(int rdp_socket)
940          while (True)          while (True)
941          {          {
942                  /* Process any events already waiting */                  /* Process any events already waiting */
943                  xwin_process_events();                  if (!xwin_process_events())
944                            /* User quit */
945                            return 0;
946    
947                  FD_ZERO(&rfds);                  FD_ZERO(&rfds);
948                  FD_SET(rdp_socket, &rfds);                  FD_SET(rdp_socket, &rfds);
# Line 659  ui_select(int rdp_socket) Line 958  ui_select(int rdp_socket)
958                  }                  }
959    
960                  if (FD_ISSET(rdp_socket, &rfds))                  if (FD_ISSET(rdp_socket, &rfds))
961                          return;                          return 1;
962          }          }
963  }  }
964    
# Line 676  ui_create_bitmap(int width, int height, Line 975  ui_create_bitmap(int width, int height,
975          Pixmap bitmap;          Pixmap bitmap;
976          uint8 *tdata;          uint8 *tdata;
977    
978          tdata = translate_image(width, height, data);          tdata = (owncolmap ? data : translate_image(width, height, data));
979          bitmap = XCreatePixmap(display, wnd, width, height, depth);          bitmap = XCreatePixmap(display, wnd, width, height, depth);
980          image = XCreateImage(display, visual, depth, ZPixmap, 0,          image = XCreateImage(display, visual, depth, ZPixmap, 0,
981                               (char *) tdata, width, height, 8, 0);                               (char *) tdata, width, height, server_bpp == 8 ? 8 : bpp, 0);
982    
983          XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height);          XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height);
984    
985          XFree(image);          XFree(image);
986          xfree(tdata);          if (!owncolmap)
987                    xfree(tdata);
988          return (HBITMAP) bitmap;          return (HBITMAP) bitmap;
989  }  }
990    
# Line 693  ui_paint_bitmap(int x, int y, int cx, in Line 993  ui_paint_bitmap(int x, int y, int cx, in
993  {  {
994          XImage *image;          XImage *image;
995          uint8 *tdata;          uint8 *tdata;
996            tdata = (owncolmap ? data : translate_image(width, height, data));
         tdata = translate_image(width, height, data);  
997          image = XCreateImage(display, visual, depth, ZPixmap, 0,          image = XCreateImage(display, visual, depth, ZPixmap, 0,
998                               (char *) tdata, width, height, 8, 0);                               (char *) tdata, width, height, server_bpp == 8 ? 8 : bpp, 0);
999    
1000          if (ownbackstore)          if (ownbackstore)
1001          {          {
# Line 709  ui_paint_bitmap(int x, int y, int cx, in Line 1008  ui_paint_bitmap(int x, int y, int cx, in
1008          }          }
1009    
1010          XFree(image);          XFree(image);
1011          xfree(tdata);          if (!owncolmap)
1012                    xfree(tdata);
1013  }  }
1014    
1015  void  void
# Line 840  ui_destroy_cursor(HCURSOR cursor) Line 1140  ui_destroy_cursor(HCURSOR cursor)
1140                  (xc)->blue  = ((c)->blue  << 8) | (c)->blue; \                  (xc)->blue  = ((c)->blue  << 8) | (c)->blue; \
1141                  (xc)->flags = DoRed | DoGreen | DoBlue;                  (xc)->flags = DoRed | DoGreen | DoBlue;
1142    
1143    
1144  HCOLOURMAP  HCOLOURMAP
1145  ui_create_colourmap(COLOURMAP * colours)  ui_create_colourmap(COLOURMAP * colours)
1146  {  {
1147          COLOURENTRY *entry;          COLOURENTRY *entry;
1148          int i, ncolours = colours->ncolours;          int i, ncolours = colours->ncolours;
1149          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++)  
1150          {          {
1151                  entry = &colours->colours[i];                  uint32 *map = xmalloc(sizeof(*colmap) * ncolours);
1152                  MAKE_XCOLOR(&xentry, entry);                  XColor xentry;
1153                    XColor xc_cache[256];
1154                  if (XAllocColor(display, xcolmap, &xentry) == 0)                  uint32 colour;
1155                    int colLookup = 256;
1156                    for (i = 0; i < ncolours; i++)
1157                  {                  {
1158                          /* Allocation failed, find closest match. */                          entry = &colours->colours[i];
1159                          int j = 256;                          MAKE_XCOLOR(&xentry, entry);
                         int nMinDist = 3 * 256 * 256;  
                         long nDist = nMinDist;  
1160    
1161                          /* only get the colors once */                          if (XAllocColor(display, xcolmap, &xentry) == 0)
                         while (colLookup--)  
1162                          {                          {
1163                                  xc_cache[colLookup].pixel = colLookup;                                  /* Allocation failed, find closest match. */
1164                                  xc_cache[colLookup].red = xc_cache[colLookup].green =                                  int j = 256;
1165                                          xc_cache[colLookup].blue = 0;                                  int nMinDist = 3 * 256 * 256;
1166                                  xc_cache[colLookup].flags = 0;                                  long nDist = nMinDist;
                                 XQueryColor(display,  
                                             DefaultColormap(display, DefaultScreen(display)),  
                                             &xc_cache[colLookup]);  
                         }  
                         colLookup = 0;  
1167    
1168                          /* approximate the pixel */                                  /* only get the colors once */
1169                          while (j--)                                  while (colLookup--)
                         {  
                                 if (xc_cache[j].flags)  
1170                                  {                                  {
1171                                          nDist = ((long) (xc_cache[j].red >> 8) -                                          xc_cache[colLookup].pixel = colLookup;
1172                                                   (long) (xentry.red >> 8)) *                                          xc_cache[colLookup].red = xc_cache[colLookup].green =
1173                                                  ((long) (xc_cache[j].red >> 8) -                                                  xc_cache[colLookup].blue = 0;
1174                                                   (long) (xentry.red >> 8)) +                                          xc_cache[colLookup].flags = 0;
1175                                                  ((long) (xc_cache[j].green >> 8) -                                          XQueryColor(display,
1176                                                   (long) (xentry.green >> 8)) *                                                      DefaultColormap(display,
1177                                                  ((long) (xc_cache[j].green >> 8) -                                                                      DefaultScreen(display)),
1178                                                   (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));  
1179                                  }                                  }
1180                                  if (nDist < nMinDist)                                  colLookup = 0;
1181    
1182                                    /* approximate the pixel */
1183                                    while (j--)
1184                                  {                                  {
1185                                          nMinDist = nDist;                                          if (xc_cache[j].flags)
1186                                          xentry.pixel = j;                                          {
1187                                                    nDist = ((long) (xc_cache[j].red >> 8) -
1188                                                             (long) (xentry.red >> 8)) *
1189                                                            ((long) (xc_cache[j].red >> 8) -
1190                                                             (long) (xentry.red >> 8)) +
1191                                                            ((long) (xc_cache[j].green >> 8) -
1192                                                             (long) (xentry.green >> 8)) *
1193                                                            ((long) (xc_cache[j].green >> 8) -
1194                                                             (long) (xentry.green >> 8)) +
1195                                                            ((long) (xc_cache[j].blue >> 8) -
1196                                                             (long) (xentry.blue >> 8)) *
1197                                                            ((long) (xc_cache[j].blue >> 8) -
1198                                                             (long) (xentry.blue >> 8));
1199                                            }
1200                                            if (nDist < nMinDist)
1201                                            {
1202                                                    nMinDist = nDist;
1203                                                    xentry.pixel = j;
1204                                            }
1205                                  }                                  }
1206                          }                          }
1207                            colour = xentry.pixel;
1208    
1209                            /* update our cache */
1210                            if (xentry.pixel < 256)
1211                            {
1212                                    xc_cache[xentry.pixel].red = xentry.red;
1213                                    xc_cache[xentry.pixel].green = xentry.green;
1214                                    xc_cache[xentry.pixel].blue = xentry.blue;
1215    
1216                            }
1217    
1218    
1219                            /* byte swap here to make translate_image faster */
1220                            map[i] = translate_colour(colour);
1221                  }                  }
1222                  colour = xentry.pixel;                  return map;
1223            }
1224            else
1225            {
1226                    XColor *xcolours, *xentry;
1227                    Colormap map;
1228    
1229                  /* update our cache */                  xcolours = xmalloc(sizeof(XColor) * ncolours);
1230                  if (xentry.pixel < 256)                  for (i = 0; i < ncolours; i++)
1231                  {                  {
1232                          xc_cache[xentry.pixel].red = xentry.red;                          entry = &colours->colours[i];
1233                          xc_cache[xentry.pixel].green = xentry.green;                          xentry = &xcolours[i];
1234                          xc_cache[xentry.pixel].blue = xentry.blue;                          xentry->pixel = i;
1235                            MAKE_XCOLOR(xentry, entry);
1236                  }                  }
1237    
1238                    map = XCreateColormap(display, wnd, visual, AllocAll);
1239                    XStoreColors(display, map, xcolours, ncolours);
1240    
1241                  /* byte swap here to make translate_image faster */                  xfree(xcolours);
1242                  map[i] = translate_colour(colour);                  return (HCOLOURMAP) map;
1243          }          }
   
         return map;  
1244  }  }
1245    
1246  void  void
1247  ui_destroy_colourmap(HCOLOURMAP map)  ui_destroy_colourmap(HCOLOURMAP map)
1248  {  {
1249          xfree(map);          if (!owncolmap)
1250                    xfree(map);
1251            else
1252                    XFreeColormap(display, (Colormap) map);
1253  }  }
1254    
1255  void  void
1256  ui_set_colourmap(HCOLOURMAP map)  ui_set_colourmap(HCOLOURMAP map)
1257  {  {
1258          colmap = map;          if (!owncolmap)
1259                    colmap = map;
1260            else
1261                    XSetWindowColormap(display, wnd, (Colormap) map);
1262  }  }
1263    
1264  void  void
# Line 1091  ui_rect( Line 1421  ui_rect(
1421          FILL_RECTANGLE(x, y, cx, cy);          FILL_RECTANGLE(x, y, cx, cy);
1422  }  }
1423    
1424    /* warning, this function only draws on wnd or backstore, not both */
1425  void  void
1426  ui_draw_glyph(int mixmode,  ui_draw_glyph(int mixmode,
1427                /* 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 1436  ui_draw_glyph(int mixmode,
1436          XSetStipple(display, gc, (Pixmap) glyph);          XSetStipple(display, gc, (Pixmap) glyph);
1437          XSetTSOrigin(display, gc, x, y);          XSetTSOrigin(display, gc, x, y);
1438    
1439          FILL_RECTANGLE(x, y, cx, cy);          FILL_RECTANGLE_BACKSTORE(x, y, cx, cy);
1440    
1441          XSetFillStyle(display, gc, FillSolid);          XSetFillStyle(display, gc, FillSolid);
1442  }  }
# Line 1134  ui_draw_glyph(int mixmode, Line 1465  ui_draw_glyph(int mixmode,
1465      }\      }\
1466    if (glyph != NULL)\    if (glyph != NULL)\
1467      {\      {\
1468        ui_draw_glyph (mixmode, x + (short) glyph->offset,\        ui_draw_glyph (mixmode, x + glyph->offset,\
1469                       y + (short) glyph->baseline,\                       y + glyph->baseline,\
1470                       glyph->width, glyph->height,\                       glyph->width, glyph->height,\
1471                       glyph->pixmap, 0, 0, bgcolour, fgcolour);\                       glyph->pixmap, 0, 0, bgcolour, fgcolour);\
1472        if (flags & TEXT2_IMPLICIT_X)\        if (flags & TEXT2_IMPLICIT_X)\
# Line 1157  ui_draw_text(uint8 font, uint8 flags, in Line 1488  ui_draw_text(uint8 font, uint8 flags, in
1488    
1489          if (boxcx > 1)          if (boxcx > 1)
1490          {          {
1491                  FILL_RECTANGLE(boxx, boxy, boxcx, boxcy);                  FILL_RECTANGLE_BACKSTORE(boxx, boxy, boxcx, boxcy);
1492          }          }
1493          else if (mixmode == MIX_OPAQUE)          else if (mixmode == MIX_OPAQUE)
1494          {          {
1495                  FILL_RECTANGLE(clipx, clipy, clipcx, clipcy);                  FILL_RECTANGLE_BACKSTORE(clipx, clipy, clipcx, clipcy);
1496          }          }
1497    
1498          /* Paint text, character by character */          /* Paint text, character by character */
# Line 1175  ui_draw_text(uint8 font, uint8 flags, in Line 1506  ui_draw_text(uint8 font, uint8 flags, in
1506                                  else                                  else
1507                                  {                                  {
1508                                          error("this shouldn't be happening\n");                                          error("this shouldn't be happening\n");
1509                                          break;                                          exit(1);
1510                                  }                                  }
1511                                  /* this will move pointer from start to first character after FF command */                                  /* this will move pointer from start to first character after FF command */
1512                                  length -= i + 3;                                  length -= i + 3;
# Line 1195  ui_draw_text(uint8 font, uint8 flags, in Line 1526  ui_draw_text(uint8 font, uint8 flags, in
1526                                                  else                                                  else
1527                                                          x += text[i + 2];                                                          x += text[i + 2];
1528                                          }                                          }
                                         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;  
1529                                          for (j = 0; j < entry->size; j++)                                          for (j = 0; j < entry->size; j++)
1530                                                  DO_GLYPH(((uint8 *) (entry->data)), j);                                                  DO_GLYPH(((uint8 *) (entry->data)), j);
1531                                  }                                  }
1532                                    if (i + 2 < length)
1533                                            i += 3;
1534                                    else
1535                                            i += 2;
1536                                    length -= i;
1537                                    /* this will move pointer from start to first character after FE command */
1538                                    text = &(text[i]);
1539                                    i = 0;
1540                                  break;                                  break;
1541    
1542                          default:                          default:
# Line 1214  ui_draw_text(uint8 font, uint8 flags, in Line 1545  ui_draw_text(uint8 font, uint8 flags, in
1545                                  break;                                  break;
1546                  }                  }
1547          }          }
1548            if (ownbackstore)
1549            {
1550                    if (boxcx > 1)
1551                            XCopyArea(display, backstore, wnd, gc, boxx,
1552                                      boxy, boxcx, boxcy, boxx, boxy);
1553                    else
1554                            XCopyArea(display, backstore, wnd, gc, clipx,
1555                                      clipy, clipcx, clipcy, clipx, clipy);
1556            }
1557  }  }
1558    
1559  void  void

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

  ViewVC Help
Powered by ViewVC 1.1.26