4 * Copyright 1998 Ulrich Weigand
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #define NONAMELESSUNION
27 #define NONAMELESSSTRUCT
30 #include "wine/winuser16.h"
34 #include "wine/server.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(cursor
);
39 /**********************************************************************/
42 #define Button6Mask (1<<13)
45 #define Button7Mask (1<<14)
48 #define NB_BUTTONS 7 /* Windows can handle 5 buttons and the wheel too */
50 static const UINT button_down_flags
[NB_BUTTONS
] =
53 MOUSEEVENTF_MIDDLEDOWN
,
54 MOUSEEVENTF_RIGHTDOWN
,
61 static const UINT button_up_flags
[NB_BUTTONS
] =
73 static DWORD last_time_modified
;
74 static RECT cursor_clip
; /* Cursor clipping rect */
76 BOOL
X11DRV_SetCursorPos( INT x
, INT y
);
78 /***********************************************************************
81 * get the coordinates of a mouse event
83 static inline void get_coords( HWND hwnd
, int x
, int y
, POINT
*pt
)
85 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
89 pt
->x
= x
+ data
->whole_rect
.left
;
90 pt
->y
= y
+ data
->whole_rect
.top
;
93 /***********************************************************************
96 * Clip point to the provided rectangle
98 static inline void clip_point_to_rect( LPCRECT rect
, LPPOINT pt
)
100 if (pt
->x
< rect
->left
) pt
->x
= rect
->left
;
101 else if (pt
->x
>= rect
->right
) pt
->x
= rect
->right
- 1;
102 if (pt
->y
< rect
->top
) pt
->y
= rect
->top
;
103 else if (pt
->y
>= rect
->bottom
) pt
->y
= rect
->bottom
- 1;
106 /***********************************************************************
107 * update_button_state
109 * Update the button state with what X provides us
111 static inline void update_button_state( unsigned int state
)
113 key_state_table
[VK_LBUTTON
] = (state
& Button1Mask
? 0x80 : 0);
114 key_state_table
[VK_MBUTTON
] = (state
& Button2Mask
? 0x80 : 0);
115 key_state_table
[VK_RBUTTON
] = (state
& Button3Mask
? 0x80 : 0);
116 /* X-buttons are not reported from XQueryPointer */
120 /***********************************************************************
123 * Update the various window states on a mouse event.
125 static void update_mouse_state( HWND hwnd
, Window window
, int x
, int y
, unsigned int state
, POINT
*pt
)
127 struct x11drv_thread_data
*data
= x11drv_thread_data();
129 if (window
== root_window
)
131 x
+= virtual_screen_rect
.left
;
132 y
+= virtual_screen_rect
.top
;
134 get_coords( hwnd
, x
, y
, pt
);
136 /* update the cursor */
138 if (data
->cursor_window
!= window
)
140 data
->cursor_window
= window
;
142 if (data
->cursor
) XDefineCursor( data
->display
, window
, data
->cursor
);
146 /* update the wine server Z-order */
148 if (window
!= data
->grab_window
&&
149 /* ignore event if a button is pressed, since the mouse is then grabbed too */
150 !(state
& (Button1Mask
|Button2Mask
|Button3Mask
|Button4Mask
|Button5Mask
|Button6Mask
|Button7Mask
)))
152 SERVER_START_REQ( update_window_zorder
)
155 req
->rect
.left
= pt
->x
;
156 req
->rect
.top
= pt
->y
;
157 req
->rect
.right
= pt
->x
+ 1;
158 req
->rect
.bottom
= pt
->y
+ 1;
159 wine_server_call( req
);
166 /***********************************************************************
169 static WORD
get_key_state(void)
173 if (GetSystemMetrics( SM_SWAPBUTTON
))
175 if (key_state_table
[VK_RBUTTON
] & 0x80) ret
|= MK_LBUTTON
;
176 if (key_state_table
[VK_LBUTTON
] & 0x80) ret
|= MK_RBUTTON
;
180 if (key_state_table
[VK_LBUTTON
] & 0x80) ret
|= MK_LBUTTON
;
181 if (key_state_table
[VK_RBUTTON
] & 0x80) ret
|= MK_RBUTTON
;
183 if (key_state_table
[VK_MBUTTON
] & 0x80) ret
|= MK_MBUTTON
;
184 if (key_state_table
[VK_SHIFT
] & 0x80) ret
|= MK_SHIFT
;
185 if (key_state_table
[VK_CONTROL
] & 0x80) ret
|= MK_CONTROL
;
186 if (key_state_table
[VK_XBUTTON1
] & 0x80) ret
|= MK_XBUTTON1
;
187 if (key_state_table
[VK_XBUTTON2
] & 0x80) ret
|= MK_XBUTTON2
;
192 /***********************************************************************
193 * queue_raw_mouse_message
195 static void queue_raw_mouse_message( UINT message
, HWND hwnd
, DWORD x
, DWORD y
,
196 DWORD data
, DWORD time
, DWORD extra_info
, UINT injected_flags
)
202 hook
.mouseData
= MAKELONG( 0, data
);
203 hook
.flags
= injected_flags
;
205 hook
.dwExtraInfo
= extra_info
;
207 last_time_modified
= GetTickCount();
208 if (HOOK_CallHooks( WH_MOUSE_LL
, HC_ACTION
, message
, (LPARAM
)&hook
, TRUE
)) return;
210 SERVER_START_REQ( send_hardware_message
)
212 req
->id
= (injected_flags
& LLMHF_INJECTED
) ? 0 : GetCurrentThreadId();
215 req
->wparam
= MAKEWPARAM( get_key_state(), data
);
220 req
->info
= extra_info
;
221 wine_server_call( req
);
228 /***********************************************************************
229 * X11DRV_send_mouse_input
231 void X11DRV_send_mouse_input( HWND hwnd
, DWORD flags
, DWORD x
, DWORD y
,
232 DWORD data
, DWORD time
, DWORD extra_info
, UINT injected_flags
)
236 if (flags
& MOUSEEVENTF_MOVE
&& flags
& MOUSEEVENTF_ABSOLUTE
)
238 if (injected_flags
& LLMHF_INJECTED
)
240 pt
.x
= (x
* screen_width
) >> 16;
241 pt
.y
= (y
* screen_height
) >> 16;
248 if (cursor_pos
.x
== x
&& cursor_pos
.y
== y
) flags
&= ~MOUSEEVENTF_MOVE
;
252 else if (flags
& MOUSEEVENTF_MOVE
)
254 int accel
[3], xMult
= 1, yMult
= 1;
256 /* dx and dy can be negative numbers for relative movements */
257 SystemParametersInfoW(SPI_GETMOUSE
, 0, accel
, 0);
259 if (abs(x
) > accel
[0] && accel
[2] != 0)
262 if ((abs(x
) > accel
[1]) && (accel
[2] == 2)) xMult
= 4;
264 if (abs(y
) > accel
[0] && accel
[2] != 0)
267 if ((abs(y
) > accel
[1]) && (accel
[2] == 2)) yMult
= 4;
271 pt
.x
= cursor_pos
.x
+ (long)x
* xMult
;
272 pt
.y
= cursor_pos
.y
+ (long)y
* yMult
;
282 if (flags
& MOUSEEVENTF_MOVE
)
284 queue_raw_mouse_message( WM_MOUSEMOVE
, hwnd
, pt
.x
, pt
.y
, data
, time
,
285 extra_info
, injected_flags
);
286 if ((injected_flags
& LLMHF_INJECTED
) &&
287 ((flags
& MOUSEEVENTF_ABSOLUTE
) || x
|| y
)) /* we have to actually move the cursor */
289 X11DRV_SetCursorPos( pt
.x
, pt
.y
);
294 clip_point_to_rect( &cursor_clip
, &pt
);
299 if (flags
& MOUSEEVENTF_LEFTDOWN
)
301 key_state_table
[VK_LBUTTON
] |= 0xc0;
302 queue_raw_mouse_message( GetSystemMetrics(SM_SWAPBUTTON
) ? WM_RBUTTONDOWN
: WM_LBUTTONDOWN
,
303 hwnd
, pt
.x
, pt
.y
, data
, time
, extra_info
, injected_flags
);
305 if (flags
& MOUSEEVENTF_LEFTUP
)
307 key_state_table
[VK_LBUTTON
] &= ~0x80;
308 queue_raw_mouse_message( GetSystemMetrics(SM_SWAPBUTTON
) ? WM_RBUTTONUP
: WM_LBUTTONUP
,
309 hwnd
, pt
.x
, pt
.y
, data
, time
, extra_info
, injected_flags
);
311 if (flags
& MOUSEEVENTF_RIGHTDOWN
)
313 key_state_table
[VK_RBUTTON
] |= 0xc0;
314 queue_raw_mouse_message( GetSystemMetrics(SM_SWAPBUTTON
) ? WM_LBUTTONDOWN
: WM_RBUTTONDOWN
,
315 hwnd
, pt
.x
, pt
.y
, data
, time
, extra_info
, injected_flags
);
317 if (flags
& MOUSEEVENTF_RIGHTUP
)
319 key_state_table
[VK_RBUTTON
] &= ~0x80;
320 queue_raw_mouse_message( GetSystemMetrics(SM_SWAPBUTTON
) ? WM_LBUTTONUP
: WM_RBUTTONUP
,
321 hwnd
, pt
.x
, pt
.y
, data
, time
, extra_info
, injected_flags
);
323 if (flags
& MOUSEEVENTF_MIDDLEDOWN
)
325 key_state_table
[VK_MBUTTON
] |= 0xc0;
326 queue_raw_mouse_message( WM_MBUTTONDOWN
, hwnd
, pt
.x
, pt
.y
, data
, time
,
327 extra_info
, injected_flags
);
329 if (flags
& MOUSEEVENTF_MIDDLEUP
)
331 key_state_table
[VK_MBUTTON
] &= ~0x80;
332 queue_raw_mouse_message( WM_MBUTTONUP
, hwnd
, pt
.x
, pt
.y
, data
, time
,
333 extra_info
, injected_flags
);
335 if (flags
& MOUSEEVENTF_WHEEL
)
337 queue_raw_mouse_message( WM_MOUSEWHEEL
, hwnd
, pt
.x
, pt
.y
, data
, time
,
338 extra_info
, injected_flags
);
340 if (flags
& MOUSEEVENTF_XDOWN
)
342 key_state_table
[VK_XBUTTON1
+ data
- 1] |= 0xc0;
343 queue_raw_mouse_message( WM_XBUTTONDOWN
, hwnd
, pt
.x
, pt
.y
, data
, time
,
344 extra_info
, injected_flags
);
346 if (flags
& MOUSEEVENTF_XUP
)
348 key_state_table
[VK_XBUTTON1
+ data
- 1] &= ~0x80;
349 queue_raw_mouse_message( WM_XBUTTONUP
, hwnd
, pt
.x
, pt
.y
, data
, time
,
350 extra_info
, injected_flags
);
355 /***********************************************************************
358 * Create an X cursor from a Windows one.
360 static Cursor
create_cursor( Display
*display
, CURSORICONINFO
*ptr
)
362 Pixmap pixmapBits
, pixmapMask
, pixmapMaskInv
, pixmapAll
;
364 Cursor cursor
= None
;
366 if (!ptr
) /* Create an empty cursor */
368 static const char data
[] = { 0 };
370 bg
.red
= bg
.green
= bg
.blue
= 0x0000;
371 pixmapBits
= XCreateBitmapFromData( display
, root_window
, data
, 1, 1 );
374 cursor
= XCreatePixmapCursor( display
, pixmapBits
, pixmapBits
,
376 XFreePixmap( display
, pixmapBits
);
379 else /* Create the X cursor from the bits */
384 TRACE("Bitmap %dx%d planes=%d bpp=%d bytesperline=%d\n",
385 ptr
->nWidth
, ptr
->nHeight
, ptr
->bPlanes
, ptr
->bBitsPerPixel
,
387 /* Create a pixmap and transfer all the bits to it */
389 /* NOTE: Following hack works, but only because XFree depth
390 * 1 images really use 1 bit/pixel (and so the same layout
391 * as the Windows cursor data). Perhaps use a more generic
394 /* This pixmap will be written with two bitmaps. The first is
395 * the mask and the second is the image.
397 if (!(pixmapAll
= XCreatePixmap( display
, root_window
,
398 ptr
->nWidth
, ptr
->nHeight
* 2, 1 )))
400 if (!(image
= XCreateImage( display
, visual
,
401 1, ZPixmap
, 0, (char *)(ptr
+ 1), ptr
->nWidth
,
402 ptr
->nHeight
* 2, 16, ptr
->nWidthBytes
/ptr
->bBitsPerPixel
)))
404 XFreePixmap( display
, pixmapAll
);
407 gc
= XCreateGC( display
, pixmapAll
, 0, NULL
);
408 XSetGraphicsExposures( display
, gc
, False
);
409 image
->byte_order
= MSBFirst
;
410 image
->bitmap_bit_order
= MSBFirst
;
411 image
->bitmap_unit
= 16;
412 _XInitImageFuncPtrs(image
);
413 if (ptr
->bPlanes
* ptr
->bBitsPerPixel
== 1)
415 /* A plain old white on black cursor. */
416 fg
.red
= fg
.green
= fg
.blue
= 0xffff;
417 bg
.red
= bg
.green
= bg
.blue
= 0x0000;
418 XPutImage( display
, pixmapAll
, gc
, image
,
419 0, 0, 0, 0, ptr
->nWidth
, ptr
->nHeight
* 2 );
423 int rbits
, gbits
, bbits
, red
, green
, blue
;
424 int rfg
, gfg
, bfg
, rbg
, gbg
, bbg
;
425 int rscale
, gscale
, bscale
;
426 int x
, y
, xmax
, ymax
, bitIndex
, byteIndex
, xorIndex
;
427 unsigned char *theMask
, *theImage
, theChar
;
428 int threshold
, fgBits
, bgBits
, bitShifted
;
429 BYTE pXorBits
[128]; /* Up to 32x32 icons */
431 switch (ptr
->bBitsPerPixel
)
446 FIXME("Currently no support for cursors with %d bits per pixel\n",
448 XFreePixmap( display
, pixmapAll
);
449 XFreeGC( display
, gc
);
451 XDestroyImage( image
);
454 /* The location of the mask. */
455 theMask
= (unsigned char *)(ptr
+ 1);
456 /* The mask should still be 1 bit per pixel. The color image
457 * should immediately follow the mask.
459 theImage
= &theMask
[ptr
->nWidth
/8 * ptr
->nHeight
];
460 rfg
= gfg
= bfg
= rbg
= gbg
= bbg
= 0;
466 xmax
= (ptr
->nWidth
> 32) ? 32 : ptr
->nWidth
;
467 if (ptr
->nWidth
> 32) {
468 ERR("Got a %dx%d cursor. Cannot handle larger than 32x32.\n",
469 ptr
->nWidth
, ptr
->nHeight
);
471 ymax
= (ptr
->nHeight
> 32) ? 32 : ptr
->nHeight
;
473 memset(pXorBits
, 0, 128);
474 for (y
=0; y
<ymax
; y
++)
476 for (x
=0; x
<xmax
; x
++)
478 red
= green
= blue
= 0;
479 switch (ptr
->bBitsPerPixel
)
482 theChar
= theImage
[byteIndex
++];
484 theChar
= theImage
[byteIndex
++];
486 theChar
= theImage
[byteIndex
++];
490 theChar
= theImage
[byteIndex
++];
491 blue
= theChar
& 0x1F;
492 green
= (theChar
& 0xE0) >> 5;
493 theChar
= theImage
[byteIndex
++];
494 green
|= (theChar
& 0x07) << 3;
495 red
= (theChar
& 0xF8) >> 3;
499 if (red
+green
+blue
> threshold
)
505 pXorBits
[xorIndex
] |= bitShifted
;
519 bitShifted
= bitShifted
<< 1;
522 rscale
= 1 << (16 - rbits
);
523 gscale
= 1 << (16 - gbits
);
524 bscale
= 1 << (16 - bbits
);
527 fg
.red
= rfg
* rscale
/ fgBits
;
528 fg
.green
= gfg
* gscale
/ fgBits
;
529 fg
.blue
= bfg
* bscale
/ fgBits
;
531 else fg
.red
= fg
.green
= fg
.blue
= 0;
532 bgBits
= xmax
* ymax
- fgBits
;
535 bg
.red
= rbg
* rscale
/ bgBits
;
536 bg
.green
= gbg
* gscale
/ bgBits
;
537 bg
.blue
= bbg
* bscale
/ bgBits
;
539 else bg
.red
= bg
.green
= bg
.blue
= 0;
540 pixmapBits
= XCreateBitmapFromData( display
, root_window
, (char *)pXorBits
, xmax
, ymax
);
543 XFreePixmap( display
, pixmapAll
);
544 XFreeGC( display
, gc
);
546 XDestroyImage( image
);
551 XPutImage( display
, pixmapAll
, gc
, image
,
552 0, 0, 0, 0, ptr
->nWidth
, ptr
->nHeight
);
553 XSetFunction( display
, gc
, GXcopy
);
555 XCopyArea( display
, pixmapBits
, pixmapAll
, gc
,
556 0, 0, xmax
, ymax
, 0, ptr
->nHeight
);
557 XFreePixmap( display
, pixmapBits
);
560 XDestroyImage( image
);
562 /* Now create the 2 pixmaps for bits and mask */
564 pixmapBits
= XCreatePixmap( display
, root_window
, ptr
->nWidth
, ptr
->nHeight
, 1 );
565 pixmapMask
= XCreatePixmap( display
, root_window
, ptr
->nWidth
, ptr
->nHeight
, 1 );
566 pixmapMaskInv
= XCreatePixmap( display
, root_window
, ptr
->nWidth
, ptr
->nHeight
, 1 );
568 /* Make sure everything went OK so far */
570 if (pixmapBits
&& pixmapMask
&& pixmapMaskInv
)
574 /* We have to do some magic here, as cursors are not fully
575 * compatible between Windows and X11. Under X11, there
576 * are only 3 possible color cursor: black, white and
577 * masked. So we map the 4th Windows color (invert the
578 * bits on the screen) to black and an additional white bit on
579 * an other place (+1,+1). This require some boolean arithmetic:
582 * And Xor Result | Bits Mask Result
583 * 0 0 black | 0 1 background
584 * 0 1 white | 1 1 foreground
585 * 1 0 no change | X 0 no change
586 * 1 1 inverted | 0 1 background
589 * Bits = not 'And' and 'Xor' or 'And2' and 'Xor2'
590 * Mask = not 'And' or 'Xor' or 'And2' and 'Xor2'
592 * FIXME: apparently some servers do support 'inverted' color.
593 * I don't know if it's correct per the X spec, but maybe
594 * we ought to take advantage of it. -- AJ
596 XSetFunction( display
, gc
, GXcopy
);
597 XCopyArea( display
, pixmapAll
, pixmapBits
, gc
,
598 0, 0, ptr
->nWidth
, ptr
->nHeight
, 0, 0 );
599 XCopyArea( display
, pixmapAll
, pixmapMask
, gc
,
600 0, 0, ptr
->nWidth
, ptr
->nHeight
, 0, 0 );
601 XCopyArea( display
, pixmapAll
, pixmapMaskInv
, gc
,
602 0, 0, ptr
->nWidth
, ptr
->nHeight
, 0, 0 );
603 XSetFunction( display
, gc
, GXand
);
604 XCopyArea( display
, pixmapAll
, pixmapMaskInv
, gc
,
605 0, ptr
->nHeight
, ptr
->nWidth
, ptr
->nHeight
, 0, 0 );
606 XSetFunction( display
, gc
, GXandReverse
);
607 XCopyArea( display
, pixmapAll
, pixmapBits
, gc
,
608 0, ptr
->nHeight
, ptr
->nWidth
, ptr
->nHeight
, 0, 0 );
609 XSetFunction( display
, gc
, GXorReverse
);
610 XCopyArea( display
, pixmapAll
, pixmapMask
, gc
,
611 0, ptr
->nHeight
, ptr
->nWidth
, ptr
->nHeight
, 0, 0 );
612 /* Additional white */
613 XSetFunction( display
, gc
, GXor
);
614 XCopyArea( display
, pixmapMaskInv
, pixmapMask
, gc
,
615 0, 0, ptr
->nWidth
, ptr
->nHeight
, 1, 1 );
616 XCopyArea( display
, pixmapMaskInv
, pixmapBits
, gc
,
617 0, 0, ptr
->nWidth
, ptr
->nHeight
, 1, 1 );
618 XSetFunction( display
, gc
, GXcopy
);
620 /* Make sure hotspot is valid */
621 hotspot
.x
= ptr
->ptHotSpot
.x
;
622 hotspot
.y
= ptr
->ptHotSpot
.y
;
623 if (hotspot
.x
< 0 || hotspot
.x
>= ptr
->nWidth
||
624 hotspot
.y
< 0 || hotspot
.y
>= ptr
->nHeight
)
626 hotspot
.x
= ptr
->nWidth
/ 2;
627 hotspot
.y
= ptr
->nHeight
/ 2;
629 cursor
= XCreatePixmapCursor( display
, pixmapBits
, pixmapMask
,
630 &fg
, &bg
, hotspot
.x
, hotspot
.y
);
633 /* Now free everything */
635 if (pixmapAll
) XFreePixmap( display
, pixmapAll
);
636 if (pixmapBits
) XFreePixmap( display
, pixmapBits
);
637 if (pixmapMask
) XFreePixmap( display
, pixmapMask
);
638 if (pixmapMaskInv
) XFreePixmap( display
, pixmapMaskInv
);
639 XFreeGC( display
, gc
);
645 /***********************************************************************
646 * SetCursor (X11DRV.@)
648 void X11DRV_SetCursor( CURSORICONINFO
*lpCursor
)
653 TRACE("%ux%u, planes %u, bpp %u\n",
654 lpCursor
->nWidth
, lpCursor
->nHeight
, lpCursor
->bPlanes
, lpCursor
->bBitsPerPixel
);
658 if (root_window
!= DefaultRootWindow(gdi_display
))
660 /* If in desktop mode, set the cursor on the desktop window */
663 cursor
= create_cursor( gdi_display
, lpCursor
);
666 XDefineCursor( gdi_display
, root_window
, cursor
);
667 /* Make the change take effect immediately */
669 XFreeCursor( gdi_display
, cursor
);
673 else /* set the same cursor for all top-level windows of the current thread */
675 struct x11drv_thread_data
*data
= x11drv_thread_data();
678 cursor
= create_cursor( data
->display
, lpCursor
);
681 if (data
->cursor
) XFreeCursor( data
->display
, data
->cursor
);
682 data
->cursor
= cursor
;
683 if (data
->cursor_window
)
685 XDefineCursor( data
->display
, data
->cursor_window
, cursor
);
686 /* Make the change take effect immediately */
687 XFlush( data
->display
);
694 /***********************************************************************
695 * SetCursorPos (X11DRV.@)
697 BOOL
X11DRV_SetCursorPos( INT x
, INT y
)
699 Display
*display
= thread_display();
702 TRACE( "warping to (%d,%d)\n", x
, y
);
705 if (cursor_pos
.x
== x
&& cursor_pos
.y
== y
)
708 /* We still need to generate WM_MOUSEMOVE */
709 queue_raw_mouse_message( WM_MOUSEMOVE
, NULL
, x
, y
, 0, GetCurrentTime(), 0, 0 );
714 clip_point_to_rect( &cursor_clip
, &pt
);
715 XWarpPointer( display
, root_window
, root_window
, 0, 0, 0, 0,
716 pt
.x
- virtual_screen_rect
.left
, pt
.y
- virtual_screen_rect
.top
);
717 XFlush( display
); /* avoids bad mouse lag in games that do their own mouse warping */
723 /***********************************************************************
724 * GetCursorPos (X11DRV.@)
726 BOOL
X11DRV_GetCursorPos(LPPOINT pos
)
728 Display
*display
= thread_display();
730 int rootX
, rootY
, winX
, winY
;
734 if ((GetTickCount() - last_time_modified
> 100) &&
735 XQueryPointer( display
, root_window
, &root
, &child
,
736 &rootX
, &rootY
, &winX
, &winY
, &xstate
))
738 update_button_state( xstate
);
739 winX
+= virtual_screen_rect
.left
;
740 winY
+= virtual_screen_rect
.top
;
741 TRACE("pointer at (%d,%d)\n", winX
, winY
);
751 /***********************************************************************
752 * ClipCursor (X11DRV.@)
754 * Set the cursor clipping rectangle.
756 BOOL
X11DRV_ClipCursor( LPCRECT clip
)
758 if (!IntersectRect( &cursor_clip
, &virtual_screen_rect
, clip
))
759 cursor_clip
= virtual_screen_rect
;
764 /***********************************************************************
767 void X11DRV_ButtonPress( HWND hwnd
, XEvent
*xev
)
769 XButtonEvent
*event
= &xev
->xbutton
;
770 int buttonNum
= event
->button
- 1;
774 if (buttonNum
>= NB_BUTTONS
) return;
783 wData
= -WHEEL_DELTA
;
793 update_mouse_state( hwnd
, event
->window
, event
->x
, event
->y
, event
->state
, &pt
);
795 X11DRV_send_mouse_input( hwnd
, button_down_flags
[buttonNum
] | MOUSEEVENTF_ABSOLUTE
| MOUSEEVENTF_MOVE
,
796 pt
.x
, pt
.y
, wData
, EVENT_x11_time_to_win32_time(event
->time
), 0, 0 );
800 /***********************************************************************
801 * X11DRV_ButtonRelease
803 void X11DRV_ButtonRelease( HWND hwnd
, XEvent
*xev
)
805 XButtonEvent
*event
= &xev
->xbutton
;
806 int buttonNum
= event
->button
- 1;
810 if (buttonNum
>= NB_BUTTONS
|| !button_up_flags
[buttonNum
]) return;
823 update_mouse_state( hwnd
, event
->window
, event
->x
, event
->y
, event
->state
, &pt
);
825 X11DRV_send_mouse_input( hwnd
, button_up_flags
[buttonNum
] | MOUSEEVENTF_ABSOLUTE
| MOUSEEVENTF_MOVE
,
826 pt
.x
, pt
.y
, wData
, EVENT_x11_time_to_win32_time(event
->time
), 0, 0 );
830 /***********************************************************************
831 * X11DRV_MotionNotify
833 void X11DRV_MotionNotify( HWND hwnd
, XEvent
*xev
)
835 XMotionEvent
*event
= &xev
->xmotion
;
838 TRACE("hwnd %p, event->is_hint %d\n", hwnd
, event
->is_hint
);
842 update_mouse_state( hwnd
, event
->window
, event
->x
, event
->y
, event
->state
, &pt
);
844 X11DRV_send_mouse_input( hwnd
, MOUSEEVENTF_MOVE
| MOUSEEVENTF_ABSOLUTE
,
845 pt
.x
, pt
.y
, 0, EVENT_x11_time_to_win32_time(event
->time
), 0, 0 );
849 /***********************************************************************
852 void X11DRV_EnterNotify( HWND hwnd
, XEvent
*xev
)
854 XCrossingEvent
*event
= &xev
->xcrossing
;
857 TRACE("hwnd %p, event->detail %d\n", hwnd
, event
->detail
);
860 if (event
->detail
== NotifyVirtual
|| event
->detail
== NotifyNonlinearVirtual
) return;
862 /* simulate a mouse motion event */
863 update_mouse_state( hwnd
, event
->window
, event
->x
, event
->y
, event
->state
, &pt
);
865 X11DRV_send_mouse_input( hwnd
, MOUSEEVENTF_MOVE
| MOUSEEVENTF_ABSOLUTE
,
866 pt
.x
, pt
.y
, 0, EVENT_x11_time_to_win32_time(event
->time
), 0, 0 );