/[rdesktop]/sourceforge.net/branches/seamlessrdp-branch/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/branches/seamlessrdp-branch/rdesktop/xwin.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 498 by astrand, Tue Oct 14 12:05:27 2003 UTC revision 831 by jdmeijer, Tue Mar 8 00:43:10 2005 UTC
# Line 1  Line 1 
1  /* -*- c-basic-offset: 8 -*-  /* -*- c-basic-offset: 8 -*-
2     rdesktop: A Remote Desktop Protocol client.     rdesktop: A Remote Desktop Protocol client.
3     User interface services - X Window System     User interface services - X Window System
4     Copyright (C) Matthew Chapman 1999-2002     Copyright (C) Matthew Chapman 1999-2005
5    
6     This program is free software; you can redistribute it and/or modify     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by     it under the terms of the GNU General Public License as published by
# 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    
31  extern int g_width;  extern int g_width;
32  extern int g_height;  extern int g_height;
33    extern int g_xpos;
34    extern int g_ypos;
35  extern BOOL g_sendmotion;  extern BOOL g_sendmotion;
36  extern BOOL g_fullscreen;  extern BOOL g_fullscreen;
37  extern BOOL g_grab_keyboard;  extern BOOL g_grab_keyboard;
# Line 40  Time g_last_gesturetime; Line 45  Time g_last_gesturetime;
45  static int g_x_socket;  static int g_x_socket;
46  static Screen *g_screen;  static Screen *g_screen;
47  Window g_wnd;  Window g_wnd;
48    extern uint32 g_embed_wnd;
49  BOOL g_enable_compose = False;  BOOL g_enable_compose = False;
50  static GC g_gc;  BOOL g_Unobscured;              /* used for screenblt */
51    static GC g_gc = NULL;
52    static GC g_create_bitmap_gc = NULL;
53    static GC g_create_glyph_gc = NULL;
54  static Visual *g_visual;  static Visual *g_visual;
55  static int g_depth;  static int g_depth;
56  static int g_bpp;  static int g_bpp;
# Line 49  static XIM g_IM; Line 58  static XIM g_IM;
58  static XIC g_IC;  static XIC g_IC;
59  static XModifierKeymap *g_mod_map;  static XModifierKeymap *g_mod_map;
60  static Cursor g_current_cursor;  static Cursor g_current_cursor;
61    static HCURSOR g_null_cursor = NULL;
62  static Atom g_protocol_atom, g_kill_atom;  static Atom g_protocol_atom, g_kill_atom;
63  static BOOL g_focused;  static BOOL g_focused;
64  static BOOL g_mouse_in_wnd;  static BOOL g_mouse_in_wnd;
65    static BOOL g_arch_match = False;       /* set to True if RGB XServer and little endian */
66    
67  /* endianness */  /* endianness */
68  static BOOL g_host_be;  static BOOL g_host_be;
69  static BOOL g_xserver_be;  static BOOL g_xserver_be;
70    static int g_red_shift_r, g_blue_shift_r, g_green_shift_r;
71    static int g_red_shift_l, g_blue_shift_l, g_green_shift_l;
72    
73  /* software backing store */  /* software backing store */
74  static BOOL g_ownbackstore;  extern BOOL g_ownbackstore;
75  static Pixmap g_backstore;  static Pixmap g_backstore = 0;
76    
77  /* Moving in single app mode */  /* Moving in single app mode */
78  static BOOL g_moving_wnd;  static BOOL g_moving_wnd;
# Line 69  static int g_move_y_offset = 0; Line 82  static int g_move_y_offset = 0;
82  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
83  extern int g_dsp_fd;  extern int g_dsp_fd;
84  extern BOOL g_dsp_busy;  extern BOOL g_dsp_busy;
85    extern BOOL g_rdpsnd;
86  #endif  #endif
87    
88  /* MWM decorations */  /* MWM decorations */
# Line 105  PixelColour; Line 119  PixelColour;
119          XFillRectangle(g_display, g_ownbackstore ? g_backstore : g_wnd, g_gc, x, y, cx, cy); \          XFillRectangle(g_display, g_ownbackstore ? g_backstore : g_wnd, g_gc, x, y, cx, cy); \
120  }  }
121    
122    #define FILL_POLYGON(p,np)\
123    { \
124            XFillPolygon(g_display, g_wnd, g_gc, p, np, Complex, CoordModePrevious); \
125            if (g_ownbackstore) \
126                    XFillPolygon(g_display, g_backstore, g_gc, p, np, Complex, CoordModePrevious); \
127    }
128    
129    #define DRAW_ELLIPSE(x,y,cx,cy,m)\
130    { \
131            switch (m) \
132            { \
133                    case 0: /* Outline */ \
134                            XDrawArc(g_display, g_wnd, g_gc, x, y, cx, cy, 0, 360*64); \
135                            if (g_ownbackstore) \
136                                    XDrawArc(g_display, g_backstore, g_gc, x, y, cx, cy, 0, 360*64); \
137                            break; \
138                    case 1: /* Filled */ \
139                            XFillArc(g_display, g_ownbackstore ? g_backstore : g_wnd, g_gc, x, y, \
140                                     cx, cy, 0, 360*64); \
141                            if (g_ownbackstore) \
142                                    XCopyArea(g_display, g_backstore, g_wnd, g_gc, x, y, cx, cy, x, y); \
143                            break; \
144            } \
145    }
146    
147  /* colour maps */  /* colour maps */
148  BOOL g_owncolmap = False;  extern BOOL g_owncolmap;
149  static Colormap g_xcolmap;  static Colormap g_xcolmap;
150  static uint32 *g_colmap = NULL;  static uint32 *g_colmap = NULL;
151    
152  #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] )
153  #define SET_FOREGROUND(col)     XSetForeground(g_display, g_gc, TRANSLATE(col));  #define SET_FOREGROUND(col)     XSetForeground(g_display, g_gc, TRANSLATE(col));
154  #define SET_BACKGROUND(col)     XSetBackground(g_display, g_gc, TRANSLATE(col));  #define SET_BACKGROUND(col)     XSetBackground(g_display, g_gc, TRANSLATE(col));
155    
# Line 158  mwm_hide_decorations(void) Line 197  mwm_hide_decorations(void)
197                          (unsigned char *) &motif_hints, PROP_MOTIF_WM_HINTS_ELEMENTS);                          (unsigned char *) &motif_hints, PROP_MOTIF_WM_HINTS_ELEMENTS);
198  }  }
199    
200  static PixelColour  #define SPLITCOLOUR15(colour, rv) \
201  split_colour15(uint32 colour)  { \
202  {          rv.red = ((colour >> 7) & 0xf8) | ((colour >> 12) & 0x7); \
203          PixelColour rv;          rv.green = ((colour >> 2) & 0xf8) | ((colour >> 8) & 0x7); \
204          rv.red = (colour & 0x7c00) >> 10;          rv.blue = ((colour << 3) & 0xf8) | ((colour >> 2) & 0x7); \
         rv.red = (rv.red * 0xff) / 0x1f;  
         rv.green = (colour & 0x03e0) >> 5;  
         rv.green = (rv.green * 0xff) / 0x1f;  
         rv.blue = (colour & 0x1f);  
         rv.blue = (rv.blue * 0xff) / 0x1f;  
         return rv;  
 }  
   
 static PixelColour  
 split_colour16(uint32 colour)  
 {  
         PixelColour rv;  
         rv.red = (colour & 0xf800) >> 11;  
         rv.red = (rv.red * 0xff) / 0x1f;  
         rv.green = (colour & 0x07e0) >> 5;  
         rv.green = (rv.green * 0xff) / 0x3f;  
         rv.blue = (colour & 0x001f);  
         rv.blue = (rv.blue * 0xff) / 0x1f;  
         return rv;  
 }  
   
 static PixelColour  
 split_colour24(uint32 colour)  
 {  
         PixelColour rv;  
         rv.blue = (colour & 0xff0000) >> 16;  
         rv.green = (colour & 0xff00) >> 8;  
         rv.red = (colour & 0xff);  
         return rv;  
205  }  }
206    
207  static uint32  #define SPLITCOLOUR16(colour, rv) \
208  make_colour16(PixelColour pc)  { \
209  {          rv.red = ((colour >> 8) & 0xf8) | ((colour >> 13) & 0x7); \
210          pc.red = (pc.red * 0x1f) / 0xff;          rv.green = ((colour >> 3) & 0xfc) | ((colour >> 9) & 0x3); \
211          pc.green = (pc.green * 0x3f) / 0xff;          rv.blue = ((colour << 3) & 0xf8) | ((colour >> 2) & 0x7); \
212          pc.blue = (pc.blue * 0x1f) / 0xff;  } \
         return (pc.red << 11) | (pc.green << 5) | pc.blue;  
 }  
