mirrored from git://source.winehq.org/git/wine.git
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
mouse.c
1930 lines (1682 loc) · 63.1 KB
/
mouse.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* X11 mouse driver
*
* Copyright 1998 Ulrich Weigand
* Copyright 2007 Henri Verbeet
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "config.h"
#include "wine/port.h"
#include <X11/Xlib.h>
#include <X11/cursorfont.h>
#include <stdarg.h>
#ifdef HAVE_X11_EXTENSIONS_XINPUT2_H
#include <X11/extensions/XInput2.h>
#endif
#ifdef SONAME_LIBXCURSOR
# include <X11/Xcursor/Xcursor.h>
static void *xcursor_handle;
# define MAKE_FUNCPTR(f) static typeof(f) * p##f
MAKE_FUNCPTR(XcursorImageCreate);
MAKE_FUNCPTR(XcursorImageDestroy);
MAKE_FUNCPTR(XcursorImageLoadCursor);
MAKE_FUNCPTR(XcursorImagesCreate);
MAKE_FUNCPTR(XcursorImagesDestroy);
MAKE_FUNCPTR(XcursorImagesLoadCursor);
MAKE_FUNCPTR(XcursorLibraryLoadCursor);
# undef MAKE_FUNCPTR
#endif /* SONAME_LIBXCURSOR */
#define NONAMELESSUNION
#define OEMRESOURCE
#include "windef.h"
#include "winbase.h"
#include "winreg.h"
#include "x11drv.h"
#include "wine/server.h"
#include "wine/unicode.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(cursor);
/**********************************************************************/
#ifndef Button6Mask
#define Button6Mask (1<<13)
#endif
#ifndef Button7Mask
#define Button7Mask (1<<14)
#endif
#define NB_BUTTONS 9 /* Windows can handle 5 buttons and the wheel too */
static const UINT button_down_flags[NB_BUTTONS] =
{
MOUSEEVENTF_LEFTDOWN,
MOUSEEVENTF_MIDDLEDOWN,
MOUSEEVENTF_RIGHTDOWN,
MOUSEEVENTF_WHEEL,
MOUSEEVENTF_WHEEL,
MOUSEEVENTF_HWHEEL,
MOUSEEVENTF_HWHEEL,
MOUSEEVENTF_XDOWN,
MOUSEEVENTF_XDOWN
};
static const UINT button_up_flags[NB_BUTTONS] =
{
MOUSEEVENTF_LEFTUP,
MOUSEEVENTF_MIDDLEUP,
MOUSEEVENTF_RIGHTUP,
0,
0,
0,
0,
MOUSEEVENTF_XUP,
MOUSEEVENTF_XUP
};
static const UINT button_down_data[NB_BUTTONS] =
{
0,
0,
0,
WHEEL_DELTA,
-WHEEL_DELTA,
-WHEEL_DELTA,
WHEEL_DELTA,
XBUTTON1,
XBUTTON2
};
static const UINT button_up_data[NB_BUTTONS] =
{
0,
0,
0,
0,
0,
0,
0,
XBUTTON1,
XBUTTON2
};
XContext cursor_context = 0;
static HWND cursor_window;
static HCURSOR last_cursor;
static DWORD last_cursor_change;
static RECT last_clip_rect;
static HWND last_clip_foreground_window;
static BOOL last_clip_refused;
static RECT clip_rect;
static Cursor create_cursor( HANDLE handle );
#ifdef HAVE_X11_EXTENSIONS_XINPUT2_H
static BOOL xinput2_available;
static BOOL broken_rawevents;
#define MAKE_FUNCPTR(f) static typeof(f) * p##f
MAKE_FUNCPTR(XIGetClientPointer);
MAKE_FUNCPTR(XIFreeDeviceInfo);
MAKE_FUNCPTR(XIQueryDevice);
MAKE_FUNCPTR(XIQueryVersion);
MAKE_FUNCPTR(XISelectEvents);
#undef MAKE_FUNCPTR
#endif
/***********************************************************************
* X11DRV_Xcursor_Init
*
* Load the Xcursor library for use.
*/
void X11DRV_Xcursor_Init(void)
{
#ifdef SONAME_LIBXCURSOR
xcursor_handle = dlopen(SONAME_LIBXCURSOR, RTLD_NOW);
if (!xcursor_handle)
{
WARN("Xcursor failed to load. Using fallback code.\n");
return;
}
#define LOAD_FUNCPTR(f) p##f = dlsym(xcursor_handle, #f)
LOAD_FUNCPTR(XcursorImageCreate);
LOAD_FUNCPTR(XcursorImageDestroy);
LOAD_FUNCPTR(XcursorImageLoadCursor);
LOAD_FUNCPTR(XcursorImagesCreate);
LOAD_FUNCPTR(XcursorImagesDestroy);
LOAD_FUNCPTR(XcursorImagesLoadCursor);
LOAD_FUNCPTR(XcursorLibraryLoadCursor);
#undef LOAD_FUNCPTR
#endif /* SONAME_LIBXCURSOR */
}
/***********************************************************************
* get_empty_cursor
*/
static Cursor get_empty_cursor(void)
{
static Cursor cursor;
static const char data[] = { 0 };
if (!cursor)
{
XColor bg;
Pixmap pixmap;
bg.red = bg.green = bg.blue = 0x0000;
pixmap = XCreateBitmapFromData( gdi_display, root_window, data, 1, 1 );
if (pixmap)
{
Cursor new = XCreatePixmapCursor( gdi_display, pixmap, pixmap, &bg, &bg, 0, 0 );
if (InterlockedCompareExchangePointer( (void **)&cursor, (void *)new, 0 ))
XFreeCursor( gdi_display, new );
XFreePixmap( gdi_display, pixmap );
}
}
return cursor;
}
/***********************************************************************
* set_window_cursor
*/
void set_window_cursor( Window window, HCURSOR handle )
{
Cursor cursor, prev;
if (!handle) cursor = get_empty_cursor();
else if (XFindContext( gdi_display, (XID)handle, cursor_context, (char **)&cursor ))
{
/* try to create it */
if (!(cursor = create_cursor( handle ))) return;
XLockDisplay( gdi_display );
if (!XFindContext( gdi_display, (XID)handle, cursor_context, (char **)&prev ))
{
/* someone else was here first */
XFreeCursor( gdi_display, cursor );
cursor = prev;
}
else
{
XSaveContext( gdi_display, (XID)handle, cursor_context, (char *)cursor );
TRACE( "cursor %p created %lx\n", handle, cursor );
}
XUnlockDisplay( gdi_display );
}
XDefineCursor( gdi_display, window, cursor );
/* make the change take effect immediately */
XFlush( gdi_display );
}
/***********************************************************************
* sync_window_cursor
*/
void sync_window_cursor( Window window )
{
HCURSOR cursor;
SERVER_START_REQ( set_cursor )
{
req->flags = 0;
wine_server_call( req );
cursor = reply->prev_count >= 0 ? wine_server_ptr_handle( reply->prev_handle ) : 0;
}
SERVER_END_REQ;
set_window_cursor( window, cursor );
}
#ifdef HAVE_X11_EXTENSIONS_XINPUT2_H
/***********************************************************************
* update_relative_valuators
*/
static void update_relative_valuators(XIAnyClassInfo **valuators, int n_valuators)
{
struct x11drv_thread_data *thread_data = x11drv_thread_data();
int i;
thread_data->x_rel_valuator.number = -1;
thread_data->y_rel_valuator.number = -1;
for (i = 0; i < n_valuators; i++)
{
XIValuatorClassInfo *class = (XIValuatorClassInfo *)valuators[i];
struct x11drv_valuator_data *valuator_data = NULL;
if (valuators[i]->type != XIValuatorClass) continue;
if (class->label == x11drv_atom( Rel_X ) ||
(!class->label && class->number == 0 && class->mode == XIModeRelative))
{
valuator_data = &thread_data->x_rel_valuator;
}
else if (class->label == x11drv_atom( Rel_Y ) ||
(!class->label && class->number == 1 && class->mode == XIModeRelative))
{
valuator_data = &thread_data->y_rel_valuator;
}
if (valuator_data) {
valuator_data->number = class->number;
valuator_data->min = class->min;
valuator_data->max = class->max;
}
}
}
#endif
/***********************************************************************
* enable_xinput2
*/
static void enable_xinput2(void)
{
#ifdef HAVE_X11_EXTENSIONS_XINPUT2_H
struct x11drv_thread_data *data = x11drv_thread_data();
XIEventMask mask;
XIDeviceInfo *pointer_info;
unsigned char mask_bits[XIMaskLen(XI_LASTEVENT)];
int count;
if (!xinput2_available) return;
if (data->xi2_state == xi_unknown)
{
int major = 2, minor = 0;
if (!pXIQueryVersion( data->display, &major, &minor )) data->xi2_state = xi_disabled;
else
{
data->xi2_state = xi_unavailable;
WARN( "X Input 2 not available\n" );
}
}
if (data->xi2_state == xi_unavailable) return;
if (!pXIGetClientPointer( data->display, None, &data->xi2_core_pointer )) return;
mask.mask = mask_bits;
mask.mask_len = sizeof(mask_bits);
mask.deviceid = XIAllDevices;
memset( mask_bits, 0, sizeof(mask_bits) );
XISetMask( mask_bits, XI_DeviceChanged );
XISetMask( mask_bits, XI_RawMotion );
XISetMask( mask_bits, XI_ButtonPress );
pXISelectEvents( data->display, DefaultRootWindow( data->display ), &mask, 1 );
pointer_info = pXIQueryDevice( data->display, data->xi2_core_pointer, &count );
update_relative_valuators( pointer_info->classes, pointer_info->num_classes );
pXIFreeDeviceInfo( pointer_info );
/* This device info list is only used to find the initial current slave if
* no XI_DeviceChanged events happened. If any hierarchy change occurred that
* might be relevant here (eg. user switching mice after (un)plugging), a
* XI_DeviceChanged event will point us to the right slave. So this list is
* safe to be obtained statically at enable_xinput2() time.
*/
if (data->xi2_devices) pXIFreeDeviceInfo( data->xi2_devices );
data->xi2_devices = pXIQueryDevice( data->display, XIAllDevices, &data->xi2_device_count );
data->xi2_current_slave = 0;
data->xi2_state = xi_enabled;
#endif
}
/***********************************************************************
* disable_xinput2
*/
static void disable_xinput2(void)
{
#ifdef HAVE_X11_EXTENSIONS_XINPUT2_H
struct x11drv_thread_data *data = x11drv_thread_data();
XIEventMask mask;
if (data->xi2_state != xi_enabled) return;
TRACE( "disabling\n" );
data->xi2_state = xi_disabled;
mask.mask = NULL;
mask.mask_len = 0;
mask.deviceid = XIAllDevices;
pXISelectEvents( data->display, DefaultRootWindow( data->display ), &mask, 1 );
pXIFreeDeviceInfo( data->xi2_devices );
data->x_rel_valuator.number = -1;
data->y_rel_valuator.number = -1;
data->xi2_devices = NULL;
data->xi2_core_pointer = 0;
data->xi2_current_slave = 0;
#endif
}
/***********************************************************************
* grab_clipping_window
*
* Start a pointer grab on the clip window.
*/
static BOOL grab_clipping_window( const RECT *clip )
{
static const WCHAR messageW[] = {'M','e','s','s','a','g','e',0};
struct x11drv_thread_data *data = x11drv_thread_data();
Window clip_window;
HWND msg_hwnd = 0;
POINT pos;
if (GetWindowThreadProcessId( GetDesktopWindow(), NULL ) == GetCurrentThreadId())
return TRUE; /* don't clip in the desktop process */
if (!data) return FALSE;
if (!(clip_window = init_clip_window())) return TRUE;
if (!(msg_hwnd = CreateWindowW( messageW, NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, 0,
GetModuleHandleW(0), NULL )))
return TRUE;
if (keyboard_grabbed)
{
WARN( "refusing to clip to %s\n", wine_dbgstr_rect(clip) );
last_clip_refused = TRUE;
last_clip_foreground_window = GetForegroundWindow();
last_clip_rect = *clip;
return FALSE;
}
else
{
last_clip_refused = FALSE;
}
/* enable XInput2 unless we are already clipping */
if (!data->clip_hwnd) enable_xinput2();
if (data->xi2_state != xi_enabled)
{
WARN( "XInput2 not supported, refusing to clip to %s\n", wine_dbgstr_rect(clip) );
DestroyWindow( msg_hwnd );
ClipCursor( NULL );
return TRUE;
}
TRACE( "clipping to %s win %lx\n", wine_dbgstr_rect(clip), clip_window );
if (!data->clip_hwnd) XUnmapWindow( data->display, clip_window );
pos = virtual_screen_to_root( clip->left, clip->top );
XMoveResizeWindow( data->display, clip_window, pos.x, pos.y,
max( 1, clip->right - clip->left ), max( 1, clip->bottom - clip->top ) );
XMapWindow( data->display, clip_window );
/* if the rectangle is shrinking we may get a pointer warp */
if (!data->clip_hwnd || clip->left > clip_rect.left || clip->top > clip_rect.top ||
clip->right < clip_rect.right || clip->bottom < clip_rect.bottom)
data->warp_serial = NextRequest( data->display );
if (!XGrabPointer( data->display, clip_window, False,
PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
GrabModeAsync, GrabModeAsync, clip_window, None, CurrentTime ))
clipping_cursor = TRUE;
if (!clipping_cursor)
{
disable_xinput2();
DestroyWindow( msg_hwnd );
return FALSE;
}
clip_rect = *clip;
if (!data->clip_hwnd) sync_window_cursor( clip_window );
InterlockedExchangePointer( (void **)&cursor_window, msg_hwnd );
data->clip_hwnd = msg_hwnd;
SendMessageW( GetDesktopWindow(), WM_X11DRV_CLIP_CURSOR, 0, (LPARAM)msg_hwnd );
return TRUE;
}
/***********************************************************************
* ungrab_clipping_window
*
* Release the pointer grab on the clip window.
*/
void ungrab_clipping_window(void)
{
Display *display = thread_init_display();
Window clip_window = init_clip_window();
if (!clip_window) return;
TRACE( "no longer clipping\n" );
XUnmapWindow( display, clip_window );
if (clipping_cursor) XUngrabPointer( display, CurrentTime );
clipping_cursor = FALSE;
SendMessageW( GetDesktopWindow(), WM_X11DRV_CLIP_CURSOR, 0, 0 );
}
/***********************************************************************
* reset_clipping_window
*
* Forcibly reset the window clipping on external events.
*/
void reset_clipping_window(void)
{
ungrab_clipping_window();
ClipCursor( NULL ); /* make sure the clip rectangle is reset too */
}
/***********************************************************************
* retry_grab_clipping_window
*
* Restore the current clip rectangle or retry the last one if it has
* been refused because of an active keyboard grab.
*/
void retry_grab_clipping_window(void)
{
if (clipping_cursor)
ClipCursor( &clip_rect );
else if (last_clip_refused && GetForegroundWindow() == last_clip_foreground_window)
ClipCursor( &last_clip_rect );
}
BOOL CDECL X11DRV_ClipCursor( const RECT *clip );
/***********************************************************************
* clip_cursor_notify
*
* Notification function called upon receiving a WM_X11DRV_CLIP_CURSOR.
*/
LRESULT clip_cursor_notify( HWND hwnd, HWND prev_clip_hwnd, HWND new_clip_hwnd )
{
struct x11drv_thread_data *data = x11drv_init_thread_data();
if (hwnd == GetDesktopWindow()) /* change the clip window stored in the desktop process */
{
static HWND clip_hwnd;
HWND prev = clip_hwnd;
clip_hwnd = new_clip_hwnd;
if (prev || new_clip_hwnd) TRACE( "clip hwnd changed from %p to %p\n", prev, new_clip_hwnd );
if (prev) SendNotifyMessageW( prev, WM_X11DRV_CLIP_CURSOR, (WPARAM)prev, 0 );
}
else if (hwnd == data->clip_hwnd) /* this is a notification that clipping has been reset */
{
TRACE( "clip hwnd reset from %p\n", hwnd );
data->clip_hwnd = 0;
data->clip_reset = GetTickCount();
disable_xinput2();
DestroyWindow( hwnd );
}
else if (hwnd == GetForegroundWindow()) /* request to clip */
{
RECT clip;
GetClipCursor( &clip );
X11DRV_ClipCursor( &clip );
}
else if (prev_clip_hwnd)
{
/* This is a notification send by the desktop window to an old
* dangling clip window.
*/
TRACE( "destroying old clip hwnd %p\n", prev_clip_hwnd );
DestroyWindow( prev_clip_hwnd );
}
return 0;
}
/***********************************************************************
* clip_fullscreen_window
*
* Turn on clipping if the active window is fullscreen.
*/
BOOL clip_fullscreen_window( HWND hwnd, BOOL reset )
{
struct x11drv_win_data *data;
struct x11drv_thread_data *thread_data;
RECT rect;
DWORD style;
BOOL fullscreen;
if (hwnd == GetDesktopWindow()) return FALSE;
style = GetWindowLongW( hwnd, GWL_STYLE );
if (!(style & WS_VISIBLE)) return FALSE;
if ((style & (WS_POPUP | WS_CHILD)) == WS_CHILD) return FALSE;
/* maximized windows don't count as full screen */
if ((style & WS_MAXIMIZE) && (style & WS_CAPTION) == WS_CAPTION) return FALSE;
if (!(data = get_win_data( hwnd ))) return FALSE;
fullscreen = is_window_rect_fullscreen( &data->whole_rect );
release_win_data( data );
if (!fullscreen) return FALSE;
if (!(thread_data = x11drv_thread_data())) return FALSE;
if (GetTickCount() - thread_data->clip_reset < 1000) return FALSE;
if (!reset && clipping_cursor && thread_data->clip_hwnd) return FALSE; /* already clipping */
rect = get_primary_monitor_rect();
if (!grab_fullscreen)
{
RECT virtual_rect = get_virtual_screen_rect();
if (!EqualRect( &rect, &virtual_rect )) return FALSE;
if (is_virtual_desktop()) return FALSE;
}
TRACE( "win %p clipping fullscreen\n", hwnd );
return grab_clipping_window( &rect );
}
/***********************************************************************
* is_old_motion_event
*/
static BOOL is_old_motion_event( unsigned long serial )
{
struct x11drv_thread_data *thread_data = x11drv_thread_data();
if (!thread_data->warp_serial) return FALSE;
if ((long)(serial - thread_data->warp_serial) < 0) return TRUE;
thread_data->warp_serial = 0; /* we caught up now */
return FALSE;
}
/***********************************************************************
* send_mouse_input
*
* Update the various window states on a mouse event.
*/
static void send_mouse_input( HWND hwnd, Window window, unsigned int state, INPUT *input )
{
struct x11drv_win_data *data;
POINT pt;
input->type = INPUT_MOUSE;
if (!hwnd)
{
struct x11drv_thread_data *thread_data = x11drv_thread_data();
HWND clip_hwnd = thread_data->clip_hwnd;
if (!clip_hwnd) return;
if (thread_data->clip_window != window) return;
if (InterlockedExchangePointer( (void **)&cursor_window, clip_hwnd ) != clip_hwnd ||
input->u.mi.time - last_cursor_change > 100)
{
sync_window_cursor( window );
last_cursor_change = input->u.mi.time;
}
input->u.mi.dx += clip_rect.left;
input->u.mi.dy += clip_rect.top;
__wine_send_input( hwnd, input );
return;
}
if (window != root_window)
{
pt.x = input->u.mi.dx;
pt.y = input->u.mi.dy;
}
else pt = root_to_virtual_screen( input->u.mi.dx, input->u.mi.dy );
if (!(data = get_win_data( hwnd ))) return;
if (window == data->whole_window)
{
pt.x += data->whole_rect.left - data->client_rect.left;
pt.y += data->whole_rect.top - data->client_rect.top;
}
if (GetWindowLongW( data->hwnd, GWL_EXSTYLE ) & WS_EX_LAYOUTRTL)
pt.x = data->client_rect.right - data->client_rect.left - 1 - pt.x;
MapWindowPoints( hwnd, 0, &pt, 1 );
if (InterlockedExchangePointer( (void **)&cursor_window, hwnd ) != hwnd ||
input->u.mi.time - last_cursor_change > 100)
{
sync_window_cursor( data->whole_window );
last_cursor_change = input->u.mi.time;
}
release_win_data( data );
if (hwnd != GetDesktopWindow())
{
hwnd = GetAncestor( hwnd, GA_ROOT );
if ((input->u.mi.dwFlags & (MOUSEEVENTF_LEFTDOWN|MOUSEEVENTF_RIGHTDOWN)) && hwnd == GetForegroundWindow())
clip_fullscreen_window( hwnd, FALSE );
}
/* update the wine server Z-order */
if (hwnd != x11drv_thread_data()->grab_hwnd &&
/* ignore event if a button is pressed, since the mouse is then grabbed too */
!(state & (Button1Mask|Button2Mask|Button3Mask|Button4Mask|Button5Mask|Button6Mask|Button7Mask)))
{
RECT rect;
SetRect( &rect, pt.x, pt.y, pt.x + 1, pt.y + 1 );
SERVER_START_REQ( update_window_zorder )
{
req->window = wine_server_user_handle( hwnd );
req->rect.left = rect.left;
req->rect.top = rect.top;
req->rect.right = rect.right;
req->rect.bottom = rect.bottom;
wine_server_call( req );
}
SERVER_END_REQ;
}
input->u.mi.dx = pt.x;
input->u.mi.dy = pt.y;
__wine_send_input( hwnd, input );
}
#ifdef SONAME_LIBXCURSOR
/***********************************************************************
* create_xcursor_frame
*
* Use Xcursor to create a frame of an X cursor from a Windows one.
*/
static XcursorImage *create_xcursor_frame( HDC hdc, const ICONINFOEXW *iinfo, HANDLE icon,
HBITMAP hbmColor, unsigned char *color_bits, int color_size,
HBITMAP hbmMask, unsigned char *mask_bits, int mask_size,
int width, int height, int istep )
{
XcursorImage *image, *ret = NULL;
DWORD delay_jiffies, num_steps;
int x, y, i;
BOOL has_alpha = FALSE;
XcursorPixel *ptr;
image = pXcursorImageCreate( width, height );
if (!image)
{
ERR("X11 failed to produce a cursor frame!\n");
return NULL;
}
image->xhot = iinfo->xHotspot;
image->yhot = iinfo->yHotspot;
image->delay = 100; /* fallback delay, 100 ms */
if (GetCursorFrameInfo(icon, 0x0 /* unknown parameter */, istep, &delay_jiffies, &num_steps) != 0)
image->delay = (100 * delay_jiffies) / 6; /* convert jiffies (1/60s) to milliseconds */
else
WARN("Failed to retrieve animated cursor frame-rate for frame %d.\n", istep);
/* draw the cursor frame to a temporary buffer then copy it into the XcursorImage */
memset( color_bits, 0x00, color_size );
SelectObject( hdc, hbmColor );
if (!DrawIconEx( hdc, 0, 0, icon, width, height, istep, NULL, DI_NORMAL ))
{
TRACE("Could not draw frame %d (walk past end of frames).\n", istep);
goto cleanup;
}
memcpy( image->pixels, color_bits, color_size );
/* check if the cursor frame was drawn with an alpha channel */
for (i = 0, ptr = image->pixels; i < width * height; i++, ptr++)
if ((has_alpha = (*ptr & 0xff000000) != 0)) break;
/* if no alpha channel was drawn then generate it from the mask */
if (!has_alpha)
{
unsigned int width_bytes = (width + 31) / 32 * 4;
/* draw the cursor mask to a temporary buffer */
memset( mask_bits, 0xFF, mask_size );
SelectObject( hdc, hbmMask );
if (!DrawIconEx( hdc, 0, 0, icon, width, height, istep, NULL, DI_MASK ))
{
ERR("Failed to draw frame mask %d.\n", istep);
goto cleanup;
}
/* use the buffer to directly modify the XcursorImage alpha channel */
for (y = 0, ptr = image->pixels; y < height; y++)
for (x = 0; x < width; x++, ptr++)
if (!((mask_bits[y * width_bytes + x / 8] << (x % 8)) & 0x80))
*ptr |= 0xff000000;
}
ret = image;
cleanup:
if (ret == NULL) pXcursorImageDestroy( image );
return ret;
}
/***********************************************************************
* create_xcursor_cursor
*
* Use Xcursor to create an X cursor from a Windows one.
*/
static Cursor create_xcursor_cursor( HDC hdc, const ICONINFOEXW *iinfo, HANDLE icon, int width, int height )
{
unsigned char *color_bits, *mask_bits;
HBITMAP hbmColor = 0, hbmMask = 0;
DWORD nFrames, delay_jiffies, i;
int color_size, mask_size;
BITMAPINFO *info = NULL;
XcursorImages *images;
XcursorImage **imgs;
Cursor cursor = 0;
/* Retrieve the number of frames to render */
if (!GetCursorFrameInfo(icon, 0x0 /* unknown parameter */, 0, &delay_jiffies, &nFrames)) return 0;
if (!(imgs = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(XcursorImage*)*nFrames ))) return 0;
/* Allocate all of the resources necessary to obtain a cursor frame */
if (!(info = HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO, bmiColors[256] )))) goto cleanup;
info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
info->bmiHeader.biWidth = width;
info->bmiHeader.biHeight = -height;
info->bmiHeader.biPlanes = 1;
info->bmiHeader.biCompression = BI_RGB;
info->bmiHeader.biXPelsPerMeter = 0;
info->bmiHeader.biYPelsPerMeter = 0;
info->bmiHeader.biClrUsed = 0;
info->bmiHeader.biClrImportant = 0;
info->bmiHeader.biBitCount = 32;
color_size = width * height * 4;
info->bmiHeader.biSizeImage = color_size;
hbmColor = CreateDIBSection( hdc, info, DIB_RGB_COLORS, (VOID **) &color_bits, NULL, 0);
if (!hbmColor)
{
ERR("Failed to create DIB section for cursor color data!\n");
goto cleanup;
}
info->bmiHeader.biBitCount = 1;
info->bmiColors[0].rgbRed = 0;
info->bmiColors[0].rgbGreen = 0;
info->bmiColors[0].rgbBlue = 0;
info->bmiColors[0].rgbReserved = 0;
info->bmiColors[1].rgbRed = 0xff;
info->bmiColors[1].rgbGreen = 0xff;
info->bmiColors[1].rgbBlue = 0xff;
info->bmiColors[1].rgbReserved = 0;
mask_size = ((width + 31) / 32 * 4) * height; /* width_bytes * height */
info->bmiHeader.biSizeImage = mask_size;
hbmMask = CreateDIBSection( hdc, info, DIB_RGB_COLORS, (VOID **) &mask_bits, NULL, 0);
if (!hbmMask)
{
ERR("Failed to create DIB section for cursor mask data!\n");
goto cleanup;
}
/* Create an XcursorImage for each frame of the cursor */
for (i=0; i<nFrames; i++)
{
imgs[i] = create_xcursor_frame( hdc, iinfo, icon,
hbmColor, color_bits, color_size,
hbmMask, mask_bits, mask_size,
width, height, i );
if (!imgs[i]) goto cleanup;
}
/* Build an X cursor out of all of the frames */
if (!(images = pXcursorImagesCreate( nFrames ))) goto cleanup;
for (images->nimage = 0; images->nimage < nFrames; images->nimage++)
images->images[images->nimage] = imgs[images->nimage];
cursor = pXcursorImagesLoadCursor( gdi_display, images );
pXcursorImagesDestroy( images ); /* Note: this frees each individual frame (calls XcursorImageDestroy) */
HeapFree( GetProcessHeap(), 0, imgs );
imgs = NULL;
cleanup:
if (imgs)
{
/* Failed to produce a cursor, free previously allocated frames */
for (i=0; i<nFrames && imgs[i]; i++)
pXcursorImageDestroy( imgs[i] );
HeapFree( GetProcessHeap(), 0, imgs );
}
/* Cleanup all of the resources used to obtain the frame data */
if (hbmColor) DeleteObject( hbmColor );
if (hbmMask) DeleteObject( hbmMask );
HeapFree( GetProcessHeap(), 0, info );
return cursor;
}
#endif /* SONAME_LIBXCURSOR */
struct system_cursors
{
WORD id;
const char *names[8];
};
static const struct system_cursors user32_cursors[] =
{
{ OCR_NORMAL, { "left_ptr" }},
{ OCR_IBEAM, { "xterm", "text" }},
{ OCR_WAIT, { "watch", "wait" }},
{ OCR_CROSS, { "cross" }},
{ OCR_UP, { "center_ptr" }},
{ OCR_SIZE, { "fleur", "size_all" }},
{ OCR_SIZEALL, { "fleur", "size_all" }},
{ OCR_ICON, { "icon" }},
{ OCR_SIZENWSE, { "top_left_corner", "nw-resize" }},
{ OCR_SIZENESW, { "top_right_corner", "ne-resize" }},
{ OCR_SIZEWE, { "h_double_arrow", "size_hor", "ew-resize" }},
{ OCR_SIZENS, { "v_double_arrow", "size_ver", "ns-resize" }},
{ OCR_NO, { "not-allowed", "forbidden", "no-drop" }},
{ OCR_HAND, { "hand2", "pointer", "pointing-hand" }},
{ OCR_APPSTARTING, { "left_ptr_watch" }},
{ OCR_HELP, { "question_arrow", "help" }},
{ 0 }
};
static const struct system_cursors comctl32_cursors[] =
{
{ 102, { "move", "dnd-move" }},
{ 104, { "copy", "dnd-copy" }},
{ 105, { "left_ptr" }},
{ 106, { "col-resize", "split_v" }},
{ 107, { "col-resize", "split_v" }},
{ 108, { "hand2", "pointer", "pointing-hand" }},
{ 135, { "row-resize", "split_h" }},
{ 0 }
};
static const struct system_cursors ole32_cursors[] =
{
{ 1, { "no-drop", "dnd-no-drop" }},
{ 2, { "move", "dnd-move" }},
{ 3, { "copy", "dnd-copy" }},
{ 4, { "alias", "dnd-link" }},
{ 0 }
};
static const struct system_cursors riched20_cursors[] =
{
{ 105, { "hand2", "pointer", "pointing-hand" }},
{ 107, { "right_ptr" }},
{ 109, { "copy", "dnd-copy" }},
{ 110, { "move", "dnd-move" }},
{ 111, { "no-drop", "dnd-no-drop" }},
{ 0 }
};
static const struct
{
const struct system_cursors *cursors;
WCHAR name[16];
} module_cursors[] =
{
{ user32_cursors, {'u','s','e','r','3','2','.','d','l','l',0} },
{ comctl32_cursors, {'c','o','m','c','t','l','3','2','.','d','l','l',0} },
{ ole32_cursors, {'o','l','e','3','2','.','d','l','l',0} },
{ riched20_cursors, {'r','i','c','h','e','d','2','0','.','d','l','l',0} }
};
struct cursor_font_fallback
{
const char *name;
unsigned int shape;
};
static const struct cursor_font_fallback fallbacks[] =
{
{ "X_cursor", XC_X_cursor },
{ "arrow", XC_arrow },
{ "based_arrow_down", XC_based_arrow_down },
{ "based_arrow_up", XC_based_arrow_up },
{ "boat", XC_boat },
{ "bogosity", XC_bogosity },
{ "bottom_left_corner", XC_bottom_left_corner },
{ "bottom_right_corner", XC_bottom_right_corner },
{ "bottom_side", XC_bottom_side },
{ "bottom_tee", XC_bottom_tee },
{ "box_spiral", XC_box_spiral },
{ "center_ptr", XC_center_ptr },
{ "circle", XC_circle },
{ "clock", XC_clock },
{ "coffee_mug", XC_coffee_mug },
{ "col-resize", XC_sb_h_double_arrow },
{ "cross", XC_cross },
{ "cross_reverse", XC_cross_reverse },
{ "crosshair", XC_crosshair },
{ "diamond_cross", XC_diamond_cross },
{ "dot", XC_dot },
{ "dotbox", XC_dotbox },
{ "double_arrow", XC_double_arrow },
{ "draft_large", XC_draft_large },
{ "draft_small", XC_draft_small },
{ "draped_box", XC_draped_box },
{ "exchange", XC_exchange },
{ "fleur", XC_fleur },
{ "gobbler", XC_gobbler },
{ "gumby", XC_gumby },
{ "h_double_arrow", XC_sb_h_double_arrow },
{ "hand1", XC_hand1 },
{ "hand2", XC_hand2 },
{ "heart", XC_heart },
{ "icon", XC_icon },
{ "iron_cross", XC_iron_cross },
{ "left_ptr", XC_left_ptr },
{ "left_side", XC_left_side },
{ "left_tee", XC_left_tee },
{ "leftbutton", XC_leftbutton },
{ "ll_angle", XC_ll_angle },
{ "lr_angle", XC_lr_angle },
{ "man", XC_man },
{ "middlebutton", XC_middlebutton },
{ "mouse", XC_mouse },
{ "pencil", XC_pencil },
{ "pirate", XC_pirate },
{ "plus", XC_plus },
{ "question_arrow", XC_question_arrow },
{ "right_ptr", XC_right_ptr },
{ "right_side", XC_right_side },
{ "right_tee", XC_right_tee },
{ "rightbutton", XC_rightbutton },
{ "row-resize", XC_sb_v_double_arrow },
{ "rtl_logo", XC_rtl_logo },
{ "sailboat", XC_sailboat },
{ "sb_down_arrow", XC_sb_down_arrow },
{ "sb_h_double_arrow", XC_sb_h_double_arrow },
{ "sb_left_arrow", XC_sb_left_arrow },
{ "sb_right_arrow", XC_sb_right_arrow },
{ "sb_up_arrow", XC_sb_up_arrow },
{ "sb_v_double_arrow", XC_sb_v_double_arrow },
{ "shuttle", XC_shuttle },
{ "sizing", XC_sizing },
{ "spider", XC_spider },
{ "spraycan", XC_spraycan },
{ "star", XC_star },
{ "target", XC_target },