/[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 483 by jsorg71, Sat Oct 11 19:12:10 2003 UTC revision 695 by stargo, Tue May 11 07:34:03 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 69  static int g_move_y_offset = 0; Line 78  static int g_move_y_offset = 0;
78  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
79  extern int g_dsp_fd;  extern int g_dsp_fd;
80  extern BOOL g_dsp_busy;  extern BOOL g_dsp_busy;
81    extern BOOL g_rdpsnd;
82  #endif  #endif
83    
84  /* MWM decorations */  /* MWM decorations */
# Line 106  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 162  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 175  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 189  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 291  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++)]; out += 2;
256                    )
257            else if (g_xserver_be)
258            {
259                    while (out < end)
260                    {
261                            value = (uint16) g_colmap[*(data++)];
262                            *(out++) = value >> 8;
263                            *(out++) = value;
264                    }
265            }
266            else
267            {
268                    while (out < end)
269                    {
270                            value = (uint16) g_colmap[*(data++)];
271                            *(out++) = value;
272                            *(out++) = value >> 8;
273                    }
274            }
275  }  }
276    
277  /* little endian - conversion happens when colourmap is built */  /* little endian - conversion happens when colourmap is built */
# Line 303  translate8to24(uint8 * data, uint8 * out Line 280  translate8to24(uint8 * data, uint8 * out
280  {  {
281          uint32 value;          uint32 value;
282    
283          while (out < end)          if (g_xserver_be)
284          {          {
285                  value = g_colmap[*(data++)];                  while (out < end)
286                  *(out++) = value;                  {
287                  *(out++) = value >> 8;                          value = g_colmap[*(data++)];
288                  *(out++) = value >> 16;                          *(out++) = value >> 16;
289                            *(out++) = value >> 8;
290                            *(out++) = value;
291                    }
292            }
293            else
294            {
295                    while (out < end)
296                    {
297                            value = g_colmap[*(data++)];
298                            *(out++) = value;
299                            *(out++) = value >> 8;
300                            *(out++) = value >> 16;
301                    }
302          }          }
303  }  }
304    
305  static void  static void
306  translate8to32(uint8 * data, uint32 * out, uint32 * end)  translate8to32(uint8 * data, uint8 * out, uint8 * end)
307  {  {
308          while (out < end)          uint32 value;
                 *(out++) = g_colmap[*(data++)];  
 }  
309    
310  /* todo the remaining translate function might need some big endian check ?? */          if (g_arch_match)
311                    REPEAT(*((uint32 *)out) = g_colmap[*(data++)]; out += 4;
312                    )
313            else if (g_xserver_be)
314            {
315                    while (out < end)
316                    {
317                            value = g_colmap[*(data++)];
318                            *(out++) = value >> 24;
319                            *(out++) = value >> 16;
320                            *(out++) = value >> 8;
321                            *(out++) = value;
322                    }
323            }
324            else
325            {
326                    while (out < end)
327                    {
328                            value = g_colmap[*(data++)];
329                            *(out++) = value;
330                            *(out++) = value >> 8;
331                            *(out++) = value >> 16;
332                            *(out++) = value >> 24;
333                    }
334            }
335    }
336    
337  static void  static void
338  translate15to16(uint16 * data, uint8 * out, uint8 * end)  translate15to16(uint16 * data, uint8 * out, uint8 * end)
# Line 333  translate15to16(uint16 * data, uint8 * o Line 346  translate15to16(uint16 * data, uint8 * o
346    
347                  if (g_host_be)                  if (g_host_be)
348                  {                  {
349                          BSWAP16(pixel)                          BSWAP16(pixel);
350                  }                  }
351    
352                  value = make_colour16(split_colour15(pixel));                  value = make_colour(split_colour15(pixel));
353    
354                  if (g_xserver_be)                  if (g_xserver_be)
355                  {                  {
# Line 363  translate15to24(uint16 * data, uint8 * o Line 376  translate15to24(uint16 * data, uint8 * o
376    
377                  if (g_host_be)                  if (g_host_be)
378                  {                  {
379                          BSWAP16(pixel)                          BSWAP16(pixel);
380                  }                  }
381    
382                  value = make_colour24(split_colour15(pixel));                  value = make_colour(split_colour15(pixel));
383                  if (g_xserver_be)                  if (g_xserver_be)
384                  {                  {
385                          *(out++) = value >> 16;                          *(out++) = value >> 16;
# Line 397  translate15to32(uint16 * data, uint8 * o Line 410  translate15to32(uint16 * data, uint8 * o
410                          BSWAP16(pixel);                          BSWAP16(pixel);
411                  }                  }
412    
413                  value = make_colour32(split_colour15(pixel));                  value = make_colour(split_colour15(pixel));
414    
415                  if (g_xserver_be)                  if (g_xserver_be)
416                  {                  {
# Line 417  translate15to32(uint16 * data, uint8 * o Line 430  translate15to32(uint16 * data, uint8 * o
430  }  }
431    
432  static void  static void
433  translate16to16(uint16 * data, uint16 * out, uint16 * end)  translate16to16(uint16 * data, uint8 * out, uint8 * end)
434  {  {
435            uint16 pixel;
436          uint16 value;          uint16 value;
437    
438          if (g_xserver_be)          while (out < end)
439          {          {
440                  while (out < end)                  pixel = *(data++);
441    
442                    if (g_host_be)
443                  {                  {
444                          value = *data;                          BSWAP16(pixel);
                         BSWAP16(value);  
                         *out = value;  
                         data++;  
                         out++;  
445                  }                  }
446    
447          }                  value = make_colour(split_colour16(pixel));
448          else  
449          {                  if (g_xserver_be)
450                  while (out < end)                  {
451                            *(out++) = value >> 8;
452                            *(out++) = value;
453                    }
454                    else
455                  {                  {
456                          *out = *data;                          *(out++) = value;
457                          out++;                          *(out++) = value >> 8;
                         data++;  
458                  }                  }
459          }          }
460  }  }
461    
   
462  static void  static void
463  translate16to24(uint16 * data, uint8 * out, uint8 * end)  translate16to24(uint16 * data, uint8 * out, uint8 * end)
464  {  {
# Line 457  translate16to24(uint16 * data, uint8 * o Line 471  translate16to24(uint16 * data, uint8 * o
471    
472                  if (g_host_be)                  if (g_host_be)
473                  {                  {
474                          BSWAP16(pixel)                          BSWAP16(pixel);
475                  }                  }
476    
477                  value = make_colour24(split_colour16(pixel));                  value = make_colour(split_colour16(pixel));
478    
479                  if (g_xserver_be)                  if (g_xserver_be)
480                  {                  {
# Line 489  translate16to32(uint16 * data, uint8 * o Line 503  translate16to32(uint16 * data, uint8 * o
503    
504                  if (g_host_be)                  if (g_host_be)
505                  {                  {
506                          BSWAP16(pixel)                          BSWAP16(pixel);
507                  }                  }
508    
509                  value = make_colour32(split_colour16(pixel));                  value = make_colour(split_colour16(pixel));
510    
511                  if (g_xserver_be)                  if (g_xserver_be)
512                  {                  {
# Line 500  translate16to32(uint16 * data, uint8 * o Line 514  translate16to32(uint16 * data, uint8 * o
514                          *(out++) = value >> 16;                          *(out++) = value >> 16;
515                          *(out++) = value >> 8;                          *(out++) = value >> 8;
516                          *(out++) = value;                          *(out++) = value;
517                  }                  }
518                  else                  else
519                  {                  {
520                          *(out++) = value;                          *(out++) = value;
521                          *(out++) = value >> 8;                          *(out++) = value >> 8;
522                          *(out++) = value >> 16;                          *(out++) = value >> 16;
523                          *(out++) = value >> 24;                          *(out++) = value >> 24;
524                  }                  }
525          }          }
526  }  }
527    
528  static void  static void
# Line 522  translate24to16(uint8 * data, uint8 * ou Line 536  translate24to16(uint8 * data, uint8 * ou
536                  pixel |= *(data++) << 8;                  pixel |= *(data++) << 8;
537                  pixel |= *(data++);                  pixel |= *(data++);
538    
539                  value = (uint16) make_colour16(split_colour24(pixel));                  value = (uint16) make_colour(split_colour24(pixel));
540    
541                  if (g_xserver_be)                  if (g_xserver_be)
542                  {                  {
# Line 540  translate24to16(uint8 * data, uint8 * ou Line 554  translate24to16(uint8 * data, uint8 * ou
554  static void  static void
555  translate24to24(uint8 * data, uint8 * out, uint8 * end)  translate24to24(uint8 * data, uint8 * out, uint8 * end)
556  {  {
557            uint32 pixel;
558            uint32 value;
559    
560          while (out < end)          while (out < end)
561          {          {
562                  *(out++) = (*(data++));                  pixel = *(data++) << 16;
563                    pixel |= *(data++) << 8;
564                    pixel |= *(data++);
565    
566                    value = make_colour(split_colour24(pixel));
567    
568                    if (g_xserver_be)
569                    {
570                            *(out++) = value >> 16;
571                            *(out++) = value >> 8;
572                            *(out++) = value;
573                    }
574                    else
575                    {
576                            *(out++) = value;
577                            *(out++) = value >> 8;
578                            *(out++) = value >> 16;
579                    }
580          }          }
581  }  }
582    
583  static void  static void
584  translate24to32(uint8 * data, uint8 * out, uint8 * end)  translate24to32(uint8 * data, uint8 * out, uint8 * end)
585  {  {
586            uint32 pixel;
587            uint32 value;
588    
589          while (out < end)          while (out < end)
590          {          {
591                    pixel = *(data++) << 16;
592                    pixel |= *(data++) << 8;
593                    pixel |= *(data++);
594    
595                    value = make_colour(split_colour24(pixel));
596    
597                  if (g_xserver_be)                  if (g_xserver_be)
598                  {                  {
599                          *(out++) = 0x00;                          *(out++) = value >> 24;
600                          *(out++) = *(data++);                          *(out++) = value >> 16;
601                          *(out++) = *(data++);                          *(out++) = value >> 8;
602                          *(out++) = *(data++);                          *(out++) = value;
603                  }                  }
604                  else                  else
605                  {                  {
606                          *(out++) = *(data++);                          *(out++) = value;
607                          *(out++) = *(data++);                          *(out++) = value >> 8;
608                          *(out++) = *(data++);                          *(out++) = value >> 16;
609                          *(out++) = 0x00;                          *(out++) = value >> 24;
610                  }                  }
611          }          }
612  }  }
# Line 571  translate24to32(uint8 * data, uint8 * ou Line 614  translate24to32(uint8 * data, uint8 * ou
614  static uint8 *  static uint8 *
615  translate_image(int width, int height, uint8 * data)  translate_image(int width, int height, uint8 * data)
616  {  {
617          int size = width * height * g_bpp / 8;          int size;
618          uint8 *out = (uint8 *) xmalloc(size);          uint8 *out;
619          uint8 *end = out + size;          uint8 *end;
620    
621            /* if server and xserver bpp match, */
622            /* and arch(endian) matches, no need to translate */
623            /* just return data */
624            if (g_arch_match)
625            {
626                    if (g_depth == 15 && g_server_bpp == 15)
627                            return data;
628                    if (g_depth == 16 && g_server_bpp == 16)
629                            return data;
630            }
631    
632            size = width * height * (g_bpp / 8);
633            out = (uint8 *) xmalloc(size);
634            end = out + size;
635    
636          switch (g_server_bpp)          switch (g_server_bpp)
637          {          {
# Line 601  translate_image(int width, int height, u Line 659  translate_image(int width, int height, u
659                                          translate16to24((uint16 *) data, out, end);                                          translate16to24((uint16 *) data, out, end);
660                                          break;                                          break;
661                                  case 16:                                  case 16:
662                                          translate16to16((uint16 *) data, (uint16 *) out,                                          translate16to16((uint16 *) data, out, end);
                                                         (uint16 *) end);  
663                                          break;                                          break;
664                          }                          }
665                          break;                          break;
# Line 627  translate_image(int width, int height, u Line 684  translate_image(int width, int height, u
684                                          translate8to8(data, out, end);                                          translate8to8(data, out, end);
685                                          break;                                          break;
686                                  case 16:                                  case 16:
687                                          translate8to16(data, (uint16 *) out, (uint16 *) end);                                          translate8to16(data, out, end);
688                                          break;                                          break;
689                                  case 24:                                  case 24:
690                                          translate8to24(data, out, end);                                          translate8to24(data, out, end);
691                                          break;                                          break;
692                                  case 32:                                  case 32:
693                                          translate8to32(data, (uint32 *) out, (uint32 *) end);                                          translate8to32(data, out, end);
694                                          break;                                          break;
695                          }                          }
696                          break;                          break;
# Line 666  get_key_state(unsigned int state, uint32 Line 723  get_key_state(unsigned int state, uint32
723          return (state & keysymMask) ? True : False;          return (state & keysymMask) ? True : False;
724  }  }
725    
726    static void
727    calculate_shifts(uint32 mask, int *shift_r, int *shift_l)
728    {
729            *shift_l = ffs(mask) - 1;
730            mask >>= *shift_l;
731            *shift_r = 8 - ffs(mask & ~(mask >> 1));
732    }
733    
734  BOOL  BOOL
735  ui_init(void)  ui_init(void)
736  {  {
737            XVisualInfo vi;
738          XPixmapFormatValues *pfm;          XPixmapFormatValues *pfm;
739          uint16 test;          uint16 test;
740          int i;          int i, screen_num, nvisuals;
741            XVisualInfo *vmatches = NULL;
742            XVisualInfo template;
743            Bool TrueColorVisual = False;
744    
745          g_display = XOpenDisplay(NULL);          g_display = XOpenDisplay(NULL);
746          if (g_display == NULL)          if (g_display == NULL)
# Line 680  ui_init(void) Line 749  ui_init(void)
749                  return False;                  return False;
750          }          }
751    
752            screen_num = DefaultScreen(g_display);
753          g_x_socket = ConnectionNumber(g_display);          g_x_socket = ConnectionNumber(g_display);
754          g_screen = DefaultScreenOfDisplay(g_display);          g_screen = ScreenOfDisplay(g_display, screen_num);
         g_visual = DefaultVisualOfScreen(g_screen);  
755          g_depth = DefaultDepthOfScreen(g_screen);          g_depth = DefaultDepthOfScreen(g_screen);
756    
757            /* Search for best TrueColor depth */
758            template.class = TrueColor;
759            vmatches = XGetVisualInfo(g_display, VisualClassMask, &template, &nvisuals);
760    
761            nvisuals--;
762            while (nvisuals >= 0)
763            {
764                    if ((vmatches + nvisuals)->depth > g_depth)
765                    {
766                            g_depth = (vmatches + nvisuals)->depth;
767                    }
768                    nvisuals--;
769                    TrueColorVisual = True;
770            }
771    
772            test = 1;
773            g_host_be = !(BOOL) (*(uint8 *) (&test));
774            g_xserver_be = (ImageByteOrder(g_display) == MSBFirst);
775    
776            if ((g_server_bpp == 8) && ((!TrueColorVisual) || (g_depth <= 8)))
777            {
778                    /* we use a colourmap, so the default visual should do */
779                    g_visual = DefaultVisualOfScreen(g_screen);
780                    g_depth = DefaultDepthOfScreen(g_screen);
781    
782                    /* Do not allocate colours on a TrueColor visual */
783                    if (g_visual->class == TrueColor)
784                    {
785                            g_owncolmap = False;
786                    }
787            }
788            else
789            {
790                    /* need a truecolour visual */
791                    if (!XMatchVisualInfo(g_display, screen_num, g_depth, TrueColor, &vi))
792                    {
793                            error("The display does not support true colour - high colour support unavailable.\n");
794                            return False;
795                    }
796    
797                    g_visual = vi.visual;
798                    g_owncolmap = False;
799                    calculate_shifts(vi.red_mask, &g_red_shift_r, &g_red_shift_l);
800                    calculate_shifts(vi.blue_mask, &g_blue_shift_r, &g_blue_shift_l);
801                    calculate_shifts(vi.green_mask, &g_green_shift_r, &g_green_shift_l);
802    
803                    /* if RGB video and averything is little endian */
804                    if (vi.red_mask > vi.green_mask && vi.green_mask > vi.blue_mask)
805                            if (!g_xserver_be && !g_host_be)
806                                    g_arch_match = True;
807            }
808    
809          pfm = XListPixmapFormats(g_display, &i);          pfm = XListPixmapFormats(g_display, &i);
810          if (pfm != NULL)          if (pfm != NULL)
811          {          {
# Line 707  ui_init(void) Line 828  ui_init(void)
828                  return False;                  return False;
829          }          }
830    
831          if (g_owncolmap != True)          if (!g_owncolmap)
832          {          {
833                  g_xcolmap = DefaultColormapOfScreen(g_screen);                  g_xcolmap =
834                            XCreateColormap(g_display, RootWindowOfScreen(g_screen), g_visual,
835                                            AllocNone);
836                  if (g_depth <= 8)                  if (g_depth <= 8)
837                          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");
838          }          }
839    
840          g_gc = XCreateGC(g_display, RootWindowOfScreen(g_screen), 0, NULL);          if ((!g_ownbackstore) && (DoesBackingStore(g_screen) != Always))
841            {
842          if (DoesBackingStore(g_screen) != Always)                  warning("External BackingStore not available, using internal\n");
843                  g_ownbackstore = True;                  g_ownbackstore = True;
844            }
845    
846          test = 1;          /*
847          g_host_be = !(BOOL) (*(uint8 *) (&test));           * Determine desktop size
848          g_xserver_be = (ImageByteOrder(g_display) == MSBFirst);           */
849            if (g_fullscreen)
850          if ((g_width == 0) || (g_height == 0))          {
851                    g_width = WidthOfScreen(g_screen);
852                    g_height = HeightOfScreen(g_screen);
853            }
854            else if (g_width < 0)
855            {
856                    /* Percent of screen */
857                    g_height = HeightOfScreen(g_screen) * (-g_width) / 100;
858                    g_width = WidthOfScreen(g_screen) * (-g_width) / 100;
859            }
860            else if (g_width == 0)
861          {          {
862                  /* Fetch geometry from _NET_WORKAREA */                  /* Fetch geometry from _NET_WORKAREA */
863                  uint32 x, y, cx, cy;                  uint32 x, y, cx, cy;
# Line 741  ui_init(void) Line 875  ui_init(void)
875                  }                  }
876          }          }
877    
         if (g_fullscreen)  
         {  
                 g_width = WidthOfScreen(g_screen);  
                 g_height = HeightOfScreen(g_screen);  
         }  
   