213    
214  static uint32  #define SPLITCOLOUR24(colour, rv) \
215  make_colour24(PixelColour pc)  { \
216  {          rv.blue = (colour & 0xff0000) >> 16; \
217          if (g_xserver_be)          rv.green = (colour & 0x00ff00) >> 8; \
218          {          rv.red = (colour & 0x0000ff); \
                 return pc.red | (pc.green << 8) | (pc.blue << 16);  
         }  
         else  
         {  
                 return (pc.red << 16) | (pc.green << 8) | pc.blue;  
         }  
219  }  }
220    
221  static uint32  #define MAKECOLOUR(pc) \
222  make_colour32(PixelColour pc)          ((pc.red >> g_red_shift_r) << g_red_shift_l) \
223  {                  | ((pc.green >> g_green_shift_r) << g_green_shift_l) \
224          if (g_xserver_be)                  | ((pc.blue >> g_blue_shift_r) << g_blue_shift_l) \
         {  
                 return pc.red | (pc.green << 8) | (pc.blue << 16);  
         }  
         else  
         {  
                 return (pc.red << 16) | (pc.green << 8) | pc.blue;  
         }  
 }  
225    
226  #define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); }  #define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); }
227  #define BSWAP24(x) { x = (((x & 0xff) << 16) | (x >> 16) | ((x >> 8) & 0xff00)); }  #define BSWAP24(x) { x = (((x & 0xff) << 16) | (x >> 16) | (x & 0xff00)); }
228  #define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \  #define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \
229                          x = (x << 16) | (x >> 16); }                          x = (x << 16) | (x >> 16); }
230    
231    #define BOUT16(o, x) { *(o++) = x >> 8; *(o++) = x; }
232    #define BOUT24(o, x) { *(o++) = x >> 16; *(o++) = x >> 8; *(o++) = x; }
233    #define BOUT32(o, x) { *(o++) = x >> 24; *(o++) = x >> 16; *(o++) = x >> 8; *(o++) = x; }
234    #define LOUT16(o, x) { *(o++) = x; *(o++) = x >> 8; }
235    #define LOUT24(o, x) { *(o++) = x; *(o++) = x >> 8; *(o++) = x >> 16; }
236    #define LOUT32(o, x) { *(o++) = x; *(o++) = x >> 8; *(o++) = x >> 16; *(o++) = x >> 24; }
237    
238  static uint32  static uint32
239  translate_colour(uint32 colour)  translate_colour(uint32 colour)
240  {  {
241            PixelColour pc;
242          switch (g_server_bpp)          switch (g_server_bpp)
243          {          {
244                  case 15:                  case 15:
245                          switch (g_bpp)                          SPLITCOLOUR15(colour, pc);
                         {  
                                 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;  
                         }  
246                          break;                          break;
247                  case 16:                  case 16:
248                          switch (g_bpp)                          SPLITCOLOUR16(colour, pc);
                         {  
                                 case 16:  
                                         break;  
                                 case 24:  
                                         colour = make_colour24(split_colour16(colour));  
                                         break;  
                                 case 32:  
                                         colour = make_colour32(split_colour16(colour));  
                                         break;  
                         }  
249                          break;                          break;
250                  case 24:                  case 24:
251                          switch (g_bpp)                          SPLITCOLOUR24(colour, pc);
                         {  
                                 case 16:  
                                         colour = make_colour16(split_colour24(colour));  
                                         break;  
                                 case 24:  
                                         break;  
                                 case 32:  
                                         colour = make_colour32(split_colour24(colour));  
                                         break;  
                         }  
252                          break;                          break;
253          }          }
254          return colour;          return MAKECOLOUR(pc);
255    }
256    
257    /* indent is confused by UNROLL8 */
258    /* *INDENT-OFF* */
259    
260    /* repeat and unroll, similar to bitmap.c */
261    /* potentialy any of the following translate */
262    /* functions can use repeat but just doing */
263    /* the most common ones */
264    
265    #define UNROLL8(stm) { stm stm stm stm stm stm stm stm }
266    /* 2 byte output repeat */
267    #define REPEAT2(stm) \
268    { \
269            while (out <= end - 8 * 2) \
270                    UNROLL8(stm) \
271            while (out < end) \
272                    { stm } \
273    }
274    /* 3 byte output repeat */
275    #define REPEAT3(stm) \
276    { \
277            while (out <= end - 8 * 3) \
278                    UNROLL8(stm) \
279            while (out < end) \
280                    { stm } \
281    }
282    /* 4 byte output repeat */
283    #define REPEAT4(stm) \
284    { \
285            while (out <= end - 8 * 4) \
286                    UNROLL8(stm) \
287            while (out < end) \
288                    { stm } \
289  }  }
290    /* *INDENT-ON* */
291    
292  static void  static void
293  translate8to8(uint8 * data, uint8 * out, uint8 * end)  translate8to8(const uint8 * data, uint8 * out, uint8 * end)
294  {  {
295          while (out < end)          while (out < end)
296                  *(out++) = (uint8) g_colmap[*(data++)];                  *(out++) = (uint8) g_colmap[*(data++)];
297  }  }
298    
299  static void  static void
300  translate8to16(uint8 * data, uint16 * out, uint16 * end)  translate8to16(const uint8 * data, uint8 * out, uint8 * end)
301  {  {
302          while (out < end)          uint16 value;
303                  *(out++) = (uint16) g_colmap[*(data++)];  
304            if (g_arch_match)
305            {
306                    /* *INDENT-OFF* */
307                    REPEAT2
308                    (
309                            *((uint16 *) out) = g_colmap[*(data++)];
310                            out += 2;
311                    )
312                    /* *INDENT-ON* */
313            }
314            else if (g_xserver_be)
315            {
316                    while (out < end)
317                    {
318                            value = (uint16) g_colmap[*(data++)];
319                            BOUT16(out, value);
320                    }
321            }
322            else
323            {
324                    while (out < end)
325                    {
326                            value = (uint16) g_colmap[*(data++)];
327                            LOUT16(out, value);
328                    }
329            }
330  }  }
331    
332  /* little endian - conversion happens when colourmap is built */  /* little endian - conversion happens when colourmap is built */
333  static void  static void
334  translate8to24(uint8 * data, uint8 * out, uint8 * end)  translate8to24(const uint8 * data, uint8 * out, uint8 * end)
335  {  {
336          uint32 value;          uint32 value;
337    
338          while (out < end)          if (g_xserver_be)
339          {          {
340                  value = g_colmap[*(data++)];                  while (out < end)
341                  *(out++) = value;                  {
342                  *(out++) = value >> 8;                          value = g_colmap[*(data++)];
343                  *(out++) = value >> 16;                          BOUT24(out, value);
344                    }
345            }
346            else
347            {
348                    while (out < end)
349                    {
350                            value = g_colmap[*(data++)];
351                            LOUT24(out, value);
352                    }
353          }          }
354  }  }
355    
356  static void  static void
357  translate8to32(uint8 * data, uint32 * out, uint32 * end)  translate8to32(const uint8 * data, uint8 * out, uint8 * end)
358  {  {
359          while (out < end)          uint32 value;
                 *(out++) = g_colmap[*(data++)];  
 }  
360    
361  /* todo the remaining translate function might need some big endian check ?? */          if (g_arch_match)
362            {
363                    /* *INDENT-OFF* */
364                    REPEAT4
365                    (
366                            *((uint32 *) out) = g_colmap[*(data++)];
367                            out += 4;
368                    )
369                    /* *INDENT-ON* */
370            }
371            else if (g_xserver_be)
372            {
373                    while (out < end)
374                    {
375                            value = g_colmap[*(data++)];
376                            BOUT32(out, value);
377                    }
378            }
379            else
380            {
381                    while (out < end)
382                    {
383                            value = g_colmap[*(data++)];
384                            LOUT32(out, value);
385                    }
386            }
387    }
388    
389  static void  static void
390  translate15to16(uint16 * data, uint8 * out, uint8 * end)  translate15to16(const uint16 * data, uint8 * out, uint8 * end)
391  {  {
392          uint16 pixel;          uint16 pixel;
393          uint16 value;          uint16 value;
394            PixelColour pc;
395    
396          while (out < end)          if (g_xserver_be)
397          {          {
398                  pixel = *(data++);                  while (out < end)
   
                 if (g_host_be)  
                 {  
                         BSWAP16(pixel)  
                 }  
   
                 value = make_colour16(split_colour15(pixel));  
   
                 if (g_xserver_be)  
399                  {                  {
400                          *(out++) = value >> 8;                          pixel = *(data++);
401                          *(out++) = value;                          if (g_host_be)
402                            {
403                                    BSWAP16(pixel);
404                            }
405                            SPLITCOLOUR15(pixel, pc);
406                            value = MAKECOLOUR(pc);
407                            BOUT16(out, value);
408                  }                  }
409                  else          }
410            else
411            {
412                    while (out < end)
413                  {                  {
414                          *(out++) = value;                          pixel = *(data++);
415                          *(out++) = value >> 8;                          if (g_host_be)
416                            {
417                                    BSWAP16(pixel);
418                            }
419                            SPLITCOLOUR15(pixel, pc);
420                            value = MAKECOLOUR(pc);
421                            LOUT16(out, value);
422                  }                  }
423          }          }
424  }  }
425    
426  static void  static void
427  translate15to24(uint16 * data, uint8 * out, uint8 * end)  translate15to24(const uint16 * data, uint8 * out, uint8 * end)
428  {  {
429          uint32 value;          uint32 value;
430          uint16 pixel;          uint16 pixel;
431            PixelColour pc;
432    
433          while (out < end)          if (g_arch_match)
434          {          {
435                  pixel = *(data++);                  /* *INDENT-OFF* */
436                    REPEAT3
437                  if (g_host_be)                  (
438                  {                          pixel = *(data++);
439                          BSWAP16(pixel)                          SPLITCOLOUR15(pixel, pc);
440                  }                          *(out++) = pc.blue;
441                            *(out++) = pc.green;
442                  value = make_colour24(split_colour15(pixel));                          *(out++) = pc.red;
443                  if (g_xserver_be)                  )
444                    /* *INDENT-ON* */
445            }
446            else if (g_xserver_be)
447            {
448                    while (out < end)
449                  {                  {
450                          *(out++) = value >> 16;                          pixel = *(data++);
451                          *(out++) = value >> 8;                          if (g_host_be)
452                          *(out++) = value;                          {
453                                    BSWAP16(pixel);
454                            }
455                            SPLITCOLOUR15(pixel, pc);
456                            value = MAKECOLOUR(pc);
457                            BOUT24(out, value);
458                  }                  }
459                  else          }
460            else
461            {
462                    while (out < end)
463                  {                  {
464                          *(out++) = value;                          pixel = *(data++);
465                          *(out++) = value >> 8;                          if (g_host_be)
466                          *(out++) = value >> 16;                          {
467                                    BSWAP16(pixel);
468                            }
469                            SPLITCOLOUR15(pixel, pc);
470                            value = MAKECOLOUR(pc);
471                            LOUT24(out, value);
472                  }                  }
473          }          }
474  }  }
475    
476  static void  static void
477  translate15to32(uint16 * data, uint8 * out, uint8 * end)  translate15to32(const uint16 * data, uint8 * out, uint8 * end)
478  {  {
479          uint16 pixel;          uint16 pixel;
480          uint32 value;          uint32 value;
481            PixelColour pc;
482    
483          while (out < end)          if (g_arch_match)
484          {          {
485                  pixel = *(data++);                  /* *INDENT-OFF* */
486                    REPEAT4
487                  if (g_host_be)                  (
488                  {                          pixel = *(data++);
489                          BSWAP16(pixel);                          SPLITCOLOUR15(pixel, pc);
490                  }                          *(out++) = pc.blue;
491                            *(out++) = pc.green;
492                  value = make_colour32(split_colour15(pixel));                          *(out++) = pc.red;
493                            *(out++) = 0;
494                  if (g_xserver_be)                  )
495                    /* *INDENT-ON* */
496            }
497            else if (g_xserver_be)
498            {
499                    while (out < end)
500                  {                  {
501                          *(out++) = value >> 24;                          pixel = *(data++);
502                          *(out++) = value >> 16;                          if (g_host_be)
503                          *(out++) = value >> 8;                          {
504                          *(out++) = value;                                  BSWAP16(pixel);
505                            }
506                            SPLITCOLOUR15(pixel, pc);
507                            value = MAKECOLOUR(pc);
508                            BOUT32(out, value);
509                  }                  }
510                  else          }
511            else
512            {
513                    while (out < end)
514                  {                  {
515                          *(out++) = value;                          pixel = *(data++);
516                          *(out++) = value >> 8;                          if (g_host_be)
517                          *(out++) = value >> 16;                          {
518                          *(out++) = value >> 24;                                  BSWAP16(pixel);
519                            }
520                            SPLITCOLOUR15(pixel, pc);
521                            value = MAKECOLOUR(pc);
522                            LOUT32(out, value);
523                  }                  }
524          }          }
525  }  }
526    
527  static void  static void
528  translate16to16(uint16 * data, uint16 * out, uint16 * end)  translate16to16(const uint16 * data, uint8 * out, uint8 * end)
529  {  {
530            uint16 pixel;
531          uint16 value;          uint16 value;
532            PixelColour pc;
533    
534          if (g_xserver_be)          if (g_xserver_be)
535          {          {
536                  while (out < end)                  if (g_host_be)
537                  {                  {
538                          value = *data;                          while (out < end)
539                          BSWAP16(value);                          {
540                          *out = value;                                  pixel = *(data++);
541                          data++;                                  BSWAP16(pixel);
542                          out++;                                  SPLITCOLOUR16(pixel, pc);
543                                    value = MAKECOLOUR(pc);
544                                    BOUT16(out, value);
545                            }
546                    }
547                    else
548                    {
549                            while (out < end)
550                            {
551                                    pixel = *(data++);
552                                    SPLITCOLOUR16(pixel, pc);
553                                    value = MAKECOLOUR(pc);
554                                    BOUT16(out, value);
555                            }
556                  }                  }
   
557          }          }
558          else          else
559          {          {
560                  while (out < end)                  if (g_host_be)
561                  {                  {
562                          *out = *data;                          while (out < end)
563                          out++;                          {
564                          data++;                                  pixel = *(data++);
565                                    BSWAP16(pixel);
566                                    SPLITCOLOUR16(pixel, pc);
567                                    value = MAKECOLOUR(pc);
568                                    LOUT16(out, value);
569                            }
570                    }
571                    else
572                    {
573                            while (out < end)
574                            {
575                                    pixel = *(data++);
576                                    SPLITCOLOUR16(pixel, pc);
577                                    value = MAKECOLOUR(pc);
578                                    LOUT16(out, value);
579                            }
580                  }                  }
581          }          }
582  }  }
583    
   
