/[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 603 by stargo, Sat Feb 7 18:47:06 2004 UTC
# Line 23  Line 23 
23  #include <unistd.h>  #include <unistd.h>
24  #include <time.h>  #include <time.h>
25  #include <errno.h>  #include <errno.h>
26    #include <strings.h>
27  #include "rdesktop.h"  #include "rdesktop.h"
28  #include "xproto.h"  #include "xproto.h"
29    
# Line 42  static int g_x_socket; Line 43  static int g_x_socket;
43  static Screen *g_screen;  static Screen *g_screen;
44  Window g_wnd;  Window g_wnd;
45  BOOL g_enable_compose = False;  BOOL g_enable_compose = False;
46  static GC g_gc;  static GC g_gc = NULL;
47  static Visual *g_visual;  static Visual *g_visual;
48  static int g_depth;  static int g_depth;
49  static int g_bpp;  static int g_bpp;
# Line 50  static XIM g_IM; Line 51  static XIM g_IM;
51  static XIC g_IC;  static XIC g_IC;
52  static XModifierKeymap *g_mod_map;  static XModifierKeymap *g_mod_map;
53  static Cursor g_current_cursor;  static Cursor g_current_cursor;
54  static HCURSOR g_null_cursor;  static HCURSOR g_null_cursor = NULL;
55  static Atom g_protocol_atom, g_kill_atom;  static Atom g_protocol_atom, g_kill_atom;
56  static BOOL g_focused;  static BOOL g_focused;
57  static BOOL g_mouse_in_wnd;  static BOOL g_mouse_in_wnd;
# Line 63  static int g_red_shift_l, g_blue_shift_l Line 64  static int g_red_shift_l, g_blue_shift_l
64    
65  /* software backing store */  /* software backing store */
66  static BOOL g_ownbackstore;  static BOOL g_ownbackstore;
67  static Pixmap g_backstore;  static Pixmap g_backstore = 0;
68    
69  /* Moving in single app mode */  /* Moving in single app mode */
70  static BOOL g_moving_wnd;  static BOOL g_moving_wnd;
# Line 699  ui_init(void) Line 700  ui_init(void)
700          XVisualInfo vi;          XVisualInfo vi;
701          XPixmapFormatValues *pfm;          XPixmapFormatValues *pfm;
702          uint16 test;          uint16 test;
703          int i, screen_num;          int i, screen_num, nvisuals;
704            XVisualInfo *vmatches = NULL;
705            XVisualInfo template;
706            Bool TrueColorVisual = False;
707    
708          g_display = XOpenDisplay(NULL);          g_display = XOpenDisplay(NULL);
709          if (g_display == NULL)          if (g_display == NULL)
# Line 713  ui_init(void) Line 717  ui_init(void)
717          g_screen = ScreenOfDisplay(g_display, screen_num);          g_screen = ScreenOfDisplay(g_display, screen_num);
718          g_depth = DefaultDepthOfScreen(g_screen);          g_depth = DefaultDepthOfScreen(g_screen);
719    
720          if (g_server_bpp == 8)          /* Search for best TrueColor depth */
721            template.class = TrueColor;
722            vmatches = XGetVisualInfo(g_display, VisualClassMask, &template, &nvisuals);
723    
724            nvisuals--;
725            while (nvisuals >= 0)
726            {
727                    if ((vmatches + nvisuals)->depth > g_depth)
728                    {
729                            g_depth = (vmatches + nvisuals)->depth;
730                    }
731                    nvisuals--;
732                    TrueColorVisual = True;
733            }
734    
735            if ((g_server_bpp == 8) && ((!TrueColorVisual) || (g_depth <= 8)))
736          {          {
737                  /* we use a colourmap, so any visual should do */                  /* we use a colourmap, so the default visual should do */
738                  g_visual = DefaultVisualOfScreen(g_screen);                  g_visual = DefaultVisualOfScreen(g_screen);
739                    g_depth = DefaultDepthOfScreen(g_screen);
740    
741                    /* Do not allocate colours on a TrueColor visual */
742                    if (g_visual->class == TrueColor)
743                    {
744                            g_owncolmap = False;
745                    }
746          }          }
747          else          else
748          {          {
# Line 758  ui_init(void) Line 784  ui_init(void)
784    
785          if (!g_owncolmap)          if (!g_owncolmap)
786          {          {
787                  g_xcolmap = DefaultColormapOfScreen(g_screen);                  g_xcolmap =
788                            XCreateColormap(g_display, RootWindowOfScreen(g_screen), g_visual,
789                                            AllocNone);
790                  if (g_depth <= 8)                  if (g_depth <= 8)
791                          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");
792          }          }
793    
         g_gc = XCreateGC(g_display, RootWindowOfScreen(g_screen), 0, NULL);  
   
794          if (DoesBackingStore(g_screen) != Always)          if (DoesBackingStore(g_screen) != Always)
795                  g_ownbackstore = True;                  g_ownbackstore = True;
796    
# Line 807  ui_init(void) Line 833  ui_init(void)
833          /* make sure width is a multiple of 4 */          /* make sure width is a multiple of 4 */
834          g_width = (g_width + 3) & ~3;          g_width = (g_width + 3) & ~3;
835    
         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);  
         }  
   
836          g_mod_map = XGetModifierMapping(g_display);          g_mod_map = XGetModifierMapping(g_display);
837    
838          xkeymap_init();          xkeymap_init();
# Line 838  ui_deinit(void) Line 853  ui_deinit(void)
853          if (g_IM != NULL)          if (g_IM != NULL)
854                  XCloseIM(g_IM);                  XCloseIM(g_IM);
855    
856            if (g_null_cursor != NULL)
857                    ui_destroy_cursor(g_null_cursor);
858    
859          XFreeModifiermap(g_mod_map);          XFreeModifiermap(g_mod_map);
860    
861          if (g_ownbackstore)          if (g_ownbackstore)
# Line 864  ui_create_window(void) Line 882  ui_create_window(void)
882          wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height;          wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height;
883    
884          attribs.background_pixel = BlackPixelOfScreen(g_screen);          attribs.background_pixel = BlackPixelOfScreen(g_screen);
885            attribs.border_pixel = WhitePixelOfScreen(g_screen);
886          attribs.backing_store = g_ownbackstore ? NotUseful : Always;          attribs.backing_store = g_ownbackstore ? NotUseful : Always;
887          attribs.override_redirect = g_fullscreen;          attribs.override_redirect = g_fullscreen;
888            attribs.colormap = g_xcolmap;
889    
890          g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), 0, 0, wndwidth, wndheight,          g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), 0, 0, wndwidth, wndheight,
891                                0, CopyFromParent, InputOutput, CopyFromParent,                                0, g_depth, InputOutput, g_visual,
892                                CWBackPixel | CWBackingStore | CWOverrideRedirect, &attribs);                                CWBackPixel | CWBackingStore | CWOverrideRedirect |
893                                  CWColormap | CWBorderPixel, &attribs);
894    
895            if (g_gc == NULL)
896                    g_gc = XCreateGC(g_display, g_wnd, 0, NULL);
897    
898            if ((g_ownbackstore) && (g_backstore == 0))
899            {
900                    g_backstore = XCreatePixmap(g_display, g_wnd, g_width, g_height, g_depth);
901    
902                    /* clear to prevent rubbish being exposed at startup */
903                    XSetForeground(g_display, g_gc, BlackPixelOfScreen(g_screen));
904                    XFillRectangle(g_display, g_backstore, g_gc, 0, 0, g_width, g_height);
905            }
906    
907          XStoreName(g_display, g_wnd, g_title);          XStoreName(g_display, g_wnd, g_title);
908    
# Line 935  ui_create_window(void) Line 968  ui_create_window(void)
968          XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1);          XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1);
969    
970          /* create invisible 1x1 cursor to be used as null cursor */          /* create invisible 1x1 cursor to be used as null cursor */
971          g_null_cursor = ui_create_cursor(0, 0, 1, 1, null_pointer_mask, null_pointer_data);          if (g_null_cursor == NULL)
972                    g_null_cursor = ui_create_cursor(0, 0, 1, 1, null_pointer_mask, null_pointer_data);
973    
974          return True;          return True;
975  }  }
# Line 1238  xwin_process_events(void) Line 1272  xwin_process_events(void)
1272  int  int
1273  ui_select(int rdp_socket)  ui_select(int rdp_socket)
1274  {  {
1275          int n = (rdp_socket > g_x_socket) ? rdp_socket + 1 : g_x_socket + 1;          int n = (rdp_socket > g_x_socket) ? rdp_socket : g_x_socket;
1276          fd_set rfds, wfds;          fd_set rfds, wfds;
1277            struct timeval tv;
1278            BOOL s_timeout = False;
1279    
1280          while (True)          while (True)
1281          {          {
# Line 1258  ui_select(int rdp_socket) Line 1294  ui_select(int rdp_socket)
1294                  if (g_dsp_busy)                  if (g_dsp_busy)
1295                  {                  {
1296                          FD_SET(g_dsp_fd, &wfds);                          FD_SET(g_dsp_fd, &wfds);
1297                          n = (g_dsp_fd + 1 > n) ? g_dsp_fd + 1 : n;                          n = (g_dsp_fd > n) ? g_dsp_fd : n;
1298                  }                  }
1299  #endif  #endif
1300                    /* default timeout */
1301                    tv.tv_sec = 60;
1302                    tv.tv_usec = 0;
1303    
1304                  switch (select(n, &rfds, &wfds, NULL, NULL))                  /* add redirection handles */
1305                    rdpdr_add_fds(&n, &rfds, &wfds, &tv, &s_timeout);
1306    
1307                    n++;
1308    
1309                    switch (select(n, &rfds, &wfds, NULL, &tv))
1310                  {                  {
1311                          case -1:                          case -1:
1312                                  error("select: %s\n", strerror(errno));                                  error("select: %s\n", strerror(errno));
1313    
1314                          case 0:                          case 0:
1315                                    /* TODO: if tv.tv_sec just times out
1316                                     * we will segfault.
1317                                     * FIXME:
1318                                     */
1319                                    //s_timeout = True;
1320                                    //rdpdr_check_fds(&rfds, &wfds, (BOOL) True);
1321                                  continue;                                  continue;
1322                  }                  }
1323    
1324                    rdpdr_check_fds(&rfds, &wfds, (BOOL) False);
1325    
1326                  if (FD_ISSET(rdp_socket, &rfds))                  if (FD_ISSET(rdp_socket, &rfds))
1327                          return 1;                          return 1;
1328    

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

  ViewVC Help
Powered by ViewVC 1.1.26