Imported Upstream version 1.15.1
[deb_xorg-server.git] / hw / xnest / Cursor.c
CommitLineData
a09e091a
JB
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 | GCForeground | GCBackground | GCClipMask;
52
53 values.function = GXcopy;
54 values.plane_mask = AllPlanes;
55 values.foreground = 1L;
56 values.background = 0L;
57 values.clip_mask = None;
58
59 XChangeGC(xnestDisplay, xnestBitmapGC, valuemask, &values);
60
61 source = XCreatePixmap(xnestDisplay,
62 xnestDefaultWindows[pScreen->myNum],
63 pCursor->bits->width, pCursor->bits->height, 1);
64
65 mask = XCreatePixmap(xnestDisplay,
66 xnestDefaultWindows[pScreen->myNum],
67 pCursor->bits->width, pCursor->bits->height, 1);
68
69 ximage = XCreateImage(xnestDisplay,
70 xnestDefaultVisual(pScreen),
71 1, XYBitmap, 0,
72 (char *) pCursor->bits->source,
73 pCursor->bits->width,
74 pCursor->bits->height, BitmapPad(xnestDisplay), 0);
75
76 XPutImage(xnestDisplay, source, xnestBitmapGC, ximage,
77 0, 0, 0, 0, pCursor->bits->width, pCursor->bits->height);
78
79 XFree(ximage);
80
81 ximage = XCreateImage(xnestDisplay,
82 xnestDefaultVisual(pScreen),
83 1, XYBitmap, 0,
84 (char *) pCursor->bits->mask,
85 pCursor->bits->width,
86 pCursor->bits->height, BitmapPad(xnestDisplay), 0);
87
88 XPutImage(xnestDisplay, mask, xnestBitmapGC, ximage,
89 0, 0, 0, 0, pCursor->bits->width, pCursor->bits->height);
90
91 XFree(ximage);
92
93 fg_color.red = pCursor->foreRed;
94 fg_color.green = pCursor->foreGreen;
95 fg_color.blue = pCursor->foreBlue;
96
97 bg_color.red = pCursor->backRed;
98 bg_color.green = pCursor->backGreen;
99 bg_color.blue = pCursor->backBlue;
100
101 xnestSetCursorPriv(pCursor, pScreen, malloc(sizeof(xnestPrivCursor)));
102 xnestCursor(pCursor, pScreen) =
103 XCreatePixmapCursor(xnestDisplay, source, mask, &fg_color, &bg_color,
104 pCursor->bits->xhot, pCursor->bits->yhot);
105
106 XFreePixmap(xnestDisplay, source);
107 XFreePixmap(xnestDisplay, mask);
108
109 return True;
110}
111
112Bool
113xnestUnrealizeCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor)
114{
115 XFreeCursor(xnestDisplay, xnestCursor(pCursor, pScreen));
116 free(xnestGetCursorPriv(pCursor, pScreen));
117 return True;
118}
119
120void
121xnestRecolorCursor(ScreenPtr pScreen, CursorPtr pCursor, Bool displayed)
122{
123 XColor fg_color, bg_color;
124
125 fg_color.red = pCursor->foreRed;
126 fg_color.green = pCursor->foreGreen;
127 fg_color.blue = pCursor->foreBlue;
128
129 bg_color.red = pCursor->backRed;
130 bg_color.green = pCursor->backGreen;
131 bg_color.blue = pCursor->backBlue;
132
133 XRecolorCursor(xnestDisplay,
134 xnestCursor(pCursor, pScreen), &fg_color, &bg_color);
135}
136
137void
138xnestSetCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor, int x,
139 int y)
140{
141 if (pCursor) {
142 XDefineCursor(xnestDisplay,
143 xnestDefaultWindows[pScreen->myNum],
144 xnestCursor(pCursor, pScreen));
145 }
146}
147
148void
149xnestMoveCursor(DeviceIntPtr pDev, ScreenPtr pScreen, int x, int y)
150{
151}
152
153Bool
154xnestDeviceCursorInitialize(DeviceIntPtr pDev, ScreenPtr pScreen)
155{
156 xnestCursorFuncPtr pScreenPriv;
157
158 pScreenPriv = (xnestCursorFuncPtr)
159 dixLookupPrivate(&pScreen->devPrivates, xnestCursorScreenKey);
160
161 return pScreenPriv->spriteFuncs->DeviceCursorInitialize(pDev, pScreen);
162}
163
164void
165xnestDeviceCursorCleanup(DeviceIntPtr pDev, ScreenPtr pScreen)
166{
167 xnestCursorFuncPtr pScreenPriv;
168
169 pScreenPriv = (xnestCursorFuncPtr)
170 dixLookupPrivate(&pScreen->devPrivates, xnestCursorScreenKey);
171
172 pScreenPriv->spriteFuncs->DeviceCursorCleanup(pDev, pScreen);
173}