584  static void  static void
585  translate16to24(uint16 * data, uint8 * out, uint8 * end)  translate16to24(const uint16 * data, uint8 * out, uint8 * end)
586  {  {
587          uint32 value;          uint32 value;
588          uint16 pixel;          uint16 pixel;
589            PixelColour pc;
590    
591          while (out < end)          if (g_arch_match)
592            {
593                    /* *INDENT-OFF* */
594                    REPEAT3
595                    (
596                            pixel = *(data++);
597                            SPLITCOLOUR16(pixel, pc);
598                            *(out++) = pc.blue;
599                            *(out++) = pc.green;
600                            *(out++) = pc.red;
601                    )
602                    /* *INDENT-ON* */
603            }
604            else if (g_xserver_be)
605          {          {
                 pixel = *(data++);  
   
606                  if (g_host_be)                  if (g_host_be)
607                  {                  {
608                          BSWAP16(pixel)                          while (out < end)
609                            {
610                                    pixel = *(data++);
611                                    BSWAP16(pixel);
612                                    SPLITCOLOUR16(pixel, pc);
613                                    value = MAKECOLOUR(pc);
614                                    BOUT24(out, value);
615                            }
616                  }                  }
617                    else
                 value = make_colour24(split_colour16(pixel));  
   
                 if (g_xserver_be)  
618                  {                  {
619                          *(out++) = value >> 16;                          while (out < end)
620                          *(out++) = value >> 8;                          {
621                          *(out++) = value;                                  pixel = *(data++);
622                                    SPLITCOLOUR16(pixel, pc);
623                                    value = MAKECOLOUR(pc);
624                                    BOUT24(out, value);
625                            }
626                    }
627            }
628            else
629            {
630                    if (g_host_be)
631                    {
632                            while (out < end)
633                            {
634                                    pixel = *(data++);
635                                    BSWAP16(pixel);
636                                    SPLITCOLOUR16(pixel, pc);
637                                    value = MAKECOLOUR(pc);
638                                    LOUT24(out, value);
639                            }
640                  }                  }
641                  else                  else
642                  {                  {
643                          *(out++) = value;                          while (out < end)
644                          *(out++) = value >> 8;                          {
645                          *(out++) = value >> 16;                                  pixel = *(data++);
646                                    SPLITCOLOUR16(pixel, pc);
647                                    value = MAKECOLOUR(pc);
648                                    LOUT24(out, value);
649                            }
650                  }                  }
651          }          }
652  }  }
653    
654  static void  static void
655  translate16to32(uint16 * data, uint8 * out, uint8 * end)  translate16to32(const uint16 * data, uint8 * out, uint8 * end)
656  {  {
657          uint16 pixel;          uint16 pixel;
658          uint32 value;          uint32 value;
659            PixelColour pc;
660    
661          while (out < end)          if (g_arch_match)
662            {
663                    /* *INDENT-OFF* */
664                    REPEAT4
665                    (
666                            pixel = *(data++);
667                            SPLITCOLOUR16(pixel, pc);
668                            *(out++) = pc.blue;
669                            *(out++) = pc.green;
670                            *(out++) = pc.red;
671                            *(out++) = 0;
672                    )
673                    /* *INDENT-ON* */
674            }
675            else if (g_xserver_be)
676          {          {
                 pixel = *(data++);  
   
677                  if (g_host_be)                  if (g_host_be)
678                  {                  {
679                          BSWAP16(pixel)                          while (out < end)
680                            {
681                                    pixel = *(data++);
682                                    BSWAP16(pixel);
683                                    SPLITCOLOUR16(pixel, pc);
684                                    value = MAKECOLOUR(pc);
685                                    BOUT32(out, value);
686                            }
687                    }
688                    else
689                    {
690                            while (out < end)
691                            {
692                                    pixel = *(data++);
693                                    SPLITCOLOUR16(pixel, pc);
694                                    value = MAKECOLOUR(pc);
695                                    BOUT32(out, value);
696                            }
697                  }                  }
698            }
699                  value = make_colour32(split_colour16(pixel));          else
700            {
701                  if (g_xserver_be)                  if (g_host_be)
702                  {                  {
703                          *(out++) = value >> 24;                          while (out < end)
704                          *(out++) = value >> 16;                          {
705                          *(out++) = value >> 8;                                  pixel = *(data++);
706                          *(out++) = value;                                  BSWAP16(pixel);
707                  }                                  SPLITCOLOUR16(pixel, pc);
708                  else                                  value = MAKECOLOUR(pc);
709                  {                                  LOUT32(out, value);
710                          *(out++) = value;                          }
711                          *(out++) = value >> 8;                  }
712                          *(out++) = value >> 16;                  else
713                          *(out++) = value >> 24;                  {
714                  }                          while (out < end)
715          }                          {
716                                    pixel = *(data++);
717                                    SPLITCOLOUR16(pixel, pc);
718                                    value = MAKECOLOUR(pc);
719                                    LOUT32(out, value);
720                            }
721                    }
722            }
723  }  }
724    
725  static void  static void
726  translate24to16(uint8 * data, uint8 * out, uint8 * end)  translate24to16(const uint8 * data, uint8 * out, uint8 * end)
727  {  {
728          uint32 pixel = 0;          uint32 pixel = 0;
729          uint16 value;          uint16 value;
730            PixelColour pc;
731    
732          while (out < end)          while (out < end)
733          {          {
734                  pixel = *(data++) << 16;                  pixel = *(data++) << 16;
735                  pixel |= *(data++) << 8;                  pixel |= *(data++) << 8;
736                  pixel |= *(data++);                  pixel |= *(data++);
737                    SPLITCOLOUR24(pixel, pc);
738                  value = (uint16) make_colour16(split_colour24(pixel));                  value = MAKECOLOUR(pc);
   
739                  if (g_xserver_be)                  if (g_xserver_be)
740                  {                  {
741                          *(out++) = value >> 8;                          BOUT16(out, value);
                         *(out++) = value;  
742                  }                  }
743                  else                  else
744                  {                  {
745                          *(out++) = value;                          LOUT16(out, value);
                         *(out++) = value >> 8;  
746                  }                  }
747          }          }
748  }  }
749    
750  static void  static void
751  translate24to24(uint8 * data, uint8 * out, uint8 * end)  translate24to24(const uint8 * data, uint8 * out, uint8 * end)
752  {  {
753          while (out < end)          uint32 pixel;
754            uint32 value;
755            PixelColour pc;
756    
757            if (g_xserver_be)
758          {          {
759                  *(out++) = (*(data++));                  while (out < end)
760                    {
761                            pixel = *(data++) << 16;
762                            pixel |= *(data++) << 8;
763                            pixel |= *(data++);
764                            SPLITCOLOUR24(pixel, pc);
765                            value = MAKECOLOUR(pc);
766                            BOUT24(out, value);
767                    }
768            }
769            else
770            {
771                    while (out < end)
772                    {
773                            pixel = *(data++) << 16;
774                            pixel |= *(data++) << 8;
775                            pixel |= *(data++);
776                            SPLITCOLOUR24(pixel, pc);
777                            value = MAKECOLOUR(pc);
778                            LOUT24(out, value);
779                    }
780          }          }
781  }  }
782    
783  static void  static void
784  translate24to32(uint8 * data, uint8 * out, uint8 * end)  translate24to32(const uint8 * data, uint8 * out, uint8 * end)
785  {  {
786          while (out < end)          uint32 pixel;
787            uint32 value;
788            PixelColour pc;
789    
790            if (g_arch_match)
791          {          {
792                  if (g_xserver_be)                  /* *INDENT-OFF* */
793                  {  #ifdef NEED_ALIGN
794                          *(out++) = 0x00;                  REPEAT4
795                    (
796                          *(out++) = *(data++);                          *(out++) = *(data++);
797                          *(out++) = *(data++);                          *(out++) = *(data++);
798                          *(out++) = *(data++);                          *(out++) = *(data++);
799                            *(out++) = 0;
800                    )
801    #else
802                    REPEAT4
803                    (
804                            *((uint32 *) out) = *((uint32 *) data);
805                            out += 4;
806                            data += 3;
807                    )
808    #endif
809                    /* *INDENT-ON* */
810            }
811            else if (g_xserver_be)
812            {
813                    while (out < end)
814                    {
815                            pixel = *(data++) << 16;
816                            pixel |= *(data++) << 8;
817                            pixel |= *(data++);
818                            SPLITCOLOUR24(pixel, pc);
819                            value = MAKECOLOUR(pc);
820                            BOUT32(out, value);
821                  }                  }
822                  else          }
823            else
824            {
825                    while (out < end)
826                  {                  {
827                          *(out++) = *(data++);                          pixel = *(data++) << 16;
828                          *(out++) = *(data++);                          pixel |= *(data++) << 8;
829                          *(out++) = *(data++);                          pixel |= *(data++);
830                          *(out++) = 0x00;                          SPLITCOLOUR24(pixel, pc);
831                            value = MAKECOLOUR(pc);
832                            LOUT32(out, value);
833                  }                  }
834          }          }
835  }  }
# Line 571  translate24to32(uint8 * data, uint8 * ou Line 837  translate24to32(uint8 * data, uint8 * ou
837  static uint8 *  static uint8 *
838  translate_image(int width, int height, uint8 * data)  translate_image(int width, int height, uint8 * data)
839  {  {
840          int size = width * height * g_bpp / 8;          int size;
841          uint8 *out = (uint8 *) xmalloc(size);          uint8 *out;
842          uint8 *end = out + size;          uint8 *end;
843    
844            /* if server and xserver bpp match, */
845            /* and arch(endian) matches, no need to translate */
846            /* just return data */
847            if (g_arch_match)
848            {
849                    if (g_depth == 15 && g_server_bpp == 15)
850                            return data;
851                    if (g_depth == 16 && g_server_bpp == 16)
852                            return data;
853                    if (g_depth == 24 && g_bpp == 24 && g_server_bpp == 24)
854                            return data;
855            }
856    
857            size = width * height * (g_bpp / 8);
858            out = (uint8 *) xmalloc(size);
859            end = out + size;
860    
861          switch (g_server_bpp)          switch (g_server_bpp)
862          {          {
# Line 601  translate_image(int width, int height, u Line 884  translate_image(int width, int height, u
884                                          translate16to24((uint16 *) data, out, end);                                          translate16to24((uint16 *) data, out, end);
885                                          break;                                          break;
886                                  case 16:                                  case 16:
887                                          translate16to16((uint16 *) data, (uint16 *) out,                                          translate16to16((uint16 *) data, out, end);
                                                         (uint16 *) end);  
888                                          break;                                          break;
889                          }                          }
890                          break;                          break;
# Line 627  translate_image(int width, int height, u Line 909  translate_image(int width, int height, u
909                                          translate8to8(data, out, end);                                          translate8to8(data, out, end);
910                                          break;                                          break;
911                                  case 16:                                  case 16:
912                                          translate8to16(data, (uint16 *) out, (uint16 *) end);                                          translate8to16(data, out, end);
913                                          break;                                          break;
914                                  case 24:                                  case 24:
915                                          translate8to24(data, out, end);                                          translate8to24(data, out, end);
916                                          break;                                          break;
917                                  case 32:                                  case 32:
918                                          translate8to32(data, (uint32 *) out, (uint32 *) end);                                          translate8to32(data, out, end);
919                                          break;                                          break;
920                          }                          }
921                          break;                          break;
# Line 666  get_key_state(unsigned int state, uint32 Line 948  get_key_state(unsigned int state, uint32
948          return (state & keysymMask) ? True : False;          return (state & keysymMask) ? True : False;
949  }  }
950    
951    static void
952    calculate_shifts(uint32 mask, int *shift_r, int *shift_l)
953    {
954            *shift_l = ffs(mask) - 1;
955            mask >>= *shift_l;
956            *shift_r = 8 - ffs(mask & ~(mask >> 1));
957    }
958    
959  BOOL  BOOL
960  ui_init(void)  ui_init(void)
961  {  {
962            XVisualInfo vi;
963          XPixmapFormatValues *pfm;          XPixmapFormatValues *pfm;
964          uint16 test;          uint16 test;
965          int i;          int i, screen_num, nvisuals;
966            XVisualInfo *vmatches = NULL;
967            XVisualInfo template;
968            Bool TrueColorVisual = False;
969    
970          g_display = XOpenDisplay(NULL);          g_display = XOpenDisplay(NULL);
971          if (g_display == NULL)          if (g_display == NULL)
# Line 680  ui_init(void) Line 974  ui_init(void)
974                  return False;                  return False;
975          }          }
976    
977            screen_num = DefaultScreen(g_display);
978          g_x_socket = ConnectionNumber(g_display);          g_x_socket = ConnectionNumber(g_display);
979          g_screen = DefaultScreenOfDisplay(g_display);          g_screen = ScreenOfDisplay(g_display, screen_num);
         g_visual = DefaultVisualOfScreen(g_screen);  
