/[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 31 by matty, Sat Sep 15 03:16:05 2001 UTC revision 33 by matty, Sat Sep 15 12:34:34 2001 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 <time.h>  #include <time.h>
24    #include <errno.h>
25  #include "rdesktop.h"  #include "rdesktop.h"
26    
27  extern int width;  extern int width;
# Line 29  extern BOOL sendmotion; Line 30  extern BOOL sendmotion;
30  extern BOOL fullscreen;  extern BOOL fullscreen;
31    
32  static Display *display;  static Display *display;
33    static int x_socket;
34  static Window wnd;  static Window wnd;
35  static GC gc;  static GC gc;
36  static Visual *visual;  static Visual *visual;
37  static int depth;  static int depth;
38  static int bpp;  static int bpp;
39    
40    /* endianness */
41    static BOOL host_be;
42    static BOOL xserver_be;
43    
44    /* software backing store */
45  static BOOL ownbackstore;  static BOOL ownbackstore;
46  static Pixmap backstore;  static Pixmap backstore;
47    
# Line 45  static Pixmap backstore; Line 52  static Pixmap backstore;
52                  XFillRectangle(display, backstore, gc, x, y, cx, cy); \                  XFillRectangle(display, backstore, gc, x, y, cx, cy); \
53  }  }
54    
55    /* colour maps */
56  static BOOL owncolmap;  static BOOL owncolmap;
57  static Colormap xcolmap;  static Colormap xcolmap;
58  static uint32 white;  static uint32 white;
59  static uint32 *colmap;  static uint32 *colmap;
60    
61  #define TRANSLATE(col)          ( owncolmap ? col : colmap[col] )  #define TRANSLATE(col)          ( owncolmap ? col : translate_colour(colmap[col]) )
62  #define SET_FOREGROUND(col)     XSetForeground(display, gc, TRANSLATE(col));  #define SET_FOREGROUND(col)     XSetForeground(display, gc, TRANSLATE(col));
63  #define SET_BACKGROUND(col)     XSetBackground(display, gc, TRANSLATE(col));  #define SET_BACKGROUND(col)     XSetBackground(display, gc, TRANSLATE(col));
64    
# Line 90  translate16(uint8 *data, uint16 *out, ui Line 98  translate16(uint8 *data, uint16 *out, ui
98                  *(out++) = (uint16)colmap[*(data++)];                  *(out++) = (uint16)colmap[*(data++)];
99  }  }
100    
101  /* XXX endianness */  /* little endian - conversion happens when colourmap is built */
102  static void  static void
103  translate24(uint8 *data, uint8 *out, uint8 *end)  translate24(uint8 *data, uint8 *out, uint8 *end)
104  {  {
# Line 113  translate32(uint8 *data, uint32 *out, ui Line 121  translate32(uint8 *data, uint32 *out, ui
121  }  }
122    
123  static uint8 *  static uint8 *
124  translate(int width, int height, uint8 *data)  translate_image(int width, int height, uint8 *data)
125  {  {
126          int size = width * height * bpp/8;          int size = width * height * bpp/8;
127          uint8 *out = xmalloc(size);          uint8 *out = xmalloc(size);
# Line 141  translate(int width, int height, uint8 * Line 149  translate(int width, int height, uint8 *
149          return out;          return out;
150  }  }
151    
152  #define L_ENDIAN  #define BSWAP16(x) x = (((x & 0xff) << 8) | (x >> 8));
153  int screen_msbfirst = 0;  #define BSWAP24(x) x = (((x & 0xff) << 16) | (x >> 16) | ((x >> 8) & 0xff00));
154    #define BSWAP32(x) x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \
155                       x = (x << 16) | (x >> 16);
156    
157    static uint32
158    translate_colour(uint32 colour)
159    {
160            switch (bpp)
161            {
162                    case 16:
163                            if (host_be != xserver_be)
164                                    BSWAP16(colour);
165                            break;
166    
167                    case 24:
168                            if (xserver_be)
169                                    BSWAP24(colour);
170                            break;
171    
172                    case 32:
173                            if (host_be != xserver_be)
174                                    BSWAP32(colour);
175                            break;
176            }
177    
178            return colour;
179    }
180    
181  BOOL  BOOL
182  ui_create_window(char *title)  ui_create_window(char *title)
# Line 154  ui_create_window(char *title) Line 187  ui_create_window(char *title)
187          unsigned long input_mask;          unsigned long input_mask;
188          XPixmapFormatValues *pfm;          XPixmapFormatValues *pfm;
189          Screen *screen;          Screen *screen;
190            uint16 test;
191          int i;          int i;
192    
   
