2 * Copyright © 2004 David Reveman
4 * Permission to use, copy, modify, distribute, and sell this software
5 * and its documentation for any purpose is hereby granted without
6 * fee, provided that the above copyright notice appear in all copies
7 * and that both that copyright notice and this permission notice
8 * appear in supporting documentation, and that the name of
9 * David Reveman not be used in advertising or publicity pertaining to
10 * distribution of the software without specific, written prior permission.
11 * David Reveman makes no representations about the suitability of this
12 * software for any purpose. It is provided "as is" without express or
15 * DAVID REVEMAN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
17 * NO EVENT SHALL DAVID REVEMAN BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
19 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
20 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
21 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 * Author: David Reveman <davidr@novell.com>
28 #include <X11/extensions/Xrandr.h>
29 #include <X11/cursorfont.h>
31 #include <glitz-glx.h>
34 #include "xglglxext.h"
38 #include "cursorstr.h"
39 #include "mipointer.h"
52 #include <X11/extensions/XKB.h>
54 #include <X11/extensions/XKBconfig.h>
57 XkbQueryExtension (Display
*dpy
,
65 XkbGetKeyboard (Display
*dpy
,
67 unsigned int deviceSpec
);
70 XkbGetControls (Display
*dpy
,
74 #ifndef XKB_BASE_DIRECTORY
75 #define XKB_BASE_DIRECTORY "/usr/lib/X11/xkb/"
77 #ifndef XKB_CONFIG_FILE
78 #define XKB_CONFIG_FILE "X0-config.keyboard"
80 #ifndef XKB_DFLT_RULES_FILE
81 #define XKB_DFLT_RULES_FILE "xorg"
83 #ifndef XKB_DFLT_KB_LAYOUT
84 #define XKB_DFLT_KB_LAYOUT "us"
86 #ifndef XKB_DFLT_KB_MODEL
87 #define XKB_DFLT_KB_MODEL "pc101"
89 #ifndef XKB_DFLT_KB_VARIANT
90 #define XKB_DFLT_KB_VARIANT NULL
92 #ifndef XKB_DFLT_KB_OPTIONS
93 #define XKB_DFLT_KB_OPTIONS NULL
98 #define XGLX_DEFAULT_SCREEN_WIDTH 800
99 #define XGLX_DEFAULT_SCREEN_HEIGHT 600
101 typedef struct _xglxScreen
{
105 CloseScreenProcPtr CloseScreen
;
106 } xglxScreenRec
, *xglxScreenPtr
;
108 int xglxScreenGeneration
= -1;
109 int xglxScreenPrivateIndex
;
111 #define XGLX_GET_SCREEN_PRIV(pScreen) \
112 ((xglxScreenPtr) (pScreen)->devPrivates[xglxScreenPrivateIndex].ptr)
114 #define XGLX_SET_SCREEN_PRIV(pScreen, v) \
115 ((pScreen)->devPrivates[xglxScreenPrivateIndex].ptr = (pointer) v)
117 #define XGLX_SCREEN_PRIV(pScreen) \
118 xglxScreenPtr pScreenPriv = XGLX_GET_SCREEN_PRIV (pScreen)
120 typedef struct _xglxCursor
{
122 } xglxCursorRec
, *xglxCursorPtr
;
124 #define XGLX_GET_CURSOR_PRIV(pCursor, pScreen) \
125 ((xglxCursorPtr) (pCursor)->devPriv[(pScreen)->myNum])
127 #define XGLX_SET_CURSOR_PRIV(pCursor, pScreen, v) \
128 ((pCursor)->devPriv[(pScreen)->myNum] = (pointer) v)
130 #define XGLX_CURSOR_PRIV(pCursor, pScreen) \
131 xglxCursorPtr pCursorPriv = XGLX_GET_CURSOR_PRIV (pCursor, pScreen)
133 static char *xDisplayName
= 0;
134 static Display
*xdisplay
= 0;
136 static CARD32 lastEventTime
= 0;
137 static ScreenPtr currentScreen
= 0;
138 static Bool softCursor
= FALSE
;
139 static Bool fullscreen
= TRUE
;
141 static Bool randrExtension
= FALSE
;
142 static int randrEvent
, randrError
;
144 static glitz_drawable_format_t
*xglxScreenFormat
= 0;
147 xglxAllocatePrivates (ScreenPtr pScreen
)
149 xglxScreenPtr pScreenPriv
;
151 if (xglxScreenGeneration
!= serverGeneration
)
153 xglxScreenPrivateIndex
= AllocateScreenPrivateIndex ();
154 if (xglxScreenPrivateIndex
< 0)
157 xglxScreenGeneration
= serverGeneration
;
160 pScreenPriv
= xalloc (sizeof (xglxScreenRec
));
164 XGLX_SET_SCREEN_PRIV (pScreen
, pScreenPriv
);
171 #define DEFAULT_REFRESH_RATE 50
174 xglxRandRGetInfo (ScreenPtr pScreen
,
177 RRScreenSizePtr pSize
;
179 *rotations
= RR_Rotate_0
;
183 XRRScreenConfiguration
*xconfig
;
184 XRRScreenSize
*sizes
;
185 int nSizes
, currentSize
= 0;
186 short *rates
, currentRate
;
189 XGLX_SCREEN_PRIV (pScreen
);
191 xconfig
= XRRGetScreenInfo (xdisplay
, pScreenPriv
->root
);
192 sizes
= XRRConfigSizes (xconfig
, &nSizes
);
193 currentRate
= XRRConfigCurrentRate (xconfig
);
195 if (pScreenPriv
->fullscreen
)
199 currentSize
= XRRConfigCurrentConfiguration (xconfig
, &rotation
);
201 for (i
= 0; i
< nSizes
; i
++)
203 pSize
= RRRegisterSize (pScreen
,
209 rates
= XRRConfigRates (xconfig
, i
, &nRates
);
211 for (j
= 0; j
< nRates
; j
++)
213 RRRegisterRate (pScreen
, pSize
, rates
[j
]);
215 if (i
== currentSize
&& rates
[j
] == currentRate
)
216 RRSetCurrentConfig (pScreen
, RR_Rotate_0
, currentRate
,
223 pSize
= RRRegisterSize (pScreen
,
229 for (i
= 0; i
< nSizes
; i
++)
231 rates
= XRRConfigRates (xconfig
, i
, &nRates
);
233 for (j
= 0; j
< nRates
; j
++)
235 RRRegisterRate (pScreen
, pSize
, rates
[j
]);
237 if (rates
[j
] == currentRate
)
238 RRSetCurrentConfig (pScreen
, RR_Rotate_0
, currentRate
,
244 XRRFreeScreenConfigInfo (xconfig
);
248 pSize
= RRRegisterSize (pScreen
,
254 RRRegisterRate (pScreen
, pSize
, DEFAULT_REFRESH_RATE
);
255 RRSetCurrentConfig (pScreen
, RR_Rotate_0
, DEFAULT_REFRESH_RATE
, pSize
);
262 xglxRandRSetConfig (ScreenPtr pScreen
,
265 RRScreenSizePtr pSize
)
269 XRRScreenConfiguration
*xconfig
;
270 XRRScreenSize
*sizes
;
271 int nSizes
, currentSize
;
273 int status
= RRSetConfigFailed
;
276 XGLX_SCREEN_PRIV (pScreen
);
278 xconfig
= XRRGetScreenInfo (xdisplay
, pScreenPriv
->root
);
279 sizes
= XRRConfigSizes (xconfig
, &nSizes
);
280 currentSize
= XRRConfigCurrentConfiguration (xconfig
, &rotation
);
282 for (i
= 0; i
< nSizes
; i
++)
284 if (pScreenPriv
->fullscreen
)
286 if (sizes
[i
].width
== pSize
->width
&&
287 sizes
[i
].height
== pSize
->height
&&
288 sizes
[i
].mwidth
== pSize
->mmWidth
&&
289 sizes
[i
].mheight
== pSize
->mmHeight
)
300 rates
= XRRConfigRates (xconfig
, i
, &nRates
);
302 for (j
= 0; j
< nRates
; j
++)
304 if (rates
[j
] == rate
)
307 if (i
>= currentSize
)
315 status
= XRRSetScreenConfigAndRate (xdisplay
,
323 XRRFreeScreenConfigInfo (xconfig
);
325 if (status
== RRSetConfigSuccess
)
329 pPixmap
= (*pScreen
->GetScreenPixmap
) (pScreen
);
331 if (pScreenPriv
->fullscreen
)
333 XGL_PIXMAP_PRIV (pPixmap
);
335 xglSetRootClip (pScreen
, FALSE
);
337 XResizeWindow (xdisplay
, pScreenPriv
->win
,
338 pSize
->width
, pSize
->height
);
340 glitz_drawable_update_size (pPixmapPriv
->drawable
,
341 pSize
->width
, pSize
->height
);
343 pScreen
->width
= pSize
->width
;
344 pScreen
->height
= pSize
->height
;
345 pScreen
->mmWidth
= pSize
->mmWidth
;
346 pScreen
->mmHeight
= pSize
->mmHeight
;
348 (*pScreen
->ModifyPixmapHeader
) (pPixmap
,
351 pPixmap
->drawable
.depth
,
352 pPixmap
->drawable
.bitsPerPixel
,
355 xglSetRootClip (pScreen
, TRUE
);
366 xglxRandRInit (ScreenPtr pScreen
)
368 rrScrPrivPtr pScrPriv
;
370 if (!RRScreenInit (pScreen
))
373 pScrPriv
= rrGetScrPriv (pScreen
);
374 pScrPriv
->rrGetInfo
= xglxRandRGetInfo
;
375 pScrPriv
->rrSetConfig
= xglxRandRSetConfig
;
383 xglxConstrainCursor (ScreenPtr pScreen
,
389 xglxCursorLimits (ScreenPtr pScreen
,
394 *pTopLeftBox
= *pHotBox
;
398 xglxDisplayCursor (ScreenPtr pScreen
,
401 XGLX_SCREEN_PRIV (pScreen
);
402 XGLX_CURSOR_PRIV (pCursor
, pScreen
);
404 XDefineCursor (xdisplay
, pScreenPriv
->win
, pCursorPriv
->cursor
);
412 xglxARGBCursorSupport (void);
415 xglxCreateARGBCursor (ScreenPtr pScreen
,
421 xglxRealizeCursor (ScreenPtr pScreen
,
424 xglxCursorPtr pCursorPriv
;
427 XColor fgColor
, bgColor
;
429 unsigned long valuemask
;
432 XGLX_SCREEN_PRIV (pScreen
);
434 valuemask
= GCForeground
| GCBackground
;
436 values
.foreground
= 1L;
437 values
.background
= 0L;
439 pCursorPriv
= xalloc (sizeof (xglxCursorRec
));
443 XGLX_SET_CURSOR_PRIV (pCursor
, pScreen
, pCursorPriv
);
446 if (pCursor
->bits
->argb
)
448 pCursorPriv
->cursor
= xglxCreateARGBCursor (pScreen
, pCursor
);
449 if (pCursorPriv
->cursor
)
454 source
= XCreatePixmap (xdisplay
,
456 pCursor
->bits
->width
,
457 pCursor
->bits
->height
,
460 mask
= XCreatePixmap (xdisplay
,
462 pCursor
->bits
->width
,
463 pCursor
->bits
->height
,
466 xgc
= XCreateGC (xdisplay
, source
, valuemask
, &values
);
468 ximage
= XCreateImage (xdisplay
,
469 DefaultVisual (xdisplay
, xscreen
),
471 (char *) pCursor
->bits
->source
,
472 pCursor
->bits
->width
,
473 pCursor
->bits
->height
,
474 BitmapPad (xdisplay
), 0);
476 XPutImage (xdisplay
, source
, xgc
, ximage
,
477 0, 0, 0, 0, pCursor
->bits
->width
, pCursor
->bits
->height
);
481 ximage
= XCreateImage (xdisplay
,
482 DefaultVisual (xdisplay
, xscreen
),
484 (char *) pCursor
->bits
->mask
,
485 pCursor
->bits
->width
,
486 pCursor
->bits
->height
,
487 BitmapPad (xdisplay
), 0);
489 XPutImage (xdisplay
, mask
, xgc
, ximage
,
490 0, 0, 0, 0, pCursor
->bits
->width
, pCursor
->bits
->height
);
493 XFreeGC (xdisplay
, xgc
);
495 fgColor
.red
= pCursor
->foreRed
;
496 fgColor
.green
= pCursor
->foreGreen
;
497 fgColor
.blue
= pCursor
->foreBlue
;
499 bgColor
.red
= pCursor
->backRed
;
500 bgColor
.green
= pCursor
->backGreen
;
501 bgColor
.blue
= pCursor
->backBlue
;
503 pCursorPriv
->cursor
=
504 XCreatePixmapCursor (xdisplay
, source
, mask
, &fgColor
, &bgColor
,
505 pCursor
->bits
->xhot
, pCursor
->bits
->yhot
);
507 XFreePixmap (xdisplay
, mask
);
508 XFreePixmap (xdisplay
, source
);
514 xglxUnrealizeCursor (ScreenPtr pScreen
,
517 XGLX_CURSOR_PRIV (pCursor
, pScreen
);
519 XFreeCursor (xdisplay
, pCursorPriv
->cursor
);
526 xglxRecolorCursor (ScreenPtr pScreen
,
530 XColor fgColor
, bgColor
;
532 XGLX_CURSOR_PRIV (pCursor
, pScreen
);
534 fgColor
.red
= pCursor
->foreRed
;
535 fgColor
.green
= pCursor
->foreGreen
;
536 fgColor
.blue
= pCursor
->foreBlue
;
538 bgColor
.red
= pCursor
->backRed
;
539 bgColor
.green
= pCursor
->backGreen
;
540 bgColor
.blue
= pCursor
->backBlue
;
542 XRecolorCursor (xdisplay
, pCursorPriv
->cursor
, &fgColor
, &bgColor
);
546 xglxSetCursorPosition (ScreenPtr pScreen
,
551 XGLX_SCREEN_PRIV (pScreen
);
553 XWarpPointer (xdisplay
, pScreenPriv
->win
, pScreenPriv
->win
,
560 xglxCloseScreen (int index
,
563 glitz_drawable_t
*drawable
;
565 XGLX_SCREEN_PRIV (pScreen
);
567 drawable
= XGL_GET_SCREEN_PRIV (pScreen
)->drawable
;
569 glitz_drawable_destroy (drawable
);
571 xglClearVisualTypes ();
573 if (pScreenPriv
->win
)
574 XDestroyWindow (xdisplay
, pScreenPriv
->win
);
576 if (pScreenPriv
->colormap
)
577 XFreeColormap (xdisplay
, pScreenPriv
->colormap
);
579 XGL_SCREEN_UNWRAP (CloseScreen
);
582 return (*pScreen
->CloseScreen
) (index
, pScreen
);
586 xglxCursorOffScreen (ScreenPtr
*ppScreen
, int *x
, int *y
)
592 xglxCrossScreen (ScreenPtr pScreen
, Bool entering
)
597 xglxWarpCursor (ScreenPtr pScreen
, int x
, int y
)
599 miPointerWarpCursor (pScreen
, x
, y
);
602 miPointerScreenFuncRec xglxPointerScreenFuncs
= {
609 xglxScreenInit (int index
,
614 XSetWindowAttributes xswa
;
616 XSizeHints
*normalHints
;
617 XClassHint
*classHint
;
618 xglxScreenPtr pScreenPriv
;
621 glitz_drawable_format_t
*format
;
622 glitz_drawable_t
*drawable
;
624 format
= xglxScreenFormat
;
626 if (!xglxAllocatePrivates (pScreen
))
629 currentScreen
= pScreen
;
631 pScreenPriv
= XGLX_GET_SCREEN_PRIV (pScreen
);
633 pScreenPriv
->root
= RootWindow (xdisplay
, xscreen
);
634 pScreenPriv
->fullscreen
= fullscreen
;
636 vinfo
= glitz_glx_get_visual_info_from_format (xdisplay
, xscreen
, format
);
639 ErrorF ("[%d] no visual info from format\n", index
);
643 pScreenPriv
->colormap
=
644 XCreateColormap (xdisplay
, pScreenPriv
->root
, vinfo
->visual
,
647 if (XRRQueryExtension (xdisplay
, &randrEvent
, &randrError
))
648 randrExtension
= TRUE
;
652 xglScreenInfo
.width
= DisplayWidth (xdisplay
, xscreen
);
653 xglScreenInfo
.height
= DisplayHeight (xdisplay
, xscreen
);
654 xglScreenInfo
.widthMm
= DisplayWidthMM (xdisplay
, xscreen
);
655 xglScreenInfo
.heightMm
= DisplayHeightMM (xdisplay
, xscreen
);
659 XRRScreenConfiguration
*xconfig
;
661 XRRScreenSize
*sizes
;
662 int nSizes
, currentSize
;
664 xconfig
= XRRGetScreenInfo (xdisplay
, pScreenPriv
->root
);
665 currentSize
= XRRConfigCurrentConfiguration (xconfig
, &rotation
);
666 sizes
= XRRConfigSizes (xconfig
, &nSizes
);
668 xglScreenInfo
.width
= sizes
[currentSize
].width
;
669 xglScreenInfo
.height
= sizes
[currentSize
].height
;
670 xglScreenInfo
.widthMm
= sizes
[currentSize
].mwidth
;
671 xglScreenInfo
.heightMm
= sizes
[currentSize
].mheight
;
673 XRRFreeScreenConfigInfo (xconfig
);
676 else if (xglScreenInfo
.width
== 0 || xglScreenInfo
.height
== 0)
678 xglScreenInfo
.width
= XGLX_DEFAULT_SCREEN_WIDTH
;
679 xglScreenInfo
.height
= XGLX_DEFAULT_SCREEN_HEIGHT
;
682 xswa
.colormap
= pScreenPriv
->colormap
;
685 XCreateWindow (xdisplay
, pScreenPriv
->root
, 0, 0,
686 xglScreenInfo
.width
, xglScreenInfo
.height
, 0,
687 vinfo
->depth
, InputOutput
, vinfo
->visual
,
692 normalHints
= XAllocSizeHints ();
693 normalHints
->flags
= PMinSize
| PMaxSize
| PSize
;
694 normalHints
->min_width
= xglScreenInfo
.width
;
695 normalHints
->min_height
= xglScreenInfo
.height
;
696 normalHints
->max_width
= xglScreenInfo
.width
;
697 normalHints
->max_height
= xglScreenInfo
.height
;
703 normalHints
->flags
|= PPosition
;
706 classHint
= XAllocClassHint ();
707 classHint
->res_name
= "xglx";
708 classHint
->res_class
= "Xglx";
710 wmHints
= XAllocWMHints ();
711 wmHints
->flags
= InputHint
;
712 wmHints
->input
= TRUE
;
714 Xutf8SetWMProperties (xdisplay
, pScreenPriv
->win
, "Xglx", "Xglx", 0, 0,
715 normalHints
, wmHints
, classHint
);
721 drawable
= glitz_glx_create_drawable_for_window (xdisplay
, xscreen
,
722 format
, pScreenPriv
->win
,
724 xglScreenInfo
.height
);
727 ErrorF ("[%d] couldn't create glitz drawable for window\n", index
);
731 XSelectInput (xdisplay
, pScreenPriv
->win
,
732 ButtonPressMask
| ButtonReleaseMask
|
733 KeyPressMask
| KeyReleaseMask
| EnterWindowMask
|
734 PointerMotionMask
| ExposureMask
);
736 XMapWindow (xdisplay
, pScreenPriv
->win
);
740 XClientMessageEvent xev
;
742 memset (&xev
, 0, sizeof (xev
));
744 xev
.type
= ClientMessage
;
745 xev
.message_type
= XInternAtom (xdisplay
, "_NET_WM_STATE", FALSE
);
746 xev
.display
= xdisplay
;
747 xev
.window
= pScreenPriv
->win
;
751 XInternAtom (xdisplay
, "_NET_WM_STATE_FULLSCREEN", FALSE
);
753 XSendEvent (xdisplay
, pScreenPriv
->root
, FALSE
,
754 SubstructureRedirectMask
, (XEvent
*) &xev
);
757 xglScreenInfo
.drawable
= drawable
;
759 if (!xglScreenInit (pScreen
))
763 if (!xglInitVisualConfigs (pScreen
))
767 XGL_SCREEN_WRAP (CloseScreen
, xglxCloseScreen
);
770 if (!xglxARGBCursorSupport ())
776 static char data
= 0;
781 if (!XAllocNamedColor (xdisplay
, pScreenPriv
->colormap
,
782 "black", &black
, &dummy
))
785 bitmap
= XCreateBitmapFromData (xdisplay
, pScreenPriv
->win
, &data
,
790 cursor
= XCreatePixmapCursor (xdisplay
, bitmap
, bitmap
, &black
, &black
,
795 XDefineCursor (xdisplay
, pScreenPriv
->win
, cursor
);
797 XFreeCursor (xdisplay
, cursor
);
798 XFreePixmap (xdisplay
, bitmap
);
799 XFreeColors (xdisplay
, pScreenPriv
->colormap
, &black
.pixel
, 1, 0);
801 miDCInitialize (pScreen
, &xglxPointerScreenFuncs
);
805 pScreen
->ConstrainCursor
= xglxConstrainCursor
;
806 pScreen
->CursorLimits
= xglxCursorLimits
;
807 pScreen
->DisplayCursor
= xglxDisplayCursor
;
808 pScreen
->RealizeCursor
= xglxRealizeCursor
;
809 pScreen
->UnrealizeCursor
= xglxUnrealizeCursor
;
810 pScreen
->RecolorCursor
= xglxRecolorCursor
;
811 pScreen
->SetCursorPosition
= xglxSetCursorPosition
;
814 if (!xglFinishScreenInit (pScreen
))
818 if (!xglxRandRInit (pScreen
))
822 while (XNextEvent (xdisplay
, &xevent
))
823 if (xevent
.type
== Expose
)
830 xglxInitOutput (ScreenInfo
*pScreenInfo
,
834 glitz_drawable_format_t
*format
, templ
;
837 unsigned long extraMask
[] = {
838 GLITZ_FORMAT_DOUBLEBUFFER_MASK
| GLITZ_FORMAT_ALPHA_SIZE_MASK
,
839 GLITZ_FORMAT_DOUBLEBUFFER_MASK
,
840 GLITZ_FORMAT_ALPHA_SIZE_MASK
,
844 xglClearVisualTypes ();
846 xglSetPixmapFormats (pScreenInfo
);
850 char *name
= xDisplayName
;
853 name
= xglxInitXorg ();
855 xdisplay
= XOpenDisplay (name
);
857 FatalError ("can't open display: %s\n", name
? name
: "NULL");
859 xscreen
= DefaultScreen (xdisplay
);
862 XDefineCursor (xdisplay
, RootWindow (xdisplay
, xscreen
),
863 XCreateFontCursor (xdisplay
, XC_watch
));
867 templ
.doublebuffer
= 1;
868 templ
.color
.fourcc
= GLITZ_FOURCC_RGB
;
869 templ
.color
.alpha_size
= 8;
871 mask
= GLITZ_FORMAT_SAMPLES_MASK
| GLITZ_FORMAT_FOURCC_MASK
;
873 for (i
= 0; i
< sizeof (extraMask
) / sizeof (extraMask
[0]); i
++)
875 format
= glitz_glx_find_window_format (xdisplay
, xscreen
,
883 FatalError ("no visual format found");
885 xglScreenInfo
.depth
=
886 format
->color
.red_size
+
887 format
->color
.green_size
+
888 format
->color
.blue_size
;
890 xglSetVisualTypes (xglScreenInfo
.depth
,
892 format
->color
.red_size
,
893 format
->color
.green_size
,
894 format
->color
.blue_size
);
896 xglxScreenFormat
= format
;
898 AddScreen (xglxScreenInit
, argc
, argv
);
902 xglxExposurePredicate (Display
*xdisplay
,
906 return (xevent
->type
== Expose
);
910 xglxNotExposurePredicate (Display
*xdisplay
,
914 return (xevent
->type
!= Expose
);
918 xglxWindowExposures (WindowPtr pWin
,
921 ScreenPtr pScreen
= pWin
->drawable
.pScreen
;
924 if (HasBorder (pWin
))
926 REGION_INIT (pScreen
, &ClipList
, NullBox
, 0);
927 REGION_SUBTRACT (pScreen
, &ClipList
, &pWin
->borderClip
,
929 REGION_INTERSECT (pScreen
, &ClipList
, &ClipList
, (RegionPtr
) pReg
);
930 (*pScreen
->PaintWindowBorder
) (pWin
, &ClipList
, PW_BORDER
);
931 REGION_UNINIT (pScreen
, &ClipList
);
934 REGION_INIT (pScreen
, &ClipList
, NullBox
, 0);
935 REGION_INTERSECT (pScreen
, &ClipList
, &pWin
->clipList
, (RegionPtr
) pReg
);
936 (*pScreen
->WindowExposures
) (pWin
, &ClipList
, NullRegion
);
937 REGION_UNINIT (pScreen
, &ClipList
);
939 return WT_WALKCHILDREN
;
943 xglxBlockHandler (pointer blockData
,
951 XGL_SCREEN_PRIV (currentScreen
);
953 while (XCheckIfEvent (xdisplay
, &X
, xglxExposurePredicate
, NULL
))
955 ScreenPtr pScreen
= currentScreen
;
957 box
.x1
= X
.xexpose
.x
;
958 box
.y1
= X
.xexpose
.y
;
959 box
.x2
= box
.x1
+ X
.xexpose
.width
;
960 box
.y2
= box
.y1
+ X
.xexpose
.height
;
962 REGION_INIT (currentScreen
, ®ion
, &box
, 1);
964 WalkTree (pScreen
, xglxWindowExposures
, ®ion
);
966 REGION_UNINIT (pScreen
, ®ion
);
969 if (!xglSyncSurface (&pScreenPriv
->pScreenPixmap
->drawable
))
970 FatalError (XGL_SW_FAILURE_STRING
);
972 glitz_surface_flush (pScreenPriv
->surface
);
973 glitz_drawable_flush (pScreenPriv
->drawable
);
979 xglxWakeupHandler (pointer blockData
,
983 ScreenPtr pScreen
= currentScreen
;
987 while (XCheckIfEvent (xdisplay
, &X
, xglxNotExposurePredicate
, NULL
))
991 x
.u
.u
.type
= KeyPress
;
992 x
.u
.u
.detail
= X
.xkey
.keycode
;
993 x
.u
.keyButtonPointer
.time
= lastEventTime
= GetTimeInMillis ();
997 x
.u
.u
.type
= KeyRelease
;
998 x
.u
.u
.detail
= X
.xkey
.keycode
;
999 x
.u
.keyButtonPointer
.time
= lastEventTime
= GetTimeInMillis ();
1003 x
.u
.u
.type
= ButtonPress
;
1004 x
.u
.u
.detail
= X
.xbutton
.button
;
1005 x
.u
.keyButtonPointer
.time
= lastEventTime
= GetTimeInMillis ();
1009 x
.u
.u
.type
= ButtonRelease
;
1010 x
.u
.u
.detail
= X
.xbutton
.button
;
1011 x
.u
.keyButtonPointer
.time
= lastEventTime
= GetTimeInMillis ();
1015 x
.u
.u
.type
= MotionNotify
;
1017 x
.u
.keyButtonPointer
.rootX
= X
.xmotion
.x
;
1018 x
.u
.keyButtonPointer
.rootY
= X
.xmotion
.y
;
1019 x
.u
.keyButtonPointer
.time
= lastEventTime
= GetTimeInMillis ();
1020 miPointerAbsoluteCursor (X
.xmotion
.x
, X
.xmotion
.y
, lastEventTime
);
1024 if (X
.xcrossing
.detail
!= NotifyInferior
) {
1026 NewCurrentScreen (pScreen
, X
.xcrossing
.x
, X
.xcrossing
.y
);
1027 x
.u
.u
.type
= MotionNotify
;
1029 x
.u
.keyButtonPointer
.rootX
= X
.xcrossing
.x
;
1030 x
.u
.keyButtonPointer
.rootY
= X
.xcrossing
.y
;
1031 x
.u
.keyButtonPointer
.time
= lastEventTime
=
1044 xglxBell (int volume
,
1049 XBell (xdisplay
, volume
);
1053 xglxKbdCtrl (DeviceIntPtr pDev
,
1056 unsigned long valueMask
;
1057 XKeyboardControl values
;
1060 valueMask
= KBKeyClickPercent
| KBBellPercent
| KBBellPitch
|
1061 KBBellDuration
| KBAutoRepeatMode
;
1063 values
.key_click_percent
= ctrl
->click
;
1064 values
.bell_percent
= ctrl
->bell
;
1065 values
.bell_pitch
= ctrl
->bell_pitch
;
1066 values
.bell_duration
= ctrl
->bell_duration
;
1067 values
.auto_repeat_mode
= (ctrl
->autoRepeat
) ? AutoRepeatModeOn
:
1070 XChangeKeyboardControl (xdisplay
, valueMask
, &values
);
1072 valueMask
= KBLed
| KBLedMode
;
1074 for (i
= 1; i
<= 32; i
++)
1077 values
.led_mode
= (ctrl
->leds
& (1 << (i
- 1))) ? LedModeOn
:
1080 XChangeKeyboardControl (xdisplay
, valueMask
, &values
);
1085 xglxKeybdProc (DeviceIntPtr pDevice
,
1089 DevicePtr pDev
= (DevicePtr
) pDevice
;
1092 return BadImplementation
;
1096 XModifierKeymap
*xmodMap
;
1098 int minKeyCode
, maxKeyCode
, mapWidth
, i
, j
;
1099 KeySymsRec xglxKeySyms
;
1100 CARD8 xglxModMap
[256];
1101 XKeyboardState values
;
1104 KeySym64
*xkeyMap64
;
1109 Bool xkbExtension
= FALSE
;
1110 int xkbOp
, xkbEvent
, xkbError
, xkbMajor
, xkbMinor
;
1113 if (pDev
!= LookupKeyboardDevice ())
1116 xmodMap
= XGetModifierMapping (xdisplay
);
1118 XDisplayKeycodes (xdisplay
, &minKeyCode
, &maxKeyCode
);
1121 xkeyMap64
= XGetKeyboardMapping (xdisplay
,
1123 maxKeyCode
- minKeyCode
+ 1,
1126 len
= (maxKeyCode
- minKeyCode
+ 1) * mapWidth
;
1127 xkeyMap
= (KeySym
*) xalloc (len
* sizeof (KeySym
));
1128 for (i
= 0; i
< len
; ++i
)
1129 xkeyMap
[i
] = xkeyMap64
[i
];
1133 xkeyMap
= XGetKeyboardMapping (xdisplay
,
1135 maxKeyCode
- minKeyCode
+ 1,
1139 memset (xglxModMap
, 0, 256);
1141 for (j
= 0; j
< 8; j
++)
1143 for (i
= 0; i
< xmodMap
->max_keypermod
; i
++)
1147 keyCode
= xmodMap
->modifiermap
[j
* xmodMap
->max_keypermod
+ i
];
1149 xglxModMap
[keyCode
] |= 1 << j
;
1153 XFreeModifiermap (xmodMap
);
1155 xglxKeySyms
.minKeyCode
= minKeyCode
;
1156 xglxKeySyms
.maxKeyCode
= maxKeyCode
;
1157 xglxKeySyms
.mapWidth
= mapWidth
;
1158 xglxKeySyms
.map
= xkeyMap
;
1161 if (!noXkbExtension
)
1162 xkbExtension
= XkbQueryExtension (xdisplay
,
1163 &xkbOp
, &xkbEvent
, &xkbError
,
1164 &xkbMajor
, &xkbMinor
);
1169 char *rules
, *model
, *layout
, *variants
, *options
;
1171 desc
= XkbGetKeyboard (xdisplay
,
1172 XkbGBN_AllComponentsMask
,
1175 if (desc
&& desc
->geom
)
1177 XkbComponentNamesRec names
;
1180 rules
= XKB_DFLT_RULES_FILE
;
1181 model
= XKB_DFLT_KB_MODEL
;
1182 layout
= XKB_DFLT_KB_LAYOUT
;
1183 variants
= XKB_DFLT_KB_VARIANT
;
1184 options
= XKB_DFLT_KB_OPTIONS
;
1186 XkbGetControls (xdisplay
, XkbAllControlsMask
, desc
);
1188 memset (&names
, 0, sizeof (XkbComponentNamesRec
));
1190 XkbSetRulesDflts (rules
, model
, layout
, variants
, options
);
1192 ret
= XkbInitKeyboardDeviceStruct ((pointer
) pDev
,
1200 XkbDDXChangeControls ((pointer
) pDev
, desc
->ctrls
,
1203 XkbFreeKeyboard (desc
, 0, False
);
1210 XGetKeyboardControl (xdisplay
, &values
);
1212 memmove (defaultKeyboardControl
.autoRepeats
,
1213 values
.auto_repeats
, sizeof (values
.auto_repeats
));
1215 ret
= InitKeyboardDeviceStruct (pDev
,
1229 return BadImplementation
;
1245 xglxLegalModifier (unsigned int key
,
1252 xglxProcessInputEvents (void)
1254 mieqProcessInputEvents ();
1259 xglxInitInput (int argc
,
1262 DeviceIntPtr pKeyboard
, pPointer
;
1264 pPointer
= AddInputDevice (xglMouseProc
, TRUE
);
1265 pKeyboard
= AddInputDevice (xglxKeybdProc
, TRUE
);
1267 RegisterPointerDevice (pPointer
);
1268 RegisterKeyboardDevice (pKeyboard
);
1270 miRegisterPointerDevice (screenInfo
.screens
[0], pPointer
);
1271 mieqInit (&pKeyboard
->public, &pPointer
->public);
1273 AddEnabledDevice (XConnectionNumber (xdisplay
));
1275 RegisterBlockAndWakeupHandlers (xglxBlockHandler
,
1283 ErrorF ("-screen WIDTH[/WIDTHMM]xHEIGHT[/HEIGHTMM] "
1284 "specify screen characteristics\n");
1285 ErrorF ("-fullscreen run fullscreen\n");
1286 ErrorF ("-display string display name of the real server\n");
1287 ErrorF ("-softcursor force software cursor\n");
1294 xglxProcessArgument (int argc
,
1298 static Bool checkDisplayName
= FALSE
;
1300 if (!checkDisplayName
)
1302 char *display
= ":0";
1305 for (j
= i
; j
< argc
; j
++)
1307 if (!strcmp (argv
[j
], "-display"))
1310 xDisplayName
= argv
[j
];
1314 else if (argv
[j
][0] == ':')
1321 xDisplayName
= getenv ("DISPLAY");
1327 n
= strspn (xDisplayName
, ":0123456789");
1328 if (strncmp (xDisplayName
, display
, n
) == 0)
1335 checkDisplayName
= TRUE
;
1338 if (!strcmp (argv
[i
], "-screen"))
1342 xglParseScreen (argv
[i
+ 1]);
1349 else if (!strcmp (argv
[i
], "-fullscreen"))
1354 else if (!strcmp (argv
[i
], "-display"))
1361 else if (!strcmp (argv
[i
], "-softcursor"))
1366 else if (!xDisplayName
)
1368 return xglxProcessXorgArgument (argc
, argv
, i
);
1387 xglxOsVendorInit (void)
1393 #include <X11/extensions/Xrender.h>
1396 xglxARGBCursorSupport (void)
1398 int renderMajor
, renderMinor
;
1400 if (!XRenderQueryVersion (xdisplay
, &renderMajor
, &renderMinor
))
1401 renderMajor
= renderMinor
= -1;
1403 return (renderMajor
> 0 || renderMinor
> 4);
1407 xglxCreateARGBCursor (ScreenPtr pScreen
,
1413 XRenderPictFormat
*xformat
;
1417 XGLX_SCREEN_PRIV (pScreen
);
1419 xpixmap
= XCreatePixmap (xdisplay
,
1421 pCursor
->bits
->width
,
1422 pCursor
->bits
->height
,
1425 xgc
= XCreateGC (xdisplay
, xpixmap
, 0, NULL
);
1427 ximage
= XCreateImage (xdisplay
,
1428 DefaultVisual (xdisplay
, xscreen
),
1430 (char *) pCursor
->bits
->argb
,
1431 pCursor
->bits
->width
,
1432 pCursor
->bits
->height
,
1433 32, pCursor
->bits
->width
* 4);
1435 XPutImage (xdisplay
, xpixmap
, xgc
, ximage
,
1436 0, 0, 0, 0, pCursor
->bits
->width
, pCursor
->bits
->height
);
1439 XFreeGC (xdisplay
, xgc
);
1441 xformat
= XRenderFindStandardFormat (xdisplay
, PictStandardARGB32
);
1442 xpicture
= XRenderCreatePicture (xdisplay
, xpixmap
, xformat
, 0, 0);
1444 cursor
= XRenderCreateCursor (xdisplay
, xpicture
,
1445 pCursor
->bits
->xhot
,
1446 pCursor
->bits
->yhot
);
1448 XRenderFreePicture (xdisplay
, xpicture
);
1449 XFreePixmap (xdisplay
, xpixmap
);