980          g_depth = DefaultDepthOfScreen(g_screen);          g_depth = DefaultDepthOfScreen(g_screen);
981    
982            /* Search for best TrueColor depth */
983            template.class = TrueColor;
984            vmatches = XGetVisualInfo(g_display, VisualClassMask, &template, &nvisuals);
985    
986            nvisuals--;
987            while (nvisuals >= 0)
988            {
989                    if ((vmatches + nvisuals)->depth > g_depth)
990                    {
991                            g_depth = (vmatches + nvisuals)->depth;
992                    }
993                    nvisuals--;
994                    TrueColorVisual = True;
995            }
996    
997            test = 1;
998            g_host_be = !(BOOL) (*(uint8 *) (&test));
999            g_xserver_be = (ImageByteOrder(g_display) == MSBFirst);
1000    
1001            if ((g_server_bpp == 8) && ((!TrueColorVisual) || (g_depth <= 8)))
1002            {
1003                    /* we use a colourmap, so the default visual should do */
1004                    g_visual = DefaultVisualOfScreen(g_screen);
1005                    g_depth = DefaultDepthOfScreen(g_screen);
1006    
1007                    /* Do not allocate colours on a TrueColor visual */
1008                    if (g_visual->class == TrueColor)
1009                    {
1010                            g_owncolmap = False;
1011                    }
1012            }
1013            else
1014            {
1015                    /* need a truecolour visual */
1016                    if (!XMatchVisualInfo(g_display, screen_num, g_depth, TrueColor, &vi))
1017                    {
1018                            error("The display does not support true colour - high colour support unavailable.\n");
1019                            return False;
1020                    }
1021    
1022                    g_visual = vi.visual;
1023                    g_owncolmap = False;
1024                    calculate_shifts(vi.red_mask, &g_red_shift_r, &g_red_shift_l);
1025                    calculate_shifts(vi.blue_mask, &g_blue_shift_r, &g_blue_shift_l);
1026                    calculate_shifts(vi.green_mask, &g_green_shift_r, &g_green_shift_l);
1027    
1028                    /* if RGB video and everything is little endian */
1029                    if ((vi.red_mask > vi.green_mask && vi.green_mask > vi.blue_mask) &&
1030                        !g_xserver_be && !g_host_be)
1031                    {
1032                            if (g_depth <= 16 || (g_red_shift_l == 16 && g_green_shift_l == 8 &&
1033                                                  g_blue_shift_l == 0))
1034                            {
1035                                    g_arch_match = True;
1036                            }
1037                    }
1038    
1039                    if (g_arch_match)
1040                    {
1041                            DEBUG(("Architectures match, enabling little endian optimisations.\n"));
1042                    }
1043            }
1044    
1045          pfm = XListPixmapFormats(g_display, &i);          pfm = XListPixmapFormats(g_display, &i);
1046          if (pfm != NULL)          if (pfm != NULL)
1047          {          {
# Line 707  ui_init(void) Line 1064  ui_init(void)
1064                  return False;                  return False;
1065          }          }
1066    
1067          if (g_owncolmap != True)          if (!g_owncolmap)
1068          {          {
1069                  g_xcolmap = DefaultColormapOfScreen(g_screen);                  g_xcolmap =
1070                            XCreateColormap(g_display, RootWindowOfScreen(g_screen), g_visual,
1071                                            AllocNone);
1072                  if (g_depth <= 8)                  if (g_depth <= 8)
1073                          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");
1074          }          }
1075    
1076          g_gc = XCreateGC(g_display, RootWindowOfScreen(g_screen), 0, NULL);          if ((!g_ownbackstore) && (DoesBackingStore(g_screen) != Always))
1077            {
1078          if (DoesBackingStore(g_screen) != Always)                  warning("External BackingStore not available, using internal\n");
1079                  g_ownbackstore = True;                  g_ownbackstore = True;
1080            }
1081    
1082          test = 1;          /*
1083          g_host_be = !(BOOL) (*(uint8 *) (&test));           * Determine desktop size
1084          g_xserver_be = (ImageByteOrder(g_display) == MSBFirst);           */
1085            if (g_fullscreen)
1086          if ((g_width == 0) || (g_height == 0))          {
1087                    g_width = WidthOfScreen(g_screen);
1088                    g_height = HeightOfScreen(g_screen);
1089            }
1090            else if (g_width < 0)
1091            {
1092                    /* Percent of screen */
1093                    g_height = HeightOfScreen(g_screen) * (-g_width) / 100;
1094                    g_width = WidthOfScreen(g_screen) * (-g_width) / 100;
1095            }
1096            else if (g_width == 0)
1097          {          {
1098                  /* Fetch geometry from _NET_WORKAREA */                  /* Fetch geometry from _NET_WORKAREA */
1099                  uint32 x, y, cx, cy;                  uint32 x, y, cx, cy;
# Line 741  ui_init(void) Line 1111  ui_init(void)
1111                  }                  }
1112          }          }
1113    
         if (g_fullscreen)  
         {  
                 g_width = WidthOfScreen(g_screen);  
                 g_height = HeightOfScreen(g_screen);  
         }  
   
