105b261ecSmrg/*
205b261ecSmrg
305b261ecSmrgCopyright 1993 by Davor Matic
405b261ecSmrg
505b261ecSmrgPermission to use, copy, modify, distribute, and sell this software
605b261ecSmrgand its documentation for any purpose is hereby granted without fee,
705b261ecSmrgprovided that the above copyright notice appear in all copies and that
805b261ecSmrgboth that copyright notice and this permission notice appear in
905b261ecSmrgsupporting documentation.  Davor Matic makes no representations about
1005b261ecSmrgthe suitability of this software for any purpose.  It is provided "as
1105b261ecSmrgis" without express or implied warranty.
1205b261ecSmrg
1305b261ecSmrg*/
1405b261ecSmrg
1505b261ecSmrg#ifdef HAVE_XNEST_CONFIG_H
1605b261ecSmrg#include <xnest-config.h>
1705b261ecSmrg#endif
1805b261ecSmrg
1905b261ecSmrg#include <X11/X.h>
2005b261ecSmrg#include <X11/Xproto.h>
2105b261ecSmrg#include "screenint.h"
2205b261ecSmrg#include "input.h"
2305b261ecSmrg#include "misc.h"
2405b261ecSmrg#include "cursor.h"
2505b261ecSmrg#include "cursorstr.h"
2605b261ecSmrg#include "scrnintstr.h"
2705b261ecSmrg#include "servermd.h"
284642e01fSmrg#include "mipointrst.h"
2905b261ecSmrg
3005b261ecSmrg#include "Xnest.h"
3105b261ecSmrg
3205b261ecSmrg#include "Display.h"
3305b261ecSmrg#include "Screen.h"
3405b261ecSmrg#include "XNCursor.h"
3505b261ecSmrg#include "Visual.h"
3605b261ecSmrg#include "Keyboard.h"
3705b261ecSmrg#include "Args.h"
3805b261ecSmrg
3935c4bbdfSmrgxnestCursorFuncRec xnestCursorFuncs = { NULL };
404642e01fSmrg
4105b261ecSmrgBool
424642e01fSmrgxnestRealizeCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor)
4305b261ecSmrg{
4435c4bbdfSmrg    XImage *ximage;
4535c4bbdfSmrg    Pixmap source, mask;
4635c4bbdfSmrg    XColor fg_color, bg_color;
4735c4bbdfSmrg    unsigned long valuemask;
4835c4bbdfSmrg    XGCValues values;
4935c4bbdfSmrg
5035c4bbdfSmrg    valuemask = GCFunction |
5135c4bbdfSmrg        GCPlaneMask | GCForeground | GCBackground | GCClipMask;
5235c4bbdfSmrg
5335c4bbdfSmrg    values.function = GXcopy;
5435c4bbdfSmrg    values.plane_mask = AllPlanes;
5535c4bbdfSmrg    values.foreground = 1L;
5635c4bbdfSmrg    values.background = 0L;
5735c4bbdfSmrg    values.clip_mask = None;
5835c4bbdfSmrg
5935c4bbdfSmrg    XChangeGC(xnestDisplay, xnestBitmapGC, valuemask, &values);
6035c4bbdfSmrg
6135c4bbdfSmrg    source = XCreatePixmap(xnestDisplay,
6235c4bbdfSmrg                           xnestDefaultWindows[pScreen->myNum],
6335c4bbdfSmrg                           pCursor->bits->width, pCursor->bits->height, 1);
6435c4bbdfSmrg
6535c4bbdfSmrg    mask = XCreatePixmap(xnestDisplay,
6635c4bbdfSmrg                         xnestDefaultWindows[pScreen->myNum],
6735c4bbdfSmrg                         pCursor->bits->width, pCursor->bits->height, 1);
6835c4bbdfSmrg
6935c4bbdfSmrg    ximage = XCreateImage(xnestDisplay,
7035c4bbdfSmrg                          xnestDefaultVisual(pScreen),
7135c4bbdfSmrg                          1, XYBitmap, 0,
7235c4bbdfSmrg                          (char *) pCursor->bits->source,
7335c4bbdfSmrg                          pCursor->bits->width,
7435c4bbdfSmrg                          pCursor->bits->height, BitmapPad(xnestDisplay), 0);
7535c4bbdfSmrg
7635c4bbdfSmrg    XPutImage(xnestDisplay, source, xnestBitmapGC, ximage,
7735c4bbdfSmrg              0, 0, 0, 0, pCursor->bits->width, pCursor->bits->height);
7835c4bbdfSmrg
7935c4bbdfSmrg    XFree(ximage);
8035c4bbdfSmrg
8135c4bbdfSmrg    ximage = XCreateImage(xnestDisplay,
8235c4bbdfSmrg                          xnestDefaultVisual(pScreen),
8335c4bbdfSmrg                          1, XYBitmap, 0,
8435c4bbdfSmrg                          (char *) pCursor->bits->mask,
8535c4bbdfSmrg                          pCursor->bits->width,
8635c4bbdfSmrg                          pCursor->bits->height, BitmapPad(xnestDisplay), 0);
8735c4bbdfSmrg
8835c4bbdfSmrg    XPutImage(xnestDisplay, mask, xnestBitmapGC, ximage,
8935c4bbdfSmrg              0, 0, 0, 0, pCursor->bits->width, pCursor->bits->height);
9035c4bbdfSmrg
9135c4bbdfSmrg    XFree(ximage);
9235c4bbdfSmrg
9335c4bbdfSmrg    fg_color.red = pCursor->foreRed;
9435c4bbdfSmrg    fg_color.green = pCursor->foreGreen;
9535c4bbdfSmrg    fg_color.blue = pCursor->foreBlue;
9635c4bbdfSmrg
9735c4bbdfSmrg    bg_color.red = pCursor->backRed;
9835c4bbdfSmrg    bg_color.green = pCursor->backGreen;
9935c4bbdfSmrg    bg_color.blue = pCursor->backBlue;
10035c4bbdfSmrg
10158cf2af7Smrg    xnestSetCursorPriv(pCursor, pScreen, calloc(1, sizeof(xnestPrivCursor)));
10235c4bbdfSmrg    xnestCursor(pCursor, pScreen) =
10335c4bbdfSmrg        XCreatePixmapCursor(xnestDisplay, source, mask, &fg_color, &bg_color,
10435c4bbdfSmrg                            pCursor->bits->xhot, pCursor->bits->yhot);
10535c4bbdfSmrg
10635c4bbdfSmrg    XFreePixmap(xnestDisplay, source);
10735c4bbdfSmrg    XFreePixmap(xnestDisplay, mask);
10835c4bbdfSmrg
10935c4bbdfSmrg    return True;
11005b261ecSmrg}
11105b261ecSmrg
11205b261ecSmrgBool
1134642e01fSmrgxnestUnrealizeCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor)
11405b261ecSmrg{
11535c4bbdfSmrg    XFreeCursor(xnestDisplay, xnestCursor(pCursor, pScreen));
11635c4bbdfSmrg    free(xnestGetCursorPriv(pCursor, pScreen));
11735c4bbdfSmrg    return True;
11805b261ecSmrg}
11905b261ecSmrg
12005b261ecSmrgvoid
12105b261ecSmrgxnestRecolorCursor(ScreenPtr pScreen, CursorPtr pCursor, Bool displayed)
12205b261ecSmrg{
12335c4bbdfSmrg    XColor fg_color, bg_color;
12435c4bbdfSmrg
12535c4bbdfSmrg    fg_color.red = pCursor->foreRed;
12635c4bbdfSmrg    fg_color.green = pCursor->foreGreen;
12735c4bbdfSmrg    fg_color.blue = pCursor->foreBlue;
12835c4bbdfSmrg
12935c4bbdfSmrg    bg_color.red = pCursor->backRed;
13035c4bbdfSmrg    bg_color.green = pCursor->backGreen;
13135c4bbdfSmrg    bg_color.blue = pCursor->backBlue;
13235c4bbdfSmrg
13335c4bbdfSmrg    XRecolorCursor(xnestDisplay,
13435c4bbdfSmrg                   xnestCursor(pCursor, pScreen), &fg_color, &bg_color);
13505b261ecSmrg}
13605b261ecSmrg
13735c4bbdfSmrgvoid
13835c4bbdfSmrgxnestSetCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor, int x,
13935c4bbdfSmrg               int y)
14005b261ecSmrg{
14135c4bbdfSmrg    if (pCursor) {
14235c4bbdfSmrg        XDefineCursor(xnestDisplay,
14335c4bbdfSmrg                      xnestDefaultWindows[pScreen->myNum],
14435c4bbdfSmrg                      xnestCursor(pCursor, pScreen));
14505b261ecSmrg    }
14605b261ecSmrg}
14705b261ecSmrg
14805b261ecSmrgvoid
14935c4bbdfSmrgxnestMoveCursor(DeviceIntPtr pDev, ScreenPtr pScreen, int x, int y)
15005b261ecSmrg{
15105b261ecSmrg}
1524642e01fSmrg
1534642e01fSmrgBool
1544642e01fSmrgxnestDeviceCursorInitialize(DeviceIntPtr pDev, ScreenPtr pScreen)
1554642e01fSmrg{
1564642e01fSmrg    xnestCursorFuncPtr pScreenPriv;
1574642e01fSmrg
1584642e01fSmrg    pScreenPriv = (xnestCursorFuncPtr)
15935c4bbdfSmrg        dixLookupPrivate(&pScreen->devPrivates, xnestCursorScreenKey);
1604642e01fSmrg
1616747b715Smrg    return pScreenPriv->spriteFuncs->DeviceCursorInitialize(pDev, pScreen);
1624642e01fSmrg}
1634642e01fSmrg
1644642e01fSmrgvoid
1654642e01fSmrgxnestDeviceCursorCleanup(DeviceIntPtr pDev, ScreenPtr pScreen)
1664642e01fSmrg{
1674642e01fSmrg    xnestCursorFuncPtr pScreenPriv;
1684642e01fSmrg
1694642e01fSmrg    pScreenPriv = (xnestCursorFuncPtr)
17035c4bbdfSmrg        dixLookupPrivate(&pScreen->devPrivates, xnestCursorScreenKey);
1714642e01fSmrg
1724642e01fSmrg    pScreenPriv->spriteFuncs->DeviceCursorCleanup(pDev, pScreen);
1734642e01fSmrg}
174