/[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 603 by stargo, Sat Feb 7 18:47:06 2004 UTC revision 709 by jsorg71, Fri Jun 11 22:37:05 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    BOOL g_Unobscured;              /* used for screenblt */
49  static GC g_gc = NULL;  static GC g_gc = NULL;
50  static Visual *g_visual;  static Visual *g_visual;
51  static int g_depth;  static int g_depth;
# Line 55  static HCURSOR g_null_cursor = NULL; Line 58  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 63  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 = 0;  static Pixmap g_backstore = 0;
72    
73  /* Moving in single app mode */  /* Moving in single app mode */
# Line 112  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 168  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 181  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 195  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 232  translate_colour(uint32 colour) Line 230  translate_colour(uint32 colour)
230          return make_colour(pc);          return make_colour(pc);
231  }  }
232    
233    /* indent is confused by UNROLL8 */
234    /* *INDENT-OFF* */
235    
236    /* repeat and unroll, similar to bitmap.c */
237    /* potentialy any of the following translate */
238    /* functions can use repeat but just doing */
239    /* the most common ones */
240    
241    #define UNROLL8(stm) { stm stm stm stm stm stm stm stm }
242    /* 2 byte output repeat */
243    #define REPEAT2(stm) \
244    { \
245            while (out <= end - 8 * 2) \
246                    UNROLL8(stm) \
247            while (out < end) \
248                    { stm } \
249    }
250    /* 4 byte output repeat */
251    #define REPEAT4(stm) \
252    { \
253            while (out <= end - 8 * 4) \
254                    UNROLL8(stm) \
255            while (out < end) \
256                    { stm } \
257    }
258    
259  static void  static void
260  translate8to8(uint8 * data, uint8 * out, uint8 * end)  translate8to8(uint8 * data, uint8 * out, uint8 * end)
261  {  {
# Line 244  translate8to16(uint8 * data, uint8 * out Line 268  translate8to16(uint8 * data, uint8 * out
268  {  {
269          uint16 value;          uint16 value;
270    
271          while (out < end)          if (g_arch_match)
272          {          {
273                  value = (uint16) g_colmap[*(data++)];                  REPEAT2
274                    (
275                  if (g_xserver_be)                          *((uint16 *) out) = g_colmap[*(data++)];
276                            out += 2;
277                    )
278            }
279            else if (g_xserver_be)
280            {
281                    while (out < end)
282                  {                  {
283                            value = (uint16) g_colmap[*(data++)];
284                          *(out++) = value >> 8;                          *(out++) = value >> 8;
285                          *(out++) = value;                          *(out++) = value;
286                  }                  }
287                  else          }
288            else
289            {
290                    while (out < end)
291                  {                  {
292                            value = (uint16) g_colmap[*(data++)];
293                          *(out++) = value;                          *(out++) = value;
294                          *(out++) = value >> 8;                          *(out++) = value >> 8;
295                  }                  }
# Line 267  translate8to24(uint8 * data, uint8 * out Line 302  translate8to24(uint8 * data, uint8 * out
302  {  {
303          uint32 value;          uint32 value;
304    
305          while (out < end)          if (g_xserver_be)
306          {          {
307                  value = g_colmap[*(data++)];                  while (out < end)
   
                 if (g_xserver_be)  
308                  {                  {
309                            value = g_colmap[*(data++)];
310                          *(out++) = value >> 16;                          *(out++) = value >> 16;
311                          *(out++) = value >> 8;                          *(out++) = value >> 8;
312                          *(out++) = value;                          *(out++) = value;
313                  }                  }
314                  else          }
315            else
316            {
317                    while (out < end)
318                  {                  {
319                            value = g_colmap[*(data++)];
320                          *(out++) = value;                          *(out++) = value;
321                          *(out++) = value >> 8;                          *(out++) = value >> 8;
322                          *(out++) = value >> 16;                          *(out++) = value >> 16;
# Line 291  translate8to32(uint8 * data, uint8 * out Line 329  translate8to32(uint8 * data, uint8 * out
329  {  {
330          uint32 value;          uint32 value;
331    
332          while (out < end)          if (g_arch_match)
333          {          {
334                  value = g_colmap[*(data++)];                  REPEAT4
335                    (
336                  if (g_xserver_be)                          *((uint32 *) out) = g_colmap[*(data++)];
337                            out += 4;
338                    )
339            }
340            else if (g_xserver_be)
341            {
342                    while (out < end)
343                  {                  {
344                            value = g_colmap[*(data++)];
345                          *(out++) = value >> 24;                          *(out++) = value >> 24;
346                          *(out++) = value >> 16;                          *(out++) = value >> 16;
347                          *(out++) = value >> 8;                          *(out++) = value >> 8;
348                          *(out++) = value;                          *(out++) = value;
349                  }                  }
350                  else          }
351            else
352            {
353                    while (out < end)
354                  {                  {
355                            value = g_colmap[*(data++)];
356                          *(out++) = value;                          *(out++) = value;
357                          *(out++) = value >> 8;                          *(out++) = value >> 8;
358                          *(out++) = value >> 16;                          *(out++) = value >> 16;
# Line 312  translate8to32(uint8 * data, uint8 * out Line 361  translate8to32(uint8 * data, uint8 * out
361          }          }
362  }  }
363    
364    /* *INDENT-ON* */
365    
366  static void  static void
367  translate15to16(uint16 * data, uint8 * out, uint8 * end)  translate15to16(uint16 * data, uint8 * out, uint8 * end)
368  {  {
# Line 592  translate24to32(uint8 * data, uint8 * ou Line 643  translate24to32(uint8 * data, uint8 * ou
643  static uint8 *  static uint8 *
644  translate_image(int width, int height, uint8 * data)  translate_image(int width, int height, uint8 * data)
645  {  {
646          int size = width * height * g_bpp / 8;          int size;
647          uint8 *out = (uint8 *) xmalloc(size);          uint8 *out;
648          uint8 *end = out + size;          uint8 *end;
649    
650            /* if server and xserver bpp match, */
651            /* and arch(endian) matches, no need to translate */
652            /* just return data */
653            if (g_arch_match)
654            {
655                    if (g_depth == 15 && g_server_bpp == 15)
656                            return data;
657                    if (g_depth == 16 && g_server_bpp == 16)
658                            return data;
659            }
660    
661            size = width * height * (g_bpp / 8);
662            out = (uint8 *) xmalloc(size);
663            end = out + size;
664    
665          switch (g_server_bpp)          switch (g_server_bpp)
666          {          {
# Line 732  ui_init(void) Line 798  ui_init(void)
798                  TrueColorVisual = True;                  TrueColorVisual = True;
799          }          }
800    
801            test = 1;
802            g_host_be = !(BOOL) (*(uint8 *) (&test));
803            g_xserver_be = (ImageByteOrder(g_display) == MSBFirst);
804    
805          if ((g_server_bpp == 8) && ((!TrueColorVisual) || (g_depth <= 8)))          if ((g_server_bpp == 8) && ((!TrueColorVisual) || (g_depth <= 8)))
806          {          {
807                  /* 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 828  ui_init(void)
828                  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);
829                  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);
830                  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);
831    
832                    /* if RGB video and averything is little endian */
833                    if (vi.red_mask > vi.green_mask && vi.green_mask > vi.blue_mask)
834                            if (!g_xserver_be && !g_host_be)
835                                    g_arch_match = True;
836          }          }
837    
838          pfm = XListPixmapFormats(g_display, &i);          pfm = XListPixmapFormats(g_display, &i);
# Line 791  ui_init(void) Line 866  ui_init(void)
866                          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");
867          }          }
868    
869          if (DoesBackingStore(g_screen) != Always)          if ((!g_ownbackstore) && (DoesBackingStore(g_screen) != Always))
870            {
871                    warning("External BackingStore not available, using internal\n");
872                  g_ownbackstore = True;                  g_ownbackstore = True;
873            }
         test = 1;  
         g_host_be = !(BOOL) (*(uint8 *) (&test));  
         g_xserver_be = (ImageByteOrder(g_display) == MSBFirst);  
874    
875          /*          /*
876           * Determine desktop size           * Determine desktop size
# Line 927  ui_create_window(void) Line 1001  ui_create_window(void)
1001                  XFree(sizehints);                  XFree(sizehints);
1002          }          }
1003    
1004            if (g_embed_wnd)
1005            {
1006                    XReparentWindow(g_display, g_wnd, (Window) g_embed_wnd, 0, 0);
1007            }
1008    
1009          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
1010                  VisibilityChangeMask | FocusChangeMask;                  VisibilityChangeMask | FocusChangeMask;
1011    
# Line 958  ui_create_window(void) Line 1037  ui_create_window(void)
1037                  XMaskEvent(g_display, VisibilityChangeMask, &xevent);                  XMaskEvent(g_display, VisibilityChangeMask, &xevent);
1038          }          }
1039          while (xevent.type != VisibilityNotify);          while (xevent.type != VisibilityNotify);
1040            g_Unobscured = xevent.xvisibility.state == VisibilityUnobscured;
1041    
1042          g_focused = False;          g_focused = False;
1043          g_mouse_in_wnd = False;          g_mouse_in_wnd = False;
# Line 975  ui_create_window(void) Line 1055  ui_create_window(void)
1055  }  }
1056    
1057  void  void
1058    ui_resize_window()
1059    {
1060            XSizeHints *sizehints;
1061            Pixmap bs;
1062    
1063            sizehints = XAllocSizeHints();
1064            if (sizehints)
1065            {
1066                    sizehints->flags = PMinSize | PMaxSize;
1067                    sizehints->min_width = sizehints->max_width = g_width;
1068                    sizehints->min_height = sizehints->max_height = g_height;
1069                    XSetWMNormalHints(g_display, g_wnd, sizehints);
1070                    XFree(sizehints);
1071            }
1072    
1073            if (!(g_fullscreen || g_embed_wnd))
1074            {
1075                    XResizeWindow(g_display, g_wnd, g_width, g_height);
1076            }
1077    
1078            /* create new backstore pixmap */
1079            if (g_backstore != 0)
1080            {
1081                    bs = XCreatePixmap(g_display, g_wnd, g_width, g_height, g_depth);
1082                    XSetForeground(g_display, g_gc, BlackPixelOfScreen(g_screen));
1083                    XFillRectangle(g_display, bs, g_gc, 0, 0, g_width, g_height);
1084                    XCopyArea(g_display, g_backstore, bs, g_gc, 0, 0, g_width, g_height, 0, 0);
1085                    XFreePixmap(g_display, g_backstore);
1086                    g_backstore = bs;
1087            }
1088    }
1089    
1090    void
1091  ui_destroy_window(void)  ui_destroy_window(void)
1092  {  {
1093          if (g_IC != NULL)          if (g_IC != NULL)
# Line 1035  xwin_process_events(void) Line 1148  xwin_process_events(void)
1148    
1149                  switch (xevent.type)                  switch (xevent.type)
1150                  {                  {
1151                            case VisibilityNotify:
1152                                    g_Unobscured = xevent.xvisibility.state == VisibilityUnobscured;
1153                                    break;
1154                          case ClientMessage:                          case ClientMessage:
1155                                  /* the window manager told us to quit */                                  /* the window manager told us to quit */
1156                                  if ((xevent.xclient.message_type == g_protocol_atom)                                  if ((xevent.xclient.message_type == g_protocol_atom)
# Line 1272  xwin_process_events(void) Line 1388  xwin_process_events(void)
1388  int  int
1389  ui_select(int rdp_socket)  ui_select(int rdp_socket)
1390  {  {
1391          int n = (rdp_socket > g_x_socket) ? rdp_socket : g_x_socket;          int n;
1392          fd_set rfds, wfds;          fd_set rfds, wfds;
1393          struct timeval tv;          struct timeval tv;
1394          BOOL s_timeout = False;          BOOL s_timeout = False;
1395    
1396          while (True)          while (True)
1397          {          {
1398                    n = (rdp_socket > g_x_socket) ? rdp_socket : g_x_socket;
1399                  /* Process any events already waiting */                  /* Process any events already waiting */
1400                  if (!xwin_process_events())                  if (!xwin_process_events())
1401                          /* User quit */                          /* User quit */
# Line 1367  ui_create_bitmap(int width, int height, Line 1484  ui_create_bitmap(int width, int height,
1484          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);
1485    
1486          XFree(image);          XFree(image);
1487          if (!g_owncolmap)          if (tdata != data)
1488                  xfree(tdata);                  xfree(tdata);
1489          return (HBITMAP) bitmap;          return (HBITMAP) bitmap;
1490  }  }
# Line 1406  ui_paint_bitmap(int x, int y, int cx, in Line 1523  ui_paint_bitmap(int x, int y, int cx, in
1523          }          }
1524    
1525          XFree(image);          XFree(image);
1526          if (!g_owncolmap)          if (tdata != data)
1527                  xfree(tdata);                  xfree(tdata);
1528  }  }
1529    
# Line 1730  ui_patblt(uint8 opcode, Line 1847  ui_patblt(uint8 opcode,
1847          {          {
1848                  case 0: /* Solid */                  case 0: /* Solid */
1849                          SET_FOREGROUND(fgcolour);                          SET_FOREGROUND(fgcolour);
1850                          FILL_RECTANGLE(x, y, cx, cy);                          FILL_RECTANGLE_BACKSTORE(x, y, cx, cy);
1851                          break;                          break;
1852    
1853                  case 2: /* Hatch */                  case 2: /* Hatch */
# Line 1741  ui_patblt(uint8 opcode, Line 1858  ui_patblt(uint8 opcode,
1858                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);
1859                          XSetStipple(g_display, g_gc, fill);                          XSetStipple(g_display, g_gc, fill);
1860                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);
1861                          FILL_RECTANGLE(x, y, cx, cy);                          FILL_RECTANGLE_BACKSTORE(x, y, cx, cy);
1862                          XSetFillStyle(g_display, g_gc, FillSolid);                          XSetFillStyle(g_display, g_gc, FillSolid);
1863                          XSetTSOrigin(g_display, g_gc, 0, 0);                          XSetTSOrigin(g_display, g_gc, 0, 0);
1864                          ui_destroy_glyph((HGLYPH) fill);                          ui_destroy_glyph((HGLYPH) fill);
# Line 1751  ui_patblt(uint8 opcode, Line 1868  ui_patblt(uint8 opcode,
1868                          for (i = 0; i != 8; i++)                          for (i = 0; i != 8; i++)
1869                                  ipattern[7 - i] = brush->pattern[i];                                  ipattern[7 - i] = brush->pattern[i];
1870                          fill = (Pixmap) ui_create_glyph(8, 8, ipattern);                          fill = (Pixmap) ui_create_glyph(8, 8, ipattern);
   
1871                          SET_FOREGROUND(bgcolour);                          SET_FOREGROUND(bgcolour);
1872                          SET_BACKGROUND(fgcolour);                          SET_BACKGROUND(fgcolour);
1873                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);
1874                          XSetStipple(g_display, g_gc, fill);                          XSetStipple(g_display, g_gc, fill);
1875                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);
1876                            FILL_RECTANGLE_BACKSTORE(x, y, cx, cy);
                         FILL_RECTANGLE(x, y, cx, cy);  
   
1877                          XSetFillStyle(g_display, g_gc, FillSolid);                          XSetFillStyle(g_display, g_gc, FillSolid);
1878                          XSetTSOrigin(g_display, g_gc, 0, 0);                          XSetTSOrigin(g_display, g_gc, 0, 0);
1879                          ui_destroy_glyph((HGLYPH) fill);                          ui_destroy_glyph((HGLYPH) fill);
# Line 1770  ui_patblt(uint8 opcode, Line 1884  ui_patblt(uint8 opcode,
1884          }          }
1885    
1886          RESET_FUNCTION(opcode);          RESET_FUNCTION(opcode);
1887    
1888            if (g_ownbackstore)
1889                    XCopyArea(g_display, g_backstore, g_wnd, g_gc, x, y, cx, cy, x, y);
1890  }  }
1891    
1892  void  void
# Line 1778  ui_screenblt(uint8 opcode, Line 1895  ui_screenblt(uint8 opcode,
1895               /* src */ int srcx, int srcy)               /* src */ int srcx, int srcy)
1896  {  {
1897          SET_FUNCTION(opcode);          SET_FUNCTION(opcode);
         XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);  
1898          if (g_ownbackstore)          if (g_ownbackstore)
1899                  XCopyArea(g_display, g_backstore, g_backstore, g_gc, srcx, srcy, cx, cy, x, y);          {
1900                    if (g_Unobscured)
1901                    {
1902                            XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);
1903                            XCopyArea(g_display, g_backstore, g_backstore, g_gc, srcx, srcy, cx, cy, x,
1904                                      y);
1905                    }
1906                    else
1907                    {
1908                            XCopyArea(g_display, g_backstore, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);
1909                            XCopyArea(g_display, g_backstore, g_backstore, g_gc, srcx, srcy, cx, cy, x,
1910                                      y);
1911                    }
1912            }
1913            else
1914            {
1915                    XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);
1916            }
1917          RESET_FUNCTION(opcode);          RESET_FUNCTION(opcode);
1918  }  }
1919    
# Line 1917  ui_draw_text(uint8 font, uint8 flags, in Line 2050  ui_draw_text(uint8 font, uint8 flags, in
2050    
2051          SET_FOREGROUND(bgcolour);          SET_FOREGROUND(bgcolour);
2052    
2053            /* Sometimes, the boxcx value is something really large, like
2054               32691. This makes XCopyArea fail with Xvnc. The code below
2055               is a quick fix. */
2056            if (boxx + boxcx > g_width)
2057                    boxcx = g_width - boxx;
2058    
2059          if (boxcx > 1)          if (boxcx > 1)
2060          {          {
2061                  FILL_RECTANGLE_BACKSTORE(boxx, boxy, boxcx, boxcy);                  FILL_RECTANGLE_BACKSTORE(boxx, boxy, boxcx, boxcy);

Legend:
Removed from v.603  
changed lines
  Added in v.709

  ViewVC Help
Powered by ViewVC 1.1.26