Cursor.c revision 05b261ec
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
29#include "Xnest.h"
30
31#include "Display.h"
32#include "Screen.h"
33#include "XNCursor.h"
34#include "Visual.h"
35#include "Keyboard.h"
36#include "Args.h"
37
38Bool
39xnestRealizeCursor(ScreenPtr pScreen, CursorPtr pCursor)
40{
41  XImage *ximage;
42  Pixmap source, mask;
43  XColor fg_color, bg_color;
44  unsigned long valuemask;
45  XGCValues values;
46
47  valuemask = GCFunction |
48              GCPlaneMask |
49	      GCForeground |
50	      GCBackground |
51	      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,
64			 pCursor->bits->height,
65			 1);
66
67  mask   = XCreatePixmap(xnestDisplay,
68			 xnestDefaultWindows[pScreen->myNum],
69			 pCursor->bits->width,
70			 pCursor->bits->height,
71			 1);
72
73  ximage = XCreateImage(xnestDisplay,
74			xnestDefaultVisual(pScreen),
75			1, XYBitmap, 0,
76			(char *)pCursor->bits->source,
77			pCursor->bits->width,
78			pCursor->bits->height,
79			BitmapPad(xnestDisplay), 0);
80
81  XPutImage(xnestDisplay, source, xnestBitmapGC, ximage,
82	    0, 0, 0, 0, pCursor->bits->width, pCursor->bits->height);
83
84  XFree(ximage);
85
86  ximage = XCreateImage(xnestDisplay,
87			xnestDefaultVisual(pScreen),
88			1, XYBitmap, 0,
89			(char *)pCursor->bits->mask,
90			pCursor->bits->width,
91			pCursor->bits->height,
92			BitmapPad(xnestDisplay), 0);
93
94  XPutImage(xnestDisplay, mask, xnestBitmapGC, ximage,
95	    0, 0, 0, 0, pCursor->bits->width, pCursor->bits->height);
96
97  XFree(ximage);
98
99  fg_color.red = pCursor->foreRed;
100  fg_color.green = pCursor->foreGreen;
101  fg_color.blue = pCursor->foreBlue;
102
103  bg_color.red = pCursor->backRed;
104  bg_color.green = pCursor->backGreen;
105  bg_color.blue = pCursor->backBlue;
106
107  pCursor->devPriv[pScreen->myNum] = (pointer)xalloc(sizeof(xnestPrivCursor));
108  xnestCursorPriv(pCursor, pScreen)->cursor =
109    XCreatePixmapCursor(xnestDisplay, source, mask, &fg_color, &bg_color,
110			pCursor->bits->xhot, pCursor->bits->yhot);
111
112  XFreePixmap(xnestDisplay, source);
113  XFreePixmap(xnestDisplay, mask);
114
115  return True;
116}
117
118Bool
119xnestUnrealizeCursor(ScreenPtr pScreen, CursorPtr pCursor)
120{
121  XFreeCursor(xnestDisplay, xnestCursor(pCursor, pScreen));
122  xfree(xnestCursorPriv(pCursor, pScreen));
123  return True;
124}
125
126void
127xnestRecolorCursor(ScreenPtr pScreen, CursorPtr pCursor, Bool displayed)
128{
129  XColor fg_color, bg_color;
130
131  fg_color.red = pCursor->foreRed;
132  fg_color.green = pCursor->foreGreen;
133  fg_color.blue = pCursor->foreBlue;
134
135  bg_color.red = pCursor->backRed;
136  bg_color.green = pCursor->backGreen;
137  bg_color.blue = pCursor->backBlue;
138
139  XRecolorCursor(xnestDisplay,
140		 xnestCursor(pCursor, pScreen),
141		 &fg_color, &bg_color);
142}
143
144void xnestSetCursor (ScreenPtr pScreen, CursorPtr pCursor, int x, int y)
145{
146    if (pCursor)
147    {
148	XDefineCursor(xnestDisplay,
149		      xnestDefaultWindows[pScreen->myNum],
150		      xnestCursor(pCursor, pScreen));
151    }
152}
153
154void
155xnestMoveCursor (ScreenPtr pScreen, int x, int y)
156{
157}
158