/[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 487 by astrand, Mon Oct 13 12:34:15 2003 UTC revision 524 by matthewc, Wed Oct 29 06:29:05 2003 UTC
# Line 49  static XIM g_IM; Line 49  static XIM g_IM;
49  static XIC g_IC;  static XIC g_IC;
50  static XModifierKeymap *g_mod_map;  static XModifierKeymap *g_mod_map;
51  static Cursor g_current_cursor;  static Cursor g_current_cursor;
52    static HCURSOR g_null_cursor;
53  static Atom g_protocol_atom, g_kill_atom;  static Atom g_protocol_atom, g_kill_atom;
54  static BOOL g_focused;  static BOOL g_focused;
55  static BOOL g_mouse_in_wnd;  static BOOL g_mouse_in_wnd;
# Line 56  static BOOL g_mouse_in_wnd; Line 57  static BOOL g_mouse_in_wnd;
57  /* endianness */  /* endianness */
58  static BOOL g_host_be;  static BOOL g_host_be;
59  static BOOL g_xserver_be;  static BOOL g_xserver_be;
60    static BOOL g_xserver_bgr;
61    
62  /* software backing store */  /* software backing store */
63  static BOOL g_ownbackstore;  static BOOL g_ownbackstore;
# Line 69  static int g_move_y_offset = 0; Line 71  static int g_move_y_offset = 0;
71  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
72  extern int g_dsp_fd;  extern int g_dsp_fd;
73  extern BOOL g_dsp_busy;  extern BOOL g_dsp_busy;
74    extern BOOL g_rdpsnd;
75  #endif  #endif
76    
77  /* MWM decorations */  /* MWM decorations */
# Line 200  make_colour16(PixelColour pc) Line 203  make_colour16(PixelColour pc)
203          pc.red = (pc.red * 0x1f) / 0xff;          pc.red = (pc.red * 0x1f) / 0xff;
204          pc.green = (pc.green * 0x3f) / 0xff;          pc.green = (pc.green * 0x3f) / 0xff;
205          pc.blue = (pc.blue * 0x1f) / 0xff;          pc.blue = (pc.blue * 0x1f) / 0xff;
206          return (pc.red << 11) | (pc.green << 5) | pc.blue;          if (g_xserver_bgr)
207                    return (pc.blue << 11) | (pc.green << 5) | pc.red;
208            else
209                    return (pc.red << 11) | (pc.green << 5) | pc.blue;
210                    
211  }  }
212    
213  static uint32  static uint32
214  make_colour24(PixelColour pc)  make_colour24(PixelColour pc)
215  {  {
216          if (g_xserver_be)          if (g_xserver_bgr)
217          {                  return (pc.blue << 16) | (pc.green << 8) | pc.red;
                 return pc.red | (pc.green << 8) | (pc.blue << 16);  
         }  
218          else          else
         {  
219                  return (pc.red << 16) | (pc.green << 8) | pc.blue;                  return (pc.red << 16) | (pc.green << 8) | pc.blue;
         }  
220  }  }
221    
222  static uint32  static uint32
223  make_colour32(PixelColour pc)  make_colour32(PixelColour pc)
224  {  {
225          if (g_xserver_be)          if (g_xserver_bgr)
226          {                  return (pc.blue << 16) | (pc.green << 8) | pc.red;
                 return pc.red | (pc.green << 8) | (pc.blue << 16);  
         }  
227          else          else
         {  
228                  return (pc.red << 16) | (pc.green << 8) | pc.blue;                  return (pc.red << 16) | (pc.green << 8) | pc.blue;
         }  
229  }  }
230    
231  #define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); }  #define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); }
# Line 273  translate_colour(uint32 colour) Line 272  translate_colour(uint32 colour)
272                                          colour = make_colour16(split_colour24(colour));                                          colour = make_colour16(split_colour24(colour));
273                                          break;                                          break;
274                                  case 24:                                  case 24:
275                                            colour = make_colour24(split_colour24(colour));
276                                          break;                                          break;
277                                  case 32:                                  case 32:
278                                          colour = make_colour32(split_colour24(colour));                                          colour = make_colour32(split_colour24(colour));
# Line 291  translate8to8(uint8 * data, uint8 * out, Line 291  translate8to8(uint8 * data, uint8 * out,
291  }  }
292    
293  static void  static void
294  translate8to16(uint8 * data, uint16 * out, uint16 * end)  translate8to16(uint8 * data, uint8 * out, uint8 * end)
295  {  {
296            uint16 value;
297    
298          while (out < end)          while (out < end)
299                  *(out++) = (uint16) g_colmap[*(data++)];          {
300                    value = (uint16) g_colmap[*(data++)];
301                    
302                    if (g_xserver_be)
303                    {
304                            *(out++) = value >> 8;
305                            *(out++) = value;
306                    }
307                    else
308                    {
309                            *(out++) = value;
310                            *(out++) = value >> 8;
311                    }
312            }
313  }  }
314    
315  /* little endian - conversion happens when colourmap is built */  /* little endian - conversion happens when colourmap is built */
# Line 306  translate8to24(uint8 * data, uint8 * out Line 321  translate8to24(uint8 * data, uint8 * out
321          while (out < end)          while (out < end)
322          {          {
323                  value = g_colmap[*(data++)];                  value = g_colmap[*(data++)];
324                  *(out++) = value;                  
325                  *(out++) = value >> 8;                  if (g_xserver_be)
326                  *(out++) = value >> 16;                  {
327                            *(out++) = value >> 16;
328                            *(out++) = value >> 8;
329                            *(out++) = value;
330                    }
331                    else
332                    {
333                            *(out++) = value;
334                            *(out++) = value >> 8;
335                            *(out++) = value >> 16;
336                    }
337          }          }
338  }  }
339    
340  static void  static void
341  translate8to32(uint8 * data, uint32 * out, uint32 * end)  translate8to32(uint8 * data, uint8 * out, uint8 * end)
342  {  {
343            uint32 value;
344    
345          while (out < end)          while (out < end)
346                  *(out++) = g_colmap[*(data++)];          {
347                    value = g_colmap[*(data++)];
348    
349                    if (g_xserver_be)
350                    {
351                            *(out++) = value >> 24;
352                            *(out++) = value >> 16;
353                            *(out++) = value >> 8;
354                            *(out++) = value;
355                    }
356                    else
357                    {
358                            *(out++) = value;
359                            *(out++) = value >> 8;
360                            *(out++) = value >> 16;
361                            *(out++) = value >> 24;
362                    }
363            }
364  }  }
365    
366  /* todo the remaining translate function might need some big endian check ?? */  /* todo the remaining translate function might need some big endian check ?? */
# Line 333  translate15to16(uint16 * data, uint8 * o Line 377  translate15to16(uint16 * data, uint8 * o
377    
378                  if (g_host_be)                  if (g_host_be)
379                  {                  {
380                          BSWAP16(pixel)                          BSWAP16(pixel);
381                  }                  }
382    
383                  value = make_colour16(split_colour15(pixel));                  value = make_colour16(split_colour15(pixel));
# Line 363  translate15to24(uint16 * data, uint8 * o Line 407  translate15to24(uint16 * data, uint8 * o
407    
408                  if (g_host_be)                  if (g_host_be)
409                  {                  {
410                          BSWAP16(pixel)                          BSWAP16(pixel);
411                  }                  }
412    
413                  value = make_colour24(split_colour15(pixel));                  value = make_colour24(split_colour15(pixel));
# Line 457  translate16to24(uint16 * data, uint8 * o Line 501  translate16to24(uint16 * data, uint8 * o
501    
502                  if (g_host_be)                  if (g_host_be)
503                  {                  {
504                          BSWAP16(pixel)                          BSWAP16(pixel);
505                  }                  }
506    
507                  value = make_colour24(split_colour16(pixel));                  value = make_colour24(split_colour16(pixel));
# Line 489  translate16to32(uint16 * data, uint8 * o Line 533  translate16to32(uint16 * data, uint8 * o
533    
534                  if (g_host_be)                  if (g_host_be)
535                  {                  {
536                          BSWAP16(pixel)                  BSWAP16(pixel)}
                 }  
