home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / ddx / sun / sunCursor.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-21  |  7.8 KB  |  323 lines

  1. /* $XConsortium: sunCursor.c,v 5.9 91/11/14 13:57:03 keith Exp $ */
  2. /*-
  3.  * sunCursor.c --
  4.  *    Functions for maintaining the Sun software cursor...
  5.  *
  6.  */
  7.  
  8. #define NEED_EVENTS
  9. #include    "sun.h"
  10. #include    <windowstr.h>
  11. #include    <regionstr.h>
  12. #include    <dix.h>
  13. #include    <dixstruct.h>
  14. #include    <opaque.h>
  15.  
  16. #include    <servermd.h>
  17. #include    "mipointer.h"
  18. #include    "cursorstr.h"
  19.  
  20. #ifdef FBIOGCURMAX  /* has hardware cursor kernel support */
  21.  
  22. #define GetCursorPrivate(s) (&(GetScreenPrivate(s)->hardwareCursor))
  23. #define SetupCursor(s)        sunCursorPtr pCurPriv = GetCursorPrivate(s)
  24.  
  25. static Bool
  26. sunRealizeCursor (pScreen, pCursor)
  27.     ScreenPtr    pScreen;
  28.     CursorPtr    pCursor;
  29. {
  30.     return TRUE;
  31. }
  32.  
  33. static Bool
  34. sunUnrealizeCursor (pScreen, pCursor)
  35.     ScreenPtr    pScreen;
  36.     CursorPtr    pCursor;
  37. {
  38.     return TRUE;
  39. }
  40.  
  41. sunInitFakePixmap (pScreen, p, w, h, bits)
  42.     ScreenPtr        pScreen;
  43.     PixmapPtr        p;
  44.     int            w, h;
  45.     unsigned char   *bits;
  46. {
  47.     p->drawable.type = DRAWABLE_PIXMAP;
  48.     p->drawable.class = 0;
  49.     p->drawable.pScreen = pScreen;
  50.     p->drawable.depth = 1;
  51.     p->drawable.bitsPerPixel = 1;
  52.     p->drawable.id = 0;
  53.     p->drawable.serialNumber = NEXT_SERIAL_NUMBER;
  54.     p->drawable.x = 0;
  55.     p->drawable.y = 0;
  56.     p->drawable.width = w;
  57.     p->drawable.height = h;
  58.     p->devKind = PixmapBytePad(w, 1);
  59.     p->refcnt = 1;
  60.     p->devPrivate.ptr = (pointer) bits;
  61. }
  62.  
  63. static void
  64. sunCursorRepad (pScreen, bits, src_bits, dst_bits, ptSrc, w, h)
  65.     ScreenPtr        pScreen;
  66.     CursorBitsPtr   bits;
  67.     unsigned char   *src_bits, *dst_bits;
  68.     DDXPointPtr        ptSrc;
  69.     int            w, h;
  70. {
  71.     SetupCursor(pScreen);
  72.     PixmapRec    src, dst;
  73.     BoxRec    box;
  74.     RegionRec    rgnDst;
  75.  
  76.     sunInitFakePixmap (pScreen, &src, bits->width, bits->height, src_bits);
  77.     sunInitFakePixmap (pScreen, &dst, w, h, dst_bits);
  78.     box.x1 = 0;
  79.     box.y1 = 0;
  80.     box.x2 = w;
  81.     box.y2 = h;
  82.     (*pScreen->RegionInit)(&rgnDst, &box, 1);
  83.     mfbDoBitblt(&src, &dst, GXcopy, &rgnDst, ptSrc);
  84.     (*pScreen->RegionUninit)(&rgnDst);
  85. }
  86.  
  87. static void
  88. sunLoadCursor (pScreen, pCursor, x, y)
  89.     ScreenPtr    pScreen;
  90.     CursorPtr    pCursor;
  91.     int        x, y;
  92. {
  93.     SetupCursor(pScreen);
  94.     struct fbcursor fbcursor;
  95.     int    w, h;
  96.     unsigned char   r[2], g[2], b[2];
  97.     DDXPointRec    ptSrc;
  98.     unsigned char   source_temp[1024], mask_temp[1024];
  99.  
  100.     fbcursor.set = FB_CUR_SETALL;
  101.     fbcursor.enable = 1;
  102.     fbcursor.pos.x = x;
  103.     fbcursor.pos.y = y;
  104.     fbcursor.hot.x = pCursor->bits->xhot;
  105.     fbcursor.hot.y = pCursor->bits->yhot;
  106.     r[0] = pCursor->backRed >> 8;
  107.     g[0] = pCursor->backGreen >> 8;
  108.     b[0] = pCursor->backBlue >> 8;
  109.     r[1] = pCursor->foreRed >> 8;
  110.     g[1] = pCursor->foreGreen >> 8;
  111.     b[1] = pCursor->foreBlue >> 8;
  112.     fbcursor.cmap.index = 0;
  113.     fbcursor.cmap.count = 2;
  114.     fbcursor.cmap.red = r;
  115.     fbcursor.cmap.green = g;
  116.     fbcursor.cmap.blue = b;
  117.     fbcursor.image = (char *) pCursor->bits->source;
  118.     fbcursor.mask = (char *) pCursor->bits->mask;
  119.     w = pCursor->bits->width;
  120.     h = pCursor->bits->height;
  121.     if (w > pCurPriv->width || h > pCurPriv->height) {
  122.     ptSrc.x = 0;
  123.     ptSrc.y = 0;
  124.     if (w > pCurPriv->width)
  125.         w = pCurPriv->width;
  126.     if (h > pCurPriv->height)
  127.         h = pCurPriv->height;
  128.     sunCursorRepad (pScreen, pCursor->bits, pCursor->bits->source,
  129.             source_temp, &ptSrc, w, h);
  130.     sunCursorRepad (pScreen, pCursor->bits, pCursor->bits->mask,
  131.             mask_temp, &ptSrc, w, h);
  132.     fbcursor.image = (char *) source_temp;
  133.     fbcursor.mask = (char *) mask_temp;
  134.     }
  135.     fbcursor.size.x = w;
  136.     fbcursor.size.y = h;
  137.     (void) ioctl (sunFbs[pScreen->myNum].fd, FBIOSCURSOR, &fbcursor);
  138. }
  139.  
  140. static void
  141. sunSetCursor (pScreen, pCursor, x, y)
  142.     ScreenPtr    pScreen;
  143.     CursorPtr    pCursor;
  144.     int        x, y;
  145. {
  146.     SetupCursor(pScreen);
  147.  
  148.     if (pCursor)
  149.         sunLoadCursor (pScreen, pCursor, x, y);
  150.     else
  151.     sunDisableCursor (pScreen);
  152. }
  153.  
  154. static void
  155. sunMoveCursor (pScreen, x, y)
  156.     ScreenPtr    pScreen;
  157.     int        x, y;
  158. {
  159.     SetupCursor(pScreen);
  160.     struct fbcursor fbcursor;
  161.     struct fbcurpos pos;
  162.  
  163.     pos.x = x;
  164.     pos.y = y;
  165.     ioctl (sunFbs[pScreen->myNum].fd, FBIOSCURPOS, &pos);
  166. }
  167.  
  168. miPointerSpriteFuncRec sunPointerSpriteFuncs = {
  169.     sunRealizeCursor,
  170.     sunUnrealizeCursor,
  171.     sunSetCursor,
  172.     sunMoveCursor,
  173. };
  174.  
  175. static void
  176. sunQueryBestSize (class, pwidth, pheight, pScreen)
  177.     int    class;
  178.     short   *pwidth, *pheight;
  179.     ScreenPtr    pScreen;
  180. {
  181.     SetupCursor (pScreen);
  182.  
  183.     switch (class)
  184.     {
  185.     case CursorShape:
  186.     if (*pwidth > pCurPriv->width)
  187.         *pwidth = pCurPriv->width;
  188.     if (*pheight > pCurPriv->height)
  189.         *pheight = pCurPriv->height;
  190.     if (*pwidth > pScreen->width)
  191.         *pwidth = pScreen->width;
  192.     if (*pheight > pScreen->height)
  193.         *pheight = pScreen->height;
  194.     break;
  195.     default:
  196.     mfbQueryBestSize (class, pwidth, pheight, pScreen);
  197.     break;
  198.     }
  199. }
  200.  
  201. extern miPointerScreenFuncRec    sunPointerScreenFuncs;
  202.  
  203. #endif
  204.  
  205. Bool
  206. sunCursorInitialize (pScreen)
  207.     ScreenPtr    pScreen;
  208. {
  209. #ifdef FBIOGCURMAX
  210.     SetupCursor (pScreen);
  211.     int        fd;
  212.     struct fbcursor fbcursor;
  213.     struct fbcurpos maxsize;
  214.     char    *source, *mask;
  215.     int        h, w;
  216.     int        size;
  217.  
  218.     pCurPriv->has_cursor = FALSE;
  219.     if (ioctl (sunFbs[pScreen->myNum].fd, FBIOGCURMAX, &maxsize) == -1)
  220.     return FALSE;
  221.     pCurPriv->width = maxsize.x;
  222.     pCurPriv->height= maxsize.y;
  223.     pScreen->QueryBestSize = sunQueryBestSize;
  224.     miPointerInitialize (pScreen,
  225.              &sunPointerSpriteFuncs,
  226.              &sunPointerScreenFuncs,
  227.              FALSE);
  228.     pCurPriv->has_cursor = TRUE;
  229.     return TRUE;
  230. #else
  231.     return FALSE;
  232. #endif
  233. }
  234.  
  235. sunDisableCursor (pScreen)
  236.     ScreenPtr    pScreen;
  237. {
  238. #ifdef FBIOGCURMAX
  239.     SetupCursor (pScreen);
  240.     struct fbcursor fbcursor;
  241.  
  242.     if (pCurPriv->has_cursor)
  243.     {
  244.         fbcursor.set = FB_CUR_SETCUR;
  245.         fbcursor.enable = 0;
  246.         (void) ioctl (sunFbs[pScreen->myNum].fd, FBIOSCURSOR, &fbcursor);
  247.     }
  248. #endif
  249. }
  250.  
  251. /*
  252.  * The following struct is from win_cursor.h.  This file can't be included 
  253.  * directly, because it drags in all of the SunView attribute stuff along 
  254.  * with it.
  255.  */
  256.  
  257. #ifdef SUN_WINDOWS
  258.  
  259. struct cursor {
  260.     short       cur_xhot, cur_yhot;    /* offset of mouse position from shape */
  261.     int         cur_function;        /* relationship of shape to screen */
  262.     struct pixrect *cur_shape;        /* memory image to use */
  263.     int         flags;            /* various options */
  264.     short       horiz_hair_thickness;    /* horizontal crosshair height */
  265.     int         horiz_hair_op;        /* drawing op       */
  266.     int         horiz_hair_color;    /* color            */
  267.     short       horiz_hair_length;    /* width           */
  268.     short       horiz_hair_gap;        /* gap             */
  269.     short       vert_hair_thickness;    /* vertical crosshair width  */
  270.     int         vert_hair_op;        /* drawing op       */
  271.     int         vert_hair_color;    /* color            */
  272.     short       vert_hair_length;    /* height           */
  273.     short       vert_hair_gap;        /* gap              */
  274. };
  275. #endif SUN_WINDOWS
  276.  
  277. void
  278. sunInitCursor ()
  279. {
  280.     if ( sunUseSunWindows() ) {
  281. #ifdef SUN_WINDOWS
  282.     static struct cursor cs;
  283.     static struct pixrect pr;
  284.     /* 
  285.      * Give the pixwin an empty cursor so that the kernel's cursor drawing 
  286.      * doesn't conflict with our cursor drawing.
  287.      */
  288.     cs.cur_xhot = cs.cur_yhot = cs.cur_function = 0;
  289.     cs.flags = 0;
  290.     cs.cur_shape = ≺
  291.     pr.pr_size.x = pr.pr_size.y = 0;
  292.     win_setcursor( windowFd, &cs );
  293. #endif SUN_WINDOWS
  294.     }
  295. }
  296.  
  297.  
  298. #ifdef SUN_WINDOWS
  299. /*
  300.  * We need to find out when dix warps the mouse so we can
  301.  * keep SunWindows in sync.
  302.  */
  303.  
  304. extern int sunIgnoreEvent;
  305.  
  306. Bool
  307. sunSetCursorPosition(pScreen, x, y, generateEvent)
  308.     ScreenPtr pScreen;
  309.     int x, y;
  310.     Bool generateEvent;
  311. {
  312.     SetupScreen(pScreen);
  313.  
  314.     pScreen->SetCursorPosition = pPrivate->SetCursorPosition;
  315.     (*pScreen->SetCursorPosition) (pScreen, x, y, generateEvent);
  316.     if (sunUseSunWindows())
  317.     if (!sunIgnoreEvent)
  318.         win_setmouseposition(windowFd, x, y);
  319.     pScreen->SetCursorPosition = sunSetCursorPosition;
  320.     return TRUE;
  321. }
  322. #endif
  323.