1998-12-07 10:13:40 +01:00
|
|
|
/*
|
1998-12-26 13:00:43 +01:00
|
|
|
* X11 mouse driver
|
1998-12-07 10:13:40 +01:00
|
|
|
*
|
1998-12-26 13:00:43 +01:00
|
|
|
* Copyright 1998 Ulrich Weigand
|
1998-12-07 10:13:40 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#ifndef X_DISPLAY_MISSING
|
|
|
|
|
1998-12-26 13:00:43 +01:00
|
|
|
#include "ts_xlib.h"
|
|
|
|
|
|
|
|
#include "callback.h"
|
1999-07-04 18:02:24 +02:00
|
|
|
#include "debugtools.h"
|
1999-04-01 10:16:08 +02:00
|
|
|
#include "mouse.h"
|
1999-02-04 12:11:01 +01:00
|
|
|
#include "win.h"
|
1999-03-14 17:35:05 +01:00
|
|
|
#include "windef.h"
|
1998-12-07 10:13:40 +01:00
|
|
|
#include "x11drv.h"
|
|
|
|
|
1999-04-19 16:56:29 +02:00
|
|
|
DEFAULT_DEBUG_CHANNEL(cursor)
|
|
|
|
|
1998-12-26 13:00:43 +01:00
|
|
|
/**********************************************************************/
|
|
|
|
|
1999-02-04 12:11:01 +01:00
|
|
|
Cursor X11DRV_MOUSE_XCursor = None; /* Current X cursor */
|
1998-12-26 13:00:43 +01:00
|
|
|
|
1999-04-10 18:37:03 +02:00
|
|
|
static BOOL X11DRV_MOUSE_WarpPointer = TRUE; /* hack; see DISPLAY_MoveCursor */
|
1998-12-26 13:00:43 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* X11DRV_MOUSE_DoSetCursor
|
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
static BOOL X11DRV_MOUSE_DoSetCursor( CURSORICONINFO *ptr )
|
1998-12-26 13:00:43 +01:00
|
|
|
{
|
1999-07-24 14:16:58 +02:00
|
|
|
Pixmap pixmapBits, pixmapMask, pixmapMaskInv, pixmapAll;
|
1998-12-26 13:00:43 +01:00
|
|
|
XColor fg, bg;
|
|
|
|
Cursor cursor = None;
|
|
|
|
|
|
|
|
if (!ptr) /* Create an empty cursor */
|
|
|
|
{
|
|
|
|
static const char data[] = { 0 };
|
|
|
|
|
|
|
|
bg.red = bg.green = bg.blue = 0x0000;
|
1999-02-04 12:11:01 +01:00
|
|
|
pixmapBits = XCreateBitmapFromData( display, X11DRV_GetXRootWindow(), data, 1, 1 );
|
1998-12-26 13:00:43 +01:00
|
|
|
if (pixmapBits)
|
|
|
|
{
|
|
|
|
cursor = XCreatePixmapCursor( display, pixmapBits, pixmapBits,
|
|
|
|
&bg, &bg, 0, 0 );
|
|
|
|
XFreePixmap( display, pixmapBits );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else /* Create the X cursor from the bits */
|
|
|
|
{
|
|
|
|
XImage *image;
|
|
|
|
|
|
|
|
if (ptr->bPlanes * ptr->bBitsPerPixel != 1)
|
|
|
|
{
|
1999-07-04 18:02:24 +02:00
|
|
|
WARN("Cursor has more than 1 bpp!\n" );
|
1998-12-26 13:00:43 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create a pixmap and transfer all the bits to it */
|
|
|
|
|
|
|
|
/* NOTE: Following hack works, but only because XFree depth
|
|
|
|
* 1 images really use 1 bit/pixel (and so the same layout
|
|
|
|
* as the Windows cursor data). Perhaps use a more generic
|
|
|
|
* algorithm here.
|
|
|
|
*/
|
1999-02-04 12:11:01 +01:00
|
|
|
pixmapAll = XCreatePixmap( display, X11DRV_GetXRootWindow(),
|
1998-12-26 13:00:43 +01:00
|
|
|
ptr->nWidth, ptr->nHeight * 2, 1 );
|
1999-02-04 12:11:01 +01:00
|
|
|
image = XCreateImage( display, DefaultVisualOfScreen(X11DRV_GetXScreen()),
|
1998-12-26 13:00:43 +01:00
|
|
|
1, ZPixmap, 0, (char *)(ptr + 1), ptr->nWidth,
|
|
|
|
ptr->nHeight * 2, 16, ptr->nWidthBytes);
|
|
|
|
if (image)
|
|
|
|
{
|
|
|
|
image->byte_order = MSBFirst;
|
|
|
|
image->bitmap_bit_order = MSBFirst;
|
|
|
|
image->bitmap_unit = 16;
|
|
|
|
_XInitImageFuncPtrs(image);
|
|
|
|
if (pixmapAll)
|
|
|
|
XPutImage( display, pixmapAll, BITMAP_monoGC, image,
|
|
|
|
0, 0, 0, 0, ptr->nWidth, ptr->nHeight * 2 );
|
|
|
|
image->data = NULL;
|
|
|
|
XDestroyImage( image );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now create the 2 pixmaps for bits and mask */
|
|
|
|
|
1999-02-04 12:11:01 +01:00
|
|
|
pixmapBits = XCreatePixmap( display, X11DRV_GetXRootWindow(),
|
1998-12-26 13:00:43 +01:00
|
|
|
ptr->nWidth, ptr->nHeight, 1 );
|
1999-02-04 12:11:01 +01:00
|
|
|
pixmapMask = XCreatePixmap( display, X11DRV_GetXRootWindow(),
|
1998-12-26 13:00:43 +01:00
|
|
|
ptr->nWidth, ptr->nHeight, 1 );
|
1999-07-24 14:16:58 +02:00
|
|
|
pixmapMaskInv = XCreatePixmap( display, X11DRV_GetXRootWindow(),
|
|
|
|
ptr->nWidth, ptr->nHeight, 1 );
|
1998-12-26 13:00:43 +01:00
|
|
|
|
|
|
|
/* Make sure everything went OK so far */
|
|
|
|
|
|
|
|
if (pixmapBits && pixmapMask && pixmapAll)
|
|
|
|
{
|
|
|
|
/* We have to do some magic here, as cursors are not fully
|
|
|
|
* compatible between Windows and X11. Under X11, there
|
|
|
|
* are only 3 possible color cursor: black, white and
|
|
|
|
* masked. So we map the 4th Windows color (invert the
|
1999-07-24 14:16:58 +02:00
|
|
|
* bits on the screen) to black and an additional white bit on
|
|
|
|
* an other place (+1,+1). This require some boolean arithmetic:
|
1998-12-26 13:00:43 +01:00
|
|
|
*
|
|
|
|
* Windows | X11
|
1999-07-24 14:16:58 +02:00
|
|
|
* And Xor Result | Bits Mask Result
|
1998-12-26 13:00:43 +01:00
|
|
|
* 0 0 black | 0 1 background
|
1999-07-24 14:16:58 +02:00
|
|
|
* 0 1 white | 1 1 foreground
|
|
|
|
* 1 0 no change | X 0 no change
|
1998-12-26 13:00:43 +01:00
|
|
|
* 1 1 inverted | 0 1 background
|
|
|
|
*
|
|
|
|
* which gives:
|
1999-07-24 14:16:58 +02:00
|
|
|
* Bits = not 'And' and 'Xor' or 'And2' and 'Xor2'
|
|
|
|
* Mask = not 'And' or 'Xor' or 'And2' and 'Xor2'
|
1998-12-26 13:00:43 +01:00
|
|
|
*
|
|
|
|
* FIXME: apparently some servers do support 'inverted' color.
|
|
|
|
* I don't know if it's correct per the X spec, but maybe
|
|
|
|
* we ought to take advantage of it. -- AJ
|
|
|
|
*/
|
1999-07-24 14:16:58 +02:00
|
|
|
XSetFunction( display, BITMAP_monoGC, GXcopy );
|
1998-12-26 13:00:43 +01:00
|
|
|
XCopyArea( display, pixmapAll, pixmapBits, BITMAP_monoGC,
|
|
|
|
0, 0, ptr->nWidth, ptr->nHeight, 0, 0 );
|
|
|
|
XCopyArea( display, pixmapAll, pixmapMask, BITMAP_monoGC,
|
|
|
|
0, 0, ptr->nWidth, ptr->nHeight, 0, 0 );
|
1999-07-24 14:16:58 +02:00
|
|
|
XCopyArea( display, pixmapAll, pixmapMaskInv, BITMAP_monoGC,
|
|
|
|
0, 0, ptr->nWidth, ptr->nHeight, 0, 0 );
|
|
|
|
XSetFunction( display, BITMAP_monoGC, GXand );
|
|
|
|
XCopyArea( display, pixmapAll, pixmapMaskInv, BITMAP_monoGC,
|
|
|
|
0, ptr->nHeight, ptr->nWidth, ptr->nHeight, 0, 0 );
|
1998-12-26 13:00:43 +01:00
|
|
|
XSetFunction( display, BITMAP_monoGC, GXandReverse );
|
|
|
|
XCopyArea( display, pixmapAll, pixmapBits, BITMAP_monoGC,
|
|
|
|
0, ptr->nHeight, ptr->nWidth, ptr->nHeight, 0, 0 );
|
|
|
|
XSetFunction( display, BITMAP_monoGC, GXorReverse );
|
|
|
|
XCopyArea( display, pixmapAll, pixmapMask, BITMAP_monoGC,
|
|
|
|
0, ptr->nHeight, ptr->nWidth, ptr->nHeight, 0, 0 );
|
1999-07-24 14:16:58 +02:00
|
|
|
/* Additional white */
|
|
|
|
XSetFunction( display, BITMAP_monoGC, GXor );
|
|
|
|
XCopyArea( display, pixmapMaskInv, pixmapMask, BITMAP_monoGC,
|
|
|
|
0, 0, ptr->nWidth, ptr->nHeight, 1, 1 );
|
|
|
|
XCopyArea( display, pixmapMaskInv, pixmapBits, BITMAP_monoGC,
|
|
|
|
0, 0, ptr->nWidth, ptr->nHeight, 1, 1 );
|
1998-12-26 13:00:43 +01:00
|
|
|
XSetFunction( display, BITMAP_monoGC, GXcopy );
|
|
|
|
fg.red = fg.green = fg.blue = 0xffff;
|
|
|
|
bg.red = bg.green = bg.blue = 0x0000;
|
|
|
|
cursor = XCreatePixmapCursor( display, pixmapBits, pixmapMask,
|
|
|
|
&fg, &bg, ptr->ptHotSpot.x, ptr->ptHotSpot.y );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now free everything */
|
|
|
|
|
|
|
|
if (pixmapAll) XFreePixmap( display, pixmapAll );
|
|
|
|
if (pixmapBits) XFreePixmap( display, pixmapBits );
|
|
|
|
if (pixmapMask) XFreePixmap( display, pixmapMask );
|
1999-07-24 14:16:58 +02:00
|
|
|
if (pixmapMaskInv) XFreePixmap( display, pixmapMaskInv );
|
1998-12-26 13:00:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (cursor == None) return FALSE;
|
1999-02-04 12:11:01 +01:00
|
|
|
if (X11DRV_MOUSE_XCursor != None) XFreeCursor( display, X11DRV_MOUSE_XCursor );
|
|
|
|
X11DRV_MOUSE_XCursor = cursor;
|
1998-12-26 13:00:43 +01:00
|
|
|
|
1999-06-13 10:35:26 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* X11DRV_MOUSE_SetCursor
|
|
|
|
*/
|
|
|
|
void X11DRV_MOUSE_SetCursor( CURSORICONINFO *lpCursor )
|
|
|
|
{
|
|
|
|
BOOL success;
|
|
|
|
|
|
|
|
EnterCriticalSection( &X11DRV_CritSection );
|
|
|
|
success = CALL_LARGE_STACK( X11DRV_MOUSE_DoSetCursor, lpCursor );
|
|
|
|
LeaveCriticalSection( &X11DRV_CritSection );
|
|
|
|
if ( !success ) return;
|
|
|
|
|
|
|
|
if (X11DRV_GetXRootWindow() != DefaultRootWindow(display))
|
1998-12-26 13:00:43 +01:00
|
|
|
{
|
1999-06-13 10:35:26 +02:00
|
|
|
/* If in desktop mode, set the cursor on the desktop window */
|
|
|
|
|
|
|
|
XDefineCursor( display, X11DRV_GetXRootWindow(), X11DRV_MOUSE_XCursor );
|
1998-12-26 13:00:43 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1999-06-13 10:35:26 +02:00
|
|
|
/* Else, set the same cursor for all top-level windows */
|
|
|
|
|
|
|
|
/* FIXME: we should not reference USER internals here, but native USER
|
|
|
|
works only in desktop mode anyway, so this should not matter */
|
1998-12-26 13:00:43 +01:00
|
|
|
|
1999-02-26 12:11:13 +01:00
|
|
|
HWND hwnd = GetWindow( GetDesktopWindow(), GW_CHILD );
|
1998-12-26 13:00:43 +01:00
|
|
|
while(hwnd)
|
|
|
|
{
|
1999-03-14 18:25:32 +01:00
|
|
|
WND *tmpWnd = WIN_FindWndPtr(hwnd);
|
|
|
|
Window win = X11DRV_WND_FindXWindow(tmpWnd );
|
1998-12-26 13:00:43 +01:00
|
|
|
if (win && win!=DefaultRootWindow(display))
|
1999-06-13 10:35:26 +02:00
|
|
|
XDefineCursor( display, win, X11DRV_MOUSE_XCursor );
|
1999-02-26 12:11:13 +01:00
|
|
|
hwnd = GetWindow( hwnd, GW_HWNDNEXT );
|
1999-03-14 18:25:32 +01:00
|
|
|
WIN_ReleaseWndPtr(tmpWnd);
|
1998-12-26 13:00:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* X11DRV_MOUSE_MoveCursor
|
|
|
|
*/
|
|
|
|
void X11DRV_MOUSE_MoveCursor(WORD wAbsX, WORD wAbsY)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* We do not want the to create MotionNotify events here,
|
|
|
|
* otherwise we will get an endless recursion:
|
|
|
|
* XMotionEvent -> MOUSEEVENTF_MOVE -> mouse_event -> DisplayMoveCursor
|
|
|
|
* -> XWarpPointer -> XMotionEvent -> ...
|
|
|
|
*
|
|
|
|
* Unfortunately, the XWarpPointer call does create a MotionNotify
|
|
|
|
* event. So, we use a hack: before MOUSE_SendEvent calls the mouse event
|
|
|
|
* procedure, it sets a global flag. If this flag is set, we skip the
|
|
|
|
* XWarpPointer call. If we are *not* called from within MOUSE_SendEvent,
|
|
|
|
* we will call XWarpPointer, which will create a MotionNotify event.
|
|
|
|
* Strictly speaking, this is also wrong, but that should normally not
|
|
|
|
* have any negative effects ...
|
|
|
|
*
|
|
|
|
* But first of all, we check whether we already are at the position
|
|
|
|
* are supposed to move to; if so, we don't need to do anything.
|
|
|
|
*/
|
|
|
|
|
|
|
|
Window root, child;
|
|
|
|
int rootX, rootY, winX, winY;
|
|
|
|
unsigned int xstate;
|
|
|
|
|
1999-04-01 10:16:08 +02:00
|
|
|
if (!X11DRV_MOUSE_WarpPointer) return;
|
1998-12-26 13:00:43 +01:00
|
|
|
|
1999-02-04 12:11:01 +01:00
|
|
|
if (!TSXQueryPointer( display, X11DRV_GetXRootWindow(), &root, &child,
|
1998-12-26 13:00:43 +01:00
|
|
|
&rootX, &rootY, &winX, &winY, &xstate ))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( winX == wAbsX && winY == wAbsY )
|
|
|
|
return;
|
|
|
|
|
1999-07-04 18:02:24 +02:00
|
|
|
TRACE("(%d,%d): moving from (%d,%d)\n", wAbsX, wAbsY, winX, winY );
|
1998-12-26 13:00:43 +01:00
|
|
|
|
1999-02-04 12:11:01 +01:00
|
|
|
TSXWarpPointer( display, X11DRV_GetXRootWindow(), X11DRV_GetXRootWindow(),
|
|
|
|
0, 0, 0, 0, wAbsX, wAbsY );
|
1998-12-26 13:00:43 +01:00
|
|
|
}
|
|
|
|
|
1999-04-01 10:16:08 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* X11DRV_MOUSE_EnableWarpPointer
|
|
|
|
*/
|
|
|
|
BOOL X11DRV_MOUSE_EnableWarpPointer(BOOL bEnable)
|
|
|
|
{
|
|
|
|
BOOL bOldEnable = X11DRV_MOUSE_WarpPointer;
|
|
|
|
|
|
|
|
X11DRV_MOUSE_WarpPointer = bEnable;
|
|
|
|
|
|
|
|
return bOldEnable;
|
|
|
|
}
|
|
|
|
|
1998-12-07 10:13:40 +01:00
|
|
|
#endif /* !defined(X_DISPLAY_MISSING) */
|