878          /* make sure width is a multiple of 4 */          /* make sure width is a multiple of 4 */
879          g_width = (g_width + 3) & ~3;          g_width = (g_width + 3) & ~3;
880    
         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);  
         }  
   
881          g_mod_map = XGetModifierMapping(g_display);          g_mod_map = XGetModifierMapping(g_display);
882    
883            xkeymap_init();
884    
885          if (g_enable_compose)          if (g_enable_compose)
886                  g_IM = XOpenIM(g_display, NULL, NULL, NULL);                  g_IM = XOpenIM(g_display, NULL, NULL, NULL);
887    
         xkeymap_init();  
888          xclip_init();          xclip_init();
889    
890          /* 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);  
891    
892          return True;          return True;
893  }  }
# Line 781  ui_deinit(void) Line 898  ui_deinit(void)
898          if (g_IM != NULL)          if (g_IM != NULL)
899                  XCloseIM(g_IM);                  XCloseIM(g_IM);
900    
901            if (g_null_cursor != NULL)
902                    ui_destroy_cursor(g_null_cursor);
903    
904          XFreeModifiermap(g_mod_map);          XFreeModifiermap(g_mod_map);
905    
906          if (g_ownbackstore)          if (g_ownbackstore)
# Line 794  ui_deinit(void) Line 914  ui_deinit(void)
914  BOOL  BOOL
915  ui_create_window(void)  ui_create_window(void)
916  {  {
917            uint8 null_pointer_mask[1] = { 0x80 };
918            uint8 null_pointer_data[4] = { 0x00, 0x00, 0x00, 0x00 };
919          XSetWindowAttributes attribs;          XSetWindowAttributes attribs;
920          XClassHint *classhints;          XClassHint *classhints;
921          XSizeHints *sizehints;          XSizeHints *sizehints;
# Line 805  ui_create_window(void) Line 927  ui_create_window(void)
927          wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height;          wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height;
928    
929          attribs.background_pixel = BlackPixelOfScreen(g_screen);          attribs.background_pixel = BlackPixelOfScreen(g_screen);
930            attribs.border_pixel = WhitePixelOfScreen(g_screen);
931          attribs.backing_store = g_ownbackstore ? NotUseful : Always;          attribs.backing_store = g_ownbackstore ? NotUseful : Always;
932          attribs.override_redirect = g_fullscreen;          attribs.override_redirect = g_fullscreen;
933            attribs.colormap = g_xcolmap;
934    
935          g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), 0, 0, wndwidth, wndheight,          g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), 0, 0, wndwidth, wndheight,
936                                0, CopyFromParent, InputOutput, CopyFromParent,                                0, g_depth, InputOutput, g_visual,
937                                CWBackPixel | CWBackingStore | CWOverrideRedirect, &attribs);                                CWBackPixel | CWBackingStore | CWOverrideRedirect |
938                                  CWColormap | CWBorderPixel, &attribs);
939    
940            if (g_gc == NULL)
941                    g_gc = XCreateGC(g_display, g_wnd, 0, NULL);
942    
943            if ((g_ownbackstore) && (g_backstore == 0))
944            {
945                    g_backstore = XCreatePixmap(g_display, g_wnd, g_width, g_height, g_depth);
946    
947                    /* clear to prevent rubbish being exposed at startup */
948                    XSetForeground(g_display, g_gc, BlackPixelOfScreen(g_screen));
949                    XFillRectangle(g_display, g_backstore, g_gc, 0, 0, g_width, g_height);
950            }
951    
952          XStoreName(g_display, g_wnd, g_title);          XStoreName(g_display, g_wnd, g_title);
953    
# Line 835  ui_create_window(void) Line 972  ui_create_window(void)
972                  XFree(sizehints);                  XFree(sizehints);
973          }          }
974    
975            if (g_embed_wnd)
976            {
977                    XReparentWindow(g_display, g_wnd, (Window) g_embed_wnd, 0, 0);
978            }
979    
980          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
981                  VisibilityChangeMask | FocusChangeMask;                  VisibilityChangeMask | FocusChangeMask;
982    
# Line 866  ui_create_window(void) Line 1008  ui_create_window(void)
1008                  XMaskEvent(g_display, VisibilityChangeMask, &xevent);                  XMaskEvent(g_display, VisibilityChangeMask, &xevent);
1009          }          }
1010          while (xevent.type != VisibilityNotify);          while (xevent.type != VisibilityNotify);
1011            g_Unobscured = xevent.xvisibility.state == VisibilityUnobscured;
1012    
1013          g_focused = False;          g_focused = False;
1014          g_mouse_in_wnd = False;          g_mouse_in_wnd = False;
# Line 875  ui_create_window(void) Line 1018  ui_create_window(void)
1018          g_kill_atom = XInternAtom(g_display, "WM_DELETE_WINDOW", True);          g_kill_atom = XInternAtom(g_display, "WM_DELETE_WINDOW", True);
1019          XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1);          XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1);
1020    
1021            /* create invisible 1x1 cursor to be used as null cursor */
1022            if (g_null_cursor == NULL)
1023                    g_null_cursor = ui_create_cursor(0, 0, 1, 1, null_pointer_mask, null_pointer_data);
1024    
1025          return True;          return True;
1026  }  }
1027    
1028  void  void
1029    ui_resize_window()
1030    {
1031            XSizeHints *sizehints;
1032    
1033            sizehints = XAllocSizeHints();
1034            if (sizehints)
1035            {
1036                    sizehints->flags = PMinSize | PMaxSize;
1037                    sizehints->min_width = sizehints->max_width = g_width;
1038                    sizehints->min_height = sizehints->max_height = g_height;
1039                    XSetWMNormalHints(g_display, g_wnd, sizehints);
1040                    XFree(sizehints);
1041            }
1042    
1043            if (!(g_fullscreen || g_embed_wnd))
1044            {
1045                    XResizeWindow(g_display, g_wnd, g_width, g_height);
1046            }
1047    }
1048    
1049    void
1050  ui_destroy_window(void)  ui_destroy_window(void)
1051  {  {
1052          if (g_IC != NULL)          if (g_IC != NULL)
# Line 924  xwin_process_events(void) Line 1092  xwin_process_events(void)
1092          key_translation tr;          key_translation tr;
1093          char str[256];          char str[256];
1094          Status status;          Status status;
         unsigned int state;  
         Window wdummy;  
         int dummy;  
1095    
1096          while (XPending(g_display) > 0)          while (XPending(g_display) > 0)
1097          {          {
# Line 942  xwin_process_events(void) Line 1107  xwin_process_events(void)
1107    
1108                  switch (xevent.type)                  switch (xevent.type)
1109                  {                  {
1110                            case VisibilityNotify:
1111                                    g_Unobscured = xevent.xvisibility.state == VisibilityUnobscured;
1112                                    break;
1113                          case ClientMessage:                          case ClientMessage:
1114                                  /* the window manager told us to quit */                                  /* the window manager told us to quit */
1115                                  if ((xevent.xclient.message_type == g_protocol_atom)                                  if ((xevent.xclient.message_type == g_protocol_atom)
# Line 1099  xwin_process_events(void) Line 1267  xwin_process_events(void)
1267                                  if (xevent.xfocus.mode == NotifyGrab)                                  if (xevent.xfocus.mode == NotifyGrab)
1268                                          break;                                          break;
1269                                  g_focused = True;                                  g_focused = True;
1270                                  XQueryPointer(g_display, g_wnd, &wdummy, &wdummy, &dummy, &dummy,                                  reset_modifier_keys();
                                               &dummy, &dummy, &state);  
                                 reset_modifier_keys(state);  
1271                                  if (g_grab_keyboard && g_mouse_in_wnd)                                  if (g_grab_keyboard && g_mouse_in_wnd)
1272                                          XGrabKeyboard(g_display, g_wnd, True,                                          XGrabKeyboard(g_display, g_wnd, True,
1273                                                        GrabModeAsync, GrabModeAsync, CurrentTime);                                                        GrabModeAsync, GrabModeAsync, CurrentTime);
# Line 1181  xwin_process_events(void) Line 1347  xwin_process_events(void)
1347  int  int
1348  ui_select(int rdp_socket)  ui_select(int rdp_socket)
1349  {  {
1350          int n = (rdp_socket > g_x_socket) ? rdp_socket + 1 : g_x_socket + 1;          int n;
1351          fd_set rfds, wfds;          fd_set rfds, wfds;
1352            struct timeval tv;
1353            BOOL s_timeout = False;
1354    
1355          while (True)          while (True)
1356          {          {
1357                    n = (rdp_socket > g_x_socket) ? rdp_socket : g_x_socket;
1358                  /* Process any events already waiting */                  /* Process any events already waiting */
1359                  if (!xwin_process_events())                  if (!xwin_process_events())
1360                          /* User quit */                          /* User quit */
# Line 1201  ui_select(int rdp_socket) Line 1370  ui_select(int rdp_socket)
1370                  if (g_dsp_busy)                  if (g_dsp_busy)
1371                  {                  {
1372                          FD_SET(g_dsp_fd, &wfds);                          FD_SET(g_dsp_fd, &wfds);
1373                          n = (g_dsp_fd + 1 > n) ? g_dsp_fd + 1 : n;                          n = (g_dsp_fd > n) ? g_dsp_fd : n;
1374                  }                  }
1375  #endif  #endif
1376                    /* default timeout */
1377                    tv.tv_sec = 60;
1378                    tv.tv_usec = 0;
1379    
1380                  switch (select(n, &rfds, &wfds, NULL, NULL))                  /* add redirection handles */
1381                    rdpdr_add_fds(&n, &rfds, &wfds, &tv, &s_timeout);
1382    
1383                    n++;
1384    
1385                    switch (select(n, &rfds, &wfds, NULL, &tv))
1386                  {                  {
1387                          case -1:                          case -1:
1388                                  error("select: %s\n", strerror(errno));                                  error("select: %s\n", strerror(errno));
1389    
1390                          case 0:                          case 0:
1391                                    /* TODO: if tv.tv_sec just times out
1392                                     * we will segfault.
1393                                     * FIXME:
1394                                     */
1395                                    //s_timeout = True;
1396                                    //rdpdr_check_fds(&rfds, &wfds, (BOOL) True);
1397                                  continue;                                  continue;
1398                  }                  }
1399    
1400                    rdpdr_check_fds(&rfds, &wfds, (BOOL) False);
1401    
1402                  if (FD_ISSET(rdp_socket, &rfds))                  if (FD_ISSET(rdp_socket, &rfds))
1403                          return 1;                          return 1;
1404    
# Line 1236  ui_create_bitmap(int width, int height, Line 1421  ui_create_bitmap(int width, int height,
1421          XImage *image;          XImage *image;
1422          Pixmap bitmap;          Pixmap bitmap;
1423          uint8 *tdata;          uint8 *tdata;
1424            int bitmap_pad;
1425    
1426            if (g_server_bpp == 8)
1427            {
1428                    bitmap_pad = 8;
1429            }
1430            else
1431            {
1432                    bitmap_pad = g_bpp;
1433    
1434                    if (g_bpp == 24)
1435                            bitmap_pad = 32;
1436            }
1437    
1438          tdata = (g_owncolmap ? data : translate_image(width, height, data));          tdata = (g_owncolmap ? data : translate_image(width, height, data));
1439          bitmap = XCreatePixmap(g_display, g_wnd, width, height, g_depth);          bitmap = XCreatePixmap(g_display, g_wnd, width, height, g_depth);
1440          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,
1441                               (char *) tdata, width, height, g_server_bpp == 8 ? 8 : g_bpp, 0);                               (char *) tdata, width, height, bitmap_pad, 0);
1442    
1443          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);
1444    
1445          XFree(image);          XFree(image);
1446          if (!g_owncolmap)          if (tdata != data)
1447                  xfree(tdata);                  xfree(tdata);
1448          return (HBITMAP) bitmap;          return (HBITMAP) bitmap;
1449  }  }
# Line 1255  ui_paint_bitmap(int x, int y, int cx, in Line 1453  ui_paint_bitmap(int x, int y, int cx, in
1453  {  {
1454          XImage *image;          XImage *image;
1455          uint8 *tdata;          uint8 *tdata;
1456            int bitmap_pad;
1457    
1458            if (g_server_bpp == 8)
1459            {
1460                    bitmap_pad = 8;
1461            }
1462            else
1463            {
1464                    bitmap_pad = g_bpp;
1465    
1466                    if (g_bpp == 24)
1467                            bitmap_pad = 32;
1468            }
1469    
1470          tdata = (g_owncolmap ? data : translate_image(width, height, data));          tdata = (g_owncolmap ? data : translate_image(width, height, data));
1471          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,
1472                               (char *) tdata, width, height, g_server_bpp == 8 ? 8 : g_bpp, 0);                               (char *) tdata, width, height, bitmap_pad, 0);
1473    
1474          if (g_ownbackstore)          if (g_ownbackstore)
1475          {          {
# Line 1270  ui_paint_bitmap(int x, int y, int cx, in Line 1482  ui_paint_bitmap(int x, int y, int cx, in
1482          }          }
1483    
1484          XFree(image);          XFree(image);
1485          if (!g_owncolmap)          if (tdata != data)
1486                  xfree(tdata);                  xfree(tdata);
1487  }  }
1488    
# Line 1396  ui_destroy_cursor(HCURSOR cursor) Line 1608  ui_destroy_cursor(HCURSOR cursor)
1608          XFreeCursor(g_display, (Cursor) cursor);          XFreeCursor(g_display, (Cursor) cursor);
1609  }  }
1610    
1611    void
1612    ui_set_null_cursor(void)
1613    {
1614            ui_set_cursor(g_null_cursor);
1615    }
1616    
1617  #define MAKE_XCOLOR(xc,c) \  #define MAKE_XCOLOR(xc,c) \
1618                  (xc)->red   = ((c)->red   << 8) | (c)->red; \                  (xc)->red   = ((c)->red   << 8) | (c)->red; \
1619                  (xc)->green = ((c)->green << 8) | (c)->green; \                  (xc)->green = ((c)->green << 8) | (c)->green; \
# Line 1477  ui_create_colourmap(COLOURMAP * colours) Line 1695  ui_create_colourmap(COLOURMAP * colours)
1695    
1696                          }                          }
1697    
1698                            map[i] = colour;
                         /* byte swap here to make translate_image faster */  
                         map[i] = translate_colour(colour);  
1699                  }                  }
1700                  return map;                  return map;
1701          }          }
# Line 1590  ui_patblt(uint8 opcode, Line 1806  ui_patblt(uint8 opcode,
1806          {          {
1807                  case 0: /* Solid */                  case 0: /* Solid */
1808                          SET_FOREGROUND(fgcolour);                          SET_FOREGROUND(fgcolour);
1809                          FILL_RECTANGLE(x, y, cx, cy);                          FILL_RECTANGLE_BACKSTORE(x, y, cx, cy);
1810                          break;                          break;
1811    
1812                  case 2: /* Hatch */                  case 2: /* Hatch */
1813                          fill = (Pixmap) ui_create_glyph(8, 8,                          fill = (Pixmap) ui_create_glyph(8, 8,
1814                                                          hatch_patterns + brush->pattern[0] * 8);                                                          hatch_patterns + brush->pattern[0] * 8);
1815                          SET_FOREGROUND(bgcolour);                          SET_FOREGROUND(fgcolour);
1816                          SET_BACKGROUND(fgcolour);                          SET_BACKGROUND(bgcolour);
1817                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);
1818                          XSetStipple(g_display, g_gc, fill);                          XSetStipple(g_display, g_gc, fill);
1819                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);
1820                          FILL_RECTANGLE(x, y, cx, cy);                          FILL_RECTANGLE_BACKSTORE(x, y, cx, cy);
1821                          XSetFillStyle(g_display, g_gc, FillSolid);                          XSetFillStyle(g_display, g_gc, FillSolid);
1822                          XSetTSOrigin(g_display, g_gc, 0, 0);                          XSetTSOrigin(g_display, g_gc, 0, 0);
1823                          ui_destroy_glyph((HGLYPH) fill);                          ui_destroy_glyph((HGLYPH) fill);
# Line 1611  ui_patblt(uint8 opcode, Line 1827  ui_patblt(uint8 opcode,
1827                          for (i = 0; i != 8; i++)                          for (i = 0; i != 8; i++)
1828                                  ipattern[7 - i] = brush->pattern[i];                                  ipattern[7 - i] = brush->pattern[i];
1829                          fill = (Pixmap) ui_create_glyph(8, 8, ipattern);                          fill = (Pixmap) ui_create_glyph(8, 8, ipattern);
   
