4 * Copyright 1998 Ulrich Weigand
5 * Copyright 2007 Henri Verbeet
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/port.h"
26 #include <X11/cursorfont.h>
28 #ifdef HAVE_X11_EXTENSIONS_XINPUT2_H
29 #include <X11/extensions/XInput2.h>
32 #ifdef SONAME_LIBXCURSOR
33 # include <X11/Xcursor/Xcursor.h>
34 static void *xcursor_handle
;
35 # define MAKE_FUNCPTR(f) static typeof(f) * p##f
36 MAKE_FUNCPTR(XcursorImageCreate
);
37 MAKE_FUNCPTR(XcursorImageDestroy
);
38 MAKE_FUNCPTR(XcursorImageLoadCursor
);
39 MAKE_FUNCPTR(XcursorImagesCreate
);
40 MAKE_FUNCPTR(XcursorImagesDestroy
);
41 MAKE_FUNCPTR(XcursorImagesLoadCursor
);
42 MAKE_FUNCPTR(XcursorLibraryLoadCursor
);
44 #endif /* SONAME_LIBXCURSOR */
46 #define NONAMELESSUNION
53 #include "wine/server.h"
54 #include "wine/unicode.h"
55 #include "wine/debug.h"
57 WINE_DEFAULT_DEBUG_CHANNEL(cursor
);
59 /**********************************************************************/
62 #define Button6Mask (1<<13)
65 #define Button7Mask (1<<14)
68 #define NB_BUTTONS 9 /* Windows can handle 5 buttons and the wheel too */
70 static const UINT button_down_flags
[NB_BUTTONS
] =
73 MOUSEEVENTF_MIDDLEDOWN
,
74 MOUSEEVENTF_RIGHTDOWN
,
83 static const UINT button_up_flags
[NB_BUTTONS
] =
96 static const UINT button_down_data
[NB_BUTTONS
] =
109 static const UINT button_up_data
[NB_BUTTONS
] =
122 XContext cursor_context
= 0;
124 static HWND cursor_window
;
125 static HCURSOR last_cursor
;
126 static DWORD last_cursor_change
;
127 static RECT last_clip_rect
;
128 static HWND last_clip_foreground_window
;
129 static BOOL last_clip_refused
;
130 static RECT clip_rect
;
131 static Cursor
create_cursor( HANDLE handle
);
133 #ifdef HAVE_X11_EXTENSIONS_XINPUT2_H
134 static BOOL xinput2_available
;
135 static BOOL broken_rawevents
;
136 #define MAKE_FUNCPTR(f) static typeof(f) * p##f
137 MAKE_FUNCPTR(XIGetClientPointer
);
138 MAKE_FUNCPTR(XIFreeDeviceInfo
);
139 MAKE_FUNCPTR(XIQueryDevice
);
140 MAKE_FUNCPTR(XIQueryVersion
);
141 MAKE_FUNCPTR(XISelectEvents
);
145 /***********************************************************************
146 * X11DRV_Xcursor_Init
148 * Load the Xcursor library for use.
150 void X11DRV_Xcursor_Init(void)
152 #ifdef SONAME_LIBXCURSOR
153 xcursor_handle
= dlopen(SONAME_LIBXCURSOR
, RTLD_NOW
);
156 WARN("Xcursor failed to load. Using fallback code.\n");
159 #define LOAD_FUNCPTR(f) p##f = dlsym(xcursor_handle, #f)
161 LOAD_FUNCPTR(XcursorImageCreate
);
162 LOAD_FUNCPTR(XcursorImageDestroy
);
163 LOAD_FUNCPTR(XcursorImageLoadCursor
);
164 LOAD_FUNCPTR(XcursorImagesCreate
);
165 LOAD_FUNCPTR(XcursorImagesDestroy
);
166 LOAD_FUNCPTR(XcursorImagesLoadCursor
);
167 LOAD_FUNCPTR(XcursorLibraryLoadCursor
);
169 #endif /* SONAME_LIBXCURSOR */
173 /***********************************************************************
176 static Cursor
get_empty_cursor(void)
178 static Cursor cursor
;
179 static const char data
[] = { 0 };
186 bg
.red
= bg
.green
= bg
.blue
= 0x0000;
187 pixmap
= XCreateBitmapFromData( gdi_display
, root_window
, data
, 1, 1 );
190 Cursor
new = XCreatePixmapCursor( gdi_display
, pixmap
, pixmap
, &bg
, &bg
, 0, 0 );
191 if (InterlockedCompareExchangePointer( (void **)&cursor
, (void *)new, 0 ))
192 XFreeCursor( gdi_display
, new );
193 XFreePixmap( gdi_display
, pixmap
);
199 /***********************************************************************
202 void set_window_cursor( Window window
, HCURSOR handle
)
206 if (!handle
) cursor
= get_empty_cursor();
207 else if (XFindContext( gdi_display
, (XID
)handle
, cursor_context
, (char **)&cursor
))
209 /* try to create it */
210 if (!(cursor
= create_cursor( handle
))) return;
212 XLockDisplay( gdi_display
);
213 if (!XFindContext( gdi_display
, (XID
)handle
, cursor_context
, (char **)&prev
))
215 /* someone else was here first */
216 XFreeCursor( gdi_display
, cursor
);
221 XSaveContext( gdi_display
, (XID
)handle
, cursor_context
, (char *)cursor
);
222 TRACE( "cursor %p created %lx\n", handle
, cursor
);
224 XUnlockDisplay( gdi_display
);
227 XDefineCursor( gdi_display
, window
, cursor
);
228 /* make the change take effect immediately */
229 XFlush( gdi_display
);
232 /***********************************************************************
235 void sync_window_cursor( Window window
)
239 SERVER_START_REQ( set_cursor
)
242 wine_server_call( req
);
243 cursor
= reply
->prev_count
>= 0 ? wine_server_ptr_handle( reply
->prev_handle
) : 0;
247 set_window_cursor( window
, cursor
);
250 #ifdef HAVE_X11_EXTENSIONS_XINPUT2_H
251 /***********************************************************************
252 * update_relative_valuators
254 static void update_relative_valuators(XIAnyClassInfo
**valuators
, int n_valuators
)
256 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
259 thread_data
->x_rel_valuator
.number
= -1;
260 thread_data
->y_rel_valuator
.number
= -1;
262 for (i
= 0; i
< n_valuators
; i
++)
264 XIValuatorClassInfo
*class = (XIValuatorClassInfo
*)valuators
[i
];
265 struct x11drv_valuator_data
*valuator_data
= NULL
;
267 if (valuators
[i
]->type
!= XIValuatorClass
) continue;
268 if (class->label
== x11drv_atom( Rel_X
) ||
269 (!class->label
&& class->number
== 0 && class->mode
== XIModeRelative
))
271 valuator_data
= &thread_data
->x_rel_valuator
;
273 else if (class->label
== x11drv_atom( Rel_Y
) ||
274 (!class->label
&& class->number
== 1 && class->mode
== XIModeRelative
))
276 valuator_data
= &thread_data
->y_rel_valuator
;
280 valuator_data
->number
= class->number
;
281 valuator_data
->min
= class->min
;
282 valuator_data
->max
= class->max
;
289 /***********************************************************************
292 static void enable_xinput2(void)
294 #ifdef HAVE_X11_EXTENSIONS_XINPUT2_H
295 struct x11drv_thread_data
*data
= x11drv_thread_data();
297 XIDeviceInfo
*pointer_info
;
298 unsigned char mask_bits
[XIMaskLen(XI_LASTEVENT
)];
301 if (!xinput2_available
) return;
303 if (data
->xi2_state
== xi_unknown
)
305 int major
= 2, minor
= 0;
306 if (!pXIQueryVersion( data
->display
, &major
, &minor
)) data
->xi2_state
= xi_disabled
;
309 data
->xi2_state
= xi_unavailable
;
310 WARN( "X Input 2 not available\n" );
313 if (data
->xi2_state
== xi_unavailable
) return;
314 if (!pXIGetClientPointer( data
->display
, None
, &data
->xi2_core_pointer
)) return;
316 mask
.mask
= mask_bits
;
317 mask
.mask_len
= sizeof(mask_bits
);
318 mask
.deviceid
= XIAllDevices
;
319 memset( mask_bits
, 0, sizeof(mask_bits
) );
320 XISetMask( mask_bits
, XI_DeviceChanged
);
321 XISetMask( mask_bits
, XI_RawMotion
);
322 XISetMask( mask_bits
, XI_ButtonPress
);
324 pXISelectEvents( data
->display
, DefaultRootWindow( data
->display
), &mask
, 1 );
326 pointer_info
= pXIQueryDevice( data
->display
, data
->xi2_core_pointer
, &count
);
327 update_relative_valuators( pointer_info
->classes
, pointer_info
->num_classes
);
328 pXIFreeDeviceInfo( pointer_info
);
330 /* This device info list is only used to find the initial current slave if
331 * no XI_DeviceChanged events happened. If any hierarchy change occurred that
332 * might be relevant here (eg. user switching mice after (un)plugging), a
333 * XI_DeviceChanged event will point us to the right slave. So this list is
334 * safe to be obtained statically at enable_xinput2() time.
336 if (data
->xi2_devices
) pXIFreeDeviceInfo( data
->xi2_devices
);
337 data
->xi2_devices
= pXIQueryDevice( data
->display
, XIAllDevices
, &data
->xi2_device_count
);
338 data
->xi2_current_slave
= 0;
340 data
->xi2_state
= xi_enabled
;
344 /***********************************************************************
347 static void disable_xinput2(void)
349 #ifdef HAVE_X11_EXTENSIONS_XINPUT2_H
350 struct x11drv_thread_data
*data
= x11drv_thread_data();
353 if (data
->xi2_state
!= xi_enabled
) return;
355 TRACE( "disabling\n" );
356 data
->xi2_state
= xi_disabled
;
360 mask
.deviceid
= XIAllDevices
;
362 pXISelectEvents( data
->display
, DefaultRootWindow( data
->display
), &mask
, 1 );
363 pXIFreeDeviceInfo( data
->xi2_devices
);
364 data
->x_rel_valuator
.number
= -1;
365 data
->y_rel_valuator
.number
= -1;
366 data
->xi2_devices
= NULL
;
367 data
->xi2_core_pointer
= 0;
368 data
->xi2_current_slave
= 0;
373 /***********************************************************************
374 * grab_clipping_window
376 * Start a pointer grab on the clip window.
378 static BOOL
grab_clipping_window( const RECT
*clip
)
380 static const WCHAR messageW
[] = {'M','e','s','s','a','g','e',0};
381 struct x11drv_thread_data
*data
= x11drv_thread_data();
386 if (GetWindowThreadProcessId( GetDesktopWindow(), NULL
) == GetCurrentThreadId())
387 return TRUE
; /* don't clip in the desktop process */
389 if (!data
) return FALSE
;
390 if (!(clip_window
= init_clip_window())) return TRUE
;
392 if (!(msg_hwnd
= CreateWindowW( messageW
, NULL
, 0, 0, 0, 0, 0, HWND_MESSAGE
, 0,
393 GetModuleHandleW(0), NULL
)))
396 if (keyboard_grabbed
)
398 WARN( "refusing to clip to %s\n", wine_dbgstr_rect(clip
) );
399 last_clip_refused
= TRUE
;
400 last_clip_foreground_window
= GetForegroundWindow();
401 last_clip_rect
= *clip
;
406 last_clip_refused
= FALSE
;
409 /* enable XInput2 unless we are already clipping */
410 if (!data
->clip_hwnd
) enable_xinput2();
412 if (data
->xi2_state
!= xi_enabled
)
414 WARN( "XInput2 not supported, refusing to clip to %s\n", wine_dbgstr_rect(clip
) );
415 DestroyWindow( msg_hwnd
);
420 TRACE( "clipping to %s win %lx\n", wine_dbgstr_rect(clip
), clip_window
);
422 if (!data
->clip_hwnd
) XUnmapWindow( data
->display
, clip_window
);
423 pos
= virtual_screen_to_root( clip
->left
, clip
->top
);
424 XMoveResizeWindow( data
->display
, clip_window
, pos
.x
, pos
.y
,
425 max( 1, clip
->right
- clip
->left
), max( 1, clip
->bottom
- clip
->top
) );
426 XMapWindow( data
->display
, clip_window
);
428 /* if the rectangle is shrinking we may get a pointer warp */
429 if (!data
->clip_hwnd
|| clip
->left
> clip_rect
.left
|| clip
->top
> clip_rect
.top
||
430 clip
->right
< clip_rect
.right
|| clip
->bottom
< clip_rect
.bottom
)
431 data
->warp_serial
= NextRequest( data
->display
);
433 if (!XGrabPointer( data
->display
, clip_window
, False
,
434 PointerMotionMask
| ButtonPressMask
| ButtonReleaseMask
,
435 GrabModeAsync
, GrabModeAsync
, clip_window
, None
, CurrentTime
))
436 clipping_cursor
= TRUE
;
438 if (!clipping_cursor
)
441 DestroyWindow( msg_hwnd
);
445 if (!data
->clip_hwnd
) sync_window_cursor( clip_window
);
446 InterlockedExchangePointer( (void **)&cursor_window
, msg_hwnd
);
447 data
->clip_hwnd
= msg_hwnd
;
448 SendNotifyMessageW( GetDesktopWindow(), WM_X11DRV_CLIP_CURSOR_NOTIFY
, 0, (LPARAM
)msg_hwnd
);
452 /***********************************************************************
453 * ungrab_clipping_window
455 * Release the pointer grab on the clip window.
457 void ungrab_clipping_window(void)
459 Display
*display
= thread_init_display();
460 Window clip_window
= init_clip_window();
462 if (!clip_window
) return;
464 TRACE( "no longer clipping\n" );
465 XUnmapWindow( display
, clip_window
);
466 if (clipping_cursor
) XUngrabPointer( display
, CurrentTime
);
467 clipping_cursor
= FALSE
;
468 SendNotifyMessageW( GetDesktopWindow(), WM_X11DRV_CLIP_CURSOR_NOTIFY
, 0, 0 );
471 /***********************************************************************
472 * reset_clipping_window
474 * Forcibly reset the window clipping on external events.
476 void reset_clipping_window(void)
478 ungrab_clipping_window();
479 ClipCursor( NULL
); /* make sure the clip rectangle is reset too */
482 /***********************************************************************
483 * retry_grab_clipping_window
485 * Restore the current clip rectangle or retry the last one if it has
486 * been refused because of an active keyboard grab.
488 void retry_grab_clipping_window(void)
491 ClipCursor( &clip_rect
);
492 else if (last_clip_refused
&& GetForegroundWindow() == last_clip_foreground_window
)
493 ClipCursor( &last_clip_rect
);
496 /***********************************************************************
499 * Notification function called upon receiving a WM_X11DRV_CLIP_CURSOR_NOTIFY.
501 LRESULT
clip_cursor_notify( HWND hwnd
, HWND prev_clip_hwnd
, HWND new_clip_hwnd
)
503 struct x11drv_thread_data
*data
= x11drv_init_thread_data();
505 if (hwnd
== GetDesktopWindow()) /* change the clip window stored in the desktop process */
507 static HWND clip_hwnd
;
509 HWND prev
= clip_hwnd
;
510 clip_hwnd
= new_clip_hwnd
;
511 if (prev
|| new_clip_hwnd
) TRACE( "clip hwnd changed from %p to %p\n", prev
, new_clip_hwnd
);
512 if (prev
) SendNotifyMessageW( prev
, WM_X11DRV_CLIP_CURSOR_NOTIFY
, (WPARAM
)prev
, 0 );
514 else if (hwnd
== data
->clip_hwnd
) /* this is a notification that clipping has been reset */
516 TRACE( "clip hwnd reset from %p\n", hwnd
);
518 data
->clip_reset
= GetTickCount();
520 DestroyWindow( hwnd
);
522 else if (prev_clip_hwnd
)
524 /* This is a notification send by the desktop window to an old
525 * dangling clip window.
527 TRACE( "destroying old clip hwnd %p\n", prev_clip_hwnd
);
528 DestroyWindow( prev_clip_hwnd
);
533 /***********************************************************************
534 * clip_fullscreen_window
536 * Turn on clipping if the active window is fullscreen.
538 BOOL
clip_fullscreen_window( HWND hwnd
, BOOL reset
)
540 struct x11drv_win_data
*data
;
541 struct x11drv_thread_data
*thread_data
;
542 MONITORINFO monitor_info
;
547 if (hwnd
== GetDesktopWindow()) return FALSE
;
548 style
= GetWindowLongW( hwnd
, GWL_STYLE
);
549 if (!(style
& WS_VISIBLE
)) return FALSE
;
550 if ((style
& (WS_POPUP
| WS_CHILD
)) == WS_CHILD
) return FALSE
;
551 /* maximized windows don't count as full screen */
552 if ((style
& WS_MAXIMIZE
) && (style
& WS_CAPTION
) == WS_CAPTION
) return FALSE
;
553 if (!(data
= get_win_data( hwnd
))) return FALSE
;
554 fullscreen
= is_window_rect_full_screen( &data
->whole_rect
);
555 release_win_data( data
);
556 if (!fullscreen
) return FALSE
;
557 if (!(thread_data
= x11drv_thread_data())) return FALSE
;
558 if (GetTickCount() - thread_data
->clip_reset
< 1000) return FALSE
;
559 if (!reset
&& clipping_cursor
&& thread_data
->clip_hwnd
) return FALSE
; /* already clipping */
561 monitor
= MonitorFromWindow( hwnd
, MONITOR_DEFAULTTONEAREST
);
562 if (!monitor
) return FALSE
;
563 monitor_info
.cbSize
= sizeof(monitor_info
);
564 if (!GetMonitorInfoW( monitor
, &monitor_info
)) return FALSE
;
565 if (!grab_fullscreen
)
567 RECT virtual_rect
= get_virtual_screen_rect();
568 if (!EqualRect( &monitor_info
.rcMonitor
, &virtual_rect
)) return FALSE
;
569 if (is_virtual_desktop()) return FALSE
;
571 TRACE( "win %p clipping fullscreen\n", hwnd
);
572 return grab_clipping_window( &monitor_info
.rcMonitor
);
576 /***********************************************************************
577 * is_old_motion_event
579 static BOOL
is_old_motion_event( unsigned long serial
)
581 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
583 if (!thread_data
->warp_serial
) return FALSE
;
584 if ((long)(serial
- thread_data
->warp_serial
) < 0) return TRUE
;
585 thread_data
->warp_serial
= 0; /* we caught up now */
590 /***********************************************************************
593 * Map the input event coordinates so they're relative to the desktop.
595 static void map_event_coords( HWND hwnd
, Window window
, Window event_root
, int x_root
, int y_root
, INPUT
*input
)
597 struct x11drv_thread_data
*thread_data
;
598 struct x11drv_win_data
*data
;
599 POINT pt
= { input
->u
.mi
.dx
, input
->u
.mi
.dy
};
601 TRACE( "hwnd %p, window %lx, event_root %lx, x_root %d, y_root %d, input %p\n", hwnd
, window
, event_root
,
602 x_root
, y_root
, input
);
606 thread_data
= x11drv_thread_data();
607 if (!thread_data
->clip_hwnd
) return;
608 if (thread_data
->clip_window
!= window
) return;
609 pt
.x
+= clip_rect
.left
;
610 pt
.y
+= clip_rect
.top
;
612 else if ((data
= get_win_data( hwnd
)))
614 if (window
== root_window
) pt
= root_to_virtual_screen( pt
.x
, pt
.y
);
615 else if (event_root
== root_window
) pt
= root_to_virtual_screen( x_root
, y_root
);
618 if (window
== data
->whole_window
)
620 pt
.x
+= data
->whole_rect
.left
- data
->client_rect
.left
;
621 pt
.y
+= data
->whole_rect
.top
- data
->client_rect
.top
;
624 if (GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_LAYOUTRTL
)
625 pt
.x
= data
->client_rect
.right
- data
->client_rect
.left
- 1 - pt
.x
;
626 MapWindowPoints( hwnd
, 0, &pt
, 1 );
628 release_win_data( data
);
631 TRACE( "mapped %s to %s\n", wine_dbgstr_point( (POINT
*)&input
->u
.mi
.dx
), wine_dbgstr_point( &pt
) );
633 input
->u
.mi
.dx
= pt
.x
;
634 input
->u
.mi
.dy
= pt
.y
;
638 /***********************************************************************
641 * Update the various window states on a mouse event.
643 static void send_mouse_input( HWND hwnd
, Window window
, unsigned int state
, INPUT
*input
)
645 struct x11drv_win_data
*data
;
647 input
->type
= INPUT_MOUSE
;
651 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
652 HWND clip_hwnd
= thread_data
->clip_hwnd
;
654 if (!clip_hwnd
) return;
655 if (thread_data
->clip_window
!= window
) return;
656 if (InterlockedExchangePointer( (void **)&cursor_window
, clip_hwnd
) != clip_hwnd
||
657 input
->u
.mi
.time
- last_cursor_change
> 100)
659 sync_window_cursor( window
);
660 last_cursor_change
= input
->u
.mi
.time
;
662 __wine_send_input( hwnd
, input
);
666 if (!(data
= get_win_data( hwnd
))) return;
667 if (InterlockedExchangePointer( (void **)&cursor_window
, hwnd
) != hwnd
||
668 input
->u
.mi
.time
- last_cursor_change
> 100)
670 sync_window_cursor( data
->whole_window
);
671 last_cursor_change
= input
->u
.mi
.time
;
673 release_win_data( data
);
675 if (hwnd
!= GetDesktopWindow())
677 hwnd
= GetAncestor( hwnd
, GA_ROOT
);
678 if ((input
->u
.mi
.dwFlags
& (MOUSEEVENTF_LEFTDOWN
|MOUSEEVENTF_RIGHTDOWN
)) && hwnd
== GetForegroundWindow())
679 clip_fullscreen_window( hwnd
, FALSE
);
682 /* update the wine server Z-order */
684 if (hwnd
!= x11drv_thread_data()->grab_hwnd
&&
685 /* ignore event if a button is pressed, since the mouse is then grabbed too */
686 !(state
& (Button1Mask
|Button2Mask
|Button3Mask
|Button4Mask
|Button5Mask
|Button6Mask
|Button7Mask
)))
688 RECT rect
= { input
->u
.mi
.dx
, input
->u
.mi
.dy
, input
->u
.mi
.dx
+ 1, input
->u
.mi
.dy
+ 1 };
690 SERVER_START_REQ( update_window_zorder
)
692 req
->window
= wine_server_user_handle( hwnd
);
693 req
->rect
.left
= rect
.left
;
694 req
->rect
.top
= rect
.top
;
695 req
->rect
.right
= rect
.right
;
696 req
->rect
.bottom
= rect
.bottom
;
697 wine_server_call( req
);
702 __wine_send_input( hwnd
, input
);
705 #ifdef SONAME_LIBXCURSOR
707 /***********************************************************************
708 * create_xcursor_frame
710 * Use Xcursor to create a frame of an X cursor from a Windows one.
712 static XcursorImage
*create_xcursor_frame( HDC hdc
, const ICONINFOEXW
*iinfo
, HANDLE icon
,
713 HBITMAP hbmColor
, unsigned char *color_bits
, int color_size
,
714 HBITMAP hbmMask
, unsigned char *mask_bits
, int mask_size
,
715 int width
, int height
, int istep
)
717 XcursorImage
*image
, *ret
= NULL
;
718 DWORD delay_jiffies
, num_steps
;
720 BOOL has_alpha
= FALSE
;
723 image
= pXcursorImageCreate( width
, height
);
726 ERR("X11 failed to produce a cursor frame!\n");
730 image
->xhot
= iinfo
->xHotspot
;
731 image
->yhot
= iinfo
->yHotspot
;
733 image
->delay
= 100; /* fallback delay, 100 ms */
734 if (GetCursorFrameInfo(icon
, 0x0 /* unknown parameter */, istep
, &delay_jiffies
, &num_steps
) != 0)
735 image
->delay
= (100 * delay_jiffies
) / 6; /* convert jiffies (1/60s) to milliseconds */
737 WARN("Failed to retrieve animated cursor frame-rate for frame %d.\n", istep
);
739 /* draw the cursor frame to a temporary buffer then copy it into the XcursorImage */
740 memset( color_bits
, 0x00, color_size
);
741 SelectObject( hdc
, hbmColor
);
742 if (!DrawIconEx( hdc
, 0, 0, icon
, width
, height
, istep
, NULL
, DI_NORMAL
))
744 TRACE("Could not draw frame %d (walk past end of frames).\n", istep
);
747 memcpy( image
->pixels
, color_bits
, color_size
);
749 /* check if the cursor frame was drawn with an alpha channel */
750 for (i
= 0, ptr
= image
->pixels
; i
< width
* height
; i
++, ptr
++)
751 if ((has_alpha
= (*ptr
& 0xff000000) != 0)) break;
753 /* if no alpha channel was drawn then generate it from the mask */
756 unsigned int width_bytes
= (width
+ 31) / 32 * 4;
758 /* draw the cursor mask to a temporary buffer */
759 memset( mask_bits
, 0xFF, mask_size
);
760 SelectObject( hdc
, hbmMask
);
761 if (!DrawIconEx( hdc
, 0, 0, icon
, width
, height
, istep
, NULL
, DI_MASK
))
763 ERR("Failed to draw frame mask %d.\n", istep
);
766 /* use the buffer to directly modify the XcursorImage alpha channel */
767 for (y
= 0, ptr
= image
->pixels
; y
< height
; y
++)
768 for (x
= 0; x
< width
; x
++, ptr
++)
769 if (!((mask_bits
[y
* width_bytes
+ x
/ 8] << (x
% 8)) & 0x80))
775 if (ret
== NULL
) pXcursorImageDestroy( image
);
779 /***********************************************************************
780 * create_xcursor_cursor
782 * Use Xcursor to create an X cursor from a Windows one.
784 static Cursor
create_xcursor_cursor( HDC hdc
, const ICONINFOEXW
*iinfo
, HANDLE icon
, int width
, int height
)
786 unsigned char *color_bits
, *mask_bits
;
787 HBITMAP hbmColor
= 0, hbmMask
= 0;
788 DWORD nFrames
, delay_jiffies
, i
;
789 int color_size
, mask_size
;
790 BITMAPINFO
*info
= NULL
;
791 XcursorImages
*images
;
795 /* Retrieve the number of frames to render */
796 if (!GetCursorFrameInfo(icon
, 0x0 /* unknown parameter */, 0, &delay_jiffies
, &nFrames
)) return 0;
797 if (!(imgs
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(XcursorImage
*)*nFrames
))) return 0;
799 /* Allocate all of the resources necessary to obtain a cursor frame */
800 if (!(info
= HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )))) goto cleanup
;
801 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
802 info
->bmiHeader
.biWidth
= width
;
803 info
->bmiHeader
.biHeight
= -height
;
804 info
->bmiHeader
.biPlanes
= 1;
805 info
->bmiHeader
.biCompression
= BI_RGB
;
806 info
->bmiHeader
.biXPelsPerMeter
= 0;
807 info
->bmiHeader
.biYPelsPerMeter
= 0;
808 info
->bmiHeader
.biClrUsed
= 0;
809 info
->bmiHeader
.biClrImportant
= 0;
810 info
->bmiHeader
.biBitCount
= 32;
811 color_size
= width
* height
* 4;
812 info
->bmiHeader
.biSizeImage
= color_size
;
813 hbmColor
= CreateDIBSection( hdc
, info
, DIB_RGB_COLORS
, (VOID
**) &color_bits
, NULL
, 0);
816 ERR("Failed to create DIB section for cursor color data!\n");
819 info
->bmiHeader
.biBitCount
= 1;
820 info
->bmiColors
[0].rgbRed
= 0;
821 info
->bmiColors
[0].rgbGreen
= 0;
822 info
->bmiColors
[0].rgbBlue
= 0;
823 info
->bmiColors
[0].rgbReserved
= 0;
824 info
->bmiColors
[1].rgbRed
= 0xff;
825 info
->bmiColors
[1].rgbGreen
= 0xff;
826 info
->bmiColors
[1].rgbBlue
= 0xff;
827 info
->bmiColors
[1].rgbReserved
= 0;
829 mask_size
= ((width
+ 31) / 32 * 4) * height
; /* width_bytes * height */
830 info
->bmiHeader
.biSizeImage
= mask_size
;
831 hbmMask
= CreateDIBSection( hdc
, info
, DIB_RGB_COLORS
, (VOID
**) &mask_bits
, NULL
, 0);
834 ERR("Failed to create DIB section for cursor mask data!\n");
838 /* Create an XcursorImage for each frame of the cursor */
839 for (i
=0; i
<nFrames
; i
++)
841 imgs
[i
] = create_xcursor_frame( hdc
, iinfo
, icon
,
842 hbmColor
, color_bits
, color_size
,
843 hbmMask
, mask_bits
, mask_size
,
845 if (!imgs
[i
]) goto cleanup
;
848 /* Build an X cursor out of all of the frames */
849 if (!(images
= pXcursorImagesCreate( nFrames
))) goto cleanup
;
850 for (images
->nimage
= 0; images
->nimage
< nFrames
; images
->nimage
++)
851 images
->images
[images
->nimage
] = imgs
[images
->nimage
];
852 cursor
= pXcursorImagesLoadCursor( gdi_display
, images
);
853 pXcursorImagesDestroy( images
); /* Note: this frees each individual frame (calls XcursorImageDestroy) */
854 HeapFree( GetProcessHeap(), 0, imgs
);
860 /* Failed to produce a cursor, free previously allocated frames */
861 for (i
=0; i
<nFrames
&& imgs
[i
]; i
++)
862 pXcursorImageDestroy( imgs
[i
] );
863 HeapFree( GetProcessHeap(), 0, imgs
);
865 /* Cleanup all of the resources used to obtain the frame data */
866 if (hbmColor
) DeleteObject( hbmColor
);
867 if (hbmMask
) DeleteObject( hbmMask
);
868 HeapFree( GetProcessHeap(), 0, info
);
872 #endif /* SONAME_LIBXCURSOR */
875 struct system_cursors
878 const char *names
[8];
881 static const struct system_cursors user32_cursors
[] =
883 { OCR_NORMAL
, { "left_ptr" }},
884 { OCR_IBEAM
, { "xterm", "text" }},
885 { OCR_WAIT
, { "watch", "wait" }},
886 { OCR_CROSS
, { "cross" }},
887 { OCR_UP
, { "center_ptr" }},
888 { OCR_SIZE
, { "fleur", "size_all" }},
889 { OCR_SIZEALL
, { "fleur", "size_all" }},
890 { OCR_ICON
, { "icon" }},
891 { OCR_SIZENWSE
, { "top_left_corner", "nw-resize" }},
892 { OCR_SIZENESW
, { "top_right_corner", "ne-resize" }},
893 { OCR_SIZEWE
, { "h_double_arrow", "size_hor", "ew-resize" }},
894 { OCR_SIZENS
, { "v_double_arrow", "size_ver", "ns-resize" }},
895 { OCR_NO
, { "not-allowed", "forbidden", "no-drop" }},
896 { OCR_HAND
, { "hand2", "pointer", "pointing-hand" }},
897 { OCR_APPSTARTING
, { "left_ptr_watch" }},
898 { OCR_HELP
, { "question_arrow", "help" }},
902 static const struct system_cursors comctl32_cursors
[] =
904 { 102, { "move", "dnd-move" }},
905 { 104, { "copy", "dnd-copy" }},
906 { 105, { "left_ptr" }},
907 { 106, { "col-resize", "split_v" }},
908 { 107, { "col-resize", "split_v" }},
909 { 108, { "hand2", "pointer", "pointing-hand" }},
910 { 135, { "row-resize", "split_h" }},
914 static const struct system_cursors ole32_cursors
[] =
916 { 1, { "no-drop", "dnd-no-drop" }},
917 { 2, { "move", "dnd-move" }},
918 { 3, { "copy", "dnd-copy" }},
919 { 4, { "alias", "dnd-link" }},
923 static const struct system_cursors riched20_cursors
[] =
925 { 105, { "hand2", "pointer", "pointing-hand" }},
926 { 107, { "right_ptr" }},
927 { 109, { "copy", "dnd-copy" }},
928 { 110, { "move", "dnd-move" }},
929 { 111, { "no-drop", "dnd-no-drop" }},
935 const struct system_cursors
*cursors
;
939 { user32_cursors
, {'u','s','e','r','3','2','.','d','l','l',0} },
940 { comctl32_cursors
, {'c','o','m','c','t','l','3','2','.','d','l','l',0} },
941 { ole32_cursors
, {'o','l','e','3','2','.','d','l','l',0} },
942 { riched20_cursors
, {'r','i','c','h','e','d','2','0','.','d','l','l',0} }
945 struct cursor_font_fallback
951 static const struct cursor_font_fallback fallbacks
[] =
953 { "X_cursor", XC_X_cursor
},
954 { "arrow", XC_arrow
},
955 { "based_arrow_down", XC_based_arrow_down
},
956 { "based_arrow_up", XC_based_arrow_up
},
958 { "bogosity", XC_bogosity
},
959 { "bottom_left_corner", XC_bottom_left_corner
},
960 { "bottom_right_corner", XC_bottom_right_corner
},
961 { "bottom_side", XC_bottom_side
},
962 { "bottom_tee", XC_bottom_tee
},
963 { "box_spiral", XC_box_spiral
},
964 { "center_ptr", XC_center_ptr
},
965 { "circle", XC_circle
},
966 { "clock", XC_clock
},
967 { "coffee_mug", XC_coffee_mug
},
968 { "col-resize", XC_sb_h_double_arrow
},
969 { "cross", XC_cross
},
970 { "cross_reverse", XC_cross_reverse
},
971 { "crosshair", XC_crosshair
},
972 { "diamond_cross", XC_diamond_cross
},
974 { "dotbox", XC_dotbox
},
975 { "double_arrow", XC_double_arrow
},
976 { "draft_large", XC_draft_large
},
977 { "draft_small", XC_draft_small
},
978 { "draped_box", XC_draped_box
},
979 { "exchange", XC_exchange
},
980 { "fleur", XC_fleur
},
981 { "gobbler", XC_gobbler
},
982 { "gumby", XC_gumby
},
983 { "h_double_arrow", XC_sb_h_double_arrow
},
984 { "hand1", XC_hand1
},
985 { "hand2", XC_hand2
},
986 { "heart", XC_heart
},
988 { "iron_cross", XC_iron_cross
},
989 { "left_ptr", XC_left_ptr
},
990 { "left_side", XC_left_side
},
991 { "left_tee", XC_left_tee
},
992 { "leftbutton", XC_leftbutton
},
993 { "ll_angle", XC_ll_angle
},
994 { "lr_angle", XC_lr_angle
},
996 { "middlebutton", XC_middlebutton
},
997 { "mouse", XC_mouse
},
998 { "pencil", XC_pencil
},
999 { "pirate", XC_pirate
},
1000 { "plus", XC_plus
},
1001 { "question_arrow", XC_question_arrow
},
1002 { "right_ptr", XC_right_ptr
},
1003 { "right_side", XC_right_side
},
1004 { "right_tee", XC_right_tee
},
1005 { "rightbutton", XC_rightbutton
},
1006 { "row-resize", XC_sb_v_double_arrow
},
1007 { "rtl_logo", XC_rtl_logo
},
1008 { "sailboat", XC_sailboat
},
1009 { "sb_down_arrow", XC_sb_down_arrow
},
1010 { "sb_h_double_arrow", XC_sb_h_double_arrow
},
1011 { "sb_left_arrow", XC_sb_left_arrow
},
1012 { "sb_right_arrow", XC_sb_right_arrow
},
1013 { "sb_up_arrow", XC_sb_up_arrow
},
1014 { "sb_v_double_arrow", XC_sb_v_double_arrow
},
1015 { "shuttle", XC_shuttle
},
1016 { "sizing", XC_sizing
},
1017 { "spider", XC_spider
},
1018 { "spraycan", XC_spraycan
},
1019 { "star", XC_star
},
1020 { "target", XC_target
},
1021 { "tcross", XC_tcross
},
1022 { "top_left_arrow", XC_top_left_arrow
},
1023 { "top_left_corner", XC_top_left_corner
},
1024 { "top_right_corner", XC_top_right_corner
},
1025 { "top_side", XC_top_side
},
1026 { "top_tee", XC_top_tee
},
1027 { "trek", XC_trek
},
1028 { "ul_angle", XC_ul_angle
},
1029 { "umbrella", XC_umbrella
},
1030 { "ur_angle", XC_ur_angle
},
1031 { "v_double_arrow", XC_sb_v_double_arrow
},
1032 { "watch", XC_watch
},
1033 { "xterm", XC_xterm
}
1036 static int fallback_cmp( const void *key
, const void *member
)
1038 const struct cursor_font_fallback
*fallback
= member
;
1039 return strcmp( key
, fallback
->name
);
1042 static int find_fallback_shape( const char *name
)
1044 struct cursor_font_fallback
*fallback
;
1046 if ((fallback
= bsearch( name
, fallbacks
, ARRAY_SIZE( fallbacks
),
1047 sizeof(*fallback
), fallback_cmp
)))
1048 return fallback
->shape
;
1052 /***********************************************************************
1053 * create_xcursor_system_cursor
1055 * Create an X cursor for a system cursor.
1057 static Cursor
create_xcursor_system_cursor( const ICONINFOEXW
*info
)
1059 static const WCHAR idW
[] = {'%','h','u',0};
1060 const struct system_cursors
*cursors
;
1065 const char * const *names
= NULL
;
1066 WCHAR
*p
, name
[MAX_PATH
* 2], valueW
[64];
1070 if (!info
->szModName
[0]) return 0;
1072 p
= strrchrW( info
->szModName
, '\\' );
1073 strcpyW( name
, p
? p
+ 1 : info
->szModName
);
1074 p
= name
+ strlenW( name
);
1076 if (info
->szResName
[0]) strcpyW( p
, info
->szResName
);
1077 else sprintfW( p
, idW
, info
->wResID
);
1080 /* @@ Wine registry key: HKCU\Software\Wine\X11 Driver\Cursors */
1081 if (!RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\X11 Driver\\Cursors", &key
))
1083 DWORD size
= sizeof(valueW
);
1084 ret
= RegQueryValueExW( key
, name
, NULL
, NULL
, (BYTE
*)valueW
, &size
);
1088 if (!valueW
[0]) return 0; /* force standard cursor */
1089 if (!WideCharToMultiByte( CP_UNIXCP
, 0, valueW
, -1, valueA
, sizeof(valueA
), NULL
, NULL
))
1095 if (info
->szResName
[0]) goto done
; /* only integer resources are supported here */
1096 if (!(module
= GetModuleHandleW( info
->szModName
))) goto done
;
1098 for (i
= 0; i
< ARRAY_SIZE( module_cursors
); i
++)
1099 if (GetModuleHandleW( module_cursors
[i
].name
) == module
) break;
1100 if (i
== ARRAY_SIZE( module_cursors
)) goto done
;
1102 cursors
= module_cursors
[i
].cursors
;
1103 for (i
= 0; cursors
[i
].id
; i
++)
1104 if (cursors
[i
].id
== info
->wResID
)
1106 strcpy( valueA
, cursors
[i
].names
[0] );
1107 names
= cursors
[i
].names
;
1114 #ifdef SONAME_LIBXCURSOR
1115 if (pXcursorLibraryLoadCursor
)
1118 cursor
= pXcursorLibraryLoadCursor( gdi_display
, valueA
);
1120 while (*names
&& !cursor
) cursor
= pXcursorLibraryLoadCursor( gdi_display
, *names
++ );
1125 int shape
= find_fallback_shape( valueA
);
1126 if (shape
!= -1) cursor
= XCreateFontCursor( gdi_display
, shape
);
1128 if (!cursor
) WARN( "no system cursor found for %s mapped to %s\n",
1129 debugstr_w(name
), debugstr_a(valueA
) );
1131 else WARN( "no system cursor found for %s\n", debugstr_w(name
) );
1136 /***********************************************************************
1137 * create_xlib_monochrome_cursor
1139 * Create a monochrome X cursor from a Windows one.
1141 static Cursor
create_xlib_monochrome_cursor( HDC hdc
, const ICONINFOEXW
*icon
, int width
, int height
)
1143 char buffer
[FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )];
1144 BITMAPINFO
*info
= (BITMAPINFO
*)buffer
;
1145 const int and_y
= 0;
1146 const int xor_y
= height
;
1147 unsigned int width_bytes
= (width
+ 31) / 32 * 4;
1148 unsigned char *mask_bits
= NULL
;
1151 XVisualInfo vis
= default_visual
;
1152 Pixmap src_pixmap
, bits_pixmap
, mask_pixmap
;
1153 struct gdi_image_bits bits
;
1156 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1157 info
->bmiHeader
.biWidth
= width
;
1158 info
->bmiHeader
.biHeight
= -height
* 2;
1159 info
->bmiHeader
.biPlanes
= 1;
1160 info
->bmiHeader
.biBitCount
= 1;
1161 info
->bmiHeader
.biCompression
= BI_RGB
;
1162 info
->bmiHeader
.biSizeImage
= width_bytes
* height
* 2;
1163 info
->bmiHeader
.biXPelsPerMeter
= 0;
1164 info
->bmiHeader
.biYPelsPerMeter
= 0;
1165 info
->bmiHeader
.biClrUsed
= 0;
1166 info
->bmiHeader
.biClrImportant
= 0;
1168 if (!(mask_bits
= HeapAlloc( GetProcessHeap(), 0, info
->bmiHeader
.biSizeImage
))) goto done
;
1169 if (!GetDIBits( hdc
, icon
->hbmMask
, 0, height
* 2, mask_bits
, info
, DIB_RGB_COLORS
)) goto done
;
1172 bits
.ptr
= mask_bits
;
1174 bits
.is_copy
= TRUE
;
1175 if (!(src_pixmap
= create_pixmap_from_image( hdc
, &vis
, info
, &bits
, DIB_RGB_COLORS
))) goto done
;
1177 bits_pixmap
= XCreatePixmap( gdi_display
, root_window
, width
, height
, 1 );
1178 mask_pixmap
= XCreatePixmap( gdi_display
, root_window
, width
, height
, 1 );
1179 gc
= XCreateGC( gdi_display
, src_pixmap
, 0, NULL
);
1180 XSetGraphicsExposures( gdi_display
, gc
, False
);
1182 /* We have to do some magic here, as cursors are not fully
1183 * compatible between Windows and X11. Under X11, there are
1184 * only 3 possible color cursor: black, white and masked. So
1185 * we map the 4th Windows color (invert the bits on the screen)
1186 * to black and an additional white bit on another place
1187 * (+1,+1). This require some boolean arithmetic:
1190 * And Xor Result | Bits Mask Result
1191 * 0 0 black | 0 1 background
1192 * 0 1 white | 1 1 foreground
1193 * 1 0 no change | X 0 no change
1194 * 1 1 inverted | 0 1 background
1197 * Bits = not 'And' and 'Xor' or 'And2' and 'Xor2'
1198 * Mask = not 'And' or 'Xor' or 'And2' and 'Xor2'
1200 XSetFunction( gdi_display
, gc
, GXcopy
);
1201 XCopyArea( gdi_display
, src_pixmap
, bits_pixmap
, gc
, 0, and_y
, width
, height
, 0, 0 );
1202 XCopyArea( gdi_display
, src_pixmap
, mask_pixmap
, gc
, 0, and_y
, width
, height
, 0, 0 );
1203 XSetFunction( gdi_display
, gc
, GXandReverse
);
1204 XCopyArea( gdi_display
, src_pixmap
, bits_pixmap
, gc
, 0, xor_y
, width
, height
, 0, 0 );
1205 XSetFunction( gdi_display
, gc
, GXorReverse
);
1206 XCopyArea( gdi_display
, src_pixmap
, mask_pixmap
, gc
, 0, xor_y
, width
, height
, 0, 0 );
1207 /* additional white */
1208 XSetFunction( gdi_display
, gc
, GXand
);
1209 XCopyArea( gdi_display
, src_pixmap
, src_pixmap
, gc
, 0, xor_y
, width
, height
, 0, and_y
);
1210 XSetFunction( gdi_display
, gc
, GXor
);
1211 XCopyArea( gdi_display
, src_pixmap
, mask_pixmap
, gc
, 0, and_y
, width
, height
, 1, 1 );
1212 XCopyArea( gdi_display
, src_pixmap
, bits_pixmap
, gc
, 0, and_y
, width
, height
, 1, 1 );
1213 XFreeGC( gdi_display
, gc
);
1215 fg
.red
= fg
.green
= fg
.blue
= 0xffff;
1216 bg
.red
= bg
.green
= bg
.blue
= 0;
1217 cursor
= XCreatePixmapCursor( gdi_display
, bits_pixmap
, mask_pixmap
,
1218 &fg
, &bg
, icon
->xHotspot
, icon
->yHotspot
);
1219 XFreePixmap( gdi_display
, src_pixmap
);
1220 XFreePixmap( gdi_display
, bits_pixmap
);
1221 XFreePixmap( gdi_display
, mask_pixmap
);
1224 HeapFree( GetProcessHeap(), 0, mask_bits
);
1228 /***********************************************************************
1229 * create_xlib_load_mono_cursor
1231 * Create a monochrome X cursor from a color Windows one by trying to load the monochrome resource.
1233 static Cursor
create_xlib_load_mono_cursor( HDC hdc
, HANDLE handle
, int width
, int height
)
1235 Cursor cursor
= None
;
1240 if (!(mono
= CopyImage( handle
, IMAGE_CURSOR
, width
, height
, LR_MONOCHROME
| LR_COPYFROMRESOURCE
)))
1243 info
.cbSize
= sizeof(info
);
1244 if (GetIconInfoExW( mono
, &info
))
1248 GetObjectW( info
.hbmMask
, sizeof(bm
), &bm
);
1249 bm
.bmHeight
= max( 1, bm
.bmHeight
/ 2 );
1250 /* make sure hotspot is valid */
1251 if (info
.xHotspot
>= bm
.bmWidth
|| info
.yHotspot
>= bm
.bmHeight
)
1253 info
.xHotspot
= bm
.bmWidth
/ 2;
1254 info
.yHotspot
= bm
.bmHeight
/ 2;
1256 cursor
= create_xlib_monochrome_cursor( hdc
, &info
, bm
.bmWidth
, bm
.bmHeight
);
1258 else DeleteObject( info
.hbmColor
);
1259 DeleteObject( info
.hbmMask
);
1261 DestroyCursor( mono
);
1265 /***********************************************************************
1266 * create_xlib_color_cursor
1268 * Create a color X cursor from a Windows one.
1270 static Cursor
create_xlib_color_cursor( HDC hdc
, const ICONINFOEXW
*icon
, int width
, int height
)
1272 char buffer
[FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )];
1273 BITMAPINFO
*info
= (BITMAPINFO
*)buffer
;
1275 Cursor cursor
= None
;
1276 XVisualInfo vis
= default_visual
;
1277 Pixmap xor_pixmap
, mask_pixmap
;
1278 struct gdi_image_bits bits
;
1279 unsigned int *color_bits
= NULL
, *ptr
;
1280 unsigned char *mask_bits
= NULL
, *xor_bits
= NULL
;
1282 BOOL has_alpha
= FALSE
;
1283 int rfg
, gfg
, bfg
, rbg
, gbg
, bbg
, fgBits
, bgBits
;
1284 unsigned int width_bytes
= (width
+ 31) / 32 * 4;
1286 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1287 info
->bmiHeader
.biWidth
= width
;
1288 info
->bmiHeader
.biHeight
= -height
;
1289 info
->bmiHeader
.biPlanes
= 1;
1290 info
->bmiHeader
.biBitCount
= 1;
1291 info
->bmiHeader
.biCompression
= BI_RGB
;
1292 info
->bmiHeader
.biSizeImage
= width_bytes
* height
;
1293 info
->bmiHeader
.biXPelsPerMeter
= 0;
1294 info
->bmiHeader
.biYPelsPerMeter
= 0;
1295 info
->bmiHeader
.biClrUsed
= 0;
1296 info
->bmiHeader
.biClrImportant
= 0;
1298 if (!(mask_bits
= HeapAlloc( GetProcessHeap(), 0, info
->bmiHeader
.biSizeImage
))) goto done
;
1299 if (!GetDIBits( hdc
, icon
->hbmMask
, 0, height
, mask_bits
, info
, DIB_RGB_COLORS
)) goto done
;
1301 info
->bmiHeader
.biBitCount
= 32;
1302 info
->bmiHeader
.biSizeImage
= width
* height
* 4;
1303 if (!(color_bits
= HeapAlloc( GetProcessHeap(), 0, info
->bmiHeader
.biSizeImage
))) goto done
;
1304 if (!(xor_bits
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, width_bytes
* height
))) goto done
;
1305 GetDIBits( hdc
, icon
->hbmColor
, 0, height
, color_bits
, info
, DIB_RGB_COLORS
);
1307 /* compute fg/bg color and xor bitmap based on average of the color values */
1309 rfg
= gfg
= bfg
= rbg
= gbg
= bbg
= fgBits
= 0;
1310 for (y
= 0, ptr
= color_bits
; y
< height
; y
++)
1312 for (x
= 0; x
< width
; x
++, ptr
++)
1314 int red
= (*ptr
>> 16) & 0xff;
1315 int green
= (*ptr
>> 8) & 0xff;
1316 int blue
= (*ptr
>> 0) & 0xff;
1317 if (red
+ green
+ blue
> 0x40)
1323 xor_bits
[y
* width_bytes
+ x
/ 8] |= 0x80 >> (x
% 8);
1335 fg
.red
= rfg
* 257 / fgBits
;
1336 fg
.green
= gfg
* 257 / fgBits
;
1337 fg
.blue
= bfg
* 257 / fgBits
;
1339 else fg
.red
= fg
.green
= fg
.blue
= 0;
1340 bgBits
= width
* height
- fgBits
;
1343 bg
.red
= rbg
* 257 / bgBits
;
1344 bg
.green
= gbg
* 257 / bgBits
;
1345 bg
.blue
= bbg
* 257 / bgBits
;
1347 else bg
.red
= bg
.green
= bg
.blue
= 0;
1349 info
->bmiHeader
.biBitCount
= 1;
1350 info
->bmiHeader
.biClrUsed
= 0;
1351 info
->bmiHeader
.biSizeImage
= width_bytes
* height
;
1353 /* generate mask from the alpha channel if we have one */
1355 for (i
= 0, ptr
= color_bits
; i
< width
* height
; i
++, ptr
++)
1356 if ((has_alpha
= (*ptr
& 0xff000000) != 0)) break;
1360 memset( mask_bits
, 0, width_bytes
* height
);
1361 for (y
= 0, ptr
= color_bits
; y
< height
; y
++)
1362 for (x
= 0; x
< width
; x
++, ptr
++)
1363 if ((*ptr
>> 24) > 25) /* more than 10% alpha */
1364 mask_bits
[y
* width_bytes
+ x
/ 8] |= 0x80 >> (x
% 8);
1366 else /* invert the mask */
1370 ptr
= (unsigned int *)mask_bits
;
1371 for (j
= 0; j
< info
->bmiHeader
.biSizeImage
/ sizeof(*ptr
); j
++, ptr
++) *ptr
^= ~0u;
1375 bits
.ptr
= xor_bits
;
1377 bits
.is_copy
= TRUE
;
1378 if (!(xor_pixmap
= create_pixmap_from_image( hdc
, &vis
, info
, &bits
, DIB_RGB_COLORS
))) goto done
;
1380 bits
.ptr
= mask_bits
;
1381 mask_pixmap
= create_pixmap_from_image( hdc
, &vis
, info
, &bits
, DIB_RGB_COLORS
);
1385 cursor
= XCreatePixmapCursor( gdi_display
, xor_pixmap
, mask_pixmap
,
1386 &fg
, &bg
, icon
->xHotspot
, icon
->yHotspot
);
1387 XFreePixmap( gdi_display
, mask_pixmap
);
1389 XFreePixmap( gdi_display
, xor_pixmap
);
1392 HeapFree( GetProcessHeap(), 0, color_bits
);
1393 HeapFree( GetProcessHeap(), 0, xor_bits
);
1394 HeapFree( GetProcessHeap(), 0, mask_bits
);
1398 /***********************************************************************
1401 * Create an X cursor from a Windows one.
1403 static Cursor
create_cursor( HANDLE handle
)
1410 if (!handle
) return get_empty_cursor();
1412 info
.cbSize
= sizeof(info
);
1413 if (!GetIconInfoExW( handle
, &info
)) return 0;
1415 if (use_system_cursors
&& (cursor
= create_xcursor_system_cursor( &info
)))
1417 DeleteObject( info
.hbmColor
);
1418 DeleteObject( info
.hbmMask
);
1422 GetObjectW( info
.hbmMask
, sizeof(bm
), &bm
);
1423 if (!info
.hbmColor
) bm
.bmHeight
= max( 1, bm
.bmHeight
/ 2 );
1425 /* make sure hotspot is valid */
1426 if (info
.xHotspot
>= bm
.bmWidth
|| info
.yHotspot
>= bm
.bmHeight
)
1428 info
.xHotspot
= bm
.bmWidth
/ 2;
1429 info
.yHotspot
= bm
.bmHeight
/ 2;
1432 hdc
= CreateCompatibleDC( 0 );
1436 #ifdef SONAME_LIBXCURSOR
1437 if (pXcursorImagesLoadCursor
)
1438 cursor
= create_xcursor_cursor( hdc
, &info
, handle
, bm
.bmWidth
, bm
.bmHeight
);
1440 if (!cursor
) cursor
= create_xlib_load_mono_cursor( hdc
, handle
, bm
.bmWidth
, bm
.bmHeight
);
1441 if (!cursor
) cursor
= create_xlib_color_cursor( hdc
, &info
, bm
.bmWidth
, bm
.bmHeight
);
1442 DeleteObject( info
.hbmColor
);
1446 cursor
= create_xlib_monochrome_cursor( hdc
, &info
, bm
.bmWidth
, bm
.bmHeight
);
1449 DeleteObject( info
.hbmMask
);
1454 /***********************************************************************
1455 * DestroyCursorIcon (X11DRV.@)
1457 void CDECL
X11DRV_DestroyCursorIcon( HCURSOR handle
)
1461 if (!XFindContext( gdi_display
, (XID
)handle
, cursor_context
, (char **)&cursor
))
1463 TRACE( "%p xid %lx\n", handle
, cursor
);
1464 XFreeCursor( gdi_display
, cursor
);
1465 XDeleteContext( gdi_display
, (XID
)handle
, cursor_context
);
1469 /***********************************************************************
1470 * SetCursor (X11DRV.@)
1472 void CDECL
X11DRV_SetCursor( HCURSOR handle
)
1474 if (InterlockedExchangePointer( (void **)&last_cursor
, handle
) != handle
||
1475 GetTickCount() - last_cursor_change
> 100)
1477 last_cursor_change
= GetTickCount();
1478 if (cursor_window
) SendNotifyMessageW( cursor_window
, WM_X11DRV_SET_CURSOR
, 0, (LPARAM
)handle
);
1482 /***********************************************************************
1483 * SetCursorPos (X11DRV.@)
1485 BOOL CDECL
X11DRV_SetCursorPos( INT x
, INT y
)
1487 struct x11drv_thread_data
*data
= x11drv_init_thread_data();
1488 POINT pos
= virtual_screen_to_root( x
, y
);
1490 if (keyboard_grabbed
)
1492 WARN( "refusing to warp to %u, %u\n", pos
.x
, pos
.y
);
1496 if (!clipping_cursor
&&
1497 XGrabPointer( data
->display
, root_window
, False
,
1498 PointerMotionMask
| ButtonPressMask
| ButtonReleaseMask
,
1499 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
)
1501 WARN( "refusing to warp pointer to %u, %u without exclusive grab\n", pos
.x
, pos
.y
);
1505 XWarpPointer( data
->display
, root_window
, root_window
, 0, 0, 0, 0, pos
.x
, pos
.y
);
1506 data
->warp_serial
= NextRequest( data
->display
);
1508 if (!clipping_cursor
)
1509 XUngrabPointer( data
->display
, CurrentTime
);
1511 XNoOp( data
->display
);
1512 XFlush( data
->display
); /* avoids bad mouse lag in games that do their own mouse warping */
1513 TRACE( "warped to %d,%d serial %lu\n", x
, y
, data
->warp_serial
);
1517 /***********************************************************************
1518 * GetCursorPos (X11DRV.@)
1520 BOOL CDECL
X11DRV_GetCursorPos(LPPOINT pos
)
1522 Display
*display
= thread_init_display();
1524 int rootX
, rootY
, winX
, winY
;
1525 unsigned int xstate
;
1528 ret
= XQueryPointer( display
, root_window
, &root
, &child
, &rootX
, &rootY
, &winX
, &winY
, &xstate
);
1532 *pos
= root_to_virtual_screen( winX
, winY
);
1533 TRACE( "pointer at %s server pos %s\n", wine_dbgstr_point(pos
), wine_dbgstr_point(&old
) );
1538 /***********************************************************************
1539 * ClipCursor (X11DRV.@)
1541 BOOL CDECL
X11DRV_ClipCursor( LPCRECT clip
)
1543 RECT virtual_rect
= get_virtual_screen_rect();
1545 if (!clip
) clip
= &virtual_rect
;
1549 HWND foreground
= GetForegroundWindow();
1552 /* forward request to the foreground window if it's in a different thread */
1553 tid
= GetWindowThreadProcessId( foreground
, &pid
);
1554 if (tid
&& tid
!= GetCurrentThreadId() && pid
== GetCurrentProcessId())
1556 TRACE( "forwarding clip request to %p\n", foreground
);
1557 SendNotifyMessageW( foreground
, WM_X11DRV_CLIP_CURSOR_REQUEST
, FALSE
, FALSE
);
1561 /* we are clipping if the clip rectangle is smaller than the screen */
1562 if (clip
->left
> virtual_rect
.left
|| clip
->right
< virtual_rect
.right
||
1563 clip
->top
> virtual_rect
.top
|| clip
->bottom
< virtual_rect
.bottom
)
1565 if (grab_clipping_window( clip
)) return TRUE
;
1567 else /* if currently clipping, check if we should switch to fullscreen clipping */
1569 struct x11drv_thread_data
*data
= x11drv_thread_data();
1570 if (data
&& data
->clip_hwnd
)
1572 if (EqualRect( clip
, &clip_rect
) || clip_fullscreen_window( foreground
, TRUE
))
1577 ungrab_clipping_window();
1581 /***********************************************************************
1582 * clip_cursor_request
1584 * Function called upon receiving a WM_X11DRV_CLIP_CURSOR_REQUEST.
1586 LRESULT
clip_cursor_request( HWND hwnd
, BOOL fullscreen
, BOOL reset
)
1590 if (hwnd
== GetDesktopWindow())
1591 WARN( "ignoring clip cursor request on desktop window.\n" );
1592 else if (hwnd
!= GetForegroundWindow())
1593 WARN( "ignoring clip cursor request on non-foreground window.\n" );
1594 else if (fullscreen
)
1595 clip_fullscreen_window( hwnd
, reset
);
1598 GetClipCursor( &clip
);
1599 X11DRV_ClipCursor( &clip
);
1605 /***********************************************************************
1606 * move_resize_window
1608 void move_resize_window( HWND hwnd
, int dir
)
1610 Display
*display
= thread_display();
1615 Window win
, root
, child
;
1616 unsigned int xstate
;
1618 if (!(win
= X11DRV_get_whole_window( hwnd
))) return;
1620 pt
= GetMessagePos();
1621 pos
= virtual_screen_to_root( (short)LOWORD( pt
), (short)HIWORD( pt
) );
1623 if (GetKeyState( VK_LBUTTON
) & 0x8000) button
= 1;
1624 else if (GetKeyState( VK_MBUTTON
) & 0x8000) button
= 2;
1625 else if (GetKeyState( VK_RBUTTON
) & 0x8000) button
= 3;
1627 TRACE( "hwnd %p/%lx, pos %s, dir %d, button %d\n", hwnd
, win
, wine_dbgstr_point(&pos
), dir
, button
);
1629 xev
.xclient
.type
= ClientMessage
;
1630 xev
.xclient
.window
= win
;
1631 xev
.xclient
.message_type
= x11drv_atom(_NET_WM_MOVERESIZE
);
1632 xev
.xclient
.serial
= 0;
1633 xev
.xclient
.display
= display
;
1634 xev
.xclient
.send_event
= True
;
1635 xev
.xclient
.format
= 32;
1636 xev
.xclient
.data
.l
[0] = pos
.x
; /* x coord */
1637 xev
.xclient
.data
.l
[1] = pos
.y
; /* y coord */
1638 xev
.xclient
.data
.l
[2] = dir
; /* direction */
1639 xev
.xclient
.data
.l
[3] = button
; /* button */
1640 xev
.xclient
.data
.l
[4] = 0; /* unused */
1642 /* need to ungrab the pointer that may have been automatically grabbed
1643 * with a ButtonPress event */
1644 XUngrabPointer( display
, CurrentTime
);
1645 XSendEvent(display
, root_window
, False
, SubstructureNotifyMask
| SubstructureRedirectMask
, &xev
);
1647 /* try to detect the end of the size/move by polling for the mouse button to be released */
1648 /* (some apps don't like it if we return before the size/move is done) */
1650 if (!button
) return;
1651 SendMessageW( hwnd
, WM_ENTERSIZEMOVE
, 0, 0 );
1657 int x
, y
, rootX
, rootY
;
1659 if (!XQueryPointer( display
, root_window
, &root
, &child
, &rootX
, &rootY
, &x
, &y
, &xstate
)) break;
1661 if (!(xstate
& (Button1Mask
<< (button
- 1))))
1663 /* fake a button release event */
1664 pos
= root_to_virtual_screen( x
, y
);
1665 input
.type
= INPUT_MOUSE
;
1666 input
.u
.mi
.dx
= pos
.x
;
1667 input
.u
.mi
.dy
= pos
.y
;
1668 input
.u
.mi
.mouseData
= button_up_data
[button
- 1];
1669 input
.u
.mi
.dwFlags
= button_up_flags
[button
- 1] | MOUSEEVENTF_ABSOLUTE
| MOUSEEVENTF_MOVE
;
1670 input
.u
.mi
.time
= GetTickCount();
1671 input
.u
.mi
.dwExtraInfo
= 0;
1672 __wine_send_input( hwnd
, &input
);
1675 while (PeekMessageW( &msg
, 0, 0, 0, PM_REMOVE
))
1677 if (!CallMsgFilterW( &msg
, MSGF_SIZE
))
1679 TranslateMessage( &msg
);
1680 DispatchMessageW( &msg
);
1684 if (!(xstate
& (Button1Mask
<< (button
- 1)))) break;
1685 MsgWaitForMultipleObjects( 0, NULL
, FALSE
, 100, QS_ALLINPUT
);
1688 TRACE( "hwnd %p/%lx done\n", hwnd
, win
);
1689 SendMessageW( hwnd
, WM_EXITSIZEMOVE
, 0, 0 );
1693 /***********************************************************************
1694 * X11DRV_ButtonPress
1696 BOOL
X11DRV_ButtonPress( HWND hwnd
, XEvent
*xev
)
1698 XButtonEvent
*event
= &xev
->xbutton
;
1699 int buttonNum
= event
->button
- 1;
1702 if (buttonNum
>= NB_BUTTONS
) return FALSE
;
1704 TRACE( "hwnd %p/%lx button %u pos %d,%d\n", hwnd
, event
->window
, buttonNum
, event
->x
, event
->y
);
1706 input
.u
.mi
.dx
= event
->x
;
1707 input
.u
.mi
.dy
= event
->y
;
1708 input
.u
.mi
.mouseData
= button_down_data
[buttonNum
];
1709 input
.u
.mi
.dwFlags
= button_down_flags
[buttonNum
] | MOUSEEVENTF_ABSOLUTE
| MOUSEEVENTF_MOVE
;
1710 input
.u
.mi
.time
= EVENT_x11_time_to_win32_time( event
->time
);
1711 input
.u
.mi
.dwExtraInfo
= 0;
1713 update_user_time( event
->time
);
1714 map_event_coords( hwnd
, event
->window
, event
->root
, event
->x_root
, event
->y_root
, &input
);
1715 send_mouse_input( hwnd
, event
->window
, event
->state
, &input
);
1720 /***********************************************************************
1721 * X11DRV_ButtonRelease
1723 BOOL
X11DRV_ButtonRelease( HWND hwnd
, XEvent
*xev
)
1725 XButtonEvent
*event
= &xev
->xbutton
;
1726 int buttonNum
= event
->button
- 1;
1729 if (buttonNum
>= NB_BUTTONS
|| !button_up_flags
[buttonNum
]) return FALSE
;
1731 TRACE( "hwnd %p/%lx button %u pos %d,%d\n", hwnd
, event
->window
, buttonNum
, event
->x
, event
->y
);
1733 input
.u
.mi
.dx
= event
->x
;
1734 input
.u
.mi
.dy
= event
->y
;
1735 input
.u
.mi
.mouseData
= button_up_data
[buttonNum
];
1736 input
.u
.mi
.dwFlags
= button_up_flags
[buttonNum
] | MOUSEEVENTF_ABSOLUTE
| MOUSEEVENTF_MOVE
;
1737 input
.u
.mi
.time
= EVENT_x11_time_to_win32_time( event
->time
);
1738 input
.u
.mi
.dwExtraInfo
= 0;
1740 map_event_coords( hwnd
, event
->window
, event
->root
, event
->x_root
, event
->y_root
, &input
);
1741 send_mouse_input( hwnd
, event
->window
, event
->state
, &input
);
1746 /***********************************************************************
1747 * X11DRV_MotionNotify
1749 BOOL
X11DRV_MotionNotify( HWND hwnd
, XEvent
*xev
)
1751 XMotionEvent
*event
= &xev
->xmotion
;
1754 TRACE( "hwnd %p/%lx pos %d,%d is_hint %d serial %lu\n",
1755 hwnd
, event
->window
, event
->x
, event
->y
, event
->is_hint
, event
->serial
);
1757 input
.u
.mi
.dx
= event
->x
;
1758 input
.u
.mi
.dy
= event
->y
;
1759 input
.u
.mi
.mouseData
= 0;
1760 input
.u
.mi
.dwFlags
= MOUSEEVENTF_MOVE
| MOUSEEVENTF_ABSOLUTE
;
1761 input
.u
.mi
.time
= EVENT_x11_time_to_win32_time( event
->time
);
1762 input
.u
.mi
.dwExtraInfo
= 0;
1764 if (!hwnd
&& is_old_motion_event( event
->serial
))
1766 TRACE( "pos %d,%d old serial %lu, ignoring\n", input
.u
.mi
.dx
, input
.u
.mi
.dy
, event
->serial
);
1769 map_event_coords( hwnd
, event
->window
, event
->root
, event
->x_root
, event
->y_root
, &input
);
1770 send_mouse_input( hwnd
, event
->window
, event
->state
, &input
);
1775 /***********************************************************************
1776 * X11DRV_EnterNotify
1778 BOOL
X11DRV_EnterNotify( HWND hwnd
, XEvent
*xev
)
1780 XCrossingEvent
*event
= &xev
->xcrossing
;
1783 TRACE( "hwnd %p/%lx pos %d,%d detail %d\n", hwnd
, event
->window
, event
->x
, event
->y
, event
->detail
);
1785 if (event
->detail
== NotifyVirtual
) return FALSE
;
1786 if (hwnd
== x11drv_thread_data()->grab_hwnd
) return FALSE
;
1788 /* simulate a mouse motion event */
1789 input
.u
.mi
.dx
= event
->x
;
1790 input
.u
.mi
.dy
= event
->y
;
1791 input
.u
.mi
.mouseData
= 0;
1792 input
.u
.mi
.dwFlags
= MOUSEEVENTF_MOVE
| MOUSEEVENTF_ABSOLUTE
;
1793 input
.u
.mi
.time
= EVENT_x11_time_to_win32_time( event
->time
);
1794 input
.u
.mi
.dwExtraInfo
= 0;
1796 if (is_old_motion_event( event
->serial
))
1798 TRACE( "pos %d,%d old serial %lu, ignoring\n", input
.u
.mi
.dx
, input
.u
.mi
.dy
, event
->serial
);
1801 map_event_coords( hwnd
, event
->window
, event
->root
, event
->x_root
, event
->y_root
, &input
);
1802 send_mouse_input( hwnd
, event
->window
, event
->state
, &input
);
1806 #ifdef HAVE_X11_EXTENSIONS_XINPUT2_H
1808 /***********************************************************************
1809 * X11DRV_DeviceChanged
1811 static BOOL
X11DRV_DeviceChanged( XGenericEventCookie
*xev
)
1813 XIDeviceChangedEvent
*event
= xev
->data
;
1814 struct x11drv_thread_data
*data
= x11drv_thread_data();
1816 if (event
->deviceid
!= data
->xi2_core_pointer
) return FALSE
;
1817 if (event
->reason
!= XISlaveSwitch
) return FALSE
;
1819 update_relative_valuators( event
->classes
, event
->num_classes
);
1820 data
->xi2_current_slave
= event
->sourceid
;
1824 /***********************************************************************
1827 static BOOL
X11DRV_RawMotion( XGenericEventCookie
*xev
)
1829 XIRawEvent
*event
= xev
->data
;
1830 const double *values
= event
->valuators
.values
;
1834 double dx
= 0, dy
= 0, val
;
1835 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
1836 struct x11drv_valuator_data
*x_rel
, *y_rel
;
1838 if (thread_data
->x_rel_valuator
.number
< 0 || thread_data
->y_rel_valuator
.number
< 0) return FALSE
;
1839 if (!event
->valuators
.mask_len
) return FALSE
;
1840 if (thread_data
->xi2_state
!= xi_enabled
) return FALSE
;
1842 /* If there is no slave currently detected, no previous motion nor device
1843 * change events were received. Look it up now on the device list in this
1846 if (!thread_data
->xi2_current_slave
)
1848 XIDeviceInfo
*devices
= thread_data
->xi2_devices
;
1850 for (i
= 0; i
< thread_data
->xi2_device_count
; i
++)
1852 if (devices
[i
].use
!= XISlavePointer
) continue;
1853 if (devices
[i
].deviceid
!= event
->deviceid
) continue;
1854 if (devices
[i
].attachment
!= thread_data
->xi2_core_pointer
) continue;
1855 thread_data
->xi2_current_slave
= event
->deviceid
;
1860 if (event
->deviceid
!= thread_data
->xi2_current_slave
) return FALSE
;
1862 x_rel
= &thread_data
->x_rel_valuator
;
1863 y_rel
= &thread_data
->y_rel_valuator
;
1865 input
.u
.mi
.mouseData
= 0;
1866 input
.u
.mi
.dwFlags
= MOUSEEVENTF_MOVE
;
1867 input
.u
.mi
.time
= EVENT_x11_time_to_win32_time( event
->time
);
1868 input
.u
.mi
.dwExtraInfo
= 0;
1872 virtual_rect
= get_virtual_screen_rect();
1874 for (i
= 0; i
<= max ( x_rel
->number
, y_rel
->number
); i
++)
1876 if (!XIMaskIsSet( event
->valuators
.mask
, i
)) continue;
1878 if (i
== x_rel
->number
)
1880 input
.u
.mi
.dx
= dx
= val
;
1881 if (x_rel
->min
< x_rel
->max
)
1882 input
.u
.mi
.dx
= val
* (virtual_rect
.right
- virtual_rect
.left
)
1883 / (x_rel
->max
- x_rel
->min
);
1885 if (i
== y_rel
->number
)
1887 input
.u
.mi
.dy
= dy
= val
;
1888 if (y_rel
->min
< y_rel
->max
)
1889 input
.u
.mi
.dy
= val
* (virtual_rect
.bottom
- virtual_rect
.top
)
1890 / (y_rel
->max
- y_rel
->min
);
1894 if (broken_rawevents
&& is_old_motion_event( xev
->serial
))
1896 TRACE( "pos %d,%d old serial %lu, ignoring\n", input
.u
.mi
.dx
, input
.u
.mi
.dy
, xev
->serial
);
1900 TRACE( "pos %d,%d (event %f,%f)\n", input
.u
.mi
.dx
, input
.u
.mi
.dy
, dx
, dy
);
1902 input
.type
= INPUT_MOUSE
;
1903 __wine_send_input( 0, &input
);
1907 #endif /* HAVE_X11_EXTENSIONS_XINPUT2_H */
1910 /***********************************************************************
1911 * X11DRV_XInput2_Init
1913 void X11DRV_XInput2_Init(void)
1915 #if defined(SONAME_LIBXI) && defined(HAVE_X11_EXTENSIONS_XINPUT2_H)
1917 void *libxi_handle
= dlopen( SONAME_LIBXI
, RTLD_NOW
);
1921 WARN( "couldn't load %s\n", SONAME_LIBXI
);
1924 #define LOAD_FUNCPTR(f) \
1925 if (!(p##f = dlsym( libxi_handle, #f))) \
1927 WARN("Failed to load %s.\n", #f); \
1931 LOAD_FUNCPTR(XIGetClientPointer
);
1932 LOAD_FUNCPTR(XIFreeDeviceInfo
);
1933 LOAD_FUNCPTR(XIQueryDevice
);
1934 LOAD_FUNCPTR(XIQueryVersion
);
1935 LOAD_FUNCPTR(XISelectEvents
);
1938 xinput2_available
= XQueryExtension( gdi_display
, "XInputExtension", &xinput2_opcode
, &event
, &error
);
1940 /* Until version 1.10.4 rawinput was broken in XOrg, see
1941 * https://bugs.freedesktop.org/show_bug.cgi?id=30068 */
1942 broken_rawevents
= strstr(XServerVendor( gdi_display
), "X.Org") &&
1943 XVendorRelease( gdi_display
) < 11004000;
1946 TRACE( "X Input 2 support not compiled in.\n" );
1951 /***********************************************************************
1952 * X11DRV_GenericEvent
1954 BOOL
X11DRV_GenericEvent( HWND hwnd
, XEvent
*xev
)
1957 #ifdef HAVE_X11_EXTENSIONS_XINPUT2_H
1958 XGenericEventCookie
*event
= &xev
->xcookie
;
1960 if (!event
->data
) return FALSE
;
1961 if (event
->extension
!= xinput2_opcode
) return FALSE
;
1963 switch (event
->evtype
)
1965 case XI_DeviceChanged
:
1966 ret
= X11DRV_DeviceChanged( event
);
1969 ret
= X11DRV_RawMotion( event
);
1973 TRACE( "Unhandled event %#x\n", event
->evtype
);