1706f2543Smrg/*
2706f2543Smrg
3706f2543SmrgCopyright 1993 by Davor Matic
4706f2543Smrg
5706f2543SmrgPermission to use, copy, modify, distribute, and sell this software
6706f2543Smrgand its documentation for any purpose is hereby granted without fee,
7706f2543Smrgprovided that the above copyright notice appear in all copies and that
8706f2543Smrgboth that copyright notice and this permission notice appear in
9706f2543Smrgsupporting documentation.  Davor Matic makes no representations about
10706f2543Smrgthe suitability of this software for any purpose.  It is provided "as
11706f2543Smrgis" without express or implied warranty.
12706f2543Smrg
13706f2543Smrg*/
14706f2543Smrg
15706f2543Smrg#ifdef HAVE_XNEST_CONFIG_H
16706f2543Smrg#include <xnest-config.h>
17706f2543Smrg#endif
18706f2543Smrg
19706f2543Smrg#include <X11/X.h>
20706f2543Smrg#include <X11/Xproto.h>
21706f2543Smrg#include "screenint.h"
22706f2543Smrg#include "input.h"
23706f2543Smrg#include "misc.h"
24706f2543Smrg#include "cursor.h"
25706f2543Smrg#include "cursorstr.h"
26706f2543Smrg#include "scrnintstr.h"
27706f2543Smrg#include "servermd.h"
28706f2543Smrg#include "mipointrst.h"
29706f2543Smrg
30706f2543Smrg#include "Xnest.h"
31706f2543Smrg
32706f2543Smrg#include "Display.h"
33706f2543Smrg#include "Screen.h"
34706f2543Smrg#include "XNCursor.h"
35706f2543Smrg#include "Visual.h"
36706f2543Smrg#include "Keyboard.h"
37706f2543Smrg#include "Args.h"
38706f2543Smrg
39706f2543SmrgxnestCursorFuncRec xnestCursorFuncs = {NULL};
40706f2543Smrg
41706f2543SmrgBool
42706f2543SmrgxnestRealizeCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor)
43706f2543Smrg{
44706f2543Smrg  XImage *ximage;
45706f2543Smrg  Pixmap source, mask;
46706f2543Smrg  XColor fg_color, bg_color;
47706f2543Smrg  unsigned long valuemask;
48706f2543Smrg  XGCValues values;
49706f2543Smrg
50706f2543Smrg  valuemask = GCFunction |
51706f2543Smrg              GCPlaneMask |
52706f2543Smrg	      GCForeground |
53706f2543Smrg	      GCBackground |
54706f2543Smrg	      GCClipMask;
55706f2543Smrg
56706f2543Smrg  values.function = GXcopy;
57706f2543Smrg  values.plane_mask = AllPlanes;
58706f2543Smrg  values.foreground = 1L;
59706f2543Smrg  values.background = 0L;
60706f2543Smrg  values.clip_mask = None;
61706f2543Smrg
62706f2543Smrg  XChangeGC(xnestDisplay, xnestBitmapGC, valuemask, &values);
63706f2543Smrg
64706f2543Smrg  source = XCreatePixmap(xnestDisplay,
65706f2543Smrg			 xnestDefaultWindows[pScreen->myNum],
66706f2543Smrg			 pCursor->bits->width,
67706f2543Smrg			 pCursor->bits->height,
68706f2543Smrg			 1);
69706f2543Smrg
70706f2543Smrg  mask   = XCreatePixmap(xnestDisplay,
71706f2543Smrg			 xnestDefaultWindows[pScreen->myNum],
72706f2543Smrg			 pCursor->bits->width,
73706f2543Smrg			 pCursor->bits->height,
74706f2543Smrg			 1);
75706f2543Smrg
76706f2543Smrg  ximage = XCreateImage(xnestDisplay,
77706f2543Smrg			xnestDefaultVisual(pScreen),
78706f2543Smrg			1, XYBitmap, 0,
79706f2543Smrg			(char *)pCursor->bits->source,
80706f2543Smrg			pCursor->bits->width,
81706f2543Smrg			pCursor->bits->height,
82706f2543Smrg			BitmapPad(xnestDisplay), 0);
83706f2543Smrg
84706f2543Smrg  XPutImage(xnestDisplay, source, xnestBitmapGC, ximage,
85706f2543Smrg	    0, 0, 0, 0, pCursor->bits->width, pCursor->bits->height);
86706f2543Smrg
87706f2543Smrg  XFree(ximage);
88706f2543Smrg
89706f2543Smrg  ximage = XCreateImage(xnestDisplay,
90706f2543Smrg			xnestDefaultVisual(pScreen),
91706f2543Smrg			1, XYBitmap, 0,
92706f2543Smrg			(char *)pCursor->bits->mask,
93706f2543Smrg			pCursor->bits->width,
94706f2543Smrg			pCursor->bits->height,
95706f2543Smrg			BitmapPad(xnestDisplay), 0);
96706f2543Smrg
97706f2543Smrg  XPutImage(xnestDisplay, mask, xnestBitmapGC, ximage,
98706f2543Smrg	    0, 0, 0, 0, pCursor->bits->width, pCursor->bits->height);
99706f2543Smrg
100706f2543Smrg  XFree(ximage);
101706f2543Smrg
102706f2543Smrg  fg_color.red = pCursor->foreRed;
103706f2543Smrg  fg_color.green = pCursor->foreGreen;
104706f2543Smrg  fg_color.blue = pCursor->foreBlue;
105706f2543Smrg
106706f2543Smrg  bg_color.red = pCursor->backRed;
107706f2543Smrg  bg_color.green = pCursor->backGreen;
108706f2543Smrg  bg_color.blue = pCursor->backBlue;
109706f2543Smrg
110706f2543Smrg  xnestSetCursorPriv(pCursor, pScreen, malloc(sizeof(xnestPrivCursor)));
111706f2543Smrg  xnestCursor(pCursor, pScreen) =
112706f2543Smrg    XCreatePixmapCursor(xnestDisplay, source, mask, &fg_color, &bg_color,
113706f2543Smrg			pCursor->bits->xhot, pCursor->bits->yhot);
114706f2543Smrg
115706f2543Smrg  XFreePixmap(xnestDisplay, source);
116706f2543Smrg  XFreePixmap(xnestDisplay, mask);
117706f2543Smrg
118706f2543Smrg  return True;
119706f2543Smrg}
120706f2543Smrg
121706f2543SmrgBool
122706f2543SmrgxnestUnrealizeCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor)
123706f2543Smrg{
124706f2543Smrg  XFreeCursor(xnestDisplay, xnestCursor(pCursor, pScreen));
125706f2543Smrg  free(xnestGetCursorPriv(pCursor, pScreen));
126706f2543Smrg  return True;
127706f2543Smrg}
128706f2543Smrg
129706f2543Smrgvoid
130706f2543SmrgxnestRecolorCursor(ScreenPtr pScreen, CursorPtr pCursor, Bool displayed)
131706f2543Smrg{
132706f2543Smrg  XColor fg_color, bg_color;
133706f2543Smrg
134706f2543Smrg  fg_color.red = pCursor->foreRed;
135706f2543Smrg  fg_color.green = pCursor->foreGreen;
136706f2543Smrg  fg_color.blue = pCursor->foreBlue;
137706f2543Smrg
138706f2543Smrg  bg_color.red = pCursor->backRed;
139706f2543Smrg  bg_color.green = pCursor->backGreen;
140706f2543Smrg  bg_color.blue = pCursor->backBlue;
141706f2543Smrg
142706f2543Smrg  XRecolorCursor(xnestDisplay,
143706f2543Smrg		 xnestCursor(pCursor, pScreen),
144706f2543Smrg		 &fg_color, &bg_color);
145706f2543Smrg}
146706f2543Smrg
147706f2543Smrgvoid xnestSetCursor (DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor, int x, int y)
148706f2543Smrg{
149706f2543Smrg    if (pCursor)
150706f2543Smrg    {
151706f2543Smrg	XDefineCursor(xnestDisplay,
152706f2543Smrg		      xnestDefaultWindows[pScreen->myNum],
153706f2543Smrg		      xnestCursor(pCursor, pScreen));
154706f2543Smrg    }
155706f2543Smrg}
156706f2543Smrg
157706f2543Smrgvoid
158706f2543SmrgxnestMoveCursor (DeviceIntPtr pDev, ScreenPtr pScreen, int x, int y)
159706f2543Smrg{
160706f2543Smrg}
161706f2543Smrg
162706f2543SmrgBool
163706f2543SmrgxnestDeviceCursorInitialize(DeviceIntPtr pDev, ScreenPtr pScreen)
164706f2543Smrg{
165706f2543Smrg    xnestCursorFuncPtr pScreenPriv;
166706f2543Smrg
167706f2543Smrg    pScreenPriv = (xnestCursorFuncPtr)
168706f2543Smrg            dixLookupPrivate(&pScreen->devPrivates, xnestCursorScreenKey);
169706f2543Smrg
170706f2543Smrg    return pScreenPriv->spriteFuncs->DeviceCursorInitialize(pDev, pScreen);
171706f2543Smrg}
172706f2543Smrg
173706f2543Smrgvoid
174706f2543SmrgxnestDeviceCursorCleanup(DeviceIntPtr pDev, ScreenPtr pScreen)
175706f2543Smrg{
176706f2543Smrg    xnestCursorFuncPtr pScreenPriv;
177706f2543Smrg
178706f2543Smrg    pScreenPriv = (xnestCursorFuncPtr)
179706f2543Smrg            dixLookupPrivate(&pScreen->devPrivates, xnestCursorScreenKey);
180706f2543Smrg
181706f2543Smrg    pScreenPriv->spriteFuncs->DeviceCursorCleanup(pDev, pScreen);
182706f2543Smrg}
183