537    
538                  value = make_colour32(split_colour16(pixel));                  value = make_colour32(split_colour16(pixel));
539    
# Line 500  translate16to32(uint16 * data, uint8 * o Line 543  translate16to32(uint16 * data, uint8 * o
543                          *(out++) = value >> 16;                          *(out++) = value >> 16;
544                          *(out++) = value >> 8;                          *(out++) = value >> 8;
545                          *(out++) = value;                          *(out++) = value;
546                  }                  }
547                  else                  else
548                  {                  {
549                          *(out++) = value;                          *(out++) = value;
550                          *(out++) = value >> 8;                          *(out++) = value >> 8;
551                          *(out++) = value >> 16;                          *(out++) = value >> 16;
552                          *(out++) = value >> 24;                          *(out++) = value >> 24;
553                  }                  }
554          }          }
555  }  }
556    
557  static void  static void
# Line 627  translate_image(int width, int height, u Line 670  translate_image(int width, int height, u
670                                          translate8to8(data, out, end);                                          translate8to8(data, out, end);
671                                          break;                                          break;
672                                  case 16:                                  case 16:
673                                          translate8to16(data, (uint16 *) out, (uint16 *) end);                                          translate8to16(data, out, end);
674                                          break;                                          break;
675                                  case 24:                                  case 24:
676                                          translate8to24(data, out, end);                                          translate8to24(data, out, end);
677                                          break;                                          break;
678                                  case 32:                                  case 32:
679                                          translate8to32(data, (uint32 *) out, (uint32 *) end);                                          translate8to32(data, out, end);
680                                          break;                                          break;
681                          }                          }
682                          break;                          break;
# Line 707  ui_init(void) Line 750  ui_init(void)
750                  return False;                  return False;
751          }          }
752    
753          if (g_owncolmap != True)          /* private colour map code only works for 8 bpp */
754            if (g_owncolmap && (g_bpp > 8))
755                    g_owncolmap = False;
756    
757            if (!g_owncolmap)
758          {          {
759                  g_xcolmap = DefaultColormapOfScreen(g_screen);                  g_xcolmap = DefaultColormapOfScreen(g_screen);
760                  if (g_depth <= 8)                  if (g_depth <= 8)
# Line 722  ui_init(void) Line 769  ui_init(void)
769          test = 1;          test = 1;
770          g_host_be = !(BOOL) (*(uint8 *) (&test));          g_host_be = !(BOOL) (*(uint8 *) (&test));
771          g_xserver_be = (ImageByteOrder(g_display) == MSBFirst);          g_xserver_be = (ImageByteOrder(g_display) == MSBFirst);
772            g_xserver_bgr = (g_visual->blue_mask > g_visual->red_mask);
773    
774          if ((g_width == 0) || (g_height == 0))          /*
775             * Determine desktop size
776             */
777            if (g_width < 0)
778            {
779                    /* Percent of screen */
780                    g_height = HeightOfScreen(g_screen) * (-g_width) / 100;
781                    g_width = WidthOfScreen(g_screen) * (-g_width) / 100;
782            }
783            else if (g_width == 0)
784          {          {
785                  /* Fetch geometry from _NET_WORKAREA */                  /* Fetch geometry from _NET_WORKAREA */
786                  uint32 x, y, cx, cy;                  uint32 x, y, cx, cy;
# Line 740  ui_init(void) Line 797  ui_init(void)
797                          g_height = 600;                          g_height = 600;
798                  }                  }
799          }          }
800            else if (g_fullscreen)
         if (g_fullscreen)  
