/[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 566 by stargo, Mon Jan 19 23:45:26 2004 UTC revision 636 by stargo, Sat Mar 13 12:08:18 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 41  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    uint32 g_embed_wnd;
47  BOOL g_enable_compose = False;  BOOL g_enable_compose = False;
48  static GC g_gc;  static GC g_gc = NULL;
 static BOOL g_gc_initialized = False;  
49  static Visual *g_visual;  static Visual *g_visual;
50  static int g_depth;  static int g_depth;
51  static int g_bpp;  static int g_bpp;
# Line 51  static XIM g_IM; Line 53  static XIM g_IM;
53  static XIC g_IC;  static XIC g_IC;
54  static XModifierKeymap *g_mod_map;  static XModifierKeymap *g_mod_map;
55  static Cursor g_current_cursor;  static Cursor g_current_cursor;
56  static HCURSOR g_null_cursor;  static HCURSOR g_null_cursor = NULL;
57  static Atom g_protocol_atom, g_kill_atom;  static Atom g_protocol_atom, g_kill_atom;
58  static BOOL g_focused;  static BOOL g_focused;
59  static BOOL g_mouse_in_wnd;  static BOOL g_mouse_in_wnd;
# Line 63  static int g_red_shift_r, g_blue_shift_r Line 65  static int g_red_shift_r, g_blue_shift_r
65  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;
66    
67  /* software backing store */  /* software backing store */
68  static BOOL g_ownbackstore;  BOOL g_ownbackstore = True;     /* We can't rely on external BackingStore */
69  static Pixmap g_backstore;  static Pixmap g_backstore = 0;
 static BOOL g_backstore_initialized = False;  
70    
71  /* Moving in single app mode */  /* Moving in single app mode */
72  static BOOL g_moving_wnd;  static BOOL g_moving_wnd;
# Line 169  static PixelColour Line 170  static PixelColour
170  split_colour15(uint32 colour)  split_colour15(uint32 colour)
171  {  {
172          PixelColour rv;          PixelColour rv;
173          rv.red = (colour & 0x7c00) >> 10;          rv.red = (colour & 0x7c00) >> 7;
174          rv.red = (rv.red * 0xff) / 0x1f;          rv.green = (colour & 0x03e0) >> 2;
175          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;  
176          return rv;          return rv;
177  }  }
178    
# Line 182  static PixelColour Line 180  static PixelColour
180  split_colour16(uint32 colour)  split_colour16(uint32 colour)
181  {  {
182          PixelColour rv;          PixelColour rv;
183          rv.red = (colour & 0xf800) >> 11;          rv.red = (colour & 0xf800) >> 8;
184          rv.red = (rv.red * 0xff) / 0x1f;          rv.green = (colour & 0x07e0) >> 3;
185          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;  
186          return rv;          return rv;
187  }  }
188    
# Line 196  split_colour24(uint32 colour) Line 191  split_colour24(uint32 colour)
191  {  {
192          PixelColour rv;          PixelColour rv;
193          rv.blue = (colour & 0xff0000) >> 16;          rv.blue = (colour & 0xff0000) >> 16;
194          rv.green = (colour & 0xff00) >> 8;          rv.green = (colour & 0x00ff00) >> 8;
195          rv.red = (colour & 0xff);          rv.red = (colour & 0x0000ff);
196          return rv;          return rv;
197  }  }
198    
# Line 733  ui_init(void) Line 728  ui_init(void)
728                  TrueColorVisual = True;                  TrueColorVisual = True;
729          }          }
730    
731          if ((g_server_bpp == 8) && ((! TrueColorVisual) || (g_depth <= 8)))          if ((g_server_bpp == 8) && ((!TrueColorVisual) || (g_depth <= 8)))
732          {          {
733                  /* we use a colourmap, so the default visual should do */                  /* we use a colourmap, so the default visual should do */
734                  g_visual = DefaultVisualOfScreen(g_screen);                  g_visual = DefaultVisualOfScreen(g_screen);
# Line 785  ui_init(void) Line 780  ui_init(void)
780    
781          if (!g_owncolmap)          if (!g_owncolmap)
782          {          {
783                  g_xcolmap = XCreateColormap(g_display,RootWindowOfScreen(g_screen),g_visual,AllocNone);                  g_xcolmap =
784                            XCreateColormap(g_display, RootWindowOfScreen(g_screen), g_visual,
785                                            AllocNone);
786                  if (g_depth <= 8)                  if (g_depth <= 8)
787                          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");
788          }          }
789    
790          if (DoesBackingStore(g_screen) != Always)          if ((!g_ownbackstore) && (DoesBackingStore(g_screen) != Always))
791            {
792                    warning("External BackingStore not available, using internal\n");
793                  g_ownbackstore = True;                  g_ownbackstore = True;
794            }
795    
796          test = 1;          test = 1;
797          g_host_be = !(BOOL) (*(uint8 *) (&test));          g_host_be = !(BOOL) (*(uint8 *) (&test));
# Line 852  ui_deinit(void) Line 852  ui_deinit(void)
852          if (g_IM != NULL)          if (g_IM != NULL)
853                  XCloseIM(g_IM);                  XCloseIM(g_IM);
854    
855            if (g_null_cursor != NULL)
856                    ui_destroy_cursor(g_null_cursor);
857    
858          XFreeModifiermap(g_mod_map);          XFreeModifiermap(g_mod_map);
859    
860          if (g_ownbackstore)          if (g_ownbackstore)
# Line 888  ui_create_window(void) Line 891  ui_create_window(void)
891                                CWBackPixel | CWBackingStore | CWOverrideRedirect |                                CWBackPixel | CWBackingStore | CWOverrideRedirect |
892                                CWColormap | CWBorderPixel, &attribs);                                CWColormap | CWBorderPixel, &attribs);
893    
894          if ( ! g_gc_initialized )          if (g_gc == NULL)
         {  
895                  g_gc = XCreateGC(g_display, g_wnd, 0, NULL);                  g_gc = XCreateGC(g_display, g_wnd, 0, NULL);
                 g_gc_initialized = True;  
         }  
