/[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 519 by matthewc, Tue Oct 28 03:40:26 2003 UTC revision 645 by jsorg71, Mon Mar 29 13:59: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    uint32 g_embed_wnd;
47  BOOL g_enable_compose = False;  BOOL g_enable_compose = False;
48  static GC g_gc;  static GC g_gc = NULL;
49  static Visual *g_visual;  static Visual *g_visual;
50  static int g_depth;  static int g_depth;
51  static int g_bpp;  static int g_bpp;
# Line 49  static XIM g_IM; Line 53  static XIM g_IM;
53  static XIC g_IC;  static XIC g_IC;
54  static XModifierKeymap *g_mod_map;  static XModifierKeymap *g_mod_map;
55  static Cursor g_current_cursor;  static Cursor g_current_cursor;
56  static HCURSOR g_null_cursor;  static HCURSOR g_null_cursor = NULL;
57  static Atom g_protocol_atom, g_kill_atom;  static Atom g_protocol_atom, g_kill_atom;
58  static BOOL g_focused;  static BOOL g_focused;
59  static BOOL g_mouse_in_wnd;  static BOOL g_mouse_in_wnd;
60    static BOOL g_arch_match = False; /* set to True if RGB XServer and little endian */
61    
62  /* endianness */  /* endianness */
63  static BOOL g_host_be;  static BOOL g_host_be;
64  static BOOL g_xserver_be;  static BOOL g_xserver_be;
65    static int g_red_shift_r, g_blue_shift_r, g_green_shift_r;
66    static int g_red_shift_l, g_blue_shift_l, g_green_shift_l;
67    
68  /* software backing store */  /* software backing store */
69  static BOOL g_ownbackstore;  BOOL g_ownbackstore = True;     /* We can't rely on external BackingStore */
70  static Pixmap g_backstore;  static Pixmap g_backstore = 0;
71    
72  /* Moving in single app mode */  /* Moving in single app mode */
73  static BOOL g_moving_wnd;  static BOOL g_moving_wnd;
# Line 112  BOOL g_owncolmap = False; Line 119  BOOL g_owncolmap = False;
119  static Colormap g_xcolmap;  static Colormap g_xcolmap;
120  static uint32 *g_colmap = NULL;  static uint32 *g_colmap = NULL;
121    
122  #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] )
123  #define SET_FOREGROUND(col)     XSetForeground(g_display, g_gc, TRANSLATE(col));  #define SET_FOREGROUND(col)     XSetForeground(g_display, g_gc, TRANSLATE(col));
124  #define SET_BACKGROUND(col)     XSetBackground(g_display, g_gc, TRANSLATE(col));  #define SET_BACKGROUND(col)     XSetBackground(g_display, g_gc, TRANSLATE(col));
125    
# Line 164  static PixelColour Line 171  static PixelColour
171  split_colour15(uint32 colour)  split_colour15(uint32 colour)
172  {  {
173          PixelColour rv;          PixelColour rv;
174          rv.red = (colour & 0x7c00) >> 10;          rv.red = (colour & 0x7c00) >> 7;
175          rv.red = (rv.red * 0xff) / 0x1f;          rv.green = (colour & 0x03e0) >> 2;
176          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;  
177          return rv;          return rv;
178  }  }
179    
# Line 177  static PixelColour Line 181  static PixelColour
181  split_colour16(uint32 colour)  split_colour16(uint32 colour)
182  {  {
183          PixelColour rv;          PixelColour rv;
184          rv.red = (colour & 0xf800) >> 11;          rv.red = (colour & 0xf800) >> 8;
185          rv.red = (rv.red * 0xff) / 0x1f;          rv.green = (colour & 0x07e0) >> 3;
186          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;  
187          return rv;          return rv;
188  }  }
189    
# Line 191  split_colour24(uint32 colour) Line 192  split_colour24(uint32 colour)
192  {  {
193          PixelColour rv;          PixelColour rv;
194          rv.blue = (colour & 0xff0000) >> 16;          rv.blue = (colour & 0xff0000) >> 16;
195          rv.green = (colour & 0xff00) >> 8;          rv.green = (colour & 0x00ff00) >> 8;
196          rv.red = (colour & 0xff);          rv.red = (colour & 0x0000ff);
197          return rv;          return rv;
198  }  }
199    
200  static uint32  static uint32
201  make_colour16(PixelColour pc)  make_colour(PixelColour pc)
202  {  {
203          pc.red = (pc.red * 0x1f) / 0xff;          return (((pc.red >> g_red_shift_r) << g_red_shift_l)
204          pc.green = (pc.green * 0x3f) / 0xff;                  | ((pc.green >> g_green_shift_r) << g_green_shift_l)
205          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;  
         }  
206  }  }
207    
208  #define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); }  #define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); }
209  #define BSWAP24(x) { x = (((x & 0xff) << 16) | (x >> 16) | ((x >> 8) & 0xff00)); }  #define BSWAP24(x) { x = (((x & 0xff) << 16) | (x >> 16) | (x & 0xff00)); }
210  #define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \  #define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \
211                          x = (x << 16) | (x >> 16); }                          x = (x << 16) | (x >> 16); }
212    
213  static uint32  static uint32
214  translate_colour(uint32 colour)  translate_colour(uint32 colour)
215  {  {
216            PixelColour pc;
217          switch (g_server_bpp)          switch (g_server_bpp)
218          {          {
219                  case 15:                  case 15:
220                          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;  
                         }  
221                          break;                          break;
222                  case 16:                  case 16:
223                          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;  
                         }  
224                          break;                          break;
225                  case 24:                  case 24:
226                          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;  
                         }  
227                          break;                          break;
228          }          }
229          return colour;          return make_colour(pc);
230  }  }
231    
232  static void  static void
# Line 293  translate8to8(uint8 * data, uint8 * out, Line 237  translate8to8(uint8 * data, uint8 * out,
237  }  }
238    
239  static void  static void
240  translate8to16(uint8 * data, uint16 * out, uint16 * end)  translate8to16(uint8 * data, uint8 * out, uint8 * end)
241  {  {
242          while (out < end)          uint16 value;
243                  *(out++) = (uint16) g_colmap[*(data++)];  
244            if (g_xserver_be)
245            {
246                    while (out < end)
247                    {
248                            value = (uint16) g_colmap[*(data++)];
249                            *(out++) = value >> 8;
250                            *(out++) = value;
251                    }
252            }
253            else
254            {
255                    while (out < end)
256                    {
257                            value = (uint16) g_colmap[*(data++)];
258                            *(out++) = value;
259                            *(out++) = value >> 8;
260                    }
261            }
262  }  }
263    
264  /* little endian - conversion happens when colourmap is built */  /* little endian - conversion happens when colourmap is built */
# Line 305  translate8to24(uint8 * data, uint8 * out Line 267  translate8to24(uint8 * data, uint8 * out
267  {  {
268          uint32 value;          uint32 value;
269    
270          while (out < end)          if (g_xserver_be)
271          {          {
272                  value = g_colmap[*(data++)];                  while (out < end)
273                  *(out++) = value;                  {
274                  *(out++) = value >> 8;                          value = g_colmap[*(data++)];
275                  *(out++) = value >> 16;                          *(out++) = value >> 16;
276                            *(out++) = value >> 8;
277                            *(out++) = value;
278                    }
279            }
280            else
281            {
282                    while (out < end)
283                    {
284                            value = g_colmap[*(data++)];
285                            *(out++) = value;
286                            *(out++) = value >> 8;
287                            *(out++) = value >> 16;
288                    }
289          }          }
290  }  }
291    
292  static void  static void
293  translate8to32(uint8 * data, uint32 * out, uint32 * end)  translate8to32(uint8 * data, uint8 * out, uint8 * end)
294  {  {
295          while (out < end)          uint32 value;
                 *(out++) = g_colmap[*(data++)];  
 }  
296    
297  /* todo the remaining translate function might need some big endian check ?? */          if (g_xserver_be)
298            {
299                    while (out < end)
300                    {
301                            value = g_colmap[*(data++)];
302                            *(out++) = value >> 24;
303                            *(out++) = value >> 16;
304                            *(out++) = value >> 8;
305                            *(out++) = value;
306                    }
307            }
308            else
309            {
310                    while (out < end)
311                    {
312                            value = g_colmap[*(data++)];
313                            *(out++) = value;
314                            *(out++) = value >> 8;
315                            *(out++) = value >> 16;
316                            *(out++) = value >> 24;
317                    }
318            }
319    }
320    
321  static void  static void
322  translate15to16(uint16 * data, uint8 * out, uint8 * end)  translate15to16(uint16 * data, uint8 * out, uint8 * end)
# Line 335  translate15to16(uint16 * data, uint8 * o Line 330  translate15to16(uint16 * data, uint8 * o
330    
331                  if (g_host_be)                  if (g_host_be)
332                  {                  {
333                  BSWAP16(pixel)}                          BSWAP16(pixel);
334                    }
335    
336                  value = make_colour16(split_colour15(pixel));                  value = make_colour(split_colour15(pixel));
337    
338                  if (g_xserver_be)                  if (g_xserver_be)
339                  {                  {
# Line 364  translate15to24(uint16 * data, uint8 * o Line 360  translate15to24(uint16 * data, uint8 * o
360    
361                  if (g_host_be)                  if (g_host_be)
362                  {                  {
363                  BSWAP16(pixel)}                          BSWAP16(pixel);
364                    }
365    
366                  value = make_colour24(split_colour15(pixel));                  value = make_colour(split_colour15(pixel));
367                  if (g_xserver_be)                  if (g_xserver_be)
368                  {                  {
369                          *(out++) = value >> 16;                          *(out++) = value >> 16;
# Line 397  translate15to32(uint16 * data, uint8 * o Line 394  translate15to32(uint16 * data, uint8 * o
394                          BSWAP16(pixel);                          BSWAP16(pixel);
395                  }                  }
396    
397                  value = make_colour32(split_colour15(pixel));                  value = make_colour(split_colour15(pixel));
398    
399                  if (g_xserver_be)                  if (g_xserver_be)
400                  {                  {
# Line 417  translate15to32(uint16 * data, uint8 * o Line 414  translate15to32(uint16 * data, uint8 * o
414  }  }
415    
416  static void  static void
417  translate16to16(uint16 * data, uint16 * out, uint16 * end)  translate16to16(uint16 * data, uint8 * out, uint8 * end)
418  {  {
419            uint16 pixel;
420          uint16 value;          uint16 value;
421    
422          if (g_xserver_be)          while (out < end)
423          {          {
424                  while (out < end)                  pixel = *(data++);
425    
426                    if (g_host_be)
427                  {                  {
428                          value = *data;                          BSWAP16(pixel);
                         BSWAP16(value);  
                         *out = value;  
                         data++;  
                         out++;  
429                  }                  }
430    
431          }                  value = make_colour(split_colour16(pixel));
432          else  
433          {                  if (g_xserver_be)
434                  while (out < end)                  {
435                            *(out++) = value >> 8;
436                            *(out++) = value;
437                    }
438                    else
439                  {                  {
440                          *out = *data;                          *(out++) = value;
441                          out++;                          *(out++) = value >> 8;
                         data++;  
442                  }                  }
443          }          }
444  }  }
445    
   
446  static void  static void
447  translate16to24(uint16 * data, uint8 * out, uint8 * end)  translate16to24(uint16 * data, uint8 * out, uint8 * end)
448  {  {
# Line 457  translate16to24(uint16 * data, uint8 * o Line 455  translate16to24(uint16 * data, uint8 * o
455    
456                  if (g_host_be)                  if (g_host_be)
457                  {                  {
458                  BSWAP16(pixel)}                          BSWAP16(pixel);
459                    }
460    
461                  value = make_colour24(split_colour16(pixel));                  value = make_colour(split_colour16(pixel));
462    
463                  if (g_xserver_be)                  if (g_xserver_be)
464                  {                  {
# Line 488  translate16to32(uint16 * data, uint8 * o Line 487  translate16to32(uint16 * data, uint8 * o
487    
488                  if (g_host_be)                  if (g_host_be)
489                  {                  {
490                  BSWAP16(pixel)}                          BSWAP16(pixel);
491                    }
492    
493                  value = make_colour32(split_colour16(pixel));                  value = make_colour(split_colour16(pixel));
494    
495                  if (g_xserver_be)                  if (g_xserver_be)
496                  {                  {
# Line 520  translate24to16(uint8 * data, uint8 * ou Line 520  translate24to16(uint8 * data, uint8 * ou
520                  pixel |= *(data++) << 8;                  pixel |= *(data++) << 8;
521                  pixel |= *(data++);                  pixel |= *(data++);
522    
523                  value = (uint16) make_colour16(split_colour24(pixel));                  value = (uint16) make_colour(split_colour24(pixel));
524    
525                  if (g_xserver_be)                  if (g_xserver_be)
526                  {                  {
# Line 538  translate24to16(uint8 * data, uint8 * ou Line 538  translate24to16(uint8 * data, uint8 * ou
538  static void  static void
539  translate24to24(uint8 * data, uint8 * out, uint8 * end)  translate24to24(uint8 * data, uint8 * out, uint8 * end)
540  {  {
541            uint32 pixel;
542            uint32 value;
543    
544          while (out < end)          while (out < end)
545          {          {
546                  *(out++) = (*(data++));                  pixel = *(data++) << 16;
547                    pixel |= *(data++) << 8;
548                    pixel |= *(data++);
549    
550                    value = make_colour(split_colour24(pixel));
551    
552                    if (g_xserver_be)
553                    {
554                            *(out++) = value >> 16;
555                            *(out++) = value >> 8;
556                            *(out++) = value;
557                    }
558                    else
559                    {
560                            *(out++) = value;
561                            *(out++) = value >> 8;
562                            *(out++) = value >> 16;
563                    }
564          }          }
565  }  }
566    
567  static void  static void
568  translate24to32(uint8 * data, uint8 * out, uint8 * end)  translate24to32(uint8 * data, uint8 * out, uint8 * end)
569  {  {
570            uint32 pixel;
571            uint32 value;
572    
573          while (out < end)          while (out < end)
574          {          {
575                    pixel = *(data++) << 16;
576                    pixel |= *(data++) << 8;
577                    pixel |= *(data++);
578    
579                    value = make_colour(split_colour24(pixel));
580    
581                  if (g_xserver_be)                  if (g_xserver_be)
582                  {                  {
583                          *(out++) = 0x00;                          *(out++) = value >> 24;
584                          *(out++) = *(data++);                          *(out++) = value >> 16;
585                          *(out++) = *(data++);                          *(out++) = value >> 8;
586                          *(out++) = *(data++);                          *(out++) = value;
587                  }                  }
588                  else                  else
589                  {                  {
590                          *(out++) = *(data++);                          *(out++) = value;
591                          *(out++) = *(data++);                          *(out++) = value >> 8;
592                          *(out++) = *(data++);                          *(out++) = value >> 16;
593                          *(out++) = 0x00;                          *(out++) = value >> 24;
594                  }                  }
595          }          }
596  }  }
# Line 569  translate24to32(uint8 * data, uint8 * ou Line 598  translate24to32(uint8 * data, uint8 * ou
598  static uint8 *  static uint8 *
599  translate_image(int width, int height, uint8 * data)  translate_image(int width, int height, uint8 * data)
600  {  {
601          int size = width * height * g_bpp / 8;          int size;
602          uint8 *out = (uint8 *) xmalloc(size);          uint8 *out;
603          uint8 *end = out + size;          uint8 *end;
604    
605            /* if server and xserver bpp match, */
606            /* and arch(endian) matches, no need to translate */
607            /* just return data */
608            if (g_arch_match)
609            {
610                    if (g_depth == 15 && g_server_bpp == 15)
611                            return data;
612                    if (g_depth == 16 && g_server_bpp == 16)
613                            return data;
614            }
615    
616            size = width * height * (g_bpp / 8);
617            out = (uint8 *) xmalloc(size);
618            end = out + size;
619    
620          switch (g_server_bpp)          switch (g_server_bpp)
621          {          {
# Line 599  translate_image(int width, int height, u Line 643  translate_image(int width, int height, u
643                                          translate16to24((uint16 *) data, out, end);                                          translate16to24((uint16 *) data, out, end);
644                                          break;                                          break;
645                                  case 16:                                  case 16:
646                                          translate16to16((uint16 *) data, (uint16 *) out,                                          translate16to16((uint16 *) data, out, end);
                                                         (uint16 *) end);  
647                                          break;                                          break;
648                          }                          }
649                          break;                          break;
# Line 625  translate_image(int width, int height, u Line 668  translate_image(int width, int height, u
668                                          translate8to8(data, out, end);                                          translate8to8(data, out, end);
669                                          break;                                          break;
670                                  case 16:                                  case 16:
671                                          translate8to16(data, (uint16 *) out, (uint16 *) end);                                          translate8to16(data, out, end);
672                                          break;                                          break;
673                                  case 24:                                  case 24:
674                                          translate8to24(data, out, end);                                          translate8to24(data, out, end);
675                                          break;                                          break;
676                                  case 32:                                  case 32:
677                                          translate8to32(data, (uint32 *) out, (uint32 *) end);                                          translate8to32(data, out, end);
678                                          break;                                          break;
679                          }                          }
680                          break;                          break;
# Line 664  get_key_state(unsigned int state, uint32 Line 707  get_key_state(unsigned int state, uint32
707          return (state & keysymMask) ? True : False;          return (state & keysymMask) ? True : False;
708  }  }
709    
710    static void
711    calculate_shifts(uint32 mask, int *shift_r, int *shift_l)
712    {
713            *shift_l = ffs(mask) - 1;
714            mask >>= *shift_l;
715            *shift_r = 8 - ffs(mask & ~(mask >> 1));
716    }
717    
718  BOOL  BOOL
719  ui_init(void)  ui_init(void)
720  {  {
721            XVisualInfo vi;
722          XPixmapFormatValues *pfm;          XPixmapFormatValues *pfm;
723          uint16 test;          uint16 test;
724          int i;          int i, screen_num, nvisuals;
725            XVisualInfo *vmatches = NULL;
726            XVisualInfo template;
727            Bool TrueColorVisual = False;
728    
729          g_display = XOpenDisplay(NULL);          g_display = XOpenDisplay(NULL);
730          if (g_display == NULL)          if (g_display == NULL)
# Line 678  ui_init(void) Line 733  ui_init(void)
733                  return False;                  return False;
734          }          }
735    
736            screen_num = DefaultScreen(g_display);
737          g_x_socket = ConnectionNumber(g_display);          g_x_socket = ConnectionNumber(g_display);
738          g_screen = DefaultScreenOfDisplay(g_display);          g_screen = ScreenOfDisplay(g_display, screen_num);
         g_visual = DefaultVisualOfScreen(g_screen);  
739          g_depth = DefaultDepthOfScreen(g_screen);          g_depth = DefaultDepthOfScreen(g_screen);
740    
741            /* Search for best TrueColor depth */
742            template.class = TrueColor;
743            vmatches = XGetVisualInfo(g_display, VisualClassMask, &template, &nvisuals);
744    
745            nvisuals--;
746            while (nvisuals >= 0)
747            {
748                    if ((vmatches + nvisuals)->depth > g_depth)
749                    {
750                            g_depth = (vmatches + nvisuals)->depth;
751                    }
752                    nvisuals--;
753                    TrueColorVisual = True;
754            }
755    
756            test = 1;
757            g_host_be = !(BOOL) (*(uint8 *) (&test));
758            g_xserver_be = (ImageByteOrder(g_display) == MSBFirst);
759    
760            if ((g_server_bpp == 8) && ((!TrueColorVisual) || (g_depth <= 8)))
761            {
762                    /* we use a colourmap, so the default visual should do */
763                    g_visual = DefaultVisualOfScreen(g_screen);
764                    g_depth = DefaultDepthOfScreen(g_screen);
765    
766                    /* Do not allocate colours on a TrueColor visual */
767                    if (g_visual->class == TrueColor)
768                    {
769                            g_owncolmap = False;
770                    }
771            }
772            else
773            {
774                    /* need a truecolour visual */
775                    if (!XMatchVisualInfo(g_display, screen_num, g_depth, TrueColor, &vi))
776                    {
777                            error("The display does not support true colour - high colour support unavailable.\n");
778                            return False;
779                    }
780    
781                    g_visual = vi.visual;
782                    g_owncolmap = False;
783                    calculate_shifts(vi.red_mask, &g_red_shift_r, &g_red_shift_l);
784                    calculate_shifts(vi.blue_mask, &g_blue_shift_r, &g_blue_shift_l);
785                    calculate_shifts(vi.green_mask, &g_green_shift_r, &g_green_shift_l);
786    
787                    /* if RGB video and averything is little endian */
788                    if (vi.red_mask > vi.green_mask && vi.green_mask > vi.blue_mask)
789                            if (!g_xserver_be && !g_host_be)
790                                    g_arch_match = True;
791            }
792    
793          pfm = XListPixmapFormats(g_display, &i);          pfm = XListPixmapFormats(g_display, &i);
794          if (pfm != NULL)          if (pfm != NULL)
795          {          {
# Line 705  ui_init(void) Line 812  ui_init(void)
812                  return False;                  return False;
813          }          }
814    
         /* private colour map code only works for 8 bpp */  
         if (g_owncolmap && (g_bpp > 8))  
                 g_owncolmap = False;  
   
815          if (!g_owncolmap)          if (!g_owncolmap)
816          {          {
817                  g_xcolmap = DefaultColormapOfScreen(g_screen);                  g_xcolmap =
818                            XCreateColormap(g_display, RootWindowOfScreen(g_screen), g_visual,
819                                            AllocNone);
820                  if (g_depth <= 8)                  if (g_depth <= 8)
821                          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");
822          }          }
823    
824          g_gc = XCreateGC(g_display, RootWindowOfScreen(g_screen), 0, NULL);          if ((!g_ownbackstore) && (DoesBackingStore(g_screen) != Always))
825            {
826          if (DoesBackingStore(g_screen) != Always)                  warning("External BackingStore not available, using internal\n");
827                  g_ownbackstore = True;                  g_ownbackstore = True;
828            }
         test = 1;  
         g_host_be = !(BOOL) (*(uint8 *) (&test));  
         g_xserver_be = (ImageByteOrder(g_display) == MSBFirst);  
829    
830          /*          /*
831           * Determine desktop size           * Determine desktop size
832           */           */
833          if (g_width < 0)          if (g_fullscreen)
834            {
835                    g_width = WidthOfScreen(g_screen);
836                    g_height = HeightOfScreen(g_screen);
837            }
838            else if (g_width < 0)
839          {          {
840                  /* Percent of screen */                  /* Percent of screen */
841                  g_height = HeightOfScreen(g_screen) * (-g_width) / 100;                  g_height = HeightOfScreen(g_screen) * (-g_width) / 100;
# Line 751  ui_init(void) Line 858  ui_init(void)
858                          g_height = 600;                          g_height = 600;
859                  }                  }
860          }          }
         else if (g_fullscreen)  
         {  
                 g_width = WidthOfScreen(g_screen);  
                 g_height = HeightOfScreen(g_screen);  
         }  
861    
862          /* make sure width is a multiple of 4 */          /* make sure width is a multiple of 4 */
863          g_width = (g_width + 3) & ~3;          g_width = (g_width + 3) & ~3;
864    
         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);  
         }  
   
865          g_mod_map = XGetModifierMapping(g_display);          g_mod_map = XGetModifierMapping(g_display);
866    
867          xkeymap_init();          xkeymap_init();
# Line 791  ui_deinit(void) Line 882  ui_deinit(void)
882          if (g_IM != NULL)          if (g_IM != NULL)
883                  XCloseIM(g_IM);                  XCloseIM(g_IM);
884    
885            if (g_null_cursor != NULL)
886                    ui_destroy_cursor(g_null_cursor);
887    
888          XFreeModifiermap(g_mod_map);          XFreeModifiermap(g_mod_map);
889    
890          if (g_ownbackstore)          if (g_ownbackstore)
# Line 801  ui_deinit(void) Line 895  ui_deinit(void)
895          g_display = NULL;          g_display = NULL;
896  }  }
897    
 #define NULL_POINTER_MASK       "\x80"  
 #define NULL_POINTER_DATA       "\x0\x0\x0"  
           
898  BOOL  BOOL
899  ui_create_window(void)  ui_create_window(void)
900  {  {
901            uint8 null_pointer_mask[1] = { 0x80 };
902            uint8 null_pointer_data[4] = { 0x00, 0x00, 0x00, 0x00 };
903          XSetWindowAttributes attribs;          XSetWindowAttributes attribs;
904          XClassHint *classhints;          XClassHint *classhints;
905          XSizeHints *sizehints;          XSizeHints *sizehints;
# Line 818  ui_create_window(void) Line 911  ui_create_window(void)
911          wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height;          wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height;
912    
913          attribs.background_pixel = BlackPixelOfScreen(g_screen);          attribs.background_pixel = BlackPixelOfScreen(g_screen);
914            attribs.border_pixel = WhitePixelOfScreen(g_screen);
915          attribs.backing_store = g_ownbackstore ? NotUseful : Always;          attribs.backing_store = g_ownbackstore ? NotUseful : Always;
916          attribs.override_redirect = g_fullscreen;          attribs.override_redirect = g_fullscreen;
917            attribs.colormap = g_xcolmap;
918    
919          g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), 0, 0, wndwidth, wndheight,          g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), 0, 0, wndwidth, wndheight,
920                                0, CopyFromParent, InputOutput, CopyFromParent,                                0, g_depth, InputOutput, g_visual,
921                                CWBackPixel | CWBackingStore | CWOverrideRedirect, &attribs);                                CWBackPixel | CWBackingStore | CWOverrideRedirect |
922                                  CWColormap | CWBorderPixel, &attribs);
923    
924            if (g_gc == NULL)
925                    g_gc = XCreateGC(g_display, g_wnd, 0, NULL);
926    
927            if ((g_ownbackstore) && (g_backstore == 0))
928            {
929                    g_backstore = XCreatePixmap(g_display, g_wnd, g_width, g_height, g_depth);
930    
931                    /* clear to prevent rubbish being exposed at startup */
932                    XSetForeground(g_display, g_gc, BlackPixelOfScreen(g_screen));
933                    XFillRectangle(g_display, g_backstore, g_gc, 0, 0, g_width, g_height);
934            }
935    
936          XStoreName(g_display, g_wnd, g_title);          XStoreName(g_display, g_wnd, g_title);
937    
# Line 848  ui_create_window(void) Line 956  ui_create_window(void)
956                  XFree(sizehints);                  XFree(sizehints);
957          }          }
958    
959            if ( g_embed_wnd )
960            {
961                    XReparentWindow(g_display, g_wnd, (Window)g_embed_wnd, 0, 0);
962            }
963    
964          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
965                  VisibilityChangeMask | FocusChangeMask;                  VisibilityChangeMask | FocusChangeMask;
966    
# Line 889  ui_create_window(void) Line 1002  ui_create_window(void)
1002          XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1);          XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1);
1003    
1004          /* create invisible 1x1 cursor to be used as null cursor */          /* create invisible 1x1 cursor to be used as null cursor */
1005          g_null_cursor = ui_create_cursor(0, 0, 1, 1, NULL_POINTER_MASK, NULL_POINTER_DATA);          if (g_null_cursor == NULL)
1006                    g_null_cursor = ui_create_cursor(0, 0, 1, 1, null_pointer_mask, null_pointer_data);
1007    
1008          return True;          return True;
1009  }  }
# Line 897  ui_create_window(void) Line 1011  ui_create_window(void)
1011  void  void
1012  ui_destroy_window(void)  ui_destroy_window(void)
1013  {  {
         ui_destroy_cursor(g_null_cursor);  
           
1014          if (g_IC != NULL)          if (g_IC != NULL)
1015                  XDestroyIC(g_IC);                  XDestroyIC(g_IC);
1016    
# Line 942  xwin_process_events(void) Line 1054  xwin_process_events(void)
1054          key_translation tr;          key_translation tr;
1055          char str[256];          char str[256];
1056          Status status;          Status status;
         unsigned int state;  
         Window wdummy;  
         int dummy;  
1057    
1058          while (XPending(g_display) > 0)          while (XPending(g_display) > 0)
1059          {          {
# Line 1117  xwin_process_events(void) Line 1226  xwin_process_events(void)
1226                                  if (xevent.xfocus.mode == NotifyGrab)                                  if (xevent.xfocus.mode == NotifyGrab)
1227                                          break;                                          break;
1228                                  g_focused = True;                                  g_focused = True;
1229                                  XQueryPointer(g_display, g_wnd, &wdummy, &wdummy, &dummy, &dummy,                                  reset_modifier_keys();
                                               &dummy, &dummy, &state);  
                                 reset_modifier_keys(state);  
1230                                  if (g_grab_keyboard && g_mouse_in_wnd)                                  if (g_grab_keyboard && g_mouse_in_wnd)
1231                                          XGrabKeyboard(g_display, g_wnd, True,                                          XGrabKeyboard(g_display, g_wnd, True,
1232                                                        GrabModeAsync, GrabModeAsync, CurrentTime);                                                        GrabModeAsync, GrabModeAsync, CurrentTime);
# Line 1199  xwin_process_events(void) Line 1306  xwin_process_events(void)
1306  int  int
1307  ui_select(int rdp_socket)  ui_select(int rdp_socket)
1308  {  {
1309          int n = (rdp_socket > g_x_socket) ? rdp_socket + 1 : g_x_socket + 1;          int n;
1310          fd_set rfds, wfds;          fd_set rfds, wfds;
1311            struct timeval tv;
1312            BOOL s_timeout = False;
1313    
1314          while (True)          while (True)
1315          {          {
1316                    n = (rdp_socket > g_x_socket) ? rdp_socket : g_x_socket;
1317                  /* Process any events already waiting */                  /* Process any events already waiting */
1318                  if (!xwin_process_events())                  if (!xwin_process_events())
1319                          /* User quit */                          /* User quit */
# Line 1219  ui_select(int rdp_socket) Line 1329  ui_select(int rdp_socket)
1329                  if (g_dsp_busy)                  if (g_dsp_busy)
1330                  {                  {
1331                          FD_SET(g_dsp_fd, &wfds);                          FD_SET(g_dsp_fd, &wfds);
1332                          n = (g_dsp_fd + 1 > n) ? g_dsp_fd + 1 : n;                          n = (g_dsp_fd > n) ? g_dsp_fd : n;
1333                  }                  }
1334  #endif  #endif
1335                    /* default timeout */
1336                    tv.tv_sec = 60;
1337                    tv.tv_usec = 0;
1338    
1339                    /* add redirection handles */
1340                    rdpdr_add_fds(&n, &rfds, &wfds, &tv, &s_timeout);
1341    
1342                  switch (select(n, &rfds, &wfds, NULL, NULL))                  n++;
1343    
1344                    switch (select(n, &rfds, &wfds, NULL, &tv))
1345                  {                  {
1346                          case -1:                          case -1:
1347                                  error("select: %s\n", strerror(errno));                                  error("select: %s\n", strerror(errno));
1348    
1349                          case 0:                          case 0:
1350                                    /* TODO: if tv.tv_sec just times out
1351                                     * we will segfault.
1352                                     * FIXME:
1353                                     */
1354                                    //s_timeout = True;
1355                                    //rdpdr_check_fds(&rfds, &wfds, (BOOL) True);
1356                                  continue;                                  continue;
1357                  }                  }
1358    
1359                    rdpdr_check_fds(&rfds, &wfds, (BOOL) False);
1360    
1361                  if (FD_ISSET(rdp_socket, &rfds))                  if (FD_ISSET(rdp_socket, &rfds))
1362                          return 1;                          return 1;
1363    
# Line 1254  ui_create_bitmap(int width, int height, Line 1380  ui_create_bitmap(int width, int height,
1380          XImage *image;          XImage *image;
1381          Pixmap bitmap;          Pixmap bitmap;
1382          uint8 *tdata;          uint8 *tdata;
1383            int bitmap_pad;
1384    
1385            if (g_server_bpp == 8)
1386            {
1387                    bitmap_pad = 8;
1388            }
1389            else
1390            {
1391                    bitmap_pad = g_bpp;
1392    
1393                    if (g_bpp == 24)
1394                            bitmap_pad = 32;
1395            }
1396    
1397          tdata = (g_owncolmap ? data : translate_image(width, height, data));          tdata = (g_owncolmap ? data : translate_image(width, height, data));
1398          bitmap = XCreatePixmap(g_display, g_wnd, width, height, g_depth);          bitmap = XCreatePixmap(g_display, g_wnd, width, height, g_depth);
1399          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,
1400                               (char *) tdata, width, height, g_server_bpp == 8 ? 8 : g_bpp, 0);                               (char *) tdata, width, height, bitmap_pad, 0);
1401    
1402          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);
1403    
1404          XFree(image);          XFree(image);
1405          if (!g_owncolmap)          if (tdata != data)
1406                  xfree(tdata);                  xfree(tdata);
1407          return (HBITMAP) bitmap;          return (HBITMAP) bitmap;
1408  }  }
# Line 1273  ui_paint_bitmap(int x, int y, int cx, in Line 1412  ui_paint_bitmap(int x, int y, int cx, in
1412  {  {
1413          XImage *image;          XImage *image;
1414          uint8 *tdata;          uint8 *tdata;
1415            int bitmap_pad;
1416    
1417            if (g_server_bpp == 8)
1418            {
1419                    bitmap_pad = 8;
1420            }
1421            else
1422            {
1423                    bitmap_pad = g_bpp;
1424    
1425                    if (g_bpp == 24)
1426                            bitmap_pad = 32;
1427            }
1428    
1429          tdata = (g_owncolmap ? data : translate_image(width, height, data));          tdata = (g_owncolmap ? data : translate_image(width, height, data));
1430          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,
1431                               (char *) tdata, width, height, g_server_bpp == 8 ? 8 : g_bpp, 0);                               (char *) tdata, width, height, bitmap_pad, 0);
1432    
1433          if (g_ownbackstore)          if (g_ownbackstore)
1434          {          {
# Line 1288  ui_paint_bitmap(int x, int y, int cx, in Line 1441  ui_paint_bitmap(int x, int y, int cx, in
1441          }          }
1442    
1443          XFree(image);          XFree(image);
1444          if (!g_owncolmap)          if (tdata != data)
1445                  xfree(tdata);                  xfree(tdata);
1446  }  }
1447    
# Line 1501  ui_create_colourmap(COLOURMAP * colours) Line 1654  ui_create_colourmap(COLOURMAP * colours)
1654    
1655                          }                          }
1656    
1657                            map[i] = colour;
                         /* byte swap here to make translate_image faster */  
                         map[i] = translate_colour(colour);  
