/[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 576 by stargo, Thu Jan 22 20:31:59 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 41  static int g_x_socket; Line 42  static int g_x_socket;
42  static Screen *g_screen;  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 = NULL;
46  static Visual *g_visual;  static Visual *g_visual;
47  static int g_depth;  static int g_depth;
48  static int g_bpp;  static int g_bpp;
# Line 49  static XIM g_IM; Line 50  static XIM g_IM;
50  static XIC g_IC;  static XIC g_IC;
51  static XModifierKeymap *g_mod_map;  static XModifierKeymap *g_mod_map;
52  static Cursor g_current_cursor;  static Cursor g_current_cursor;
53  static HCURSOR g_null_cursor;  static HCURSOR g_null_cursor = NULL;
54  static Atom g_protocol_atom, g_kill_atom;  static Atom g_protocol_atom, g_kill_atom;
55  static BOOL g_focused;  static BOOL g_focused;
56  static BOOL g_mouse_in_wnd;  static BOOL g_mouse_in_wnd;
# Line 62  static int g_red_shift_l, g_blue_shift_l Line 63  static int g_red_shift_l, g_blue_shift_l
63    
64  /* software backing store */  /* software backing store */
65  static BOOL g_ownbackstore;  static BOOL g_ownbackstore;
66  static Pixmap g_backstore;  static Pixmap g_backstore = NULL;
67    
68  /* Moving in single app mode */  /* Moving in single app mode */
69  static BOOL g_moving_wnd;  static BOOL g_moving_wnd;
# Line 310  translate8to32(uint8 * data, uint8 * out Line 311  translate8to32(uint8 * data, uint8 * out
311          }          }
312  }  }
313    
 /* todo the remaining translate function might need some big endian check ?? */  
   
