1/*
2
3Copyright 1993 by Davor Matic
4
5Permission to use, copy, modify, distribute, and sell this software
6and its documentation for any purpose is hereby granted without fee,
7provided that the above copyright notice appear in all copies and that
8both that copyright notice and this permission notice appear in
9supporting documentation.  Davor Matic makes no representations about
10the suitability of this software for any purpose.  It is provided "as
11is" without express or implied warranty.
12
13*/
14
15#ifdef HAVE_XNEST_CONFIG_H
16#include <xnest-config.h>
17#endif
18
19#include <X11/X.h>
20#include <X11/Xproto.h>
21#include "screenint.h"
22#include "input.h"
23#include "misc.h"
24#include "cursor.h"
25#include "cursorstr.h"
26#include "scrnintstr.h"
27#include "servermd.h"
28#include "mipointrst.h"
29
30#include "Xnest.h"
31
32#include "Display.h"
33#include "Screen.h"
34#include "XNCursor.h"
35#include "Visual.h"
36#include "Keyboard.h"
37#include "Args.h"
38
39xnestCursorFuncRec xnestCursorFuncs = {NULL};
40
41Bool
42xnestRealizeCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor)
43{
44  XImage *ximage;
45  Pixmap source, mask;
46  XColor fg_color, bg_color;
47  unsigned long valuemask;
48  XGCValues values;
49
50  valuemask = GCFunction |
51              GCPlaneMask |
52	      GCForeground |
53	      GCBackground |
54	      GCClipMask;
55
56  values.function = GXcopy;
57  values.plane_mask = AllPlanes;
58  values.foreground = 1L;
59  values.background = 0L;
60  values.clip_mask = None;
61
62  XChangeGC(xnestDisplay, xnestBitmapGC, valuemask, &values);
63
64  source = XCreatePixmap(xnestDisplay,
65			 xnestDefaultWindows[pScreen->myNum],
66			 pCursor->bits->width,
67			 pCursor->bits->height,
68			 1);
69
70  mask   = XCreatePixmap(xnestDisplay,
71			 xnestDefaultWindows[pScreen->myNum],
72			 pCursor->bits->width,
73			 pCursor->bits->height,
74			 1);
75
76  ximage = XCreateImage(xnestDisplay,
77			xnestDefaultVisual(pScreen),
78			1, XYBitmap, 0,
79			(char *)pCursor->bits->source,
80			pCursor->bits->width,
81			pCursor->bits->height,
82			BitmapPad(xnestDisplay), 0);
83
84  XPutImage(xnestDisplay, source, xnestBitmapGC, ximage,
85	    0, 0, 0, 0, pCursor->bits->width, pCursor->bits->height);
86
87  XFree(ximage);
88
89  ximage = XCreateImage(xnestDisplay,
90			xnestDefaultVisual(pScreen),
91			1, XYBitmap, 0,
92			(char *)pCursor->bits->mask,
93			pCursor->bits->width,
94			pCursor->bits->height,
95			BitmapPad(xnestDisplay), 0);
96
97  XPutImage(xnestDisplay, mask, xnestBitmapGC, ximage,
98	    0, 0, 0, 0, pCursor->bits->width, pCursor->bits->height);
99
100  XFree(ximage);
101
102  fg_color.red = pCursor->foreRed;
103  fg_color.green = pCursor->foreGreen;
104  fg_color.blue = pCursor->foreBlue;
105
106  bg_color.red = pCursor->backRed;
107  bg_color.green = pCursor->backGreen;
108  bg_color.blue = pCursor->backBlue;
109
110  xnestSetCursorPriv(pCursor, pScreen, malloc(sizeof(xnestPrivCursor)));
111  xnestCursor(pCursor, pScreen) =
112    XCreatePixmapCursor(xnestDisplay, source, mask, &fg_color, &bg_color,
113			pCursor->bits->xhot, pCursor->bits->yhot);
114
115  XFreePixmap(xnestDisplay, source);
116  XFreePixmap(xnestDisplay, mask);
117
118  return True;
119}
120
121Bool
122xnestUnrealizeCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor)
123{
124  XFreeCursor(xnestDisplay, xnestCursor(pCursor, pScreen));
125  free(xnestGetCursorPriv(pCursor, pScreen));
126  return True;
127}
128
129void
130xnestRecolorCursor(ScreenPtr pScreen, CursorPtr pCursor, Bool displayed)
131{
132  XColor fg_color, bg_color;
133
134  fg_color.red = pCursor->foreRed;
135  fg_color.green = pCursor->foreGreen;
136  fg_color.blue = pCursor->foreBlue;
137
138  bg_color.red = pCursor->backRed;
139  bg_color.green = pCursor->backGreen;
140  bg_color.blue = pCursor->backBlue;
141
142  XRecolorCursor(xnestDisplay,
143		 xnestCursor(pCursor, pScreen),
144		 &fg_color, &bg_color);
145}
146
147void xnestSetCursor (DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor, int x, int y)
148{
149    if (pCursor)
150    {
151	XDefineCursor(xnestDisplay,
152		      xnestDefaultWindows[pScreen->myNum],
153		      xnestCursor(pCursor, pScreen));
154    }
155}
156
157void
158xnestMoveCursor (DeviceIntPtr pDev, ScreenPtr pScreen, int x, int y)
159{
160}
161
162Bool
163xnestDeviceCursorInitialize(DeviceIntPtr pDev, ScreenPtr pScreen)
164{
165    xnestCursorFuncPtr pScreenPriv;
166
167    pScreenPriv = (xnestCursorFuncPtr)
168            dixLookupPrivate(&pScreen->devPrivates, xnestCursorScreenKey);
169
170    return pScreenPriv->spriteFuncs->DeviceCursorInitialize(pDev, pScreen);
171}
172
173void
174xnestDeviceCursorCleanup(DeviceIntPtr pDev, ScreenPtr pScreen)
175{
176    xnestCursorFuncPtr pScreenPriv;
177
178    pScreenPriv = (xnestCursorFuncPtr)
179            dixLookupPrivate(&pScreen->devPrivates, xnestCursorScreenKey);
180
181    pScreenPriv->spriteFuncs->DeviceCursorCleanup(pDev, pScreen);
182}
183