/[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 636 by stargo, Sat Mar 13 12:08:18 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;
# Line 57  static BOOL g_mouse_in_wnd; Line 61  static BOOL g_mouse_in_wnd;
61  /* endianness */  /* endianness */
62  static BOOL g_host_be;  static BOOL g_host_be;
63  static BOOL g_xserver_be;  static BOOL g_xserver_be;
64    static int g_red_shift_r, g_blue_shift_r, g_green_shift_r;
65    static int g_red_shift_l, g_blue_shift_l, g_green_shift_l;
66    
67  /* software backing store */  /* software backing store */
68  static BOOL g_ownbackstore;  BOOL g_ownbackstore = True;     /* We can't rely on external BackingStore */
69  static Pixmap g_backstore;  static Pixmap g_backstore = 0;
70    
71  /* Moving in single app mode */  /* Moving in single app mode */
72  static BOOL g_moving_wnd;  static BOOL g_moving_wnd;
# Line 112  BOOL g_owncolmap = False; Line 118  BOOL g_owncolmap = False;
118  static Colormap g_xcolmap;  static Colormap g_xcolmap;
119  static uint32 *g_colmap = NULL;  static uint32 *g_colmap = NULL;
120    
121  #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] )
122  #define SET_FOREGROUND(col)     XSetForeground(g_display, g_gc, TRANSLATE(col));  #define SET_FOREGROUND(col)     XSetForeground(g_display, g_gc, TRANSLATE(col));
123  #define SET_BACKGROUND(col)     XSetBackground(g_display, g_gc, TRANSLATE(col));  #define SET_BACKGROUND(col)     XSetBackground(g_display, g_gc, TRANSLATE(col));
124    
# Line 164  static PixelColour Line 170  static PixelColour
170  split_colour15(uint32 colour)  split_colour15(uint32 colour)
171  {  {
172          PixelColour rv;          PixelColour rv;
173          rv.red = (colour & 0x7c00) >> 10;          rv.red = (colour & 0x7c00) >> 7;
174          rv.red = (rv.red * 0xff) / 0x1f;          rv.green = (colour & 0x03e0) >> 2;
175          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;  
176          return rv;          return rv;
177  }  }
178    
# Line 177  static PixelColour Line 180  static PixelColour
180  split_colour16(uint32 colour)  split_colour16(uint32 colour)
181  {  {
182          PixelColour rv;          PixelColour rv;
183          rv.red = (colour & 0xf800) >> 11;          rv.red = (colour & 0xf800) >> 8;
184          rv.red = (rv.red * 0xff) / 0x1f;          rv.green = (colour & 0x07e0) >> 3;
185          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;  
186          return rv;          return rv;
187  }  }
188    
# Line 191  split_colour24(uint32 colour) Line 191  split_colour24(uint32 colour)
191  {  {
192          PixelColour rv;          PixelColour rv;
193          rv.blue = (colour & 0xff0000) >> 16;          rv.blue = (colour & 0xff0000) >> 16;
194          rv.green = (colour & 0xff00) >> 8;          rv.green = (colour & 0x00ff00) >> 8;
195          rv.red = (colour & 0xff);          rv.red = (colour & 0x0000ff);
196          return rv;          return rv;
197  }  }
198    
199  static uint32  static uint32
200  make_colour16(PixelColour pc)  make_colour(PixelColour pc)
201  {  {
202          pc.red = (pc.red * 0x1f) / 0xff;          return (((pc.red >> g_red_shift_r) << g_red_shift_l)
203          pc.green = (pc.green * 0x3f) / 0xff;                  | ((pc.green >> g_green_shift_r) << g_green_shift_l)
204          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;  
         }  
205  }  }
206    
207  #define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); }  #define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); }
208  #define BSWAP24(x) { x = (((x & 0xff) << 16) | (x >> 16) | ((x >> 8) & 0xff00)); }  #define BSWAP24(x) { x = (((x & 0xff) << 16) | (x >> 16) | (x & 0xff00)); }
209  #define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \  #define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \
210                          x = (x << 16) | (x >> 16); }                          x = (x << 16) | (x >> 16); }
211    
212  static uint32  static uint32
213  translate_colour(uint32 colour)  translate_colour(uint32 colour)
214  {  {
215            PixelColour pc;
216          switch (g_server_bpp)          switch (g_server_bpp)
217          {          {
218                  case 15:                  case 15:
219                          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;  
                         }  
220                          break;                          break;
221                  case 16:                  case 16:
222                          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;  
                         }  
223                          break;                          break;
224                  case 24:                  case 24:
225                          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;  
                         }  
226                          break;                          break;
227          }          }
228          return colour;          return make_colour(pc);
229  }  }
230    
231  static void  static void
# Line 293  translate8to8(uint8 * data, uint8 * out, Line 236  translate8to8(uint8 * data, uint8 * out,
236  }  }
237    
238  static void  static void
239  translate8to16(uint8 * data, uint16 * out, uint16 * end)  translate8to16(uint8 * data, uint8 * out, uint8 * end)
240  {  {
241            uint16 value;
242    
243          while (out < end)          while (out < end)
244                  *(out++) = (uint16) g_colmap[*(data++)];          {
245                    value = (uint16) g_colmap[*(data++)];
246    
247                    if (g_xserver_be)
248                    {
249                            *(out++) = value >> 8;
250                            *(out++) = value;
251                    }
252                    else
253                    {
254                            *(out++) = value;
255                            *(out++) = value >> 8;
256                    }
257            }
258  }  }
259    
260  /* little endian - conversion happens when colourmap is built */  /* little endian - conversion happens when colourmap is built */
# Line 308  translate8to24(uint8 * data, uint8 * out Line 266  translate8to24(uint8 * data, uint8 * out
266          while (out < end)          while (out < end)
267          {          {
268                  value = g_colmap[*(data++)];                  value = g_colmap[*(data++)];
269                  *(out++) = value;  
270                  *(out++) = value >> 8;                  if (g_xserver_be)
271                  *(out++) = value >> 16;                  {
272                            *(out++) = value >> 16;
273                            *(out++) = value >> 8;
274                            *(out++) = value;
275                    }
276                    else
277                    {
278                            *(out++) = value;
279                            *(out++) = value >> 8;
280                            *(out++) = value >> 16;
281                    }
282          }          }
283  }  }
284    
285  static void  static void
286  translate8to32(uint8 * data, uint32 * out, uint32 * end)  translate8to32(uint8 * data, uint8 * out, uint8 * end)
287  {  {
288            uint32 value;
289    
290          while (out < end)          while (out < end)
291                  *(out++) = g_colmap[*(data++)];          {
292  }                  value = g_colmap[*(data++)];
293    
294  /* todo the remaining translate function might need some big endian check ?? */                  if (g_xserver_be)
295                    {
296                            *(out++) = value >> 24;
297                            *(out++) = value >> 16;
298                            *(out++) = value >> 8;
299                            *(out++) = value;
300                    }
301                    else
302                    {
303                            *(out++) = value;
304                            *(out++) = value >> 8;
305                            *(out++) = value >> 16;
306                            *(out++) = value >> 24;
307                    }
308            }
309    }
310    
311  static void  static void
312  translate15to16(uint16 * data, uint8 * out, uint8 * end)  translate15to16(uint16 * data, uint8 * out, uint8 * end)
# Line 335  translate15to16(uint16 * data, uint8 * o Line 320  translate15to16(uint16 * data, uint8 * o
320    
321                  if (g_host_be)                  if (g_host_be)
322                  {                  {
323                  BSWAP16(pixel)}                          BSWAP16(pixel);
324                    }
325    
326                  value = make_colour16(split_colour15(pixel));                  value = make_colour(split_colour15(pixel));
327    
328                  if (g_xserver_be)                  if (g_xserver_be)
329                  {                  {
# Line 364  translate15to24(uint16 * data, uint8 * o Line 350  translate15to24(uint16 * data, uint8 * o
350    
351                  if (g_host_be)                  if (g_host_be)
352                  {                  {
353                  BSWAP16(pixel)}                          BSWAP16(pixel);
354                    }
355    
356                  value = make_colour24(split_colour15(pixel));                  value = make_colour(split_colour15(pixel));
357                  if (g_xserver_be)                  if (g_xserver_be)
358                  {                  {
359                          *(out++) = value >> 16;                          *(out++) = value >> 16;
# Line 397  translate15to32(uint16 * data, uint8 * o Line 384  translate15to32(uint16 * data, uint8 * o
384                          BSWAP16(pixel);                          BSWAP16(pixel);
385                  }                  }
386    
387                  value = make_colour32(split_colour15(pixel));                  value = make_colour(split_colour15(pixel));
388    
389                  if (g_xserver_be)                  if (g_xserver_be)
390                  {                  {
# Line 417  translate15to32(uint16 * data, uint8 * o Line 404  translate15to32(uint16 * data, uint8 * o
404  }  }
405    
406  static void  static void
407  translate16to16(uint16 * data, uint16 * out, uint16 * end)  translate16to16(uint16 * data, uint8 * out, uint8 * end)
408  {  {
409            uint16 pixel;
410          uint16 value;          uint16 value;
411    
412          if (g_xserver_be)          while (out < end)
413          {          {
414                  while (out < end)                  pixel = *(data++);
415    
416                    if (g_host_be)
417                  {                  {
418                          value = *data;                          BSWAP16(pixel);
                         BSWAP16(value);  
                         *out = value;  
                         data++;  
                         out++;  
419                  }                  }
420    
421          }                  value = make_colour(split_colour16(pixel));
422          else  
423          {                  if (g_xserver_be)
                 while (out < end)  
424                  {                  {
425                          *out = *data;                          *(out++) = value >> 8;
426                          out++;                          *(out++) = value;
427                          data++;                  }
428                    else
429                    {
430                            *(out++) = value;
431                            *(out++) = value >> 8;
432                  }                  }
433          }          }
434  }  }
435    
   
436  static void  static void
437  translate16to24(uint16 * data, uint8 * out, uint8 * end)  translate16to24(uint16 * data, uint8 * out, uint8 * end)
438  {  {
# Line 457  translate16to24(uint16 * data, uint8 * o Line 445  translate16to24(uint16 * data, uint8 * o
445    
446                  if (g_host_be)                  if (g_host_be)
447                  {                  {
448                  BSWAP16(pixel)}                          BSWAP16(pixel);
449                    }
450    
451                  value = make_colour24(split_colour16(pixel));                  value = make_colour(split_colour16(pixel));
452    
453                  if (g_xserver_be)                  if (g_xserver_be)
454                  {                  {
# Line 488  translate16to32(uint16 * data, uint8 * o Line 477  translate16to32(uint16 * data, uint8 * o
477    
478                  if (g_host_be)                  if (g_host_be)
479                  {                  {
480                  BSWAP16(pixel)}                          BSWAP16(pixel);
481                    }
482    
483                  value = make_colour32(split_colour16(pixel));                  value = make_colour(split_colour16(pixel));
484    
485                  if (g_xserver_be)                  if (g_xserver_be)
486                  {                  {
# Line 520  translate24to16(uint8 * data, uint8 * ou Line 510  translate24to16(uint8 * data, uint8 * ou
510                  pixel |= *(data++) << 8;                  pixel |= *(data++) << 8;
511                  pixel |= *(data++);                  pixel |= *(data++);
512    
513                  value = (uint16) make_colour16(split_colour24(pixel));                  value = (uint16) make_colour(split_colour24(pixel));
514    
515                  if (g_xserver_be)                  if (g_xserver_be)
516                  {                  {
# Line 538  translate24to16(uint8 * data, uint8 * ou Line 528  translate24to16(uint8 * data, uint8 * ou
528  static void  static void
529  translate24to24(uint8 * data, uint8 * out, uint8 * end)  translate24to24(uint8 * data, uint8 * out, uint8 * end)
530  {  {
531            uint32 pixel;
532            uint32 value;
533    
534          while (out < end)          while (out < end)
535          {          {
536                  *(out++) = (*(data++));                  pixel = *(data++) << 16;
537                    pixel |= *(data++) << 8;
538                    pixel |= *(data++);
539    
540                    value = make_colour(split_colour24(pixel));
541    
542                    if (g_xserver_be)
543                    {
544                            *(out++) = value >> 16;
545                            *(out++) = value >> 8;
546                            *(out++) = value;
547                    }
548                    else
549                    {
550                            *(out++) = value;
551                            *(out++) = value >> 8;
552                            *(out++) = value >> 16;
553                    }
554          }          }
555  }  }
556    
557  static void  static void
558  translate24to32(uint8 * data, uint8 * out, uint8 * end)  translate24to32(uint8 * data, uint8 * out, uint8 * end)
559  {  {
560            uint32 pixel;
561            uint32 value;
562    
563          while (out < end)          while (out < end)
564          {          {
565                    pixel = *(data++) << 16;
566                    pixel |= *(data++) << 8;
567                    pixel |= *(data++);
568    
569                    value = make_colour(split_colour24(pixel));
570    
571                  if (g_xserver_be)                  if (g_xserver_be)
572                  {                  {
573                          *(out++) = 0x00;                          *(out++) = value >> 24;
574                          *(out++) = *(data++);                          *(out++) = value >> 16;
575                          *(out++) = *(data++);                          *(out++) = value >> 8;
576                          *(out++) = *(data++);                          *(out++) = value;
577                  }                  }
578                  else                  else
579                  {                  {
580                          *(out++) = *(data++);                          *(out++) = value;
581                          *(out++) = *(data++);                          *(out++) = value >> 8;
582                          *(out++) = *(data++);                          *(out++) = value >> 16;
583                          *(out++) = 0x00;                          *(out++) = value >> 24;
584                  }                  }
585          }          }
586  }  }
# Line 599  translate_image(int width, int height, u Line 618  translate_image(int width, int height, u
618                                          translate16to24((uint16 *) data, out, end);                                          translate16to24((uint16 *) data, out, end);
619                                          break;                                          break;
620                                  case 16:                                  case 16:
621                                          translate16to16((uint16 *) data, (uint16 *) out,                                          translate16to16((uint16 *) data, out, end);
                                                         (uint16 *) end);  
622                                          break;                                          break;
623                          }                          }
624                          break;                          break;
# Line 625  translate_image(int width, int height, u Line 643  translate_image(int width, int height, u
643                                          translate8to8(data, out, end);                                          translate8to8(data, out, end);
644                                          break;                                          break;
645                                  case 16:                                  case 16:
646                                          translate8to16(data, (uint16 *) out, (uint16 *) end);                                          translate8to16(data, out, end);
647                                          break;                                          break;
648                                  case 24:                                  case 24:
649                                          translate8to24(data, out, end);                                          translate8to24(data, out, end);
650                                          break;                                          break;
651                                  case 32:                                  case 32:
652                                          translate8to32(data, (uint32 *) out, (uint32 *) end);                                          translate8to32(data, out, end);
653                                          break;                                          break;
654                          }                          }
655                          break;                          break;
# Line 664  get_key_state(unsigned int state, uint32 Line 682  get_key_state(unsigned int state, uint32
682          return (state & keysymMask) ? True : False;          return (state & keysymMask) ? True : False;
683  }  }
684    
685    static void
686    calculate_shifts(uint32 mask, int *shift_r, int *shift_l)
687    {
688            *shift_l = ffs(mask) - 1;
689            mask >>= *shift_l;
690            *shift_r = 8 - ffs(mask & ~(mask >> 1));
691    }
692    
693  BOOL  BOOL
694  ui_init(void)  ui_init(void)
695  {  {
696            XVisualInfo vi;
697          XPixmapFormatValues *pfm;          XPixmapFormatValues *pfm;
698          uint16 test;          uint16 test;
699          int i;          int i, screen_num, nvisuals;
700            XVisualInfo *vmatches = NULL;
701            XVisualInfo template;
702            Bool TrueColorVisual = False;
703    
704          g_display = XOpenDisplay(NULL);          g_display = XOpenDisplay(NULL);
705          if (g_display == NULL)          if (g_display == NULL)
# Line 678  ui_init(void) Line 708  ui_init(void)
708                  return False;                  return False;
709          }          }
710    
711            screen_num = DefaultScreen(g_display);
712          g_x_socket = ConnectionNumber(g_display);          g_x_socket = ConnectionNumber(g_display);
713          g_screen = DefaultScreenOfDisplay(g_display);          g_screen = ScreenOfDisplay(g_display, screen_num);
         g_visual = DefaultVisualOfScreen(g_screen);  
714          g_depth = DefaultDepthOfScreen(g_screen);          g_depth = DefaultDepthOfScreen(g_screen);
715    
716            /* Search for best TrueColor depth */
717            template.class = TrueColor;
718            vmatches = XGetVisualInfo(g_display, VisualClassMask, &template, &nvisuals);
719    
720            nvisuals--;
721            while (nvisuals >= 0)
722            {
723                    if ((vmatches + nvisuals)->depth > g_depth)
724                    {
725                            g_depth = (vmatches + nvisuals)->depth;
726                    }
727                    nvisuals--;
728                    TrueColorVisual = True;
729            }
730    
731            if ((g_server_bpp == 8) && ((!TrueColorVisual) || (g_depth <= 8)))
732            {
733                    /* we use a colourmap, so the default visual should do */
734                    g_visual = DefaultVisualOfScreen(g_screen);
735                    g_depth = DefaultDepthOfScreen(g_screen);
736    
737                    /* Do not allocate colours on a TrueColor visual */
738                    if (g_visual->class == TrueColor)
739                    {
740                            g_owncolmap = False;
741                    }
742            }
743            else
744            {
745                    /* need a truecolour visual */
746                    if (!XMatchVisualInfo(g_display, screen_num, g_depth, TrueColor, &vi))
747                    {
748                            error("The display does not support true colour - high colour support unavailable.\n");
749                            return False;
750                    }
751    
752                    g_visual = vi.visual;
753                    g_owncolmap = False;
754                    calculate_shifts(vi.red_mask, &g_red_shift_r, &g_red_shift_l);
755                    calculate_shifts(vi.blue_mask, &g_blue_shift_r, &g_blue_shift_l);
756                    calculate_shifts(vi.green_mask, &g_green_shift_r, &g_green_shift_l);
757            }
758    
759          pfm = XListPixmapFormats(g_display, &i);          pfm = XListPixmapFormats(g_display, &i);
760          if (pfm != NULL)          if (pfm != NULL)
761          {          {
# Line 705  ui_init(void) Line 778  ui_init(void)
778                  return False;                  return False;
779          }          }
780    
         /* private colour map code only works for 8 bpp */  
         if (g_owncolmap && (g_bpp > 8))  
                 g_owncolmap = False;  
   
781          if (!g_owncolmap)          if (!g_owncolmap)
782          {          {
783                  g_xcolmap = DefaultColormapOfScreen(g_screen);                  g_xcolmap =
784                            XCreateColormap(g_display, RootWindowOfScreen(g_screen), g_visual,
785                                            AllocNone);
786                  if (g_depth <= 8)                  if (g_depth <= 8)
787                          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");
788          }          }
789    
790          g_gc = XCreateGC(g_display, RootWindowOfScreen(g_screen), 0, NULL);          if ((!g_ownbackstore) && (DoesBackingStore(g_screen) != Always))
791            {
792          if (DoesBackingStore(g_screen) != Always)                  warning("External BackingStore not available, using internal\n");
793                  g_ownbackstore = True;                  g_ownbackstore = True;
794            }
795    
796          test = 1;          test = 1;
797          g_host_be = !(BOOL) (*(uint8 *) (&test));          g_host_be = !(BOOL) (*(uint8 *) (&test));
# Line 728  ui_init(void) Line 800  ui_init(void)
800          /*          /*
801           * Determine desktop size           * Determine desktop size
802           */           */
803          if (g_width < 0)          if (g_fullscreen)
804            {
805                    g_width = WidthOfScreen(g_screen);
806                    g_height = HeightOfScreen(g_screen);
807            }
808            else if (g_width < 0)
809          {          {
810                  /* Percent of screen */                  /* Percent of screen */
811                  g_height = HeightOfScreen(g_screen) * (-g_width) / 100;                  g_height = HeightOfScreen(g_screen) * (-g_width) / 100;
# Line 751  ui_init(void) Line 828  ui_init(void)
828                          g_height = 600;                          g_height = 600;
829                  }                  }
830          }          }
         else if (g_fullscreen)  
         {  
                 g_width = WidthOfScreen(g_screen);  
                 g_height = HeightOfScreen(g_screen);  
         }  
831    
832          /* make sure width is a multiple of 4 */          /* make sure width is a multiple of 4 */
833          g_width = (g_width + 3) & ~3;          g_width = (g_width + 3) & ~3;
834    
         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);  
         }  
   
