/[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 594 by n-ki, Tue Feb 3 13:55:12 2004 UTC revision 679 by jsorg71, Mon Apr 26 23:00:25 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 = NULL;  static GC g_gc = NULL;
49  static Visual *g_visual;  static Visual *g_visual;
# Line 54  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 62  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 = NULL;  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 111  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 167  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 180  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 194  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 231  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 243  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 266  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 290  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 591  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 731  ui_init(void) Line 766  ui_init(void)
766                  TrueColorVisual = True;                  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)))          if ((g_server_bpp == 8) && ((!TrueColorVisual) || (g_depth <= 8)))
774          {          {
775                  /* we use a colourmap, so the default visual should do */                  /* we use a colourmap, so the default visual should do */
# Line 757  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 790  ui_init(void) Line 834  ui_init(void)
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          if (DoesBackingStore(g_screen) != Always)          if ((!g_ownbackstore) && (DoesBackingStore(g_screen) != Always))
838            {
839                    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
# Line 894  ui_create_window(void) Line 937  ui_create_window(void)
937          if (g_gc == NULL)          if (g_gc == NULL)
938                  g_gc = XCreateGC(g_display, g_wnd, 0, NULL);                  g_gc = XCreateGC(g_display, g_wnd, 0, NULL);
939    
940          if ((g_ownbackstore) && (g_backstore == NULL))          if ((g_ownbackstore) && (g_backstore == 0))
941          {          {
942                  g_backstore = XCreatePixmap(g_display, g_wnd, g_width, g_height, g_depth);                  g_backstore = XCreatePixmap(g_display, g_wnd, g_width, g_height, g_depth);
943    
# Line 926  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 974  ui_create_window(void) Line 1022  ui_create_window(void)
1022  }  }
1023    
1024  void  void
1025    ui_resize_window()
1026    {
1027            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)  ui_destroy_window(void)
1047  {  {
1048          if (g_IC != NULL)          if (g_IC != NULL)
# Line 1271  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 : g_x_socket;          int n;
1344          fd_set rfds, wfds;          fd_set rfds, wfds;
1345          struct timeval tv;          struct timeval tv;
1346          BOOL s_timeout = False;          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 1366  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 1405  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 1777  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 1916  ui_draw_text(uint8 font, uint8 flags, in Line 1992  ui_draw_text(uint8 font, uint8 flags, in
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);

Legend:
Removed from v.594  
changed lines
  Added in v.679

  ViewVC Help
Powered by ViewVC 1.1.26