/[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 521 by stargo, Tue Oct 28 09:02:46 2003 UTC revision 592 by n-ki, Fri Jan 30 14:10:32 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 41  static int g_x_socket; Line 42  static int g_x_socket;
42  static Screen *g_screen;  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 = NULL;
46  static Visual *g_visual;  static Visual *g_visual;
47  static int g_depth;  static int g_depth;
48  static int g_bpp;  static int g_bpp;
# Line 49  static XIM g_IM; Line 50  static XIM g_IM;
50  static XIC g_IC;  static XIC g_IC;
51  static XModifierKeymap *g_mod_map;  static XModifierKeymap *g_mod_map;
52  static Cursor g_current_cursor;  static Cursor g_current_cursor;
53  static HCURSOR g_null_cursor;  static HCURSOR g_null_cursor = NULL;
54  static Atom g_protocol_atom, g_kill_atom;  static Atom g_protocol_atom, g_kill_atom;
55  static BOOL g_focused;  static BOOL g_focused;
56  static BOOL g_mouse_in_wnd;  static BOOL g_mouse_in_wnd;
# Line 57  static BOOL g_mouse_in_wnd; Line 58  static BOOL g_mouse_in_wnd;
58  /* endianness */  /* endianness */
59  static BOOL g_host_be;  static BOOL g_host_be;
60  static BOOL g_xserver_be;  static BOOL g_xserver_be;
61    static int g_red_shift_r, g_blue_shift_r, g_green_shift_r;
62    static int g_red_shift_l, g_blue_shift_l, g_green_shift_l;
63    
64  /* software backing store */  /* software backing store */
65  static BOOL g_ownbackstore;  static BOOL g_ownbackstore;
66  static Pixmap g_backstore;  static Pixmap g_backstore = NULL;
67    
68  /* Moving in single app mode */  /* Moving in single app mode */
69  static BOOL g_moving_wnd;  static BOOL g_moving_wnd;
# Line 112  BOOL g_owncolmap = False; Line 115  BOOL g_owncolmap = False;
115  static Colormap g_xcolmap;  static Colormap g_xcolmap;
116  static uint32 *g_colmap = NULL;  static uint32 *g_colmap = NULL;
117    
118  #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] )
119  #define SET_FOREGROUND(col)     XSetForeground(g_display, g_gc, TRANSLATE(col));  #define SET_FOREGROUND(col)     XSetForeground(g_display, g_gc, TRANSLATE(col));
120  #define SET_BACKGROUND(col)     XSetBackground(g_display, g_gc, TRANSLATE(col));  #define SET_BACKGROUND(col)     XSetBackground(g_display, g_gc, TRANSLATE(col));
121    
# Line 197  split_colour24(uint32 colour) Line 200  split_colour24(uint32 colour)
200  }  }
201    
202  static uint32  static uint32
203  make_colour16(PixelColour pc)  make_colour(PixelColour pc)
204  {  {
205          pc.red = (pc.red * 0x1f) / 0xff;          return (((pc.red >> g_red_shift_r) << g_red_shift_l)
206          pc.green = (pc.green * 0x3f) / 0xff;                  | ((pc.green >> g_green_shift_r) << g_green_shift_l)
207          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;  
         }  
208  }  }
209    
210  #define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); }  #define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); }
211  #define BSWAP24(x) { x = (((x & 0xff) << 16) | (x >> 16) | ((x >> 8) & 0xff00)); }  #define BSWAP24(x) { x = (((x & 0xff) << 16) | (x >> 16) | (x & 0xff00)); }
212  #define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \  #define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \
213                          x = (x << 16) | (x >> 16); }                          x = (x << 16) | (x >> 16); }
214    
215  static uint32  static uint32
216  translate_colour(uint32 colour)  translate_colour(uint32 colour)
217  {  {
218            PixelColour pc;
219          switch (g_server_bpp)          switch (g_server_bpp)
220          {          {
221                  case 15:                  case 15:
222                          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;  
                         }  
223                          break;                          break;
224                  case 16:                  case 16:
225                          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;  
                         }  
226                          break;                          break;
227                  case 24:                  case 24:
228                          switch (g_bpp)                          pc = split_colour24(colour);
                         {  
                                 case 16:  
                                         colour = make_colour16(split_colour24(colour));  
                                         break;  
                                 case 24:  
                                         colour = make_colour24(split_colour24(colour));  
                                         break;  
                                 case 32:  
                                         colour = make_colour32(split_colour24(colour));  
                                         break;  
                         }  
229                          break;                          break;
230          }          }
231          return colour;          return make_colour(pc);
232  }  }
233    
234  static void  static void
# Line 301  translate8to16(uint8 * data, uint8 * out Line 246  translate8to16(uint8 * data, uint8 * out
246          while (out < end)          while (out < end)
247          {          {
248                  value = (uint16) g_colmap[*(data++)];                  value = (uint16) g_colmap[*(data++)];
249                    
250                  if (g_xserver_be)                  if (g_xserver_be)
251                  {                  {
252                          *(out++) = value >> 8;                          *(out++) = value >> 8;
# Line 324  translate8to24(uint8 * data, uint8 * out Line 269  translate8to24(uint8 * data, uint8 * out
269          while (out < end)          while (out < end)
270          {          {
271                  value = g_colmap[*(data++)];                  value = g_colmap[*(data++)];
272                    
273                  if (g_xserver_be)                  if (g_xserver_be)
274                  {                  {
275                          *(out++) = value >> 16;                          *(out++) = value >> 16;
# Line 366  translate8to32(uint8 * data, uint8 * out Line 311  translate8to32(uint8 * data, uint8 * out
311          }          }
312  }  }
313    
 /* todo the remaining translate function might need some big endian check ?? */  
   
314  static void  static void
315  translate15to16(uint16 * data, uint8 * out, uint8 * end)  translate15to16(uint16 * data, uint8 * out, uint8 * end)
316  {  {
# Line 383  translate15to16(uint16 * data, uint8 * o Line 326  translate15to16(uint16 * data, uint8 * o
326                          BSWAP16(pixel);                          BSWAP16(pixel);
327                  }                  }
328    
329                  value = make_colour16(split_colour15(pixel));                  value = make_colour(split_colour15(pixel));
330    
331                  if (g_xserver_be)                  if (g_xserver_be)
332                  {                  {
# Line 413  translate15to24(uint16 * data, uint8 * o Line 356  translate15to24(uint16 * data, uint8 * o
356                          BSWAP16(pixel);                          BSWAP16(pixel);
357                  }                  }
358    
359                  value = make_colour24(split_colour15(pixel));                  value = make_colour(split_colour15(pixel));
360                  if (g_xserver_be)                  if (g_xserver_be)
361                  {                  {
362                          *(out++) = value >> 16;                          *(out++) = value >> 16;
# Line 444  translate15to32(uint16 * data, uint8 * o Line 387  translate15to32(uint16 * data, uint8 * o
387                          BSWAP16(pixel);                          BSWAP16(pixel);
388                  }                  }
389    
390                  value = make_colour32(split_colour15(pixel));                  value = make_colour(split_colour15(pixel));
391    
392                  if (g_xserver_be)                  if (g_xserver_be)
393                  {                  {
# Line 464  translate15to32(uint16 * data, uint8 * o Line 407  translate15to32(uint16 * data, uint8 * o
407  }  }
408    
409  static void  static void
410  translate16to16(uint16 * data, uint16 * out, uint16 * end)  translate16to16(uint16 * data, uint8 * out, uint8 * end)
411  {  {
412            uint16 pixel;
413          uint16 value;          uint16 value;
414    
415          if (g_xserver_be)          while (out < end)
416          {          {
417                  while (out < end)                  pixel = *(data++);
418    
419                    if (g_host_be)
420                  {                  {
421                          value = *data;                          BSWAP16(pixel);
                         BSWAP16(value);  
                         *out = value;  
                         data++;  
                         out++;  
422                  }                  }
423    
424          }                  value = make_colour(split_colour16(pixel));
425          else  
426          {                  if (g_xserver_be)
427                  while (out < end)                  {
428                            *(out++) = value >> 8;
429                            *(out++) = value;
430                    }
431                    else
432                  {                  {
433                          *out = *data;                          *(out++) = value;
434                          out++;                          *(out++) = value >> 8;
                         data++;  
435                  }                  }
436          }          }
437  }  }
438    
   
439  static void  static void
440  translate16to24(uint16 * data, uint8 * out, uint8 * end)  translate16to24(uint16 * data, uint8 * out, uint8 * end)
441  {  {
# Line 507  translate16to24(uint16 * data, uint8 * o Line 451  translate16to24(uint16 * data, uint8 * o
451                          BSWAP16(pixel);                          BSWAP16(pixel);
452                  }                  }
453    
454                  value = make_colour24(split_colour16(pixel));                  value = make_colour(split_colour16(pixel));
455    
456                  if (g_xserver_be)                  if (g_xserver_be)
457                  {                  {
# Line 536  translate16to32(uint16 * data, uint8 * o Line 480  translate16to32(uint16 * data, uint8 * o
480    
481                  if (g_host_be)                  if (g_host_be)
482                  {                  {
483                  BSWAP16(pixel)}                          BSWAP16(pixel);
484                    }
485    
486                  value = make_colour32(split_colour16(pixel));                  value = make_colour(split_colour16(pixel));
487    
488                  if (g_xserver_be)                  if (g_xserver_be)
489                  {                  {
# Line 568  translate24to16(uint8 * data, uint8 * ou Line 513  translate24to16(uint8 * data, uint8 * ou
513                  pixel |= *(data++) << 8;                  pixel |= *(data++) << 8;
514                  pixel |= *(data++);                  pixel |= *(data++);
515    
516                  value = (uint16) make_colour16(split_colour24(pixel));                  value = (uint16) make_colour(split_colour24(pixel));
517    
518                  if (g_xserver_be)                  if (g_xserver_be)
519                  {                  {
# Line 586  translate24to16(uint8 * data, uint8 * ou Line 531  translate24to16(uint8 * data, uint8 * ou
531  static void  static void
532  translate24to24(uint8 * data, uint8 * out, uint8 * end)  translate24to24(uint8 * data, uint8 * out, uint8 * end)
533  {  {
534            uint32 pixel;
535            uint32 value;
536    
537          while (out < end)          while (out < end)
538          {          {
539                  *(out++) = (*(data++));                  pixel = *(data++) << 16;
540                    pixel |= *(data++) << 8;
541                    pixel |= *(data++);
542    
543                    value = make_colour(split_colour24(pixel));
544    
545                    if (g_xserver_be)
546                    {
547                            *(out++) = value >> 16;
548                            *(out++) = value >> 8;
549                            *(out++) = value;
550                    }
551                    else
552                    {
553                            *(out++) = value;
554                            *(out++) = value >> 8;
555                            *(out++) = value >> 16;
556                    }
557          }          }
558  }  }
559    
560  static void  static void
561  translate24to32(uint8 * data, uint8 * out, uint8 * end)  translate24to32(uint8 * data, uint8 * out, uint8 * end)
562  {  {
563            uint32 pixel;
564            uint32 value;
565    
566          while (out < end)          while (out < end)
567          {          {
568                    pixel = *(data++) << 16;
569                    pixel |= *(data++) << 8;
570                    pixel |= *(data++);
571    
572                    value = make_colour(split_colour24(pixel));
573    
574                  if (g_xserver_be)                  if (g_xserver_be)
575                  {                  {
576                          *(out++) = 0x00;                          *(out++) = value >> 24;
577                          *(out++) = *(data++);                          *(out++) = value >> 16;
578                          *(out++) = *(data++);                          *(out++) = value >> 8;
579                          *(out++) = *(data++);                          *(out++) = value;
580                  }                  }
581                  else                  else
582                  {                  {
583                          *(out++) = *(data++);                          *(out++) = value;
584                          *(out++) = *(data++);                          *(out++) = value >> 8;
585                          *(out++) = *(data++);                          *(out++) = value >> 16;
586                          *(out++) = 0x00;                          *(out++) = value >> 24;
587                  }                  }
588          }          }
589  }  }
# Line 647  translate_image(int width, int height, u Line 621  translate_image(int width, int height, u
621                                          translate16to24((uint16 *) data, out, end);                                          translate16to24((uint16 *) data, out, end);
622                                          break;                                          break;
623                                  case 16:                                  case 16:
624                                          translate16to16((uint16 *) data, (uint16 *) out,                                          translate16to16((uint16 *) data, out, end);
                                                         (uint16 *) end);  
625                                          break;                                          break;
626                          }                          }
627                          break;                          break;
# Line 712  get_key_state(unsigned int state, uint32 Line 685  get_key_state(unsigned int state, uint32
685          return (state & keysymMask) ? True : False;          return (state & keysymMask) ? True : False;
686  }  }
687    
688    static void
689    calculate_shifts(uint32 mask, int *shift_r, int *shift_l)
690    {
691            *shift_l = ffs(mask) - 1;
692            mask >>= *shift_l;
693            *shift_r = 8 - ffs(mask & ~(mask >> 1));
694    }
695    
696  BOOL  BOOL
697  ui_init(void)  ui_init(void)
698  {  {
699            XVisualInfo vi;
700          XPixmapFormatValues *pfm;          XPixmapFormatValues *pfm;
701          uint16 test;          uint16 test;
702          int i;          int i, screen_num, nvisuals;
703            XVisualInfo *vmatches = NULL;
704            XVisualInfo template;
705            Bool TrueColorVisual = False;
706    
707          g_display = XOpenDisplay(NULL);          g_display = XOpenDisplay(NULL);
708          if (g_display == NULL)          if (g_display == NULL)
# Line 726  ui_init(void) Line 711  ui_init(void)
711                  return False;                  return False;
712          }          }
713    
714            screen_num = DefaultScreen(g_display);
715          g_x_socket = ConnectionNumber(g_display);          g_x_socket = ConnectionNumber(g_display);
716          g_screen = DefaultScreenOfDisplay(g_display);          g_screen = ScreenOfDisplay(g_display, screen_num);
         g_visual = DefaultVisualOfScreen(g_screen);  
717          g_depth = DefaultDepthOfScreen(g_screen);          g_depth = DefaultDepthOfScreen(g_screen);
718    
719            /* Search for best TrueColor depth */
720            template.class = TrueColor;
721            vmatches = XGetVisualInfo(g_display, VisualClassMask, &template, &nvisuals);
722    
723            nvisuals--;
724            while (nvisuals >= 0)
725            {
726                    if ((vmatches + nvisuals)->depth > g_depth)
727                    {
728                            g_depth = (vmatches + nvisuals)->depth;
729                    }
730                    nvisuals--;
731                    TrueColorVisual = True;
732            }
733    
734            if ((g_server_bpp == 8) && ((!TrueColorVisual) || (g_depth <= 8)))
735            {
736                    /* we use a colourmap, so the default visual should do */
737                    g_visual = DefaultVisualOfScreen(g_screen);
738                    g_depth = DefaultDepthOfScreen(g_screen);
739    
740                    /* Do not allocate colours on a TrueColor visual */
741                    if (g_visual->class == TrueColor)
742                    {
743                            g_owncolmap = False;
744                    }
745            }
746            else
747            {
748                    /* need a truecolour visual */
749                    if (!XMatchVisualInfo(g_display, screen_num, g_depth, TrueColor, &vi))
750                    {
751                            error("The display does not support true colour - high colour support unavailable.\n");
752                            return False;
753                    }
754    
755                    g_visual = vi.visual;
756                    g_owncolmap = False;
757                    calculate_shifts(vi.red_mask, &g_red_shift_r, &g_red_shift_l);
758                    calculate_shifts(vi.blue_mask, &g_blue_shift_r, &g_blue_shift_l);
759                    calculate_shifts(vi.green_mask, &g_green_shift_r, &g_green_shift_l);
760            }
761    
762          pfm = XListPixmapFormats(g_display, &i);          pfm = XListPixmapFormats(g_display, &i);
763          if (pfm != NULL)          if (pfm != NULL)
764          {          {
# Line 753  ui_init(void) Line 781  ui_init(void)
781                  return False;                  return False;
782          }          }
783    
         /* private colour map code only works for 8 bpp */  
         if (g_owncolmap && (g_bpp > 8))  
                 g_owncolmap = False;  
   
784          if (!g_owncolmap)          if (!g_owncolmap)
785          {          {
786                  g_xcolmap = DefaultColormapOfScreen(g_screen);                  g_xcolmap =
787                            XCreateColormap(g_display, RootWindowOfScreen(g_screen), g_visual,
788                                            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 776  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 799  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 839  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 849  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 866  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 == NULL))
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 937  ui_create_window(void) Line 967  ui_create_window(void)
967          XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1);          XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1);
968    
969          /* create invisible 1x1 cursor to be used as null cursor */          /* create invisible 1x1 cursor to be used as null cursor */
970          g_null_cursor = ui_create_cursor(0, 0, 1, 1, NULL_POINTER_MASK, NULL_POINTER_DATA);          if (g_null_cursor == NULL)
971                    g_null_cursor = ui_create_cursor(0, 0, 1, 1, null_pointer_mask, null_pointer_data);
972    
973          return True;          return True;
974  }  }
# Line 945  ui_create_window(void) Line 976  ui_create_window(void)
976  void  void
977  ui_destroy_window(void)  ui_destroy_window(void)
978  {  {
         ui_destroy_cursor(g_null_cursor);  
           
979          if (g_IC != NULL)          if (g_IC != NULL)
980                  XDestroyIC(g_IC);                  XDestroyIC(g_IC);
981    
# Line 990  xwin_process_events(void) Line 1019  xwin_process_events(void)
1019          key_translation tr;          key_translation tr;
1020          char str[256];          char str[256];
1021          Status status;          Status status;
         unsigned int state;  
         Window wdummy;  
         int dummy;  
1022    
1023          while (XPending(g_display) > 0)          while (XPending(g_display) > 0)
1024          {          {
# Line 1165  xwin_process_events(void) Line 1191  xwin_process_events(void)
1191                                  if (xevent.xfocus.mode == NotifyGrab)                                  if (xevent.xfocus.mode == NotifyGrab)
1192                                          break;                                          break;
1193                                  g_focused = True;                                  g_focused = True;
1194                                  XQueryPointer(g_display, g_wnd, &wdummy, &wdummy, &dummy, &dummy,                                  reset_modifier_keys();
                                               &dummy, &dummy, &state);  
                                 reset_modifier_keys(state);  
1195                                  if (g_grab_keyboard && g_mouse_in_wnd)                                  if (g_grab_keyboard && g_mouse_in_wnd)
1196                                          XGrabKeyboard(g_display, g_wnd, True,                                          XGrabKeyboard(g_display, g_wnd, True,
1197                                                        GrabModeAsync, GrabModeAsync, CurrentTime);                                                        GrabModeAsync, GrabModeAsync, CurrentTime);
# Line 1247  xwin_process_events(void) Line 1271  xwin_process_events(void)
1271  int  int
1272  ui_select(int rdp_socket)  ui_select(int rdp_socket)
1273  {  {
1274          int n = (rdp_socket > g_x_socket) ? rdp_socket + 1 : g_x_socket + 1;          int n = (rdp_socket > g_x_socket) ? rdp_socket : g_x_socket;
1275          fd_set rfds, wfds;          fd_set rfds, wfds;
1276            struct timeval tv;
1277            BOOL s_timeout = False;
1278    
1279          while (True)          while (True)
1280          {          {
# Line 1267  ui_select(int rdp_socket) Line 1293  ui_select(int rdp_socket)
1293                  if (g_dsp_busy)                  if (g_dsp_busy)
1294                  {                  {
1295                          FD_SET(g_dsp_fd, &wfds);                          FD_SET(g_dsp_fd, &wfds);
1296                          n = (g_dsp_fd + 1 > n) ? g_dsp_fd + 1 : n;                          n = (g_dsp_fd > n) ? g_dsp_fd : n;
1297                  }                  }
1298  #endif  #endif
1299                    /* default timeout */
1300                    tv.tv_sec = 60;
1301                    tv.tv_usec = 0;
1302    
1303                    /* add redirection handles */
1304                    rdpdr_add_fds(&n, &rfds, &wfds, &tv, &s_timeout);
1305    
1306                  switch (select(n, &rfds, &wfds, NULL, NULL))                  n++;
1307    
1308                    switch (select(n, &rfds, &wfds, NULL, &tv))
1309                  {                  {
1310                          case -1:                          case -1:
1311                                  error("select: %s\n", strerror(errno));                                  error("select: %s\n", strerror(errno));
1312    
1313                          case 0:                          case 0:
1314                                    s_timeout = True;
1315                                    rdpdr_check_fds(&rfds, &wfds, (BOOL) True);
1316                                  continue;                                  continue;
1317                  }                  }
1318    
1319                    rdpdr_check_fds(&rfds, &wfds, (BOOL) False);
1320    
1321                  if (FD_ISSET(rdp_socket, &rfds))                  if (FD_ISSET(rdp_socket, &rfds))
1322                          return 1;                          return 1;
1323    
# Line 1576  ui_create_colourmap(COLOURMAP * colours) Line 1614  ui_create_colourmap(COLOURMAP * colours)
1614    
1615                          }                          }
1616    
1617                            map[i] = colour;
                         /* byte swap here to make translate_image faster */  
                         map[i] = translate_colour(colour);  
1618                  }                  }
1619                  return map;                  return map;
1620          }          }
# Line 1834  ui_draw_glyph(int mixmode, Line 1870  ui_draw_glyph(int mixmode,
1870  {\  {\
1871    glyph = cache_get_font (font, ttext[idx]);\    glyph = cache_get_font (font, ttext[idx]);\
1872    if (!(flags & TEXT2_IMPLICIT_X))\    if (!(flags & TEXT2_IMPLICIT_X))\
1873      {\
1874        xyoffset = ttext[++idx];\
1875        if ((xyoffset & 0x80))\
1876      {\      {\
1877        xyoffset = ttext[++idx];\        if (flags & TEXT2_VERTICAL)\
1878        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;\  
         }\  
1879        else\        else\
1880          {\          x += ttext[idx+1] | (ttext[idx+2] << 8);\
1881            if (flags & TEXT2_VERTICAL) \        idx += 2;\
             y += xyoffset;\  
           else\  
             x += xyoffset;\  
         }\  
1882      }\      }\
1883    if (glyph != NULL)\      else\
1884      {\      {\
1885        ui_draw_glyph (mixmode, x + glyph->offset,\        if (flags & TEXT2_VERTICAL)\
1886                       y + glyph->baseline,\          y += xyoffset;\
1887                       glyph->width, glyph->height,\        else\
1888                       glyph->pixmap, 0, 0, bgcolour, fgcolour);\          x += xyoffset;\
       if (flags & TEXT2_IMPLICIT_X)\  
         x += glyph->width;\  
1889      }\      }\
1890      }\
1891      if (glyph != NULL)\
1892      {\
1893        x1 = x + glyph->offset;\
1894        y1 = y + glyph->baseline;\
1895        XSetStipple(g_display, g_gc, (Pixmap) glyph->pixmap);\
1896        XSetTSOrigin(g_display, g_gc, x1, y1);\
1897        FILL_RECTANGLE_BACKSTORE(x1, y1, glyph->width, glyph->height);\
1898        if (flags & TEXT2_IMPLICIT_X)\
1899          x += glyph->width;\
1900      }\
1901  }  }
1902    
1903  void  void
# Line 1870  ui_draw_text(uint8 font, uint8 flags, in Line 1907  ui_draw_text(uint8 font, uint8 flags, in
1907               int fgcolour, uint8 * text, uint8 length)               int fgcolour, uint8 * text, uint8 length)
1908  {  {
1909          FONTGLYPH *glyph;          FONTGLYPH *glyph;
1910          int i, j, xyoffset;          int i, j, xyoffset, x1, y1;
1911          DATABLOB *entry;          DATABLOB *entry;
1912    
1913          SET_FOREGROUND(bgcolour);          SET_FOREGROUND(bgcolour);
# Line 1884  ui_draw_text(uint8 font, uint8 flags, in Line 1921  ui_draw_text(uint8 font, uint8 flags, in
1921                  FILL_RECTANGLE_BACKSTORE(clipx, clipy, clipcx, clipcy);                  FILL_RECTANGLE_BACKSTORE(clipx, clipy, clipcx, clipcy);
1922          }          }
1923    
1924            SET_FOREGROUND(fgcolour);
1925            SET_BACKGROUND(bgcolour);
1926            XSetFillStyle(g_display, g_gc, FillStippled);
1927    
1928          /* Paint text, character by character */          /* Paint text, character by character */
1929          for (i = 0; i < length;)          for (i = 0; i < length;)
1930          {          {
# Line 1934  ui_draw_text(uint8 font, uint8 flags, in Line 1975  ui_draw_text(uint8 font, uint8 flags, in
1975                                  break;                                  break;
1976                  }                  }
1977          }          }
1978    
1979            XSetFillStyle(g_display, g_gc, FillSolid);
1980    
1981          if (g_ownbackstore)          if (g_ownbackstore)
1982          {          {
1983                  if (boxcx > 1)                  if (boxcx > 1)

Legend:
Removed from v.521  
changed lines
  Added in v.592

  ViewVC Help
Powered by ViewVC 1.1.26