835          g_mod_map = XGetModifierMapping(g_display);          g_mod_map = XGetModifierMapping(g_display);
836    
837          xkeymap_init();          xkeymap_init();
# Line 791  ui_deinit(void) Line 852  ui_deinit(void)
852          if (g_IM != NULL)          if (g_IM != NULL)
853                  XCloseIM(g_IM);                  XCloseIM(g_IM);
854    
855            if (g_null_cursor != NULL)
856                    ui_destroy_cursor(g_null_cursor);
857    
858          XFreeModifiermap(g_mod_map);          XFreeModifiermap(g_mod_map);
859    
860          if (g_ownbackstore)          if (g_ownbackstore)
# Line 801  ui_deinit(void) Line 865  ui_deinit(void)
865          g_display = NULL;          g_display = NULL;
866  }  }
867    
 #define NULL_POINTER_MASK       "\x80"  
 #define NULL_POINTER_DATA       "\x0\x0\x0"  
           
868  BOOL  BOOL
869  ui_create_window(void)  ui_create_window(void)
870  {  {
871            uint8 null_pointer_mask[1] = { 0x80 };
872            uint8 null_pointer_data[4] = { 0x00, 0x00, 0x00, 0x00 };
873          XSetWindowAttributes attribs;          XSetWindowAttributes attribs;
874          XClassHint *classhints;          XClassHint *classhints;
875          XSizeHints *sizehints;          XSizeHints *sizehints;
# Line 818  ui_create_window(void) Line 881  ui_create_window(void)
881          wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height;          wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height;
882    
883          attribs.background_pixel = BlackPixelOfScreen(g_screen);          attribs.background_pixel = BlackPixelOfScreen(g_screen);
884            attribs.border_pixel = WhitePixelOfScreen(g_screen);
885          attribs.backing_store = g_ownbackstore ? NotUseful : Always;          attribs.backing_store = g_ownbackstore ? NotUseful : Always;
886          attribs.override_redirect = g_fullscreen;          attribs.override_redirect = g_fullscreen;
887            attribs.colormap = g_xcolmap;
888    
889          g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), 0, 0, wndwidth, wndheight,          g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), 0, 0, wndwidth, wndheight,
890                                0, CopyFromParent, InputOutput, CopyFromParent,                                0, g_depth, InputOutput, g_visual,
891                                CWBackPixel | CWBackingStore | CWOverrideRedirect, &attribs);                                CWBackPixel | CWBackingStore | CWOverrideRedirect |
892                                  CWColormap | CWBorderPixel, &attribs);
893    
894            if (g_gc == NULL)
895                    g_gc = XCreateGC(g_display, g_wnd, 0, NULL);
896    
897            if ((g_ownbackstore) && (g_backstore == 0))
898            {
899                    g_backstore = XCreatePixmap(g_display, g_wnd, g_width, g_height, g_depth);
900    
901                    /* clear to prevent rubbish being exposed at startup */
902                    XSetForeground(g_display, g_gc, BlackPixelOfScreen(g_screen));
903                    XFillRectangle(g_display, g_backstore, g_gc, 0, 0, g_width, g_height);
904            }
905    
906          XStoreName(g_display, g_wnd, g_title);          XStoreName(g_display, g_wnd, g_title);
907    
# Line 848  ui_create_window(void) Line 926  ui_create_window(void)
926                  XFree(sizehints);                  XFree(sizehints);
927          }          }
928    
929            if ( g_embed_wnd )
930            {
931                    XReparentWindow(g_display, g_wnd, (Window)g_embed_wnd, 0, 0);
932            }
933    
934          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
935                  VisibilityChangeMask | FocusChangeMask;                  VisibilityChangeMask | FocusChangeMask;
936    
# Line 889  ui_create_window(void) Line 972  ui_create_window(void)
972          XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1);          XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1);
973    
974          /* create invisible 1x1 cursor to be used as null cursor */          /* create invisible 1x1 cursor to be used as null cursor */
975          g_null_cursor = ui_create_cursor(0, 0, 1, 1, NULL_POINTER_MASK, NULL_POINTER_DATA);          if (g_null_cursor == NULL)
976                    g_null_cursor = ui_create_cursor(0, 0, 1, 1, null_pointer_mask, null_pointer_data);
977    
978          return True;          return True;
979  }  }
# Line 897  ui_create_window(void) Line 981  ui_create_window(void)
981  void  void
982  ui_destroy_window(void)  ui_destroy_window(void)
983  {  {
         ui_destroy_cursor(g_null_cursor);  
           
984          if (g_IC != NULL)          if (g_IC != NULL)
985                  XDestroyIC(g_IC);                  XDestroyIC(g_IC);
986    
# Line 942  xwin_process_events(void) Line 1024  xwin_process_events(void)
1024          key_translation tr;          key_translation tr;
1025          char str[256];          char str[256];
1026          Status status;          Status status;
         unsigned int state;  
         Window wdummy;  
         int dummy;  
1027    
1028          while (XPending(g_display) > 0)          while (XPending(g_display) > 0)
1029          {          {
# Line 1117  xwin_process_events(void) Line 1196  xwin_process_events(void)
1196                                  if (xevent.xfocus.mode == NotifyGrab)                                  if (xevent.xfocus.mode == NotifyGrab)
1197                                          break;                                          break;
1198                                  g_focused = True;                                  g_focused = True;
1199                                  XQueryPointer(g_display, g_wnd, &wdummy, &wdummy, &dummy, &dummy,                                  reset_modifier_keys();
                                               &dummy, &dummy, &state);  
                                 reset_modifier_keys(state);  
1200                                  if (g_grab_keyboard && g_mouse_in_wnd)                                  if (g_grab_keyboard && g_mouse_in_wnd)
1201                                          XGrabKeyboard(g_display, g_wnd, True,                                          XGrabKeyboard(g_display, g_wnd, True,
1202                                                        GrabModeAsync, GrabModeAsync, CurrentTime);                                                        GrabModeAsync, GrabModeAsync, CurrentTime);
# Line 1199  xwin_process_events(void) Line 1276  xwin_process_events(void)
1276  int  int
1277  ui_select(int rdp_socket)  ui_select(int rdp_socket)
1278  {  {
1279          int n = (rdp_socket > g_x_socket) ? rdp_socket + 1 : g_x_socket + 1;          int n;
1280          fd_set rfds, wfds;          fd_set rfds, wfds;
1281            struct timeval tv;
1282            BOOL s_timeout = False;
1283    
1284          while (True)          while (True)
1285          {          {
1286                    n = (rdp_socket > g_x_socket) ? rdp_socket : g_x_socket;
1287                  /* Process any events already waiting */                  /* Process any events already waiting */
1288                  if (!xwin_process_events())                  if (!xwin_process_events())
1289                          /* User quit */                          /* User quit */
# Line 1219  ui_select(int rdp_socket) Line 1299  ui_select(int rdp_socket)
1299                  if (g_dsp_busy)                  if (g_dsp_busy)
1300                  {                  {
1301                          FD_SET(g_dsp_fd, &wfds);                          FD_SET(g_dsp_fd, &wfds);
1302                          n = (g_dsp_fd + 1 > n) ? g_dsp_fd + 1 : n;                          n = (g_dsp_fd > n) ? g_dsp_fd : n;
1303                  }                  }
1304  #endif  #endif
1305                    /* default timeout */
1306                    tv.tv_sec = 60;
1307                    tv.tv_usec = 0;
1308    
1309                    /* add redirection handles */
1310                    rdpdr_add_fds(&n, &rfds, &wfds, &tv, &s_timeout);
1311    
1312                  switch (select(n, &rfds, &wfds, NULL, NULL))                  n++;
1313    
1314                    switch (select(n, &rfds, &wfds, NULL, &tv))
1315                  {                  {
1316                          case -1:                          case -1:
1317                                  error("select: %s\n", strerror(errno));                                  error("select: %s\n", strerror(errno));
1318    
1319                          case 0:                          case 0:
1320                                    /* TODO: if tv.tv_sec just times out
1321                                     * we will segfault.
1322                                     * FIXME:
1323                                     */
1324                                    //s_timeout = True;
1325                                    //rdpdr_check_fds(&rfds, &wfds, (BOOL) True);
1326                                  continue;                                  continue;
1327                  }                  }
1328    
1329                    rdpdr_check_fds(&rfds, &wfds, (BOOL) False);
1330    
1331                  if (FD_ISSET(rdp_socket, &rfds))                  if (FD_ISSET(rdp_socket, &rfds))
1332                          return 1;                          return 1;
1333    
# Line 1254  ui_create_bitmap(int width, int height, Line 1350  ui_create_bitmap(int width, int height,
1350          XImage *image;          XImage *image;
1351          Pixmap bitmap;          Pixmap bitmap;
1352          uint8 *tdata;          uint8 *tdata;
1353            int bitmap_pad;
1354    
1355            if (g_server_bpp == 8)
1356            {
1357                    bitmap_pad = 8;
1358            }
1359            else
1360            {
1361                    bitmap_pad = g_bpp;
1362    
1363                    if (g_bpp == 24)
1364                            bitmap_pad = 32;
1365            }
1366    
1367          tdata = (g_owncolmap ? data : translate_image(width, height, data));          tdata = (g_owncolmap ? data : translate_image(width, height, data));
1368          bitmap = XCreatePixmap(g_display, g_wnd, width, height, g_depth);          bitmap = XCreatePixmap(g_display, g_wnd, width, height, g_depth);
1369          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,
1370                               (char *) tdata, width, height, g_server_bpp == 8 ? 8 : g_bpp, 0);                               (char *) tdata, width, height, bitmap_pad, 0);
1371    
1372          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);
1373    
# Line 1273  ui_paint_bitmap(int x, int y, int cx, in Line 1382  ui_paint_bitmap(int x, int y, int cx, in
1382  {  {
1383          XImage *image;          XImage *image;
1384          uint8 *tdata;          uint8 *tdata;
1385            int bitmap_pad;
1386    
1387            if (g_server_bpp == 8)
1388            {
1389                    bitmap_pad = 8;
1390            }
1391            else
1392            {
1393                    bitmap_pad = g_bpp;
1394    
1395                    if (g_bpp == 24)
1396                            bitmap_pad = 32;
1397            }
1398    
1399          tdata = (g_owncolmap ? data : translate_image(width, height, data));          tdata = (g_owncolmap ? data : translate_image(width, height, data));
1400          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,
1401                               (char *) tdata, width, height, g_server_bpp == 8 ? 8 : g_bpp, 0);                               (char *) tdata, width, height, bitmap_pad, 0);
1402    
1403          if (g_ownbackstore)          if (g_ownbackstore)
1404          {          {
# Line 1501  ui_create_colourmap(COLOURMAP * colours) Line 1624  ui_create_colourmap(COLOURMAP * colours)
1624    
1625                          }                          }
1626    
1627                            map[i] = colour;
                         /* byte swap here to make translate_image faster */  
                         map[i] = translate_colour(colour);  
1628                  }                  }
1629                  return map;                  return map;
1630          }          }
# Line 1662  ui_screenblt(uint8 opcode, Line 1783  ui_screenblt(uint8 opcode,
1783               /* src */ int srcx, int srcy)               /* src */ int srcx, int srcy)
1784  {  {
1785          SET_FUNCTION(opcode);          SET_FUNCTION(opcode);
         XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);  
1786          if (g_ownbackstore)          if (g_ownbackstore)
1787            {
1788                    XCopyArea(g_display, g_backstore, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);
1789                  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);
1790            }
1791            else
1792            {
1793                    XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);
1794            }
1795          RESET_FUNCTION(opcode);          RESET_FUNCTION(opcode);
1796  }  }
1797    
# Line 1759  ui_draw_glyph(int mixmode, Line 1886  ui_draw_glyph(int mixmode,
1886  {\  {\
1887    glyph = cache_get_font (font, ttext[idx]);\    glyph = cache_get_font (font, ttext[idx]);\
1888    if (!(flags & TEXT2_IMPLICIT_X))\    if (!(flags & TEXT2_IMPLICIT_X))\
1889      {\
1890        xyoffset = ttext[++idx];\
1891        if ((xyoffset & 0x80))\
1892      {\      {\
1893        xyoffset = ttext[++idx];\        if (flags & TEXT2_VERTICAL)\
1894        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;\  
         }\  
1895        else\        else\
1896          {\          x += ttext[idx+1] | (ttext[idx+2] << 8);\
1897            if (flags & TEXT2_VERTICAL) \        idx += 2;\
             y += xyoffset;\  
           else\  
             x += xyoffset;\  
         }\  
1898      }\      }\
1899    if (glyph != NULL)\      else\
1900      {\      {\
1901        ui_draw_glyph (mixmode, x + glyph->offset,\        if (flags & TEXT2_VERTICAL)\
1902                       y + glyph->baseline,\          y += xyoffset;\
1903                       glyph->width, glyph->height,\        else\
1904                       glyph->pixmap, 0, 0, bgcolour, fgcolour);\          x += xyoffset;\
       if (flags & TEXT2_IMPLICIT_X)\  
         x += glyph->width;\  
1905      }\      }\
1906      }\
1907      if (glyph != NULL)\
1908      {\
1909        x1 = x + glyph->offset;\
1910        y1 = y + glyph->baseline;\
1911        XSetStipple(g_display, g_gc, (Pixmap) glyph->pixmap);\
1912        XSetTSOrigin(g_display, g_gc, x1, y1);\
1913        FILL_RECTANGLE_BACKSTORE(x1, y1, glyph->width, glyph->height);\
1914        if (flags & TEXT2_IMPLICIT_X)\
1915          x += glyph->width;\
1916      }\
1917  }  }
1918    
1919  void  void
# Line 1795  ui_draw_text(uint8 font, uint8 flags, in Line 1923  ui_draw_text(uint8 font, uint8 flags, in
1923               int fgcolour, uint8 * text, uint8 length)               int fgcolour, uint8 * text, uint8 length)
1924  {  {
1925          FONTGLYPH *glyph;          FONTGLYPH *glyph;
1926          int i, j, xyoffset;          int i, j, xyoffset, x1, y1;
1927          DATABLOB *entry;          DATABLOB *entry;
1928    
1929          SET_FOREGROUND(bgcolour);          SET_FOREGROUND(bgcolour);
1930    
1931            /* Sometimes, the boxcx value is something really large, like
1932               32691. This makes XCopyArea fail with Xvnc. The code below
1933               is a quick fix. */
1934            if (boxx + boxcx > g_width)
1935                    boxcx = g_width - boxx;
1936    
1937          if (boxcx > 1)          if (boxcx > 1)
1938          {          {
1939                  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 1943  ui_draw_text(uint8 font, uint8 flags, in
1943                  FILL_RECTANGLE_BACKSTORE(clipx, clipy, clipcx, clipcy);                  FILL_RECTANGLE_BACKSTORE(clipx, clipy, clipcx, clipcy);
1944          }          }
1945    
1946            SET_FOREGROUND(fgcolour);
1947            SET_BACKGROUND(bgcolour);
1948            XSetFillStyle(g_display, g_gc, FillStippled);
1949    
1950          /* Paint text, character by character */          /* Paint text, character by character */
1951          for (i = 0; i < length;)          for (i = 0; i < length;)
1952          {          {
# Line 1859  ui_draw_text(uint8 font, uint8 flags, in Line 1997  ui_draw_text(uint8 font, uint8 flags, in
1997                                  break;                                  break;
1998                  }                  }
1999          }          }
2000    
2001            XSetFillStyle(g_display, g_gc, FillSolid);
2002    
2003          if (g_ownbackstore)          if (g_ownbackstore)
2004          {          {
2005                  if (boxcx > 1)                  if (boxcx > 1)

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

  ViewVC Help
Powered by ViewVC 1.1.26