/[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 517 by matthewc, Tue Oct 28 03:30:51 2003 UTC revision 566 by stargo, Mon Jan 19 23:45:26 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 <time.h>  #include <time.h>
25  #include <errno.h>  #include <errno.h>
26  #include "rdesktop.h"  #include "rdesktop.h"
# Line 42  static Screen *g_screen; Line 43  static Screen *g_screen;
43  Window g_wnd;  Window g_wnd;
44  BOOL g_enable_compose = False;  BOOL g_enable_compose = False;
45  static GC g_gc;  static GC g_gc;
46    static BOOL g_gc_initialized = False;
47  static Visual *g_visual;  static Visual *g_visual;
48  static int g_depth;  static int g_depth;
49  static int g_bpp;  static int g_bpp;
# Line 57  static BOOL g_mouse_in_wnd; Line 59  static BOOL g_mouse_in_wnd;
59  /* endianness */  /* endianness */
60  static BOOL g_host_be;  static BOOL g_host_be;
61  static BOOL g_xserver_be;  static BOOL g_xserver_be;
62    static int g_red_shift_r, g_blue_shift_r, g_green_shift_r;
63    static int g_red_shift_l, g_blue_shift_l, g_green_shift_l;
64    
65  /* software backing store */  /* software backing store */
66  static BOOL g_ownbackstore;  static BOOL g_ownbackstore;
67  static Pixmap g_backstore;  static Pixmap g_backstore;
68    static BOOL g_backstore_initialized = False;
69    
70  /* Moving in single app mode */  /* Moving in single app mode */
71  static BOOL g_moving_wnd;  static BOOL g_moving_wnd;
# Line 112  BOOL g_owncolmap = False; Line 117  BOOL g_owncolmap = False;
117  static Colormap g_xcolmap;  static Colormap g_xcolmap;
118  static uint32 *g_colmap = NULL;  static uint32 *g_colmap = NULL;
119    
120  #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] )
121  #define SET_FOREGROUND(col)     XSetForeground(g_display, g_gc, TRANSLATE(col));  #define SET_FOREGROUND(col)     XSetForeground(g_display, g_gc, TRANSLATE(col));
122  #define SET_BACKGROUND(col)     XSetBackground(g_display, g_gc, TRANSLATE(col));  #define SET_BACKGROUND(col)     XSetBackground(g_display, g_gc, TRANSLATE(col));
123    
# Line 197  split_colour24(uint32 colour) Line 202  split_colour24(uint32 colour)
202  }  }
203    
204  static uint32  static uint32
205  make_colour16(PixelColour pc)  make_colour(PixelColour pc)
206  {  {
207          pc.red = (pc.red * 0x1f) / 0xff;          return (((pc.red >> g_red_shift_r) << g_red_shift_l)
208          pc.green = (pc.green * 0x3f) / 0xff;                  | ((pc.green >> g_green_shift_r) << g_green_shift_l)
209          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;  
         }  
210  }  }
211    
212  #define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); }  #define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); }
213  #define BSWAP24(x) { x = (((x & 0xff) << 16) | (x >> 16) | ((x >> 8) & 0xff00)); }  #define BSWAP24(x) { x = (((x & 0xff) << 16) | (x >> 16) | (x & 0xff00)); }
214  #define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \  #define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \
215                          x = (x << 16) | (x >> 16); }                          x = (x << 16) | (x >> 16); }
216    
217  static uint32  static uint32
218  translate_colour(uint32 colour)  translate_colour(uint32 colour)
219  {  {
220            PixelColour pc;
221          switch (g_server_bpp)          switch (g_server_bpp)
222          {          {
223                  case 15:                  case 15:
224                          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;  
                         }  
225                          break;                          break;
226                  case 16:                  case 16:
227                          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;  
                         }  
228                          break;                          break;
229                  case 24:                  case 24:
230                          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;  
                         }  
231                          break;                          break;
232          }          }
233          return colour;          return make_colour(pc);
234  }  }
235    
236  static void  static void
# Line 293  translate8to8(uint8 * data, uint8 * out, Line 241  translate8to8(uint8 * data, uint8 * out,
241  }  }
242    
243  static void  static void
244  translate8to16(uint8 * data, uint16 * out, uint16 * end)  translate8to16(uint8 * data, uint8 * out, uint8 * end)
245  {  {
246            uint16 value;
247    
248          while (out < end)          while (out < end)
249                  *(out++) = (uint16) g_colmap[*(data++)];          {
250                    value = (uint16) g_colmap[*(data++)];
251    
252                    if (g_xserver_be)
253                    {
254                            *(out++) = value >> 8;
255                            *(out++) = value;
256                    }
257                    else
258                    {
259                            *(out++) = value;
260                            *(out++) = value >> 8;
261                    }
262            }
263  }  }
264    
265  /* little endian - conversion happens when colourmap is built */  /* little endian - conversion happens when colourmap is built */
# Line 308  translate8to24(uint8 * data, uint8 * out Line 271  translate8to24(uint8 * data, uint8 * out
271          while (out < end)          while (out < end)
272          {          {
273                  value = g_colmap[*(data++)];                  value = g_colmap[*(data++)];
274                  *(out++) = value;  
275                  *(out++) = value >> 8;                  if (g_xserver_be)
276                  *(out++) = value >> 16;                  {
277                            *(out++) = value >> 16;
278                            *(out++) = value >> 8;
279                            *(out++) = value;
280                    }
281                    else
282                    {
283                            *(out++) = value;
284                            *(out++) = value >> 8;
285                            *(out++) = value >> 16;
286                    }
287          }          }
288  }  }
289    
290  static void  static void
291  translate8to32(uint8 * data, uint32 * out, uint32 * end)  translate8to32(uint8 * data, uint8 * out, uint8 * end)
292  {  {
293            uint32 value;
294    
295          while (out < end)          while (out < end)
296                  *(out++) = g_colmap[*(data++)];          {
297  }                  value = g_colmap[*(data++)];
298    
299  /* todo the remaining translate function might need some big endian check ?? */                  if (g_xserver_be)
300                    {
301                            *(out++) = value >> 24;
302                            *(out++) = value >> 16;
303                            *(out++) = value >> 8;
304                            *(out++) = value;
305                    }
306                    else
307                    {
308                            *(out++) = value;
309                            *(out++) = value >> 8;
310                            *(out++) = value >> 16;
311                            *(out++) = value >> 24;
312                    }
313            }
314    }
315    
316  static void  static void
317  translate15to16(uint16 * data, uint8 * out, uint8 * end)  translate15to16(uint16 * data, uint8 * out, uint8 * end)
# Line 335  translate15to16(uint16 * data, uint8 * o Line 325  translate15to16(uint16 * data, uint8 * o
325    
326                  if (g_host_be)                  if (g_host_be)
327                  {                  {
328                  BSWAP16(pixel)}                          BSWAP16(pixel);
329                    }
330    
331                  value = make_colour16(split_colour15(pixel));                  value = make_colour(split_colour15(pixel));
332    
333                  if (g_xserver_be)                  if (g_xserver_be)
334                  {                  {
# Line 364  translate15to24(uint16 * data, uint8 * o Line 355  translate15to24(uint16 * data, uint8 * o
355    
356                  if (g_host_be)                  if (g_host_be)
357                  {                  {
358                  BSWAP16(pixel)}                          BSWAP16(pixel);
359                    }
360    
361                  value = make_colour24(split_colour15(pixel));                  value = make_colour(split_colour15(pixel));
362                  if (g_xserver_be)                  if (g_xserver_be)
363                  {                  {
364                          *(out++) = value >> 16;                          *(out++) = value >> 16;
# Line 397  translate15to32(uint16 * data, uint8 * o Line 389  translate15to32(uint16 * data, uint8 * o
389                          BSWAP16(pixel);                          BSWAP16(pixel);
390                  }                  }
391    
392                  value = make_colour32(split_colour15(pixel));                  value = make_colour(split_colour15(pixel));
393    
394                  if (g_xserver_be)                  if (g_xserver_be)
395                  {                  {
# Line 417  translate15to32(uint16 * data, uint8 * o Line 409  translate15to32(uint16 * data, uint8 * o
409  }  }
410    
411  static void  static void
412  translate16to16(uint16 * data, uint16 * out, uint16 * end)  translate16to16(uint16 * data, uint8 * out, uint8 * end)
413  {  {
414            uint16 pixel;
415          uint16 value;          uint16 value;
416    
417          if (g_xserver_be)          while (out < end)
418          {          {
419                  while (out < end)                  pixel = *(data++);
420    
421                    if (g_host_be)
422                  {                  {
423                          value = *data;                          BSWAP16(pixel);
                         BSWAP16(value);  
                         *out = value;  
                         data++;  
                         out++;  
424                  }                  }
425    
426          }                  value = make_colour(split_colour16(pixel));
427          else  
428          {                  if (g_xserver_be)
429                  while (out < end)                  {
430                            *(out++) = value >> 8;
431                            *(out++) = value;
432                    }
433                    else
434                  {                  {
435                          *out = *data;                          *(out++) = value;
436                          out++;                          *(out++) = value >> 8;
                         data++;  
437                  }                  }
438          }          }
439  }  }
440    
   
441  static void  static void
442  translate16to24(uint16 * data, uint8 * out, uint8 * end)  translate16to24(uint16 * data, uint8 * out, uint8 * end)
443  {  {
# Line 457  translate16to24(uint16 * data, uint8 * o Line 450  translate16to24(uint16 * data, uint8 * o
450    
451                  if (g_host_be)                  if (g_host_be)
452                  {                  {
453                  BSWAP16(pixel)}                          BSWAP16(pixel);
454                    }
455    
456                  value = make_colour24(split_colour16(pixel));                  value = make_colour(split_colour16(pixel));
457    
458                  if (g_xserver_be)                  if (g_xserver_be)
459                  {                  {
# Line 488  translate16to32(uint16 * data, uint8 * o Line 482  translate16to32(uint16 * data, uint8 * o
482    
483                  if (g_host_be)                  if (g_host_be)
484                  {                  {
485                  BSWAP16(pixel)}                          BSWAP16(pixel);
486                    }
487    
488                  value = make_colour32(split_colour16(pixel));                  value = make_colour(split_colour16(pixel));
489    
490                  if (g_xserver_be)                  if (g_xserver_be)
491                  {                  {
# Line 520  translate24to16(uint8 * data, uint8 * ou Line 515  translate24to16(uint8 * data, uint8 * ou
515                  pixel |= *(data++) << 8;                  pixel |= *(data++) << 8;
516                  pixel |= *(data++);                  pixel |= *(data++);
517    
518                  value = (uint16) make_colour16(split_colour24(pixel));                  value = (uint16) make_colour(split_colour24(pixel));
519    
520                  if (g_xserver_be)                  if (g_xserver_be)
521                  {                  {
# Line 538  translate24to16(uint8 * data, uint8 * ou Line 533  translate24to16(uint8 * data, uint8 * ou
533  static void  static void
534  translate24to24(uint8 * data, uint8 * out, uint8 * end)  translate24to24(uint8 * data, uint8 * out, uint8 * end)
535  {  {
536            uint32 pixel;
537            uint32 value;
538    
539          while (out < end)          while (out < end)
540          {          {
541                  *(out++) = (*(data++));                  pixel = *(data++) << 16;
542                    pixel |= *(data++) << 8;
543                    pixel |= *(data++);
544    
545                    value = make_colour(split_colour24(pixel));
546    
547                    if (g_xserver_be)
548                    {
549                            *(out++) = value >> 16;
550                            *(out++) = value >> 8;
551                            *(out++) = value;
552                    }
553                    else
554                    {
555                            *(out++) = value;
556                            *(out++) = value >> 8;
557                            *(out++) = value >> 16;
558                    }
559          }          }
560  }  }
561    
562  static void  static void
563  translate24to32(uint8 * data, uint8 * out, uint8 * end)  translate24to32(uint8 * data, uint8 * out, uint8 * end)
564  {  {
565            uint32 pixel;
566            uint32 value;
567    
568          while (out < end)          while (out < end)
569          {          {
570                    pixel = *(data++) << 16;
571                    pixel |= *(data++) << 8;
572                    pixel |= *(data++);
573    
574                    value = make_colour(split_colour24(pixel));
575    
576                  if (g_xserver_be)                  if (g_xserver_be)
577                  {                  {
578                          *(out++) = 0x00;                          *(out++) = value >> 24;
579                          *(out++) = *(data++);                          *(out++) = value >> 16;
580                          *(out++) = *(data++);                          *(out++) = value >> 8;
581                          *(out++) = *(data++);                          *(out++) = value;
582                  }                  }
583                  else                  else
584                  {                  {
585                          *(out++) = *(data++);                          *(out++) = value;
586                          *(out++) = *(data++);                          *(out++) = value >> 8;
587                          *(out++) = *(data++);                          *(out++) = value >> 16;
588                          *(out++) = 0x00;                          *(out++) = value >> 24;
589                  }                  }
590          }          }
591  }  }
# Line 599  translate_image(int width, int height, u Line 623  translate_image(int width, int height, u
623                                          translate16to24((uint16 *) data, out, end);                                          translate16to24((uint16 *) data, out, end);
624                                          break;                                          break;
625                                  case 16:                                  case 16:
626                                          translate16to16((uint16 *) data, (uint16 *) out,                                          translate16to16((uint16 *) data, out, end);
                                                         (uint16 *) end);  
627                                          break;                                          break;
628                          }                          }
629                          break;                          break;
# Line 625  translate_image(int width, int height, u Line 648  translate_image(int width, int height, u
648                                          translate8to8(data, out, end);                                          translate8to8(data, out, end);
649                                          break;                                          break;
650                                  case 16:                                  case 16:
651                                          translate8to16(data, (uint16 *) out, (uint16 *) end);                                          translate8to16(data, out, end);
652                                          break;                                          break;
653                                  case 24:                                  case 24:
654                                          translate8to24(data, out, end);                                          translate8to24(data, out, end);
655                                          break;                                          break;
656                                  case 32:                                  case 32:
657                                          translate8to32(data, (uint32 *) out, (uint32 *) end);                                          translate8to32(data, out, end);
658                                          break;                                          break;
659                          }                          }
660                          break;                          break;
# Line 664  get_key_state(unsigned int state, uint32 Line 687  get_key_state(unsigned int state, uint32
687          return (state & keysymMask) ? True : False;          return (state & keysymMask) ? True : False;
688  }  }
689    
690    static void
691    calculate_shifts(uint32 mask, int *shift_r, int *shift_l)
692    {
693            *shift_l = ffs(mask) - 1;
694            mask >>= *shift_l;
695            *shift_r = 8 - ffs(mask & ~(mask >> 1));
696    }
697    
698  BOOL  BOOL
699  ui_init(void)  ui_init(void)
700  {  {
701            XVisualInfo vi;
702          XPixmapFormatValues *pfm;          XPixmapFormatValues *pfm;
703          uint16 test;          uint16 test;
704          int i;          int i, screen_num, nvisuals;
705            XVisualInfo *vmatches = NULL;
706            XVisualInfo template;
707            Bool TrueColorVisual = False;
708    
709          g_display = XOpenDisplay(NULL);          g_display = XOpenDisplay(NULL);
710          if (g_display == NULL)          if (g_display == NULL)
# Line 678  ui_init(void) Line 713  ui_init(void)
713                  return False;                  return False;
714          }          }
715    
716            screen_num = DefaultScreen(g_display);
717          g_x_socket = ConnectionNumber(g_display);          g_x_socket = ConnectionNumber(g_display);
718          g_screen = DefaultScreenOfDisplay(g_display);          g_screen = ScreenOfDisplay(g_display, screen_num);
         g_visual = DefaultVisualOfScreen(g_screen);  
719          g_depth = DefaultDepthOfScreen(g_screen);          g_depth = DefaultDepthOfScreen(g_screen);
720    
721            /* Search for best TrueColor depth */
722            template.class = TrueColor;
723            vmatches = XGetVisualInfo(g_display, VisualClassMask, &template, &nvisuals);
724    
725            nvisuals--;
726            while (nvisuals >= 0)
727            {
728                    if ((vmatches + nvisuals)->depth > g_depth)
729                    {
730                            g_depth = (vmatches + nvisuals)->depth;
731                    }
732                    nvisuals--;
733                    TrueColorVisual = True;
734            }
735    
736            if ((g_server_bpp == 8) && ((! TrueColorVisual) || (g_depth <= 8)))
737            {
738                    /* we use a colourmap, so the default visual should do */
739                    g_visual = DefaultVisualOfScreen(g_screen);
740                    g_depth = DefaultDepthOfScreen(g_screen);
741    
742                    /* Do not allocate colours on a TrueColor visual */
743                    if (g_visual->class == TrueColor)
744                    {
745                            g_owncolmap = False;
746                    }
747            }
748            else
749            {
750                    /* need a truecolour visual */
751                    if (!XMatchVisualInfo(g_display, screen_num, g_depth, TrueColor, &vi))
752                    {
753                            error("The display does not support true colour - high colour support unavailable.\n");
754                            return False;
755                    }
756    
757                    g_visual = vi.visual;
758                    g_owncolmap = False;
759                    calculate_shifts(vi.red_mask, &g_red_shift_r, &g_red_shift_l);
760                    calculate_shifts(vi.blue_mask, &g_blue_shift_r, &g_blue_shift_l);
761                    calculate_shifts(vi.green_mask, &g_green_shift_r, &g_green_shift_l);
762            }
763    
764          pfm = XListPixmapFormats(g_display, &i);          pfm = XListPixmapFormats(g_display, &i);
765          if (pfm != NULL)          if (pfm != NULL)
766          {          {
# Line 705  ui_init(void) Line 783  ui_init(void)
783                  return False;                  return False;
784          }          }
785    
         /* private colour map code only works for 8 bpp */  
         if (g_owncolmap && (g_bpp > 8))  
                 g_owncolmap = False;  
   
786          if (!g_owncolmap)          if (!g_owncolmap)
787          {          {
788                  g_xcolmap = DefaultColormapOfScreen(g_screen);                  g_xcolmap = XCreateColormap(g_display,RootWindowOfScreen(g_screen),g_visual,AllocNone);
789                  if (g_depth <= 8)                  if (g_depth <= 8)
790                          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");
791          }          }
792    
         g_gc = XCreateGC(g_display, RootWindowOfScreen(g_screen), 0, NULL);  
   
793          if (DoesBackingStore(g_screen) != Always)          if (DoesBackingStore(g_screen) != Always)
794                  g_ownbackstore = True;                  g_ownbackstore = True;
795    
# 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 780  ui_init(void) Line 841  ui_init(void)
841    
842          xclip_init();          xclip_init();
843    
844          /* 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);  
845    
846          return True;          return True;
847  }  }
# Line 802  ui_deinit(void) Line 862  ui_deinit(void)
862          g_display = NULL;          g_display = NULL;
863  }  }
864    
 #define NULL_POINTER_MASK       "\x80"  
 #define NULL_POINTER_DATA       "\x0\x0\x0"  
           
865  BOOL  BOOL
866  ui_create_window(void)  ui_create_window(void)
867  {  {
868            uint8 null_pointer_mask[1] = { 0x80 };
869            uint8 null_pointer_data[4] = { 0x00, 0x00, 0x00, 0x00 };
870          XSetWindowAttributes attribs;          XSetWindowAttributes attribs;
871          XClassHint *classhints;          XClassHint *classhints;
872          XSizeHints *sizehints;          XSizeHints *sizehints;
# Line 819  ui_create_window(void) Line 878  ui_create_window(void)
878          wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height;          wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height;
879    
880          attribs.background_pixel = BlackPixelOfScreen(g_screen);          attribs.background_pixel = BlackPixelOfScreen(g_screen);
881            attribs.border_pixel = WhitePixelOfScreen(g_screen);
882          attribs.backing_store = g_ownbackstore ? NotUseful : Always;          attribs.backing_store = g_ownbackstore ? NotUseful : Always;
883          attribs.override_redirect = g_fullscreen;          attribs.override_redirect = g_fullscreen;
884            attribs.colormap = g_xcolmap;
885    
886          g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), 0, 0, wndwidth, wndheight,          g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), 0, 0, wndwidth, wndheight,
887                                0, CopyFromParent, InputOutput, CopyFromParent,                                0, g_depth, InputOutput, g_visual,
888                                CWBackPixel | CWBackingStore | CWOverrideRedirect, &attribs);                                CWBackPixel | CWBackingStore | CWOverrideRedirect |
889                                  CWColormap | CWBorderPixel, &attribs);
890    
891            if ( ! g_gc_initialized )
892            {
893                    g_gc = XCreateGC(g_display, g_wnd, 0, NULL);
894                    g_gc_initialized = True;
895            }
896    
897            if ((g_ownbackstore) && (! g_backstore_initialized))
898            {
899                    g_backstore =
900                            XCreatePixmap(g_display, g_wnd, g_width, g_height,
901                                          g_depth);
902    
903                    /* clear to prevent rubbish being exposed at startup */
904                    XSetForeground(g_display, g_gc, BlackPixelOfScreen(g_screen));
905                    XFillRectangle(g_display, g_backstore, g_gc, 0, 0, g_width, g_height);
906                    g_backstore_initialized = True;
907            }
908    
909          XStoreName(g_display, g_wnd, g_title);          XStoreName(g_display, g_wnd, g_title);
910    
# Line 890  ui_create_window(void) Line 970  ui_create_window(void)
970          XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1);          XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1);
971    
972          /* create invisible 1x1 cursor to be used as null cursor */          /* create invisible 1x1 cursor to be used as null cursor */
973          g_null_cursor = ui_create_cursor(0, 0, 1, 1, NULL_POINTER_MASK, NULL_POINTER_DATA);          g_null_cursor = ui_create_cursor(0, 0, 1, 1, null_pointer_mask, null_pointer_data);
974    
975          return True;          return True;
976  }  }
# Line 898  ui_create_window(void) Line 978  ui_create_window(void)
978  void  void
979  ui_destroy_window(void)  ui_destroy_window(void)
980  {  {
         ui_destroy_cursor(g_null_cursor);  
           
981          if (g_IC != NULL)          if (g_IC != NULL)
982                  XDestroyIC(g_IC);                  XDestroyIC(g_IC);
983    
# Line 943  xwin_process_events(void) Line 1021  xwin_process_events(void)
1021          key_translation tr;          key_translation tr;
1022          char str[256];          char str[256];
1023          Status status;          Status status;
         unsigned int state;  
         Window wdummy;  
         int dummy;  
1024    
1025          while (XPending(g_display) > 0)          while (XPending(g_display) > 0)
1026          {          {
# Line 1118  xwin_process_events(void) Line 1193  xwin_process_events(void)
1193                                  if (xevent.xfocus.mode == NotifyGrab)                                  if (xevent.xfocus.mode == NotifyGrab)
1194                                          break;                                          break;
1195                                  g_focused = True;                                  g_focused = True;
1196                                  XQueryPointer(g_display, g_wnd, &wdummy, &wdummy, &dummy, &dummy,                                  reset_modifier_keys();
                                               &dummy, &dummy, &state);  
                                 reset_modifier_keys(state);  
1197                                  if (g_grab_keyboard && g_mouse_in_wnd)                                  if (g_grab_keyboard && g_mouse_in_wnd)
1198                                          XGrabKeyboard(g_display, g_wnd, True,                                          XGrabKeyboard(g_display, g_wnd, True,
1199                                                        GrabModeAsync, GrabModeAsync, CurrentTime);                                                        GrabModeAsync, GrabModeAsync, CurrentTime);
# Line 1255  ui_create_bitmap(int width, int height, Line 1328  ui_create_bitmap(int width, int height,
1328          XImage *image;          XImage *image;
1329          Pixmap bitmap;          Pixmap bitmap;
1330          uint8 *tdata;          uint8 *tdata;
1331            int bitmap_pad;
1332    
1333            if (g_server_bpp == 8)
1334            {
1335                    bitmap_pad = 8;
1336            }
1337            else
1338            {
1339                    bitmap_pad = g_bpp;
1340    
1341                    if (g_bpp == 24)
1342                            bitmap_pad = 32;
1343            }
1344    
1345          tdata = (g_owncolmap ? data : translate_image(width, height, data));          tdata = (g_owncolmap ? data : translate_image(width, height, data));
1346          bitmap = XCreatePixmap(g_display, g_wnd, width, height, g_depth);          bitmap = XCreatePixmap(g_display, g_wnd, width, height, g_depth);
1347          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,
1348                               (char *) tdata, width, height, g_server_bpp == 8 ? 8 : g_bpp, 0);                               (char *) tdata, width, height, bitmap_pad, 0);
1349    
1350          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);
1351    
# Line 1274  ui_paint_bitmap(int x, int y, int cx, in Line 1360  ui_paint_bitmap(int x, int y, int cx, in
1360  {  {
1361          XImage *image;          XImage *image;
1362          uint8 *tdata;          uint8 *tdata;
1363            int bitmap_pad;
1364    
1365            if (g_server_bpp == 8)
1366            {
1367                    bitmap_pad = 8;
1368            }
1369            else
1370            {
1371                    bitmap_pad = g_bpp;
1372    
1373                    if (g_bpp == 24)
1374                            bitmap_pad = 32;
1375            }
1376    
1377          tdata = (g_owncolmap ? data : translate_image(width, height, data));          tdata = (g_owncolmap ? data : translate_image(width, height, data));
1378          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,
1379                               (char *) tdata, width, height, g_server_bpp == 8 ? 8 : g_bpp, 0);                               (char *) tdata, width, height, bitmap_pad, 0);
1380    
1381          if (g_ownbackstore)          if (g_ownbackstore)
1382          {          {
# Line 1502  ui_create_colourmap(COLOURMAP * colours) Line 1602  ui_create_colourmap(COLOURMAP * colours)
1602    
1603                          }                          }
1604    
1605                            map[i] = colour;
                         /* byte swap here to make translate_image faster */  
                         map[i] = translate_colour(colour);  
1606                  }                  }
1607                  return map;                  return map;
1608          }          }
# Line 1760  ui_draw_glyph(int mixmode, Line 1858  ui_draw_glyph(int mixmode,
1858  {\  {\
1859    glyph = cache_get_font (font, ttext[idx]);\    glyph = cache_get_font (font, ttext[idx]);\
1860    if (!(flags & TEXT2_IMPLICIT_X))\    if (!(flags & TEXT2_IMPLICIT_X))\
1861      {\
1862        xyoffset = ttext[++idx];\
1863        if ((xyoffset & 0x80))\
1864      {\      {\
1865        xyoffset = ttext[++idx];\        if (flags & TEXT2_VERTICAL)\
1866        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;\  
         }\  
1867        else\        else\
1868          {\          x += ttext[idx+1] | (ttext[idx+2] << 8);\
1869            if (flags & TEXT2_VERTICAL) \        idx += 2;\
             y += xyoffset;\  
           else\  
             x += xyoffset;\  
         }\  
1870      }\      }\
1871    if (glyph != NULL)\      else\
1872      {\      {\
1873        ui_draw_glyph (mixmode, x + glyph->offset,\        if (flags & TEXT2_VERTICAL)\
1874                       y + glyph->baseline,\          y += xyoffset;\
1875                       glyph->width, glyph->height,\        else\
1876                       glyph->pixmap, 0, 0, bgcolour, fgcolour);\          x += xyoffset;\
       if (flags & TEXT2_IMPLICIT_X)\  
         x += glyph->width;\  
1877      }\      }\
1878      }\
1879      if (glyph != NULL)\
1880      {\
1881        x1 = x + glyph->offset;\
1882        y1 = y + glyph->baseline;\
1883        XSetStipple(g_display, g_gc, (Pixmap) glyph->pixmap);\
1884        XSetTSOrigin(g_display, g_gc, x1, y1);\
1885        FILL_RECTANGLE_BACKSTORE(x1, y1, glyph->width, glyph->height);\
1886        if (flags & TEXT2_IMPLICIT_X)\
1887          x += glyph->width;\
1888      }\
1889  }  }
1890    
1891  void  void
# Line 1796  ui_draw_text(uint8 font, uint8 flags, in Line 1895  ui_draw_text(uint8 font, uint8 flags, in
1895               int fgcolour, uint8 * text, uint8 length)               int fgcolour, uint8 * text, uint8 length)
1896  {  {
1897          FONTGLYPH *glyph;          FONTGLYPH *glyph;
1898          int i, j, xyoffset;          int i, j, xyoffset, x1, y1;
1899          DATABLOB *entry;          DATABLOB *entry;
1900    
1901          SET_FOREGROUND(bgcolour);          SET_FOREGROUND(bgcolour);
# Line 1810  ui_draw_text(uint8 font, uint8 flags, in Line 1909  ui_draw_text(uint8 font, uint8 flags, in
1909                  FILL_RECTANGLE_BACKSTORE(clipx, clipy, clipcx, clipcy);                  FILL_RECTANGLE_BACKSTORE(clipx, clipy, clipcx, clipcy);
1910          }          }
1911    
1912            SET_FOREGROUND(fgcolour);
1913            SET_BACKGROUND(bgcolour);
1914            XSetFillStyle(g_display, g_gc, FillStippled);
1915    
1916          /* Paint text, character by character */          /* Paint text, character by character */
1917          for (i = 0; i < length;)          for (i = 0; i < length;)
1918          {          {
# Line 1860  ui_draw_text(uint8 font, uint8 flags, in Line 1963  ui_draw_text(uint8 font, uint8 flags, in
1963                                  break;                                  break;
1964                  }                  }
1965          }          }
1966    
1967            XSetFillStyle(g_display, g_gc, FillSolid);
1968    
1969          if (g_ownbackstore)          if (g_ownbackstore)
1970          {          {
1971                  if (boxcx > 1)                  if (boxcx > 1)

Legend:
Removed from v.517  
changed lines
  Added in v.566

  ViewVC Help
Powered by ViewVC 1.1.26