1114          /* make sure width is a multiple of 4 */          /* make sure width is a multiple of 4 */
1115          g_width = (g_width + 3) & ~3;          g_width = (g_width + 3) & ~3;
1116    
         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);  
         }  
   
1117          g_mod_map = XGetModifierMapping(g_display);          g_mod_map = XGetModifierMapping(g_display);
1118    
1119          xkeymap_init();          xkeymap_init();
# Line 770  ui_init(void) Line 1123  ui_init(void)
1123    
1124          xclip_init();          xclip_init();
1125    
1126          /* 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);  
1127    
1128          return True;          return True;
1129  }  }
# Line 782  ui_deinit(void) Line 1134  ui_deinit(void)
1134          if (g_IM != NULL)          if (g_IM != NULL)
1135                  XCloseIM(g_IM);                  XCloseIM(g_IM);
1136    
1137            if (g_null_cursor != NULL)
1138                    ui_destroy_cursor(g_null_cursor);
1139    
1140          XFreeModifiermap(g_mod_map);          XFreeModifiermap(g_mod_map);
1141    
1142          if (g_ownbackstore)          if (g_ownbackstore)
# Line 795  ui_deinit(void) Line 1150  ui_deinit(void)
1150  BOOL  BOOL
1151  ui_create_window(void)  ui_create_window(void)
1152  {  {
1153            uint8 null_pointer_mask[1] = { 0x80 };
1154            uint8 null_pointer_data[24] = { 0x00 };
1155    
1156          XSetWindowAttributes attribs;          XSetWindowAttributes attribs;
1157          XClassHint *classhints;          XClassHint *classhints;
1158          XSizeHints *sizehints;          XSizeHints *sizehints;
# Line 806  ui_create_window(void) Line 1164  ui_create_window(void)
1164          wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height;          wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height;
1165    
1166          attribs.background_pixel = BlackPixelOfScreen(g_screen);          attribs.background_pixel = BlackPixelOfScreen(g_screen);
1167            attribs.border_pixel = WhitePixelOfScreen(g_screen);
1168          attribs.backing_store = g_ownbackstore ? NotUseful : Always;          attribs.backing_store = g_ownbackstore ? NotUseful : Always;
1169          attribs.override_redirect = g_fullscreen;          attribs.override_redirect = g_fullscreen;
1170            attribs.colormap = g_xcolmap;
1171    
1172            g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), g_xpos, g_ypos, wndwidth,
1173                                  wndheight, 0, g_depth, InputOutput, g_visual,
1174                                  CWBackPixel | CWBackingStore | CWOverrideRedirect | CWColormap |
1175                                  CWBorderPixel, &attribs);
1176    
1177          g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), 0, 0, wndwidth, wndheight,          if (g_gc == NULL)
1178                                0, CopyFromParent, InputOutput, CopyFromParent,                  g_gc = XCreateGC(g_display, g_wnd, 0, NULL);
1179                                CWBackPixel | CWBackingStore | CWOverrideRedirect, &attribs);  
1180            if (g_create_bitmap_gc == NULL)
1181                    g_create_bitmap_gc = XCreateGC(g_display, g_wnd, 0, NULL);
1182    
1183            if ((g_ownbackstore) && (g_backstore == 0))
1184            {
1185                    g_backstore = XCreatePixmap(g_display, g_wnd, g_width, g_height, g_depth);
1186    
1187                    /* clear to prevent rubbish being exposed at startup */
1188                    XSetForeground(g_display, g_gc, BlackPixelOfScreen(g_screen));
1189                    XFillRectangle(g_display, g_backstore, g_gc, 0, 0, g_width, g_height);
1190            }
1191    
1192          XStoreName(g_display, g_wnd, g_title);          XStoreName(g_display, g_wnd, g_title);
1193    
# Line 836  ui_create_window(void) Line 1212  ui_create_window(void)
1212                  XFree(sizehints);                  XFree(sizehints);
1213          }          }
1214    
1215            if (g_embed_wnd)
1216            {
1217                    XReparentWindow(g_display, g_wnd, (Window) g_embed_wnd, 0, 0);
1218            }
1219    
1220          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
1221                  VisibilityChangeMask | FocusChangeMask;                  VisibilityChangeMask | FocusChangeMask;
1222    
# Line 867  ui_create_window(void) Line 1248  ui_create_window(void)
1248                  XMaskEvent(g_display, VisibilityChangeMask, &xevent);                  XMaskEvent(g_display, VisibilityChangeMask, &xevent);
1249          }          }
1250          while (xevent.type != VisibilityNotify);          while (xevent.type != VisibilityNotify);
1251            g_Unobscured = xevent.xvisibility.state == VisibilityUnobscured;
1252    
1253          g_focused = False;          g_focused = False;
1254          g_mouse_in_wnd = False;          g_mouse_in_wnd = False;
# Line 876  ui_create_window(void) Line 1258  ui_create_window(void)
1258          g_kill_atom = XInternAtom(g_display, "WM_DELETE_WINDOW", True);          g_kill_atom = XInternAtom(g_display, "WM_DELETE_WINDOW", True);
1259          XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1);          XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1);
1260    
1261            /* create invisible 1x1 cursor to be used as null cursor */
1262            if (g_null_cursor == NULL)
1263                    g_null_cursor = ui_create_cursor(0, 0, 1, 1, null_pointer_mask, null_pointer_data);
1264    
1265          return True;          return True;
1266  }  }
1267    
1268  void  void
1269    ui_resize_window()
1270    {
1271            XSizeHints *sizehints;
1272            Pixmap bs;
1273    
1274            sizehints = XAllocSizeHints();
1275            if (sizehints)
1276            {
1277                    sizehints->flags = PMinSize | PMaxSize;
1278                    sizehints->min_width = sizehints->max_width = g_width;
1279                    sizehints->min_height = sizehints->max_height = g_height;
1280                    XSetWMNormalHints(g_display, g_wnd, sizehints);
1281                    XFree(sizehints);
1282            }
1283    
1284            if (!(g_fullscreen || g_embed_wnd))
1285            {
1286                    XResizeWindow(g_display, g_wnd, g_width, g_height);
1287            }
1288    
1289            /* create new backstore pixmap */
1290            if (g_backstore != 0)
1291            {
1292                    bs = XCreatePixmap(g_display, g_wnd, g_width, g_height, g_depth);
1293                    XSetForeground(g_display, g_gc, BlackPixelOfScreen(g_screen));
1294                    XFillRectangle(g_display, bs, g_gc, 0, 0, g_width, g_height);
1295                    XCopyArea(g_display, g_backstore, bs, g_gc, 0, 0, g_width, g_height, 0, 0);
1296                    XFreePixmap(g_display, g_backstore);
1297                    g_backstore = bs;
1298            }
1299    }
1300    
1301    void
1302  ui_destroy_window(void)  ui_destroy_window(void)
1303  {  {
1304          if (g_IC != NULL)          if (g_IC != NULL)
# Line 925  xwin_process_events(void) Line 1344  xwin_process_events(void)
1344          key_translation tr;          key_translation tr;
1345          char str[256];          char str[256];
1346          Status status;          Status status;
         unsigned int state;  
         Window wdummy;  
         int dummy;  
1347    
1348          while (XPending(g_display) > 0)          while (XPending(g_display) > 0)
1349          {          {
# Line 943  xwin_process_events(void) Line 1359  xwin_process_events(void)
1359    
1360                  switch (xevent.type)                  switch (xevent.type)
1361                  {                  {
1362                            case VisibilityNotify:
1363                                    g_Unobscured = xevent.xvisibility.state == VisibilityUnobscured;
1364                                    break;
1365                          case ClientMessage:                          case ClientMessage:
1366                                  /* the window manager told us to quit */                                  /* the window manager told us to quit */
1367                                  if ((xevent.xclient.message_type == g_protocol_atom)                                  if ((xevent.xclient.message_type == g_protocol_atom)
# Line 1100  xwin_process_events(void) Line 1519  xwin_process_events(void)
1519                                  if (xevent.xfocus.mode == NotifyGrab)                                  if (xevent.xfocus.mode == NotifyGrab)
1520                                          break;                                          break;
1521                                  g_focused = True;                                  g_focused = True;
1522                                  XQueryPointer(g_display, g_wnd, &wdummy, &wdummy, &dummy, &dummy,                                  reset_modifier_keys();
                                               &dummy, &dummy, &state);  
                                 reset_modifier_keys(state);  
1523                                  if (g_grab_keyboard && g_mouse_in_wnd)                                  if (g_grab_keyboard && g_mouse_in_wnd)
1524                                          XGrabKeyboard(g_display, g_wnd, True,                                          XGrabKeyboard(g_display, g_wnd, True,
1525                                                        GrabModeAsync, GrabModeAsync, CurrentTime);                                                        GrabModeAsync, GrabModeAsync, CurrentTime);
# Line 1182  xwin_process_events(void) Line 1599  xwin_process_events(void)
1599  int  int
1600  ui_select(int rdp_socket)  ui_select(int rdp_socket)
1601  {  {
1602          int n = (rdp_socket > g_x_socket) ? rdp_socket + 1 : g_x_socket + 1;          int n;
1603          fd_set rfds, wfds;          fd_set rfds, wfds;
1604            struct timeval tv;
1605            BOOL s_timeout = False;
1606    
1607          while (True)          while (True)
1608          {          {
1609                    n = (rdp_socket > g_x_socket) ? rdp_socket : g_x_socket;
1610                  /* Process any events already waiting */                  /* Process any events already waiting */
1611                  if (!xwin_process_events())                  if (!xwin_process_events())
1612                          /* User quit */                          /* User quit */
# Line 1202  ui_select(int rdp_socket) Line 1622  ui_select(int rdp_socket)
1622                  if (g_dsp_busy)                  if (g_dsp_busy)
1623                  {                  {
1624                          FD_SET(g_dsp_fd, &wfds);                          FD_SET(g_dsp_fd, &wfds);
1625                          n = (g_dsp_fd + 1 > n) ? g_dsp_fd + 1 : n;                          n = (g_dsp_fd > n) ? g_dsp_fd : n;
1626                  }                  }
1627  #endif  #endif
1628                    /* default timeout */
1629                    tv.tv_sec = 60;
1630                    tv.tv_usec = 0;
1631    
1632                    /* add redirection handles */
1633                    rdpdr_add_fds(&n, &rfds, &wfds, &tv, &s_timeout);
1634    
1635                  switch (select(n, &rfds, &wfds, NULL, NULL))                  n++;
1636    
1637                    switch (select(n, &rfds, &wfds, NULL, &tv))
1638                  {                  {
1639                          case -1:                          case -1:
1640                                  error("select: %s\n", strerror(errno));                                  error("select: %s\n", strerror(errno));
1641    
1642                          case 0:                          case 0:
1643                                    /* Abort serial read calls */
1644                                    if (s_timeout)
1645                                            rdpdr_check_fds(&rfds, &wfds, (BOOL) True);
1646                                  continue;                                  continue;
1647                  }                  }
1648    
1649                    rdpdr_check_fds(&rfds, &wfds, (BOOL) False);
1650    
1651                  if (FD_ISSET(rdp_socket, &rfds))                  if (FD_ISSET(rdp_socket, &rfds))
1652                          return 1;                          return 1;
1653    
# Line 1237  ui_create_bitmap(int width, int height, Line 1670  ui_create_bitmap(int width, int height,
1670          XImage *image;          XImage *image;
1671          Pixmap bitmap;          Pixmap bitmap;
1672          uint8 *tdata;          uint8 *tdata;
1673            int bitmap_pad;
1674    
1675            if (g_server_bpp == 8)
1676            {
1677                    bitmap_pad = 8;
1678            }
1679            else
1680            {
1681                    bitmap_pad = g_bpp;
1682    
1683                    if (g_bpp == 24)
1684                            bitmap_pad = 32;
1685            }
1686    
1687          tdata = (g_owncolmap ? data : translate_image(width, height, data));          tdata = (g_owncolmap ? data : translate_image(width, height, data));
1688          bitmap = XCreatePixmap(g_display, g_wnd, width, height, g_depth);          bitmap = XCreatePixmap(g_display, g_wnd, width, height, g_depth);
1689          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,
1690                               (char *) tdata, width, height, g_server_bpp == 8 ? 8 : g_bpp, 0);                               (char *) tdata, width, height, bitmap_pad, 0);
1691    
1692          XPutImage(g_display, bitmap, g_gc, image, 0, 0, 0, 0, width, height);          XPutImage(g_display, bitmap, g_create_bitmap_gc, image, 0, 0, 0, 0, width, height);
1693    
1694          XFree(image);          XFree(image);
1695          if (!g_owncolmap)          if (tdata != data)
1696                  xfree(tdata);                  xfree(tdata);
1697          return (HBITMAP) bitmap;          return (HBITMAP) bitmap;
1698  }  }
# Line 1256  ui_paint_bitmap(int x, int y, int cx, in Line 1702  ui_paint_bitmap(int x, int y, int cx, in
1702  {  {
1703          XImage *image;          XImage *image;
1704          uint8 *tdata;          uint8 *tdata;
1705            int bitmap_pad;
1706    
1707            if (g_server_bpp == 8)
1708            {
1709                    bitmap_pad = 8;
1710            }
1711            else
1712            {
1713                    bitmap_pad = g_bpp;
1714    
1715                    if (g_bpp == 24)
1716                            bitmap_pad = 32;
1717            }
1718    
1719          tdata = (g_owncolmap ? data : translate_image(width, height, data));          tdata = (g_owncolmap ? data : translate_image(width, height, data));
1720          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,
1721                               (char *) tdata, width, height, g_server_bpp == 8 ? 8 : g_bpp, 0);                               (char *) tdata, width, height, bitmap_pad, 0);
1722    
1723          if (g_ownbackstore)          if (g_ownbackstore)
1724          {          {
# Line 1271  ui_paint_bitmap(int x, int y, int cx, in Line 1731  ui_paint_bitmap(int x, int y, int cx, in
1731          }          }
1732    
1733          XFree(image);          XFree(image);
1734          if (!g_owncolmap)          if (tdata != data)
1735                  xfree(tdata);                  xfree(tdata);
1736  }  }
1737    
# Line 1287  ui_create_glyph(int width, int height, u Line 1747  ui_create_glyph(int width, int height, u
1747          XImage *image;          XImage *image;
1748          Pixmap bitmap;          Pixmap bitmap;
1749          int scanline;          int scanline;
         GC gc;  
1750    
1751          scanline = (width + 7) / 8;          scanline = (width + 7) / 8;
1752    
1753          bitmap = XCreatePixmap(g_display, g_wnd, width, height, 1);          bitmap = XCreatePixmap(g_display, g_wnd, width, height, 1);
1754          gc = XCreateGC(g_display, bitmap, 0, NULL);          if (g_create_glyph_gc == 0)
1755                    g_create_glyph_gc = XCreateGC(g_display, bitmap, 0, NULL);
1756    
1757          image = XCreateImage(g_display, g_visual, 1, ZPixmap, 0, (char *) data,          image = XCreateImage(g_display, g_visual, 1, ZPixmap, 0, (char *) data,
1758                               width, height, 8, scanline);                               width, height, 8, scanline);
# Line 1300  ui_create_glyph(int width, int height, u Line 1760  ui_create_glyph(int width, int height, u
1760          image->bitmap_bit_order = MSBFirst;          image->bitmap_bit_order = MSBFirst;
1761          XInitImage(image);          XInitImage(image);
1762    
1763          XPutImage(g_display, bitmap, gc, image, 0, 0, 0, 0, width, height);          XPutImage(g_display, bitmap, g_create_glyph_gc, image, 0, 0, 0, 0, width, height);
1764    
1765          XFree(image);          XFree(image);
         XFreeGC(g_display, gc);  
1766          return (HGLYPH) bitmap;          return (HGLYPH) bitmap;
1767  }  }
1768    
# Line 1397  ui_destroy_cursor(HCURSOR cursor) Line 1856  ui_destroy_cursor(HCURSOR cursor)
1856          XFreeCursor(g_display, (Cursor) cursor);          XFreeCursor(g_display, (Cursor) cursor);
1857  }  }
1858    
1859    void
1860    ui_set_null_cursor(void)
1861    {
1862            ui_set_cursor(g_null_cursor);
1863    }
1864    
1865  #define MAKE_XCOLOR(xc,c) \  #define MAKE_XCOLOR(xc,c) \
1866                  (xc)->red   = ((c)->red   << 8) | (c)->red; \                  (xc)->red   = ((c)->red   << 8) | (c)->red; \
1867                  (xc)->green = ((c)->green << 8) | (c)->green; \                  (xc)->green = ((c)->green << 8) | (c)->green; \
# Line 1478  ui_create_colourmap(COLOURMAP * colours) Line 1943  ui_create_colourmap(COLOURMAP * colours)
1943    
1944                          }                          }
1945    
1946                            map[i] = colour;
                         /* byte swap here to make translate_image faster */  
                         map[i] = translate_colour(colour);  
