/[rdesktop]/sourceforge.net/branches/seamlessrdp-branch/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/branches/seamlessrdp-branch/rdesktop/xwin.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 619 by astrand, Wed Mar 3 10:41:53 2004 UTC revision 688 by jsorg71, Fri Apr 30 19:14:15 2004 UTC
# Line 43  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 56  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 64  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  BOOL g_ownbackstore = True;     /* We can't rely on external BackingStore */  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 113  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 227  translate_colour(uint32 colour) Line 230  translate_colour(uint32 colour)
230          return make_colour(pc);          return make_colour(pc);
231  }  }
232    
233    #define UNROLL8(stm) { stm stm stm stm stm stm stm stm }
234    #define REPEAT(stm) \
235    { \
236            while (out <= end - 8 * 4) \
237                    UNROLL8(stm) \
238            while (out < end) \
239                    { stm } \
240    }
241    
242  static void  static void
243  translate8to8(uint8 * data, uint8 * out, uint8 * end)  translate8to8(uint8 * data, uint8 * out, uint8 * end)
244  {  {
# Line 239  translate8to16(uint8 * data, uint8 * out Line 251  translate8to16(uint8 * data, uint8 * out
251  {  {
252          uint16 value;          uint16 value;
253    
254          while (out < end)          if (g_arch_match)
255                    REPEAT(*(((uint16*)out)++) = g_colmap[*(data++)];)
256            else if (g_xserver_be)
257          {          {
258                  value = (uint16) g_colmap[*(data++)];                  while (out < end)
   
                 if (g_xserver_be)  
259                  {                  {
260                            value = (uint16) g_colmap[*(data++)];
261                          *(out++) = value >> 8;                          *(out++) = value >> 8;
262                          *(out++) = value;                          *(out++) = value;
263                  }                  }
264                  else          }
265            else
266            {
267                    while (out < end)
268                  {                  {
269                            value = (uint16) g_colmap[*(data++)];
270                          *(out++) = value;                          *(out++) = value;
271                          *(out++) = value >> 8;                          *(out++) = value >> 8;
272                  }                  }
# Line 262  translate8to24(uint8 * data, uint8 * out Line 279  translate8to24(uint8 * data, uint8 * out
279  {  {
280          uint32 value;          uint32 value;
281    
282          while (out < end)          if (g_xserver_be)
283          {          {
284                  value = g_colmap[*(data++)];                  while (out < end)
   
                 if (g_xserver_be)  
285                  {                  {
286                            value = g_colmap[*(data++)];
287                          *(out++) = value >> 16;                          *(out++) = value >> 16;
288                          *(out++) = value >> 8;                          *(out++) = value >> 8;
289                          *(out++) = value;                          *(out++) = value;
290                  }                  }
291                  else          }
292            else
293            {
294                    while (out < end)
295                  {                  {
296                            value = g_colmap[*(data++)];
297                          *(out++) = value;                          *(out++) = value;
298                          *(out++) = value >> 8;                          *(out++) = value >> 8;
299                          *(out++) = value >> 16;                          *(out++) = value >> 16;
# Line 286  translate8to32(uint8 * data, uint8 * out Line 306  translate8to32(uint8 * data, uint8 * out
306  {  {
307          uint32 value;          uint32 value;
308    
309          while (out < end)          if (g_arch_match)
310                    REPEAT(*(((uint32*)out)++) = g_colmap[*(data++)];)
311            else if (g_xserver_be)
312          {          {
313                  value = g_colmap[*(data++)];                  while (out < end)
   
                 if (g_xserver_be)  
314                  {                  {
315                            value = g_colmap[*(data++)];
316                          *(out++) = value >> 24;                          *(out++) = value >> 24;
317                          *(out++) = value >> 16;                          *(out++) = value >> 16;
318                          *(out++) = value >> 8;                          *(out++) = value >> 8;
319                          *(out++) = value;                          *(out++) = value;
320                  }                  }
321                  else          }
322            else
323            {
324                    while (out < end)
325                  {                  {
326                            value = g_colmap[*(data++)];
327                          *(out++) = value;                          *(out++) = value;
328                          *(out++) = value >> 8;                          *(out++) = value >> 8;
329                          *(out++) = value >> 16;                          *(out++) = value >> 16;
# Line 587  translate24to32(uint8 * data, uint8 * ou Line 612  translate24to32(uint8 * data, uint8 * ou
612  static uint8 *  static uint8 *
613  translate_image(int width, int height, uint8 * data)  translate_image(int width, int height, uint8 * data)
614  {  {
615          int size = width * height * g_bpp / 8;          int size;
616          uint8 *out = (uint8 *) xmalloc(size);          uint8 *out;
617          uint8 *end = out + size;          uint8 *end;
618    
619            /* if server and xserver bpp match, */
620            /* and arch(endian) matches, no need to translate */
621            /* just return data */
622            if (g_arch_match)
623            {
624                    if (g_depth == 15 && g_server_bpp == 15)
625                            return data;
626                    if (g_depth == 16 && g_server_bpp == 16)
627                            return data;
628            }
629    
630            size = width * height * (g_bpp / 8);
631            out = (uint8 *) xmalloc(size);
632            end = out + size;
633    
634          switch (g_server_bpp)          switch (g_server_bpp)
635          {          {
# Line 727  ui_init(void) Line 767  ui_init(void)
767                  TrueColorVisual = True;                  TrueColorVisual = True;
768          }          }
769    
770            test = 1;
771            g_host_be = !(BOOL) (*(uint8 *) (&test));
772            g_xserver_be = (ImageByteOrder(g_display) == MSBFirst);
773    
774          if ((g_server_bpp == 8) && ((!TrueColorVisual) || (g_depth <= 8)))          if ((g_server_bpp == 8) && ((!TrueColorVisual) || (g_depth <= 8)))
775          {          {
776                  /* we use a colourmap, so the default visual should do */                  /* we use a colourmap, so the default visual should do */
# Line 753  ui_init(void) Line 797  ui_init(void)
797                  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);
798                  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);
799                  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);
800    
801                    /* if RGB video and averything is little endian */
802                    if (vi.red_mask > vi.green_mask && vi.green_mask > vi.blue_mask)
803                            if (!g_xserver_be && !g_host_be)
804                                    g_arch_match = True;
805          }          }
806    
807          pfm = XListPixmapFormats(g_display, &i);          pfm = XListPixmapFormats(g_display, &i);
# Line 792  ui_init(void) Line 841  ui_init(void)
841                  g_ownbackstore = True;                  g_ownbackstore = True;
842          }          }
843    
         test = 1;  
         g_host_be = !(BOOL) (*(uint8 *) (&test));  
         g_xserver_be = (ImageByteOrder(g_display) == MSBFirst);  
   
844          /*          /*
845           * Determine desktop size           * Determine desktop size
846           */           */
# Line 925  ui_create_window(void) Line 970  ui_create_window(void)
970                  XFree(sizehints);                  XFree(sizehints);
971          }          }
972    
973            if (g_embed_wnd)
974            {
975                    XReparentWindow(g_display, g_wnd, (Window) g_embed_wnd, 0, 0);
976            }
977    
978          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
979                  VisibilityChangeMask | FocusChangeMask;                  VisibilityChangeMask | FocusChangeMask;
980    
# Line 956  ui_create_window(void) Line 1006  ui_create_window(void)
1006                  XMaskEvent(g_display, VisibilityChangeMask, &xevent);                  XMaskEvent(g_display, VisibilityChangeMask, &xevent);
1007          }          }
1008          while (xevent.type != VisibilityNotify);          while (xevent.type != VisibilityNotify);
1009            g_Unobscured = xevent.xvisibility.state == VisibilityUnobscured;
1010    
1011          g_focused = False;          g_focused = False;
1012          g_mouse_in_wnd = False;          g_mouse_in_wnd = False;
# Line 973  ui_create_window(void) Line 1024  ui_create_window(void)
1024  }  }
1025    
1026  void  void
1027    ui_resize_window()
1028    {
1029            XSizeHints *sizehints;
1030    
1031            sizehints = XAllocSizeHints();
1032            if (sizehints)
1033            {
1034                    sizehints->flags = PMinSize | PMaxSize;
1035                    sizehints->min_width = sizehints->max_width = g_width;
1036                    sizehints->min_height = sizehints->max_height = g_height;
1037                    XSetWMNormalHints(g_display, g_wnd, sizehints);
1038                    XFree(sizehints);
1039            }
1040    
1041            if (!(g_fullscreen || g_embed_wnd))
1042            {
1043                    XResizeWindow(g_display, g_wnd, g_width, g_height);
1044            }
1045    }
1046    
1047    void
1048  ui_destroy_window(void)  ui_destroy_window(void)
1049  {  {
1050          if (g_IC != NULL)          if (g_IC != NULL)
# Line 1033  xwin_process_events(void) Line 1105  xwin_process_events(void)
1105    
1106                  switch (xevent.type)                  switch (xevent.type)
1107                  {                  {
1108                            case VisibilityNotify:
1109                                    g_Unobscured = xevent.xvisibility.state == VisibilityUnobscured;
1110                                    break;
1111                          case ClientMessage:                          case ClientMessage:
1112                                  /* the window manager told us to quit */                                  /* the window manager told us to quit */
1113                                  if ((xevent.xclient.message_type == g_protocol_atom)                                  if ((xevent.xclient.message_type == g_protocol_atom)
# Line 1366  ui_create_bitmap(int width, int height, Line 1441  ui_create_bitmap(int width, int height,
1441          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);
1442    
1443          XFree(image);          XFree(image);
1444          if (!g_owncolmap)          if (tdata != data)
1445                  xfree(tdata);                  xfree(tdata);
1446          return (HBITMAP) bitmap;          return (HBITMAP) bitmap;
1447  }  }
# Line 1405  ui_paint_bitmap(int x, int y, int cx, in Line 1480  ui_paint_bitmap(int x, int y, int cx, in
1480          }          }
1481    
1482          XFree(image);          XFree(image);
1483          if (!g_owncolmap)          if (tdata != data)
1484                  xfree(tdata);                  xfree(tdata);
1485  }  }
1486    
# Line 1729  ui_patblt(uint8 opcode, Line 1804  ui_patblt(uint8 opcode,
1804          {          {
1805                  case 0: /* Solid */                  case 0: /* Solid */
1806                          SET_FOREGROUND(fgcolour);                          SET_FOREGROUND(fgcolour);
1807                          FILL_RECTANGLE(x, y, cx, cy);                          FILL_RECTANGLE_BACKSTORE(x, y, cx, cy);
1808                          break;                          break;
1809    
1810                  case 2: /* Hatch */                  case 2: /* Hatch */
# Line 1740  ui_patblt(uint8 opcode, Line 1815  ui_patblt(uint8 opcode,
1815                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);
1816                          XSetStipple(g_display, g_gc, fill);                          XSetStipple(g_display, g_gc, fill);
1817                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);
1818                          FILL_RECTANGLE(x, y, cx, cy);                          FILL_RECTANGLE_BACKSTORE(x, y, cx, cy);
1819                          XSetFillStyle(g_display, g_gc, FillSolid);                          XSetFillStyle(g_display, g_gc, FillSolid);
1820                          XSetTSOrigin(g_display, g_gc, 0, 0);                          XSetTSOrigin(g_display, g_gc, 0, 0);
1821                          ui_destroy_glyph((HGLYPH) fill);                          ui_destroy_glyph((HGLYPH) fill);
# Line 1750  ui_patblt(uint8 opcode, Line 1825  ui_patblt(uint8 opcode,
1825                          for (i = 0; i != 8; i++)                          for (i = 0; i != 8; i++)
1826                                  ipattern[7 - i] = brush->pattern[i];                                  ipattern[7 - i] = brush->pattern[i];
1827                          fill = (Pixmap) ui_create_glyph(8, 8, ipattern);                          fill = (Pixmap) ui_create_glyph(8, 8, ipattern);
   
1828                          SET_FOREGROUND(bgcolour);                          SET_FOREGROUND(bgcolour);
1829                          SET_BACKGROUND(fgcolour);                          SET_BACKGROUND(fgcolour);
1830                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);
1831                          XSetStipple(g_display, g_gc, fill);                          XSetStipple(g_display, g_gc, fill);
1832                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);
1833                            FILL_RECTANGLE_BACKSTORE(x, y, cx, cy);
                         FILL_RECTANGLE(x, y, cx, cy);  
   
1834                          XSetFillStyle(g_display, g_gc, FillSolid);                          XSetFillStyle(g_display, g_gc, FillSolid);
1835                          XSetTSOrigin(g_display, g_gc, 0, 0);                          XSetTSOrigin(g_display, g_gc, 0, 0);
1836                          ui_destroy_glyph((HGLYPH) fill);                          ui_destroy_glyph((HGLYPH) fill);
# Line 1769  ui_patblt(uint8 opcode, Line 1841  ui_patblt(uint8 opcode,
1841          }          }
1842    
1843          RESET_FUNCTION(opcode);          RESET_FUNCTION(opcode);
1844    
1845            if (g_ownbackstore)
1846                    XCopyArea(g_display, g_backstore, g_wnd, g_gc, x, y, cx, cy, x, y);
1847  }  }
1848    
1849  void  void
# Line 1779  ui_screenblt(uint8 opcode, Line 1854  ui_screenblt(uint8 opcode,
1854          SET_FUNCTION(opcode);          SET_FUNCTION(opcode);
1855          if (g_ownbackstore)          if (g_ownbackstore)
1856          {          {
1857                  XCopyArea(g_display, g_backstore, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);                  if (g_Unobscured)
1858                  XCopyArea(g_display, g_backstore, g_backstore, g_gc, srcx, srcy, cx, cy, x, y);                  {
1859                            XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);
1860                            XCopyArea(g_display, g_backstore, g_backstore, g_gc, srcx, srcy, cx, cy, x, y);
1861                    }
1862                    else
1863                    {
1864                            XCopyArea(g_display, g_backstore, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);
1865                            XCopyArea(g_display, g_backstore, g_backstore, g_gc, srcx, srcy, cx, cy, x, y);
1866                    }
1867          }          }
1868          else          else
1869          {          {
# Line 1922  ui_draw_text(uint8 font, uint8 flags, in Line 2005  ui_draw_text(uint8 font, uint8 flags, in
2005    
2006          SET_FOREGROUND(bgcolour);          SET_FOREGROUND(bgcolour);
2007    
2008            /* Sometimes, the boxcx value is something really large, like
2009               32691. This makes XCopyArea fail with Xvnc. The code below
2010               is a quick fix. */
2011            if (boxx + boxcx > g_width)
2012                    boxcx = g_width - boxx;
2013    
2014          if (boxcx > 1)          if (boxcx > 1)
2015          {          {
2016                  FILL_RECTANGLE_BACKSTORE(boxx, boxy, boxcx, boxcy);                  FILL_RECTANGLE_BACKSTORE(boxx, boxy, boxcx, boxcy);

Legend:
Removed from v.619  
changed lines
  Added in v.688

  ViewVC Help
Powered by ViewVC 1.1.26