/[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 500 by astrand, Wed Oct 15 14:32:43 2003 UTC revision 679 by jsorg71, Mon Apr 26 23:00:25 2004 UTC
# Line 20  Line 20 
20    
21  #include <X11/Xlib.h>  #include <X11/Xlib.h>
22  #include <X11/Xutil.h>  #include <X11/Xutil.h>
23    #include <unistd.h>
24    #include <sys/time.h>
25  #include <time.h>  #include <time.h>
26  #include <errno.h>  #include <errno.h>
27    #include <strings.h>
28  #include "rdesktop.h"  #include "rdesktop.h"
29  #include "xproto.h"  #include "xproto.h"
30    
# Line 40  Time g_last_gesturetime; Line 43  Time g_last_gesturetime;
43  static int g_x_socket;  static int g_x_socket;
44  static Screen *g_screen;  static Screen *g_screen;
45  Window g_wnd;  Window g_wnd;
46    extern uint32 g_embed_wnd;
47  BOOL g_enable_compose = False;  BOOL g_enable_compose = False;
48  static GC g_gc;  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 = 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;  extern BOOL g_ownbackstore;
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 69  static int g_move_y_offset = 0; Line 77  static int g_move_y_offset = 0;
77  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
78  extern int g_dsp_fd;  extern int g_dsp_fd;
79  extern BOOL g_dsp_busy;  extern BOOL g_dsp_busy;
80    extern BOOL g_rdpsnd;
81  #endif  #endif
82    
83  /* MWM decorations */  /* MWM decorations */
# Line 106  PixelColour; Line 115  PixelColour;
115  }  }
116    
117  /* colour maps */  /* colour maps */
118  BOOL g_owncolmap = False;  extern BOOL g_owncolmap;
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 162  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 175  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 189  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    #define UNROLL8(stm) { stm stm stm stm stm stm stm stm }
233    #define REPEAT(stm) \
234    { \
235            while (out <= end - 8 * 4) \
236                    UNROLL8(stm) \
237            while (out < end) \
238                    { stm } \
239  }  }
240    
241  static void  static void
# Line 291  translate8to8(uint8 * data, uint8 * out, Line 246  translate8to8(uint8 * data, uint8 * out,
246  }  }
247    
248  static void  static void
249  translate8to16(uint8 * data, uint16 * out, uint16 * end)  translate8to16(uint8 * data, uint8 * out, uint8 * end)
250  {  {
251          while (out < end)          uint16 value;
252                  *(out++) = (uint16) g_colmap[*(data++)];  
253            if (g_arch_match)
254                    REPEAT(*(((uint16*)out)++) = g_colmap[*(data++)];)
255            else if (g_xserver_be)
256            {
257                    while (out < end)
258                    {
259                            value = (uint16) g_colmap[*(data++)];
260                            *(out++) = value >> 8;
261                            *(out++) = value;
262                    }
263            }
264            else
265            {
266                    while (out < end)
267                    {
268                            value = (uint16) g_colmap[*(data++)];
269                            *(out++) = value;
270                            *(out++) = value >> 8;
271                    }
272            }
273  }  }
274    
275  /* little endian - conversion happens when colourmap is built */  /* little endian - conversion happens when colourmap is built */
# Line 303  translate8to24(uint8 * data, uint8 * out Line 278  translate8to24(uint8 * data, uint8 * out
278  {  {
279          uint32 value;          uint32 value;
280    
281          while (out < end)          if (g_xserver_be)
282          {          {
283                  value = g_colmap[*(data++)];                  while (out < end)
284                  *(out++) = value;                  {
285                  *(out++) = value >> 8;                          value = g_colmap[*(data++)];
286                  *(out++) = value >> 16;                          *(out++) = value >> 16;
287                            *(out++) = value >> 8;
288                            *(out++) = value;
289                    }
290            }
291            else
292            {
293                    while (out < end)
294                    {
295                            value = g_colmap[*(data++)];
296                            *(out++) = value;
297                            *(out++) = value >> 8;
298                            *(out++) = value >> 16;
299                    }
300          }          }
301  }  }
302    
303  static void  static void
304  translate8to32(uint8 * data, uint32 * out, uint32 * end)  translate8to32(uint8 * data, uint8 * out, uint8 * end)
305  {  {
306          while (out < end)          uint32 value;
                 *(out++) = g_colmap[*(data++)];  
 }  
307    
308  /* todo the remaining translate function might need some big endian check ?? */          if (g_arch_match)
309                    REPEAT(*(((uint32*)out)++) = g_colmap[*(data++)];)
310            else if (g_xserver_be)
311            {
312                    while (out < end)
313                    {
314                            value = g_colmap[*(data++)];
315                            *(out++) = value >> 24;
316                            *(out++) = value >> 16;
317                            *(out++) = value >> 8;
318                            *(out++) = value;
319                    }
320            }
321            else
322            {
323                    while (out < end)
324                    {
325                            value = g_colmap[*(data++)];
326                            *(out++) = value;
327                            *(out++) = value >> 8;
328                            *(out++) = value >> 16;
329                            *(out++) = value >> 24;
330                    }
331            }
332    }
333    
334  static void  static void
335  translate15to16(uint16 * data, uint8 * out, uint8 * end)  translate15to16(uint16 * data, uint8 * out, uint8 * end)
# Line 333  translate15to16(uint16 * data, uint8 * o Line 343  translate15to16(uint16 * data, uint8 * o
343    
344                  if (g_host_be)                  if (g_host_be)
345                  {                  {
346                  BSWAP16(pixel)}                          BSWAP16(pixel);
347                    }
348    
349                  value = make_colour16(split_colour15(pixel));                  value = make_colour(split_colour15(pixel));
350    
351                  if (g_xserver_be)                  if (g_xserver_be)
352                  {                  {
# Line 362  translate15to24(uint16 * data, uint8 * o Line 373  translate15to24(uint16 * data, uint8 * o
373    
374                  if (g_host_be)                  if (g_host_be)
375                  {                  {
376                  BSWAP16(pixel)}                          BSWAP16(pixel);
377                    }
378    
379                  value = make_colour24(split_colour15(pixel));                  value = make_colour(split_colour15(pixel));
380                  if (g_xserver_be)                  if (g_xserver_be)
381                  {                  {
382                          *(out++) = value >> 16;                          *(out++) = value >> 16;
# Line 395  translate15to32(uint16 * data, uint8 * o Line 407  translate15to32(uint16 * data, uint8 * o
407                          BSWAP16(pixel);                          BSWAP16(pixel);
408                  }                  }
409    
410                  value = make_colour32(split_colour15(pixel));                  value = make_colour(split_colour15(pixel));
411    
412                  if (g_xserver_be)                  if (g_xserver_be)
413                  {                  {
# Line 415  translate15to32(uint16 * data, uint8 * o Line 427  translate15to32(uint16 * data, uint8 * o
427  }  }
428    
429  static void  static void
430  translate16to16(uint16 * data, uint16 * out, uint16 * end)  translate16to16(uint16 * data, uint8 * out, uint8 * end)
431  {  {
432            uint16 pixel;
433          uint16 value;          uint16 value;
434    
435          if (g_xserver_be)          while (out < end)
436          {          {
437                  while (out < end)                  pixel = *(data++);
438    
439                    if (g_host_be)
440                  {                  {
441                          value = *data;                          BSWAP16(pixel);
                         BSWAP16(value);  
                         *out = value;  
                         data++;  
                         out++;  
442                  }                  }
443    
444          }                  value = make_colour(split_colour16(pixel));
445          else  
446          {                  if (g_xserver_be)
447                  while (out < end)                  {
448                            *(out++) = value >> 8;
449                            *(out++) = value;
450                    }
451                    else
452                  {                  {
453                          *out = *data;                          *(out++) = value;
454                          out++;                          *(out++) = value >> 8;
                         data++;  
455                  }                  }
456          }          }
457  }  }
458    
   
459  static void  static void
460  translate16to24(uint16 * data, uint8 * out, uint8 * end)  translate16to24(uint16 * data, uint8 * out, uint8 * end)
461  {  {
# Line 455  translate16to24(uint16 * data, uint8 * o Line 468  translate16to24(uint16 * data, uint8 * o
468    
469                  if (g_host_be)                  if (g_host_be)
470                  {                  {
471                  BSWAP16(pixel)}                          BSWAP16(pixel);
472                    }
473    
474                  value = make_colour24(split_colour16(pixel));                  value = make_colour(split_colour16(pixel));
475    
476                  if (g_xserver_be)                  if (g_xserver_be)
477                  {                  {
# Line 486  translate16to32(uint16 * data, uint8 * o Line 500  translate16to32(uint16 * data, uint8 * o
500    
501                  if (g_host_be)                  if (g_host_be)
502                  {                  {
503                  BSWAP16(pixel)}                          BSWAP16(pixel);
504                    }
505    
506                  value = make_colour32(split_colour16(pixel));                  value = make_colour(split_colour16(pixel));
507    
508                  if (g_xserver_be)                  if (g_xserver_be)
509                  {                  {
# Line 518  translate24to16(uint8 * data, uint8 * ou Line 533  translate24to16(uint8 * data, uint8 * ou
533                  pixel |= *(data++) << 8;                  pixel |= *(data++) << 8;
534                  pixel |= *(data++);                  pixel |= *(data++);
535    
536                  value = (uint16) make_colour16(split_colour24(pixel));                  value = (uint16) make_colour(split_colour24(pixel));
537    
538                  if (g_xserver_be)                  if (g_xserver_be)
539                  {                  {
# Line 536  translate24to16(uint8 * data, uint8 * ou Line 551  translate24to16(uint8 * data, uint8 * ou
551  static void  static void
552  translate24to24(uint8 * data, uint8 * out, uint8 * end)  translate24to24(uint8 * data, uint8 * out, uint8 * end)
553  {  {
554            uint32 pixel;
555            uint32 value;
556    
557          while (out < end)          while (out < end)
558          {          {
559                  *(out++) = (*(data++));                  pixel = *(data++) << 16;
560                    pixel |= *(data++) << 8;
561                    pixel |= *(data++);
562    
563                    value = make_colour(split_colour24(pixel));
564    
565                    if (g_xserver_be)
566                    {
567                            *(out++) = value >> 16;
568                            *(out++) = value >> 8;
569                            *(out++) = value;
570                    }
571                    else
572                    {
573                            *(out++) = value;
574                            *(out++) = value >> 8;
575                            *(out++) = value >> 16;
576                    }
577          }          }
578  }  }
579    
580  static void  static void
581  translate24to32(uint8 * data, uint8 * out, uint8 * end)  translate24to32(uint8 * data, uint8 * out, uint8 * end)
582  {  {
583            uint32 pixel;
584            uint32 value;
585    
586          while (out < end)          while (out < end)
587          {          {
588                    pixel = *(data++) << 16;
589                    pixel |= *(data++) << 8;
590                    pixel |= *(data++);
591    
592                    value = make_colour(split_colour24(pixel));
593    
594                  if (g_xserver_be)                  if (g_xserver_be)
595                  {                  {
596                          *(out++) = 0x00;                          *(out++) = value >> 24;
597                          *(out++) = *(data++);                          *(out++) = value >> 16;
598                          *(out++) = *(data++);                          *(out++) = value >> 8;
599                          *(out++) = *(data++);                          *(out++) = value;
600                  }                  }
601                  else                  else
602                  {                  {
603                          *(out++) = *(data++);                          *(out++) = value;
604                          *(out++) = *(data++);                          *(out++) = value >> 8;
605                          *(out++) = *(data++);                          *(out++) = value >> 16;
606                          *(out++) = 0x00;                          *(out++) = value >> 24;
607                  }                  }
608          }          }
609  }  }
# Line 567  translate24to32(uint8 * data, uint8 * ou Line 611  translate24to32(uint8 * data, uint8 * ou
611  static uint8 *  static uint8 *
612  translate_image(int width, int height, uint8 * data)  translate_image(int width, int height, uint8 * data)
613  {  {
614          int size = width * height * g_bpp / 8;          int size;
615          uint8 *out = (uint8 *) xmalloc(size);          uint8 *out;
616          uint8 *end = out + size;          uint8 *end;
617    
618            /* if server and xserver bpp match, */
619            /* and arch(endian) matches, no need to translate */
620            /* just return data */
621            if (g_arch_match)
622            {
623                    if (g_depth == 15 && g_server_bpp == 15)
624                            return data;
625                    if (g_depth == 16 && g_server_bpp == 16)
626                            return data;
627            }
628    
629            size = width * height * (g_bpp / 8);
630            out = (uint8 *) xmalloc(size);
631            end = out + size;
632    
633          switch (g_server_bpp)          switch (g_server_bpp)
634          {          {
# Line 597  translate_image(int width, int height, u Line 656  translate_image(int width, int height, u
656                                          translate16to24((uint16 *) data, out, end);                                          translate16to24((uint16 *) data, out, end);
657                                          break;                                          break;
658                                  case 16:                                  case 16:
659                                          translate16to16((uint16 *) data, (uint16 *) out,                                          translate16to16((uint16 *) data, out, end);
                                                         (uint16 *) end);  
660                                          break;                                          break;
661                          }                          }
662                          break;                          break;
# Line 623  translate_image(int width, int height, u Line 681  translate_image(int width, int height, u
681                                          translate8to8(data, out, end);                                          translate8to8(data, out, end);
682                                          break;                                          break;
683                                  case 16:                                  case 16:
684                                          translate8to16(data, (uint16 *) out, (uint16 *) end);                                          translate8to16(data, out, end);
685                                          break;                                          break;
686                                  case 24:                                  case 24:
687                                          translate8to24(data, out, end);                                          translate8to24(data, out, end);
688                                          break;                                          break;
689                                  case 32:                                  case 32:
690                                          translate8to32(data, (uint32 *) out, (uint32 *) end);                                          translate8to32(data, out, end);
691                                          break;                                          break;
692                          }                          }
693                          break;                          break;
# Line 662  get_key_state(unsigned int state, uint32 Line 720  get_key_state(unsigned int state, uint32
720          return (state & keysymMask) ? True : False;          return (state & keysymMask) ? True : False;
721  }  }
722    
723    static void
724    calculate_shifts(uint32 mask, int *shift_r, int *shift_l)
725    {
726            *shift_l = ffs(mask) - 1;
727            mask >>= *shift_l;
728            *shift_r = 8 - ffs(mask & ~(mask >> 1));
729    }
730    
731  BOOL  BOOL
732  ui_init(void)  ui_init(void)
733  {  {
734            XVisualInfo vi;
735          XPixmapFormatValues *pfm;          XPixmapFormatValues *pfm;
736          uint16 test;          uint16 test;
737          int i;          int i, screen_num, nvisuals;
738            XVisualInfo *vmatches = NULL;
739            XVisualInfo template;
740            Bool TrueColorVisual = False;
741    
742          g_display = XOpenDisplay(NULL);          g_display = XOpenDisplay(NULL);
743          if (g_display == NULL)          if (g_display == NULL)
# Line 676  ui_init(void) Line 746  ui_init(void)
746                  return False;                  return False;
747          }          }
748    
749            screen_num = DefaultScreen(g_display);
750          g_x_socket = ConnectionNumber(g_display);          g_x_socket = ConnectionNumber(g_display);
751          g_screen = DefaultScreenOfDisplay(g_display);          g_screen = ScreenOfDisplay(g_display, screen_num);
         g_visual = DefaultVisualOfScreen(g_screen);  
752          g_depth = DefaultDepthOfScreen(g_screen);          g_depth = DefaultDepthOfScreen(g_screen);
753    
754            /* Search for best TrueColor depth */
755            template.class = TrueColor;
756            vmatches = XGetVisualInfo(g_display, VisualClassMask, &template, &nvisuals);
757    
758            nvisuals--;
759            while (nvisuals >= 0)
760            {
761                    if ((vmatches + nvisuals)->depth > g_depth)
762                    {
763                            g_depth = (vmatches + nvisuals)->depth;
764                    }
765                    nvisuals--;
766                    TrueColorVisual = True;
767            }
768    
769            test = 1;
770            g_host_be = !(BOOL) (*(uint8 *) (&test));
771            g_xserver_be = (ImageByteOrder(g_display) == MSBFirst);
772    
773            if ((g_server_bpp == 8) && ((!TrueColorVisual) || (g_depth <= 8)))
774            {
775                    /* we use a colourmap, so the default visual should do */
776                    g_visual = DefaultVisualOfScreen(g_screen);
777                    g_depth = DefaultDepthOfScreen(g_screen);
778    
779                    /* Do not allocate colours on a TrueColor visual */
780                    if (g_visual->class == TrueColor)
781                    {
782                            g_owncolmap = False;
783                    }
784            }
785            else
786            {
787                    /* need a truecolour visual */
788                    if (!XMatchVisualInfo(g_display, screen_num, g_depth, TrueColor, &vi))
789                    {
790                            error("The display does not support true colour - high colour support unavailable.\n");
791                            return False;
792                    }
793    
794                    g_visual = vi.visual;
795                    g_owncolmap = False;
796                    calculate_shifts(vi.red_mask, &g_red_shift_r, &g_red_shift_l);
797                    calculate_shifts(vi.blue_mask, &g_blue_shift_r, &g_blue_shift_l);
798                    calculate_shifts(vi.green_mask, &g_green_shift_r, &g_green_shift_l);
799    
800                    /* if RGB video and averything is little endian */
801                    if (vi.red_mask > vi.green_mask && vi.green_mask > vi.blue_mask)
802                            if (!g_xserver_be && !g_host_be)
803                                    g_arch_match = True;
804            }
805    
806          pfm = XListPixmapFormats(g_display, &i);          pfm = XListPixmapFormats(g_display, &i);
807          if (pfm != NULL)          if (pfm != NULL)
808          {          {
# Line 703  ui_init(void) Line 825  ui_init(void)
825                  return False;                  return False;
826          }          }
827    
828          if (g_owncolmap != True)          if (!g_owncolmap)
829          {          {
830                  g_xcolmap = DefaultColormapOfScreen(g_screen);                  g_xcolmap =
831                            XCreateColormap(g_display, RootWindowOfScreen(g_screen), g_visual,
832                                            AllocNone);
833                  if (g_depth <= 8)                  if (g_depth <= 8)
834                          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");
835          }          }
836    
837          g_gc = XCreateGC(g_display, RootWindowOfScreen(g_screen), 0, NULL);          if ((!g_ownbackstore) && (DoesBackingStore(g_screen) != Always))
838            {
839          if (DoesBackingStore(g_screen) != Always)                  warning("External BackingStore not available, using internal\n");
840                  g_ownbackstore = True;                  g_ownbackstore = True;
841            }
         test = 1;  
         g_host_be = !(BOOL) (*(uint8 *) (&test));  
         g_xserver_be = (ImageByteOrder(g_display) == MSBFirst);  
842    
843          /*          /*
844           * Determine desktop size           * Determine desktop size
845           */           */
846          if (g_width < 0)          if (g_fullscreen)
847            {
848                    g_width = WidthOfScreen(g_screen);
849                    g_height = HeightOfScreen(g_screen);
850            }
851            else if (g_width < 0)
852          {          {
853                  /* Percent of screen */                  /* Percent of screen */
854                  g_height = HeightOfScreen(g_screen) * (-g_width) / 100;                  g_height = HeightOfScreen(g_screen) * (-g_width) / 100;
# Line 745  ui_init(void) Line 871  ui_init(void)
871                          g_height = 600;                          g_height = 600;
872                  }                  }
873          }          }
         else if (g_fullscreen)  
         {  
                 g_width = WidthOfScreen(g_screen);  
                 g_height = HeightOfScreen(g_screen);  
         }  
874    
875          /* make sure width is a multiple of 4 */          /* make sure width is a multiple of 4 */
876          g_width = (g_width + 3) & ~3;          g_width = (g_width + 3) & ~3;
877    
         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);  
         }  
   
878          g_mod_map = XGetModifierMapping(g_display);          g_mod_map = XGetModifierMapping(g_display);
879    
880          xkeymap_init();          xkeymap_init();
# Line 774  ui_init(void) Line 884  ui_init(void)
884    
885          xclip_init();          xclip_init();
886    
887          /* 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);  
888    
889          return True;          return True;
890  }  }
# Line 786  ui_deinit(void) Line 895  ui_deinit(void)
895          if (g_IM != NULL)          if (g_IM != NULL)
896                  XCloseIM(g_IM);                  XCloseIM(g_IM);
897    
898            if (g_null_cursor != NULL)
899                    ui_destroy_cursor(g_null_cursor);
900    
901          XFreeModifiermap(g_mod_map);          XFreeModifiermap(g_mod_map);
902    
903          if (g_ownbackstore)          if (g_ownbackstore)
# Line 799  ui_deinit(void) Line 911  ui_deinit(void)
911  BOOL  BOOL
912  ui_create_window(void)  ui_create_window(void)
913  {  {
914            uint8 null_pointer_mask[1] = { 0x80 };
915            uint8 null_pointer_data[4] = { 0x00, 0x00, 0x00, 0x00 };
916          XSetWindowAttributes attribs;          XSetWindowAttributes attribs;
917          XClassHint *classhints;          XClassHint *classhints;
918          XSizeHints *sizehints;          XSizeHints *sizehints;
# Line 810  ui_create_window(void) Line 924  ui_create_window(void)
924          wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height;          wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height;
925    
926          attribs.background_pixel = BlackPixelOfScreen(g_screen);          attribs.background_pixel = BlackPixelOfScreen(g_screen);
927            attribs.border_pixel = WhitePixelOfScreen(g_screen);
928          attribs.backing_store = g_ownbackstore ? NotUseful : Always;          attribs.backing_store = g_ownbackstore ? NotUseful : Always;
929          attribs.override_redirect = g_fullscreen;          attribs.override_redirect = g_fullscreen;
930            attribs.colormap = g_xcolmap;
931    
932          g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), 0, 0, wndwidth, wndheight,          g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), 0, 0, wndwidth, wndheight,
933                                0, CopyFromParent, InputOutput, CopyFromParent,                                0, g_depth, InputOutput, g_visual,
934                                CWBackPixel | CWBackingStore | CWOverrideRedirect, &attribs);                                CWBackPixel | CWBackingStore | CWOverrideRedirect |
935                                  CWColormap | CWBorderPixel, &attribs);
936    
937            if (g_gc == NULL)
938                    g_gc = XCreateGC(g_display, g_wnd, 0, NULL);
939    
940            if ((g_ownbackstore) && (g_backstore == 0))
941            {
942                    g_backstore = XCreatePixmap(g_display, g_wnd, g_width, g_height, g_depth);
943    
944                    /* clear to prevent rubbish being exposed at startup */
945                    XSetForeground(g_display, g_gc, BlackPixelOfScreen(g_screen));
946                    XFillRectangle(g_display, g_backstore, g_gc, 0, 0, g_width, g_height);
947            }
948    
949          XStoreName(g_display, g_wnd, g_title);          XStoreName(g_display, g_wnd, g_title);
950    
# Line 840  ui_create_window(void) Line 969  ui_create_window(void)
969                  XFree(sizehints);                  XFree(sizehints);
970          }          }
971    
972            if (g_embed_wnd)
973            {
974                    XReparentWindow(g_display, g_wnd, (Window) g_embed_wnd, 0, 0);
975            }
976    
977          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
978                  VisibilityChangeMask | FocusChangeMask;                  VisibilityChangeMask | FocusChangeMask;
979    
# Line 880  ui_create_window(void) Line 1014  ui_create_window(void)
1014          g_kill_atom = XInternAtom(g_display, "WM_DELETE_WINDOW", True);          g_kill_atom = XInternAtom(g_display, "WM_DELETE_WINDOW", True);
1015          XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1);          XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1);
1016    
1017            /* create invisible 1x1 cursor to be used as null cursor */
1018            if (g_null_cursor == NULL)
1019                    g_null_cursor = ui_create_cursor(0, 0, 1, 1, null_pointer_mask, null_pointer_data);
1020    
1021          return True;          return True;
1022  }  }
1023    
1024  void  void
1025    ui_resize_window()
1026    {
1027            XSizeHints *sizehints;
1028    
1029            sizehints = XAllocSizeHints();
1030            if (sizehints)
1031            {
1032                    sizehints->flags = PMinSize | PMaxSize;
1033                    sizehints->min_width = sizehints->max_width = g_width;
1034                    sizehints->min_height = sizehints->max_height = g_height;
1035                    XSetWMNormalHints(g_display, g_wnd, sizehints);
1036                    XFree(sizehints);
1037            }
1038    
1039            if (!(g_fullscreen || g_embed_wnd))
1040            {
1041                    XResizeWindow(g_display, g_wnd, g_width, g_height);
1042            }
1043    }
1044    
1045    void
1046  ui_destroy_window(void)  ui_destroy_window(void)
1047  {  {
1048          if (g_IC != NULL)          if (g_IC != NULL)
# Line 929  xwin_process_events(void) Line 1088  xwin_process_events(void)
1088          key_translation tr;          key_translation tr;
1089          char str[256];          char str[256];
1090          Status status;          Status status;
         unsigned int state;  
         Window wdummy;  
         int dummy;  
1091    
1092          while (XPending(g_display) > 0)          while (XPending(g_display) > 0)
1093          {          {
# Line 1104  xwin_process_events(void) Line 1260  xwin_process_events(void)
1260                                  if (xevent.xfocus.mode == NotifyGrab)                                  if (xevent.xfocus.mode == NotifyGrab)
1261                                          break;                                          break;
1262                                  g_focused = True;                                  g_focused = True;
1263                                  XQueryPointer(g_display, g_wnd, &wdummy, &wdummy, &dummy, &dummy,                                  reset_modifier_keys();
                                               &dummy, &dummy, &state);  
                                 reset_modifier_keys(state);  
1264                                  if (g_grab_keyboard && g_mouse_in_wnd)                                  if (g_grab_keyboard && g_mouse_in_wnd)
1265                                          XGrabKeyboard(g_display, g_wnd, True,                                          XGrabKeyboard(g_display, g_wnd, True,
1266                                                        GrabModeAsync, GrabModeAsync, CurrentTime);                                                        GrabModeAsync, GrabModeAsync, CurrentTime);
# Line 1186  xwin_process_events(void) Line 1340  xwin_process_events(void)
1340  int  int
1341  ui_select(int rdp_socket)  ui_select(int rdp_socket)
1342  {  {
1343          int n = (rdp_socket > g_x_socket) ? rdp_socket + 1 : g_x_socket + 1;          int n;
1344          fd_set rfds, wfds;          fd_set rfds, wfds;
1345            struct timeval tv;
1346            BOOL s_timeout = False;
1347    
1348          while (True)          while (True)
1349          {          {
1350                    n = (rdp_socket > g_x_socket) ? rdp_socket : g_x_socket;
1351                  /* Process any events already waiting */                  /* Process any events already waiting */
1352                  if (!xwin_process_events())                  if (!xwin_process_events())
1353                          /* User quit */                          /* User quit */
# Line 1206  ui_select(int rdp_socket) Line 1363  ui_select(int rdp_socket)
1363                  if (g_dsp_busy)                  if (g_dsp_busy)
1364                  {                  {
1365                          FD_SET(g_dsp_fd, &wfds);                          FD_SET(g_dsp_fd, &wfds);
1366                          n = (g_dsp_fd + 1 > n) ? g_dsp_fd + 1 : n;                          n = (g_dsp_fd > n) ? g_dsp_fd : n;
1367                  }                  }
1368  #endif  #endif
1369                    /* default timeout */
1370                    tv.tv_sec = 60;
1371                    tv.tv_usec = 0;
1372    
1373                  switch (select(n, &rfds, &wfds, NULL, NULL))                  /* add redirection handles */
1374                    rdpdr_add_fds(&n, &rfds, &wfds, &tv, &s_timeout);
1375    
1376                    n++;
1377    
1378                    switch (select(n, &rfds, &wfds, NULL, &tv))
1379                  {                  {
1380                          case -1:                          case -1:
1381                                  error("select: %s\n", strerror(errno));                                  error("select: %s\n", strerror(errno));
1382    
1383                          case 0:                          case 0:
1384                                    /* TODO: if tv.tv_sec just times out
1385                                     * we will segfault.
1386                                     * FIXME:
1387                                     */
1388                                    //s_timeout = True;
1389                                    //rdpdr_check_fds(&rfds, &wfds, (BOOL) True);
1390                                  continue;                                  continue;
1391                  }                  }
1392    
1393                    rdpdr_check_fds(&rfds, &wfds, (BOOL) False);
1394    
1395                  if (FD_ISSET(rdp_socket, &rfds))                  if (FD_ISSET(rdp_socket, &rfds))
1396                          return 1;                          return 1;
1397    
# Line 1241  ui_create_bitmap(int width, int height, Line 1414  ui_create_bitmap(int width, int height,
1414          XImage *image;          XImage *image;
1415          Pixmap bitmap;          Pixmap bitmap;
1416          uint8 *tdata;          uint8 *tdata;
1417            int bitmap_pad;
1418    
1419            if (g_server_bpp == 8)
1420            {
1421                    bitmap_pad = 8;
1422            }
1423            else
1424            {
1425                    bitmap_pad = g_bpp;
1426    
1427                    if (g_bpp == 24)
1428                            bitmap_pad = 32;
1429            }
1430    
1431          tdata = (g_owncolmap ? data : translate_image(width, height, data));          tdata = (g_owncolmap ? data : translate_image(width, height, data));
1432          bitmap = XCreatePixmap(g_display, g_wnd, width, height, g_depth);          bitmap = XCreatePixmap(g_display, g_wnd, width, height, g_depth);
1433          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,
1434                               (char *) tdata, width, height, g_server_bpp == 8 ? 8 : g_bpp, 0);                               (char *) tdata, width, height, bitmap_pad, 0);
1435    
1436          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);
1437    
1438          XFree(image);          XFree(image);
1439          if (!g_owncolmap)          if (tdata != data)
1440                  xfree(tdata);                  xfree(tdata);
1441          return (HBITMAP) bitmap;          return (HBITMAP) bitmap;
1442  }  }
# Line 1260  ui_paint_bitmap(int x, int y, int cx, in Line 1446  ui_paint_bitmap(int x, int y, int cx, in
1446  {  {
1447          XImage *image;          XImage *image;
1448          uint8 *tdata;          uint8 *tdata;
1449            int bitmap_pad;
1450    
1451            if (g_server_bpp == 8)
1452            {
1453                    bitmap_pad = 8;
1454            }
1455            else
1456            {
1457                    bitmap_pad = g_bpp;
1458    
1459                    if (g_bpp == 24)
1460                            bitmap_pad = 32;
1461            }
1462    
1463          tdata = (g_owncolmap ? data : translate_image(width, height, data));          tdata = (g_owncolmap ? data : translate_image(width, height, data));
1464          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,
1465                               (char *) tdata, width, height, g_server_bpp == 8 ? 8 : g_bpp, 0);                               (char *) tdata, width, height, bitmap_pad, 0);
1466    
1467          if (g_ownbackstore)          if (g_ownbackstore)
1468          {          {
# Line 1275  ui_paint_bitmap(int x, int y, int cx, in Line 1475  ui_paint_bitmap(int x, int y, int cx, in
1475          }          }
1476    
1477          XFree(image);          XFree(image);
1478          if (!g_owncolmap)          if (tdata != data)
1479                  xfree(tdata);                  xfree(tdata);
1480  }  }
1481    
# Line 1401  ui_destroy_cursor(HCURSOR cursor) Line 1601  ui_destroy_cursor(HCURSOR cursor)
1601          XFreeCursor(g_display, (Cursor) cursor);          XFreeCursor(g_display, (Cursor) cursor);
1602  }  }
1603    
1604    void
1605    ui_set_null_cursor(void)
1606    {
1607            ui_set_cursor(g_null_cursor);
1608    }
1609    
1610  #define MAKE_XCOLOR(xc,c) \  #define MAKE_XCOLOR(xc,c) \
1611                  (xc)->red   = ((c)->red   << 8) | (c)->red; \                  (xc)->red   = ((c)->red   << 8) | (c)->red; \
1612                  (xc)->green = ((c)->green << 8) | (c)->green; \                  (xc)->green = ((c)->green << 8) | (c)->green; \
# Line 1482  ui_create_colourmap(COLOURMAP * colours) Line 1688  ui_create_colourmap(COLOURMAP * colours)
1688    
1689                          }                          }
1690    
1691                            map[i] = colour;
                         /* byte swap here to make translate_image faster */  
                         map[i] = translate_colour(colour);  