1830                          SET_FOREGROUND(bgcolour);                          SET_FOREGROUND(bgcolour);
1831                          SET_BACKGROUND(fgcolour);                          SET_BACKGROUND(fgcolour);
1832                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);
1833                          XSetStipple(g_display, g_gc, fill);                          XSetStipple(g_display, g_gc, fill);
1834                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);
1835                            FILL_RECTANGLE_BACKSTORE(x, y, cx, cy);
                         FILL_RECTANGLE(x, y, cx, cy);  
   
1836                          XSetFillStyle(g_display, g_gc, FillSolid);                          XSetFillStyle(g_display, g_gc, FillSolid);
1837                          XSetTSOrigin(g_display, g_gc, 0, 0);                          XSetTSOrigin(g_display, g_gc, 0, 0);
1838                          ui_destroy_glyph((HGLYPH) fill);                          ui_destroy_glyph((HGLYPH) fill);
# Line 1630  ui_patblt(uint8 opcode, Line 1843  ui_patblt(uint8 opcode,
1843          }          }
1844    
1845          RESET_FUNCTION(opcode);          RESET_FUNCTION(opcode);
1846    
1847            if (g_ownbackstore)
1848                    XCopyArea(g_display, g_backstore, g_wnd, g_gc, x, y, cx, cy, x, y);
1849  }  }
1850    
1851  void  void
# Line 1638  ui_screenblt(uint8 opcode, Line 1854  ui_screenblt(uint8 opcode,
1854               /* src */ int srcx, int srcy)               /* src */ int srcx, int srcy)
1855  {  {
1856          SET_FUNCTION(opcode);          SET_FUNCTION(opcode);
         XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);  
1857          if (g_ownbackstore)          if (g_ownbackstore)
1858                  XCopyArea(g_display, g_backstore, g_backstore, g_gc, srcx, srcy, cx, cy, x, y);          {
1859                    if (g_Unobscured)
1860                    {
1861                            XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);
1862                            XCopyArea(g_display, g_backstore, g_backstore, g_gc, srcx, srcy, cx, cy, x,
1863                                      y);
1864                    }
1865                    else
1866                    {
1867                            XCopyArea(g_display, g_backstore, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);
1868                            XCopyArea(g_display, g_backstore, g_backstore, g_gc, srcx, srcy, cx, cy, x,
1869                                      y);
1870                    }
1871            }
1872            else
1873            {
1874                    XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);
1875            }
1876          RESET_FUNCTION(opcode);          RESET_FUNCTION(opcode);
1877  }  }
1878    
# Line 1735  ui_draw_glyph(int mixmode, Line 1967  ui_draw_glyph(int mixmode,
1967  {\  {\
1968    glyph = cache_get_font (font, ttext[idx]);\    glyph = cache_get_font (font, ttext[idx]);\
1969    if (!(flags & TEXT2_IMPLICIT_X))\    if (!(flags & TEXT2_IMPLICIT_X))\
1970      {\
1971        xyoffset = ttext[++idx];\
1972        if ((xyoffset & 0x80))\
1973      {\      {\
1974        xyoffset = ttext[++idx];\        if (flags & TEXT2_VERTICAL)\
1975        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;\  
         }\  
1976        else\        else\
1977          {\          x += ttext[idx+1] | (ttext[idx+2] << 8);\
1978            if (flags & TEXT2_VERTICAL) \        idx += 2;\
             y += xyoffset;\  
           else\  
             x += xyoffset;\  
         }\  
1979      }\      }\
1980    if (glyph != NULL)\      else\
1981      {\      {\
1982        ui_draw_glyph (mixmode, x + glyph->offset,\        if (flags & TEXT2_VERTICAL)\
1983                       y + glyph->baseline,\          y += xyoffset;\
1984                       glyph->width, glyph->height,\        else\
1985                       glyph->pixmap, 0, 0, bgcolour, fgcolour);\          x += xyoffset;\
       if (flags & TEXT2_IMPLICIT_X)\  
         x += glyph->width;\  
1986      }\      }\
1987      }\
1988      if (glyph != NULL)\
1989      {\
1990        x1 = x + glyph->offset;\
1991        y1 = y + glyph->baseline;\
1992        XSetStipple(g_display, g_gc, (Pixmap) glyph->pixmap);\
1993        XSetTSOrigin(g_display, g_gc, x1, y1);\
1994        FILL_RECTANGLE_BACKSTORE(x1, y1, glyph->width, glyph->height);\
1995        if (flags & TEXT2_IMPLICIT_X)\
1996          x += glyph->width;\
1997      }\
1998  }  }
1999    
2000  void  void
# Line 1771  ui_draw_text(uint8 font, uint8 flags, in Line 2004  ui_draw_text(uint8 font, uint8 flags, in
2004               int fgcolour, uint8 * text, uint8 length)               int fgcolour, uint8 * text, uint8 length)
2005  {  {
2006          FONTGLYPH *glyph;          FONTGLYPH *glyph;
2007          int i, j, xyoffset;          int i, j, xyoffset, x1, y1;
2008          DATABLOB *entry;          DATABLOB *entry;
2009    
2010          SET_FOREGROUND(bgcolour);          SET_FOREGROUND(bgcolour);
2011    
2012            /* Sometimes, the boxcx value is something really large, like
2013               32691. This makes XCopyArea fail with Xvnc. The code below
2014               is a quick fix. */
2015            if (boxx + boxcx > g_width)
2016                    boxcx = g_width - boxx;
2017    
2018          if (boxcx > 1)          if (boxcx > 1)
2019          {          {
2020                  FILL_RECTANGLE_BACKSTORE(boxx, boxy, boxcx, boxcy);                  FILL_RECTANGLE_BACKSTORE(boxx, boxy, boxcx, boxcy);
# Line 1785  ui_draw_text(uint8 font, uint8 flags, in Line 2024  ui_draw_text(uint8 font, uint8 flags, in
2024                  FILL_RECTANGLE_BACKSTORE(clipx, clipy, clipcx, clipcy);                  FILL_RECTANGLE_BACKSTORE(clipx, clipy, clipcx, clipcy);
2025          }          }
2026    
2027            SET_FOREGROUND(fgcolour);
2028            SET_BACKGROUND(bgcolour);
2029            XSetFillStyle(g_display, g_gc, FillStippled);
2030    
2031          /* Paint text, character by character */          /* Paint text, character by character */
2032          for (i = 0; i < length;)          for (i = 0; i < length;)
2033          {          {
# Line 1835  ui_draw_text(uint8 font, uint8 flags, in Line 2078  ui_draw_text(uint8 font, uint8 flags, in
2078                                  break;                                  break;
2079                  }                  }
2080          }          }
2081    
2082            XSetFillStyle(g_display, g_gc, FillSolid);
2083    
2084          if (g_ownbackstore)          if (g_ownbackstore)
2085          {          {
2086                  if (boxcx > 1)                  if (boxcx > 1)

Legend:
Removed from v.483  
changed lines
  Added in v.695

  ViewVC Help
Powered by ViewVC 1.1.26