/[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 501 by stargo, Fri Oct 17 08:23:47 2003 UTC revision 713 by jsorg71, Wed Jun 16 03:08:55 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 = 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 107  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 163  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 >> 7) & 0xf8) | ((colour >> 12) & 0x7);
176          rv.red = (rv.red * 0xff) / 0x1f;          rv.green = ((colour >> 2) & 0xf8) | ((colour >> 8) & 0x7);
177          rv.green = (colour & 0x03e0) >> 5;          rv.blue = ((colour << 3) & 0xf8) | ((colour >> 2) & 0x7);
         rv.green = (rv.green * 0xff) / 0x1f;  
         rv.blue = (colour & 0x1f);  
         rv.blue = (rv.blue * 0xff) / 0x1f;  
178          return rv;          return rv;
179  }  }
180    
# Line 176  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 >> 8) & 0xf8) | ((colour >> 13) & 0x7);
186          rv.red = (rv.red * 0xff) / 0x1f;          rv.green = ((colour >> 3) & 0xfc) | ((colour >> 9) & 0x3);
187          rv.green = (colour & 0x07e0) >> 5;          rv.blue = ((colour << 3) & 0xf8) | ((colour >> 2) & 0x7);
         rv.green = (rv.green * 0xff) / 0x3f;  
         rv.blue = (colour & 0x001f);  
         rv.blue = (rv.blue * 0xff) / 0x1f;  
