/[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 541 by stargo, Sun Nov 2 16:43:29 2003 UTC revision 609 by stargo, Mon Feb 16 20:28:09 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 311  translate8to32(uint8 * data, uint8 * out Line 313  translate8to32(uint8 * data, uint8 * out
313          }          }
314  }  }
315    
 /* todo the remaining translate function might need some big endian check ?? */  
   
316  static void  static void
317  translate15to16(uint16 * data, uint8 * out, uint8 * end)  translate15to16(uint16 * data, uint8 * out, uint8 * end)
318  {  {
# Line 543  translate24to24(uint8 * data, uint8 * ou Line 543  translate24to24(uint8 * data, uint8 * ou
543                  pixel |= *(data++);                  pixel |= *(data++);
544    
545                  value = make_colour(split_colour24(pixel));                  value = make_colour(split_colour24(pixel));
546                    
547                  if (g_xserver_be)                  if (g_xserver_be)
548                  {                  {
549                          *(out++) = value >> 16;                          *(out++) = value >> 16;
# Line 701  ui_init(void) Line 701  ui_init(void)
701          XVisualInfo vi;          XVisualInfo vi;
702          XPixmapFormatValues *pfm;          XPixmapFormatValues *pfm;
703          uint16 test;          uint16 test;
704          int i, screen_num;          int i, screen_num, nvisuals;
705            XVisualInfo *vmatches = NULL;
706            XVisualInfo template;
707            Bool TrueColorVisual = False;
708    
709          g_display = XOpenDisplay(NULL);          g_display = XOpenDisplay(NULL);
710          if (g_display == NULL)          if (g_display == NULL)
# Line 715  ui_init(void) Line 718  ui_init(void)
718          g_screen = ScreenOfDisplay(g_display, screen_num);          g_screen = ScreenOfDisplay(g_display, screen_num);
719          g_depth = DefaultDepthOfScreen(g_screen);          g_depth = DefaultDepthOfScreen(g_screen);
720    
721          if (g_server_bpp == 8)          /* Search for best TrueColor depth */
722            template.class = TrueColor;
723            vmatches = XGetVisualInfo(g_display, VisualClassMask, &template, &nvisuals);
724    
725            nvisuals--;
726            while (nvisuals >= 0)
727          {          {
728                  /* we use a colourmap, so any visual should do */                  if ((vmatches + nvisuals)->depth > g_depth)
729                    {
730                            g_depth = (vmatches + nvisuals)->depth;
731                    }
732                    nvisuals--;
733                    TrueColorVisual = True;
734            }
735    
736            if ((g_server_bpp == 8) && ((!TrueColorVisual) || (g_depth <= 8)))
737            {
738                    /* we use a colourmap, so the default visual should do */
739                  g_visual = DefaultVisualOfScreen(g_screen);                  g_visual = DefaultVisualOfScreen(g_screen);
740                    g_depth = DefaultDepthOfScreen(g_screen);
741    
742                    /* Do not allocate colours on a TrueColor visual */
743                    if (g_visual->class == TrueColor)
744                    {
745                            g_owncolmap = False;
746                    }
747          }          }
748          else          else
749          {          {
# Line 760  ui_init(void) Line 785  ui_init(void)
785    
786          if (!g_owncolmap)          if (!g_owncolmap)
787          {          {
788                  g_xcolmap = DefaultColormapOfScreen(g_screen);                  g_xcolmap =
789                            XCreateColormap(g_display, RootWindowOfScreen(g_screen), g_visual,
790                                            AllocNone);
791                  if (g_depth <= 8)                  if (g_depth <= 8)
792                          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");
793          }          }
794    
795          g_gc = XCreateGC(g_display, RootWindowOfScreen(g_screen), 0, NULL);          if ((!g_ownbackstore) && (DoesBackingStore(g_screen) != Always))
796            {
797          if (DoesBackingStore(g_screen) != Always)                  warning("External BackingStore not available, using internal\n");
798                  g_ownbackstore = True;                  g_ownbackstore = True;
799            }
800    
801          test = 1;          test = 1;
802          g_host_be = !(BOOL) (*(uint8 *) (&test));          g_host_be = !(BOOL) (*(uint8 *) (&test));
# Line 777  ui_init(void) Line 805  ui_init(void)
805          /*          /*
806           * Determine desktop size           * Determine desktop size
807           */           */
808          if (g_width < 0)          if (g_fullscreen)
809            {
810                    g_width = WidthOfScreen(g_screen);
811                    g_height = HeightOfScreen(g_screen);
812            }
813            else if (g_width < 0)
814          {          {
815                  /* Percent of screen */                  /* Percent of screen */
816                  g_height = HeightOfScreen(g_screen) * (-g_width) / 100;                  g_height = HeightOfScreen(g_screen) * (-g_width) / 100;
# Line 800  ui_init(void) Line 833  ui_init(void)
833                          g_height = 600;                          g_height = 600;
834                  }                  }
835          }          }
         else if (g_fullscreen)  
         {  
                 g_width = WidthOfScreen(g_screen);  
                 g_height = HeightOfScreen(g_screen);  
         }  
836    
837          /* make sure width is a multiple of 4 */          /* make sure width is a multiple of 4 */
838          g_width = (g_width + 3) & ~3;          g_width = (g_width + 3) & ~3;
839    
         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);  
         }  
   
840          g_mod_map = XGetModifierMapping(g_display);          g_mod_map = XGetModifierMapping(g_display);
841    
842          xkeymap_init();          xkeymap_init();
# Line 840  ui_deinit(void) Line 857  ui_deinit(void)
857          if (g_IM != NULL)          if (g_IM != NULL)
858                  XCloseIM(g_IM);                  XCloseIM(g_IM);
859    
860            if (g_null_cursor != NULL)
861                    ui_destroy_cursor(g_null_cursor);
862    
863          XFreeModifiermap(g_mod_map);          XFreeModifiermap(g_mod_map);
864    
865          if (g_ownbackstore)          if (g_ownbackstore)
# Line 866  ui_create_window(void) Line 886  ui_create_window(void)
886          wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height;          wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height;
887    
888          attribs.background_pixel = BlackPixelOfScreen(g_screen);          attribs.background_pixel = BlackPixelOfScreen(g_screen);
889            attribs.border_pixel = WhitePixelOfScreen(g_screen);
890          attribs.backing_store = g_ownbackstore ? NotUseful : Always;          attribs.backing_store = g_ownbackstore ? NotUseful : Always;
891          attribs.override_redirect = g_fullscreen;          attribs.override_redirect = g_fullscreen;
892            attribs.colormap = g_xcolmap;
893    
894          g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), 0, 0, wndwidth, wndheight,          g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), 0, 0, wndwidth, wndheight,
895                                0, CopyFromParent, InputOutput, CopyFromParent,                                0, g_depth, InputOutput, g_visual,
896                                CWBackPixel | CWBackingStore | CWOverrideRedirect, &attribs);                                CWBackPixel | CWBackingStore | CWOverrideRedirect |
897                                  CWColormap | CWBorderPixel, &attribs);
898    
899            if (g_gc == NULL)
900                    g_gc = XCreateGC(g_display, g_wnd, 0, NULL);
901    
902            if ((g_ownbackstore) && (g_backstore == 0))
903            {
904                    g_backstore = XCreatePixmap(g_display, g_wnd, g_width, g_height, g_depth);
905    
906                    /* clear to prevent rubbish being exposed at startup */
907                    XSetForeground(g_display, g_gc, BlackPixelOfScreen(g_screen));
908                    XFillRectangle(g_display, g_backstore, g_gc, 0, 0, g_width, g_height);
909            }
910    
911          XStoreName(g_display, g_wnd, g_title);          XStoreName(g_display, g_wnd, g_title);
912    
# Line 937  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 988  xwin_process_events(void) Line 1024  xwin_process_events(void)
1024          key_translation tr;          key_translation tr;
1025          char str[256];          char str[256];
1026          Status status;          Status status;
         unsigned int state;  
         Window wdummy;  
         int dummy;  