801          {          {
802                  g_width = WidthOfScreen(g_screen);                  g_width = WidthOfScreen(g_screen);
803                  g_height = HeightOfScreen(g_screen);                  g_height = HeightOfScreen(g_screen);
# Line 763  ui_init(void) Line 819  ui_init(void)
819    
820          g_mod_map = XGetModifierMapping(g_display);          g_mod_map = XGetModifierMapping(g_display);
821    
822            xkeymap_init();
823    
824          if (g_enable_compose)          if (g_enable_compose)
825                  g_IM = XOpenIM(g_display, NULL, NULL, NULL);                  g_IM = XOpenIM(g_display, NULL, NULL, NULL);
826    
         xkeymap_init();  
827          xclip_init();          xclip_init();
828    
829          /* todo take this out when high colour is done */          DEBUG_RDP5(("server bpp %d client bpp %d depth %d\n", g_server_bpp, g_bpp, g_depth));
         printf("server bpp %d client bpp %d depth %d\n", g_server_bpp, g_bpp, g_depth);  
830    
831          return True;          return True;
832  }  }
# Line 791  ui_deinit(void) Line 847  ui_deinit(void)
847          g_display = NULL;          g_display = NULL;
848  }  }
849    
850    #define NULL_POINTER_MASK       "\x80"
851    #define NULL_POINTER_DATA       "\x0\x0\x0"
852            
853  BOOL  BOOL
854  ui_create_window(void)  ui_create_window(void)
855  {  {
# Line 875  ui_create_window(void) Line 934  ui_create_window(void)
934          g_kill_atom = XInternAtom(g_display, "WM_DELETE_WINDOW", True);          g_kill_atom = XInternAtom(g_display, "WM_DELETE_WINDOW", True);
935          XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1);          XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1);
936    
937            /* create invisible 1x1 cursor to be used as null cursor */
938            g_null_cursor = ui_create_cursor(0, 0, 1, 1, NULL_POINTER_MASK, NULL_POINTER_DATA);
939    
940          return True;          return True;
941  }  }
942    
943  void  void
944  ui_destroy_window(void)  ui_destroy_window(void)
945  {  {
946            ui_destroy_cursor(g_null_cursor);
947            
948          if (g_IC != NULL)          if (g_IC != NULL)
949                  XDestroyIC(g_IC);                  XDestroyIC(g_IC);
950    
# Line 1202  ui_select(int rdp_socket) Line 1266  ui_select(int rdp_socket)
1266                  {                  {
1267                          FD_SET(g_dsp_fd, &wfds);                          FD_SET(g_dsp_fd, &wfds);
1268                          n = (g_dsp_fd + 1 > n) ? g_dsp_fd + 1 : n;                          n = (g_dsp_fd + 1 > n) ? g_dsp_fd + 1 : n;
1269                  }                  }
1270  #endif  #endif
1271    
1272                  switch (select(n, &rfds, &wfds, NULL, NULL))                  switch (select(n, &rfds, &wfds, NULL, NULL))
# Line 1236  ui_create_bitmap(int width, int height, Line 1300  ui_create_bitmap(int width, int height,
1300          XImage *image;          XImage *image;
1301          Pixmap bitmap;          Pixmap bitmap;
1302          uint8 *tdata;          uint8 *tdata;
1303            int bitmap_pad;
1304    
1305            if (g_server_bpp == 8)
1306            {
1307                    bitmap_pad = 8;
1308            }
1309            else
1310            {
1311                    bitmap_pad = g_bpp;
1312    
1313                    if (g_bpp == 24)
1314                            bitmap_pad = 32;
1315            }
1316    
1317          tdata = (g_owncolmap ? data : translate_image(width, height, data));          tdata = (g_owncolmap ? data : translate_image(width, height, data));
1318          bitmap = XCreatePixmap(g_display, g_wnd, width, height, g_depth);          bitmap = XCreatePixmap(g_display, g_wnd, width, height, g_depth);
1319          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,
1320                               (char *) tdata, width, height, g_server_bpp == 8 ? 8 : g_bpp, 0);                               (char *) tdata, width, height, bitmap_pad, 0);
1321    
1322          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);
1323    
# Line 1255  ui_paint_bitmap(int x, int y, int cx, in Line 1332  ui_paint_bitmap(int x, int y, int cx, in
1332  {  {
1333          XImage *image;          XImage *image;
1334          uint8 *tdata;          uint8 *tdata;
1335            int bitmap_pad;
1336    
1337            if (g_server_bpp == 8)
1338            {
1339                    bitmap_pad = 8;
1340            }
1341            else
1342            {
1343                    bitmap_pad = g_bpp;
1344    
1345                    if (g_bpp == 24)
1346                            bitmap_pad = 32;
1347            }
1348    
1349          tdata = (g_owncolmap ? data : translate_image(width, height, data));          tdata = (g_owncolmap ? data : translate_image(width, height, data));
1350          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,
1351                               (char *) tdata, width, height, g_server_bpp == 8 ? 8 : g_bpp, 0);                               (char *) tdata, width, height, bitmap_pad, 0);
1352    
1353          if (g_ownbackstore)          if (g_ownbackstore)
1354          {          {
# Line 1396  ui_destroy_cursor(HCURSOR cursor) Line 1487  ui_destroy_cursor(HCURSOR cursor)
1487          XFreeCursor(g_display, (Cursor) cursor);          XFreeCursor(g_display, (Cursor) cursor);
1488  }  }
1489    
1490    void
1491    ui_set_null_cursor(void)
1492    {
1493            ui_set_cursor(g_null_cursor);
1494    }
1495    
1496  #define MAKE_XCOLOR(xc,c) \  #define MAKE_XCOLOR(xc,c) \
1497                  (xc)->red   = ((c)->red   << 8) | (c)->red; \                  (xc)->red   = ((c)->red   << 8) | (c)->red; \
1498                  (xc)->green = ((c)->green << 8) | (c)->green; \                  (xc)->green = ((c)->green << 8) | (c)->green; \

Legend:
Removed from v.487  
changed lines
  Added in v.524

  ViewVC Help
Powered by ViewVC 1.1.26