188          return rv;          return rv;
189  }  }
190    
# Line 190  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    /* indent is confused by UNROLL8 */
234    /* *INDENT-OFF* */
235    
236    /* repeat and unroll, similar to bitmap.c */
237    /* potentialy any of the following translate */
238    /* functions can use repeat but just doing */
239    /* the most common ones */
240    
241    #define UNROLL8(stm) { stm stm stm stm stm stm stm stm }
242    /* 2 byte output repeat */
243    #define REPEAT2(stm) \
244    { \
245            while (out <= end - 8 * 2) \
246                    UNROLL8(stm) \
247            while (out < end) \
248                    { stm } \
249    }
250    /* 4 byte output repeat */
251    #define REPEAT4(stm) \
252    { \
253            while (out <= end - 8 * 4) \
254                    UNROLL8(stm) \
255            while (out < end) \
256                    { stm } \
257  }  }
258    
259  static void  static void
# Line 292  translate8to8(uint8 * data, uint8 * out, Line 264  translate8to8(uint8 * data, uint8 * out,
264  }  }
265    
266  static void  static void
267  translate8to16(uint8 * data, uint16 * out, uint16 * end)  translate8to16(uint8 * data, uint8 * out, uint8 * end)
268  {  {
269          while (out < end)          uint16 value;
270                  *(out++) = (uint16) g_colmap[*(data++)];  
271            if (g_arch_match)
272            {
273                    REPEAT2
274                    (
275                            *((uint16 *) out) = g_colmap[*(data++)];
276                            out += 2;
277                    )
278            }
279            else if (g_xserver_be)
280            {
281                    while (out < end)
282                    {
283                            value = (uint16) g_colmap[*(data++)];
284                            *(out++) = value >> 8;
285                            *(out++) = value;
286                    }
287            }
288            else
289            {
290                    while (out < end)
291                    {
292                            value = (uint16) g_colmap[*(data++)];
293                            *(out++) = value;
294                            *(out++) = value >> 8;
295                    }
296            }
297  }  }
298    
299  /* little endian - conversion happens when colourmap is built */  /* little endian - conversion happens when colourmap is built */
# Line 304  translate8to24(uint8 * data, uint8 * out Line 302  translate8to24(uint8 * data, uint8 * out
302  {  {
303          uint32 value;          uint32 value;
304    
305          while (out < end)          if (g_xserver_be)
306          {          {
307                  value = g_colmap[*(data++)];                  while (out < end)
308                  *(out++) = value;                  {
309                  *(out++) = value >> 8;                          value = g_colmap[*(data++)];
310                  *(out++) = value >> 16;                          *(out++) = value >> 16;
311                            *(out++) = value >> 8;
312                            *(out++) = value;
313                    }
314            }
315            else
316            {
317                    while (out < end)
318                    {
319                            value = g_colmap[*(data++)];
320                            *(out++) = value;
321                            *(out++) = value >> 8;
322                            *(out++) = value >> 16;
323                    }
324          }          }
325  }  }
326    
327  static void  static void
328  translate8to32(uint8 * data, uint32 * out, uint32 * end)  translate8to32(uint8 * data, uint8 * out, uint8 * end)
329  {  {
330          while (out < end)          uint32 value;
331                  *(out++) = g_colmap[*(data++)];  
332            if (g_arch_match)
333            {
334                    REPEAT4
335                    (
336                            *((uint32 *) out) = g_colmap[*(data++)];
337                            out += 4;
338                    )
339            }
340            else if (g_xserver_be)
341            {
342                    while (out < end)
343                    {
344                            value = g_colmap[*(data++)];
345                            *(out++) = value >> 24;
346                            *(out++) = value >> 16;
347                            *(out++) = value >> 8;
348                            *(out++) = value;
349                    }
350            }
351            else
352            {
353                    while (out < end)
354                    {
355                            value = g_colmap[*(data++)];
356                            *(out++) = value;
357                            *(out++) = value >> 8;
358                            *(out++) = value >> 16;
359                            *(out++) = value >> 24;
360                    }
361            }
362  }  }
363    
364  /* todo the remaining translate function might need some big endian check ?? */  /* *INDENT-ON* */
365    
366  static void  static void
367  translate15to16(uint16 * data, uint8 * out, uint8 * end)  translate15to16(uint16 * data, uint8 * out, uint8 * end)
# Line 334  translate15to16(uint16 * data, uint8 * o Line 375  translate15to16(uint16 * data, uint8 * o
375    
376                  if (g_host_be)                  if (g_host_be)
377                  {                  {
378                  BSWAP16(pixel)}                          BSWAP16(pixel);
379                    }
380    
381                  value = make_colour16(split_colour15(pixel));                  value = make_colour(split_colour15(pixel));
382    
383                  if (g_xserver_be)                  if (g_xserver_be)
384                  {                  {
# Line 363  translate15to24(uint16 * data, uint8 * o Line 405  translate15to24(uint16 * data, uint8 * o
405    
406                  if (g_host_be)                  if (g_host_be)
407                  {                  {
408                  BSWAP16(pixel)}                          BSWAP16(pixel);
409                    }
410    
411                  value = make_colour24(split_colour15(pixel));                  value = make_colour(split_colour15(pixel));
412                  if (g_xserver_be)                  if (g_xserver_be)
413                  {                  {
414                          *(out++) = value >> 16;                          *(out++) = value >> 16;
# Line 396  translate15to32(uint16 * data, uint8 * o Line 439  translate15to32(uint16 * data, uint8 * o
439                          BSWAP16(pixel);                          BSWAP16(pixel);
440                  }                  }
441    
442                  value = make_colour32(split_colour15(pixel));                  value = make_colour(split_colour15(pixel));
443    
444                  if (g_xserver_be)                  if (g_xserver_be)
445                  {                  {
# Line 416  translate15to32(uint16 * data, uint8 * o Line 459  translate15to32(uint16 * data, uint8 * o
459  }  }
460    
461  static void  static void
462  translate16to16(uint16 * data, uint16 * out, uint16 * end)  translate16to16(uint16 * data, uint8 * out, uint8 * end)
463  {  {
464            uint16 pixel;
465          uint16 value;          uint16 value;
466    
467          if (g_xserver_be)          while (out < end)
468          {          {
469                  while (out < end)                  pixel = *(data++);
470    
471                    if (g_host_be)
472                  {                  {
473                          value = *data;                          BSWAP16(pixel);
                         BSWAP16(value);  
                         *out = value;  
                         data++;  
                         out++;  
474                  }                  }
475    
476          }                  value = make_colour(split_colour16(pixel));
477          else  
478          {                  if (g_xserver_be)
                 while (out < end)  
479                  {                  {
480                          *out = *data;                          *(out++) = value >> 8;
481                          out++;                          *(out++) = value;
482                          data++;                  }
483                    else
484                    {
485                            *(out++) = value;
486                            *(out++) = value >> 8;
487                  }                  }
488          }          }
489  }  }
490    
   
491  static void  static void
492  translate16to24(uint16 * data, uint8 * out, uint8 * end)  translate16to24(uint16 * data, uint8 * out, uint8 * end)
493  {  {
# Line 456  translate16to24(uint16 * data, uint8 * o Line 500  translate16to24(uint16 * data, uint8 * o
500    
501                  if (g_host_be)                  if (g_host_be)
502                  {                  {
503                  BSWAP16(pixel)}                          BSWAP16(pixel);
504                    }
505    
506                  value = make_colour24(split_colour16(pixel));                  value = make_colour(split_colour16(pixel));
507    
508                  if (g_xserver_be)                  if (g_xserver_be)
509                  {                  {
# Line 487  translate16to32(uint16 * data, uint8 * o Line 532  translate16to32(uint16 * data, uint8 * o
532    
533                  if (g_host_be)                  if (g_host_be)
534                  {                  {
535                  BSWAP16(pixel)}                          BSWAP16(pixel);
536                    }
537    
538                  value = make_colour32(split_colour16(pixel));                  value = make_colour(split_colour16(pixel));
539    
540                  if (g_xserver_be)                  if (g_xserver_be)
541                  {                  {
# Line 519  translate24to16(uint8 * data, uint8 * ou Line 565  translate24to16(uint8 * data, uint8 * ou
565                  pixel |= *(data++) << 8;                  pixel |= *(data++) << 8;
566                  pixel |= *(data++);                  pixel |= *(data++);
567    
568                  value = (uint16) make_colour16(split_colour24(pixel));                  value = (uint16) make_colour(split_colour24(pixel));
569    
570                  if (g_xserver_be)                  if (g_xserver_be)
571                  {                  {
# Line 537  translate24to16(uint8 * data, uint8 * ou Line 583  translate24to16(uint8 * data, uint8 * ou
583  static void  static void
584  translate24to24(uint8 * data, uint8 * out, uint8 * end)  translate24to24(uint8 * data, uint8 * out, uint8 * end)
585  {  {
586            uint32 pixel;
587            uint32 value;
588    
589          while (out < end)          while (out < end)
590          {          {
591                  *(out++) = (*(data++));                  pixel = *(data++) << 16;
592                    pixel |= *(data++) << 8;
593                    pixel |= *(data++);
594    
595                    value = make_colour(split_colour24(pixel));
596    
597                    if (g_xserver_be)
598                    {
599                            *(out++) = value >> 16;
600                            *(out++) = value >> 8;
601                            *(out++) = value;
602                    }
603                    else
604                    {
605                            *(out++) = value;
606                            *(out++) = value >> 8;
607                            *(out++) = value >> 16;
608                    }
609          }          }
610  }  }
611    
612  static void  static void
613  translate24to32(uint8 * data, uint8 * out, uint8 * end)  translate24to32(uint8 * data, uint8 * out, uint8 * end)
614  {  {
615            uint32 pixel;
616            uint32 value;
617    
618          while (out < end)          while (out < end)
619          {          {
620                    pixel = *(data++) << 16;
621                    pixel |= *(data++) << 8;
622                    pixel |= *(data++);
623    
624                    value = make_colour(split_colour24(pixel));
625    
626                  if (g_xserver_be)                  if (g_xserver_be)
627                  {                  {
628                          *(out++) = 0x00;                          *(out++) = value >> 24;
629                          *(out++) = *(data++);                          *(out++) = value >> 16;
630                          *(out++) = *(data++);                          *(out++) = value >> 8;
631                          *(out++) = *(data++);                          *(out++) = value;
632                  }                  }
633                  else                  else
634                  {                  {
635                          *(out++) = *(data++);                          *(out++) = value;
636                          *(out++) = *(data++);                          *(out++) = value >> 8;
637                          *(out++) = *(data++);                          *(out++) = value >> 16;
638                          *(out++) = 0x00;                          *(out++) = value >> 24;
639                  }                  }
640          }          }
641  }  }
# Line 568  translate24to32(uint8 * data, uint8 * ou Line 643  translate24to32(uint8 * data, uint8 * ou
643  static uint8 *  static uint8 *
644  translate_image(int width, int height, uint8 * data)  translate_image(int width, int height, uint8 * data)
645  {  {
646          int size = width * height * g_bpp / 8;          int size;
647          uint8 *out = (uint8 *) xmalloc(size);          uint8 *out;
648          uint8 *end = out + size;          uint8 *end;
649    
650            /* if server and xserver bpp match, */
651            /* and arch(endian) matches, no need to translate */
652            /* just return data */
653            if (g_arch_match)
654            {
655                    if (g_depth == 15 && g_server_bpp == 15)
656                            return data;
657                    if (g_depth == 16 && g_server_bpp == 16)
658                            return data;
659            }
660    
661            size = width * height * (g_bpp / 8);
662            out = (uint8 *) xmalloc(size);
663            end = out + size;
664    
665          switch (g_server_bpp)          switch (g_server_bpp)
666          {          {
# Line 598  translate_image(int width, int height, u Line 688  translate_image(int width, int height, u
688                                          translate16to24((uint16 *) data, out, end);                                          translate16to24((uint16 *) data, out, end);
689                                          break;                                          break;
690                                  case 16:                                  case 16:
691                                          translate16to16((uint16 *) data, (uint16 *) out,                                          translate16to16((uint16 *) data, out, end);
                                                         (uint16 *) end);  
692                                          break;                                          break;
693                          }                          }
694                          break;                          break;
# Line 624  translate_image(int width, int height, u Line 713  translate_image(int width, int height, u
713                                          translate8to8(data, out, end);                                          translate8to8(data, out, end);
714                                          break;                                          break;
715                                  case 16:                                  case 16:
716                                          translate8to16(data, (uint16 *) out, (uint16 *) end);                                          translate8to16(data, out, end);
717                                          break;                                          break;
718                                  case 24:                                  case 24:
719                                          translate8to24(data, out, end);                                          translate8to24(data, out, end);
720                                          break;                                          break;
721                                  case 32:                                  case 32:
722                                          translate8to32(data, (uint32 *) out, (uint32 *) end);                                          translate8to32(data, out, end);
723                                          break;                                          break;
724                          }                          }
725                          break;                          break;
# Line 663  get_key_state(unsigned int state, uint32 Line 752  get_key_state(unsigned int state, uint32
752          return (state & keysymMask) ? True : False;          return (state & keysymMask) ? True : False;
753  }  }
754    
755    static void
756    calculate_shifts(uint32 mask, int *shift_r, int *shift_l)
757    {
758            *shift_l = ffs(mask) - 1;
759            mask >>= *shift_l;
760            *shift_r = 8 - ffs(mask & ~(mask >> 1));
761    }
762    
763  BOOL  BOOL
764  ui_init(void)  ui_init(void)
765  {  {
766            XVisualInfo vi;
767          XPixmapFormatValues *pfm;          XPixmapFormatValues *pfm;
768          uint16 test;          uint16 test;
769          int i;          int i, screen_num, nvisuals;
770            XVisualInfo *vmatches = NULL;
771            XVisualInfo template;
772            Bool TrueColorVisual = False;
773    
774          g_display = XOpenDisplay(NULL);          g_display = XOpenDisplay(NULL);
775          if (g_display == NULL)          if (g_display == NULL)
# Line 677  ui_init(void) Line 778  ui_init(void)
778                  return False;                  return False;
779          }          }
780    
781            screen_num = DefaultScreen(g_display);
782          g_x_socket = ConnectionNumber(g_display);          g_x_socket = ConnectionNumber(g_display);
783          g_screen = DefaultScreenOfDisplay(g_display);          g_screen = ScreenOfDisplay(g_display, screen_num);
         g_visual = DefaultVisualOfScreen(g_screen);  
784          g_depth = DefaultDepthOfScreen(g_screen);          g_depth = DefaultDepthOfScreen(g_screen);
785    
786            /* Search for best TrueColor depth */
787            template.class = TrueColor;
788            vmatches = XGetVisualInfo(g_display, VisualClassMask, &template, &nvisuals);
789    
790            nvisuals--;
791            while (nvisuals >= 0)
792            {
793                    if ((vmatches + nvisuals)->depth > g_depth)
794                    {
795                            g_depth = (vmatches + nvisuals)->depth;
796                    }
797                    nvisuals--;
798                    TrueColorVisual = True;
799            }
800    
801            test = 1;
802            g_host_be = !(BOOL) (*(uint8 *) (&test));
803            g_xserver_be = (ImageByteOrder(g_display) == MSBFirst);
804    
805            if ((g_server_bpp == 8) && ((!TrueColorVisual) || (g_depth <= 8)))
806            {
807                    /* we use a colourmap, so the default visual should do */
808                    g_visual = DefaultVisualOfScreen(g_screen);
809                    g_depth = DefaultDepthOfScreen(g_screen);
810    
811                    /* Do not allocate colours on a TrueColor visual */
812                    if (g_visual->class == TrueColor)
813                    {
814                            g_owncolmap = False;
815                    }
816            }
817            else
818            {
819                    /* need a truecolour visual */
820                    if (!XMatchVisualInfo(g_display, screen_num, g_depth, TrueColor, &vi))
821                    {
822                            error("The display does not support true colour - high colour support unavailable.\n");
823                            return False;
824                    }
825    
826                    g_visual = vi.visual;
827                    g_owncolmap = False;
828                    calculate_shifts(vi.red_mask, &g_red_shift_r, &g_red_shift_l);
829                    calculate_shifts(vi.blue_mask, &g_blue_shift_r, &g_blue_shift_l);
830                    calculate_shifts(vi.green_mask, &g_green_shift_r, &g_green_shift_l);
831    
832                    /* if RGB video and averything is little endian */
833                    if (vi.red_mask > vi.green_mask && vi.green_mask > vi.blue_mask)
834                            if (!g_xserver_be && !g_host_be)
835                                    g_arch_match = True;
836            }
837    
838          pfm = XListPixmapFormats(g_display, &i);          pfm = XListPixmapFormats(g_display, &i);
839          if (pfm != NULL)          if (pfm != NULL)
840          {          {
# Line 704  ui_init(void) Line 857  ui_init(void)
857                  return False;                  return False;
858          }          }
859    
860          if (g_owncolmap != True)          if (!g_owncolmap)
861          {          {
862                  g_xcolmap = DefaultColormapOfScreen(g_screen);                  g_xcolmap =
863                            XCreateColormap(g_display, RootWindowOfScreen(g_screen), g_visual,
864                                            AllocNone);
865                  if (g_depth <= 8)                  if (g_depth <= 8)
866                          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");
867          }          }
868    
869          g_gc = XCreateGC(g_display, RootWindowOfScreen(g_screen), 0, NULL);          if ((!g_ownbackstore) && (DoesBackingStore(g_screen) != Always))
870            {
871          if (DoesBackingStore(g_screen) != Always)                  warning("External BackingStore not available, using internal\n");
872                  g_ownbackstore = True;                  g_ownbackstore = True;
873            }
         test = 1;  
         g_host_be = !(BOOL) (*(uint8 *) (&test));  
         g_xserver_be = (ImageByteOrder(g_display) == MSBFirst);  
874    
875          /*          /*
876           * Determine desktop size           * Determine desktop size
877           */           */
878          if (g_width < 0)          if (g_fullscreen)
879            {
880                    g_width = WidthOfScreen(g_screen);
881                    g_height = HeightOfScreen(g_screen);
882            }
883            else if (g_width < 0)
884          {          {
885                  /* Percent of screen */                  /* Percent of screen */
886                  g_height = HeightOfScreen(g_screen) * (-g_width) / 100;                  g_height = HeightOfScreen(g_screen) * (-g_width) / 100;
# Line 746  ui_init(void) Line 903  ui_init(void)
903                          g_height = 600;                          g_height = 600;
904                  }                  }
905          }          }
         else if (g_fullscreen)  
         {  
                 g_width = WidthOfScreen(g_screen);  
                 g_height = HeightOfScreen(g_screen);  
         }  
906    
907          /* make sure width is a multiple of 4 */          /* make sure width is a multiple of 4 */
908          g_width = (g_width + 3) & ~3;          g_width = (g_width + 3) & ~3;
909    
         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);  
         }  
   
910          g_mod_map = XGetModifierMapping(g_display);          g_mod_map = XGetModifierMapping(g_display);
911    
912          xkeymap_init();          xkeymap_init();
# Line 775  ui_init(void) Line 916  ui_init(void)
916    
917          xclip_init();          xclip_init();
918    
919          /* 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);  
920    
921          return True;          return True;
922  }  }
# Line 787  ui_deinit(void) Line 927  ui_deinit(void)
927          if (g_IM != NULL)          if (g_IM != NULL)
928                  XCloseIM(g_IM);                  XCloseIM(g_IM);
929    
930            if (g_null_cursor != NULL)
931                    ui_destroy_cursor(g_null_cursor);
932    
933          XFreeModifiermap(g_mod_map);          XFreeModifiermap(g_mod_map);
934    
935          if (g_ownbackstore)          if (g_ownbackstore)
# Line 800  ui_deinit(void) Line 943  ui_deinit(void)
943  BOOL  BOOL
944  ui_create_window(void)  ui_create_window(void)
945  {  {
946            uint8 null_pointer_mask[1] = { 0x80 };
947            uint8 null_pointer_data[4] = { 0x00, 0x00, 0x00, 0x00 };
948          XSetWindowAttributes attribs;          XSetWindowAttributes attribs;
949          XClassHint *classhints;          XClassHint *classhints;
950          XSizeHints *sizehints;          XSizeHints *sizehints;
# Line 811  ui_create_window(void) Line 956  ui_create_window(void)
956          wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height;          wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height;
957    
958          attribs.background_pixel = BlackPixelOfScreen(g_screen);          attribs.background_pixel = BlackPixelOfScreen(g_screen);
959            attribs.border_pixel = WhitePixelOfScreen(g_screen);
960          attribs.backing_store = g_ownbackstore ? NotUseful : Always;          attribs.backing_store = g_ownbackstore ? NotUseful : Always;
961          attribs.override_redirect = g_fullscreen;          attribs.override_redirect = g_fullscreen;
962            attribs.colormap = g_xcolmap;
963    
964          g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), 0, 0, wndwidth, wndheight,          g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), 0, 0, wndwidth, wndheight,
965                                0, CopyFromParent, InputOutput, CopyFromParent,                                0, g_depth, InputOutput, g_visual,
966                                CWBackPixel | CWBackingStore | CWOverrideRedirect, &attribs);                                CWBackPixel | CWBackingStore | CWOverrideRedirect |
967                                  CWColormap | CWBorderPixel, &attribs);
968    
969            if (g_gc == NULL)
970                    g_gc = XCreateGC(g_display, g_wnd, 0, NULL);
971    
972            if ((g_ownbackstore) && (g_backstore == 0))
973            {
974                    g_backstore = XCreatePixmap(g_display, g_wnd, g_width, g_height, g_depth);
975    
976                    /* clear to prevent rubbish being exposed at startup */
977                    XSetForeground(g_display, g_gc, BlackPixelOfScreen(g_screen));
978                    XFillRectangle(g_display, g_backstore, g_gc, 0, 0, g_width, g_height);
979            }
980    
981          XStoreName(g_display, g_wnd, g_title);          XStoreName(g_display, g_wnd, g_title);
982    
# Line 841  ui_create_window(void) Line 1001  ui_create_window(void)
1001                  XFree(sizehints);                  XFree(sizehints);
1002          }          }
1003    
1004            if (g_embed_wnd)
1005            {
1006                    XReparentWindow(g_display, g_wnd, (Window) g_embed_wnd, 0, 0);
1007            }
1008    
1009          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
1010                  VisibilityChangeMask | FocusChangeMask;                  VisibilityChangeMask | FocusChangeMask;
1011    
# Line 872  ui_create_window(void) Line 1037  ui_create_window(void)
1037                  XMaskEvent(g_display, VisibilityChangeMask, &xevent);                  XMaskEvent(g_display, VisibilityChangeMask, &xevent);
1038          }          }
1039          while (xevent.type != VisibilityNotify);          while (xevent.type != VisibilityNotify);
1040            g_Unobscured = xevent.xvisibility.state == VisibilityUnobscured;
1041    
1042          g_focused = False;          g_focused = False;
1043          g_mouse_in_wnd = False;          g_mouse_in_wnd = False;
# Line 881  ui_create_window(void) Line 1047  ui_create_window(void)
1047          g_kill_atom = XInternAtom(g_display, "WM_DELETE_WINDOW", True);          g_kill_atom = XInternAtom(g_display, "WM_DELETE_WINDOW", True);
1048          XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1);          XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1);
1049    
1050            /* create invisible 1x1 cursor to be used as null cursor */
1051            if (g_null_cursor == NULL)
1052                    g_null_cursor = ui_create_cursor(0, 0, 1, 1, null_pointer_mask, null_pointer_data);
1053    
1054          return True;          return True;
1055  }  }
1056    
1057  void  void
1058    ui_resize_window()
1059    {
1060            XSizeHints *sizehints;
1061            Pixmap bs;
1062    
1063            sizehints = XAllocSizeHints();
1064            if (sizehints)
1065            {
1066                    sizehints->flags = PMinSize | PMaxSize;
1067                    sizehints->min_width = sizehints->max_width = g_width;
1068                    sizehints->min_height = sizehints->max_height = g_height;
1069                    XSetWMNormalHints(g_display, g_wnd, sizehints);
1070                    XFree(sizehints);
1071            }
1072    
1073            if (!(g_fullscreen || g_embed_wnd))
1074            {
1075                    XResizeWindow(g_display, g_wnd, g_width, g_height);
1076            }
1077    
1078            /* create new backstore pixmap */
1079            if (g_backstore != 0)
1080            {
1081                    bs = XCreatePixmap(g_display, g_wnd, g_width, g_height, g_depth);
1082                    XSetForeground(g_display, g_gc, BlackPixelOfScreen(g_screen));
1083                    XFillRectangle(g_display, bs, g_gc, 0, 0, g_width, g_height);
1084                    XCopyArea(g_display, g_backstore, bs, g_gc, 0, 0, g_width, g_height, 0, 0);
1085                    XFreePixmap(g_display, g_backstore);
1086                    g_backstore = bs;
1087            }
1088    }
1089    
1090    void
1091  ui_destroy_window(void)  ui_destroy_window(void)
1092  {  {
1093          if (g_IC != NULL)          if (g_IC != NULL)
# Line 930  xwin_process_events(void) Line 1133  xwin_process_events(void)
1133          key_translation tr;          key_translation tr;
1134          char str[256];          char str[256];
1135          Status status;          Status status;
         unsigned int state;  
         Window wdummy;  
         int dummy;  
1136    
1137          while (XPending(g_display) > 0)          while (XPending(g_display) > 0)
1138          {          {
# Line 948  xwin_process_events(void) Line 1148  xwin_process_events(void)
1148    
1149                  switch (xevent.type)                  switch (xevent.type)
1150                  {                  {
1151                            case VisibilityNotify:
1152                                    g_Unobscured = xevent.xvisibility.state == VisibilityUnobscured;
1153                                    break;
1154                          case ClientMessage:                          case ClientMessage:
1155                                  /* the window manager told us to quit */                                  /* the window manager told us to quit */
1156                                  if ((xevent.xclient.message_type == g_protocol_atom)                                  if ((xevent.xclient.message_type == g_protocol_atom)
# Line 1105  xwin_process_events(void) Line 1308  xwin_process_events(void)
1308                                  if (xevent.xfocus.mode == NotifyGrab)                                  if (xevent.xfocus.mode == NotifyGrab)
1309                                          break;                                          break;
1310                                  g_focused = True;                                  g_focused = True;
1311                                  XQueryPointer(g_display, g_wnd, &wdummy, &wdummy, &dummy, &dummy,                                  reset_modifier_keys();
                                               &dummy, &dummy, &state);  
                                 reset_modifier_keys(state);  
1312                                  if (g_grab_keyboard && g_mouse_in_wnd)                                  if (g_grab_keyboard && g_mouse_in_wnd)
1313                                          XGrabKeyboard(g_display, g_wnd, True,                                          XGrabKeyboard(g_display, g_wnd, True,
1314                                                        GrabModeAsync, GrabModeAsync, CurrentTime);                                                        GrabModeAsync, GrabModeAsync, CurrentTime);
# Line 1187  xwin_process_events(void) Line 1388  xwin_process_events(void)
1388  int  int
1389  ui_select(int rdp_socket)  ui_select(int rdp_socket)
1390  {  {
1391          int n = (rdp_socket > g_x_socket) ? rdp_socket + 1 : g_x_socket + 1;          int n;
1392          fd_set rfds, wfds;          fd_set rfds, wfds;
1393            struct timeval tv;
1394            BOOL s_timeout = False;
1395    
1396          while (True)          while (True)
1397          {          {
1398                    n = (rdp_socket > g_x_socket) ? rdp_socket : g_x_socket;
1399                  /* Process any events already waiting */                  /* Process any events already waiting */
1400                  if (!xwin_process_events())                  if (!xwin_process_events())
1401                          /* User quit */                          /* User quit */
# Line 1204  ui_select(int rdp_socket) Line 1408  ui_select(int rdp_socket)
1408    
1409  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
1410                  /* FIXME: there should be an API for registering fds */                  /* FIXME: there should be an API for registering fds */
1411                  if (g_rdpsnd && g_dsp_busy)                  if (g_dsp_busy)
1412                  {                  {
1413                          FD_SET(g_dsp_fd, &wfds);                          FD_SET(g_dsp_fd, &wfds);
1414                          n = (g_dsp_fd + 1 > n) ? g_dsp_fd + 1 : n;                          n = (g_dsp_fd > n) ? g_dsp_fd : n;
1415                  }                  }
1416  #endif  #endif
1417                    /* default timeout */
1418                    tv.tv_sec = 60;
1419                    tv.tv_usec = 0;
1420    
1421                    /* add redirection handles */
1422                    rdpdr_add_fds(&n, &rfds, &wfds, &tv, &s_timeout);
1423    
1424                    n++;
1425    
1426                  switch (select(n, &rfds, &wfds, NULL, NULL))                  switch (select(n, &rfds, &wfds, NULL, &tv))
1427                  {                  {
1428                          case -1:                          case -1:
1429                                  error("select: %s\n", strerror(errno));                                  error("select: %s\n", strerror(errno));
1430    
1431                          case 0:                          case 0:
1432                                    /* TODO: if tv.tv_sec just times out
1433                                     * we will segfault.
1434                                     * FIXME:
1435                                     */
1436                                    //s_timeout = True;
1437                                    //rdpdr_check_fds(&rfds, &wfds, (BOOL) True);
1438                                  continue;                                  continue;
1439                  }                  }
1440    
1441                    rdpdr_check_fds(&rfds, &wfds, (BOOL) False);
1442    
1443                  if (FD_ISSET(rdp_socket, &rfds))                  if (FD_ISSET(rdp_socket, &rfds))
1444                          return 1;                          return 1;
1445    
1446  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
1447                  if (g_rdpsnd && g_dsp_busy && FD_ISSET(g_dsp_fd, &wfds))                  if (g_dsp_busy && FD_ISSET(g_dsp_fd, &wfds))
1448                          wave_out_play();                          wave_out_play();
1449  #endif  #endif
1450          }          }
# Line 1242  ui_create_bitmap(int width, int height, Line 1462  ui_create_bitmap(int width, int height,
1462          XImage *image;          XImage *image;
1463          Pixmap bitmap;          Pixmap bitmap;
1464          uint8 *tdata;          uint8 *tdata;
1465            int bitmap_pad;
1466    
1467            if (g_server_bpp == 8)
1468            {
1469                    bitmap_pad = 8;
1470            }
1471            else
1472            {
1473                    bitmap_pad = g_bpp;
1474    
1475                    if (g_bpp == 24)
1476                            bitmap_pad = 32;
1477            }
1478    
1479          tdata = (g_owncolmap ? data : translate_image(width, height, data));          tdata = (g_owncolmap ? data : translate_image(width, height, data));
1480          bitmap = XCreatePixmap(g_display, g_wnd, width, height, g_depth);          bitmap = XCreatePixmap(g_display, g_wnd, width, height, g_depth);
1481          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,
1482                               (char *) tdata, width, height, g_server_bpp == 8 ? 8 : g_bpp, 0);                               (char *) tdata, width, height, bitmap_pad, 0);
1483    
1484          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);
1485    
1486          XFree(image);          XFree(image);
1487          if (!g_owncolmap)          if (tdata != data)
1488                  xfree(tdata);                  xfree(tdata);
1489          return (HBITMAP) bitmap;          return (HBITMAP) bitmap;
1490  }  }
# Line 1261  ui_paint_bitmap(int x, int y, int cx, in Line 1494  ui_paint_bitmap(int x, int y, int cx, in
1494  {  {
1495          XImage *image;          XImage *image;
1496          uint8 *tdata;          uint8 *tdata;
1497            int bitmap_pad;
1498    
1499            if (g_server_bpp == 8)
1500            {
1501                    bitmap_pad = 8;
1502            }
1503            else
1504            {
1505                    bitmap_pad = g_bpp;
1506    
1507                    if (g_bpp == 24)
1508                            bitmap_pad = 32;
1509            }
1510    
1511          tdata = (g_owncolmap ? data : translate_image(width, height, data));          tdata = (g_owncolmap ? data : translate_image(width, height, data));
1512          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,
1513                               (char *) tdata, width, height, g_server_bpp == 8 ? 8 : g_bpp, 0);                               (char *) tdata, width, height, bitmap_pad, 0);
1514    
1515          if (g_ownbackstore)          if (g_ownbackstore)
1516          {          {
# Line 1276  ui_paint_bitmap(int x, int y, int cx, in Line 1523  ui_paint_bitmap(int x, int y, int cx, in
1523          }          }
1524    
1525          XFree(image);          XFree(image);
1526          if (!g_owncolmap)          if (tdata != data)
1527                  xfree(tdata);                  xfree(tdata);
1528  }  }
1529    
# Line 1402  ui_destroy_cursor(HCURSOR cursor) Line 1649  ui_destroy_cursor(HCURSOR cursor)
1649          XFreeCursor(g_display, (Cursor) cursor);          XFreeCursor(g_display, (Cursor) cursor);
1650  }  }
1651    
1652    void
1653    ui_set_null_cursor(void)
1654    {
1655            ui_set_cursor(g_null_cursor);
1656    }
1657    
1658  #define MAKE_XCOLOR(xc,c) \  #define MAKE_XCOLOR(xc,c) \
1659                  (xc)->red   = ((c)->red   << 8) | (c)->red; \                  (xc)->red   = ((c)->red   << 8) | (c)->red; \
1660                  (xc)->green = ((c)->green << 8) | (c)->green; \                  (xc)->green = ((c)->green << 8) | (c)->green; \
# Line 1483  ui_create_colourmap(COLOURMAP * colours) Line 1736  ui_create_colourmap(COLOURMAP * colours)
1736    
1737                          }                          }
1738    
1739                            map[i] = colour;
                         /* byte swap here to make translate_image faster */  
                         map[i] = translate_colour(colour);  