1692                  }                  }
1693                  return map;                  return map;
1694          }          }
# Line 1643  ui_screenblt(uint8 opcode, Line 1847  ui_screenblt(uint8 opcode,
1847               /* src */ int srcx, int srcy)               /* src */ int srcx, int srcy)
1848  {  {
1849          SET_FUNCTION(opcode);          SET_FUNCTION(opcode);
         XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);  
1850          if (g_ownbackstore)          if (g_ownbackstore)
1851            {
1852                    XCopyArea(g_display, g_backstore, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);
1853                  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);
1854            }
1855            else
1856            {
1857                    XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);
1858            }
1859          RESET_FUNCTION(opcode);          RESET_FUNCTION(opcode);
1860  }  }
1861    
# Line 1740  ui_draw_glyph(int mixmode, Line 1950  ui_draw_glyph(int mixmode,
1950  {\  {\
1951    glyph = cache_get_font (font, ttext[idx]);\    glyph = cache_get_font (font, ttext[idx]);\
1952    if (!(flags & TEXT2_IMPLICIT_X))\    if (!(flags & TEXT2_IMPLICIT_X))\
1953      {\
1954        xyoffset = ttext[++idx];\
1955        if ((xyoffset & 0x80))\
1956      {\      {\
1957        xyoffset = ttext[++idx];\        if (flags & TEXT2_VERTICAL)\
1958        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;\  
         }\  
1959        else\        else\
1960          {\          x += ttext[idx+1] | (ttext[idx+2] << 8);\
1961            if (flags & TEXT2_VERTICAL) \        idx += 2;\
             y += xyoffset;\  
           else\  
             x += xyoffset;\  
         }\  
1962      }\      }\
1963    if (glyph != NULL)\      else\
1964      {\      {\
1965        ui_draw_glyph (mixmode, x + glyph->offset,\        if (flags & TEXT2_VERTICAL)\
1966                       y + glyph->baseline,\          y += xyoffset;\
1967                       glyph->width, glyph->height,\        else\
1968                       glyph->pixmap, 0, 0, bgcolour, fgcolour);\          x += xyoffset;\
       if (flags & TEXT2_IMPLICIT_X)\  
         x += glyph->width;\  
1969      }\      }\
1970      }\
1971      if (glyph != NULL)\
1972      {\
1973        x1 = x + glyph->offset;\
1974        y1 = y + glyph->baseline;\
1975        XSetStipple(g_display, g_gc, (Pixmap) glyph->pixmap);\
1976        XSetTSOrigin(g_display, g_gc, x1, y1);\
1977        FILL_RECTANGLE_BACKSTORE(x1, y1, glyph->width, glyph->height);\
1978        if (flags & TEXT2_IMPLICIT_X)\
1979          x += glyph->width;\
1980      }\
1981  }  }
1982    
1983  void  void
# Line 1776  ui_draw_text(uint8 font, uint8 flags, in Line 1987  ui_draw_text(uint8 font, uint8 flags, in
1987               int fgcolour, uint8 * text, uint8 length)               int fgcolour, uint8 * text, uint8 length)
1988  {  {
1989          FONTGLYPH *glyph;          FONTGLYPH *glyph;
1990          int i, j, xyoffset;          int i, j, xyoffset, x1, y1;
1991          DATABLOB *entry;          DATABLOB *entry;
1992    
1993          SET_FOREGROUND(bgcolour);          SET_FOREGROUND(bgcolour);
1994    
1995            /* Sometimes, the boxcx value is something really large, like
1996               32691. This makes XCopyArea fail with Xvnc. The code below
1997               is a quick fix. */
1998            if (boxx + boxcx > g_width)
1999                    boxcx = g_width - boxx;
2000    
2001          if (boxcx > 1)          if (boxcx > 1)
2002          {          {
2003                  FILL_RECTANGLE_BACKSTORE(boxx, boxy, boxcx, boxcy);                  FILL_RECTANGLE_BACKSTORE(boxx, boxy, boxcx, boxcy);
# Line 1790  ui_draw_text(uint8 font, uint8 flags, in Line 2007  ui_draw_text(uint8 font, uint8 flags, in
2007                  FILL_RECTANGLE_BACKSTORE(clipx, clipy, clipcx, clipcy);                  FILL_RECTANGLE_BACKSTORE(clipx, clipy, clipcx, clipcy);
2008          }          }
2009    
2010            SET_FOREGROUND(fgcolour);
2011            SET_BACKGROUND(bgcolour);
2012            XSetFillStyle(g_display, g_gc, FillStippled);
2013    
2014          /* Paint text, character by character */          /* Paint text, character by character */
2015          for (i = 0; i < length;)          for (i = 0; i < length;)
2016          {          {
# Line 1840  ui_draw_text(uint8 font, uint8 flags, in Line 2061  ui_draw_text(uint8 font, uint8 flags, in
2061                                  break;                                  break;
2062                  }                  }
2063          }          }
2064    
2065            XSetFillStyle(g_display, g_gc, FillSolid);
2066    
2067          if (g_ownbackstore)          if (g_ownbackstore)
2068          {          {
2069                  if (boxcx > 1)                  if (boxcx > 1)

Legend:
Removed from v.500  
changed lines
  Added in v.679

  ViewVC Help
Powered by ViewVC 1.1.26