/[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 543 by astrand, Mon Nov 3 13:33:35 2003 UTC revision 708 by jsorg71, Fri Jun 4 15:01:36 2004 UTC
# Line 21  Line 21 
21  #include <X11/Xlib.h>  #include <X11/Xlib.h>
22  #include <X11/Xutil.h>  #include <X11/Xutil.h>
23  #include <unistd.h>  #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 41  Time g_last_gesturetime; Line 43  Time g_last_gesturetime;
43  static int g_x_socket;  static int g_x_socket;
44  static Screen *g_screen;  static Screen *g_screen;
45  Window g_wnd;  Window g_wnd;
46    extern uint32 g_embed_wnd;
47  BOOL g_enable_compose = False;  BOOL g_enable_compose = False;
48  static GC g_gc;  BOOL g_Unobscured;              /* used for screenblt */
49    static GC g_gc = NULL;
50  static Visual *g_visual;  static Visual *g_visual;
51  static int g_depth;  static int g_depth;
52  static int g_bpp;  static int g_bpp;
# Line 50  static XIM g_IM; Line 54  static XIM g_IM;
54  static XIC g_IC;  static XIC g_IC;
55  static XModifierKeymap *g_mod_map;  static XModifierKeymap *g_mod_map;
56  static Cursor g_current_cursor;  static Cursor g_current_cursor;
57  static HCURSOR g_null_cursor;  static HCURSOR g_null_cursor = NULL;
58  static Atom g_protocol_atom, g_kill_atom;  static Atom g_protocol_atom, g_kill_atom;
59  static BOOL g_focused;  static BOOL g_focused;
60  static BOOL g_mouse_in_wnd;  static BOOL g_mouse_in_wnd;
61    static BOOL g_arch_match = False;       /* set to True if RGB XServer and little endian */
62    
63  /* endianness */  /* endianness */
64  static BOOL g_host_be;  static BOOL g_host_be;
# Line 62  static int g_red_shift_r, g_blue_shift_r Line 67  static int g_red_shift_r, g_blue_shift_r
67  static int g_red_shift_l, g_blue_shift_l, g_green_shift_l;  static int g_red_shift_l, g_blue_shift_l, g_green_shift_l;
68    
69  /* software backing store */  /* software backing store */
70  static BOOL g_ownbackstore;  extern BOOL g_ownbackstore;
71  static Pixmap g_backstore;  static Pixmap g_backstore = 0;
72    
73  /* Moving in single app mode */  /* Moving in single app mode */
74  static BOOL g_moving_wnd;  static BOOL g_moving_wnd;
# Line 111  PixelColour; Line 116  PixelColour;
116  }  }
117    
118  /* colour maps */  /* colour maps */
119  BOOL g_owncolmap = False;  extern BOOL g_owncolmap;
120  static Colormap g_xcolmap;  static Colormap g_xcolmap;
121  static uint32 *g_colmap = NULL;  static uint32 *g_colmap = NULL;
122    
# Line 167  static PixelColour Line 172  static PixelColour
172  split_colour15(uint32 colour)  split_colour15(uint32 colour)
173  {  {
174          PixelColour rv;          PixelColour rv;
175          rv.red = (colour & 0x7c00) >> 10;          rv.red = ((colour >> 7) & 0xf8) | ((colour >> 12) & 0x7);
176          rv.red = (rv.red * 0xff) / 0x1f;          rv.green = ((colour >> 2) & 0xf8) | ((colour >> 8) & 0x7);
177          rv.green = (colour & 0x03e0) >> 5;          rv.blue = ((colour << 3) & 0xf8) | ((colour >> 2) & 0x7);
         rv.green = (rv.green * 0xff) / 0x1f;  
         rv.blue = (colour & 0x1f);  
         rv.blue = (rv.blue * 0xff) / 0x1f;  
178          return rv;          return rv;
179  }  }
180    
# Line 180  static PixelColour Line 182  static PixelColour
182  split_colour16(uint32 colour)  split_colour16(uint32 colour)
183  {  {
184          PixelColour rv;          PixelColour rv;
185          rv.red = (colour & 0xf800) >> 11;          rv.red = ((colour >> 8) & 0xf8) | ((colour >> 13) & 0x7);
186          rv.red = (rv.red * 0xff) / 0x1f;          rv.green = ((colour >> 3) & 0xfc) | ((colour >> 9) & 0x3);
187          rv.green = (colour & 0x07e0) >> 5;          rv.blue = ((colour << 3) & 0xf8) | ((colour >> 2) & 0x7);
         rv.green = (rv.green * 0xff) / 0x3f;  
         rv.blue = (colour & 0x001f);  
         rv.blue = (rv.blue * 0xff) / 0x1f;  
188          return rv;          return rv;
189  }  }
190    
# Line 194  split_colour24(uint32 colour) Line 193  split_colour24(uint32 colour)
193  {  {
194          PixelColour rv;          PixelColour rv;
195          rv.blue = (colour & 0xff0000) >> 16;          rv.blue = (colour & 0xff0000) >> 16;
196          rv.green = (colour & 0xff00) >> 8;          rv.green = (colour & 0x00ff00) >> 8;
197          rv.red = (colour & 0xff);          rv.red = (colour & 0x0000ff);
198          return rv;          return rv;
199  }  }
200    
# Line 231  translate_colour(uint32 colour) Line 230  translate_colour(uint32 colour)
230          return make_colour(pc);          return make_colour(pc);
231  }  }
232    
233    #define UNROLL8(stm) { stm stm stm stm stm stm stm stm }
234    #define REPEAT(stm) \
235    { \
236            while (out <= end - 8 * 4) \
237                    UNROLL8(stm) \
238            while (out < end) \
239                    { stm } \
240    }
241    
242  static void  static void
243  translate8to8(uint8 * data, uint8 * out, uint8 * end)  translate8to8(uint8 * data, uint8 * out, uint8 * end)
244  {  {
# Line 243  translate8to16(uint8 * data, uint8 * out Line 251  translate8to16(uint8 * data, uint8 * out
251  {  {
252          uint16 value;          uint16 value;
253    
254            if (g_arch_match)
255                    REPEAT(*((uint16 *) out) = g_colmap[*(data++)];
256                           out += 2;)
257            else
258    if (g_xserver_be)
259    {
260          while (out < end)          while (out < end)
261          {          {
262                  value = (uint16) g_colmap[*(data++)];                  value = (uint16) g_colmap[*(data++)];
263                    *(out++) = value >> 8;
264                  if (g_xserver_be)                  *(out++) = value;
                 {  
                         *(out++) = value >> 8;  
                         *(out++) = value;  
                 }  
                 else  
                 {  
                         *(out++) = value;  
                         *(out++) = value >> 8;  
                 }  
265          }          }
266  }  }
267    else
268    {
269            while (out < end)
270            {
271                    value = (uint16) g_colmap[*(data++)];
272                    *(out++) = value;
273                    *(out++) = value >> 8;
274            }
275    }
276    }
277    
278  /* little endian - conversion happens when colourmap is built */  /* little endian - conversion happens when colourmap is built */
279  static void  static void
# Line 266  translate8to24(uint8 * data, uint8 * out Line 281  translate8to24(uint8 * data, uint8 * out
281  {  {
282          uint32 value;          uint32 value;
283    
284          while (out < end)          if (g_xserver_be)
285          {          {
286                  value = g_colmap[*(data++)];                  while (out < end)
   
                 if (g_xserver_be)  
287                  {                  {
288                            value = g_colmap[*(data++)];
289                          *(out++) = value >> 16;                          *(out++) = value >> 16;
290                          *(out++) = value >> 8;                          *(out++) = value >> 8;
291                          *(out++) = value;                          *(out++) = value;
292                  }                  }
293                  else          }
294            else
295            {
296                    while (out < end)
297                  {                  {
298                            value = g_colmap[*(data++)];
299                          *(out++) = value;                          *(out++) = value;
300                          *(out++) = value >> 8;                          *(out++) = value >> 8;
301                          *(out++) = value >> 16;                          *(out++) = value >> 16;
# Line 290  translate8to32(uint8 * data, uint8 * out Line 308  translate8to32(uint8 * data, uint8 * out
308  {  {
309          uint32 value;          uint32 value;
310    
311            if (g_arch_match)
312                    REPEAT(*((uint32 *) out) = g_colmap[*(data++)];
313                           out += 4;)
314            else
315    if (g_xserver_be)
316    {
317          while (out < end)          while (out < end)
318          {          {
319                  value = g_colmap[*(data++)];                  value = g_colmap[*(data++)];
320                    *(out++) = value >> 24;
321                  if (g_xserver_be)                  *(out++) = value >> 16;
322                  {                  *(out++) = value >> 8;
323                          *(out++) = value >> 24;                  *(out++) = value;
                         *(out++) = value >> 16;  
                         *(out++) = value >> 8;  
                         *(out++) = value;  
                 }  
                 else  
                 {  
                         *(out++) = value;  
                         *(out++) = value >> 8;  
                         *(out++) = value >> 16;  
                         *(out++) = value >> 24;  
                 }  
324          }          }
325  }  }
326    else
327  /* todo the remaining translate function might need some big endian check ?? */  {
328            while (out < end)
329            {
330                    value = g_colmap[*(data++)];
331                    *(out++) = value;
332                    *(out++) = value >> 8;
333                    *(out++) = value >> 16;
334                    *(out++) = value >> 24;
335            }
336    }
337    }
338    
339  static void  static void
340  translate15to16(uint16 * data, uint8 * out, uint8 * end)  translate15to16(uint16 * data, uint8 * out, uint8 * end)
# Line 593  translate24to32(uint8 * data, uint8 * ou Line 616  translate24to32(uint8 * data, uint8 * ou
616  static uint8 *  static uint8 *
617  translate_image(int width, int height, uint8 * data)  translate_image(int width, int height, uint8 * data)
618  {  {
619          int size = width * height * g_bpp / 8;          int size;
620          uint8 *out = (uint8 *) xmalloc(size);          uint8 *out;
621          uint8 *end = out + size;          uint8 *end;
622    
623            /* if server and xserver bpp match, */
624            /* and arch(endian) matches, no need to translate */
625            /* just return data */
626            if (g_arch_match)
627            {
628                    if (g_depth == 15 && g_server_bpp == 15)
629                            return data;
630                    if (g_depth == 16 && g_server_bpp == 16)
631                            return data;
632            }
633    
634            size = width * height * (g_bpp / 8);
635            out = (uint8 *) xmalloc(size);
636            end = out + size;
637    
638          switch (g_server_bpp)          switch (g_server_bpp)
639          {          {
# Line 701  ui_init(void) Line 739  ui_init(void)
739          XVisualInfo vi;          XVisualInfo vi;
740          XPixmapFormatValues *pfm;          XPixmapFormatValues *pfm;
741          uint16 test;          uint16 test;
742          int i, screen_num;          int i, screen_num, nvisuals;
743            XVisualInfo *vmatches = NULL;
744            XVisualInfo template;
745            Bool TrueColorVisual = False;
746    
747          g_display = XOpenDisplay(NULL);          g_display = XOpenDisplay(NULL);
748          if (g_display == NULL)          if (g_display == NULL)
# Line 715  ui_init(void) Line 756  ui_init(void)
756          g_screen = ScreenOfDisplay(g_display, screen_num);          g_screen = ScreenOfDisplay(g_display, screen_num);
757          g_depth = DefaultDepthOfScreen(g_screen);          g_depth = DefaultDepthOfScreen(g_screen);
758    
759          if (g_server_bpp == 8)          /* Search for best TrueColor depth */
760            template.class = TrueColor;
761            vmatches = XGetVisualInfo(g_display, VisualClassMask, &template, &nvisuals);
762    
763            nvisuals--;
764            while (nvisuals >= 0)
765            {
766                    if ((vmatches + nvisuals)->depth > g_depth)
767                    {
768                            g_depth = (vmatches + nvisuals)->depth;
769                    }
770                    nvisuals--;
771                    TrueColorVisual = True;
772            }
773    
774            test = 1;
775            g_host_be = !(BOOL) (*(uint8 *) (&test));
776            g_xserver_be = (ImageByteOrder(g_display) == MSBFirst);
777    
778            if ((g_server_bpp == 8) && ((!TrueColorVisual) || (g_depth <= 8)))
779          {          {
780                  /* we use a colourmap, so any visual should do */                  /* we use a colourmap, so the default visual should do */
781                  g_visual = DefaultVisualOfScreen(g_screen);                  g_visual = DefaultVisualOfScreen(g_screen);
782                    g_depth = DefaultDepthOfScreen(g_screen);
783    
784                    /* Do not allocate colours on a TrueColor visual */
785                    if (g_visual->class == TrueColor)
786                    {
787                            g_owncolmap = False;
788                    }
789          }          }
790          else          else
791          {          {
# Line 734  ui_init(void) Line 801  ui_init(void)
801                  calculate_shifts(vi.red_mask, &g_red_shift_r, &g_red_shift_l);                  calculate_shifts(vi.red_mask, &g_red_shift_r, &g_red_shift_l);
802                  calculate_shifts(vi.blue_mask, &g_blue_shift_r, &g_blue_shift_l);                  calculate_shifts(vi.blue_mask, &g_blue_shift_r, &g_blue_shift_l);
803                  calculate_shifts(vi.green_mask, &g_green_shift_r, &g_green_shift_l);                  calculate_shifts(vi.green_mask, &g_green_shift_r, &g_green_shift_l);
804    
805                    /* if RGB video and averything is little endian */
806                    if (vi.red_mask > vi.green_mask && vi.green_mask > vi.blue_mask)
807                            if (!g_xserver_be && !g_host_be)
808                                    g_arch_match = True;
809          }          }
810    
811          pfm = XListPixmapFormats(g_display, &i);          pfm = XListPixmapFormats(g_display, &i);
# Line 760  ui_init(void) Line 832  ui_init(void)
832    
833          if (!g_owncolmap)          if (!g_owncolmap)
834          {          {
835                  g_xcolmap = DefaultColormapOfScreen(g_screen);                  g_xcolmap =
836                            XCreateColormap(g_display, RootWindowOfScreen(g_screen), g_visual,
837                                            AllocNone);
838                  if (g_depth <= 8)                  if (g_depth <= 8)
839                          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");
840          }          }
841    
842          g_gc = XCreateGC(g_display, RootWindowOfScreen(g_screen), 0, NULL);          if ((!g_ownbackstore) && (DoesBackingStore(g_screen) != Always))
843            {
844          if (DoesBackingStore(g_screen) != Always)                  warning("External BackingStore not available, using internal\n");
845                  g_ownbackstore = True;                  g_ownbackstore = True;
846            }
         test = 1;  
         g_host_be = !(BOOL) (*(uint8 *) (&test));  
         g_xserver_be = (ImageByteOrder(g_display) == MSBFirst);  
847    
848          /*          /*
849           * Determine desktop size           * Determine desktop size
850           */           */
851          if (g_width < 0)          if (g_fullscreen)
852            {
853                    g_width = WidthOfScreen(g_screen);
854                    g_height = HeightOfScreen(g_screen);
855            }
856            else if (g_width < 0)
857          {          {
858                  /* Percent of screen */                  /* Percent of screen */
859                  g_height = HeightOfScreen(g_screen) * (-g_width) / 100;                  g_height = HeightOfScreen(g_screen) * (-g_width) / 100;
# Line 800  ui_init(void) Line 876  ui_init(void)
876                          g_height = 600;                          g_height = 600;
877                  }                  }
878          }          }
         else if (g_fullscreen)  
         {  
                 g_width = WidthOfScreen(g_screen);  
                 g_height = HeightOfScreen(g_screen);  
         }  
879    
880          /* make sure width is a multiple of 4 */          /* make sure width is a multiple of 4 */
881          g_width = (g_width + 3) & ~3;          g_width = (g_width + 3) & ~3;
882    
         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);  
         }  
   
883          g_mod_map = XGetModifierMapping(g_display);          g_mod_map = XGetModifierMapping(g_display);
884    
885          xkeymap_init();          xkeymap_init();
# Line 840  ui_deinit(void) Line 900  ui_deinit(void)
900          if (g_IM != NULL)          if (g_IM != NULL)
901                  XCloseIM(g_IM);                  XCloseIM(g_IM);
902    
903            if (g_null_cursor != NULL)
904                    ui_destroy_cursor(g_null_cursor);
905    
906          XFreeModifiermap(g_mod_map);          XFreeModifiermap(g_mod_map);
907    
908          if (g_ownbackstore)          if (g_ownbackstore)
# Line 866  ui_create_window(void) Line 929  ui_create_window(void)
929          wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height;          wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height;
930    
931          attribs.background_pixel = BlackPixelOfScreen(g_screen);          attribs.background_pixel = BlackPixelOfScreen(g_screen);
932            attribs.border_pixel = WhitePixelOfScreen(g_screen);
933          attribs.backing_store = g_ownbackstore ? NotUseful : Always;          attribs.backing_store = g_ownbackstore ? NotUseful : Always;
934          attribs.override_redirect = g_fullscreen;          attribs.override_redirect = g_fullscreen;
935            attribs.colormap = g_xcolmap;
936    
937          g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), 0, 0, wndwidth, wndheight,          g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), 0, 0, wndwidth, wndheight,
938                                0, CopyFromParent, InputOutput, CopyFromParent,                                0, g_depth, InputOutput, g_visual,
939                                CWBackPixel | CWBackingStore | CWOverrideRedirect, &attribs);                                CWBackPixel | CWBackingStore | CWOverrideRedirect |
940                                  CWColormap | CWBorderPixel, &attribs);
941    
942            if (g_gc == NULL)
943                    g_gc = XCreateGC(g_display, g_wnd, 0, NULL);
944    
945            if ((g_ownbackstore) && (g_backstore == 0))
946            {
947                    g_backstore = XCreatePixmap(g_display, g_wnd, g_width, g_height, g_depth);
948    
949                    /* clear to prevent rubbish being exposed at startup */
950                    XSetForeground(g_display, g_gc, BlackPixelOfScreen(g_screen));
951                    XFillRectangle(g_display, g_backstore, g_gc, 0, 0, g_width, g_height);
952            }
953    
954          XStoreName(g_display, g_wnd, g_title);          XStoreName(g_display, g_wnd, g_title);
955    
# Line 896  ui_create_window(void) Line 974  ui_create_window(void)
974                  XFree(sizehints);                  XFree(sizehints);
975          }          }
976    
977            if (g_embed_wnd)
978            {
979                    XReparentWindow(g_display, g_wnd, (Window) g_embed_wnd, 0, 0);
980            }
981    
982          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
983                  VisibilityChangeMask | FocusChangeMask;                  VisibilityChangeMask | FocusChangeMask;
984    
# Line 927  ui_create_window(void) Line 1010  ui_create_window(void)
1010                  XMaskEvent(g_display, VisibilityChangeMask, &xevent);                  XMaskEvent(g_display, VisibilityChangeMask, &xevent);
1011          }          }
1012          while (xevent.type != VisibilityNotify);          while (xevent.type != VisibilityNotify);
1013            g_Unobscured = xevent.xvisibility.state == VisibilityUnobscured;
1014    
1015          g_focused = False;          g_focused = False;
1016          g_mouse_in_wnd = False;          g_mouse_in_wnd = False;
# Line 937  ui_create_window(void) Line 1021  ui_create_window(void)
1021          XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1);          XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1);
1022    
1023          /* create invisible 1x1 cursor to be used as null cursor */          /* create invisible 1x1 cursor to be used as null cursor */
1024          g_null_cursor = ui_create_cursor(0, 0, 1, 1, null_pointer_mask, null_pointer_data);          if (g_null_cursor == NULL)
1025                    g_null_cursor = ui_create_cursor(0, 0, 1, 1, null_pointer_mask, null_pointer_data);
1026    
1027          return True;          return True;
1028  }  }
1029    
1030  void  void
1031    ui_resize_window()
1032    {
1033            XSizeHints *sizehints;
1034            Pixmap bs;
1035    
1036            sizehints = XAllocSizeHints();
1037            if (sizehints)
1038            {
1039                    sizehints->flags = PMinSize | PMaxSize;
1040                    sizehints->min_width = sizehints->max_width = g_width;
1041                    sizehints->min_height = sizehints->max_height = g_height;
1042                    XSetWMNormalHints(g_display, g_wnd, sizehints);
1043                    XFree(sizehints);
1044            }
1045    
1046            if (!(g_fullscreen || g_embed_wnd))
1047            {
1048                    XResizeWindow(g_display, g_wnd, g_width, g_height);
1049            }
1050    
1051            /* create new backstore pixmap */
1052            if (g_backstore != 0)
1053            {
1054                    bs = XCreatePixmap(g_display, g_wnd, g_width, g_height, g_depth);
1055                    XSetForeground(g_display, g_gc, BlackPixelOfScreen(g_screen));
1056                    XFillRectangle(g_display, bs, g_gc, 0, 0, g_width, g_height);
1057                    XCopyArea(g_display, g_backstore, bs, g_gc, 0, 0, g_width, g_height, 0, 0);
1058                    XFreePixmap(g_display, g_backstore);
1059                    g_backstore = bs;
1060            }
1061    }
1062    
1063    void
1064  ui_destroy_window(void)  ui_destroy_window(void)
1065  {  {
1066          if (g_IC != NULL)          if (g_IC != NULL)
# Line 1003  xwin_process_events(void) Line 1121  xwin_process_events(void)
1121    
1122                  switch (xevent.type)                  switch (xevent.type)
1123                  {                  {
1124                            case VisibilityNotify:
1125                                    g_Unobscured = xevent.xvisibility.state == VisibilityUnobscured;
1126                                    break;
1127                          case ClientMessage:                          case ClientMessage:
1128                                  /* the window manager told us to quit */                                  /* the window manager told us to quit */
1129                                  if ((xevent.xclient.message_type == g_protocol_atom)                                  if ((xevent.xclient.message_type == g_protocol_atom)
# Line 1240  xwin_process_events(void) Line 1361  xwin_process_events(void)
1361  int  int
1362  ui_select(int rdp_socket)  ui_select(int rdp_socket)
1363  {  {
1364          int n = (rdp_socket > g_x_socket) ? rdp_socket + 1 : g_x_socket + 1;          int n;
1365          fd_set rfds, wfds;          fd_set rfds, wfds;
1366            struct timeval tv;
1367            BOOL s_timeout = False;
1368    
1369          while (True)          while (True)
1370          {          {
1371                    n = (rdp_socket > g_x_socket) ? rdp_socket : g_x_socket;
1372                  /* Process any events already waiting */                  /* Process any events already waiting */
1373                  if (!xwin_process_events())                  if (!xwin_process_events())
1374                          /* User quit */                          /* User quit */
# Line 1260  ui_select(int rdp_socket) Line 1384  ui_select(int rdp_socket)
1384                  if (g_dsp_busy)                  if (g_dsp_busy)
1385                  {                  {
1386                          FD_SET(g_dsp_fd, &wfds);                          FD_SET(g_dsp_fd, &wfds);
1387                          n = (g_dsp_fd + 1 > n) ? g_dsp_fd + 1 : n;                          n = (g_dsp_fd > n) ? g_dsp_fd : n;
1388                  }                  }
1389  #endif  #endif
1390                    /* default timeout */
1391                    tv.tv_sec = 60;
1392                    tv.tv_usec = 0;
1393    
1394                    /* add redirection handles */
1395                    rdpdr_add_fds(&n, &rfds, &wfds, &tv, &s_timeout);
1396    
1397                  switch (select(n, &rfds, &wfds, NULL, NULL))                  n++;
1398    
1399                    switch (select(n, &rfds, &wfds, NULL, &tv))
1400                  {                  {
1401                          case -1:                          case -1:
1402                                  error("select: %s\n", strerror(errno));                                  error("select: %s\n", strerror(errno));
1403    
1404                          case 0:                          case 0:
1405                                    /* TODO: if tv.tv_sec just times out
1406                                     * we will segfault.
1407                                     * FIXME:
1408                                     */
1409                                    //s_timeout = True;
1410                                    //rdpdr_check_fds(&rfds, &wfds, (BOOL) True);
1411                                  continue;                                  continue;
1412                  }                  }
1413    
1414                    rdpdr_check_fds(&rfds, &wfds, (BOOL) False);
1415    
1416                  if (FD_ISSET(rdp_socket, &rfds))                  if (FD_ISSET(rdp_socket, &rfds))
1417                          return 1;                          return 1;
1418    
# Line 1317  ui_create_bitmap(int width, int height, Line 1457  ui_create_bitmap(int width, int height,
1457          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);
1458    
1459          XFree(image);          XFree(image);
1460          if (!g_owncolmap)          if (tdata != data)
1461                  xfree(tdata);                  xfree(tdata);
1462          return (HBITMAP) bitmap;          return (HBITMAP) bitmap;
1463  }  }
# Line 1356  ui_paint_bitmap(int x, int y, int cx, in Line 1496  ui_paint_bitmap(int x, int y, int cx, in
1496          }          }
1497    
1498          XFree(image);          XFree(image);
1499          if (!g_owncolmap)          if (tdata != data)
1500                  xfree(tdata);                  xfree(tdata);
1501  }  }
1502    
# Line 1680  ui_patblt(uint8 opcode, Line 1820  ui_patblt(uint8 opcode,
1820          {          {
1821                  case 0: /* Solid */                  case 0: /* Solid */
1822                          SET_FOREGROUND(fgcolour);                          SET_FOREGROUND(fgcolour);
1823                          FILL_RECTANGLE(x, y, cx, cy);                          FILL_RECTANGLE_BACKSTORE(x, y, cx, cy);
1824                          break;                          break;
1825    
1826                  case 2: /* Hatch */                  case 2: /* Hatch */
# Line 1691  ui_patblt(uint8 opcode, Line 1831  ui_patblt(uint8 opcode,
1831                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);
1832                          XSetStipple(g_display, g_gc, fill);                          XSetStipple(g_display, g_gc, fill);
1833                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);
1834                          FILL_RECTANGLE(x, y, cx, cy);                          FILL_RECTANGLE_BACKSTORE(x, y, cx, cy);
1835                          XSetFillStyle(g_display, g_gc, FillSolid);                          XSetFillStyle(g_display, g_gc, FillSolid);
1836                          XSetTSOrigin(g_display, g_gc, 0, 0);                          XSetTSOrigin(g_display, g_gc, 0, 0);
1837                          ui_destroy_glyph((HGLYPH) fill);                          ui_destroy_glyph((HGLYPH) fill);
# Line 1701  ui_patblt(uint8 opcode, Line 1841  ui_patblt(uint8 opcode,
1841                          for (i = 0; i != 8; i++)                          for (i = 0; i != 8; i++)
1842                                  ipattern[7 - i] = brush->pattern[i];                                  ipattern[7 - i] = brush->pattern[i];
1843                          fill = (Pixmap) ui_create_glyph(8, 8, ipattern);                          fill = (Pixmap) ui_create_glyph(8, 8, ipattern);
   
1844                          SET_FOREGROUND(bgcolour);                          SET_FOREGROUND(bgcolour);
1845                          SET_BACKGROUND(fgcolour);                          SET_BACKGROUND(fgcolour);
1846                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);
1847                          XSetStipple(g_display, g_gc, fill);                          XSetStipple(g_display, g_gc, fill);
1848                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);
1849                            FILL_RECTANGLE_BACKSTORE(x, y, cx, cy);
                         FILL_RECTANGLE(x, y, cx, cy);  
   
1850                          XSetFillStyle(g_display, g_gc, FillSolid);                          XSetFillStyle(g_display, g_gc, FillSolid);
1851                          XSetTSOrigin(g_display, g_gc, 0, 0);                          XSetTSOrigin(g_display, g_gc, 0, 0);
1852                          ui_destroy_glyph((HGLYPH) fill);                          ui_destroy_glyph((HGLYPH) fill);
# Line 1720  ui_patblt(uint8 opcode, Line 1857  ui_patblt(uint8 opcode,
1857          }          }
1858    
1859          RESET_FUNCTION(opcode);          RESET_FUNCTION(opcode);
1860    
1861            if (g_ownbackstore)
1862                    XCopyArea(g_display, g_backstore, g_wnd, g_gc, x, y, cx, cy, x, y);
1863  }  }
1864    
1865  void  void
# Line 1728  ui_screenblt(uint8 opcode, Line 1868  ui_screenblt(uint8 opcode,
1868               /* src */ int srcx, int srcy)               /* src */ int srcx, int srcy)
1869  {  {
1870          SET_FUNCTION(opcode);          SET_FUNCTION(opcode);
         XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);  
1871          if (g_ownbackstore)          if (g_ownbackstore)
1872                  XCopyArea(g_display, g_backstore, g_backstore, g_gc, srcx, srcy, cx, cy, x, y);          {
1873                    if (g_Unobscured)
1874                    {
1875                            XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);
1876                            XCopyArea(g_display, g_backstore, g_backstore, g_gc, srcx, srcy, cx, cy, x,
1877                                      y);
1878                    }
1879                    else
1880                    {
1881                            XCopyArea(g_display, g_backstore, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);
1882                            XCopyArea(g_display, g_backstore, g_backstore, g_gc, srcx, srcy, cx, cy, x,
1883                                      y);
1884                    }
1885            }
1886            else
1887            {
1888                    XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);
1889            }
1890          RESET_FUNCTION(opcode);          RESET_FUNCTION(opcode);
1891  }  }
1892    
# Line 1825  ui_draw_glyph(int mixmode, Line 1981  ui_draw_glyph(int mixmode,
1981  {\  {\
1982    glyph = cache_get_font (font, ttext[idx]);\    glyph = cache_get_font (font, ttext[idx]);\
1983    if (!(flags & TEXT2_IMPLICIT_X))\    if (!(flags & TEXT2_IMPLICIT_X))\
1984      {\
1985        xyoffset = ttext[++idx];\
1986        if ((xyoffset & 0x80))\
1987      {\      {\
1988        xyoffset = ttext[++idx];\        if (flags & TEXT2_VERTICAL)\
1989        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;\  
         }\  
1990        else\        else\
1991          {\          x += ttext[idx+1] | (ttext[idx+2] << 8);\
1992            if (flags & TEXT2_VERTICAL) \        idx += 2;\
             y += xyoffset;\  
           else\  
             x += xyoffset;\  
         }\  
1993      }\      }\
1994    if (glyph != NULL)\      else\
1995      {\      {\
1996        ui_draw_glyph (mixmode, x + glyph->offset,\        if (flags & TEXT2_VERTICAL)\
1997                       y + glyph->baseline,\          y += xyoffset;\
1998                       glyph->width, glyph->height,\        else\
1999                       glyph->pixmap, 0, 0, bgcolour, fgcolour);\          x += xyoffset;\
       if (flags & TEXT2_IMPLICIT_X)\  
         x += glyph->width;\  
2000      }\      }\
2001      }\
2002      if (glyph != NULL)\
2003      {\
2004        x1 = x + glyph->offset;\
2005        y1 = y + glyph->baseline;\
2006        XSetStipple(g_display, g_gc, (Pixmap) glyph->pixmap);\
2007        XSetTSOrigin(g_display, g_gc, x1, y1);\
2008        FILL_RECTANGLE_BACKSTORE(x1, y1, glyph->width, glyph->height);\
2009        if (flags & TEXT2_IMPLICIT_X)\
2010          x += glyph->width;\
2011      }\
2012  }  }
2013    
2014  void  void
# Line 1861  ui_draw_text(uint8 font, uint8 flags, in Line 2018  ui_draw_text(uint8 font, uint8 flags, in
2018               int fgcolour, uint8 * text, uint8 length)               int fgcolour, uint8 * text, uint8 length)
2019  {  {
2020          FONTGLYPH *glyph;          FONTGLYPH *glyph;
2021          int i, j, xyoffset;          int i, j, xyoffset, x1, y1;
2022          DATABLOB *entry;          DATABLOB *entry;
2023    
2024          SET_FOREGROUND(bgcolour);          SET_FOREGROUND(bgcolour);
2025    
2026            /* Sometimes, the boxcx value is something really large, like
2027               32691. This makes XCopyArea fail with Xvnc. The code below
2028               is a quick fix. */
2029            if (boxx + boxcx > g_width)
2030                    boxcx = g_width - boxx;
2031    
2032          if (boxcx > 1)          if (boxcx > 1)
2033          {          {
2034                  FILL_RECTANGLE_BACKSTORE(boxx, boxy, boxcx, boxcy);                  FILL_RECTANGLE_BACKSTORE(boxx, boxy, boxcx, boxcy);
# Line 1875  ui_draw_text(uint8 font, uint8 flags, in Line 2038  ui_draw_text(uint8 font, uint8 flags, in
2038                  FILL_RECTANGLE_BACKSTORE(clipx, clipy, clipcx, clipcy);                  FILL_RECTANGLE_BACKSTORE(clipx, clipy, clipcx, clipcy);
2039          }          }
2040    
2041            SET_FOREGROUND(fgcolour);
2042            SET_BACKGROUND(bgcolour);
2043            XSetFillStyle(g_display, g_gc, FillStippled);
2044    
2045          /* Paint text, character by character */          /* Paint text, character by character */
2046          for (i = 0; i < length;)          for (i = 0; i < length;)
2047          {          {
# Line 1925  ui_draw_text(uint8 font, uint8 flags, in Line 2092  ui_draw_text(uint8 font, uint8 flags, in
2092                                  break;                                  break;
2093                  }                  }
2094          }          }
2095    
2096            XSetFillStyle(g_display, g_gc, FillSolid);
2097    
2098          if (g_ownbackstore)          if (g_ownbackstore)
2099          {          {
2100                  if (boxcx > 1)                  if (boxcx > 1)

Legend:
Removed from v.543  
changed lines
  Added in v.708

  ViewVC Help
Powered by ViewVC 1.1.26