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
|
/*
* Copyright © 2004 David Reveman
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without
* fee, provided that the above copyright notice appear in all copies
* and that both that copyright notice and this permission notice
* appear in supporting documentation, and that the name of
* David Reveman not be used in advertising or publicity pertaining to
* distribution of the software without specific, written prior permission.
* David Reveman makes no representations about the suitability of this
* software for any purpose. It is provided "as is" without express or
* implied warranty.
*
* DAVID REVEMAN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
* NO EVENT SHALL DAVID REVEMAN BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* Author: David Reveman <davidr@novell.com>
*/
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <glitz-glx.h>
#include "xgl.h"
#include "inputstr.h"
#include "cursorstr.h"
#include "mipointer.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <math.h>
#define XGLX_DEFAULT_SCREEN_WIDTH 800
#define XGLX_DEFAULT_SCREEN_HEIGHT 600
typedef struct _xglxScreen {
Window win;
Colormap colormap;
CloseScreenProcPtr CloseScreen;
} xglxScreenRec, *xglxScreenPtr;
int xglxScreenGeneration = -1;
int xglxScreenPrivateIndex;
#define XGLX_GET_SCREEN_PRIV(pScreen) \
((xglxScreenPtr) (pScreen)->devPrivates[xglxScreenPrivateIndex].ptr)
#define XGLX_SET_SCREEN_PRIV(pScreen, v) \
((pScreen)->devPrivates[xglxScreenPrivateIndex].ptr = (pointer) v)
#define XGLX_SCREEN_PRIV(pScreen) \
xglxScreenPtr pScreenPriv = XGLX_GET_SCREEN_PRIV (pScreen)
typedef struct _xglxCursor {
Cursor cursor;
} xglxCursorRec, *xglxCursorPtr;
#define XGLX_GET_CURSOR_PRIV(pCursor, pScreen) \
((xglxCursorPtr) (pCursor)->devPriv[(pScreen)->myNum])
#define XGLX_SET_CURSOR_PRIV(pCursor, pScreen, v) \
((pCursor)->devPriv[(pScreen)->myNum] = (pointer) v)
#define XGLX_CURSOR_PRIV(pCursor, pScreen) \
xglxCursorPtr pCursorPriv = XGLX_GET_CURSOR_PRIV (pCursor, pScreen)
char *xDisplayName = NULL;
Display *xdisplay = NULL;
int xscreen;
glitz_format_t *xglxCurrentFormat;
CARD32 lastEventTime = 0;
ScreenPtr currentScreen = NULL;
Bool softCursor = FALSE;
xglScreenInfoRec xglScreenInfo = {
NULL, 0, 0, 0, 0, FALSE,
DEFAULT_GEOMETRY_DATA_TYPE,
DEFAULT_GEOMETRY_USAGE,
FALSE,
XGL_DEFAULT_PBO_MASK,
FALSE
};
static Bool
xglxAllocatePrivates (ScreenPtr pScreen)
{
xglxScreenPtr pScreenPriv;
if (xglxScreenGeneration != serverGeneration)
{
xglxScreenPrivateIndex = AllocateScreenPrivateIndex ();
if (xglxScreenPrivateIndex < 0)
return FALSE;
xglxScreenGeneration = serverGeneration;
}
pScreenPriv = xalloc (sizeof (xglxScreenRec));
if (!pScreenPriv)
return FALSE;
XGLX_SET_SCREEN_PRIV (pScreen, pScreenPriv);
return TRUE;
}
static void
xglxConstrainCursor (ScreenPtr pScreen,
BoxPtr pBox)
{
}
static void
xglxCursorLimits (ScreenPtr pScreen,
CursorPtr pCursor,
BoxPtr pHotBox,
BoxPtr pTopLeftBox)
{
*pTopLeftBox = *pHotBox;
}
static Bool
xglxDisplayCursor (ScreenPtr pScreen,
CursorPtr pCursor)
{
XGLX_SCREEN_PRIV (pScreen);
XGLX_CURSOR_PRIV (pCursor, pScreen);
XDefineCursor (xdisplay, pScreenPriv->win, pCursorPriv->cursor);
return TRUE;
}
#ifdef ARGB_CURSOR
static Bool
xglxARGBCursorSupport (void);
static Cursor
xglxCreateARGBCursor (ScreenPtr pScreen,
CursorPtr pCursor);
#endif
static Bool
xglxRealizeCursor (ScreenPtr pScreen,
CursorPtr pCursor)
{
xglxCursorPtr pCursorPriv;
XImage *ximage;
Pixmap source, mask;
XColor fgColor, bgColor;
GC xgc;
unsigned long valuemask;
XGCValues values;
XGLX_SCREEN_PRIV (pScreen);
valuemask = GCForeground | GCBackground;
values.foreground = 1L;
values.background = 0L;
pCursorPriv = xalloc (sizeof (xglxCursorRec));
if (!pCursorPriv)
return FALSE;
XGLX_SET_CURSOR_PRIV (pCursor, pScreen, pCursorPriv);
#ifdef ARGB_CURSOR
if (pCursor->bits->argb)
{
pCursorPriv->cursor = xglxCreateARGBCursor (pScreen, pCursor);
if (pCursorPriv->cursor)
return TRUE;
}
#endif
source = XCreatePixmap (xdisplay,
pScreenPriv->win,
pCursor->bits->width,
pCursor->bits->height,
1);
mask = XCreatePixmap (xdisplay,
pScreenPriv->win,
pCursor->bits->width,
pCursor->bits->height,
1);
xgc = XCreateGC (xdisplay, source, valuemask, &values);
ximage = XCreateImage (xdisplay,
DefaultVisual (xdisplay, xscreen),
1, XYBitmap, 0,
(char *) pCursor->bits->source,
pCursor->bits->width,
pCursor->bits->height,
BitmapPad (xdisplay), 0);
XPutImage (xdisplay, source, xgc, ximage,
0, 0, 0, 0, pCursor->bits->width, pCursor->bits->height);
XFree (ximage);
ximage = XCreateImage (xdisplay,
DefaultVisual (xdisplay, xscreen),
1, XYBitmap, 0,
(char *) pCursor->bits->mask,
pCursor->bits->width,
pCursor->bits->height,
BitmapPad (xdisplay), 0);
XPutImage (xdisplay, mask, xgc, ximage,
0, 0, 0, 0, pCursor->bits->width, pCursor->bits->height);
XFree (ximage);
XFreeGC (xdisplay, xgc);
fgColor.red = pCursor->foreRed;
fgColor.green = pCursor->foreGreen;
fgColor.blue = pCursor->foreBlue;
bgColor.red = pCursor->backRed;
bgColor.green = pCursor->backGreen;
bgColor.blue = pCursor->backBlue;
pCursorPriv->cursor =
XCreatePixmapCursor (xdisplay, source, mask, &fgColor, &bgColor,
pCursor->bits->xhot, pCursor->bits->yhot);
XFreePixmap (xdisplay, mask);
XFreePixmap (xdisplay, source);
return TRUE;
}
static Bool
xglxUnrealizeCursor (ScreenPtr pScreen,
CursorPtr pCursor)
{
XGLX_CURSOR_PRIV (pCursor, pScreen);
XFreeCursor (xdisplay, pCursorPriv->cursor);
xfree (pCursorPriv);
return TRUE;
}
static void
xglxRecolorCursor (ScreenPtr pScreen,
CursorPtr pCursor,
Bool displayed)
{
XColor fgColor, bgColor;
XGLX_CURSOR_PRIV (pCursor, pScreen);
fgColor.red = pCursor->foreRed;
fgColor.green = pCursor->foreGreen;
fgColor.blue = pCursor->foreBlue;
bgColor.red = pCursor->backRed;
bgColor.green = pCursor->backGreen;
bgColor.blue = pCursor->backBlue;
XRecolorCursor (xdisplay, pCursorPriv->cursor, &fgColor, &bgColor);
}
static Bool
xglxSetCursorPosition (ScreenPtr pScreen,
int x,
int y,
Bool generateEvent)
{
XGLX_SCREEN_PRIV (pScreen);
XWarpPointer (xdisplay, pScreenPriv->win, pScreenPriv->win,
0, 0, 0, 0, x, y);
return TRUE;
}
static Bool
xglxCloseScreen (int index,
ScreenPtr pScreen)
{
glitz_drawable_t *drawable;
XGLX_SCREEN_PRIV (pScreen);
drawable = XGL_GET_SCREEN_PRIV (pScreen)->drawable;
if (drawable)
glitz_drawable_destroy (drawable);
xglClearVisualTypes ();
if (pScreenPriv->win)
XDestroyWindow (xdisplay, pScreenPriv->win);
if (pScreenPriv->colormap)
XFreeColormap (xdisplay, pScreenPriv->colormap);
XGL_SCREEN_UNWRAP (CloseScreen);
xfree (pScreenPriv);
return (*pScreen->CloseScreen) (index, pScreen);
}
static Bool
xglxCursorOffScreen (ScreenPtr *ppScreen, int *x, int *y)
{
return FALSE;
}
static void
xglxCrossScreen (ScreenPtr pScreen, Bool entering)
{
}
static void
xglxWarpCursor (ScreenPtr pScreen, int x, int y)
{
miPointerWarpCursor (pScreen, x, y);
}
miPointerScreenFuncRec xglxPointerScreenFuncs = {
xglxCursorOffScreen,
xglxCrossScreen,
xglxWarpCursor
};
static Bool
xglxScreenInit (int index,
ScreenPtr pScreen,
int argc,
char **argv)
{
XSetWindowAttributes xswa;
XWMHints *wmHints;
XSizeHints *normalHints;
XClassHint *classHint;
xglxScreenPtr pScreenPriv;
Window root;
XVisualInfo *vinfo;
XEvent xevent;
glitz_drawable_format_t *format;
glitz_drawable_t *drawable;
format = xglVisuals[0].format;
if (!xglxAllocatePrivates (pScreen))
return FALSE;
currentScreen = pScreen;
pScreenPriv = XGLX_GET_SCREEN_PRIV (pScreen);
root = RootWindow (xdisplay, xscreen);
vinfo = glitz_glx_get_visual_info_from_format (xdisplay, xscreen, format);
if (!vinfo)
{
ErrorF ("[%d] no visual info from format\n", index);
return FALSE;
}
pScreenPriv->colormap =
XCreateColormap (xdisplay, root, vinfo->visual, AllocNone);
if (xglScreenInfo.fullscreen)
{
xglScreenInfo.width = DisplayWidth (xdisplay, xscreen);
xglScreenInfo.height = DisplayHeight (xdisplay, xscreen);
xglScreenInfo.widthMm = DisplayWidthMM (xdisplay, xscreen);
xglScreenInfo.heightMm = DisplayHeightMM (xdisplay, xscreen);
}
else if (xglScreenInfo.width == 0 || xglScreenInfo.height == 0)
{
xglScreenInfo.width = XGLX_DEFAULT_SCREEN_WIDTH;
xglScreenInfo.height = XGLX_DEFAULT_SCREEN_HEIGHT;
}
xswa.colormap = pScreenPriv->colormap;
pScreenPriv->win =
XCreateWindow (xdisplay, root, 0, 0,
xglScreenInfo.width, xglScreenInfo.height, 0,
vinfo->depth, InputOutput, vinfo->visual,
CWColormap, &xswa);
XFree (vinfo);
normalHints = XAllocSizeHints ();
normalHints->flags = PMinSize | PMaxSize | PSize;
normalHints->min_width = xglScreenInfo.width;
normalHints->min_height = xglScreenInfo.height;
normalHints->max_width = xglScreenInfo.width;
normalHints->max_height = xglScreenInfo.height;
if (xglScreenInfo.fullscreen)
{
normalHints->x = 0;
normalHints->y = 0;
normalHints->flags |= PPosition;
}
classHint = XAllocClassHint ();
classHint->res_name = "xglx";
classHint->res_class = "Xglx";
wmHints = XAllocWMHints ();
wmHints->flags = InputHint;
wmHints->input = TRUE;
Xutf8SetWMProperties (xdisplay, pScreenPriv->win, "Xglx", "Xglx", 0, 0,
normalHints, wmHints, classHint);
XFree (wmHints);
XFree (classHint);
XFree (normalHints);
drawable = glitz_glx_create_drawable_for_window (xdisplay, xscreen,
format, pScreenPriv->win,
xglScreenInfo.width,
xglScreenInfo.height);
if (!drawable)
{
ErrorF ("[%d] couldn't create glitz drawable for window\n", index);
return FALSE;
}
XSelectInput (xdisplay, pScreenPriv->win,
ButtonPressMask | ButtonReleaseMask |
KeyPressMask | KeyReleaseMask | EnterWindowMask |
PointerMotionMask | ExposureMask);
XMapWindow (xdisplay, pScreenPriv->win);
if (xglScreenInfo.fullscreen)
{
XClientMessageEvent xev;
memset (&xev, 0, sizeof (xev));
xev.type = ClientMessage;
xev.message_type = XInternAtom (xdisplay, "_NET_WM_STATE", FALSE);
xev.display = xdisplay;
xev.window = pScreenPriv->win;
xev.format = 32;
xev.data.l[0] = 1;
xev.data.l[1] =
XInternAtom (xdisplay, "_NET_WM_STATE_FULLSCREEN", FALSE);
XSendEvent (xdisplay, root, FALSE, SubstructureRedirectMask,
(XEvent *) &xev);
}
xglScreenInfo.drawable = drawable;
if (!xglScreenInit (pScreen, &xglScreenInfo))
return FALSE;
XGL_SCREEN_WRAP (CloseScreen, xglxCloseScreen);
#ifdef ARGB_CURSOR
if (!xglxARGBCursorSupport ())
softCursor = TRUE;
#endif
if (softCursor)
{
static char data = 0;
XColor black, dummy;
Pixmap bitmap;
Cursor cursor;
if (!XAllocNamedColor (xdisplay, pScreenPriv->colormap,
"black", &black, &dummy))
return FALSE;
bitmap = XCreateBitmapFromData (xdisplay, pScreenPriv->win, &data,
1, 1);
if (!bitmap)
return FALSE;
cursor = XCreatePixmapCursor (xdisplay, bitmap, bitmap, &black, &black,
0, 0);
if (!cursor)
return FALSE;
XDefineCursor (xdisplay, pScreenPriv->win, cursor);
XFreeCursor (xdisplay, cursor);
XFreePixmap (xdisplay, bitmap);
XFreeColors (xdisplay, pScreenPriv->colormap, &black.pixel, 1, 0);
miDCInitialize (pScreen, &xglxPointerScreenFuncs);
}
else
{
pScreen->ConstrainCursor = xglxConstrainCursor;
pScreen->CursorLimits = xglxCursorLimits;
pScreen->DisplayCursor = xglxDisplayCursor;
pScreen->RealizeCursor = xglxRealizeCursor;
pScreen->UnrealizeCursor = xglxUnrealizeCursor;
pScreen->RecolorCursor = xglxRecolorCursor;
pScreen->SetCursorPosition = xglxSetCursorPosition;
}
if (!xglFinishScreenInit (pScreen))
return FALSE;
while (XNextEvent (xdisplay, &xevent))
if (xevent.type == Expose)
break;
return TRUE;
}
void
InitOutput (ScreenInfo *pScreenInfo,
int argc,
char **argv)
{
glitz_drawable_format_t *format, templ;
int i;
unsigned long mask;
unsigned long extraMask[] = {
GLITZ_FORMAT_PBUFFER_MASK |
GLITZ_FORMAT_DOUBLEBUFFER_MASK,
0
};
xglSetPixmapFormats (pScreenInfo);
if (!xdisplay)
{
xdisplay = XOpenDisplay (xDisplayName);
if (!xdisplay)
FatalError ("can't open display");
xscreen = DefaultScreen (xdisplay);
}
templ.types.window = 1;
templ.types.pbuffer = 1;
templ.samples = 1;
templ.doublebuffer = 1;
templ.color.alpha_size = 8;
mask =
GLITZ_FORMAT_WINDOW_MASK |
GLITZ_FORMAT_SAMPLES_MASK;
for (i = 0; i < sizeof (extraMask) / sizeof (extraMask[0]); i++)
{
format = glitz_glx_find_drawable_format (xdisplay, xscreen,
mask | extraMask[i],
&templ, 0);
if (format)
break;
}
if (!format)
FatalError ("no visual format found");
xglSetVisualTypesAndMasks (pScreenInfo, format, (1 << TrueColor));
xglInitVisuals (pScreenInfo);
AddScreen (xglxScreenInit, argc, argv);
}
static Bool
xglxExposurePredicate (Display *xdisplay,
XEvent *xevent,
char *args)
{
return (xevent->type == Expose);
}
static Bool
xglxNotExposurePredicate (Display *xdisplay,
XEvent *xevent,
char *args)
{
return (xevent->type != Expose);
}
static int
xglxWindowExposures (WindowPtr pWin,
pointer pReg)
{
ScreenPtr pScreen = pWin->drawable.pScreen;
RegionRec ClipList;
if (HasBorder (pWin))
{
REGION_INIT (pScreen, &ClipList, NullBox, 0);
REGION_SUBTRACT (pScreen, &ClipList, &pWin->borderClip,
&pWin->winSize);
REGION_INTERSECT (pScreen, &ClipList, &ClipList, (RegionPtr) pReg);
(*pScreen->PaintWindowBorder) (pWin, &ClipList, PW_BORDER);
REGION_UNINIT (pScreen, &ClipList);
}
REGION_INIT (pScreen, &ClipList, NullBox, 0);
REGION_INTERSECT (pScreen, &ClipList, &pWin->clipList, (RegionPtr) pReg);
(*pScreen->WindowExposures) (pWin, &ClipList, NullRegion);
REGION_UNINIT (pScreen, &ClipList);
return WT_WALKCHILDREN;
}
static void
xglxBlockHandler (pointer blockData,
OSTimePtr pTimeout,
pointer pReadMask)
{
XEvent X;
RegionRec region;
BoxRec box;
XGL_SCREEN_PRIV (currentScreen);
while (XCheckIfEvent (xdisplay, &X, xglxExposurePredicate, NULL))
{
ScreenPtr pScreen = currentScreen;
box.x1 = X.xexpose.x;
box.y1 = X.xexpose.y;
box.x2 = box.x1 + X.xexpose.width;
box.y2 = box.y1 + X.xexpose.height;
REGION_INIT (currentScreen, ®ion, &box, 1);
WalkTree (pScreen, xglxWindowExposures, ®ion);
REGION_UNINIT (pScreen, ®ion);
}
if (!xglSyncSurface (&pScreenPriv->pScreenPixmap->drawable))
FatalError (XGL_SW_FAILURE_STRING);
glitz_surface_flush (pScreenPriv->surface);
glitz_drawable_flush (pScreenPriv->drawable);
XFlush (xdisplay);
}
static void
xglxWakeupHandler (pointer blockData,
int result,
pointer pReadMask)
{
ScreenPtr pScreen = currentScreen;
XEvent X;
xEvent x;
while (XCheckIfEvent (xdisplay, &X, xglxNotExposurePredicate, NULL))
{
switch (X.type) {
case KeyPress:
x.u.u.type = KeyPress;
x.u.u.detail = X.xkey.keycode;
x.u.keyButtonPointer.time = lastEventTime = GetTimeInMillis ();
mieqEnqueue (&x);
break;
case KeyRelease:
x.u.u.type = KeyRelease;
x.u.u.detail = X.xkey.keycode;
x.u.keyButtonPointer.time = lastEventTime = GetTimeInMillis ();
mieqEnqueue (&x);
break;
case ButtonPress:
x.u.u.type = ButtonPress;
x.u.u.detail = X.xbutton.button;
x.u.keyButtonPointer.time = lastEventTime = GetTimeInMillis ();
mieqEnqueue (&x);
break;
case ButtonRelease:
x.u.u.type = ButtonRelease;
x.u.u.detail = X.xbutton.button;
x.u.keyButtonPointer.time = lastEventTime = GetTimeInMillis ();
mieqEnqueue (&x);
break;
case MotionNotify:
x.u.u.type = MotionNotify;
x.u.keyButtonPointer.rootX = X.xmotion.x;
x.u.keyButtonPointer.rootY = X.xmotion.y;
x.u.keyButtonPointer.time = lastEventTime = GetTimeInMillis ();
miPointerAbsoluteCursor (X.xmotion.x, X.xmotion.y, lastEventTime);
mieqEnqueue (&x);
break;
case EnterNotify:
if (X.xcrossing.detail != NotifyInferior) {
if (pScreen) {
NewCurrentScreen (pScreen, X.xcrossing.x, X.xcrossing.y);
x.u.u.type = MotionNotify;
x.u.keyButtonPointer.rootX = X.xcrossing.x;
x.u.keyButtonPointer.rootY = X.xcrossing.y;
x.u.keyButtonPointer.time = lastEventTime =
GetTimeInMillis ();
mieqEnqueue (&x);
}
}
break;
default:
break;
}
}
}
static void
xglxBell (int volume,
DeviceIntPtr pDev,
pointer ctrl,
int cls)
{
XBell (xdisplay, volume);
}
static int
xglxKeybdProc (DeviceIntPtr pDevice,
int onoff)
{
Bool ret;
DevicePtr pDev = (DevicePtr) pDevice;
if (!pDev)
return BadImplementation;
switch (onoff) {
case DEVICE_INIT: {
XModifierKeymap *xmodMap;
KeySym *xkeyMap;
int minKeyCode, maxKeyCode, mapWidth, i, j;
KeySymsRec xglxKeySyms;
CARD8 xglxModMap[256];
XKeyboardState values;
if (pDev != LookupKeyboardDevice ())
return !Success;
xmodMap = XGetModifierMapping (xdisplay);
XDisplayKeycodes (xdisplay, &minKeyCode, &maxKeyCode);
xkeyMap = XGetKeyboardMapping (xdisplay,
minKeyCode,
maxKeyCode - minKeyCode + 1,
&mapWidth);
memset (xglxModMap, 0, 256);
for (j = 0; j < 8; j++)
{
for (i = 0; i < xmodMap->max_keypermod; i++)
{
CARD8 keyCode;
keyCode = xmodMap->modifiermap[j * xmodMap->max_keypermod + i];
if (keyCode)
xglxModMap[keyCode] |= 1 << j;
}
}
XFreeModifiermap (xmodMap);
xglxKeySyms.minKeyCode = minKeyCode;
xglxKeySyms.maxKeyCode = maxKeyCode;
xglxKeySyms.mapWidth = mapWidth;
xglxKeySyms.map = xkeyMap;
XGetKeyboardControl (xdisplay, &values);
memmove (defaultKeyboardControl.autoRepeats,
values.auto_repeats, sizeof (values.auto_repeats));
ret = InitKeyboardDeviceStruct (pDev,
&xglxKeySyms,
xglxModMap,
xglxBell,
xglKbdCtrl);
XFree (xkeyMap);
if (!ret)
return BadImplementation;
} break;
case DEVICE_ON:
pDev->on = TRUE;
break;
case DEVICE_OFF:
case DEVICE_CLOSE:
pDev->on = FALSE;
break;
}
return Success;
}
Bool
LegalModifier (unsigned int key,
DevicePtr pDev)
{
return TRUE;
}
void
ProcessInputEvents ()
{
mieqProcessInputEvents ();
miPointerUpdate ();
}
void
InitInput (int argc, char **argv)
{
DeviceIntPtr pKeyboard, pPointer;
pPointer = AddInputDevice (xglMouseProc, TRUE);
pKeyboard = AddInputDevice (xglxKeybdProc, TRUE);
RegisterPointerDevice (pPointer);
RegisterKeyboardDevice (pKeyboard);
miRegisterPointerDevice (screenInfo.screens[0], pPointer);
mieqInit (&pKeyboard->public, &pPointer->public);
AddEnabledDevice (XConnectionNumber (xdisplay));
RegisterBlockAndWakeupHandlers (xglxBlockHandler,
xglxWakeupHandler,
NULL);
}
void
ddxUseMsg (void)
{
ErrorF ("\nXglx usage:\n");
ErrorF ("-display string display name of the real server\n");
ErrorF ("-softcursor force software cursor\n");
xglUseMsg ();
}
int
ddxProcessArgument (int argc, char **argv, int i)
{
if (!strcmp (argv[i], "-display"))
{
if (++i < argc) {
xDisplayName = argv[i];
return 2;
}
return 0;
}
else if (!strcmp (argv[i], "-softcursor"))
{
softCursor = TRUE;
return 1;
}
return xglProcessArgument (&xglScreenInfo, argc, argv, i);
}
void
AbortDDX (void)
{
}
void
ddxGiveUp ()
{
AbortDDX ();
}
void
OsVendorInit (void)
{
}
#ifdef ARGB_CURSOR
#include <X11/extensions/Xrender.h>
static Bool
xglxARGBCursorSupport (void)
{
int renderMajor, renderMinor;
if (!XRenderQueryVersion (xdisplay, &renderMajor, &renderMinor))
renderMajor = renderMinor = -1;
return (renderMajor > 0 || renderMinor > 4);
}
static Cursor
xglxCreateARGBCursor (ScreenPtr pScreen,
CursorPtr pCursor)
{
Pixmap xpixmap;
GC xgc;
XImage *ximage;
XRenderPictFormat *xformat;
Picture xpicture;
Cursor cursor;
XGLX_SCREEN_PRIV (pScreen);
xpixmap = XCreatePixmap (xdisplay,
pScreenPriv->win,
pCursor->bits->width,
pCursor->bits->height,
32);
xgc = XCreateGC (xdisplay, xpixmap, 0, NULL);
ximage = XCreateImage (xdisplay,
DefaultVisual (xdisplay, xscreen),
32, ZPixmap, 0,
(char *) pCursor->bits->argb,
pCursor->bits->width,
pCursor->bits->height,
32, pCursor->bits->width * 4);
XPutImage (xdisplay, xpixmap, xgc, ximage,
0, 0, 0, 0, pCursor->bits->width, pCursor->bits->height);
XFree (ximage);
XFreeGC (xdisplay, xgc);
xformat = XRenderFindStandardFormat (xdisplay, PictStandardARGB32);
xpicture = XRenderCreatePicture (xdisplay, xpixmap, xformat, 0, 0);
cursor = XRenderCreateCursor (xdisplay, xpicture,
pCursor->bits->xhot,
pCursor->bits->yhot);
XRenderFreePicture (xdisplay, xpicture);
XFreePixmap (xdisplay, xpixmap);
return cursor;
}
#endif
|