1658                  }                  }
1659                  return map;                  return map;
1660          }          }
# Line 1662  ui_screenblt(uint8 opcode, Line 1813  ui_screenblt(uint8 opcode,
1813               /* src */ int srcx, int srcy)               /* src */ int srcx, int srcy)
1814  {  {
1815          SET_FUNCTION(opcode);          SET_FUNCTION(opcode);
         XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);  
1816          if (g_ownbackstore)          if (g_ownbackstore)
1817            {
1818                    XCopyArea(g_display, g_backstore, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);
1819                  XCopyArea(g_display, g_backstore, g_backstore, g_gc, srcx, srcy, cx, cy, x, y);                  XCopyArea(g_display, g_backstore, g_backstore, g_gc, srcx, srcy, cx, cy, x, y);
1820            }
1821            else
1822            {
1823                    XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);
1824            }
1825          RESET_FUNCTION(opcode);          RESET_FUNCTION(opcode);
1826  }  }
1827    
# Line 1759  ui_draw_glyph(int mixmode, Line 1916  ui_draw_glyph(int mixmode,
1916  {\  {\
1917    glyph = cache_get_font (font, ttext[idx]);\    glyph = cache_get_font (font, ttext[idx]);\
1918    if (!(flags & TEXT2_IMPLICIT_X))\    if (!(flags & TEXT2_IMPLICIT_X))\
1919      {\
1920        xyoffset = ttext[++idx];\
1921        if ((xyoffset & 0x80))\
1922      {\      {\
1923        xyoffset = ttext[++idx];\        if (flags & TEXT2_VERTICAL)\
1924        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;\  
         }\  
1925        else\        else\
1926          {\          x += ttext[idx+1] | (ttext[idx+2] << 8);\
1927            if (flags & TEXT2_VERTICAL) \        idx += 2;\
             y += xyoffset;\  
           else\  
             x += xyoffset;\  
         }\  
1928      }\      }\
1929    if (glyph != NULL)\      else\
1930      {\      {\
1931        ui_draw_glyph (mixmode, x + glyph->offset,\        if (flags & TEXT2_VERTICAL)\
1932                       y + glyph->baseline,\          y += xyoffset;\
1933                       glyph->width, glyph->height,\        else\
1934                       glyph->pixmap, 0, 0, bgcolour, fgcolour);\          x += xyoffset;\
       if (flags & TEXT2_IMPLICIT_X)\  
         x += glyph->width;\  
1935      }\      }\
1936      }\
1937      if (glyph != NULL)\
1938      {\
1939        x1 = x + glyph->offset;\
1940        y1 = y + glyph->baseline;\
1941        XSetStipple(g_display, g_gc, (Pixmap) glyph->pixmap);\
1942        XSetTSOrigin(g_display, g_gc, x1, y1);\
1943        FILL_RECTANGLE_BACKSTORE(x1, y1, glyph->width, glyph->height);\
1944        if (flags & TEXT2_IMPLICIT_X)\
1945          x += glyph->width;\
1946      }\
1947  }  }
1948    
1949  void  void
# Line 1795  ui_draw_text(uint8 font, uint8 flags, in Line 1953  ui_draw_text(uint8 font, uint8 flags, in
1953               int fgcolour, uint8 * text, uint8 length)               int fgcolour, uint8 * text, uint8 length)
1954  {  {
1955          FONTGLYPH *glyph;          FONTGLYPH *glyph;
1956          int i, j, xyoffset;          int i, j, xyoffset, x1, y1;
1957          DATABLOB *entry;          DATABLOB *entry;
1958    
1959          SET_FOREGROUND(bgcolour);          SET_FOREGROUND(bgcolour);
1960    
1961            /* Sometimes, the boxcx value is something really large, like
1962               32691. This makes XCopyArea fail with Xvnc. The code below
1963               is a quick fix. */
1964            if (boxx + boxcx > g_width)
1965                    boxcx = g_width - boxx;
1966    
1967          if (boxcx > 1)          if (boxcx > 1)
1968          {          {
1969                  FILL_RECTANGLE_BACKSTORE(boxx, boxy, boxcx, boxcy);                  FILL_RECTANGLE_BACKSTORE(boxx, boxy, boxcx, boxcy);
# Line 1809  ui_draw_text(uint8 font, uint8 flags, in Line 1973  ui_draw_text(uint8 font, uint8 flags, in
1973                  FILL_RECTANGLE_BACKSTORE(clipx, clipy, clipcx, clipcy);                  FILL_RECTANGLE_BACKSTORE(clipx, clipy, clipcx, clipcy);
1974          }          }
1975    
1976            SET_FOREGROUND(fgcolour);
1977            SET_BACKGROUND(bgcolour);
1978            XSetFillStyle(g_display, g_gc, FillStippled);
1979    
1980          /* Paint text, character by character */          /* Paint text, character by character */
1981          for (i = 0; i < length;)          for (i = 0; i < length;)
1982          {          {
# Line 1859  ui_draw_text(uint8 font, uint8 flags, in Line 2027  ui_draw_text(uint8 font, uint8 flags, in
2027                                  break;                                  break;
2028                  }                  }
2029          }          }
2030    
2031            XSetFillStyle(g_display, g_gc, FillSolid);
2032    
2033          if (g_ownbackstore)          if (g_ownbackstore)
2034          {          {
2035                  if (boxcx > 1)                  if (boxcx > 1)

Legend:
Removed from v.519  
changed lines
  Added in v.645

  ViewVC Help
Powered by ViewVC 1.1.26