/[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 534 by stargo, Thu Oct 30 00:10:32 2003 UTC revision 680 by jsorg71, Mon Apr 26 23:14:07 2004 UTC
# Line 20  Line 20 
20    
21  #include <X11/Xlib.h>  #include <X11/Xlib.h>
22  #include <X11/Xutil.h>  #include <X11/Xutil.h>
23    #include <unistd.h>
24    #include <sys/time.h>
25  #include <time.h>  #include <time.h>
26  #include <errno.h>  #include <errno.h>
27    #include <strings.h>
28  #include "rdesktop.h"  #include "rdesktop.h"
29  #include "xproto.h"  #include "xproto.h"
30    
# Line 40  Time g_last_gesturetime; Line 43  Time g_last_gesturetime;
43  static int g_x_socket;  static int g_x_socket;
44  static Screen *g_screen;  static Screen *g_screen;
45  Window g_wnd;  Window g_wnd;
46    extern uint32 g_embed_wnd;
47  BOOL g_enable_compose = False;  BOOL g_enable_compose = False;
48  static GC g_gc;  static GC g_gc = NULL;
49  static Visual *g_visual;  static Visual *g_visual;
50  static int g_depth;  static int g_depth;
51  static int g_bpp;  static int g_bpp;
# Line 49  static XIM g_IM; Line 53  static XIM g_IM;
53  static XIC g_IC;  static XIC g_IC;
54  static XModifierKeymap *g_mod_map;  static XModifierKeymap *g_mod_map;
55  static Cursor g_current_cursor;  static Cursor g_current_cursor;
56  static HCURSOR g_null_cursor;  static HCURSOR g_null_cursor = NULL;
57  static Atom g_protocol_atom, g_kill_atom;  static Atom g_protocol_atom, g_kill_atom;
58  static BOOL g_focused;  static BOOL g_focused;
59  static BOOL g_mouse_in_wnd;  static BOOL g_mouse_in_wnd;
60    static BOOL g_arch_match = False;       /* set to True if RGB XServer and little endian */
61    
62  /* endianness */  /* endianness */
63  static BOOL g_host_be;  static BOOL g_host_be;
# Line 61  static int g_red_shift_r, g_blue_shift_r Line 66  static int g_red_shift_r, g_blue_shift_r
66  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;
67    
68  /* software backing store */  /* software backing store */
69  static BOOL g_ownbackstore;  extern BOOL g_ownbackstore;
70  static Pixmap g_backstore;  static Pixmap g_backstore = 0;
71    
72  /* Moving in single app mode */  /* Moving in single app mode */
73  static BOOL g_moving_wnd;  static BOOL g_moving_wnd;
# Line 110  PixelColour; Line 115  PixelColour;
115  }  }
116    
117  /* colour maps */  /* colour maps */
118  BOOL g_owncolmap = False;  extern BOOL g_owncolmap;
119  static Colormap g_xcolmap;  static Colormap g_xcolmap;
120  static uint32 *g_colmap = NULL;  static uint32 *g_colmap = NULL;
121    
# Line 166  static PixelColour Line 171  static PixelColour
171  split_colour15(uint32 colour)  split_colour15(uint32 colour)
172  {  {
173          PixelColour rv;          PixelColour rv;
174          rv.red = (colour & 0x7c00) >> 10;          rv.red = (colour & 0x7c00) >> 7;
175          rv.red = (rv.red * 0xff) / 0x1f;          rv.green = (colour & 0x03e0) >> 2;
176          rv.green = (colour & 0x03e0) >> 5;          rv.blue = (colour & 0x001f) << 3;
         rv.green = (rv.green * 0xff) / 0x1f;  
         rv.blue = (colour & 0x1f);  
         rv.blue = (rv.blue * 0xff) / 0x1f;  
177          return rv;          return rv;
178  }  }
179    
# Line 179  static PixelColour Line 181  static PixelColour
181  split_colour16(uint32 colour)  split_colour16(uint32 colour)
182  {  {
183          PixelColour rv;          PixelColour rv;
184          rv.red = (colour & 0xf800) >> 11;          rv.red = (colour & 0xf800) >> 8;
185          rv.red = (rv.red * 0xff) / 0x1f;          rv.green = (colour & 0x07e0) >> 3;
186          rv.green = (colour & 0x07e0) >> 5;          rv.blue = (colour & 0x001f) << 3;
         rv.green = (rv.green * 0xff) / 0x3f;  
         rv.blue = (colour & 0x001f);  
         rv.blue = (rv.blue * 0xff) / 0x1f;  
187          return rv;          return rv;
188  }  }
189    
# Line 193  split_colour24(uint32 colour) Line 192  split_colour24(uint32 colour)
192  {  {
193          PixelColour rv;          PixelColour rv;
194          rv.blue = (colour & 0xff0000) >> 16;          rv.blue = (colour & 0xff0000) >> 16;
195          rv.green = (colour & 0xff00) >> 8;          rv.green = (colour & 0x00ff00) >> 8;
196          rv.red = (colour & 0xff);          rv.red = (colour & 0x0000ff);
197          return rv;          return rv;
198  }  }
199    
# Line 230  translate_colour(uint32 colour) Line 229  translate_colour(uint32 colour)
229          return make_colour(pc);          return make_colour(pc);
230  }  }
231    
232    #define UNROLL8(stm) { stm stm stm stm stm stm stm stm }
233    #define REPEAT(stm) \
234    { \
235            while (out <= end - 8 * 4) \
236                    UNROLL8(stm) \
237            while (out < end) \
238                    { stm } \
239    }
240    
241  static void  static void
242  translate8to8(uint8 * data, uint8 * out, uint8 * end)  translate8to8(uint8 * data, uint8 * out, uint8 * end)
243  {  {
# Line 242  translate8to16(uint8 * data, uint8 * out Line 250  translate8to16(uint8 * data, uint8 * out
250  {  {
251          uint16 value;          uint16 value;
252    
253          while (out < end)          if (g_arch_match)
254                    REPEAT(*(((uint16*)out)++) = g_colmap[*(data++)];)
255            else if (g_xserver_be)
256          {          {
257                  value = (uint16) g_colmap[*(data++)];                  while (out < end)
   
                 if (g_xserver_be)  
258                  {                  {
259                            value = (uint16) g_colmap[*(data++)];
260                          *(out++) = value >> 8;                          *(out++) = value >> 8;
261                          *(out++) = value;                          *(out++) = value;
262                  }                  }
263                  else          }
264            else
265            {
266                    while (out < end)
267                  {                  {
268                            value = (uint16) g_colmap[*(data++)];
269                          *(out++) = value;                          *(out++) = value;
270                          *(out++) = value >> 8;                          *(out++) = value >> 8;
271                  }                  }
# Line 265  translate8to24(uint8 * data, uint8 * out Line 278  translate8to24(uint8 * data, uint8 * out
278  {  {
279          uint32 value;          uint32 value;
280    
281          while (out < end)          if (g_xserver_be)
282          {          {
283                  value = g_colmap[*(data++)];                  while (out < end)
   
                 if (g_xserver_be)  
284                  {                  {
285                            value = g_colmap[*(data++)];
286                          *(out++) = value >> 16;                          *(out++) = value >> 16;
287                          *(out++) = value >> 8;                          *(out++) = value >> 8;
288                          *(out++) = value;                          *(out++) = value;
289                  }                  }
290                  else          }
291            else
292            {
293                    while (out < end)
294                  {                  {
295                            value = g_colmap[*(data++)];
296                          *(out++) = value;                          *(out++) = value;
297                          *(out++) = value >> 8;                          *(out++) = value >> 8;
298                          *(out++) = value >> 16;                          *(out++) = value >> 16;
# Line 289  translate8to32(uint8 * data, uint8 * out Line 305  translate8to32(uint8 * data, uint8 * out
305  {  {
306          uint32 value;          uint32 value;
307    
308          while (out < end)          if (g_arch_match)
309                    REPEAT(*(((uint32*)out)++) = g_colmap[*(data++)];)
310            else if (g_xserver_be)
311          {          {
312                  value = g_colmap[*(data++)];                  while (out < end)
   
                 if (g_xserver_be)  
313                  {                  {
314                            value = g_colmap[*(data++)];
315                          *(out++) = value >> 24;                          *(out++) = value >> 24;
316                          *(out++) = value >> 16;                          *(out++) = value >> 16;
317                          *(out++) = value >> 8;                          *(out++) = value >> 8;
318                          *(out++) = value;                          *(out++) = value;
319                  }                  }
320                  else          }
321            else
322            {
323                    while (out < end)
324                  {                  {
325                            value = g_colmap[*(data++)];
326                          *(out++) = value;                          *(out++) = value;
327                          *(out++) = value >> 8;                          *(out++) = value >> 8;
328                          *(out++) = value >> 16;                          *(out++) = value >> 16;
# Line 310  translate8to32(uint8 * data, uint8 * out Line 331  translate8to32(uint8 * data, uint8 * out
331          }          }
332  }  }
333    
 /* todo the remaining translate function might need some big endian check ?? */  
   
334  static void  static void
335  translate15to16(uint16 * data, uint8 * out, uint8 * end)  translate15to16(uint16 * data, uint8 * out, uint8 * end)
336  {  {
# Line 542  translate24to24(uint8 * data, uint8 * ou Line 561  translate24to24(uint8 * data, uint8 * ou
561                  pixel |= *(data++);                  pixel |= *(data++);
562    
563                  value = make_colour(split_colour24(pixel));                  value = make_colour(split_colour24(pixel));
564                    
565                  if (g_xserver_be)                  if (g_xserver_be)
566                  {                  {
567                          *(out++) = value >> 16;                          *(out++) = value >> 16;
# Line 592  translate24to32(uint8 * data, uint8 * ou Line 611  translate24to32(uint8 * data, uint8 * ou
611  static uint8 *  static uint8 *
612  translate_image(int width, int height, uint8 * data)  translate_image(int width, int height, uint8 * data)
613  {  {
614          int size = width * height * g_bpp / 8;          int size;
615          uint8 *out = (uint8 *) xmalloc(size);          uint8 *out;
616          uint8 *end = out + size;          uint8 *end;
617    
618            /* if server and xserver bpp match, */
619            /* and arch(endian) matches, no need to translate */
620            /* just return data */
621            if (g_arch_match)
622            {
623                    if (g_depth == 15 && g_server_bpp == 15)
624                            return data;
625                    if (g_depth == 16 && g_server_bpp == 16)
626                            return data;
627            }
628    
629            size = width * height * (g_bpp / 8);
630            out = (uint8 *) xmalloc(size);
631            end = out + size;
632    
633          switch (g_server_bpp)          switch (g_server_bpp)
634          {          {
# Line 700  ui_init(void) Line 734  ui_init(void)
734          XVisualInfo vi;          XVisualInfo vi;
735          XPixmapFormatValues *pfm;          XPixmapFormatValues *pfm;
736          uint16 test;          uint16 test;
737          int i, screen_num;          int i, screen_num, nvisuals;
738            XVisualInfo *vmatches = NULL;
739            XVisualInfo template;
740            Bool TrueColorVisual = False;
741    
742          g_display = XOpenDisplay(NULL);          g_display = XOpenDisplay(NULL);
743          if (g_display == NULL)          if (g_display == NULL)
# Line 714  ui_init(void) Line 751  ui_init(void)
751          g_screen = ScreenOfDisplay(g_display, screen_num);          g_screen = ScreenOfDisplay(g_display, screen_num);
752          g_depth = DefaultDepthOfScreen(g_screen);          g_depth = DefaultDepthOfScreen(g_screen);
753    
754          if (g_server_bpp == 8)          /* Search for best TrueColor depth */
755            template.class = TrueColor;
756            vmatches = XGetVisualInfo(g_display, VisualClassMask, &template, &nvisuals);
757    
758            nvisuals--;
759            while (nvisuals >= 0)
760          {          {
761                  /* we use a colourmap, so any visual should do */                  if ((vmatches + nvisuals)->depth > g_depth)
762                    {
763                            g_depth = (vmatches + nvisuals)->depth;
764                    }
765                    nvisuals--;
766                    TrueColorVisual = True;
767            }
768    
769            test = 1;
770            g_host_be = !(BOOL) (*(uint8 *) (&test));
771            g_xserver_be = (ImageByteOrder(g_display) == MSBFirst);
772    
773            if ((g_server_bpp == 8) && ((!TrueColorVisual) || (g_depth <= 8)))
774            {
775                    /* we use a colourmap, so the default visual should do */
776                  g_visual = DefaultVisualOfScreen(g_screen);                  g_visual = DefaultVisualOfScreen(g_screen);
777                    g_depth = DefaultDepthOfScreen(g_screen);
778    
779                    /* Do not allocate colours on a TrueColor visual */
780                    if (g_visual->class == TrueColor)
781                    {
782                            g_owncolmap = False;
783                    }
784          }          }
785          else          else
786          {          {
# Line 733  ui_init(void) Line 796  ui_init(void)
796                  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);
797                  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);
798                  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);
799    
800                    /* if RGB video and averything is little endian */
801                    if (vi.red_mask > vi.green_mask && vi.green_mask > vi.blue_mask)
802                            if (!g_xserver_be && !g_host_be)
803                                    g_arch_match = True;
804          }          }
805    
806          pfm = XListPixmapFormats(g_display, &i);          pfm = XListPixmapFormats(g_display, &i);
# Line 759  ui_init(void) Line 827  ui_init(void)
827    
828          if (!g_owncolmap)          if (!g_owncolmap)
829          {          {
830                  g_xcolmap = DefaultColormapOfScreen(g_screen);                  g_xcolmap =
831                            XCreateColormap(g_display, RootWindowOfScreen(g_screen), g_visual,
832                                            AllocNone);
833                  if (g_depth <= 8)                  if (g_depth <= 8)
834                          warning("Screen depth is 8 bits or lower: you may want to use -C for a private colourmap\n");                          warning("Screen depth is 8 bits or lower: you may want to use -C for a private colourmap\n");
835          }          }
836    
837          g_gc = XCreateGC(g_display, RootWindowOfScreen(g_screen), 0, NULL);          if ((!g_ownbackstore) && (DoesBackingStore(g_screen) != Always))
838            {
839          if (DoesBackingStore(g_screen) != Always)                  warning("External BackingStore not available, using internal\n");
840                  g_ownbackstore = True;                  g_ownbackstore = True;
841            }
         test = 1;  
         g_host_be = !(BOOL) (*(uint8 *) (&test));  
         g_xserver_be = (ImageByteOrder(g_display) == MSBFirst);  
842    
843          /*          /*
844           * Determine desktop size           * Determine desktop size
845           */           */
846          if (g_width < 0)          if (g_fullscreen)
847            {
848                    g_width = WidthOfScreen(g_screen);
849                    g_height = HeightOfScreen(g_screen);
850            }
851            else if (g_width < 0)
852          {          {
853                  /* Percent of screen */                  /* Percent of screen */
854                  g_height = HeightOfScreen(g_screen) * (-g_width) / 100;                  g_height = HeightOfScreen(g_screen) * (-g_width) / 100;
# Line 799  ui_init(void) Line 871  ui_init(void)
871                          g_height = 600;                          g_height = 600;
872                  }                  }
873          }          }
         else if (g_fullscreen)  
         {  
                 g_width = WidthOfScreen(g_screen);  
                 g_height = HeightOfScreen(g_screen);  
         }  
874    
875          /* make sure width is a multiple of 4 */          /* make sure width is a multiple of 4 */
876          g_width = (g_width + 3) & ~3;          g_width = (g_width + 3) & ~3;
877    
         if (g_ownbackstore)  
         {  
                 g_backstore =  
                         XCreatePixmap(g_display, RootWindowOfScreen(g_screen), g_width, g_height,  
                                       g_depth);  
   
                 /* clear to prevent rubbish being exposed at startup */  
                 XSetForeground(g_display, g_gc, BlackPixelOfScreen(g_screen));  
                 XFillRectangle(g_display, g_backstore, g_gc, 0, 0, g_width, g_height);  
         }  
   
878          g_mod_map = XGetModifierMapping(g_display);          g_mod_map = XGetModifierMapping(g_display);
879    
880          xkeymap_init();          xkeymap_init();
# Line 839  ui_deinit(void) Line 895  ui_deinit(void)
895          if (g_IM != NULL)          if (g_IM != NULL)
896                  XCloseIM(g_IM);                  XCloseIM(g_IM);
897    
898            if (g_null_cursor != NULL)
899                    ui_destroy_cursor(g_null_cursor);
900    
901          XFreeModifiermap(g_mod_map);          XFreeModifiermap(g_mod_map);
902    
903          if (g_ownbackstore)          if (g_ownbackstore)
# Line 849  ui_deinit(void) Line 908  ui_deinit(void)
908          g_display = NULL;          g_display = NULL;
909  }  }
910    
 #define NULL_POINTER_MASK       "\x80"  
 #define NULL_POINTER_DATA       "\x0\x0\x0"  
   
911  BOOL  BOOL
912  ui_create_window(void)  ui_create_window(void)
913  {  {
914            uint8 null_pointer_mask[1] = { 0x80 };
915            uint8 null_pointer_data[4] = { 0x00, 0x00, 0x00, 0x00 };
916          XSetWindowAttributes attribs;          XSetWindowAttributes attribs;
917          XClassHint *classhints;          XClassHint *classhints;
918          XSizeHints *sizehints;          XSizeHints *sizehints;
# Line 866  ui_create_window(void) Line 924  ui_create_window(void)
924          wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height;          wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height;
925    
926          attribs.background_pixel = BlackPixelOfScreen(g_screen);          attribs.background_pixel = BlackPixelOfScreen(g_screen);
927            attribs.border_pixel = WhitePixelOfScreen(g_screen);
928          attribs.backing_store = g_ownbackstore ? NotUseful : Always;          attribs.backing_store = g_ownbackstore ? NotUseful : Always;
929          attribs.override_redirect = g_fullscreen;          attribs.override_redirect = g_fullscreen;
930            attribs.colormap = g_xcolmap;
931    
932          g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), 0, 0, wndwidth, wndheight,          g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), 0, 0, wndwidth, wndheight,
933                                0, CopyFromParent, InputOutput, CopyFromParent,                                0, g_depth, InputOutput, g_visual,
934                                CWBackPixel | CWBackingStore | CWOverrideRedirect, &attribs);                                CWBackPixel | CWBackingStore | CWOverrideRedirect |
935                                  CWColormap | CWBorderPixel, &attribs);
936    
937            if (g_gc == NULL)
938                    g_gc = XCreateGC(g_display, g_wnd, 0, NULL);
939    
940            if ((g_ownbackstore) && (g_backstore == 0))
941            {
942                    g_backstore = XCreatePixmap(g_display, g_wnd, g_width, g_height, g_depth);
943    
944                    /* clear to prevent rubbish being exposed at startup */
945                    XSetForeground(g_display, g_gc, BlackPixelOfScreen(g_screen));
946                    XFillRectangle(g_display, g_backstore, g_gc, 0, 0, g_width, g_height);
947            }
948    
949          XStoreName(g_display, g_wnd, g_title);          XStoreName(g_display, g_wnd, g_title);
950    
# Line 896  ui_create_window(void) Line 969  ui_create_window(void)
969                  XFree(sizehints);                  XFree(sizehints);
970          }          }
971    
972            if (g_embed_wnd)
973            {
974                    XReparentWindow(g_display, g_wnd, (Window) g_embed_wnd, 0, 0);
975            }
976    
977          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
978                  VisibilityChangeMask | FocusChangeMask;                  VisibilityChangeMask | FocusChangeMask;
979    
# Line 937  ui_create_window(void) Line 1015  ui_create_window(void)
1015          XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1);          XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1);
1016    
1017          /* create invisible 1x1 cursor to be used as null cursor */          /* create invisible 1x1 cursor to be used as null cursor */
1018          g_null_cursor = ui_create_cursor(0, 0, 1, 1, NULL_POINTER_MASK, NULL_POINTER_DATA);          if (g_null_cursor == NULL)
1019                    g_null_cursor = ui_create_cursor(0, 0, 1, 1, null_pointer_mask, null_pointer_data);
1020    
1021          return True;          return True;
1022  }  }
1023    
1024  void  void
1025  ui_destroy_window(void)  ui_resize_window()
1026  {  {
1027          ui_destroy_cursor(g_null_cursor);          XSizeHints *sizehints;
1028    
1029            sizehints = XAllocSizeHints();
1030            if (sizehints)
1031            {
1032                    sizehints->flags = PMinSize | PMaxSize;
1033                    sizehints->min_width = sizehints->max_width = g_width;
1034                    sizehints->min_height = sizehints->max_height = g_height;
1035                    XSetWMNormalHints(g_display, g_wnd, sizehints);
1036                    XFree(sizehints);
1037            }
1038    
1039            if (!(g_fullscreen || g_embed_wnd))
1040            {
1041                    XResizeWindow(g_display, g_wnd, g_width, g_height);
1042            }
1043    }
1044    
1045    void
1046    ui_destroy_window(void)
1047    {
1048          if (g_IC != NULL)          if (g_IC != NULL)
1049                  XDestroyIC(g_IC);                  XDestroyIC(g_IC);
1050    
# Line 990  xwin_process_events(void) Line 1088  xwin_process_events(void)
1088          key_translation tr;          key_translation tr;
1089          char str[256];          char str[256];
1090          Status status;          Status status;
         unsigned int state;  
         Window wdummy;  
         int dummy;  
1091    
1092          while (XPending(g_display) > 0)          while (XPending(g_display) > 0)
1093          {          {
# Line 1165  xwin_process_events(void) Line 1260  xwin_process_events(void)
1260                                  if (xevent.xfocus.mode == NotifyGrab)                                  if (xevent.xfocus.mode == NotifyGrab)
1261                                          break;                                          break;
1262                                  g_focused = True;                                  g_focused = True;
1263                                  XQueryPointer(g_display, g_wnd, &wdummy, &wdummy, &dummy, &dummy,                                  reset_modifier_keys();
                                               &dummy, &dummy, &state);  
                                 reset_modifier_keys(state);  
1264                                  if (g_grab_keyboard && g_mouse_in_wnd)                                  if (g_grab_keyboard && g_mouse_in_wnd)
1265                                          XGrabKeyboard(g_display, g_wnd, True,                                          XGrabKeyboard(g_display, g_wnd, True,
1266                                                        GrabModeAsync, GrabModeAsync, CurrentTime);                                                        GrabModeAsync, GrabModeAsync, CurrentTime);
# Line 1247  xwin_process_events(void) Line 1340  xwin_process_events(void)
1340  int  int
1341  ui_select(int rdp_socket)  ui_select(int rdp_socket)
1342  {  {
1343          int n = (rdp_socket > g_x_socket) ? rdp_socket + 1 : g_x_socket + 1;          int n;
1344          fd_set rfds, wfds;          fd_set rfds, wfds;
1345            struct timeval tv;
1346            BOOL s_timeout = False;
1347    
1348          while (True)          while (True)
1349          {          {
1350                    n = (rdp_socket > g_x_socket) ? rdp_socket : g_x_socket;
1351                  /* Process any events already waiting */                  /* Process any events already waiting */
1352                  if (!xwin_process_events())                  if (!xwin_process_events())
1353                          /* User quit */                          /* User quit */
# Line 1267  ui_select(int rdp_socket) Line 1363  ui_select(int rdp_socket)
1363                  if (g_dsp_busy)                  if (g_dsp_busy)
1364                  {                  {
1365                          FD_SET(g_dsp_fd, &wfds);                          FD_SET(g_dsp_fd, &wfds);
1366                          n = (g_dsp_fd + 1 > n) ? g_dsp_fd + 1 : n;                          n = (g_dsp_fd > n) ? g_dsp_fd : n;
1367                  }                  }
1368  #endif  #endif
1369                    /* default timeout */
1370                    tv.tv_sec = 60;
1371                    tv.tv_usec = 0;
1372    
1373                  switch (select(n, &rfds, &wfds, NULL, NULL))                  /* add redirection handles */
1374                    rdpdr_add_fds(&n, &rfds, &wfds, &tv, &s_timeout);
1375    
1376                    n++;
1377    
1378                    switch (select(n, &rfds, &wfds, NULL, &tv))
1379                  {                  {
1380                          case -1:                          case -1:
1381                                  error("select: %s\n", strerror(errno));                                  error("select: %s\n", strerror(errno));
1382    
1383                          case 0:                          case 0:
1384                                    /* TODO: if tv.tv_sec just times out
1385                                     * we will segfault.
1386                                     * FIXME:
1387                                     */
1388                                    //s_timeout = True;
1389                                    //rdpdr_check_fds(&rfds, &wfds, (BOOL) True);
1390                                  continue;                                  continue;
1391                  }                  }
1392    
1393                    rdpdr_check_fds(&rfds, &wfds, (BOOL) False);
1394    
1395                  if (FD_ISSET(rdp_socket, &rfds))                  if (FD_ISSET(rdp_socket, &rfds))
1396                          return 1;                          return 1;
1397    
# Line 1324  ui_create_bitmap(int width, int height, Line 1436  ui_create_bitmap(int width, int height,
1436          XPutImage(g_display, bitmap, g_gc, image, 0, 0, 0, 0, width, height);          XPutImage(g_display, bitmap, g_gc, image, 0, 0, 0, 0, width, height);
1437    
1438          XFree(image);          XFree(image);
1439          if (!g_owncolmap)          if (tdata != data)
1440                  xfree(tdata);                  xfree(tdata);
1441          return (HBITMAP) bitmap;          return (HBITMAP) bitmap;
1442  }  }
# Line 1363  ui_paint_bitmap(int x, int y, int cx, in Line 1475  ui_paint_bitmap(int x, int y, int cx, in
1475          }          }
1476    
1477          XFree(image);          XFree(image);
1478          if (!g_owncolmap)          if (tdata != data)
1479                  xfree(tdata);                  xfree(tdata);
1480  }  }
1481    
# Line 1687  ui_patblt(uint8 opcode, Line 1799  ui_patblt(uint8 opcode,
1799          {          {
1800                  case 0: /* Solid */                  case 0: /* Solid */
1801                          SET_FOREGROUND(fgcolour);                          SET_FOREGROUND(fgcolour);
1802                          FILL_RECTANGLE(x, y, cx, cy);                          FILL_RECTANGLE_BACKSTORE(x, y, cx, cy);
1803                          break;                          break;
1804    
1805                  case 2: /* Hatch */                  case 2: /* Hatch */
# Line 1698  ui_patblt(uint8 opcode, Line 1810  ui_patblt(uint8 opcode,
1810                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);
1811                          XSetStipple(g_display, g_gc, fill);                          XSetStipple(g_display, g_gc, fill);
1812                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);
1813                          FILL_RECTANGLE(x, y, cx, cy);                          FILL_RECTANGLE_BACKSTORE(x, y, cx, cy);
1814                          XSetFillStyle(g_display, g_gc, FillSolid);                          XSetFillStyle(g_display, g_gc, FillSolid);
1815                          XSetTSOrigin(g_display, g_gc, 0, 0);                          XSetTSOrigin(g_display, g_gc, 0, 0);
1816                          ui_destroy_glyph((HGLYPH) fill);                          ui_destroy_glyph((HGLYPH) fill);
# Line 1708  ui_patblt(uint8 opcode, Line 1820  ui_patblt(uint8 opcode,
1820                          for (i = 0; i != 8; i++)                          for (i = 0; i != 8; i++)
1821                                  ipattern[7 - i] = brush->pattern[i];                                  ipattern[7 - i] = brush->pattern[i];
1822                          fill = (Pixmap) ui_create_glyph(8, 8, ipattern);                          fill = (Pixmap) ui_create_glyph(8, 8, ipattern);
   
1823                          SET_FOREGROUND(bgcolour);                          SET_FOREGROUND(bgcolour);
1824                          SET_BACKGROUND(fgcolour);                          SET_BACKGROUND(fgcolour);
1825                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);
1826                          XSetStipple(g_display, g_gc, fill);                          XSetStipple(g_display, g_gc, fill);
1827                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);
1828                            FILL_RECTANGLE_BACKSTORE(x, y, cx, cy);
                         FILL_RECTANGLE(x, y, cx, cy);  
   
1829                          XSetFillStyle(g_display, g_gc, FillSolid);                          XSetFillStyle(g_display, g_gc, FillSolid);
1830                          XSetTSOrigin(g_display, g_gc, 0, 0);                          XSetTSOrigin(g_display, g_gc, 0, 0);
1831                          ui_destroy_glyph((HGLYPH) fill);                          ui_destroy_glyph((HGLYPH) fill);
# Line 1727  ui_patblt(uint8 opcode, Line 1836  ui_patblt(uint8 opcode,
1836          }          }
1837    
1838          RESET_FUNCTION(opcode);          RESET_FUNCTION(opcode);
1839    
1840            if (g_ownbackstore)
1841                    XCopyArea(g_display, g_backstore, g_wnd, g_gc, x, y, cx, cy, x, y);
1842  }  }
1843    
1844  void  void
# Line 1735  ui_screenblt(uint8 opcode, Line 1847  ui_screenblt(uint8 opcode,
1847               /* src */ int srcx, int srcy)               /* src */ int srcx, int srcy)
1848  {  {
1849          SET_FUNCTION(opcode);          SET_FUNCTION(opcode);
         XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);  
1850          if (g_ownbackstore)          if (g_ownbackstore)
1851            {
1852                    XCopyArea(g_display, g_backstore, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);
1853                  XCopyArea(g_display, g_backstore, g_backstore, g_gc, srcx, srcy, cx, cy, x, y);                  XCopyArea(g_display, g_backstore, g_backstore, g_gc, srcx, srcy, cx, cy, x, y);
1854            }
1855            else
1856            {
1857                    XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);
1858            }
1859          RESET_FUNCTION(opcode);          RESET_FUNCTION(opcode);
1860  }  }
1861    
# Line 1832  ui_draw_glyph(int mixmode, Line 1950  ui_draw_glyph(int mixmode,
1950  {\  {\
1951    glyph = cache_get_font (font, ttext[idx]);\    glyph = cache_get_font (font, ttext[idx]);\
1952    if (!(flags & TEXT2_IMPLICIT_X))\    if (!(flags & TEXT2_IMPLICIT_X))\
1953      {\
1954        xyoffset = ttext[++idx];\
1955        if ((xyoffset & 0x80))\
1956      {\      {\
1957        xyoffset = ttext[++idx];\        if (flags & TEXT2_VERTICAL)\
1958        if ((xyoffset & 0x80))\          y += ttext[idx+1] | (ttext[idx+2] << 8);\
         {\  
           if (flags & TEXT2_VERTICAL) \  
             y += ttext[idx+1] | (ttext[idx+2] << 8);\  
           else\  
             x += ttext[idx+1] | (ttext[idx+2] << 8);\  
           idx += 2;\  
         }\  
1959        else\        else\
1960          {\          x += ttext[idx+1] | (ttext[idx+2] << 8);\
1961            if (flags & TEXT2_VERTICAL) \        idx += 2;\
             y += xyoffset;\  
           else\  
             x += xyoffset;\  
         }\  
1962      }\      }\
1963    if (glyph != NULL)\      else\
1964      {\      {\
1965        ui_draw_glyph (mixmode, x + glyph->offset,\        if (flags & TEXT2_VERTICAL)\
1966                       y + glyph->baseline,\          y += xyoffset;\
1967                       glyph->width, glyph->height,\        else\
1968                       glyph->pixmap, 0, 0, bgcolour, fgcolour);\          x += xyoffset;\
       if (flags & TEXT2_IMPLICIT_X)\  
         x += glyph->width;\  
1969      }\      }\
1970      }\
1971      if (glyph != NULL)\
1972      {\
1973        x1 = x + glyph->offset;\
1974        y1 = y + glyph->baseline;\
1975        XSetStipple(g_display, g_gc, (Pixmap) glyph->pixmap);\
1976        XSetTSOrigin(g_display, g_gc, x1, y1);\
1977        FILL_RECTANGLE_BACKSTORE(x1, y1, glyph->width, glyph->height);\
1978        if (flags & TEXT2_IMPLICIT_X)\
1979          x += glyph->width;\
1980      }\
1981  }  }
1982    
1983  void  void
# Line 1868  ui_draw_text(uint8 font, uint8 flags, in Line 1987  ui_draw_text(uint8 font, uint8 flags, in
1987               int fgcolour, uint8 * text, uint8 length)               int fgcolour, uint8 * text, uint8 length)
1988  {  {
1989          FONTGLYPH *glyph;          FONTGLYPH *glyph;
1990          int i, j, xyoffset;          int i, j, xyoffset, x1, y1;
1991          DATABLOB *entry;          DATABLOB *entry;
1992    
1993          SET_FOREGROUND(bgcolour);          SET_FOREGROUND(bgcolour);
1994    
1995            /* Sometimes, the boxcx value is something really large, like
1996               32691. This makes XCopyArea fail with Xvnc. The code below
1997               is a quick fix. */
1998            if (boxx + boxcx > g_width)
1999                    boxcx = g_width - boxx;
2000    
2001          if (boxcx > 1)          if (boxcx > 1)
2002          {          {
2003                  FILL_RECTANGLE_BACKSTORE(boxx, boxy, boxcx, boxcy);                  FILL_RECTANGLE_BACKSTORE(boxx, boxy, boxcx, boxcy);
# Line 1882  ui_draw_text(uint8 font, uint8 flags, in Line 2007  ui_draw_text(uint8 font, uint8 flags, in
2007                  FILL_RECTANGLE_BACKSTORE(clipx, clipy, clipcx, clipcy);                  FILL_RECTANGLE_BACKSTORE(clipx, clipy, clipcx, clipcy);
2008          }          }
2009    
2010            SET_FOREGROUND(fgcolour);
2011            SET_BACKGROUND(bgcolour);
2012            XSetFillStyle(g_display, g_gc, FillStippled);
2013    
2014          /* Paint text, character by character */          /* Paint text, character by character */
2015          for (i = 0; i < length;)          for (i = 0; i < length;)
2016          {          {
# Line 1932  ui_draw_text(uint8 font, uint8 flags, in Line 2061  ui_draw_text(uint8 font, uint8 flags, in
2061                                  break;                                  break;
2062                  }                  }
2063          }          }
2064    
2065            XSetFillStyle(g_display, g_gc, FillSolid);
2066    
2067          if (g_ownbackstore)          if (g_ownbackstore)
2068          {          {
2069                  if (boxcx > 1)                  if (boxcx > 1)

Legend:
Removed from v.534  
changed lines
  Added in v.680

  ViewVC Help
Powered by ViewVC 1.1.26