1027    
1028          while (XPending(g_display) > 0)          while (XPending(g_display) > 0)
1029          {          {
# Line 1163  xwin_process_events(void) Line 1196  xwin_process_events(void)
1196                                  if (xevent.xfocus.mode == NotifyGrab)                                  if (xevent.xfocus.mode == NotifyGrab)
1197                                          break;                                          break;
1198                                  g_focused = True;                                  g_focused = True;
1199                                  XQueryPointer(g_display, g_wnd, &wdummy, &wdummy, &dummy, &dummy,                                  reset_modifier_keys();
                                               &dummy, &dummy, &state);  
                                 reset_modifier_keys(state);  
1200                                  if (g_grab_keyboard && g_mouse_in_wnd)                                  if (g_grab_keyboard && g_mouse_in_wnd)
1201                                          XGrabKeyboard(g_display, g_wnd, True,                                          XGrabKeyboard(g_display, g_wnd, True,
1202                                                        GrabModeAsync, GrabModeAsync, CurrentTime);                                                        GrabModeAsync, GrabModeAsync, CurrentTime);
# Line 1245  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 1265  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                  switch (select(n, &rfds, &wfds, NULL, NULL))                  /* add redirection handles */
1310                    rdpdr_add_fds(&n, &rfds, &wfds, &tv, &s_timeout);
1311    
1312                    n++;
1313    
1314                    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 1733  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 1830  ui_draw_glyph(int mixmode, Line 1886  ui_draw_glyph(int mixmode,
1886  {\  {\
1887    glyph = cache_get_font (font, ttext[idx]);\    glyph = cache_get_font (font, ttext[idx]);\
1888    if (!(flags & TEXT2_IMPLICIT_X))\    if (!(flags & TEXT2_IMPLICIT_X))\
1889      {\
1890        xyoffset = ttext[++idx];\
1891        if ((xyoffset & 0x80))\
1892      {\      {\
1893        xyoffset = ttext[++idx];\        if (flags & TEXT2_VERTICAL)\
1894        if ((xyoffset & 0x80))\          y += ttext[idx+1] | (ttext[idx+2] << 8);\
         {\  
           if (flags & TEXT2_VERTICAL) \  
             y += ttext[idx+1] | (ttext[idx+2] << 8);\  
           else\  
             x += ttext[idx+1] | (ttext[idx+2] << 8);\  
           idx += 2;\  
         }\  
1895        else\        else\
1896          {\          x += ttext[idx+1] | (ttext[idx+2] << 8);\
1897            if (flags & TEXT2_VERTICAL) \        idx += 2;\
             y += xyoffset;\  
           else\  
             x += xyoffset;\  
         }\  
1898      }\      }\
1899    if (glyph != NULL)\      else\
1900      {\      {\
1901        ui_draw_glyph (mixmode, x + glyph->offset,\        if (flags & TEXT2_VERTICAL)\
1902                       y + glyph->baseline,\          y += xyoffset;\
1903                       glyph->width, glyph->height,\        else\
1904                       glyph->pixmap, 0, 0, bgcolour, fgcolour);\          x += xyoffset;\
       if (flags & TEXT2_IMPLICIT_X)\  
         x += glyph->width;\  
1905      }\      }\
1906      }\
1907      if (glyph != NULL)\
1908      {\
1909        x1 = x + glyph->offset;\
1910        y1 = y + glyph->baseline;\
1911        XSetStipple(g_display, g_gc, (Pixmap) glyph->pixmap);\
1912        XSetTSOrigin(g_display, g_gc, x1, y1);\
1913        FILL_RECTANGLE_BACKSTORE(x1, y1, glyph->width, glyph->height);\
1914        if (flags & TEXT2_IMPLICIT_X)\
1915          x += glyph->width;\
1916      }\
1917  }  }
1918    
1919  void  void
# Line 1866  ui_draw_text(uint8 font, uint8 flags, in Line 1923  ui_draw_text(uint8 font, uint8 flags, in
1923               int fgcolour, uint8 * text, uint8 length)               int fgcolour, uint8 * text, uint8 length)
1924  {  {
1925          FONTGLYPH *glyph;          FONTGLYPH *glyph;
1926          int i, j, xyoffset;          int i, j, xyoffset, x1, y1;
1927          DATABLOB *entry;          DATABLOB *entry;
1928    
1929          SET_FOREGROUND(bgcolour);          SET_FOREGROUND(bgcolour);
# Line 1880  ui_draw_text(uint8 font, uint8 flags, in Line 1937  ui_draw_text(uint8 font, uint8 flags, in
1937                  FILL_RECTANGLE_BACKSTORE(clipx, clipy, clipcx, clipcy);                  FILL_RECTANGLE_BACKSTORE(clipx, clipy, clipcx, clipcy);
1938          }          }
1939    
1940            SET_FOREGROUND(fgcolour);
1941            SET_BACKGROUND(bgcolour);
1942            XSetFillStyle(g_display, g_gc, FillStippled);
1943    
1944          /* Paint text, character by character */          /* Paint text, character by character */
1945          for (i = 0; i < length;)          for (i = 0; i < length;)
1946          {          {
# Line 1930  ui_draw_text(uint8 font, uint8 flags, in Line 1991  ui_draw_text(uint8 font, uint8 flags, in
1991                                  break;                                  break;
1992                  }                  }
1993          }          }
1994    
1995            XSetFillStyle(g_display, g_gc, FillSolid);
1996    
1997          if (g_ownbackstore)          if (g_ownbackstore)
1998          {          {
1999                  if (boxcx > 1)                  if (boxcx > 1)

Legend:
Removed from v.541  
changed lines
  Added in v.609

  ViewVC Help
Powered by ViewVC 1.1.26