1 //opengl platform specific functions for GLX - Added 9/15/99 Matthew Mueller
15 #include <X11/extensions/xf86dga.h>
16 #include <X11/extensions/xf86vmode.h>
20 #include <X11/Xatom.h>
25 #include <X11/Xm/MwmUtil.h>
29 /* bit definitions for MwmHints.flags */
30 #define MWM_HINTS_FUNCTIONS (1L << 0)
31 #define MWM_HINTS_DECORATIONS (1L << 1)
32 #define MWM_HINTS_INPUT_MODE (1L << 2)
33 #define MWM_HINTS_STATUS (1L << 3)
35 /* bit definitions for MwmHints.functions */
36 #define MWM_FUNC_ALL (1L << 0)
37 #define MWM_FUNC_RESIZE (1L << 1)
38 #define MWM_FUNC_MOVE (1L << 2)
39 #define MWM_FUNC_MINIMIZE (1L << 3)
40 #define MWM_FUNC_MAXIMIZE (1L << 4)
41 #define MWM_FUNC_CLOSE (1L << 5)
44 /* bit definitions for MwmHints.decorations */
45 #define MWM_DECOR_ALL (1L << 0)
46 #define MWM_DECOR_BORDER (1L << 1)
47 #define MWM_DECOR_RESIZEH (1L << 2)
48 #define MWM_DECOR_TITLE (1L << 3)
49 #define MWM_DECOR_MENU (1L << 4)
50 #define MWM_DECOR_MINIMIZE (1L << 5)
51 #define MWM_DECOR_MAXIMIZE (1L << 6)
56 unsigned long functions;
57 unsigned long decorations;
62 #define PROP_MOTIF_WM_HINTS_ELEMENTS 5
69 * Specify which Motif window manager border decorations to put on a * top-level window. For example, you can specify that
70 a window is not * resizabe, or omit the titlebar, or completely remove all decorations. * Input: dpy - the X display
72 * flags - bitwise-OR of the MWM_DECOR_xxx symbols in
74 * indicating what decoration elements to enable. Zero would
77 void set_mwm_border( Display *dpy, Window w, unsigned long dflags,unsigned long fflags ) {
78 PropMotifWmHints motif_hints;
81 /* setup the property */
82 motif_hints.flags = MWM_HINTS_DECORATIONS|MWM_HINTS_FUNCTIONS;
83 motif_hints.decorations = dflags;
84 motif_hints.functions = fflags;
86 /* get the atom for the property */
87 prop = XInternAtom( dpy, "_MOTIF_WM_HINTS", True ); if (!prop) {
88 mprintf((0,"set_mwm_border: prop==0\n"));
89 /* something went wrong! */
93 /* not sure this is correct, seems to work, XA_WM_HINTS didn't work */ proptype = prop;
95 XChangeProperty( dpy, w, /* display, window */ prop, proptype, /* property, type */
96 32, /* format: 32-bit datums */ PropModeReplace, /* mode */
97 (unsigned char *) &motif_hints, /* data */ PROP_MOTIF_WM_HINTS_ELEMENTS /* nelements */);
100 int glx_erbase,glx_evbase;
102 XSetWindowAttributes swa;
104 XVisualInfo *visinfo;
105 GLXContext glxcontext;
106 Pixmap blankpixmap=None;
107 Cursor blankcursor=None;
110 void set_wm_hints(int fullscreen){
111 XSizeHints *hints=NULL;
114 // return;//seems screwed.
115 if (!hints) hints=XAllocSizeHints();
116 hints->width=hints->min_width=hints->max_width=hints->base_width=grd_curscreen->sc_w;
117 hints->height=hints->min_height=hints->max_height=hints->base_height=grd_curscreen->sc_h;
118 hints->flags=PSize|PMinSize|PMaxSize|PBaseSize;
119 // hints->min_width=hints->max_width=grd_curscreen->sc_w;
120 // hints->min_height=hints->max_height=grd_curscreen->sc_h;
121 // hints->flags=PMinSize|PMaxSize;
122 XSetWMNormalHints(dpy,win,hints);
125 set_mwm_border(dpy,win,0,0);
127 set_mwm_border(dpy,win,MWM_DECOR_TITLE|MWM_DECOR_BORDER,MWM_FUNC_MOVE|MWM_FUNC_CLOSE);
131 static int attribs[]={GLX_RGBA,GLX_DOUBLEBUFFER,GLX_DEPTH_SIZE,0,GLX_STENCIL_SIZE,0,
132 GLX_ACCUM_RED_SIZE,0,GLX_ACCUM_GREEN_SIZE,0,GLX_ACCUM_BLUE_SIZE,0,GLX_ACCUM_ALPHA_SIZE,0,None};
134 void ogl_do_fullscreen_internal(void){
135 // ogl_smash_texture_list_internal();//not needed
138 XMoveWindow(dpy,win,0,0);
139 // XDefineCursor(dpy,win,blankcursor);
140 //XGrabPointer(dpy,win,0,swa.event_mask,GrabModeAsync,GrabModeAsync,win,blankcursor,CurrentTime);
141 XGrabPointer(dpy,win,1,ButtonPressMask | ButtonReleaseMask | PointerMotionMask,GrabModeAsync,GrabModeAsync,win,blankcursor,CurrentTime);
142 // XGrabKeyboard(dpy,win,1,GrabModeAsync,GrabModeAsync,CurrentTime);//grabbing keyboard doesn't seem to do much good anyway.
145 //make ogl_fullscreen
146 //can you even do this with DGA ? just resizing with ctrl-alt-(-/+) caused X to die a horrible death.
147 //might have to kill the window/context/whatever first? HRm.
151 // XUndefineCursor(dpy,win);
152 XUngrabPointer(dpy,CurrentTime);
153 // XUngrabKeyboard(dpy,CurrentTime);
160 inline void ogl_swap_buffers_internal(void){
161 glXSwapBuffers(dpy,win);
163 int ogl_init_window(int x, int y){
165 XResizeWindow(dpy,win,x,y);
167 glxcontext=glXCreateContext(dpy,visinfo,0,GL_TRUE);
170 swa.colormap=XCreateColormap(dpy,RootWindow(dpy,visinfo->screen),visinfo->visual,AllocNone);
173 swa.event_mask=ExposureMask | StructureNotifyMask | KeyPressMask | KeyReleaseMask| ButtonPressMask | ButtonReleaseMask | PointerMotionMask;
174 //win = XCreateWindow(dpy,RootWindow(dpy,visinfo->screen),0,0,x,y,0,visinfo->depth,InputOutput,visinfo->visual,CWBorderPixel|CWColormap|CWEventMask,&swa);
175 win = XCreateWindow(dpy,RootWindow(dpy,visinfo->screen),0,0,x,y,0,visinfo->depth,InputOutput,visinfo->visual,CWColormap|CWEventMask,&swa);
177 XStoreName(dpy,win,"D2X");
178 // XStoreName(dpy,win,"agry");
182 glXMakeCurrent(dpy,win,glxcontext);
184 set_wm_hints(ogl_fullscreen);
190 unsigned char *blankdata;
192 XQueryBestCursor(dpy,win,1,1,&w,&h);
193 // mprintf((0,"bestcursor %ix%i\n",w,h));
194 blankdata=d_malloc(w*h/8);
195 memset(blankdata,0,w*h/8);
196 memset(&blankcolor,0,sizeof(XColor));
197 blankpixmap=XCreateBitmapFromData(dpy,win,blankdata,w,h);
198 blankcursor=XCreatePixmapCursor(dpy,blankpixmap,blankpixmap,&blankcolor,&blankcolor,w,h);
204 ogl_do_fullscreen_internal();
205 // gr_do_fullscreen(ogl_fullscreen);
208 init_gii_xwin(dpy,win);
212 void ogl_destroy_window(void){
214 glXDestroyContext(dpy,glxcontext);
215 XDestroyWindow(dpy,win);
216 XFreeColormap(dpy,swa.colormap);
224 Error("no display\n");
225 else if (glXQueryExtension(dpy,&glx_erbase,&glx_evbase)==False)
227 else if (!(visinfo = glXChooseVisual(dpy,DefaultScreen(dpy),attribs)))
228 Error("no visual\n");
230 void ogl_close(void){
233 ogl_do_fullscreen_internal();
235 ogl_destroy_window();
236 if (blankcursor!=None){
237 XFreeCursor(dpy,blankcursor);
238 XFreePixmap(dpy,blankpixmap);