/[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 536 by matthewc, Fri Oct 31 04:29:57 2003 UTC revision 566 by stargo, Mon Jan 19 23:45:26 2004 UTC
# Line 20  Line 20 
20    
21  #include <X11/Xlib.h>  #include <X11/Xlib.h>
22  #include <X11/Xutil.h>  #include <X11/Xutil.h>
23    #include <unistd.h>
24  #include <time.h>  #include <time.h>
25  #include <errno.h>  #include <errno.h>
26  #include "rdesktop.h"  #include "rdesktop.h"
# Line 42  static Screen *g_screen; Line 43  static Screen *g_screen;
43  Window g_wnd;  Window g_wnd;
44  BOOL g_enable_compose = False;  BOOL g_enable_compose = False;
45  static GC g_gc;  static GC g_gc;
46    static BOOL g_gc_initialized = False;
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 63  static int g_red_shift_l, g_blue_shift_l Line 65  static int g_red_shift_l, g_blue_shift_l
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;
68    static BOOL g_backstore_initialized = False;
69    
70  /* Moving in single app mode */  /* Moving in single app mode */
71  static BOOL g_moving_wnd;  static BOOL g_moving_wnd;
# Line 310  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 542  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 700  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 714  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                    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 any visual should do */                  /* 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 759  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 = XCreateColormap(g_display,RootWindowOfScreen(g_screen),g_visual,AllocNone);
789                  if (g_depth <= 8)                  if (g_depth <= 8)
790                          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");
791          }          }
792    
         g_gc = XCreateGC(g_display, RootWindowOfScreen(g_screen), 0, NULL);  
   
793          if (DoesBackingStore(g_screen) != Always)          if (DoesBackingStore(g_screen) != Always)
794                  g_ownbackstore = True;                  g_ownbackstore = True;
795    
# Line 776  ui_init(void) Line 800  ui_init(void)
800          /*          /*
801           * Determine desktop size           * Determine desktop size
802           */           */
803          if (g_width < 0)          if (g_fullscreen)
804            {
805                    g_width = WidthOfScreen(g_screen);
806                    g_height = HeightOfScreen(g_screen);
807            }
808            else if (g_width < 0)
809          {          {
810                  /* Percent of screen */                  /* Percent of screen */
811                  g_height = HeightOfScreen(g_screen) * (-g_width) / 100;                  g_height = HeightOfScreen(g_screen) * (-g_width) / 100;
# Line 799  ui_init(void) Line 828  ui_init(void)
828                          g_height = 600;                          g_height = 600;
829                  }                  }
830          }          }
         else if (g_fullscreen)  
         {  
                 g_width = WidthOfScreen(g_screen);  
                 g_height = HeightOfScreen(g_screen);  
         }  
831    
832          /* make sure width is a multiple of 4 */          /* make sure width is a multiple of 4 */
833          g_width = (g_width + 3) & ~3;          g_width = (g_width + 3) & ~3;
834    
         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);  
         }  
   