896    
897          if ((g_ownbackstore) && (! g_backstore_initialized))          if ((g_ownbackstore) && (g_backstore == 0))
898          {          {
899                  g_backstore =                  g_backstore = XCreatePixmap(g_display, g_wnd, g_width, g_height, g_depth);
                         XCreatePixmap(g_display, g_wnd, g_width, g_height,  
                                       g_depth);  
900    
901                  /* clear to prevent rubbish being exposed at startup */                  /* clear to prevent rubbish being exposed at startup */
902                  XSetForeground(g_display, g_gc, BlackPixelOfScreen(g_screen));                  XSetForeground(g_display, g_gc, BlackPixelOfScreen(g_screen));
903                  XFillRectangle(g_display, g_backstore, g_gc, 0, 0, g_width, g_height);                  XFillRectangle(g_display, g_backstore, g_gc, 0, 0, g_width, g_height);
                 g_backstore_initialized = True;  
904          }          }
905    
906          XStoreName(g_display, g_wnd, g_title);          XStoreName(g_display, g_wnd, g_title);
# Line 929  ui_create_window(void) Line 926  ui_create_window(void)
926                  XFree(sizehints);                  XFree(sizehints);
927          }          }
928    
929            if ( g_embed_wnd )
930            {
931                    XReparentWindow(g_display, g_wnd, (Window)g_embed_wnd, 0, 0);
932            }
933    
934          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
935                  VisibilityChangeMask | FocusChangeMask;                  VisibilityChangeMask | FocusChangeMask;
936    
# Line 970  ui_create_window(void) Line 972  ui_create_window(void)
972          XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1);          XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1);
973    
974          /* create invisible 1x1 cursor to be used as null cursor */          /* create invisible 1x1 cursor to be used as null cursor */
975          g_null_cursor = ui_create_cursor(0, 0, 1, 1, null_pointer_mask, null_pointer_data);          if (g_null_cursor == NULL)
976                    g_null_cursor = ui_create_cursor(0, 0, 1, 1, null_pointer_mask, null_pointer_data);
977    
978          return True;          return True;
979  }  }
# Line 1273  xwin_process_events(void) Line 1276  xwin_process_events(void)
1276  int  int
1277  ui_select(int rdp_socket)  ui_select(int rdp_socket)
1278  {  {
1279          int n = (rdp_socket > g_x_socket) ? rdp_socket + 1 : g_x_socket + 1;          int n;
1280          fd_set rfds, wfds;          fd_set rfds, wfds;
1281            struct timeval tv;
1282            BOOL s_timeout = False;
1283    
1284          while (True)          while (True)
1285          {          {
1286                    n = (rdp_socket > g_x_socket) ? rdp_socket : g_x_socket;
1287                  /* Process any events already waiting */                  /* Process any events already waiting */
1288                  if (!xwin_process_events())                  if (!xwin_process_events())
1289                          /* User quit */                          /* User quit */
# Line 1293  ui_select(int rdp_socket) Line 1299  ui_select(int rdp_socket)
1299                  if (g_dsp_busy)                  if (g_dsp_busy)
1300                  {                  {
1301                          FD_SET(g_dsp_fd, &wfds);                          FD_SET(g_dsp_fd, &wfds);
1302                          n = (g_dsp_fd + 1 > n) ? g_dsp_fd + 1 : n;                          n = (g_dsp_fd > n) ? g_dsp_fd : n;
1303                  }                  }
1304  #endif  #endif
1305                    /* default timeout */
1306                    tv.tv_sec = 60;
1307                    tv.tv_usec = 0;
1308    
1309                    /* add redirection handles */
1310                    rdpdr_add_fds(&n, &rfds, &wfds, &tv, &s_timeout);
1311    
1312                    n++;
1313    
1314                  switch (select(n, &rfds, &wfds, NULL, NULL))                  switch (select(n, &rfds, &wfds, NULL, &tv))
1315                  {                  {
1316                          case -1:                          case -1:
1317                                  error("select: %s\n", strerror(errno));                                  error("select: %s\n", strerror(errno));
1318    
1319                          case 0:                          case 0:
1320                                    /* TODO: if tv.tv_sec just times out
1321                                     * we will segfault.
1322                                     * FIXME:
1323                                     */
1324                                    //s_timeout = True;
1325                                    //rdpdr_check_fds(&rfds, &wfds, (BOOL) True);
1326                                  continue;                                  continue;
1327                  }                  }
1328    
1329                    rdpdr_check_fds(&rfds, &wfds, (BOOL) False);
1330    
1331                  if (FD_ISSET(rdp_socket, &rfds))                  if (FD_ISSET(rdp_socket, &rfds))
1332                          return 1;                          return 1;
1333    
# Line 1761  ui_screenblt(uint8 opcode, Line 1783  ui_screenblt(uint8 opcode,
1783               /* src */ int srcx, int srcy)               /* src */ int srcx, int srcy)
1784  {  {
1785          SET_FUNCTION(opcode);          SET_FUNCTION(opcode);
         XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);  
1786          if (g_ownbackstore)          if (g_ownbackstore)
1787            {
1788                    XCopyArea(g_display, g_backstore, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);
1789                  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);
1790            }
1791            else
1792            {
1793                    XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);
1794            }
1795          RESET_FUNCTION(opcode);          RESET_FUNCTION(opcode);
1796  }  }
1797    
# Line 1900  ui_draw_text(uint8 font, uint8 flags, in Line 1928  ui_draw_text(uint8 font, uint8 flags, in
1928    
1929          SET_FOREGROUND(bgcolour);          SET_FOREGROUND(bgcolour);
1930    
1931            /* Sometimes, the boxcx value is something really large, like
1932               32691. This makes XCopyArea fail with Xvnc. The code below
1933               is a quick fix. */
1934            if (boxx + boxcx > g_width)
1935                    boxcx = g_width - boxx;
1936    
1937          if (boxcx > 1)          if (boxcx > 1)
1938          {          {
1939                  FILL_RECTANGLE_BACKSTORE(boxx, boxy, boxcx, boxcy);                  FILL_RECTANGLE_BACKSTORE(boxx, boxy, boxcx, boxcy);

Legend:
Removed from v.566  
changed lines
  Added in v.636

  ViewVC Help
Powered by ViewVC 1.1.26