/[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 606 by stargo, Sat Feb 14 23:20:24 2004 UTC revision 677 by n-ki, Mon Apr 26 13:48:39 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>  #include <strings.h>
# Line 42  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 = NULL;  static GC g_gc = NULL;
49  static Visual *g_visual;  static Visual *g_visual;
# Line 55  static HCURSOR g_null_cursor = NULL; Line 57  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 63  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 = 0;  static Pixmap g_backstore = 0;
71    
72  /* Moving in single app mode */  /* Moving in single app mode */
# Line 112  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 168  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 181  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 195  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 244  translate8to16(uint8 * data, uint8 * out Line 241  translate8to16(uint8 * data, uint8 * out
241  {  {
242          uint16 value;          uint16 value;
243    
244          while (out < end)          if (g_xserver_be)
245          {          {
246                  value = (uint16) g_colmap[*(data++)];                  while (out < end)
   
                 if (g_xserver_be)  
247                  {                  {
248                            value = (uint16) g_colmap[*(data++)];
249                          *(out++) = value >> 8;                          *(out++) = value >> 8;
250                          *(out++) = value;                          *(out++) = value;
251                  }                  }
252                  else          }
253            else
254            {
255                    while (out < end)
256                  {                  {
257                            value = (uint16) g_colmap[*(data++)];
258                          *(out++) = value;                          *(out++) = value;
259                          *(out++) = value >> 8;                          *(out++) = value >> 8;
260                  }                  }
# Line 267  translate8to24(uint8 * data, uint8 * out Line 267  translate8to24(uint8 * data, uint8 * out
267  {  {
268          uint32 value;          uint32 value;
269    
270          while (out < end)          if (g_xserver_be)
271          {          {
272                  value = g_colmap[*(data++)];                  while (out < end)
   
                 if (g_xserver_be)  
273                  {                  {
274                            value = g_colmap[*(data++)];
275                          *(out++) = value >> 16;                          *(out++) = value >> 16;
276                          *(out++) = value >> 8;                          *(out++) = value >> 8;
277                          *(out++) = value;                          *(out++) = value;
278                  }                  }
279                  else          }
280            else
281            {
282                    while (out < end)
283                  {                  {
284                            value = g_colmap[*(data++)];
285                          *(out++) = value;                          *(out++) = value;
286                          *(out++) = value >> 8;                          *(out++) = value >> 8;
287                          *(out++) = value >> 16;                          *(out++) = value >> 16;
# Line 291  translate8to32(uint8 * data, uint8 * out Line 294  translate8to32(uint8 * data, uint8 * out
294  {  {
295          uint32 value;          uint32 value;
296    
297          while (out < end)          if (g_xserver_be)
298          {          {
299                  value = g_colmap[*(data++)];                  while (out < end)
   
                 if (g_xserver_be)  
300                  {                  {
301                            value = g_colmap[*(data++)];
302                          *(out++) = value >> 24;                          *(out++) = value >> 24;
303                          *(out++) = value >> 16;                          *(out++) = value >> 16;
304                          *(out++) = value >> 8;                          *(out++) = value >> 8;
305                          *(out++) = value;                          *(out++) = value;
306                  }                  }
307                  else          }
308            else
309            {
310                    while (out < end)
311                  {                  {
312                            value = g_colmap[*(data++)];
313                          *(out++) = value;                          *(out++) = value;
314                          *(out++) = value >> 8;                          *(out++) = value >> 8;
315                          *(out++) = value >> 16;                          *(out++) = value >> 16;
# Line 592  translate24to32(uint8 * data, uint8 * ou Line 598  translate24to32(uint8 * data, uint8 * ou
598  static uint8 *  static uint8 *
599  translate_image(int width, int height, uint8 * data)  translate_image(int width, int height, uint8 * data)
600  {  {
601          int size = width * height * g_bpp / 8;          int size;
602          uint8 *out = (uint8 *) xmalloc(size);          uint8 *out;
603          uint8 *end = out + size;          uint8 *end;
604    
605            /* if server and xserver bpp match, */
606            /* and arch(endian) matches, no need to translate */
607            /* just return data */
608            if (g_arch_match)
609            {
610                    if (g_depth == 15 && g_server_bpp == 15)
611                            return data;
612                    if (g_depth == 16 && g_server_bpp == 16)
613                            return data;
614            }
615    
616            size = width * height * (g_bpp / 8);
617            out = (uint8 *) xmalloc(size);
618            end = out + size;
619    
620          switch (g_server_bpp)          switch (g_server_bpp)
621          {          {
# Line 732  ui_init(void) Line 753  ui_init(void)
753                  TrueColorVisual = True;                  TrueColorVisual = True;
754          }          }
755    
756            test = 1;
757            g_host_be = !(BOOL) (*(uint8 *) (&test));
758            g_xserver_be = (ImageByteOrder(g_display) == MSBFirst);
759    
760          if ((g_server_bpp == 8) && ((!TrueColorVisual) || (g_depth <= 8)))          if ((g_server_bpp == 8) && ((!TrueColorVisual) || (g_depth <= 8)))
761          {          {
762                  /* we use a colourmap, so the default visual should do */                  /* we use a colourmap, so the default visual should do */
# Line 758  ui_init(void) Line 783  ui_init(void)
783                  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);
784                  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);
785                  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);
786    
787                    /* if RGB video and averything is little endian */
788                    if (vi.red_mask > vi.green_mask && vi.green_mask > vi.blue_mask)
789                            if (!g_xserver_be && !g_host_be)
790                                    g_arch_match = True;
791          }          }
792    
793          pfm = XListPixmapFormats(g_display, &i);          pfm = XListPixmapFormats(g_display, &i);
# Line 791  ui_init(void) Line 821  ui_init(void)
821                          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");
822          }          }
823    
824          if (DoesBackingStore(g_screen) != Always)          if ((!g_ownbackstore) && (DoesBackingStore(g_screen) != Always))
825            {
826                    warning("External BackingStore not available, using internal\n");
827                  g_ownbackstore = True;                  g_ownbackstore = True;
828            }
         test = 1;  
         g_host_be = !(BOOL) (*(uint8 *) (&test));  
         g_xserver_be = (ImageByteOrder(g_display) == MSBFirst);  
829    
830          /*          /*
831           * Determine desktop size           * Determine desktop size
# Line 927  ui_create_window(void) Line 956  ui_create_window(void)
956                  XFree(sizehints);                  XFree(sizehints);
957          }          }
958    
959            if (g_embed_wnd)
960            {
961                    XReparentWindow(g_display, g_wnd, (Window) g_embed_wnd, 0, 0);
962            }
963    
964          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
965                  VisibilityChangeMask | FocusChangeMask;                  VisibilityChangeMask | FocusChangeMask;
966    
# Line 975  ui_create_window(void) Line 1009  ui_create_window(void)
1009  }  }
1010    
1011  void  void
1012    ui_resize_window()
1013    {
1014            XSizeHints *sizehints;
1015    
1016            sizehints = XAllocSizeHints();
1017            if (sizehints)
1018            {
1019                    sizehints->flags = PMinSize | PMaxSize;
1020                    sizehints->min_width = sizehints->max_width = g_width;
1021                    sizehints->min_height = sizehints->max_height = g_height;
1022                    XSetWMNormalHints(g_display, g_wnd, sizehints);
1023                    XFree(sizehints);
1024            }
1025    
1026            if (!(g_fullscreen || g_embed_wnd))
1027            {
1028                    XResizeWindow(g_display, g_wnd, g_width, g_height);
1029            }
1030    }
1031    
1032    void
1033  ui_destroy_window(void)  ui_destroy_window(void)
1034  {  {
1035          if (g_IC != NULL)          if (g_IC != NULL)
# Line 1368  ui_create_bitmap(int width, int height, Line 1423  ui_create_bitmap(int width, int height,
1423          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);
1424    
1425          XFree(image);          XFree(image);
1426          if (!g_owncolmap)          if (tdata != data)
1427                  xfree(tdata);                  xfree(tdata);
1428          return (HBITMAP) bitmap;          return (HBITMAP) bitmap;
1429  }  }
# Line 1407  ui_paint_bitmap(int x, int y, int cx, in Line 1462  ui_paint_bitmap(int x, int y, int cx, in
1462          }          }
1463    
1464          XFree(image);          XFree(image);
1465          if (!g_owncolmap)          if (tdata != data)
1466                  xfree(tdata);                  xfree(tdata);
1467  }  }
1468    
# Line 1779  ui_screenblt(uint8 opcode, Line 1834  ui_screenblt(uint8 opcode,
1834               /* src */ int srcx, int srcy)               /* src */ int srcx, int srcy)
1835  {  {
1836          SET_FUNCTION(opcode);          SET_FUNCTION(opcode);
         XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);  
1837          if (g_ownbackstore)          if (g_ownbackstore)
1838            {
1839                    XCopyArea(g_display, g_backstore, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);
1840                  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);
1841            }
1842            else
1843            {
1844                    XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);
1845            }
1846          RESET_FUNCTION(opcode);          RESET_FUNCTION(opcode);
1847  }  }
1848    
# Line 1918  ui_draw_text(uint8 font, uint8 flags, in Line 1979  ui_draw_text(uint8 font, uint8 flags, in
1979    
1980          SET_FOREGROUND(bgcolour);          SET_FOREGROUND(bgcolour);
1981    
1982            /* Sometimes, the boxcx value is something really large, like
1983               32691. This makes XCopyArea fail with Xvnc. The code below
1984               is a quick fix. */
1985            if (boxx + boxcx > g_width)
1986                    boxcx = g_width - boxx;
1987    
1988          if (boxcx > 1)          if (boxcx > 1)
1989          {          {
1990                  FILL_RECTANGLE_BACKSTORE(boxx, boxy, boxcx, boxcy);                  FILL_RECTANGLE_BACKSTORE(boxx, boxy, boxcx, boxcy);

Legend:
Removed from v.606  
changed lines
  Added in v.677

  ViewVC Help
Powered by ViewVC 1.1.26