/[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 517 by matthewc, Tue Oct 28 03:30:51 2003 UTC revision 688 by jsorg71, Fri Apr 30 19:14:15 2004 UTC
# Line 20  Line 20 
20    
21  #include <X11/Xlib.h>  #include <X11/Xlib.h>
22  #include <X11/Xutil.h>  #include <X11/Xutil.h>
23    #include <unistd.h>
24    #include <sys/time.h>
25  #include <time.h>  #include <time.h>
26  #include <errno.h>  #include <errno.h>
27    #include <strings.h>
28  #include "rdesktop.h"  #include "rdesktop.h"
29  #include "xproto.h"  #include "xproto.h"
30    
# Line 40  Time g_last_gesturetime; Line 43  Time g_last_gesturetime;
43  static int g_x_socket;  static int g_x_socket;
44  static Screen *g_screen;  static Screen *g_screen;
45  Window g_wnd;  Window g_wnd;
46    extern uint32 g_embed_wnd;
47  BOOL g_enable_compose = False;  BOOL g_enable_compose = False;
48  static GC g_gc;  BOOL g_Unobscured; /* used for screenblt */
49    static GC g_gc = NULL;
50  static Visual *g_visual;  static Visual *g_visual;
51  static int g_depth;  static int g_depth;
52  static int g_bpp;  static int g_bpp;
# Line 49  static XIM g_IM; Line 54  static XIM g_IM;
54  static XIC g_IC;  static XIC g_IC;
55  static XModifierKeymap *g_mod_map;  static XModifierKeymap *g_mod_map;
56  static Cursor g_current_cursor;  static Cursor g_current_cursor;
57  static HCURSOR g_null_cursor;  static HCURSOR g_null_cursor = NULL;
58  static Atom g_protocol_atom, g_kill_atom;  static Atom g_protocol_atom, g_kill_atom;
59  static BOOL g_focused;  static BOOL g_focused;
60  static BOOL g_mouse_in_wnd;  static BOOL g_mouse_in_wnd;
61    static BOOL g_arch_match = False;       /* set to True if RGB XServer and little endian */
62    
63  /* endianness */  /* endianness */
64  static BOOL g_host_be;  static BOOL g_host_be;
65  static BOOL g_xserver_be;  static BOOL g_xserver_be;
66    static int g_red_shift_r, g_blue_shift_r, g_green_shift_r;
67    static int g_red_shift_l, g_blue_shift_l, g_green_shift_l;
68    
69  /* software backing store */  /* software backing store */
70  static BOOL g_ownbackstore;  extern BOOL g_ownbackstore;
71  static Pixmap g_backstore;  static Pixmap g_backstore = 0;
72    
73  /* Moving in single app mode */  /* Moving in single app mode */
74  static BOOL g_moving_wnd;  static BOOL g_moving_wnd;
# Line 108  PixelColour; Line 116  PixelColour;
116  }  }
117    
118  /* colour maps */  /* colour maps */
119  BOOL g_owncolmap = False;  extern BOOL g_owncolmap;
120  static Colormap g_xcolmap;  static Colormap g_xcolmap;
121  static uint32 *g_colmap = NULL;  static uint32 *g_colmap = NULL;
122    
123  #define TRANSLATE(col)          ( g_server_bpp != 8 ? translate_colour(col) : g_owncolmap ? col : translate_colour(g_colmap[col]) )  #define TRANSLATE(col)          ( g_server_bpp != 8 ? translate_colour(col) : g_owncolmap ? col : g_colmap[col] )
124  #define SET_FOREGROUND(col)     XSetForeground(g_display, g_gc, TRANSLATE(col));  #define SET_FOREGROUND(col)     XSetForeground(g_display, g_gc, TRANSLATE(col));
125  #define SET_BACKGROUND(col)     XSetBackground(g_display, g_gc, TRANSLATE(col));  #define SET_BACKGROUND(col)     XSetBackground(g_display, g_gc, TRANSLATE(col));
126    
# Line 164  static PixelColour Line 172  static PixelColour
172  split_colour15(uint32 colour)  split_colour15(uint32 colour)
173  {  {
174          PixelColour rv;          PixelColour rv;
175          rv.red = (colour & 0x7c00) >> 10;          rv.red = (colour & 0x7c00) >> 7;
176          rv.red = (rv.red * 0xff) / 0x1f;          rv.green = (colour & 0x03e0) >> 2;
177          rv.green = (colour & 0x03e0) >> 5;          rv.blue = (colour & 0x001f) << 3;
         rv.green = (rv.green * 0xff) / 0x1f;  
         rv.blue = (colour & 0x1f);  
         rv.blue = (rv.blue * 0xff) / 0x1f;  
178          return rv;          return rv;
179  }  }
180    
# Line 177  static PixelColour Line 182  static PixelColour
182  split_colour16(uint32 colour)  split_colour16(uint32 colour)
183  {  {
184          PixelColour rv;          PixelColour rv;
185          rv.red = (colour & 0xf800) >> 11;          rv.red = (colour & 0xf800) >> 8;
186          rv.red = (rv.red * 0xff) / 0x1f;          rv.green = (colour & 0x07e0) >> 3;
187          rv.green = (colour & 0x07e0) >> 5;          rv.blue = (colour & 0x001f) << 3;
         rv.green = (rv.green * 0xff) / 0x3f;  
         rv.blue = (colour & 0x001f);  
         rv.blue = (rv.blue * 0xff) / 0x1f;  
188          return rv;          return rv;
189  }  }
190    
# Line 191  split_colour24(uint32 colour) Line 193  split_colour24(uint32 colour)
193  {  {
194          PixelColour rv;          PixelColour rv;
195          rv.blue = (colour & 0xff0000) >> 16;          rv.blue = (colour & 0xff0000) >> 16;
196          rv.green = (colour & 0xff00) >> 8;          rv.green = (colour & 0x00ff00) >> 8;
197          rv.red = (colour & 0xff);          rv.red = (colour & 0x0000ff);
198          return rv;          return rv;
199  }  }
200    
201  static uint32  static uint32
202  make_colour16(PixelColour pc)  make_colour(PixelColour pc)
203  {  {
204          pc.red = (pc.red * 0x1f) / 0xff;          return (((pc.red >> g_red_shift_r) << g_red_shift_l)
205          pc.green = (pc.green * 0x3f) / 0xff;                  | ((pc.green >> g_green_shift_r) << g_green_shift_l)
206          pc.blue = (pc.blue * 0x1f) / 0xff;                  | ((pc.blue >> g_blue_shift_r) << g_blue_shift_l));
         return (pc.red << 11) | (pc.green << 5) | pc.blue;  
 }  
   
 static uint32  
 make_colour24(PixelColour pc)  
 {  
         if (g_xserver_be)  
         {  
                 return pc.red | (pc.green << 8) | (pc.blue << 16);  
         }  
         else  
         {  
                 return (pc.red << 16) | (pc.green << 8) | pc.blue;  
         }  
 }  
   
 static uint32  
 make_colour32(PixelColour pc)  
 {  
         if (g_xserver_be)  
         {  
                 return pc.red | (pc.green << 8) | (pc.blue << 16);  
         }  
         else  
         {  
                 return (pc.red << 16) | (pc.green << 8) | pc.blue;  
         }  
207  }  }
208    
209  #define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); }  #define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); }
210  #define BSWAP24(x) { x = (((x & 0xff) << 16) | (x >> 16) | ((x >> 8) & 0xff00)); }  #define BSWAP24(x) { x = (((x & 0xff) << 16) | (x >> 16) | (x & 0xff00)); }
211  #define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \  #define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \
212                          x = (x << 16) | (x >> 16); }                          x = (x << 16) | (x >> 16); }
213    
214  static uint32  static uint32
215  translate_colour(uint32 colour)  translate_colour(uint32 colour)
216  {  {
217            PixelColour pc;
218          switch (g_server_bpp)          switch (g_server_bpp)
219          {          {
220                  case 15:                  case 15:
221                          switch (g_bpp)                          pc = split_colour15(colour);
                         {  
                                 case 16:  
                                         colour = make_colour16(split_colour15(colour));  
                                         break;  
                                 case 24:  
                                         colour = make_colour24(split_colour15(colour));  
                                         break;  
                                 case 32:  
                                         colour = make_colour32(split_colour15(colour));  
                                         break;  
                         }  
222                          break;                          break;
223                  case 16:                  case 16:
224                          switch (g_bpp)                          pc = split_colour16(colour);
                         {  
                                 case 16:  
                                         break;  
                                 case 24:  
                                         colour = make_colour24(split_colour16(colour));  
                                         break;  
                                 case 32:  
                                         colour = make_colour32(split_colour16(colour));  
                                         break;  
                         }  
225                          break;                          break;
226                  case 24:                  case 24:
227                          switch (g_bpp)                          pc = split_colour24(colour);
                         {  
                                 case 16:  
                                         colour = make_colour16(split_colour24(colour));  
                                         break;  
                                 case 24:  
                                         break;  
                                 case 32:  
                                         colour = make_colour32(split_colour24(colour));  
                                         break;  
                         }  
228                          break;                          break;
229          }          }
230          return colour;          return make_colour(pc);
231    }
232    
233    #define UNROLL8(stm) { stm stm stm stm stm stm stm stm }
234    #define REPEAT(stm) \
235    { \
236            while (out <= end - 8 * 4) \
237                    UNROLL8(stm) \
238            while (out < end) \
239                    { stm } \
240  }  }
241    
242  static void  static void
# Line 293  translate8to8(uint8 * data, uint8 * out, Line 247  translate8to8(uint8 * data, uint8 * out,
247  }  }
248    
249  static void  static void
250  translate8to16(uint8 * data, uint16 * out, uint16 * end)  translate8to16(uint8 * data, uint8 * out, uint8 * end)
251  {  {
252          while (out < end)          uint16 value;
253                  *(out++) = (uint16) g_colmap[*(data++)];  
254            if (g_arch_match)
255                    REPEAT(*(((uint16*)out)++) = g_colmap[*(data++)];)
256            else if (g_xserver_be)
257            {
258                    while (out < end)
259                    {
260                            value = (uint16) g_colmap[*(data++)];
261                            *(out++) = value >> 8;
262                            *(out++) = value;
263                    }
264            }
265            else
266            {
267                    while (out < end)
268                    {
269                            value = (uint16) g_colmap[*(data++)];
270                            *(out++) = value;
271                            *(out++) = value >> 8;
272                    }
273            }
274  }  }
275    
276  /* little endian - conversion happens when colourmap is built */  /* little endian - conversion happens when colourmap is built */
# Line 305  translate8to24(uint8 * data, uint8 * out Line 279  translate8to24(uint8 * data, uint8 * out
279  {  {
280          uint32 value;          uint32 value;
281    
282          while (out < end)          if (g_xserver_be)
283          {          {
284                  value = g_colmap[*(data++)];                  while (out < end)
285                  *(out++) = value;                  {
286                  *(out++) = value >> 8;                          value = g_colmap[*(data++)];
287                  *(out++) = value >> 16;                          *(out++) = value >> 16;
288                            *(out++) = value >> 8;
289                            *(out++) = value;
290                    }
291            }
292            else
293            {
294                    while (out < end)
295                    {
296                            value = g_colmap[*(data++)];
297                            *(out++) = value;
298                            *(out++) = value >> 8;
299                            *(out++) = value >> 16;
300                    }
301          }          }
302  }  }
303    
304  static void  static void
305  translate8to32(uint8 * data, uint32 * out, uint32 * end)  translate8to32(uint8 * data, uint8 * out, uint8 * end)
306  {  {
307          while (out < end)          uint32 value;
                 *(out++) = g_colmap[*(data++)];  
 }  
308    
309  /* todo the remaining translate function might need some big endian check ?? */          if (g_arch_match)
310                    REPEAT(*(((uint32*)out)++) = g_colmap[*(data++)];)
311            else if (g_xserver_be)
312            {
313                    while (out < end)
314                    {
315                            value = g_colmap[*(data++)];
316                            *(out++) = value >> 24;
317                            *(out++) = value >> 16;
318                            *(out++) = value >> 8;
319                            *(out++) = value;
320                    }
321            }
322            else
323            {
324                    while (out < end)
325                    {
326                            value = g_colmap[*(data++)];
327                            *(out++) = value;
328                            *(out++) = value >> 8;
329                            *(out++) = value >> 16;
330                            *(out++) = value >> 24;
331                    }
332            }
333    }
334    
335  static void  static void
336  translate15to16(uint16 * data, uint8 * out, uint8 * end)  translate15to16(uint16 * data, uint8 * out, uint8 * end)
# Line 335  translate15to16(uint16 * data, uint8 * o Line 344  translate15to16(uint16 * data, uint8 * o
344    
345                  if (g_host_be)                  if (g_host_be)
346                  {                  {
347                  BSWAP16(pixel)}                          BSWAP16(pixel);
348                    }
349    
350                  value = make_colour16(split_colour15(pixel));                  value = make_colour(split_colour15(pixel));
351    
352                  if (g_xserver_be)                  if (g_xserver_be)
353                  {                  {
# Line 364  translate15to24(uint16 * data, uint8 * o Line 374  translate15to24(uint16 * data, uint8 * o
374    
375                  if (g_host_be)                  if (g_host_be)
376                  {                  {
377                  BSWAP16(pixel)}                          BSWAP16(pixel);
378                    }
379    
380                  value = make_colour24(split_colour15(pixel));                  value = make_colour(split_colour15(pixel));
381                  if (g_xserver_be)                  if (g_xserver_be)
382                  {                  {
383                          *(out++) = value >> 16;                          *(out++) = value >> 16;
# Line 397  translate15to32(uint16 * data, uint8 * o Line 408  translate15to32(uint16 * data, uint8 * o
408                          BSWAP16(pixel);                          BSWAP16(pixel);
409                  }                  }
410    
411                  value = make_colour32(split_colour15(pixel));                  value = make_colour(split_colour15(pixel));
412    
413                  if (g_xserver_be)                  if (g_xserver_be)
414                  {                  {
# Line 417  translate15to32(uint16 * data, uint8 * o Line 428  translate15to32(uint16 * data, uint8 * o
428  }  }
429    
430  static void  static void
431  translate16to16(uint16 * data, uint16 * out, uint16 * end)  translate16to16(uint16 * data, uint8 * out, uint8 * end)
432  {  {
433            uint16 pixel;
434          uint16 value;          uint16 value;
435    
436          if (g_xserver_be)          while (out < end)
437          {          {
438                  while (out < end)                  pixel = *(data++);
439    
440                    if (g_host_be)
441                  {                  {
442                          value = *data;                          BSWAP16(pixel);
                         BSWAP16(value);  
                         *out = value;  
                         data++;  
                         out++;  
443                  }                  }
444    
445          }                  value = make_colour(split_colour16(pixel));
446          else  
447          {                  if (g_xserver_be)
                 while (out < end)  
448                  {                  {
449                          *out = *data;                          *(out++) = value >> 8;
450                          out++;                          *(out++) = value;
451                          data++;                  }
452                    else
453                    {
454                            *(out++) = value;
455                            *(out++) = value >> 8;
456                  }                  }
457          }          }
458  }  }
459    
   
460  static void  static void
461  translate16to24(uint16 * data, uint8 * out, uint8 * end)  translate16to24(uint16 * data, uint8 * out, uint8 * end)
462  {  {
# Line 457  translate16to24(uint16 * data, uint8 * o Line 469  translate16to24(uint16 * data, uint8 * o
469    
470                  if (g_host_be)                  if (g_host_be)
471                  {                  {
472                  BSWAP16(pixel)}                          BSWAP16(pixel);
473                    }
474    
475                  value = make_colour24(split_colour16(pixel));                  value = make_colour(split_colour16(pixel));
476    
477                  if (g_xserver_be)                  if (g_xserver_be)
478                  {                  {
# Line 488  translate16to32(uint16 * data, uint8 * o Line 501  translate16to32(uint16 * data, uint8 * o
501    
502                  if (g_host_be)                  if (g_host_be)
503                  {                  {
504                  BSWAP16(pixel)}                          BSWAP16(pixel);
505                    }
506    
507                  value = make_colour32(split_colour16(pixel));                  value = make_colour(split_colour16(pixel));
508    
509                  if (g_xserver_be)                  if (g_xserver_be)
510                  {                  {
# Line 520  translate24to16(uint8 * data, uint8 * ou Line 534  translate24to16(uint8 * data, uint8 * ou
534                  pixel |= *(data++) << 8;                  pixel |= *(data++) << 8;
535                  pixel |= *(data++);                  pixel |= *(data++);
536    
537                  value = (uint16) make_colour16(split_colour24(pixel));                  value = (uint16) make_colour(split_colour24(pixel));
538    
539                  if (g_xserver_be)                  if (g_xserver_be)
540                  {                  {
# Line 538  translate24to16(uint8 * data, uint8 * ou Line 552  translate24to16(uint8 * data, uint8 * ou
552  static void  static void
553  translate24to24(uint8 * data, uint8 * out, uint8 * end)  translate24to24(uint8 * data, uint8 * out, uint8 * end)
554  {  {
555            uint32 pixel;
556            uint32 value;
557    
558          while (out < end)          while (out < end)
559          {          {
560                  *(out++) = (*(data++));                  pixel = *(data++) << 16;
561                    pixel |= *(data++) << 8;
562                    pixel |= *(data++);
563    
564                    value = make_colour(split_colour24(pixel));
565    
566                    if (g_xserver_be)
567                    {
568                            *(out++) = value >> 16;
569                            *(out++) = value >> 8;
570                            *(out++) = value;
571                    }
572                    else
573                    {
574                            *(out++) = value;
575                            *(out++) = value >> 8;
576                            *(out++) = value >> 16;
577                    }
578          }          }
579  }  }
580    
581  static void  static void
582  translate24to32(uint8 * data, uint8 * out, uint8 * end)  translate24to32(uint8 * data, uint8 * out, uint8 * end)
583  {  {
584            uint32 pixel;
585            uint32 value;
586    
587          while (out < end)          while (out < end)
588          {          {
589                    pixel = *(data++) << 16;
590                    pixel |= *(data++) << 8;
591                    pixel |= *(data++);
592    
593                    value = make_colour(split_colour24(pixel));
594    
595                  if (g_xserver_be)                  if (g_xserver_be)
596                  {                  {
597                          *(out++) = 0x00;                          *(out++) = value >> 24;
598                          *(out++) = *(data++);                          *(out++) = value >> 16;
599                          *(out++) = *(data++);                          *(out++) = value >> 8;
600                          *(out++) = *(data++);                          *(out++) = value;
601                  }                  }
602                  else                  else
603                  {                  {
604                          *(out++) = *(data++);                          *(out++) = value;
605                          *(out++) = *(data++);                          *(out++) = value >> 8;
606                          *(out++) = *(data++);                          *(out++) = value >> 16;
607                          *(out++) = 0x00;                          *(out++) = value >> 24;
608                  }                  }
609          }          }
610  }  }
# Line 569  translate24to32(uint8 * data, uint8 * ou Line 612  translate24to32(uint8 * data, uint8 * ou
612  static uint8 *  static uint8 *
613  translate_image(int width, int height, uint8 * data)  translate_image(int width, int height, uint8 * data)
614  {  {
615          int size = width * height * g_bpp / 8;          int size;
616          uint8 *out = (uint8 *) xmalloc(size);          uint8 *out;
617          uint8 *end = out + size;          uint8 *end;
618    
619            /* if server and xserver bpp match, */
620            /* and arch(endian) matches, no need to translate */
621            /* just return data */
622            if (g_arch_match)
623            {
624                    if (g_depth == 15 && g_server_bpp == 15)
625                            return data;
626                    if (g_depth == 16 && g_server_bpp == 16)
627                            return data;
628            }
629    
630            size = width * height * (g_bpp / 8);
631            out = (uint8 *) xmalloc(size);
632            end = out + size;
633    
634          switch (g_server_bpp)          switch (g_server_bpp)
635          {          {
# Line 599  translate_image(int width, int height, u Line 657  translate_image(int width, int height, u
657                                          translate16to24((uint16 *) data, out, end);                                          translate16to24((uint16 *) data, out, end);
658                                          break;                                          break;
659                                  case 16:                                  case 16:
660                                          translate16to16((uint16 *) data, (uint16 *) out,                                          translate16to16((uint16 *) data, out, end);
                                                         (uint16 *) end);  
661                                          break;                                          break;
662                          }                          }
663                          break;                          break;
# Line 625  translate_image(int width, int height, u Line 682  translate_image(int width, int height, u
682                                          translate8to8(data, out, end);                                          translate8to8(data, out, end);
683                                          break;                                          break;
684                                  case 16:                                  case 16:
685                                          translate8to16(data, (uint16 *) out, (uint16 *) end);                                          translate8to16(data, out, end);
686                                          break;                                          break;
687                                  case 24:                                  case 24:
688                                          translate8to24(data, out, end);                                          translate8to24(data, out, end);
689                                          break;                                          break;
690                                  case 32:                                  case 32:
691                                          translate8to32(data, (uint32 *) out, (uint32 *) end);                                          translate8to32(data, out, end);
692                                          break;                                          break;
693                          }                          }
694                          break;                          break;
# Line 664  get_key_state(unsigned int state, uint32 Line 721  get_key_state(unsigned int state, uint32
721          return (state & keysymMask) ? True : False;          return (state & keysymMask) ? True : False;
722  }  }
723    
724    static void
725    calculate_shifts(uint32 mask, int *shift_r, int *shift_l)
726    {
727            *shift_l = ffs(mask) - 1;
728            mask >>= *shift_l;
729            *shift_r = 8 - ffs(mask & ~(mask >> 1));
730    }
731    
732  BOOL  BOOL
733  ui_init(void)  ui_init(void)
734  {  {
735            XVisualInfo vi;
736          XPixmapFormatValues *pfm;          XPixmapFormatValues *pfm;
737          uint16 test;          uint16 test;
738          int i;          int i, screen_num, nvisuals;
739            XVisualInfo *vmatches = NULL;
740            XVisualInfo template;
741            Bool TrueColorVisual = False;
742    
743          g_display = XOpenDisplay(NULL);          g_display = XOpenDisplay(NULL);
744          if (g_display == NULL)          if (g_display == NULL)
# Line 678  ui_init(void) Line 747  ui_init(void)
747                  return False;                  return False;
748          }          }
749    
750            screen_num = DefaultScreen(g_display);
751          g_x_socket = ConnectionNumber(g_display);          g_x_socket = ConnectionNumber(g_display);
752          g_screen = DefaultScreenOfDisplay(g_display);          g_screen = ScreenOfDisplay(g_display, screen_num);
         g_visual = DefaultVisualOfScreen(g_screen);  
753          g_depth = DefaultDepthOfScreen(g_screen);          g_depth = DefaultDepthOfScreen(g_screen);
754    
755            /* Search for best TrueColor depth */
756            template.class = TrueColor;
757            vmatches = XGetVisualInfo(g_display, VisualClassMask, &template, &nvisuals);
758    
759            nvisuals--;
760            while (nvisuals >= 0)
761            {
762                    if ((vmatches + nvisuals)->depth > g_depth)
763                    {
764                            g_depth = (vmatches + nvisuals)->depth;
765                    }
766                    nvisuals--;
767                    TrueColorVisual = True;
768            }
769    
770            test = 1;
771            g_host_be = !(BOOL) (*(uint8 *) (&test));
772            g_xserver_be = (ImageByteOrder(g_display) == MSBFirst);
773    
774            if ((g_server_bpp == 8) && ((!TrueColorVisual) || (g_depth <= 8)))
775            {
776                    /* we use a colourmap, so the default visual should do */
777                    g_visual = DefaultVisualOfScreen(g_screen);
778                    g_depth = DefaultDepthOfScreen(g_screen);
779    
780                    /* Do not allocate colours on a TrueColor visual */
781                    if (g_visual->class == TrueColor)
782                    {
783                            g_owncolmap = False;
784                    }
785            }
786            else
787            {
788                    /* need a truecolour visual */
789                    if (!XMatchVisualInfo(g_display, screen_num, g_depth, TrueColor, &vi))
790                    {
791                            error("The display does not support true colour - high colour support unavailable.\n");
792                            return False;
793                    }
794    
795                    g_visual = vi.visual;
796                    g_owncolmap = False;
797                    calculate_shifts(vi.red_mask, &g_red_shift_r, &g_red_shift_l);
798                    calculate_shifts(vi.blue_mask, &g_blue_shift_r, &g_blue_shift_l);
799                    calculate_shifts(vi.green_mask, &g_green_shift_r, &g_green_shift_l);
800    
801                    /* if RGB video and averything is little endian */
802                    if (vi.red_mask > vi.green_mask && vi.green_mask > vi.blue_mask)
803                            if (!g_xserver_be && !g_host_be)
804                                    g_arch_match = True;
805            }
806    
807          pfm = XListPixmapFormats(g_display, &i);          pfm = XListPixmapFormats(g_display, &i);
808          if (pfm != NULL)          if (pfm != NULL)
809          {          {
# Line 705  ui_init(void) Line 826  ui_init(void)
826                  return False;                  return False;
827          }          }
828    
         /* private colour map code only works for 8 bpp */  
         if (g_owncolmap && (g_bpp > 8))  
                 g_owncolmap = False;  
   
829          if (!g_owncolmap)          if (!g_owncolmap)
830          {          {
831                  g_xcolmap = DefaultColormapOfScreen(g_screen);                  g_xcolmap =
832                            XCreateColormap(g_display, RootWindowOfScreen(g_screen), g_visual,
833                                            AllocNone);
834                  if (g_depth <= 8)                  if (g_depth <= 8)
835                          warning("Screen depth is 8 bits or lower: you may want to use -C for a private colourmap\n");                          warning("Screen depth is 8 bits or lower: you may want to use -C for a private colourmap\n");
836          }          }
837    
838          g_gc = XCreateGC(g_display, RootWindowOfScreen(g_screen), 0, NULL);          if ((!g_ownbackstore) && (DoesBackingStore(g_screen) != Always))
839            {
840          if (DoesBackingStore(g_screen) != Always)                  warning("External BackingStore not available, using internal\n");
841                  g_ownbackstore = True;                  g_ownbackstore = True;
842            }
         test = 1;  
         g_host_be = !(BOOL) (*(uint8 *) (&test));  
         g_xserver_be = (ImageByteOrder(g_display) == MSBFirst);  
843    
844          /*          /*
845           * Determine desktop size           * Determine desktop size
846           */           */
847          if (g_width < 0)          if (g_fullscreen)
848            {
849                    g_width = WidthOfScreen(g_screen);
850                    g_height = HeightOfScreen(g_screen);
851            }
852            else if (g_width < 0)
853          {          {
854                  /* Percent of screen */                  /* Percent of screen */
855                  g_height = HeightOfScreen(g_screen) * (-g_width) / 100;                  g_height = HeightOfScreen(g_screen) * (-g_width) / 100;
# Line 751  ui_init(void) Line 872  ui_init(void)
872                          g_height = 600;                          g_height = 600;
873                  }                  }
874          }          }
         else if (g_fullscreen)  
         {  
                 g_width = WidthOfScreen(g_screen);  
                 g_height = HeightOfScreen(g_screen);  
         }  
875    
876          /* make sure width is a multiple of 4 */          /* make sure width is a multiple of 4 */
877          g_width = (g_width + 3) & ~3;          g_width = (g_width + 3) & ~3;
878    
         if (g_ownbackstore)  
         {  
                 g_backstore =  
                         XCreatePixmap(g_display, RootWindowOfScreen(g_screen), g_width, g_height,  
                                       g_depth);  
   
                 /* clear to prevent rubbish being exposed at startup */  
                 XSetForeground(g_display, g_gc, BlackPixelOfScreen(g_screen));  
                 XFillRectangle(g_display, g_backstore, g_gc, 0, 0, g_width, g_height);  
         }  
   
879          g_mod_map = XGetModifierMapping(g_display);          g_mod_map = XGetModifierMapping(g_display);
880    
881          xkeymap_init();          xkeymap_init();
# Line 780  ui_init(void) Line 885  ui_init(void)
885    
886          xclip_init();          xclip_init();
887    
888          /* todo take this out when high colour is done */          DEBUG_RDP5(("server bpp %d client bpp %d depth %d\n", g_server_bpp, g_bpp, g_depth));
         printf("server bpp %d client bpp %d depth %d\n", g_server_bpp, g_bpp, g_depth);  
889    
890          return True;          return True;
891  }  }
# Line 792  ui_deinit(void) Line 896  ui_deinit(void)
896          if (g_IM != NULL)          if (g_IM != NULL)
897                  XCloseIM(g_IM);                  XCloseIM(g_IM);
898    
899            if (g_null_cursor != NULL)
900                    ui_destroy_cursor(g_null_cursor);
901    
902          XFreeModifiermap(g_mod_map);          XFreeModifiermap(g_mod_map);
903    
904          if (g_ownbackstore)          if (g_ownbackstore)
# Line 802  ui_deinit(void) Line 909  ui_deinit(void)
909          g_display = NULL;          g_display = NULL;
910  }  }
911    
 #define NULL_POINTER_MASK       "\x80"  
 #define NULL_POINTER_DATA       "\x0\x0\x0"  
           
912  BOOL  BOOL
913  ui_create_window(void)  ui_create_window(void)
914  {  {
915            uint8 null_pointer_mask[1] = { 0x80 };
916            uint8 null_pointer_data[4] = { 0x00, 0x00, 0x00, 0x00 };
917          XSetWindowAttributes attribs;          XSetWindowAttributes attribs;
918          XClassHint *classhints;          XClassHint *classhints;
919          XSizeHints *sizehints;          XSizeHints *sizehints;
# Line 819  ui_create_window(void) Line 925  ui_create_window(void)
925          wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height;          wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height;
926    
927          attribs.background_pixel = BlackPixelOfScreen(g_screen);          attribs.background_pixel = BlackPixelOfScreen(g_screen);
928            attribs.border_pixel = WhitePixelOfScreen(g_screen);
929          attribs.backing_store = g_ownbackstore ? NotUseful : Always;          attribs.backing_store = g_ownbackstore ? NotUseful : Always;
930          attribs.override_redirect = g_fullscreen;          attribs.override_redirect = g_fullscreen;
931            attribs.colormap = g_xcolmap;
932    
933          g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), 0, 0, wndwidth, wndheight,          g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), 0, 0, wndwidth, wndheight,
934                                0, CopyFromParent, InputOutput, CopyFromParent,                                0, g_depth, InputOutput, g_visual,
935                                CWBackPixel | CWBackingStore | CWOverrideRedirect, &attribs);                                CWBackPixel | CWBackingStore | CWOverrideRedirect |
936                                  CWColormap | CWBorderPixel, &attribs);
937    
938            if (g_gc == NULL)
939                    g_gc = XCreateGC(g_display, g_wnd, 0, NULL);
940    
941            if ((g_ownbackstore) && (g_backstore == 0))
942            {
943                    g_backstore = XCreatePixmap(g_display, g_wnd, g_width, g_height, g_depth);
944    
945                    /* clear to prevent rubbish being exposed at startup */
946                    XSetForeground(g_display, g_gc, BlackPixelOfScreen(g_screen));
947                    XFillRectangle(g_display, g_backstore, g_gc, 0, 0, g_width, g_height);
948            }
949    
950          XStoreName(g_display, g_wnd, g_title);          XStoreName(g_display, g_wnd, g_title);
951    
# Line 849  ui_create_window(void) Line 970  ui_create_window(void)
970                  XFree(sizehints);                  XFree(sizehints);
971          }          }
972    
973            if (g_embed_wnd)
974            {
975                    XReparentWindow(g_display, g_wnd, (Window) g_embed_wnd, 0, 0);
976            }
977    
978          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
979                  VisibilityChangeMask | FocusChangeMask;                  VisibilityChangeMask | FocusChangeMask;
980    
# Line 880  ui_create_window(void) Line 1006  ui_create_window(void)
1006                  XMaskEvent(g_display, VisibilityChangeMask, &xevent);                  XMaskEvent(g_display, VisibilityChangeMask, &xevent);
1007          }          }
1008          while (xevent.type != VisibilityNotify);          while (xevent.type != VisibilityNotify);
1009            g_Unobscured = xevent.xvisibility.state == VisibilityUnobscured;
1010    
1011          g_focused = False;          g_focused = False;
1012          g_mouse_in_wnd = False;          g_mouse_in_wnd = False;
# Line 890  ui_create_window(void) Line 1017  ui_create_window(void)
1017          XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1);          XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1);
1018    
1019          /* create invisible 1x1 cursor to be used as null cursor */          /* create invisible 1x1 cursor to be used as null cursor */
1020          g_null_cursor = ui_create_cursor(0, 0, 1, 1, NULL_POINTER_MASK, NULL_POINTER_DATA);          if (g_null_cursor == NULL)
1021                    g_null_cursor = ui_create_cursor(0, 0, 1, 1, null_pointer_mask, null_pointer_data);
1022    
1023          return True;          return True;
1024  }  }
1025    
1026  void  void
1027    ui_resize_window()
1028    {
1029            XSizeHints *sizehints;
1030    
1031            sizehints = XAllocSizeHints();
1032            if (sizehints)
1033            {
1034                    sizehints->flags = PMinSize | PMaxSize;
1035                    sizehints->min_width = sizehints->max_width = g_width;
1036                    sizehints->min_height = sizehints->max_height = g_height;
1037                    XSetWMNormalHints(g_display, g_wnd, sizehints);
1038                    XFree(sizehints);
1039            }
1040    
1041            if (!(g_fullscreen || g_embed_wnd))
1042            {
1043                    XResizeWindow(g_display, g_wnd, g_width, g_height);
1044            }
1045    }
1046    
1047    void
1048  ui_destroy_window(void)  ui_destroy_window(void)
1049  {  {
         ui_destroy_cursor(g_null_cursor);  
           
1050          if (g_IC != NULL)          if (g_IC != NULL)
1051                  XDestroyIC(g_IC);                  XDestroyIC(g_IC);
1052    
# Line 943  xwin_process_events(void) Line 1090  xwin_process_events(void)
1090          key_translation tr;          key_translation tr;
1091          char str[256];          char str[256];
1092          Status status;          Status status;
         unsigned int state;  
         Window wdummy;  
         int dummy;  
1093    
1094          while (XPending(g_display) > 0)          while (XPending(g_display) > 0)
1095          {          {
# Line 961  xwin_process_events(void) Line 1105  xwin_process_events(void)
1105    
1106                  switch (xevent.type)                  switch (xevent.type)
1107                  {                  {
1108                            case VisibilityNotify:
1109                                    g_Unobscured = xevent.xvisibility.state == VisibilityUnobscured;
1110                                    break;
1111                          case ClientMessage:                          case ClientMessage:
1112                                  /* the window manager told us to quit */                                  /* the window manager told us to quit */
1113                                  if ((xevent.xclient.message_type == g_protocol_atom)                                  if ((xevent.xclient.message_type == g_protocol_atom)
# Line 1118  xwin_process_events(void) Line 1265  xwin_process_events(void)
1265                                  if (xevent.xfocus.mode == NotifyGrab)                                  if (xevent.xfocus.mode == NotifyGrab)
1266                                          break;                                          break;
1267                                  g_focused = True;                                  g_focused = True;
1268                                  XQueryPointer(g_display, g_wnd, &wdummy, &wdummy, &dummy, &dummy,                                  reset_modifier_keys();
                                               &dummy, &dummy, &state);  
                                 reset_modifier_keys(state);  
1269                                  if (g_grab_keyboard && g_mouse_in_wnd)                                  if (g_grab_keyboard && g_mouse_in_wnd)
1270                                          XGrabKeyboard(g_display, g_wnd, True,                                          XGrabKeyboard(g_display, g_wnd, True,
1271                                                        GrabModeAsync, GrabModeAsync, CurrentTime);                                                        GrabModeAsync, GrabModeAsync, CurrentTime);
# Line 1200  xwin_process_events(void) Line 1345  xwin_process_events(void)
1345  int  int
1346  ui_select(int rdp_socket)  ui_select(int rdp_socket)
1347  {  {
1348          int n = (rdp_socket > g_x_socket) ? rdp_socket + 1 : g_x_socket + 1;          int n;
1349          fd_set rfds, wfds;          fd_set rfds, wfds;
1350            struct timeval tv;
1351            BOOL s_timeout = False;
1352    
1353          while (True)          while (True)
1354          {          {
1355                    n = (rdp_socket > g_x_socket) ? rdp_socket : g_x_socket;
1356                  /* Process any events already waiting */                  /* Process any events already waiting */
1357                  if (!xwin_process_events())                  if (!xwin_process_events())
1358                          /* User quit */                          /* User quit */
# Line 1220  ui_select(int rdp_socket) Line 1368  ui_select(int rdp_socket)
1368                  if (g_dsp_busy)                  if (g_dsp_busy)
1369                  {                  {
1370                          FD_SET(g_dsp_fd, &wfds);                          FD_SET(g_dsp_fd, &wfds);
1371                          n = (g_dsp_fd + 1 > n) ? g_dsp_fd + 1 : n;                          n = (g_dsp_fd > n) ? g_dsp_fd : n;
1372                  }                  }
1373  #endif  #endif
1374                    /* default timeout */
1375                    tv.tv_sec = 60;
1376                    tv.tv_usec = 0;
1377    
1378                    /* add redirection handles */
1379                    rdpdr_add_fds(&n, &rfds, &wfds, &tv, &s_timeout);
1380    
1381                  switch (select(n, &rfds, &wfds, NULL, NULL))                  n++;
1382    
1383                    switch (select(n, &rfds, &wfds, NULL, &tv))
1384                  {                  {
1385                          case -1:                          case -1:
1386                                  error("select: %s\n", strerror(errno));                                  error("select: %s\n", strerror(errno));
1387    
1388                          case 0:                          case 0:
1389                                    /* TODO: if tv.tv_sec just times out
1390                                     * we will segfault.
1391                                     * FIXME:
1392                                     */
1393                                    //s_timeout = True;
1394                                    //rdpdr_check_fds(&rfds, &wfds, (BOOL) True);
1395                                  continue;                                  continue;
1396                  }                  }
1397    
1398                    rdpdr_check_fds(&rfds, &wfds, (BOOL) False);
1399    
1400                  if (FD_ISSET(rdp_socket, &rfds))                  if (FD_ISSET(rdp_socket, &rfds))
1401                          return 1;                          return 1;
1402    
# Line 1255  ui_create_bitmap(int width, int height, Line 1419  ui_create_bitmap(int width, int height,
1419          XImage *image;          XImage *image;
1420          Pixmap bitmap;          Pixmap bitmap;
1421          uint8 *tdata;          uint8 *tdata;
1422            int bitmap_pad;
1423    
1424            if (g_server_bpp == 8)
1425            {
1426                    bitmap_pad = 8;
1427            }
1428            else
1429            {
1430                    bitmap_pad = g_bpp;
1431    
1432                    if (g_bpp == 24)
1433                            bitmap_pad = 32;
1434            }
1435    
1436          tdata = (g_owncolmap ? data : translate_image(width, height, data));          tdata = (g_owncolmap ? data : translate_image(width, height, data));
1437          bitmap = XCreatePixmap(g_display, g_wnd, width, height, g_depth);          bitmap = XCreatePixmap(g_display, g_wnd, width, height, g_depth);
1438          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,
1439                               (char *) tdata, width, height, g_server_bpp == 8 ? 8 : g_bpp, 0);                               (char *) tdata, width, height, bitmap_pad, 0);
1440    
1441          XPutImage(g_display, bitmap, g_gc, image, 0, 0, 0, 0, width, height);          XPutImage(g_display, bitmap, g_gc, image, 0, 0, 0, 0, width, height);
1442    
1443          XFree(image);          XFree(image);
1444          if (!g_owncolmap)          if (tdata != data)
1445                  xfree(tdata);                  xfree(tdata);
1446          return (HBITMAP) bitmap;          return (HBITMAP) bitmap;
1447  }  }
# Line 1274  ui_paint_bitmap(int x, int y, int cx, in Line 1451  ui_paint_bitmap(int x, int y, int cx, in
1451  {  {
1452          XImage *image;          XImage *image;
1453          uint8 *tdata;          uint8 *tdata;
1454            int bitmap_pad;
1455    
1456            if (g_server_bpp == 8)
1457            {
1458                    bitmap_pad = 8;
1459            }
1460            else
1461            {
1462                    bitmap_pad = g_bpp;
1463    
1464                    if (g_bpp == 24)
1465                            bitmap_pad = 32;
1466            }
1467    
1468          tdata = (g_owncolmap ? data : translate_image(width, height, data));          tdata = (g_owncolmap ? data : translate_image(width, height, data));
1469          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,
1470                               (char *) tdata, width, height, g_server_bpp == 8 ? 8 : g_bpp, 0);                               (char *) tdata, width, height, bitmap_pad, 0);
1471    
1472          if (g_ownbackstore)          if (g_ownbackstore)
1473          {          {
# Line 1289  ui_paint_bitmap(int x, int y, int cx, in Line 1480  ui_paint_bitmap(int x, int y, int cx, in
1480          }          }
1481    
1482          XFree(image);          XFree(image);
1483          if (!g_owncolmap)          if (tdata != data)
1484                  xfree(tdata);                  xfree(tdata);
1485  }  }
1486    
# Line 1502  ui_create_colourmap(COLOURMAP * colours) Line 1693  ui_create_colourmap(COLOURMAP * colours)
1693    
1694                          }                          }
1695    
1696                            map[i] = colour;
                         /* byte swap here to make translate_image faster */  
                         map[i] = translate_colour(colour);  
1697                  }                  }
1698                  return map;                  return map;
1699          }          }
# Line 1615  ui_patblt(uint8 opcode, Line 1804  ui_patblt(uint8 opcode,
1804          {          {
1805                  case 0: /* Solid */                  case 0: /* Solid */
1806                          SET_FOREGROUND(fgcolour);                          SET_FOREGROUND(fgcolour);
1807                          FILL_RECTANGLE(x, y, cx, cy);                          FILL_RECTANGLE_BACKSTORE(x, y, cx, cy);
1808                          break;                          break;
1809    
1810                  case 2: /* Hatch */                  case 2: /* Hatch */
# Line 1626  ui_patblt(uint8 opcode, Line 1815  ui_patblt(uint8 opcode,
1815                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);
1816                          XSetStipple(g_display, g_gc, fill);                          XSetStipple(g_display, g_gc, fill);
1817                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);
1818                          FILL_RECTANGLE(x, y, cx, cy);                          FILL_RECTANGLE_BACKSTORE(x, y, cx, cy);
1819                          XSetFillStyle(g_display, g_gc, FillSolid);                          XSetFillStyle(g_display, g_gc, FillSolid);
1820                          XSetTSOrigin(g_display, g_gc, 0, 0);                          XSetTSOrigin(g_display, g_gc, 0, 0);
1821                          ui_destroy_glyph((HGLYPH) fill);                          ui_destroy_glyph((HGLYPH) fill);
# Line 1636  ui_patblt(uint8 opcode, Line 1825  ui_patblt(uint8 opcode,
1825                          for (i = 0; i != 8; i++)                          for (i = 0; i != 8; i++)
1826                                  ipattern[7 - i] = brush->pattern[i];                                  ipattern[7 - i] = brush->pattern[i];
1827                          fill = (Pixmap) ui_create_glyph(8, 8, ipattern);                          fill = (Pixmap) ui_create_glyph(8, 8, ipattern);
   
