4 * Copyright 1998 Ulrich Weigand
9 #ifndef X_DISPLAY_MISSING
18 /**********************************************************************/
20 Cursor DISPLAY_XCursor
= None
; /* Current X cursor */
22 BOOL32 DISPLAY_DisableWarpPointer
= FALSE
; /* hack; see DISPLAY_MoveCursor */
24 /***********************************************************************
25 * X11DRV_MOUSE_DoSetCursor
27 static BOOL32
X11DRV_MOUSE_DoSetCursor( CURSORICONINFO
*ptr
)
29 Pixmap pixmapBits
, pixmapMask
, pixmapAll
;
33 if (!ptr
) /* Create an empty cursor */
35 static const char data
[] = { 0 };
37 bg
.red
= bg
.green
= bg
.blue
= 0x0000;
38 pixmapBits
= XCreateBitmapFromData( display
, rootWindow
, data
, 1, 1 );
41 cursor
= XCreatePixmapCursor( display
, pixmapBits
, pixmapBits
,
43 XFreePixmap( display
, pixmapBits
);
46 else /* Create the X cursor from the bits */
50 if (ptr
->bPlanes
* ptr
->bBitsPerPixel
!= 1)
52 WARN(cursor
, "Cursor has more than 1 bpp!\n" );
56 /* Create a pixmap and transfer all the bits to it */
58 /* NOTE: Following hack works, but only because XFree depth
59 * 1 images really use 1 bit/pixel (and so the same layout
60 * as the Windows cursor data). Perhaps use a more generic
63 pixmapAll
= XCreatePixmap( display
, rootWindow
,
64 ptr
->nWidth
, ptr
->nHeight
* 2, 1 );
65 image
= XCreateImage( display
, DefaultVisualOfScreen(screen
),
66 1, ZPixmap
, 0, (char *)(ptr
+ 1), ptr
->nWidth
,
67 ptr
->nHeight
* 2, 16, ptr
->nWidthBytes
);
70 image
->byte_order
= MSBFirst
;
71 image
->bitmap_bit_order
= MSBFirst
;
72 image
->bitmap_unit
= 16;
73 _XInitImageFuncPtrs(image
);
75 XPutImage( display
, pixmapAll
, BITMAP_monoGC
, image
,
76 0, 0, 0, 0, ptr
->nWidth
, ptr
->nHeight
* 2 );
78 XDestroyImage( image
);
81 /* Now create the 2 pixmaps for bits and mask */
83 pixmapBits
= XCreatePixmap( display
, rootWindow
,
84 ptr
->nWidth
, ptr
->nHeight
, 1 );
85 pixmapMask
= XCreatePixmap( display
, rootWindow
,
86 ptr
->nWidth
, ptr
->nHeight
, 1 );
88 /* Make sure everything went OK so far */
90 if (pixmapBits
&& pixmapMask
&& pixmapAll
)
92 /* We have to do some magic here, as cursors are not fully
93 * compatible between Windows and X11. Under X11, there
94 * are only 3 possible color cursor: black, white and
95 * masked. So we map the 4th Windows color (invert the
96 * bits on the screen) to black. This require some boolean
100 * Xor And Result | Bits Mask Result
101 * 0 0 black | 0 1 background
102 * 0 1 no change | X 0 no change
103 * 1 0 white | 1 1 foreground
104 * 1 1 inverted | 0 1 background
107 * Bits = 'Xor' and not 'And'
108 * Mask = 'Xor' or not 'And'
110 * FIXME: apparently some servers do support 'inverted' color.
111 * I don't know if it's correct per the X spec, but maybe
112 * we ought to take advantage of it. -- AJ
114 XCopyArea( display
, pixmapAll
, pixmapBits
, BITMAP_monoGC
,
115 0, 0, ptr
->nWidth
, ptr
->nHeight
, 0, 0 );
116 XCopyArea( display
, pixmapAll
, pixmapMask
, BITMAP_monoGC
,
117 0, 0, ptr
->nWidth
, ptr
->nHeight
, 0, 0 );
118 XSetFunction( display
, BITMAP_monoGC
, GXandReverse
);
119 XCopyArea( display
, pixmapAll
, pixmapBits
, BITMAP_monoGC
,
120 0, ptr
->nHeight
, ptr
->nWidth
, ptr
->nHeight
, 0, 0 );
121 XSetFunction( display
, BITMAP_monoGC
, GXorReverse
);
122 XCopyArea( display
, pixmapAll
, pixmapMask
, BITMAP_monoGC
,
123 0, ptr
->nHeight
, ptr
->nWidth
, ptr
->nHeight
, 0, 0 );
124 XSetFunction( display
, BITMAP_monoGC
, GXcopy
);
125 fg
.red
= fg
.green
= fg
.blue
= 0xffff;
126 bg
.red
= bg
.green
= bg
.blue
= 0x0000;
127 cursor
= XCreatePixmapCursor( display
, pixmapBits
, pixmapMask
,
128 &fg
, &bg
, ptr
->ptHotSpot
.x
, ptr
->ptHotSpot
.y
);
131 /* Now free everything */
133 if (pixmapAll
) XFreePixmap( display
, pixmapAll
);
134 if (pixmapBits
) XFreePixmap( display
, pixmapBits
);
135 if (pixmapMask
) XFreePixmap( display
, pixmapMask
);
138 if (cursor
== None
) return FALSE
;
139 if (DISPLAY_XCursor
!= None
) XFreeCursor( display
, DISPLAY_XCursor
);
140 DISPLAY_XCursor
= cursor
;
142 if (rootWindow
!= DefaultRootWindow(display
) || !WIN_GetDesktop())
144 /* Set the cursor on the desktop window */
145 XDefineCursor( display
, rootWindow
, cursor
);
149 /* FIXME: this won't work correctly with native USER !*/
151 /* Set the same cursor for all top-level windows */
152 HWND32 hwnd
= GetWindow32( GetDesktopWindow32(), GW_CHILD
);
155 Window win
= X11DRV_WND_FindXWindow( WIN_FindWndPtr( hwnd
) );
156 if (win
&& win
!=DefaultRootWindow(display
))
157 XDefineCursor( display
, win
, cursor
);
158 hwnd
= GetWindow32( hwnd
, GW_HWNDNEXT
);
164 /***********************************************************************
165 * X11DRV_MOUSE_SetCursor
167 void X11DRV_MOUSE_SetCursor( CURSORICONINFO
*lpCursor
)
169 EnterCriticalSection( &X11DRV_CritSection
);
170 CALL_LARGE_STACK( X11DRV_MOUSE_DoSetCursor
, lpCursor
);
171 LeaveCriticalSection( &X11DRV_CritSection
);
174 /***********************************************************************
175 * X11DRV_MOUSE_MoveCursor
177 void X11DRV_MOUSE_MoveCursor(WORD wAbsX
, WORD wAbsY
)
180 * We do not want the to create MotionNotify events here,
181 * otherwise we will get an endless recursion:
182 * XMotionEvent -> MOUSEEVENTF_MOVE -> mouse_event -> DisplayMoveCursor
183 * -> XWarpPointer -> XMotionEvent -> ...
185 * Unfortunately, the XWarpPointer call does create a MotionNotify
186 * event. So, we use a hack: before MOUSE_SendEvent calls the mouse event
187 * procedure, it sets a global flag. If this flag is set, we skip the
188 * XWarpPointer call. If we are *not* called from within MOUSE_SendEvent,
189 * we will call XWarpPointer, which will create a MotionNotify event.
190 * Strictly speaking, this is also wrong, but that should normally not
191 * have any negative effects ...
193 * But first of all, we check whether we already are at the position
194 * are supposed to move to; if so, we don't need to do anything.
198 int rootX
, rootY
, winX
, winY
;
201 if (DISPLAY_DisableWarpPointer
) return;
203 if (!TSXQueryPointer( display
, rootWindow
, &root
, &child
,
204 &rootX
, &rootY
, &winX
, &winY
, &xstate
))
207 if ( winX
== wAbsX
&& winY
== wAbsY
)
210 TRACE( cursor
, "(%d,%d): moving from (%d,%d)\n", wAbsX
, wAbsY
, winX
, winY
);
212 TSXWarpPointer( display
, rootWindow
, rootWindow
, 0, 0, 0, 0, wAbsX
, wAbsY
);
215 #endif /* !defined(X_DISPLAY_MISSING) */