1947                  }                  }
1948                  return map;                  return map;
1949          }          }
# Line 1591  ui_patblt(uint8 opcode, Line 2054  ui_patblt(uint8 opcode,
2054          {          {
2055                  case 0: /* Solid */                  case 0: /* Solid */
2056                          SET_FOREGROUND(fgcolour);                          SET_FOREGROUND(fgcolour);
2057                          FILL_RECTANGLE(x, y, cx, cy);                          FILL_RECTANGLE_BACKSTORE(x, y, cx, cy);
2058                          break;                          break;
2059    
2060                  case 2: /* Hatch */                  case 2: /* Hatch */
# Line 1602  ui_patblt(uint8 opcode, Line 2065  ui_patblt(uint8 opcode,
2065                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);
2066                          XSetStipple(g_display, g_gc, fill);                          XSetStipple(g_display, g_gc, fill);
2067                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);
2068                          FILL_RECTANGLE(x, y, cx, cy);                          FILL_RECTANGLE_BACKSTORE(x, y, cx, cy);
2069                          XSetFillStyle(g_display, g_gc, FillSolid);                          XSetFillStyle(g_display, g_gc, FillSolid);
2070                          XSetTSOrigin(g_display, g_gc, 0, 0);                          XSetTSOrigin(g_display, g_gc, 0, 0);
2071                          ui_destroy_glyph((HGLYPH) fill);                          ui_destroy_glyph((HGLYPH) fill);
# Line 1612  ui_patblt(uint8 opcode, Line 2075  ui_patblt(uint8 opcode,
2075                          for (i = 0; i != 8; i++)                          for (i = 0; i != 8; i++)
2076                                  ipattern[7 - i] = brush->pattern[i];                                  ipattern[7 - i] = brush->pattern[i];
2077                          fill = (Pixmap) ui_create_glyph(8, 8, ipattern);                          fill = (Pixmap) ui_create_glyph(8, 8, ipattern);
   