1740                  }                  }
1741                  return map;                  return map;
1742          }          }
# Line 1596  ui_patblt(uint8 opcode, Line 1847  ui_patblt(uint8 opcode,
1847          {          {
1848                  case 0: /* Solid */                  case 0: /* Solid */
1849                          SET_FOREGROUND(fgcolour);                          SET_FOREGROUND(fgcolour);
1850                          FILL_RECTANGLE(x, y, cx, cy);                          FILL_RECTANGLE_BACKSTORE(x, y, cx, cy);
1851                          break;                          break;
1852    
1853                  case 2: /* Hatch */                  case 2: /* Hatch */
# Line 1607  ui_patblt(uint8 opcode, Line 1858  ui_patblt(uint8 opcode,
1858                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);
1859                          XSetStipple(g_display, g_gc, fill);                          XSetStipple(g_display, g_gc, fill);
1860                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);
1861                          FILL_RECTANGLE(x, y, cx, cy);                          FILL_RECTANGLE_BACKSTORE(x, y, cx, cy);
1862                          XSetFillStyle(g_display, g_gc, FillSolid);                          XSetFillStyle(g_display, g_gc, FillSolid);
1863                          XSetTSOrigin(g_display, g_gc, 0, 0);                          XSetTSOrigin(g_display, g_gc, 0, 0);
1864                          ui_destroy_glyph((HGLYPH) fill);                          ui_destroy_glyph((HGLYPH) fill);
# Line 1617  ui_patblt(uint8 opcode, Line 1868  ui_patblt(uint8 opcode,
1868                          for (i = 0; i != 8; i++)                          for (i = 0; i != 8; i++)
1869                                  ipattern[7 - i] = brush->pattern[i];                                  ipattern[7 - i] = brush->pattern[i];
1870                          fill = (Pixmap) ui_create_glyph(8, 8, ipattern);                          fill = (Pixmap) ui_create_glyph(8, 8, ipattern);
   