193          display = XOpenDisplay(NULL);          display = XOpenDisplay(NULL);
194          if (display == NULL)          if (display == NULL)
195          {          {
# Line 164  ui_create_window(char *title) Line 197  ui_create_window(char *title)
197                  return False;                  return False;
198          }          }
199    
200            x_socket = ConnectionNumber(display);
201          screen = DefaultScreenOfDisplay(display);          screen = DefaultScreenOfDisplay(display);
202          visual = DefaultVisualOfScreen(screen);          visual = DefaultVisualOfScreen(screen);
203          depth = DefaultDepthOfScreen(screen);          depth = DefaultDepthOfScreen(screen);
# Line 196  ui_create_window(char *title) Line 230  ui_create_window(char *title)
230          else          else
231                  xcolmap = DefaultColormapOfScreen(screen);                  xcolmap = DefaultColormapOfScreen(screen);
232    
233            test = 1;
234            host_be = !(BOOL)(*(uint8 *)(&test));
235            xserver_be = (ImageByteOrder(display) == MSBFirst);
236    
237          white = WhitePixelOfScreen(screen);          white = WhitePixelOfScreen(screen);
238          attribs.background_pixel = BlackPixelOfScreen(screen);          attribs.background_pixel = BlackPixelOfScreen(screen);
239          attribs.backing_store = DoesBackingStore(screen);          attribs.backing_store = DoesBackingStore(screen);
# Line 343  xwin_translate_mouse(unsigned long butto Line 381  xwin_translate_mouse(unsigned long butto
381          return 0;          return 0;
382  }  }
383    
384  void  static void
385  ui_process_events()  xwin_process_events()
386  {  {
387          XEvent event;          XEvent event;
388          uint8 scancode;          uint8 scancode;
# Line 428  ui_process_events() Line 466  ui_process_events()
466  }  }
467    
468  void  void
469    ui_select(int rdp_socket)
470    {
471            int n = (rdp_socket > x_socket) ? rdp_socket+1 : x_socket+1;
472            fd_set rfds;
473    
474            XFlush(display);
475    
476            FD_ZERO(&rfds);
477    
478            while (True)
479            {
480                    FD_ZERO(&rfds);
481                    FD_SET(rdp_socket, &rfds);
482                    FD_SET(x_socket, &rfds);
483    
484                    switch (select(n, &rfds, NULL, NULL, NULL))
485                    {
486                            case -1:
487                                    error("select: %s\n", strerror(errno));
488    
489                            case 0:
490                                    continue;
491                    }
492    
493                    if (FD_ISSET(x_socket, &rfds))
494                            xwin_process_events();
495    
496                    if (FD_ISSET(rdp_socket, &rfds))
497                            return;
498            }
499    }
500    
501    void
502  ui_move_pointer(int x, int y)  ui_move_pointer(int x, int y)
503  {  {
504          XWarpPointer(display, wnd, wnd, 0, 0, 0, 0, x, y);          XWarpPointer(display, wnd, wnd, 0, 0, 0, 0, x, y);
# Line 440  ui_create_bitmap(int width, int height, Line 511  ui_create_bitmap(int width, int height,
511          Pixmap bitmap;          Pixmap bitmap;
512          uint8 *tdata;          uint8 *tdata;
513    
514          tdata = (owncolmap ? data : translate(width, height, data));          tdata = (owncolmap ? data : translate_image(width, height, data));
515          bitmap = XCreatePixmap(display, wnd, width, height, depth);          bitmap = XCreatePixmap(display, wnd, width, height, depth);
516          image = XCreateImage(display, visual, depth, ZPixmap,          image = XCreateImage(display, visual, depth, ZPixmap,
517                               0, tdata, width, height, 8, 0);                               0, tdata, width, height, 8, 0);
# Line 460  ui_paint_bitmap(int x, int y, int cx, in Line 531  ui_paint_bitmap(int x, int y, int cx, in
531          XImage *image;          XImage *image;
532          uint8 *tdata;          uint8 *tdata;
533    
534          tdata = (owncolmap ? data : translate(width, height, data));          tdata = (owncolmap ? data : translate_image(width, height, data));
535          image = XCreateImage(display, visual, depth, ZPixmap,          image = XCreateImage(display, visual, depth, ZPixmap,
536                               0, tdata, width, height, 8, 0);                               0, tdata, width, height, 8, 0);
537    
# Line 635  ui_create_colourmap(COLOURMAP *colours) Line 706  ui_create_colourmap(COLOURMAP *colours)
706          {          {
707                  uint32 *map = xmalloc(sizeof(*colmap) * ncolours);                  uint32 *map = xmalloc(sizeof(*colmap) * ncolours);
708                  XColor xentry;                  XColor xentry;
709                    uint32 colour;
710    
711                  for (i = 0; i < ncolours; i++)                  for (i = 0; i < ncolours; i++)
712                  {                  {
# Line 642  ui_create_colourmap(COLOURMAP *colours) Line 714  ui_create_colourmap(COLOURMAP *colours)
714                          MAKE_XCOLOR(&xentry, entry);                          MAKE_XCOLOR(&xentry, entry);
715    
716                          if (XAllocColor(display, xcolmap, &xentry) != 0)                          if (XAllocColor(display, xcolmap, &xentry) != 0)
717                                  map[i] = xentry.pixel;                                  colour = translate_colour(xentry.pixel);
718                          else                          else
719                                  map[i] = white;                                  colour = translate_colour(white);
720    
721                            /* byte swap here to make translate_image faster */
722                            map[i] = translate_colour(colour);
723                  }                  }
724    
725                  return map;                  return map;

Legend:
Removed from v.31  
changed lines
  Added in v.33

  ViewVC Help
Powered by ViewVC 1.1.26