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
47 #define NONAMELESSSTRUCT
54 #include "wine/server.h"
55 #include "wine/library.h"
56 #include "wine/unicode.h"
57 #include "wine/debug.h"
59 WINE_DEFAULT_DEBUG_CHANNEL(cursor);
61 /**********************************************************************/
64 #define Button6Mask (1<<13)
67 #define Button7Mask (1<<14)
70 #define NB_BUTTONS 9 /* Windows can handle 5 buttons and the wheel too */
72 static const UINT button_down_flags[NB_BUTTONS] =
75 MOUSEEVENTF_MIDDLEDOWN,
76 MOUSEEVENTF_RIGHTDOWN,
79 MOUSEEVENTF_XDOWN, /* FIXME: horizontal wheel */
85 static const UINT button_up_flags[NB_BUTTONS] =
98 static const UINT button_down_data[NB_BUTTONS] =
111 static const UINT button_up_data[NB_BUTTONS] =
124 static HWND cursor_window;
125 static HCURSOR last_cursor;
126 static DWORD last_cursor_change;
127 static XContext cursor_context;
128 static RECT clip_rect;
129 static Cursor create_cursor( HANDLE handle );
131 #ifdef HAVE_X11_EXTENSIONS_XINPUT2_H
132 static BOOL xinput2_available;
133 static int xinput2_core_pointer;
134 #define MAKE_FUNCPTR(f) static typeof(f) * p##f
135 MAKE_FUNCPTR(XIFreeDeviceInfo);
136 MAKE_FUNCPTR(XIQueryDevice);
137 MAKE_FUNCPTR(XIQueryVersion);
138 MAKE_FUNCPTR(XISelectEvents);
142 /***********************************************************************
143 * X11DRV_Xcursor_Init
145 * Load the Xcursor library for use.
147 void X11DRV_Xcursor_Init(void)
149 #ifdef SONAME_LIBXCURSOR
150 xcursor_handle = wine_dlopen(SONAME_LIBXCURSOR, RTLD_NOW, NULL, 0);
151 if (!xcursor_handle) /* wine_dlopen failed. */
153 WARN("Xcursor failed to load. Using fallback code.\n");
156 #define LOAD_FUNCPTR(f) \
157 p##f = wine_dlsym(xcursor_handle, #f, NULL, 0)
159 LOAD_FUNCPTR(XcursorImageCreate);
160 LOAD_FUNCPTR(XcursorImageDestroy);
161 LOAD_FUNCPTR(XcursorImageLoadCursor);
162 LOAD_FUNCPTR(XcursorImagesCreate);
163 LOAD_FUNCPTR(XcursorImagesDestroy);
164 LOAD_FUNCPTR(XcursorImagesLoadCursor);
165 LOAD_FUNCPTR(XcursorLibraryLoadCursor);
167 #endif /* SONAME_LIBXCURSOR */
171 /***********************************************************************
174 static Cursor get_empty_cursor(void)
176 static Cursor cursor;
177 static const char data[] = { 0 };
185 bg.red = bg.green = bg.blue = 0x0000;
186 pixmap = XCreateBitmapFromData( gdi_display, root_window, data, 1, 1 );
189 cursor = XCreatePixmapCursor( gdi_display, pixmap, pixmap, &bg, &bg, 0, 0 );
190 XFreePixmap( gdi_display, pixmap );
197 /***********************************************************************
200 void set_window_cursor( Window window, HCURSOR handle )
205 if (!handle) cursor = get_empty_cursor();
206 else if (!cursor_context || XFindContext( gdi_display, (XID)handle, cursor_context, (char **)&cursor ))
208 /* try to create it */
210 if (!(cursor = create_cursor( handle ))) return;
213 if (!cursor_context) cursor_context = XUniqueContext();
214 if (!XFindContext( gdi_display, (XID)handle, cursor_context, (char **)&prev ))
216 /* someone else was here first */
217 XFreeCursor( gdi_display, cursor );
222 XSaveContext( gdi_display, (XID)handle, cursor_context, (char *)cursor );
223 TRACE( "cursor %p created %lx\n", handle, cursor );
227 XDefineCursor( gdi_display, window, cursor );
228 /* make the change take effect immediately */
229 XFlush( gdi_display );
233 /***********************************************************************
236 void sync_window_cursor( Window window )
240 SERVER_START_REQ( set_cursor )
243 wine_server_call( req );
244 cursor = reply->prev_count >= 0 ? wine_server_ptr_handle( reply->prev_handle ) : 0;
248 set_window_cursor( window, cursor );
251 /***********************************************************************
254 static void enable_xinput2(void)
256 #ifdef HAVE_X11_EXTENSIONS_XINPUT2_H
257 struct x11drv_thread_data *data = x11drv_thread_data();
258 XIDeviceInfo *devices;
260 unsigned char mask_bits[XIMaskLen(XI_LASTEVENT)];
263 if (!xinput2_available) return;
265 if (data->xi2_state == xi_unknown)
267 int major = 2, minor = 0;
269 if (!pXIQueryVersion( data->display, &major, &minor )) data->xi2_state = xi_disabled;
272 data->xi2_state = xi_unavailable;
273 WARN( "X Input 2 not available\n" );
277 if (data->xi2_state == xi_unavailable) return;
280 devices = pXIQueryDevice( data->display, XIAllDevices, &count );
281 for (i = 0; i < count; ++i)
283 if (devices[i].use != XIMasterPointer) continue;
284 for (j = 0; j < devices[i].num_classes; j++)
286 XIValuatorClassInfo *class = (XIValuatorClassInfo *)devices[i].classes[j];
288 if (devices[i].classes[j]->type != XIValuatorClass) continue;
289 if (class->number != 0 && class->number != 1) continue;
290 if (class->mode == XIModeAbsolute)
292 TRACE( "Device %u (%s) class %u num %u %f,%f res %u is absolute, not enabling XInput2\n",
293 devices[i].deviceid, debugstr_a(devices[i].name),
294 j, class->number, class->min, class->max, class->resolution );
298 TRACE( "Using %u (%s) as core pointer\n",
299 devices[i].deviceid, debugstr_a(devices[i].name) );
300 xinput2_core_pointer = devices[i].deviceid;
304 mask.mask = mask_bits;
305 mask.mask_len = sizeof(mask_bits);
306 memset( mask_bits, 0, sizeof(mask_bits) );
307 XISetMask( mask_bits, XI_RawMotion );
308 XISetMask( mask_bits, XI_ButtonPress );
310 for (i = 0; i < count; ++i)
312 if (devices[i].use == XISlavePointer && devices[i].attachment == xinput2_core_pointer)
314 TRACE( "Device %u (%s) is attached to the core pointer\n",
315 devices[i].deviceid, debugstr_a(devices[i].name) );
316 mask.deviceid = devices[i].deviceid;
317 pXISelectEvents( data->display, DefaultRootWindow( data->display ), &mask, 1 );
318 data->xi2_state = xi_enabled;
323 pXIFreeDeviceInfo( devices );
328 /***********************************************************************
331 static void disable_xinput2(void)
333 #ifdef HAVE_X11_EXTENSIONS_XINPUT2_H
334 struct x11drv_thread_data *data = x11drv_thread_data();
336 XIDeviceInfo *devices;
339 if (data->xi2_state != xi_enabled) return;
341 TRACE( "disabling\n" );
342 data->xi2_state = xi_disabled;
348 devices = pXIQueryDevice( data->display, XIAllDevices, &count );
349 for (i = 0; i < count; ++i)
351 if (devices[i].use == XISlavePointer && devices[i].attachment == xinput2_core_pointer)
353 mask.deviceid = devices[i].deviceid;
354 pXISelectEvents( data->display, DefaultRootWindow( data->display ), &mask, 1 );
357 pXIFreeDeviceInfo( devices );
363 /***********************************************************************
364 * grab_clipping_window
366 * Start a pointer grab on the clip window.
368 static BOOL grab_clipping_window( const RECT *clip, BOOL only_with_xinput )
370 static const WCHAR messageW[] = {'M','e','s','s','a','g','e',0};
371 struct x11drv_thread_data *data = x11drv_thread_data();
375 if (!data) return FALSE;
376 if (!(clip_window = init_clip_window())) return TRUE;
378 if (!(msg_hwnd = CreateWindowW( messageW, NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, 0,
379 GetModuleHandleW(0), NULL )))
382 /* enable XInput2 unless we are already clipping */
383 if (!data->clip_hwnd) enable_xinput2();
385 /* don't clip to 1x1 rectangle if we don't have XInput */
386 if (clip->right - clip->left == 1 && clip->bottom - clip->top == 1) only_with_xinput = TRUE;
387 if (only_with_xinput && data->xi2_state != xi_enabled)
389 WARN( "XInput2 not supported, refusing to clip to %s\n", wine_dbgstr_rect(clip) );
390 DestroyWindow( msg_hwnd );
395 TRACE( "clipping to %s win %lx\n", wine_dbgstr_rect(clip), clip_window );
398 if (!data->clip_hwnd) XUnmapWindow( data->display, clip_window );
399 XMoveResizeWindow( data->display, clip_window,
400 clip->left - virtual_screen_rect.left, clip->top - virtual_screen_rect.top,
401 max( 1, clip->right - clip->left ), max( 1, clip->bottom - clip->top ) );
402 XMapWindow( data->display, clip_window );
404 /* if the rectangle is shrinking we may get a pointer warp */
405 if (!data->clip_hwnd || clip->left > clip_rect.left || clip->top > clip_rect.top ||
406 clip->right < clip_rect.right || clip->bottom < clip_rect.bottom)
407 data->warp_serial = NextRequest( data->display );
409 if (!XGrabPointer( data->display, clip_window, False,
410 PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
411 GrabModeAsync, GrabModeAsync, clip_window, None, CurrentTime ))
415 if (!clipping_cursor)
418 DestroyWindow( msg_hwnd );
422 if (!data->clip_hwnd) sync_window_cursor( clip_window );
423 InterlockedExchangePointer( (void **)&cursor_window, msg_hwnd );
424 data->clip_hwnd = msg_hwnd;
425 SendMessageW( GetDesktopWindow(), WM_X11DRV_CLIP_CURSOR, 0, (LPARAM)msg_hwnd );
429 /***********************************************************************
430 * ungrab_clipping_window
432 * Release the pointer grab on the clip window.
434 void ungrab_clipping_window(void)
436 Display *display = thread_init_display();
437 Window clip_window = init_clip_window();
439 if (!clip_window) return;
441 TRACE( "no longer clipping\n" );
443 XUnmapWindow( display, clip_window );
446 SendMessageW( GetDesktopWindow(), WM_X11DRV_CLIP_CURSOR, 0, 0 );
449 /***********************************************************************
450 * reset_clipping_window
452 * Forcibly reset the window clipping on external events.
454 void reset_clipping_window(void)
456 ungrab_clipping_window();
457 ClipCursor( NULL ); /* make sure the clip rectangle is reset too */
460 /***********************************************************************
463 * Notification function called upon receiving a WM_X11DRV_CLIP_CURSOR.
465 LRESULT clip_cursor_notify( HWND hwnd, HWND new_clip_hwnd )
467 struct x11drv_thread_data *data = x11drv_thread_data();
469 if (hwnd == GetDesktopWindow()) /* change the clip window stored in the desktop process */
471 static HWND clip_hwnd;
473 HWND prev = clip_hwnd;
474 clip_hwnd = new_clip_hwnd;
475 if (prev || new_clip_hwnd) TRACE( "clip hwnd changed from %p to %p\n", prev, new_clip_hwnd );
476 if (prev) SendNotifyMessageW( prev, WM_X11DRV_CLIP_CURSOR, 0, 0 );
478 else if (hwnd == data->clip_hwnd) /* this is a notification that clipping has been reset */
480 TRACE( "clip hwnd reset from %p\n", hwnd );
482 data->clip_reset = GetTickCount();
484 DestroyWindow( hwnd );
486 else if (hwnd == GetForegroundWindow()) /* request to clip */
490 GetClipCursor( &clip );
491 if (clip.left > virtual_screen_rect.left || clip.right < virtual_screen_rect.right ||
492 clip.top > virtual_screen_rect.top || clip.bottom < virtual_screen_rect.bottom)
493 return grab_clipping_window( &clip, FALSE );
498 /***********************************************************************
499 * clip_fullscreen_window
501 * Turn on clipping if the active window is fullscreen.
503 BOOL clip_fullscreen_window( HWND hwnd, BOOL reset )
505 struct x11drv_win_data *data;
506 struct x11drv_thread_data *thread_data;
510 if (hwnd == GetDesktopWindow()) return FALSE;
511 if (!(data = X11DRV_get_win_data( hwnd ))) return FALSE;
512 style = GetWindowLongW( hwnd, GWL_STYLE );
513 if (!(style & WS_VISIBLE)) return FALSE;
514 if ((style & (WS_POPUP | WS_CHILD)) == WS_CHILD) return FALSE;
515 /* maximized windows don't count as full screen */
516 if ((style & WS_MAXIMIZE) && (style & WS_CAPTION) == WS_CAPTION) return FALSE;
517 if (!is_window_rect_fullscreen( &data->whole_rect )) return FALSE;
518 if (!(thread_data = x11drv_thread_data())) return FALSE;
519 if (GetTickCount() - thread_data->clip_reset < 1000) return FALSE;
520 if (!reset && clipping_cursor && thread_data->clip_hwnd) return FALSE; /* already clipping */
521 SetRect( &rect, 0, 0, screen_width, screen_height );
522 if (!grab_fullscreen)
524 if (!EqualRect( &rect, &virtual_screen_rect )) return FALSE;
525 if (root_window != DefaultRootWindow( gdi_display )) return FALSE;
527 TRACE( "win %p clipping fullscreen\n", hwnd );
528 return grab_clipping_window( &rect, TRUE );
531 /***********************************************************************
534 * Update the various window states on a mouse event.
536 static void send_mouse_input( HWND hwnd, Window window, unsigned int state, INPUT *input )
538 struct x11drv_win_data *data;
541 input->type = INPUT_MOUSE;
545 struct x11drv_thread_data *thread_data = x11drv_thread_data();
546 HWND clip_hwnd = thread_data->clip_hwnd;
548 if (!clip_hwnd) return;
549 if (thread_data->clip_window != window) return;
550 if (InterlockedExchangePointer( (void **)&cursor_window, clip_hwnd ) != clip_hwnd ||
551 input->u.mi.time - last_cursor_change > 100)
553 sync_window_cursor( window );
554 last_cursor_change = input->u.mi.time;
556 input->u.mi.dx += clip_rect.left;
557 input->u.mi.dy += clip_rect.top;
558 __wine_send_input( hwnd, input );
562 if (!(data = X11DRV_get_win_data( hwnd ))) return;
564 if (window == data->whole_window)
566 input->u.mi.dx += data->whole_rect.left - data->client_rect.left;
567 input->u.mi.dy += data->whole_rect.top - data->client_rect.top;
569 if (window == root_window)
571 input->u.mi.dx += virtual_screen_rect.left;
572 input->u.mi.dy += virtual_screen_rect.top;
574 pt.x = input->u.mi.dx;
575 pt.y = input->u.mi.dy;
576 if (GetWindowLongW( data->hwnd, GWL_EXSTYLE ) & WS_EX_LAYOUTRTL)
577 pt.x = data->client_rect.right - data->client_rect.left - 1 - pt.x;
578 MapWindowPoints( hwnd, 0, &pt, 1 );
580 if (InterlockedExchangePointer( (void **)&cursor_window, hwnd ) != hwnd ||
581 input->u.mi.time - last_cursor_change > 100)
583 sync_window_cursor( data->whole_window );
584 last_cursor_change = input->u.mi.time;
587 if (hwnd != GetDesktopWindow())
589 hwnd = GetAncestor( hwnd, GA_ROOT );
590 if ((input->u.mi.dwFlags & (MOUSEEVENTF_LEFTDOWN|MOUSEEVENTF_RIGHTDOWN)) && hwnd == GetForegroundWindow())
591 clip_fullscreen_window( hwnd, FALSE );
594 /* update the wine server Z-order */
596 if (window != x11drv_thread_data()->grab_window &&
597 /* ignore event if a button is pressed, since the mouse is then grabbed too */
598 !(state & (Button1Mask|Button2Mask|Button3Mask|Button4Mask|Button5Mask|Button6Mask|Button7Mask)))
601 SetRect( &rect, pt.x, pt.y, pt.x + 1, pt.y + 1 );
602 MapWindowPoints( 0, hwnd, (POINT *)&rect, 2 );
604 SERVER_START_REQ( update_window_zorder )
606 req->window = wine_server_user_handle( hwnd );
607 req->rect.left = rect.left;
608 req->rect.top = rect.top;
609 req->rect.right = rect.right;
610 req->rect.bottom = rect.bottom;
611 wine_server_call( req );
616 input->u.mi.dx = pt.x;
617 input->u.mi.dy = pt.y;
618 __wine_send_input( hwnd, input );
621 #ifdef SONAME_LIBXCURSOR
623 /***********************************************************************
624 * create_xcursor_frame
626 * Use Xcursor to create a frame of an X cursor from a Windows one.
628 static XcursorImage *create_xcursor_frame( HDC hdc, const ICONINFOEXW *iinfo, HANDLE icon,
629 HBITMAP hbmColor, unsigned char *color_bits, int color_size,
630 HBITMAP hbmMask, unsigned char *mask_bits, int mask_size,
631 int width, int height, int istep )
633 XcursorImage *image, *ret = NULL;
634 DWORD delay_jiffies, num_steps;
635 int x, y, i, has_alpha = FALSE;
639 image = pXcursorImageCreate( width, height );
643 ERR("X11 failed to produce a cursor frame!\n");
647 image->xhot = iinfo->xHotspot;
648 image->yhot = iinfo->yHotspot;
650 image->delay = 100; /* fallback delay, 100 ms */
651 if (GetCursorFrameInfo(icon, 0x0 /* unknown parameter */, istep, &delay_jiffies, &num_steps) != 0)
652 image->delay = (100 * delay_jiffies) / 6; /* convert jiffies (1/60s) to milliseconds */
654 WARN("Failed to retrieve animated cursor frame-rate for frame %d.\n", istep);
656 /* draw the cursor frame to a temporary buffer then copy it into the XcursorImage */
657 memset( color_bits, 0x00, color_size );
658 SelectObject( hdc, hbmColor );
659 if (!DrawIconEx( hdc, 0, 0, icon, width, height, istep, NULL, DI_NORMAL ))
661 TRACE("Could not draw frame %d (walk past end of frames).\n", istep);
664 memcpy( image->pixels, color_bits, color_size );
666 /* check if the cursor frame was drawn with an alpha channel */
667 for (i = 0, ptr = image->pixels; i < width * height; i++, ptr++)
668 if ((has_alpha = (*ptr & 0xff000000) != 0)) break;
670 /* if no alpha channel was drawn then generate it from the mask */
673 unsigned int width_bytes = (width + 31) / 32 * 4;
675 /* draw the cursor mask to a temporary buffer */
676 memset( mask_bits, 0xFF, mask_size );
677 SelectObject( hdc, hbmMask );
678 if (!DrawIconEx( hdc, 0, 0, icon, width, height, istep, NULL, DI_MASK ))
680 ERR("Failed to draw frame mask %d.\n", istep);
683 /* use the buffer to directly modify the XcursorImage alpha channel */
684 for (y = 0, ptr = image->pixels; y < height; y++)
685 for (x = 0; x < width; x++, ptr++)
686 if (!((mask_bits[y * width_bytes + x / 8] << (x % 8)) & 0x80))
692 if (ret == NULL) pXcursorImageDestroy( image );
696 /***********************************************************************
697 * create_xcursor_cursor
699 * Use Xcursor to create an X cursor from a Windows one.
701 static Cursor create_xcursor_cursor( HDC hdc, const ICONINFOEXW *iinfo, HANDLE icon, int width, int height )
703 unsigned char *color_bits, *mask_bits;
704 HBITMAP hbmColor = 0, hbmMask = 0;
705 DWORD nFrames, delay_jiffies, i;
706 int color_size, mask_size;
707 BITMAPINFO *info = NULL;
708 XcursorImages *images;
712 /* Retrieve the number of frames to render */
713 if (!GetCursorFrameInfo(icon, 0x0 /* unknown parameter */, 0, &delay_jiffies, &nFrames)) return 0;
714 if (!(imgs = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(XcursorImage*)*nFrames ))) return 0;
716 /* Allocate all of the resources necessary to obtain a cursor frame */
717 if (!(info = HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO, bmiColors[256] )))) goto cleanup;
718 info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
719 info->bmiHeader.biWidth = width;
720 info->bmiHeader.biHeight = -height;
721 info->bmiHeader.biPlanes = 1;
722 info->bmiHeader.biCompression = BI_RGB;
723 info->bmiHeader.biXPelsPerMeter = 0;
724 info->bmiHeader.biYPelsPerMeter = 0;
725 info->bmiHeader.biClrUsed = 0;
726 info->bmiHeader.biClrImportant = 0;
727 info->bmiHeader.biBitCount = 32;
728 color_size = width * height * 4;
729 info->bmiHeader.biSizeImage = color_size;
730 hbmColor = CreateDIBSection( hdc, info, DIB_RGB_COLORS, (VOID **) &color_bits, NULL, 0);
733 ERR("Failed to create DIB section for cursor color data!\n");
736 info->bmiHeader.biBitCount = 1;
737 info->bmiColors[0].rgbRed = 0;
738 info->bmiColors[0].rgbGreen = 0;
739 info->bmiColors[0].rgbBlue = 0;
740 info->bmiColors[0].rgbReserved = 0;
741 info->bmiColors[1].rgbRed = 0xff;
742 info->bmiColors[1].rgbGreen = 0xff;
743 info->bmiColors[1].rgbBlue = 0xff;
744 info->bmiColors[1].rgbReserved = 0;
746 mask_size = ((width + 31) / 32 * 4) * height; /* width_bytes * height */
747 info->bmiHeader.biSizeImage = mask_size;
748 hbmMask = CreateDIBSection( hdc, info, DIB_RGB_COLORS, (VOID **) &mask_bits, NULL, 0);
751 ERR("Failed to create DIB section for cursor mask data!\n");
755 /* Create an XcursorImage for each frame of the cursor */
756 for (i=0; i<nFrames; i++)
758 imgs[i] = create_xcursor_frame( hdc, iinfo, icon,
759 hbmColor, color_bits, color_size,
760 hbmMask, mask_bits, mask_size,
762 if (!imgs[i]) goto cleanup;
765 /* Build an X cursor out of all of the frames */
766 if (!(images = pXcursorImagesCreate( nFrames ))) goto cleanup;
767 for (images->nimage = 0; images->nimage < nFrames; images->nimage++)
768 images->images[images->nimage] = imgs[images->nimage];
770 cursor = pXcursorImagesLoadCursor( gdi_display, images );
772 pXcursorImagesDestroy( images ); /* Note: this frees each individual frame (calls XcursorImageDestroy) */
773 HeapFree( GetProcessHeap(), 0, imgs );
779 /* Failed to produce a cursor, free previously allocated frames */
780 for (i=0; i<nFrames && imgs[i]; i++)
781 pXcursorImageDestroy( imgs[i] );
782 HeapFree( GetProcessHeap(), 0, imgs );
784 /* Cleanup all of the resources used to obtain the frame data */
785 if (hbmColor) DeleteObject( hbmColor );
786 if (hbmMask) DeleteObject( hbmMask );
787 HeapFree( GetProcessHeap(), 0, info );
792 struct system_cursors
798 static const struct system_cursors user32_cursors[] =
800 { OCR_NORMAL, "left_ptr" },
801 { OCR_IBEAM, "xterm" },
802 { OCR_WAIT, "watch" },
803 { OCR_CROSS, "cross" },
804 { OCR_UP, "center_ptr" },
805 { OCR_SIZE, "fleur" },
806 { OCR_SIZEALL, "fleur" },
807 { OCR_ICON, "icon" },
808 { OCR_SIZENWSE, "nwse-resize" },
809 { OCR_SIZENESW, "nesw-resize" },
810 { OCR_SIZEWE, "ew-resize" },
811 { OCR_SIZENS, "ns-resize" },
812 { OCR_NO, "not-allowed" },
813 { OCR_HAND, "hand2" },
814 { OCR_APPSTARTING, "left_ptr_watch" },
815 { OCR_HELP, "question_arrow" },
819 static const struct system_cursors comctl32_cursors[] =
824 { 106, "row-resize" },
825 { 107, "row-resize" },
827 { 135, "col-resize" },
831 static const struct system_cursors ole32_cursors[] =
840 static const struct system_cursors riched20_cursors[] =
843 { 107, "right_ptr" },
852 const struct system_cursors *cursors;
856 { user32_cursors, {'u','s','e','r','3','2','.','d','l','l',0} },
857 { comctl32_cursors, {'c','o','m','c','t','l','3','2','.','d','l','l',0} },
858 { ole32_cursors, {'o','l','e','3','2','.','d','l','l',0} },
859 { riched20_cursors, {'r','i','c','h','e','d','2','0','.','d','l','l',0} }
862 /***********************************************************************
863 * create_xcursor_system_cursor
865 * Create an X cursor for a system cursor.
867 static Cursor create_xcursor_system_cursor( const ICONINFOEXW *info )
869 static const WCHAR idW[] = {'%','h','u',0};
870 const struct system_cursors *cursors;
875 WCHAR *p, name[MAX_PATH * 2], valueW[64];
879 if (!pXcursorLibraryLoadCursor) return 0;
880 if (!info->szModName[0]) return 0;
882 p = strrchrW( info->szModName, '\\' );
883 strcpyW( name, p ? p + 1 : info->szModName );
884 p = name + strlenW( name );
886 if (info->szResName[0]) strcpyW( p, info->szResName );
887 else sprintfW( p, idW, info->wResID );
890 /* @@ Wine registry key: HKCU\Software\Wine\X11 Driver\Cursors */
891 if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\X11 Driver\\Cursors", &key ))
893 size = sizeof(valueW) / sizeof(WCHAR);
894 ret = RegQueryValueExW( key, name, NULL, NULL, (BYTE *)valueW, &size );
898 if (!valueW[0]) return 0; /* force standard cursor */
899 if (!WideCharToMultiByte( CP_UNIXCP, 0, valueW, -1, valueA, sizeof(valueA), NULL, NULL ))
905 if (info->szResName[0]) goto done; /* only integer resources are supported here */
906 if (!(module = GetModuleHandleW( info->szModName ))) goto done;
908 for (i = 0; i < sizeof(module_cursors)/sizeof(module_cursors[0]); i++)
909 if (GetModuleHandleW( module_cursors[i].name ) == module) break;
910 if (i == sizeof(module_cursors)/sizeof(module_cursors[0])) goto done;
912 cursors = module_cursors[i].cursors;
913 for (i = 0; cursors[i].id; i++)
914 if (cursors[i].id == info->wResID)
916 strcpy( valueA, cursors[i].name );
924 cursor = pXcursorLibraryLoadCursor( gdi_display, valueA );
926 if (!cursor) WARN( "no system cursor found for %s mapped to %s\n",
927 debugstr_w(name), debugstr_a(valueA) );
929 else WARN( "no system cursor found for %s\n", debugstr_w(name) );
933 #endif /* SONAME_LIBXCURSOR */
936 /***********************************************************************
937 * create_cursor_from_bitmaps
939 * Create an X11 cursor from source bitmaps.
941 static Cursor create_cursor_from_bitmaps( HBITMAP src_xor, HBITMAP src_and, int width, int height,
942 int xor_y, int and_y, XColor *fg, XColor *bg,
943 int hotspot_x, int hotspot_y )
945 HDC src = 0, dst = 0;
946 HBITMAP bits = 0, mask = 0, mask_inv = 0;
949 if (!(src = CreateCompatibleDC( 0 ))) goto done;
950 if (!(dst = CreateCompatibleDC( 0 ))) goto done;
952 if (!(bits = CreateBitmap( width, height, 1, 1, NULL ))) goto done;
953 if (!(mask = CreateBitmap( width, height, 1, 1, NULL ))) goto done;
954 if (!(mask_inv = CreateBitmap( width, height, 1, 1, NULL ))) goto done;
956 /* We have to do some magic here, as cursors are not fully
957 * compatible between Windows and X11. Under X11, there are
958 * only 3 possible color cursor: black, white and masked. So
959 * we map the 4th Windows color (invert the bits on the screen)
960 * to black and an additional white bit on an other place
961 * (+1,+1). This require some boolean arithmetic:
964 * And Xor Result | Bits Mask Result
965 * 0 0 black | 0 1 background
966 * 0 1 white | 1 1 foreground
967 * 1 0 no change | X 0 no change
968 * 1 1 inverted | 0 1 background
971 * Bits = not 'And' and 'Xor' or 'And2' and 'Xor2'
972 * Mask = not 'And' or 'Xor' or 'And2' and 'Xor2'
974 SelectObject( src, src_and );
975 SelectObject( dst, bits );
976 BitBlt( dst, 0, 0, width, height, src, 0, and_y, SRCCOPY );
977 SelectObject( dst, mask );
978 BitBlt( dst, 0, 0, width, height, src, 0, and_y, SRCCOPY );
979 SelectObject( dst, mask_inv );
980 BitBlt( dst, 0, 0, width, height, src, 0, and_y, SRCCOPY );
981 SelectObject( src, src_xor );
982 BitBlt( dst, 0, 0, width, height, src, 0, xor_y, SRCAND /* src & dst */ );
983 SelectObject( dst, bits );
984 BitBlt( dst, 0, 0, width, height, src, 0, xor_y, SRCERASE /* src & ~dst */ );
985 SelectObject( dst, mask );
986 BitBlt( dst, 0, 0, width, height, src, 0, xor_y, 0xdd0228 /* src | ~dst */ );
987 /* additional white */
988 SelectObject( src, mask_inv );
989 BitBlt( dst, 1, 1, width, height, src, 0, 0, SRCPAINT /* src | dst */);
990 SelectObject( dst, bits );
991 BitBlt( dst, 1, 1, width, height, src, 0, 0, SRCPAINT /* src | dst */ );
994 cursor = XCreatePixmapCursor( gdi_display, X11DRV_get_pixmap(bits), X11DRV_get_pixmap(mask),
995 fg, bg, hotspot_x, hotspot_y );
1001 DeleteObject( bits );
1002 DeleteObject( mask );
1003 DeleteObject( mask_inv );
1007 /***********************************************************************
1008 * create_xlib_cursor
1010 * Create an X cursor from a Windows one.
1012 static Cursor create_xlib_cursor( HDC hdc, const ICONINFOEXW *icon, int width, int height )
1015 Cursor cursor = None;
1016 HBITMAP xor_bitmap = 0;
1018 unsigned int *color_bits = NULL, *ptr;
1019 unsigned char *mask_bits = NULL, *xor_bits = NULL;
1020 int i, x, y, has_alpha = 0;
1021 int rfg, gfg, bfg, rbg, gbg, bbg, fgBits, bgBits;
1022 unsigned int width_bytes = (width + 31) / 32 * 4;
1024 if (!(info = HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO, bmiColors[256] ))))
1026 info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1027 info->bmiHeader.biWidth = width;
1028 info->bmiHeader.biHeight = -height;
1029 info->bmiHeader.biPlanes = 1;
1030 info->bmiHeader.biBitCount = 1;
1031 info->bmiHeader.biCompression = BI_RGB;
1032 info->bmiHeader.biSizeImage = width_bytes * height;
1033 info->bmiHeader.biXPelsPerMeter = 0;
1034 info->bmiHeader.biYPelsPerMeter = 0;
1035 info->bmiHeader.biClrUsed = 0;
1036 info->bmiHeader.biClrImportant = 0;
1038 if (!(mask_bits = HeapAlloc( GetProcessHeap(), 0, info->bmiHeader.biSizeImage ))) goto done;
1039 if (!GetDIBits( hdc, icon->hbmMask, 0, height, mask_bits, info, DIB_RGB_COLORS )) goto done;
1041 info->bmiHeader.biBitCount = 32;
1042 info->bmiHeader.biSizeImage = width * height * 4;
1043 if (!(color_bits = HeapAlloc( GetProcessHeap(), 0, info->bmiHeader.biSizeImage ))) goto done;
1044 if (!(xor_bits = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, width_bytes * height ))) goto done;
1045 GetDIBits( hdc, icon->hbmColor, 0, height, color_bits, info, DIB_RGB_COLORS );
1047 /* compute fg/bg color and xor bitmap based on average of the color values */
1049 if (!(xor_bitmap = CreateBitmap( width, height, 1, 1, NULL ))) goto done;
1050 rfg = gfg = bfg = rbg = gbg = bbg = fgBits = 0;
1051 for (y = 0, ptr = color_bits; y < height; y++)
1053 for (x = 0; x < width; x++, ptr++)
1055 int red = (*ptr >> 16) & 0xff;
1056 int green = (*ptr >> 8) & 0xff;
1057 int blue = (*ptr >> 0) & 0xff;
1058 if (red + green + blue > 0x40)
1064 xor_bits[y * width_bytes + x / 8] |= 0x80 >> (x % 8);
1076 fg.red = rfg * 257 / fgBits;
1077 fg.green = gfg * 257 / fgBits;
1078 fg.blue = bfg * 257 / fgBits;
1080 else fg.red = fg.green = fg.blue = 0;
1081 bgBits = width * height - fgBits;
1084 bg.red = rbg * 257 / bgBits;
1085 bg.green = gbg * 257 / bgBits;
1086 bg.blue = bbg * 257 / bgBits;
1088 else bg.red = bg.green = bg.blue = 0;
1090 info->bmiHeader.biBitCount = 1;
1091 info->bmiHeader.biSizeImage = width_bytes * height;
1092 SetDIBits( hdc, xor_bitmap, 0, height, xor_bits, info, DIB_RGB_COLORS );
1094 /* generate mask from the alpha channel if we have one */
1096 for (i = 0, ptr = color_bits; i < width * height; i++, ptr++)
1097 if ((has_alpha = (*ptr & 0xff000000) != 0)) break;
1101 /* make sure the bitmaps are owned by x11drv */
1102 HBITMAP orig = SelectObject( hdc, icon->hbmMask );
1103 SelectObject( hdc, xor_bitmap );
1104 SelectObject( hdc, orig );
1106 memset( mask_bits, 0, width_bytes * height );
1107 for (y = 0, ptr = color_bits; y < height; y++)
1108 for (x = 0; x < width; x++, ptr++)
1109 if ((*ptr >> 24) > 25) /* more than 10% alpha */
1110 mask_bits[y * width_bytes + x / 8] |= 0x80 >> (x % 8);
1112 info->bmiHeader.biBitCount = 1;
1113 info->bmiHeader.biSizeImage = width_bytes * height;
1114 SetDIBits( hdc, icon->hbmMask, 0, height, mask_bits, info, DIB_RGB_COLORS );
1117 cursor = XCreatePixmapCursor( gdi_display,
1118 X11DRV_get_pixmap(xor_bitmap),
1119 X11DRV_get_pixmap(icon->hbmMask),
1120 &fg, &bg, icon->xHotspot, icon->yHotspot );
1121 wine_tsx11_unlock();
1125 cursor = create_cursor_from_bitmaps( xor_bitmap, icon->hbmMask, width, height, 0, 0,
1126 &fg, &bg, icon->xHotspot, icon->yHotspot );
1130 DeleteObject( xor_bitmap );
1131 HeapFree( GetProcessHeap(), 0, info );
1132 HeapFree( GetProcessHeap(), 0, color_bits );
1133 HeapFree( GetProcessHeap(), 0, xor_bits );
1134 HeapFree( GetProcessHeap(), 0, mask_bits );
1138 /***********************************************************************
1141 * Create an X cursor from a Windows one.
1143 static Cursor create_cursor( HANDLE handle )
1149 if (!handle) return get_empty_cursor();
1151 info.cbSize = sizeof(info);
1152 if (!GetIconInfoExW( handle, &info )) return 0;
1154 #ifdef SONAME_LIBXCURSOR
1155 if (use_system_cursors && (cursor = create_xcursor_system_cursor( &info )))
1157 DeleteObject( info.hbmColor );
1158 DeleteObject( info.hbmMask );
1163 GetObjectW( info.hbmMask, sizeof(bm), &bm );
1164 if (!info.hbmColor) bm.bmHeight = max( 1, bm.bmHeight / 2 );
1166 /* make sure hotspot is valid */
1167 if (info.xHotspot >= bm.bmWidth || info.yHotspot >= bm.bmHeight)
1169 info.xHotspot = bm.bmWidth / 2;
1170 info.yHotspot = bm.bmHeight / 2;
1175 HDC hdc = CreateCompatibleDC( 0 );
1178 #ifdef SONAME_LIBXCURSOR
1179 if (pXcursorImagesLoadCursor)
1180 cursor = create_xcursor_cursor( hdc, &info, handle, bm.bmWidth, bm.bmHeight );
1182 if (!cursor) cursor = create_xlib_cursor( hdc, &info, bm.bmWidth, bm.bmHeight );
1184 DeleteObject( info.hbmColor );
1190 fg.red = fg.green = fg.blue = 0xffff;
1191 bg.red = bg.green = bg.blue = 0;
1192 cursor = create_cursor_from_bitmaps( info.hbmMask, info.hbmMask, bm.bmWidth, bm.bmHeight,
1193 bm.bmHeight, 0, &fg, &bg, info.xHotspot, info.yHotspot );
1196 DeleteObject( info.hbmMask );
1200 /***********************************************************************
1201 * DestroyCursorIcon (X11DRV.@)
1203 void CDECL X11DRV_DestroyCursorIcon( HCURSOR handle )
1208 if (cursor_context && !XFindContext( gdi_display, (XID)handle, cursor_context, (char **)&cursor ))
1210 TRACE( "%p xid %lx\n", handle, cursor );
1211 XFreeCursor( gdi_display, cursor );
1212 XDeleteContext( gdi_display, (XID)handle, cursor_context );
1214 wine_tsx11_unlock();
1217 /***********************************************************************
1218 * SetCursor (X11DRV.@)
1220 void CDECL X11DRV_SetCursor( HCURSOR handle )
1222 if (InterlockedExchangePointer( (void **)&last_cursor, handle ) != handle ||
1223 GetTickCount() - last_cursor_change > 100)
1225 last_cursor_change = GetTickCount();
1226 if (cursor_window) SendNotifyMessageW( cursor_window, WM_X11DRV_SET_CURSOR, 0, (LPARAM)handle );
1230 /***********************************************************************
1231 * SetCursorPos (X11DRV.@)
1233 BOOL CDECL X11DRV_SetCursorPos( INT x, INT y )
1235 struct x11drv_thread_data *data = x11drv_init_thread_data();
1238 XWarpPointer( data->display, root_window, root_window, 0, 0, 0, 0,
1239 x - virtual_screen_rect.left, y - virtual_screen_rect.top );
1240 data->warp_serial = NextRequest( data->display );
1241 XNoOp( data->display );
1242 XFlush( data->display ); /* avoids bad mouse lag in games that do their own mouse warping */
1243 wine_tsx11_unlock();
1244 TRACE( "warped to %d,%d serial %lu\n", x, y, data->warp_serial );
1248 /***********************************************************************
1249 * GetCursorPos (X11DRV.@)
1251 BOOL CDECL X11DRV_GetCursorPos(LPPOINT pos)
1253 Display *display = thread_init_display();
1255 int rootX, rootY, winX, winY;
1256 unsigned int xstate;
1260 ret = XQueryPointer( display, root_window, &root, &child, &rootX, &rootY, &winX, &winY, &xstate );
1264 pos->x = winX + virtual_screen_rect.left;
1265 pos->y = winY + virtual_screen_rect.top;
1266 TRACE( "pointer at (%d,%d) server pos %d,%d\n", pos->x, pos->y, old.x, old.y );
1268 wine_tsx11_unlock();
1272 /***********************************************************************
1273 * ClipCursor (X11DRV.@)
1275 BOOL CDECL X11DRV_ClipCursor( LPCRECT clip )
1279 ungrab_clipping_window();
1283 if (GetWindowThreadProcessId( GetDesktopWindow(), NULL ) == GetCurrentThreadId())
1284 return TRUE; /* don't clip in the desktop process */
1288 HWND foreground = GetForegroundWindow();
1290 /* we are clipping if the clip rectangle is smaller than the screen */
1291 if (clip->left > virtual_screen_rect.left || clip->right < virtual_screen_rect.right ||
1292 clip->top > virtual_screen_rect.top || clip->bottom < virtual_screen_rect.bottom)
1296 /* forward request to the foreground window if it's in a different thread */
1297 tid = GetWindowThreadProcessId( foreground, &pid );
1298 if (tid && tid != GetCurrentThreadId() && pid == GetCurrentProcessId())
1300 TRACE( "forwarding clip request to %p\n", foreground );
1301 SendNotifyMessageW( foreground, WM_X11DRV_CLIP_CURSOR, 0, 0 );
1304 else if (grab_clipping_window( clip, FALSE )) return TRUE;
1306 else /* if currently clipping, check if we should switch to fullscreen clipping */
1308 struct x11drv_thread_data *data = x11drv_thread_data();
1309 if (data && data->clip_hwnd)
1311 if (EqualRect( clip, &clip_rect ) || clip_fullscreen_window( foreground, TRUE ))
1316 ungrab_clipping_window();
1320 /***********************************************************************
1321 * X11DRV_ButtonPress
1323 void X11DRV_ButtonPress( HWND hwnd, XEvent *xev )
1325 XButtonEvent *event = &xev->xbutton;
1326 int buttonNum = event->button - 1;
1329 if (buttonNum >= NB_BUTTONS) return;
1331 TRACE( "hwnd %p/%lx button %u pos %d,%d\n", hwnd, event->window, buttonNum, event->x, event->y );
1333 input.u.mi.dx = event->x;
1334 input.u.mi.dy = event->y;
1335 input.u.mi.mouseData = button_down_data[buttonNum];
1336 input.u.mi.dwFlags = button_down_flags[buttonNum] | MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE;
1337 input.u.mi.time = EVENT_x11_time_to_win32_time( event->time );
1338 input.u.mi.dwExtraInfo = 0;
1340 update_user_time( event->time );
1341 send_mouse_input( hwnd, event->window, event->state, &input );
1345 /***********************************************************************
1346 * X11DRV_ButtonRelease
1348 void X11DRV_ButtonRelease( HWND hwnd, XEvent *xev )
1350 XButtonEvent *event = &xev->xbutton;
1351 int buttonNum = event->button - 1;
1354 if (buttonNum >= NB_BUTTONS || !button_up_flags[buttonNum]) return;
1356 TRACE( "hwnd %p/%lx button %u pos %d,%d\n", hwnd, event->window, buttonNum, event->x, event->y );
1358 input.u.mi.dx = event->x;
1359 input.u.mi.dy = event->y;
1360 input.u.mi.mouseData = button_up_data[buttonNum];
1361 input.u.mi.dwFlags = button_up_flags[buttonNum] | MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE;
1362 input.u.mi.time = EVENT_x11_time_to_win32_time( event->time );
1363 input.u.mi.dwExtraInfo = 0;
1365 send_mouse_input( hwnd, event->window, event->state, &input );
1369 /***********************************************************************
1370 * X11DRV_MotionNotify
1372 void X11DRV_MotionNotify( HWND hwnd, XEvent *xev )
1374 XMotionEvent *event = &xev->xmotion;
1377 TRACE( "hwnd %p/%lx pos %d,%d is_hint %d serial %lu\n",
1378 hwnd, event->window, event->x, event->y, event->is_hint, event->serial );
1380 input.u.mi.dx = event->x;
1381 input.u.mi.dy = event->y;
1382 input.u.mi.mouseData = 0;
1383 input.u.mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE;
1384 input.u.mi.time = EVENT_x11_time_to_win32_time( event->time );
1385 input.u.mi.dwExtraInfo = 0;
1389 struct x11drv_thread_data *thread_data = x11drv_thread_data();
1390 if (thread_data->warp_serial && (long)(event->serial - thread_data->warp_serial) < 0) return;
1393 send_mouse_input( hwnd, event->window, event->state, &input );
1397 /***********************************************************************
1398 * X11DRV_EnterNotify
1400 void X11DRV_EnterNotify( HWND hwnd, XEvent *xev )
1402 XCrossingEvent *event = &xev->xcrossing;
1405 TRACE( "hwnd %p/%lx pos %d,%d detail %d\n", hwnd, event->window, event->x, event->y, event->detail );
1407 if (event->detail == NotifyVirtual || event->detail == NotifyNonlinearVirtual) return;
1408 if (event->window == x11drv_thread_data()->grab_window) return;
1410 /* simulate a mouse motion event */
1411 input.u.mi.dx = event->x;
1412 input.u.mi.dy = event->y;
1413 input.u.mi.mouseData = 0;
1414 input.u.mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE;
1415 input.u.mi.time = EVENT_x11_time_to_win32_time( event->time );
1416 input.u.mi.dwExtraInfo = 0;
1418 send_mouse_input( hwnd, event->window, event->state, &input );
1421 #ifdef HAVE_X11_EXTENSIONS_XINPUT2_H
1423 /***********************************************************************
1426 static void X11DRV_RawMotion( XGenericEventCookie *xev )
1428 XIRawEvent *event = xev->data;
1429 const double *values = event->valuators.values;
1431 struct x11drv_thread_data *thread_data = x11drv_thread_data();
1433 if (!event->valuators.mask_len) return;
1434 if (thread_data->xi2_state != xi_enabled) return;
1438 input.u.mi.mouseData = 0;
1439 input.u.mi.dwFlags = MOUSEEVENTF_MOVE;
1440 input.u.mi.time = EVENT_x11_time_to_win32_time( event->time );
1441 input.u.mi.dwExtraInfo = 0;
1443 if (XIMaskIsSet( event->valuators.mask, 0 )) input.u.mi.dx = *values++;
1444 if (XIMaskIsSet( event->valuators.mask, 1 )) input.u.mi.dy = *values++;
1446 if (thread_data->warp_serial)
1448 if ((long)(xev->serial - thread_data->warp_serial) < 0)
1450 TRACE( "pos %d,%d old serial %lu, ignoring\n", input.u.mi.dx, input.u.mi.dy, xev->serial );
1453 thread_data->warp_serial = 0; /* we caught up now */
1456 TRACE( "pos %d,%d\n", input.u.mi.dx, input.u.mi.dy );
1458 input.type = INPUT_MOUSE;
1459 __wine_send_input( 0, &input );
1462 #endif /* HAVE_X11_EXTENSIONS_XINPUT2_H */
1465 /***********************************************************************
1466 * X11DRV_XInput2_Init
1468 void X11DRV_XInput2_Init(void)
1470 #if defined(SONAME_LIBXI) && defined(HAVE_X11_EXTENSIONS_XINPUT2_H)
1472 void *libxi_handle = wine_dlopen( SONAME_LIBXI, RTLD_NOW, NULL, 0 );
1476 WARN( "couldn't load %s\n", SONAME_LIBXI );
1479 #define LOAD_FUNCPTR(f) \
1480 if (!(p##f = wine_dlsym( libxi_handle, #f, NULL, 0))) \
1482 WARN("Failed to load %s.\n", #f); \
1486 LOAD_FUNCPTR(XIFreeDeviceInfo);
1487 LOAD_FUNCPTR(XIQueryDevice);
1488 LOAD_FUNCPTR(XIQueryVersion);
1489 LOAD_FUNCPTR(XISelectEvents);
1493 xinput2_available = XQueryExtension( gdi_display, "XInputExtension", &xinput2_opcode, &event, &error );
1494 wine_tsx11_unlock();
1496 TRACE( "X Input 2 support not compiled in.\n" );
1501 /***********************************************************************
1502 * X11DRV_GenericEvent
1504 void X11DRV_GenericEvent( HWND hwnd, XEvent *xev )
1506 #ifdef HAVE_X11_EXTENSIONS_XINPUT2_H
1507 XGenericEventCookie *event = &xev->xcookie;
1509 if (!event->data) return;
1510 if (event->extension != xinput2_opcode) return;
1512 switch (event->evtype)
1515 X11DRV_RawMotion( event );
1519 TRACE( "Unhandled event %#x\n", event->evtype );