835          g_mod_map = XGetModifierMapping(g_display);          g_mod_map = XGetModifierMapping(g_display);
836    
837          xkeymap_init();          xkeymap_init();
# Line 865  ui_create_window(void) Line 878  ui_create_window(void)
878          wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height;          wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height;
879    
880          attribs.background_pixel = BlackPixelOfScreen(g_screen);          attribs.background_pixel = BlackPixelOfScreen(g_screen);
881            attribs.border_pixel = WhitePixelOfScreen(g_screen);
882          attribs.backing_store = g_ownbackstore ? NotUseful : Always;          attribs.backing_store = g_ownbackstore ? NotUseful : Always;
883          attribs.override_redirect = g_fullscreen;          attribs.override_redirect = g_fullscreen;
884            attribs.colormap = g_xcolmap;
885    
886          g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), 0, 0, wndwidth, wndheight,          g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), 0, 0, wndwidth, wndheight,
887                                0, CopyFromParent, InputOutput, CopyFromParent,                                0, g_depth, InputOutput, g_visual,
888                                CWBackPixel | CWBackingStore | CWOverrideRedirect, &attribs);                                CWBackPixel | CWBackingStore | CWOverrideRedirect |
889                                  CWColormap | CWBorderPixel, &attribs);
890    
891            if ( ! g_gc_initialized )
892            {
893                    g_gc = XCreateGC(g_display, g_wnd, 0, NULL);
894                    g_gc_initialized = True;
895            }
896    
897            if ((g_ownbackstore) && (! g_backstore_initialized))
898            {
899                    g_backstore =
900                            XCreatePixmap(g_display, g_wnd, g_width, g_height,
901                                          g_depth);
902    
903                    /* clear to prevent rubbish being exposed at startup */
904                    XSetForeground(g_display, g_gc, BlackPixelOfScreen(g_screen));
905                    XFillRectangle(g_display, g_backstore, g_gc, 0, 0, g_width, g_height);
906                    g_backstore_initialized = True;
907            }
908    
909          XStoreName(g_display, g_wnd, g_title);          XStoreName(g_display, g_wnd, g_title);
910    
# Line 944  ui_create_window(void) Line 978  ui_create_window(void)
978  void  void
979  ui_destroy_window(void)  ui_destroy_window(void)
980  {  {
         ui_destroy_cursor(g_null_cursor);  
   
981          if (g_IC != NULL)          if (g_IC != NULL)
982                  XDestroyIC(g_IC);                  XDestroyIC(g_IC);
983    
# Line 989  xwin_process_events(void) Line 1021  xwin_process_events(void)
1021          key_translation tr;          key_translation tr;
1022          char str[256];          char str[256];
1023          Status status;          Status status;
         unsigned int state;  
         Window wdummy;  
         int dummy;  
1024    
1025          while (XPending(g_display) > 0)          while (XPending(g_display) > 0)
1026          {          {
# Line 1164  xwin_process_events(void) Line 1193  xwin_process_events(void)
1193                                  if (xevent.xfocus.mode == NotifyGrab)                                  if (xevent.xfocus.mode == NotifyGrab)
1194                                          break;                                          break;
1195                                  g_focused = True;                                  g_focused = True;
1196                                  XQueryPointer(g_display, g_wnd, &wdummy, &wdummy, &dummy, &dummy,                                  reset_modifier_keys();
                                               &dummy, &dummy, &state);  
                                 reset_modifier_keys(state);  
1197                                  if (g_grab_keyboard && g_mouse_in_wnd)                                  if (g_grab_keyboard && g_mouse_in_wnd)
1198                                          XGrabKeyboard(g_display, g_wnd, True,                                          XGrabKeyboard(g_display, g_wnd, True,
1199                                                        GrabModeAsync, GrabModeAsync, CurrentTime);                                                        GrabModeAsync, GrabModeAsync, CurrentTime);
# Line 1831  ui_draw_glyph(int mixmode, Line 1858  ui_draw_glyph(int mixmode,
1858  {\  {\
1859    glyph = cache_get_font (font, ttext[idx]);\    glyph = cache_get_font (font, ttext[idx]);\
1860    if (!(flags & TEXT2_IMPLICIT_X))\    if (!(flags & TEXT2_IMPLICIT_X))\
1861      {\
1862        xyoffset = ttext[++idx];\
1863        if ((xyoffset & 0x80))\
1864      {\      {\
1865        xyoffset = ttext[++idx];\        if (flags & TEXT2_VERTICAL)\
1866        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;\  
         }\  
1867        else\        else\
1868          {\          x += ttext[idx+1] | (ttext[idx+2] << 8);\
1869            if (flags & TEXT2_VERTICAL) \        idx += 2;\
             y += xyoffset;\  
           else\  
             x += xyoffset;\  
         }\  
1870      }\      }\
1871    if (glyph != NULL)\      else\
1872      {\      {\
1873        ui_draw_glyph (mixmode, x + glyph->offset,\        if (flags & TEXT2_VERTICAL)\
1874                       y + glyph->baseline,\          y += xyoffset;\
1875                       glyph->width, glyph->height,\        else\
1876                       glyph->pixmap, 0, 0, bgcolour, fgcolour);\          x += xyoffset;\
       if (flags & TEXT2_IMPLICIT_X)\  
         x += glyph->width;\  
1877      }\      }\
1878      }\
1879      if (glyph != NULL)\
1880      {\
1881        x1 = x + glyph->offset;\
1882        y1 = y + glyph->baseline;\
1883        XSetStipple(g_display, g_gc, (Pixmap) glyph->pixmap);\
1884        XSetTSOrigin(g_display, g_gc, x1, y1);\
1885        FILL_RECTANGLE_BACKSTORE(x1, y1, glyph->width, glyph->height);\
1886        if (flags & TEXT2_IMPLICIT_X)\
1887          x += glyph->width;\
1888      }\
1889  }  }
1890    
1891  void  void
# Line 1867  ui_draw_text(uint8 font, uint8 flags, in Line 1895  ui_draw_text(uint8 font, uint8 flags, in
1895               int fgcolour, uint8 * text, uint8 length)               int fgcolour, uint8 * text, uint8 length)
1896  {  {
1897          FONTGLYPH *glyph;          FONTGLYPH *glyph;
1898          int i, j, xyoffset;          int i, j, xyoffset, x1, y1;
1899          DATABLOB *entry;          DATABLOB *entry;
1900    
1901          SET_FOREGROUND(bgcolour);          SET_FOREGROUND(bgcolour);
# Line 1881  ui_draw_text(uint8 font, uint8 flags, in Line 1909  ui_draw_text(uint8 font, uint8 flags, in
1909                  FILL_RECTANGLE_BACKSTORE(clipx, clipy, clipcx, clipcy);                  FILL_RECTANGLE_BACKSTORE(clipx, clipy, clipcx, clipcy);
1910          }          }
1911    
1912            SET_FOREGROUND(fgcolour);
1913            SET_BACKGROUND(bgcolour);
1914            XSetFillStyle(g_display, g_gc, FillStippled);
1915    
1916          /* Paint text, character by character */          /* Paint text, character by character */
1917          for (i = 0; i < length;)          for (i = 0; i < length;)
1918          {          {
# Line 1931  ui_draw_text(uint8 font, uint8 flags, in Line 1963  ui_draw_text(uint8 font, uint8 flags, in
1963                                  break;                                  break;
1964                  }                  }
1965          }          }
1966    
1967            XSetFillStyle(g_display, g_gc, FillSolid);
1968    
1969          if (g_ownbackstore)          if (g_ownbackstore)
1970          {          {
1971                  if (boxcx > 1)                  if (boxcx > 1)

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

  ViewVC Help
Powered by ViewVC 1.1.26