1828                          SET_FOREGROUND(bgcolour);                          SET_FOREGROUND(bgcolour);
1829                          SET_BACKGROUND(fgcolour);                          SET_BACKGROUND(fgcolour);
1830                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);
1831                          XSetStipple(g_display, g_gc, fill);                          XSetStipple(g_display, g_gc, fill);
1832                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);
1833                            FILL_RECTANGLE_BACKSTORE(x, y, cx, cy);
                         FILL_RECTANGLE(x, y, cx, cy);  
   
1834                          XSetFillStyle(g_display, g_gc, FillSolid);                          XSetFillStyle(g_display, g_gc, FillSolid);
1835                          XSetTSOrigin(g_display, g_gc, 0, 0);                          XSetTSOrigin(g_display, g_gc, 0, 0);
1836                          ui_destroy_glyph((HGLYPH) fill);                          ui_destroy_glyph((HGLYPH) fill);
# Line 1655  ui_patblt(uint8 opcode, Line 1841  ui_patblt(uint8 opcode,
1841          }          }
1842    
1843          RESET_FUNCTION(opcode);          RESET_FUNCTION(opcode);
1844    
1845            if (g_ownbackstore)
1846                    XCopyArea(g_display, g_backstore, g_wnd, g_gc, x, y, cx, cy, x, y);
1847  }  }
1848    
1849  void  void
# Line 1663  ui_screenblt(uint8 opcode, Line 1852  ui_screenblt(uint8 opcode,
1852               /* src */ int srcx, int srcy)               /* src */ int srcx, int srcy)
1853  {  {
1854          SET_FUNCTION(opcode);          SET_FUNCTION(opcode);
         XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);  
1855          if (g_ownbackstore)          if (g_ownbackstore)
1856                  XCopyArea(g_display, g_backstore, g_backstore, g_gc, srcx, srcy, cx, cy, x, y);          {
1857                    if (g_Unobscured)
1858                    {
1859                            XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);
1860                            XCopyArea(g_display, g_backstore, g_backstore, g_gc, srcx, srcy, cx, cy, x, y);
1861                    }
1862                    else
1863                    {
1864                            XCopyArea(g_display, g_backstore, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);
1865                            XCopyArea(g_display, g_backstore, g_backstore, g_gc, srcx, srcy, cx, cy, x, y);
1866                    }
1867            }
1868            else
1869            {
1870                    XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);
1871            }
1872          RESET_FUNCTION(opcode);          RESET_FUNCTION(opcode);
1873  }  }
1874    
# Line 1760  ui_draw_glyph(int mixmode, Line 1963  ui_draw_glyph(int mixmode,
1963  {\  {\
1964    glyph = cache_get_font (font, ttext[idx]);\    glyph = cache_get_font (font, ttext[idx]);\
1965    if (!(flags & TEXT2_IMPLICIT_X))\    if (!(flags & TEXT2_IMPLICIT_X))\
1966      {\
1967        xyoffset = ttext[++idx];\
1968        if ((xyoffset & 0x80))\
1969      {\      {\
1970        xyoffset = ttext[++idx];\        if (flags & TEXT2_VERTICAL)\
1971        if ((xyoffset & 0x80))\          y += ttext[idx+1] | (ttext[idx+2] << 8);\
         {\  
           if (flags & TEXT2_VERTICAL) \  
             y += ttext[idx+1] | (ttext[idx+2] << 8);\  
           else\  
             x += ttext[idx+1] | (ttext[idx+2] << 8);\  
           idx += 2;\  
         }\  
1972        else\        else\
1973          {\          x += ttext[idx+1] | (ttext[idx+2] << 8);\
1974            if (flags & TEXT2_VERTICAL) \        idx += 2;\
             y += xyoffset;\  
           else\  
             x += xyoffset;\  
         }\  
1975      }\      }\
1976    if (glyph != NULL)\      else\
1977      {\      {\
1978        ui_draw_glyph (mixmode, x + glyph->offset,\        if (flags & TEXT2_VERTICAL)\
1979                       y + glyph->baseline,\          y += xyoffset;\
1980                       glyph->width, glyph->height,\        else\
1981                       glyph->pixmap, 0, 0, bgcolour, fgcolour);\          x += xyoffset;\
       if (flags & TEXT2_IMPLICIT_X)\  
         x += glyph->width;\  
1982      }\      }\
1983      }\
1984      if (glyph != NULL)\
1985      {\
1986        x1 = x + glyph->offset;\
1987        y1 = y + glyph->baseline;\
1988        XSetStipple(g_display, g_gc, (Pixmap) glyph->pixmap);\
1989        XSetTSOrigin(g_display, g_gc, x1, y1);\
1990        FILL_RECTANGLE_BACKSTORE(x1, y1, glyph->width, glyph->height);\
1991        if (flags & TEXT2_IMPLICIT_X)\
1992          x += glyph->width;\
1993      }\
1994  }  }
1995    
1996  void  void
# Line 1796  ui_draw_text(uint8 font, uint8 flags, in Line 2000  ui_draw_text(uint8 font, uint8 flags, in
2000               int fgcolour, uint8 * text, uint8 length)               int fgcolour, uint8 * text, uint8 length)
2001  {  {
2002          FONTGLYPH *glyph;          FONTGLYPH *glyph;
2003          int i, j, xyoffset;          int i, j, xyoffset, x1, y1;
2004          DATABLOB *entry;          DATABLOB *entry;
2005    
2006          SET_FOREGROUND(bgcolour);          SET_FOREGROUND(bgcolour);
2007    
2008            /* Sometimes, the boxcx value is something really large, like
2009               32691. This makes XCopyArea fail with Xvnc. The code below
2010               is a quick fix. */
2011            if (boxx + boxcx > g_width)
2012                    boxcx = g_width - boxx;
2013    
2014          if (boxcx > 1)          if (boxcx > 1)
2015          {          {
2016                  FILL_RECTANGLE_BACKSTORE(boxx, boxy, boxcx, boxcy);                  FILL_RECTANGLE_BACKSTORE(boxx, boxy, boxcx, boxcy);
# Line 1810  ui_draw_text(uint8 font, uint8 flags, in Line 2020  ui_draw_text(uint8 font, uint8 flags, in
2020                  FILL_RECTANGLE_BACKSTORE(clipx, clipy, clipcx, clipcy);                  FILL_RECTANGLE_BACKSTORE(clipx, clipy, clipcx, clipcy);
2021          }          }
2022    
2023            SET_FOREGROUND(fgcolour);
2024            SET_BACKGROUND(bgcolour);
2025            XSetFillStyle(g_display, g_gc, FillStippled);
2026    
2027          /* Paint text, character by character */          /* Paint text, character by character */
2028          for (i = 0; i < length;)          for (i = 0; i < length;)
2029          {          {
# Line 1860  ui_draw_text(uint8 font, uint8 flags, in Line 2074  ui_draw_text(uint8 font, uint8 flags, in
2074                                  break;                                  break;
2075                  }                  }
2076          }          }
2077    
2078            XSetFillStyle(g_display, g_gc, FillSolid);
2079    
2080          if (g_ownbackstore)          if (g_ownbackstore)
2081          {          {
2082                  if (boxcx > 1)                  if (boxcx > 1)

Legend:
Removed from v.517  
changed lines
  Added in v.688

  ViewVC Help
Powered by ViewVC 1.1.26