314  static void  static void
315  translate15to16(uint16 * data, uint8 * out, uint8 * end)  translate15to16(uint16 * data, uint8 * out, uint8 * end)
316  {  {
# Line 542  translate24to24(uint8 * data, uint8 * ou Line 541  translate24to24(uint8 * data, uint8 * ou
541                  pixel |= *(data++);                  pixel |= *(data++);
542    
543                  value = make_colour(split_colour24(pixel));                  value = make_colour(split_colour24(pixel));
544                    
545                  if (g_xserver_be)                  if (g_xserver_be)
546                  {                  {
547                          *(out++) = value >> 16;                          *(out++) = value >> 16;
# Line 700  ui_init(void) Line 699  ui_init(void)
699          XVisualInfo vi;          XVisualInfo vi;
700          XPixmapFormatValues *pfm;          XPixmapFormatValues *pfm;
701          uint16 test;          uint16 test;
702          int i, screen_num;          int i, screen_num, nvisuals;
703            XVisualInfo *vmatches = NULL;
704            XVisualInfo template;
705            Bool TrueColorVisual = False;
706    
707          g_display = XOpenDisplay(NULL);          g_display = XOpenDisplay(NULL);
708          if (g_display == NULL)          if (g_display == NULL)
# Line 714  ui_init(void) Line 716  ui_init(void)
716          g_screen = ScreenOfDisplay(g_display, screen_num);          g_screen = ScreenOfDisplay(g_display, screen_num);
717          g_depth = DefaultDepthOfScreen(g_screen);          g_depth = DefaultDepthOfScreen(g_screen);
718    
719          if (g_server_bpp == 8)          /* Search for best TrueColor depth */
720            template.class = TrueColor;
721            vmatches = XGetVisualInfo(g_display, VisualClassMask, &template, &nvisuals);
722    
723            nvisuals--;
724            while (nvisuals >= 0)
725          {          {
726                  /* we use a colourmap, so any visual should do */                  if ((vmatches + nvisuals)->depth > g_depth)
727                    {
728                            g_depth = (vmatches + nvisuals)->depth;
729                    }
730                    nvisuals--;
731                    TrueColorVisual = True;
732            }
733    
734            if ((g_server_bpp == 8) && ((! TrueColorVisual) || (g_depth <= 8)))
735            {
736                    /* we use a colourmap, so the default visual should do */
737                  g_visual = DefaultVisualOfScreen(g_screen);                  g_visual = DefaultVisualOfScreen(g_screen);
738                    g_depth = DefaultDepthOfScreen(g_screen);
739    
740                    /* Do not allocate colours on a TrueColor visual */
741                    if (g_visual->class == TrueColor)
742                    {
743                            g_owncolmap = False;
744                    }
745          }          }
746          else          else
747          {          {
# Line 759  ui_init(void) Line 783  ui_init(void)
783    
784          if (!g_owncolmap)          if (!g_owncolmap)
785          {          {
786                  g_xcolmap = DefaultColormapOfScreen(g_screen);                  g_xcolmap = XCreateColormap(g_display,RootWindowOfScreen(g_screen),g_visual,AllocNone);
787                  if (g_depth <= 8)                  if (g_depth <= 8)
788                          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");
789          }          }
790    
         g_gc = XCreateGC(g_display, RootWindowOfScreen(g_screen), 0, NULL);  
   
791          if (DoesBackingStore(g_screen) != Always)          if (DoesBackingStore(g_screen) != Always)
792                  g_ownbackstore = True;                  g_ownbackstore = True;
793    
# Line 776  ui_init(void) Line 798  ui_init(void)
798          /*          /*
799           * Determine desktop size           * Determine desktop size
800           */           */
801          if (g_width < 0)          if (g_fullscreen)
802            {
803                    g_width = WidthOfScreen(g_screen);
804                    g_height = HeightOfScreen(g_screen);
805            }
806            else if (g_width < 0)
807          {          {
808                  /* Percent of screen */                  /* Percent of screen */
809                  g_height = HeightOfScreen(g_screen) * (-g_width) / 100;                  g_height = HeightOfScreen(g_screen) * (-g_width) / 100;
# Line 799  ui_init(void) Line 826  ui_init(void)
826                          g_height = 600;                          g_height = 600;
827                  }                  }
828          }          }
         else if (g_fullscreen)  
         {  
                 g_width = WidthOfScreen(g_screen);  
                 g_height = HeightOfScreen(g_screen);  
         }  
829    
830          /* make sure width is a multiple of 4 */          /* make sure width is a multiple of 4 */
831          g_width = (g_width + 3) & ~3;          g_width = (g_width + 3) & ~3;
832    
         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);  
         }  
   
833          g_mod_map = XGetModifierMapping(g_display);          g_mod_map = XGetModifierMapping(g_display);
834    
835          xkeymap_init();          xkeymap_init();
# Line 838  ui_deinit(void) Line 849  ui_deinit(void)
849  {  {
850          if (g_IM != NULL)          if (g_IM != NULL)
851                  XCloseIM(g_IM);                  XCloseIM(g_IM);
852            
853            if (g_null_cursor != NULL)
854                    ui_destroy_cursor(g_null_cursor);
855    
856          XFreeModifiermap(g_mod_map);          XFreeModifiermap(g_mod_map);
857    
# Line 865  ui_create_window(void) Line 879  ui_create_window(void)
879          wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height;          wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height;
880    
881          attribs.background_pixel = BlackPixelOfScreen(g_screen);          attribs.background_pixel = BlackPixelOfScreen(g_screen);
882            attribs.border_pixel = WhitePixelOfScreen(g_screen);
883          attribs.backing_store = g_ownbackstore ? NotUseful : Always;          attribs.backing_store = g_ownbackstore ? NotUseful : Always;
884          attribs.override_redirect = g_fullscreen;          attribs.override_redirect = g_fullscreen;
885            attribs.colormap = g_xcolmap;
886    
887          g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), 0, 0, wndwidth, wndheight,          g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), 0, 0, wndwidth, wndheight,
888                                0, CopyFromParent, InputOutput, CopyFromParent,                                0, g_depth, InputOutput, g_visual,
889                                CWBackPixel | CWBackingStore | CWOverrideRedirect, &attribs);                                CWBackPixel | CWBackingStore | CWOverrideRedirect |
890                                  CWColormap | CWBorderPixel, &attribs);
891    
892            if (g_gc == NULL)
893                    g_gc = XCreateGC(g_display, g_wnd, 0, NULL);
894    
895            if ((g_ownbackstore) && (g_backstore == NULL))
896            {
897                    g_backstore =
898                            XCreatePixmap(g_display, g_wnd, g_width, g_height,
899                                          g_depth);
900    
901                    /* clear to prevent rubbish being exposed at startup */
902                    XSetForeground(g_display, g_gc, BlackPixelOfScreen(g_screen));
903                    XFillRectangle(g_display, g_backstore, g_gc, 0, 0, g_width, g_height);
904            }
905    
906          XStoreName(g_display, g_wnd, g_title);          XStoreName(g_display, g_wnd, g_title);
907    
# Line 936  ui_create_window(void) Line 967  ui_create_window(void)
967          XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1);          XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1);
968    
969          /* create invisible 1x1 cursor to be used as null cursor */          /* create invisible 1x1 cursor to be used as null cursor */
970          g_null_cursor = ui_create_cursor(0, 0, 1, 1, null_pointer_mask, null_pointer_data);          if (g_null_cursor == NULL)
971                    g_null_cursor = ui_create_cursor(0, 0, 1, 1, null_pointer_mask, null_pointer_data);
972    
973          return True;          return True;
974  }  }
# Line 944  ui_create_window(void) Line 976  ui_create_window(void)
976  void  void
977  ui_destroy_window(void)  ui_destroy_window(void)
978  {  {
         ui_destroy_cursor(g_null_cursor);  
   
979          if (g_IC != NULL)          if (g_IC != NULL)
980                  XDestroyIC(g_IC);                  XDestroyIC(g_IC);
981    
# Line 989  xwin_process_events(void) Line 1019  xwin_process_events(void)
1019          key_translation tr;          key_translation tr;
1020          char str[256];          char str[256];
1021          Status status;          Status status;
         unsigned int state;  
         Window wdummy;  
         int dummy;  
1022    
1023          while (XPending(g_display) > 0)          while (XPending(g_display) > 0)
1024          {          {
# Line 1164  xwin_process_events(void) Line 1191  xwin_process_events(void)
1191                                  if (xevent.xfocus.mode == NotifyGrab)                                  if (xevent.xfocus.mode == NotifyGrab)
1192                                          break;                                          break;
1193                                  g_focused = True;                                  g_focused = True;
1194                                  XQueryPointer(g_display, g_wnd, &wdummy, &wdummy, &dummy, &dummy,                                  reset_modifier_keys();
                                               &dummy, &dummy, &state);  
                                 reset_modifier_keys(state);  
1195                                  if (g_grab_keyboard && g_mouse_in_wnd)                                  if (g_grab_keyboard && g_mouse_in_wnd)
1196                                          XGrabKeyboard(g_display, g_wnd, True,                                          XGrabKeyboard(g_display, g_wnd, True,
1197                                                        GrabModeAsync, GrabModeAsync, CurrentTime);                                                        GrabModeAsync, GrabModeAsync, CurrentTime);
# Line 1831  ui_draw_glyph(int mixmode, Line 1856  ui_draw_glyph(int mixmode,
1856  {\  {\
1857    glyph = cache_get_font (font, ttext[idx]);\    glyph = cache_get_font (font, ttext[idx]);\
1858    if (!(flags & TEXT2_IMPLICIT_X))\    if (!(flags & TEXT2_IMPLICIT_X))\
1859      {\
1860        xyoffset = ttext[++idx];\
1861        if ((xyoffset & 0x80))\
1862      {\      {\
1863        xyoffset = ttext[++idx];\        if (flags & TEXT2_VERTICAL)\
1864        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;\  
         }\  
1865        else\        else\
1866          {\          x += ttext[idx+1] | (ttext[idx+2] << 8);\
1867            if (flags & TEXT2_VERTICAL) \        idx += 2;\
             y += xyoffset;\  
           else\  
             x += xyoffset;\  
         }\  
1868      }\      }\
1869    if (glyph != NULL)\      else\
1870      {\      {\
1871        ui_draw_glyph (mixmode, x + glyph->offset,\        if (flags & TEXT2_VERTICAL)\
1872                       y + glyph->baseline,\          y += xyoffset;\
1873                       glyph->width, glyph->height,\        else\
1874                       glyph->pixmap, 0, 0, bgcolour, fgcolour);\          x += xyoffset;\
       if (flags & TEXT2_IMPLICIT_X)\  
         x += glyph->width;\  
1875      }\      }\
1876      }\
1877      if (glyph != NULL)\
1878      {\
1879        x1 = x + glyph->offset;\
1880        y1 = y + glyph->baseline;\
1881        XSetStipple(g_display, g_gc, (Pixmap) glyph->pixmap);\
1882        XSetTSOrigin(g_display, g_gc, x1, y1);\
1883        FILL_RECTANGLE_BACKSTORE(x1, y1, glyph->width, glyph->height);\
1884        if (flags & TEXT2_IMPLICIT_X)\
1885          x += glyph->width;\
1886      }\
1887  }  }
1888    
1889  void  void
# Line 1867  ui_draw_text(uint8 font, uint8 flags, in Line 1893  ui_draw_text(uint8 font, uint8 flags, in
1893               int fgcolour, uint8 * text, uint8 length)               int fgcolour, uint8 * text, uint8 length)
1894  {  {
1895          FONTGLYPH *glyph;          FONTGLYPH *glyph;
1896          int i, j, xyoffset;          int i, j, xyoffset, x1, y1;
1897          DATABLOB *entry;          DATABLOB *entry;
1898    
1899          SET_FOREGROUND(bgcolour);          SET_FOREGROUND(bgcolour);
# Line 1881  ui_draw_text(uint8 font, uint8 flags, in Line 1907  ui_draw_text(uint8 font, uint8 flags, in
1907                  FILL_RECTANGLE_BACKSTORE(clipx, clipy, clipcx, clipcy);                  FILL_RECTANGLE_BACKSTORE(clipx, clipy, clipcx, clipcy);
1908          }          }
1909    
1910            SET_FOREGROUND(fgcolour);
1911            SET_BACKGROUND(bgcolour);
1912            XSetFillStyle(g_display, g_gc, FillStippled);
1913    
1914          /* Paint text, character by character */          /* Paint text, character by character */
1915          for (i = 0; i < length;)          for (i = 0; i < length;)
1916          {          {
# Line 1931  ui_draw_text(uint8 font, uint8 flags, in Line 1961  ui_draw_text(uint8 font, uint8 flags, in
1961                                  break;                                  break;
1962                  }                  }
1963          }          }
1964    
1965            XSetFillStyle(g_display, g_gc, FillSolid);
1966    
1967          if (g_ownbackstore)          if (g_ownbackstore)
1968          {          {
1969                  if (boxcx > 1)                  if (boxcx > 1)

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

  ViewVC Help
Powered by ViewVC 1.1.26