1871                          SET_FOREGROUND(bgcolour);                          SET_FOREGROUND(bgcolour);
1872                          SET_BACKGROUND(fgcolour);                          SET_BACKGROUND(fgcolour);
1873                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);
1874                          XSetStipple(g_display, g_gc, fill);                          XSetStipple(g_display, g_gc, fill);
1875                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);
1876                            FILL_RECTANGLE_BACKSTORE(x, y, cx, cy);
                         FILL_RECTANGLE(x, y, cx, cy);  
   
1877                          XSetFillStyle(g_display, g_gc, FillSolid);                          XSetFillStyle(g_display, g_gc, FillSolid);
1878                          XSetTSOrigin(g_display, g_gc, 0, 0);                          XSetTSOrigin(g_display, g_gc, 0, 0);
1879                          ui_destroy_glyph((HGLYPH) fill);                          ui_destroy_glyph((HGLYPH) fill);
# Line 1636  ui_patblt(uint8 opcode, Line 1884  ui_patblt(uint8 opcode,
1884          }          }
1885    
1886          RESET_FUNCTION(opcode);          RESET_FUNCTION(opcode);
1887    
1888            if (g_ownbackstore)
1889                    XCopyArea(g_display, g_backstore, g_wnd, g_gc, x, y, cx, cy, x, y);
1890  }  }
1891    
1892  void  void
# Line 1644  ui_screenblt(uint8 opcode, Line 1895  ui_screenblt(uint8 opcode,
1895               /* src */ int srcx, int srcy)               /* src */ int srcx, int srcy)
1896  {  {
1897          SET_FUNCTION(opcode);          SET_FUNCTION(opcode);
         XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);  
1898          if (g_ownbackstore)          if (g_ownbackstore)
1899                  XCopyArea(g_display, g_backstore, g_backstore, g_gc, srcx, srcy, cx, cy, x, y);          {
1900                    if (g_Unobscured)
1901                    {
1902                            XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);
1903                            XCopyArea(g_display, g_backstore, g_backstore, g_gc, srcx, srcy, cx, cy, x,
1904                                      y);
1905                    }
1906                    else
1907                    {
1908                            XCopyArea(g_display, g_backstore, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);
1909                            XCopyArea(g_display, g_backstore, g_backstore, g_gc, srcx, srcy, cx, cy, x,
1910                                      y);
1911                    }
1912            }
1913            else
1914            {
1915                    XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);
1916            }
1917          RESET_FUNCTION(opcode);          RESET_FUNCTION(opcode);
1918  }  }
1919    
# Line 1741  ui_draw_glyph(int mixmode, Line 2008  ui_draw_glyph(int mixmode,
2008  {\  {\
2009    glyph = cache_get_font (font, ttext[idx]);\    glyph = cache_get_font (font, ttext[idx]);\
2010    if (!(flags & TEXT2_IMPLICIT_X))\    if (!(flags & TEXT2_IMPLICIT_X))\
2011      {\
2012        xyoffset = ttext[++idx];\
2013        if ((xyoffset & 0x80))\
2014      {\      {\
2015        xyoffset = ttext[++idx];\        if (flags & TEXT2_VERTICAL)\
2016        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;\  
         }\  
2017        else\        else\
2018          {\          x += ttext[idx+1] | (ttext[idx+2] << 8);\
2019            if (flags & TEXT2_VERTICAL) \        idx += 2;\
             y += xyoffset;\  
           else\  
             x += xyoffset;\  
         }\  
2020      }\      }\
2021    if (glyph != NULL)\      else\
2022      {\      {\
2023        ui_draw_glyph (mixmode, x + glyph->offset,\        if (flags & TEXT2_VERTICAL)\
2024                       y + glyph->baseline,\          y += xyoffset;\
2025                       glyph->width, glyph->height,\        else\
2026                       glyph->pixmap, 0, 0, bgcolour, fgcolour);\          x += xyoffset;\
       if (flags & TEXT2_IMPLICIT_X)\  
         x += glyph->width;\  
2027      }\      }\
2028      }\
2029      if (glyph != NULL)\
2030      {\
2031        x1 = x + glyph->offset;\
2032        y1 = y + glyph->baseline;\
2033        XSetStipple(g_display, g_gc, (Pixmap) glyph->pixmap);\
2034        XSetTSOrigin(g_display, g_gc, x1, y1);\
2035        FILL_RECTANGLE_BACKSTORE(x1, y1, glyph->width, glyph->height);\
2036        if (flags & TEXT2_IMPLICIT_X)\
2037          x += glyph->width;\
2038      }\
2039  }  }
2040    
2041  void  void
# Line 1777  ui_draw_text(uint8 font, uint8 flags, in Line 2045  ui_draw_text(uint8 font, uint8 flags, in
2045               int fgcolour, uint8 * text, uint8 length)               int fgcolour, uint8 * text, uint8 length)
2046  {  {
2047          FONTGLYPH *glyph;          FONTGLYPH *glyph;
2048          int i, j, xyoffset;          int i, j, xyoffset, x1, y1;
2049          DATABLOB *entry;          DATABLOB *entry;
2050    
2051          SET_FOREGROUND(bgcolour);          SET_FOREGROUND(bgcolour);
2052    
2053            /* Sometimes, the boxcx value is something really large, like
2054               32691. This makes XCopyArea fail with Xvnc. The code below
2055               is a quick fix. */
2056            if (boxx + boxcx > g_width)
2057                    boxcx = g_width - boxx;
2058    
2059          if (boxcx > 1)          if (boxcx > 1)
2060          {          {
2061                  FILL_RECTANGLE_BACKSTORE(boxx, boxy, boxcx, boxcy);                  FILL_RECTANGLE_BACKSTORE(boxx, boxy, boxcx, boxcy);
# Line 1791  ui_draw_text(uint8 font, uint8 flags, in Line 2065  ui_draw_text(uint8 font, uint8 flags, in
2065                  FILL_RECTANGLE_BACKSTORE(clipx, clipy, clipcx, clipcy);                  FILL_RECTANGLE_BACKSTORE(clipx, clipy, clipcx, clipcy);
2066          }          }
2067    
2068            SET_FOREGROUND(fgcolour);
2069            SET_BACKGROUND(bgcolour);
2070            XSetFillStyle(g_display, g_gc, FillStippled);
2071    
2072          /* Paint text, character by character */          /* Paint text, character by character */
2073          for (i = 0; i < length;)          for (i = 0; i < length;)
2074          {          {
# Line 1841  ui_draw_text(uint8 font, uint8 flags, in Line 2119  ui_draw_text(uint8 font, uint8 flags, in
2119                                  break;                                  break;
2120                  }                  }
2121          }          }
2122    
2123            XSetFillStyle(g_display, g_gc, FillSolid);
2124    
2125          if (g_ownbackstore)          if (g_ownbackstore)
2126          {          {
2127                  if (boxcx > 1)                  if (boxcx > 1)
# Line 1902  ui_desktop_restore(uint32 offset, int x, Line 2183  ui_desktop_restore(uint32 offset, int x,
2183    
2184          XFree(image);          XFree(image);
2185  }  }
2186    
2187    /* these do nothing here but are used in uiports */
2188    void
2189    ui_begin_update(void)
2190    {
2191    }
2192    
2193    void
2194    ui_end_update(void)
2195    {
2196    }

Legend:
Removed from v.501  
changed lines
  Added in v.713

  ViewVC Help
Powered by ViewVC 1.1.26