/[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 564 by jsorg71, Fri Jan 16 23:15:33 2004 UTC revision 620 by astrand, Wed Mar 3 10:46:35 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 42  static int g_x_socket; Line 44  static int g_x_socket;
44  static Screen *g_screen;  static Screen *g_screen;
45  Window g_wnd;  Window g_wnd;
46  BOOL g_enable_compose = False;  BOOL g_enable_compose = False;
47  static GC g_gc;  static GC g_gc = NULL;
48  static Visual *g_visual;  static Visual *g_visual;
49  static int g_depth;  static int g_depth;
50  static int g_bpp;  static int g_bpp;
# Line 50  static XIM g_IM; Line 52  static XIM g_IM;
52  static XIC g_IC;  static XIC g_IC;
53  static XModifierKeymap *g_mod_map;  static XModifierKeymap *g_mod_map;
54  static Cursor g_current_cursor;  static Cursor g_current_cursor;
55  static HCURSOR g_null_cursor;  static HCURSOR g_null_cursor = NULL;
56  static Atom g_protocol_atom, g_kill_atom;  static Atom g_protocol_atom, g_kill_atom;
57  static BOOL g_focused;  static BOOL g_focused;
58  static BOOL g_mouse_in_wnd;  static BOOL g_mouse_in_wnd;
# Line 62  static int g_red_shift_r, g_blue_shift_r Line 64  static int g_red_shift_r, g_blue_shift_r
64  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;
65    
66  /* software backing store */  /* software backing store */
67  static BOOL g_ownbackstore;  BOOL g_ownbackstore = True;     /* We can't rely on external BackingStore */
68  static Pixmap g_backstore;  static Pixmap g_backstore = 0;
69    
70  /* Moving in single app mode */  /* Moving in single app mode */
71  static BOOL g_moving_wnd;  static BOOL g_moving_wnd;
# Line 167  static PixelColour Line 169  static PixelColour
169  split_colour15(uint32 colour)  split_colour15(uint32 colour)
170  {  {
171          PixelColour rv;          PixelColour rv;
172          rv.red = (colour & 0x7c00) >> 10;          rv.red = (colour & 0x7c00) >> 7;
173          rv.red = (rv.red * 0xff) / 0x1f;          rv.green = (colour & 0x03e0) >> 2;
174          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;  
175          return rv;          return rv;
176  }  }
177    
# Line 180  static PixelColour Line 179  static PixelColour
179  split_colour16(uint32 colour)  split_colour16(uint32 colour)
180  {  {
181          PixelColour rv;          PixelColour rv;
182          rv.red = (colour & 0xf800) >> 11;          rv.red = (colour & 0xf800) >> 8;
183          rv.red = (rv.red * 0xff) / 0x1f;          rv.green = (colour & 0x07e0) >> 3;
184          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;  
185          return rv;          return rv;
186  }  }
187    
# Line 194  split_colour24(uint32 colour) Line 190  split_colour24(uint32 colour)
190  {  {
191          PixelColour rv;          PixelColour rv;
192          rv.blue = (colour & 0xff0000) >> 16;          rv.blue = (colour & 0xff0000) >> 16;
193          rv.green = (colour & 0xff00) >> 8;          rv.green = (colour & 0x00ff00) >> 8;
194          rv.red = (colour & 0xff);          rv.red = (colour & 0x0000ff);
195          return rv;          return rv;
196  }  }
197    
# Line 699  ui_init(void) Line 695  ui_init(void)
695          XVisualInfo vi;          XVisualInfo vi;
696          XPixmapFormatValues *pfm;          XPixmapFormatValues *pfm;
697          uint16 test;          uint16 test;
698          int i, screen_num;          int i, screen_num, nvisuals;
699            XVisualInfo *vmatches = NULL;
700            XVisualInfo template;
701            Bool TrueColorVisual = False;
702    
703          g_display = XOpenDisplay(NULL);          g_display = XOpenDisplay(NULL);
704          if (g_display == NULL)          if (g_display == NULL)
# Line 713  ui_init(void) Line 712  ui_init(void)
712          g_screen = ScreenOfDisplay(g_display, screen_num);          g_screen = ScreenOfDisplay(g_display, screen_num);
713          g_depth = DefaultDepthOfScreen(g_screen);          g_depth = DefaultDepthOfScreen(g_screen);
714    
715          if (g_server_bpp == 8)          /* Search for best TrueColor depth */
716            template.class = TrueColor;
717            vmatches = XGetVisualInfo(g_display, VisualClassMask, &template, &nvisuals);
718    
719            nvisuals--;
720            while (nvisuals >= 0)
721            {
722                    if ((vmatches + nvisuals)->depth > g_depth)
723                    {
724                            g_depth = (vmatches + nvisuals)->depth;
725                    }
726                    nvisuals--;
727                    TrueColorVisual = True;
728            }
729    
730            if ((g_server_bpp == 8) && ((!TrueColorVisual) || (g_depth <= 8)))
731          {          {
732                  /* we use a colourmap, so any visual should do */                  /* we use a colourmap, so the default visual should do */
733                  g_visual = DefaultVisualOfScreen(g_screen);                  g_visual = DefaultVisualOfScreen(g_screen);
734                    g_depth = DefaultDepthOfScreen(g_screen);
735    
736                    /* Do not allocate colours on a TrueColor visual */
737                    if (g_visual->class == TrueColor)
738                    {
739                            g_owncolmap = False;
740                    }
741          }          }
742          else          else
743          {          {
# Line 758  ui_init(void) Line 779  ui_init(void)
779    
780          if (!g_owncolmap)          if (!g_owncolmap)
781          {          {
782                  g_xcolmap = DefaultColormapOfScreen(g_screen);                  g_xcolmap =
783                            XCreateColormap(g_display, RootWindowOfScreen(g_screen), g_visual,
784                                            AllocNone);
785                  if (g_depth <= 8)                  if (g_depth <= 8)
786                          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");
787          }          }
788    
789          g_gc = XCreateGC(g_display, RootWindowOfScreen(g_screen), 0, NULL);          if ((!g_ownbackstore) && (DoesBackingStore(g_screen) != Always))
790            {
791          if (DoesBackingStore(g_screen) != Always)                  warning("External BackingStore not available, using internal\n");
792                  g_ownbackstore = True;                  g_ownbackstore = True;
793            }
794    
795          test = 1;          test = 1;
796          g_host_be = !(BOOL) (*(uint8 *) (&test));          g_host_be = !(BOOL) (*(uint8 *) (&test));
# Line 807  ui_init(void) Line 831  ui_init(void)
831          /* make sure width is a multiple of 4 */          /* make sure width is a multiple of 4 */
832          g_width = (g_width + 3) & ~3;          g_width = (g_width + 3) & ~3;
833    
         if (g_ownbackstore)  
         {  
                 g_backstore =  
                         XCreatePixmap(g_display, RootWindowOfScreen(g_screen), g_width, g_height,  
                                       g_depth);  
   
                 /* clear to prevent rubbish being exposed at startup */  
                 XSetForeground(g_display, g_gc, BlackPixelOfScreen(g_screen));  
                 XFillRectangle(g_display, g_backstore, g_gc, 0, 0, g_width, g_height);  
         }  
   
834          g_mod_map = XGetModifierMapping(g_display);          g_mod_map = XGetModifierMapping(g_display);
835    
836          xkeymap_init();          xkeymap_init();
# Line 838  ui_deinit(void) Line 851  ui_deinit(void)
851          if (g_IM != NULL)          if (g_IM != NULL)
852                  XCloseIM(g_IM);                  XCloseIM(g_IM);
853    
854            if (g_null_cursor != NULL)
855                    ui_destroy_cursor(g_null_cursor);
856    
857          XFreeModifiermap(g_mod_map);          XFreeModifiermap(g_mod_map);
858    
859          if (g_ownbackstore)          if (g_ownbackstore)
# Line 864  ui_create_window(void) Line 880  ui_create_window(void)
880          wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height;          wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height;
881    
882          attribs.background_pixel = BlackPixelOfScreen(g_screen);          attribs.background_pixel = BlackPixelOfScreen(g_screen);
883            attribs.border_pixel = WhitePixelOfScreen(g_screen);
884          attribs.backing_store = g_ownbackstore ? NotUseful : Always;          attribs.backing_store = g_ownbackstore ? NotUseful : Always;
885          attribs.override_redirect = g_fullscreen;          attribs.override_redirect = g_fullscreen;
886            attribs.colormap = g_xcolmap;
887    
888          g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), 0, 0, wndwidth, wndheight,          g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), 0, 0, wndwidth, wndheight,
889                                0, CopyFromParent, InputOutput, CopyFromParent,                                0, g_depth, InputOutput, g_visual,
890                                CWBackPixel | CWBackingStore | CWOverrideRedirect, &attribs);                                CWBackPixel | CWBackingStore | CWOverrideRedirect |
891                                  CWColormap | CWBorderPixel, &attribs);
892    
893            if (g_gc == NULL)
894                    g_gc = XCreateGC(g_display, g_wnd, 0, NULL);
895    
896            if ((g_ownbackstore) && (g_backstore == 0))
897            {
898                    g_backstore = XCreatePixmap(g_display, g_wnd, g_width, g_height, g_depth);
899    
900                    /* clear to prevent rubbish being exposed at startup */
901                    XSetForeground(g_display, g_gc, BlackPixelOfScreen(g_screen));
902                    XFillRectangle(g_display, g_backstore, g_gc, 0, 0, g_width, g_height);
903            }
904    
905          XStoreName(g_display, g_wnd, g_title);          XStoreName(g_display, g_wnd, g_title);
906    
# Line 935  ui_create_window(void) Line 966  ui_create_window(void)
966          XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1);          XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1);
967    
968          /* create invisible 1x1 cursor to be used as null cursor */          /* create invisible 1x1 cursor to be used as null cursor */
969          g_null_cursor = ui_create_cursor(0, 0, 1, 1, null_pointer_mask, null_pointer_data);          if (g_null_cursor == NULL)
970                    g_null_cursor = ui_create_cursor(0, 0, 1, 1, null_pointer_mask, null_pointer_data);
971    
972          return True;          return True;
973  }  }
# Line 1238  xwin_process_events(void) Line 1270  xwin_process_events(void)
1270  int  int
1271  ui_select(int rdp_socket)  ui_select(int rdp_socket)
1272  {  {
1273          int n = (rdp_socket > g_x_socket) ? rdp_socket + 1 : g_x_socket + 1;          int n;
1274          fd_set rfds, wfds;          fd_set rfds, wfds;
1275            struct timeval tv;
1276            BOOL s_timeout = False;
1277    
1278          while (True)          while (True)
1279          {          {
1280                    n = (rdp_socket > g_x_socket) ? rdp_socket : g_x_socket;
1281                  /* Process any events already waiting */                  /* Process any events already waiting */
1282                  if (!xwin_process_events())                  if (!xwin_process_events())
1283                          /* User quit */                          /* User quit */
# Line 1258  ui_select(int rdp_socket) Line 1293  ui_select(int rdp_socket)
1293                  if (g_dsp_busy)                  if (g_dsp_busy)
1294                  {                  {
1295                          FD_SET(g_dsp_fd, &wfds);                          FD_SET(g_dsp_fd, &wfds);
1296                          n = (g_dsp_fd + 1 > n) ? g_dsp_fd + 1 : n;                          n = (g_dsp_fd > n) ? g_dsp_fd : n;
1297                  }                  }
1298  #endif  #endif
1299                    /* default timeout */
1300                    tv.tv_sec = 60;
1301                    tv.tv_usec = 0;
1302    
1303                  switch (select(n, &rfds, &wfds, NULL, NULL))                  /* add redirection handles */
1304                    rdpdr_add_fds(&n, &rfds, &wfds, &tv, &s_timeout);
1305    
1306                    n++;
1307    
1308                    switch (select(n, &rfds, &wfds, NULL, &tv))
1309                  {                  {
1310                          case -1:                          case -1:
1311                                  error("select: %s\n", strerror(errno));                                  error("select: %s\n", strerror(errno));
1312    
1313                          case 0:                          case 0:
1314                                    /* TODO: if tv.tv_sec just times out
1315                                     * we will segfault.
1316                                     * FIXME:
1317                                     */
1318                                    //s_timeout = True;
1319                                    //rdpdr_check_fds(&rfds, &wfds, (BOOL) True);
1320                                  continue;                                  continue;
1321                  }                  }
1322    
1323                    rdpdr_check_fds(&rfds, &wfds, (BOOL) False);
1324    
1325                  if (FD_ISSET(rdp_socket, &rfds))                  if (FD_ISSET(rdp_socket, &rfds))
1326                          return 1;                          return 1;
1327    
# Line 1726  ui_screenblt(uint8 opcode, Line 1777  ui_screenblt(uint8 opcode,
1777               /* src */ int srcx, int srcy)               /* src */ int srcx, int srcy)
1778  {  {
1779          SET_FUNCTION(opcode);          SET_FUNCTION(opcode);
         XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);  
1780          if (g_ownbackstore)          if (g_ownbackstore)
1781            {
1782                    XCopyArea(g_display, g_backstore, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);
1783                  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);
1784            }
1785            else
1786            {
1787                    XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);
1788            }
1789          RESET_FUNCTION(opcode);          RESET_FUNCTION(opcode);
1790  }  }
1791    
# Line 1865  ui_draw_text(uint8 font, uint8 flags, in Line 1922  ui_draw_text(uint8 font, uint8 flags, in
1922    
1923          SET_FOREGROUND(bgcolour);          SET_FOREGROUND(bgcolour);
1924    
1925            /* Sometimes, the boxcx value is something really large, like
1926               32691. This makes XCopyArea fail with Xvnc. The code below
1927               is a quick fix. */
1928            if (boxx + boxcx > g_width)
1929                    boxcx = g_width - boxx;
1930    
1931          if (boxcx > 1)          if (boxcx > 1)
1932          {          {
1933                  FILL_RECTANGLE_BACKSTORE(boxx, boxy, boxcx, boxcy);                  FILL_RECTANGLE_BACKSTORE(boxx, boxy, boxcx, boxcy);

Legend:
Removed from v.564  
changed lines
  Added in v.620

  ViewVC Help
Powered by ViewVC 1.1.26