2078                          SET_FOREGROUND(bgcolour);                          SET_FOREGROUND(bgcolour);
2079                          SET_BACKGROUND(fgcolour);                          SET_BACKGROUND(fgcolour);
2080                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);
2081                          XSetStipple(g_display, g_gc, fill);                          XSetStipple(g_display, g_gc, fill);
2082                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);
2083                            FILL_RECTANGLE_BACKSTORE(x, y, cx, cy);
                         FILL_RECTANGLE(x, y, cx, cy);  
   
2084                          XSetFillStyle(g_display, g_gc, FillSolid);                          XSetFillStyle(g_display, g_gc, FillSolid);
2085                          XSetTSOrigin(g_display, g_gc, 0, 0);                          XSetTSOrigin(g_display, g_gc, 0, 0);
2086                          ui_destroy_glyph((HGLYPH) fill);                          ui_destroy_glyph((HGLYPH) fill);
# Line 1631  ui_patblt(uint8 opcode, Line 2091  ui_patblt(uint8 opcode,
2091          }          }
2092    
2093          RESET_FUNCTION(opcode);          RESET_FUNCTION(opcode);
2094    
2095            if (g_ownbackstore)
2096                    XCopyArea(g_display, g_backstore, g_wnd, g_gc, x, y, cx, cy, x, y);
2097  }  }
2098    
2099  void  void
# Line 1639  ui_screenblt(uint8 opcode, Line 2102  ui_screenblt(uint8 opcode,
2102               /* src */ int srcx, int srcy)               /* src */ int srcx, int srcy)
2103  {  {
2104          SET_FUNCTION(opcode);          SET_FUNCTION(opcode);
         XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);  
2105          if (g_ownbackstore)          if (g_ownbackstore)
2106                  XCopyArea(g_display, g_backstore, g_backstore, g_gc, srcx, srcy, cx, cy, x, y);          {
2107                    if (g_Unobscured)
2108                    {
2109                            XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);
2110                            XCopyArea(g_display, g_backstore, g_backstore, g_gc, srcx, srcy, cx, cy, x,
2111                                      y);
2112                    }
2113                    else
2114                    {
2115                            XCopyArea(g_display, g_backstore, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);
2116                            XCopyArea(g_display, g_backstore, g_backstore, g_gc, srcx, srcy, cx, cy, x,
2117                                      y);
2118                    }
2119            }
2120            else
2121            {
2122                    XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);
2123            }
2124          RESET_FUNCTION(opcode);          RESET_FUNCTION(opcode);
2125  }  }
2126    
# Line 1712  ui_rect( Line 2191  ui_rect(
2191          FILL_RECTANGLE(x, y, cx, cy);          FILL_RECTANGLE(x, y, cx, cy);
2192  }  }
2193    
2194    void
2195    ui_polygon(uint8 opcode,
2196               /* mode */ uint8 fillmode,
2197               /* dest */ POINT * point, int npoints,
2198               /* brush */ BRUSH * brush, int bgcolour, int fgcolour)
2199    {
2200            uint8 style, i, ipattern[8];
2201            Pixmap fill;
2202    
2203            SET_FUNCTION(opcode);
2204    
2205            switch (fillmode)
2206            {
2207                    case ALTERNATE:
2208                            XSetFillRule(g_display, g_gc, EvenOddRule);
2209                            break;
2210                    case WINDING:
2211                            XSetFillRule(g_display, g_gc, WindingRule);
2212                            break;
2213                    default:
2214                            unimpl("fill mode %d\n", fillmode);
2215            }
2216    
2217            if (brush)
2218                    style = brush->style;
2219            else
2220                    style = 0;
2221    
2222            switch (style)
2223            {
2224                    case 0: /* Solid */
2225                            SET_FOREGROUND(fgcolour);
2226                            FILL_POLYGON((XPoint *) point, npoints);
2227                            break;
2228    
2229                    case 2: /* Hatch */
2230                            fill = (Pixmap) ui_create_glyph(8, 8,
2231                                                            hatch_patterns + brush->pattern[0] * 8);
2232                            SET_FOREGROUND(fgcolour);
2233                            SET_BACKGROUND(bgcolour);
2234                            XSetFillStyle(g_display, g_gc, FillOpaqueStippled);
2235                            XSetStipple(g_display, g_gc, fill);
2236                            XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);
2237                            FILL_POLYGON((XPoint *) point, npoints);
2238                            XSetFillStyle(g_display, g_gc, FillSolid);
2239                            XSetTSOrigin(g_display, g_gc, 0, 0);
2240                            ui_destroy_glyph((HGLYPH) fill);
2241                            break;
2242    
2243                    case 3: /* Pattern */
2244                            for (i = 0; i != 8; i++)
2245                                    ipattern[7 - i] = brush->pattern[i];
2246                            fill = (Pixmap) ui_create_glyph(8, 8, ipattern);
2247                            SET_FOREGROUND(bgcolour);
2248                            SET_BACKGROUND(fgcolour);
2249                            XSetFillStyle(g_display, g_gc, FillOpaqueStippled);
2250                            XSetStipple(g_display, g_gc, fill);
2251                            XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);
2252                            FILL_POLYGON((XPoint *) point, npoints);
2253                            XSetFillStyle(g_display, g_gc, FillSolid);
2254                            XSetTSOrigin(g_display, g_gc, 0, 0);
2255                            ui_destroy_glyph((HGLYPH) fill);
2256                            break;
2257    
2258                    default:
2259                            unimpl("brush %d\n", brush->style);
2260            }
2261    
2262            RESET_FUNCTION(opcode);
2263    }
2264    
2265    void
2266    ui_ellipse(uint8 opcode,
2267               /* mode */ uint8 fillmode,
2268               /* dest */ int x, int y, int cx, int cy,
2269               /* brush */ BRUSH * brush, int bgcolour, int fgcolour)
2270    {
2271            uint8 style, i, ipattern[8];
2272            Pixmap fill;
2273    
2274            SET_FUNCTION(opcode);
2275    
2276            if (brush)
2277                    style = brush->style;
2278            else
2279                    style = 0;
2280    
2281            switch (style)
2282            {
2283                    case 0: /* Solid */
2284                            SET_FOREGROUND(fgcolour);
2285                            DRAW_ELLIPSE(x, y, cx, cy, fillmode);
2286                            break;
2287    
2288                    case 2: /* Hatch */
2289                            fill = (Pixmap) ui_create_glyph(8, 8,
2290                                                            hatch_patterns + brush->pattern[0] * 8);
2291                            SET_FOREGROUND(fgcolour);
2292                            SET_BACKGROUND(bgcolour);
2293                            XSetFillStyle(g_display, g_gc, FillOpaqueStippled);
2294                            XSetStipple(g_display, g_gc, fill);
2295                            XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);
2296                            DRAW_ELLIPSE(x, y, cx, cy, fillmode);
2297                            XSetFillStyle(g_display, g_gc, FillSolid);
2298                            XSetTSOrigin(g_display, g_gc, 0, 0);
2299                            ui_destroy_glyph((HGLYPH) fill);
2300                            break;
2301    
2302                    case 3: /* Pattern */
2303                            for (i = 0; i != 8; i++)
2304                                    ipattern[7 - i] = brush->pattern[i];
2305                            fill = (Pixmap) ui_create_glyph(8, 8, ipattern);
2306                            SET_FOREGROUND(bgcolour);
2307                            SET_BACKGROUND(fgcolour);
2308                            XSetFillStyle(g_display, g_gc, FillOpaqueStippled);
2309                            XSetStipple(g_display, g_gc, fill);
2310                            XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);
2311                            DRAW_ELLIPSE(x, y, cx, cy, fillmode);
2312                            XSetFillStyle(g_display, g_gc, FillSolid);
2313                            XSetTSOrigin(g_display, g_gc, 0, 0);
2314                            ui_destroy_glyph((HGLYPH) fill);
2315                            break;
2316    
2317                    default:
2318                            unimpl("brush %d\n", brush->style);
2319            }
2320    
2321            RESET_FUNCTION(opcode);
2322    }
2323    
2324  /* warning, this function only draws on wnd or backstore, not both */  /* warning, this function only draws on wnd or backstore, not both */
2325  void  void
2326  ui_draw_glyph(int mixmode,  ui_draw_glyph(int mixmode,
# Line 1736  ui_draw_glyph(int mixmode, Line 2345  ui_draw_glyph(int mixmode,
2345  {\  {\
2346    glyph = cache_get_font (font, ttext[idx]);\    glyph = cache_get_font (font, ttext[idx]);\
2347    if (!(flags & TEXT2_IMPLICIT_X))\    if (!(flags & TEXT2_IMPLICIT_X))\
2348      {\
2349        xyoffset = ttext[++idx];\
2350        if ((xyoffset & 0x80))\
2351      {\      {\
2352        xyoffset = ttext[++idx];\        if (flags & TEXT2_VERTICAL)\
2353        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;\  
         }\  
2354        else\        else\
2355          {\          x += ttext[idx+1] | (ttext[idx+2] << 8);\
2356            if (flags & TEXT2_VERTICAL) \        idx += 2;\
             y += xyoffset;\  
           else\  
             x += xyoffset;\  
         }\  
2357      }\      }\
2358    if (glyph != NULL)\      else\
2359      {\      {\
2360        ui_draw_glyph (mixmode, x + glyph->offset,\        if (flags & TEXT2_VERTICAL)\
2361                       y + glyph->baseline,\          y += xyoffset;\
2362                       glyph->width, glyph->height,\        else\
2363                       glyph->pixmap, 0, 0, bgcolour, fgcolour);\          x += xyoffset;\
       if (flags & TEXT2_IMPLICIT_X)\  
         x += glyph->width;\  
2364      }\      }\
2365      }\
2366      if (glyph != NULL)\
2367      {\
2368        x1 = x + glyph->offset;\
2369        y1 = y + glyph->baseline;\
2370        XSetStipple(g_display, g_gc, (Pixmap) glyph->pixmap);\
2371        XSetTSOrigin(g_display, g_gc, x1, y1);\
2372        FILL_RECTANGLE_BACKSTORE(x1, y1, glyph->width, glyph->height);\
2373        if (flags & TEXT2_IMPLICIT_X)\
2374          x += glyph->width;\
2375      }\
2376  }  }
2377    
2378  void  void
# Line 1772  ui_draw_text(uint8 font, uint8 flags, in Line 2382  ui_draw_text(uint8 font, uint8 flags, in
2382               int fgcolour, uint8 * text, uint8 length)               int fgcolour, uint8 * text, uint8 length)
2383  {  {
2384          FONTGLYPH *glyph;          FONTGLYPH *glyph;
2385          int i, j, xyoffset;          int i, j, xyoffset, x1, y1;
2386          DATABLOB *entry;          DATABLOB *entry;
2387    
2388          SET_FOREGROUND(bgcolour);          SET_FOREGROUND(bgcolour);
2389    
2390            /* Sometimes, the boxcx value is something really large, like
2391               32691. This makes XCopyArea fail with Xvnc. The code below
2392               is a quick fix. */
2393            if (boxx + boxcx > g_width)
2394                    boxcx = g_width - boxx;
2395    
2396          if (boxcx > 1)          if (boxcx > 1)
2397          {          {
2398                  FILL_RECTANGLE_BACKSTORE(boxx, boxy, boxcx, boxcy);                  FILL_RECTANGLE_BACKSTORE(boxx, boxy, boxcx, boxcy);
# Line 1786  ui_draw_text(uint8 font, uint8 flags, in Line 2402  ui_draw_text(uint8 font, uint8 flags, in
2402                  FILL_RECTANGLE_BACKSTORE(clipx, clipy, clipcx, clipcy);                  FILL_RECTANGLE_BACKSTORE(clipx, clipy, clipcx, clipcy);
2403          }          }
2404    
2405            SET_FOREGROUND(fgcolour);
2406            SET_BACKGROUND(bgcolour);
2407            XSetFillStyle(g_display, g_gc, FillStippled);
2408    
2409          /* Paint text, character by character */          /* Paint text, character by character */
2410          for (i = 0; i < length;)          for (i = 0; i < length;)
2411          {          {
# Line 1836  ui_draw_text(uint8 font, uint8 flags, in Line 2456  ui_draw_text(uint8 font, uint8 flags, in
2456                                  break;                                  break;
2457                  }                  }
2458          }          }
2459    
2460            XSetFillStyle(g_display, g_gc, FillSolid);
2461    
2462          if (g_ownbackstore)          if (g_ownbackstore)
2463          {          {
2464                  if (boxcx > 1)                  if (boxcx > 1)
# Line 1897  ui_desktop_restore(uint32 offset, int x, Line 2520  ui_desktop_restore(uint32 offset, int x,
2520    
2521          XFree(image);          XFree(image);
2522  }  }
2523    
2524    /* these do nothing here but are used in uiports */
2525    void
2526    ui_begin_update(void)
2527    {
2528    }
2529    
2530    void
2531    ui_end_update(void)
2532    {
2533    }

Legend:
Removed from v.498  
changed lines
  Added in v.831

  ViewVC Help
Powered by ViewVC 1.1.26