2 Copyright (C) 1996-1997 Id Software, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 #include <X11/Xutil.h>
30 #include <X11/keysym.h>
31 #include <X11/cursorfont.h>
34 #include <X11/extensions/XShm.h>
35 #if !defined(__APPLE__) && !defined(__MACH__) && !defined(SUNOS)
36 #include <X11/extensions/xf86dga.h>
38 #include <X11/extensions/xf86vmode.h>
41 #include "darkplaces.xpm"
43 // Tell startup code that we have a client
44 int cl_available = true;
46 // note: if we used the XRandR extension we could support refresh rates
47 qboolean vid_supportrefreshrate = false;
50 XVisualInfo *(GLAPIENTRY *qglXChooseVisual)(Display *dpy, int screen, int *attribList);
51 GLXContext (GLAPIENTRY *qglXCreateContext)(Display *dpy, XVisualInfo *vis, GLXContext shareList, Bool direct);
52 void (GLAPIENTRY *qglXDestroyContext)(Display *dpy, GLXContext ctx);
53 Bool (GLAPIENTRY *qglXMakeCurrent)(Display *dpy, GLXDrawable drawable, GLXContext ctx);
54 void (GLAPIENTRY *qglXSwapBuffers)(Display *dpy, GLXDrawable drawable);
55 const char *(GLAPIENTRY *qglXQueryExtensionsString)(Display *dpy, int screen);
57 //GLX_ARB_get_proc_address
58 void *(GLAPIENTRY *qglXGetProcAddressARB)(const GLubyte *procName);
60 static dllfunction_t getprocaddressfuncs[] =
62 {"glXGetProcAddressARB", (void **) &qglXGetProcAddressARB},
66 //GLX_SGI_swap_control
67 GLint (GLAPIENTRY *qglXSwapIntervalSGI)(GLint interval);
69 static dllfunction_t swapcontrolfuncs[] =
71 {"glXSwapIntervalSGI", (void **) &qglXSwapIntervalSGI},
75 static Display *vidx11_display = NULL;
76 static int vidx11_screen;
78 static GLXContext ctx = NULL;
80 Atom wm_delete_window_atom;
82 #define KEY_MASK (KeyPressMask | KeyReleaseMask)
83 #define MOUSE_MASK (ButtonPressMask | ButtonReleaseMask | \
84 PointerMotionMask | ButtonMotionMask)
85 #define X_MASK (KEY_MASK | MOUSE_MASK | VisibilityChangeMask | \
86 StructureNotifyMask | FocusChangeMask | EnterWindowMask | \
90 static qboolean mouse_avail = true;
91 static qboolean vid_usingmousegrab = false;
92 static qboolean vid_usingmouse = false;
93 static qboolean vid_usinghidecursor = false;
94 static qboolean vid_usingvsync = false;
95 static qboolean vid_usevsync = false;
96 static qboolean vid_x11_hardwaregammasupported = false;
97 static qboolean vid_x11_dgasupported = false;
98 static int vid_x11_gammarampsize = 0;
100 #if !defined(__APPLE__) && !defined(SUNOS)
101 cvar_t vid_dgamouse = {CVAR_SAVE, "vid_dgamouse", "1", "make use of DGA mouse input"};
102 static qboolean vid_usingdgamouse = false;
105 qboolean vidmode_ext = false;
107 static int win_x, win_y;
109 static XF86VidModeModeInfo init_vidmode;
110 static qboolean vid_isfullscreen = false;
112 static Visual *vidx11_visual;
113 static Colormap vidx11_colormap;
115 /*-----------------------------------------------------------------------*/
117 static int XLateKey(XKeyEvent *ev, char *ascii)
121 KeySym keysym, shifted;
123 keysym = XLookupKeysym (ev, 0);
124 XLookupString(ev, buf, sizeof buf, &shifted, 0);
129 case XK_KP_Page_Up: key = K_KP_PGUP; break;
130 case XK_Page_Up: key = K_PGUP; break;
132 case XK_KP_Page_Down: key = K_KP_PGDN; break;
133 case XK_Page_Down: key = K_PGDN; break;
135 case XK_KP_Home: key = K_KP_HOME; break;
136 case XK_Home: key = K_HOME; break;
138 case XK_KP_End: key = K_KP_END; break;
139 case XK_End: key = K_END; break;
141 case XK_KP_Left: key = K_KP_LEFTARROW; break;
142 case XK_Left: key = K_LEFTARROW; break;
144 case XK_KP_Right: key = K_KP_RIGHTARROW; break;
145 case XK_Right: key = K_RIGHTARROW; break;
147 case XK_KP_Down: key = K_KP_DOWNARROW; break;
148 case XK_Down: key = K_DOWNARROW; break;
150 case XK_KP_Up: key = K_KP_UPARROW; break;
151 case XK_Up: key = K_UPARROW; break;
153 case XK_Escape: key = K_ESCAPE; break;
155 case XK_KP_Enter: key = K_KP_ENTER; break;
156 case XK_Return: key = K_ENTER; break;
158 case XK_Tab: key = K_TAB; break;
160 case XK_F1: key = K_F1; break;
162 case XK_F2: key = K_F2; break;
164 case XK_F3: key = K_F3; break;
166 case XK_F4: key = K_F4; break;
168 case XK_F5: key = K_F5; break;
170 case XK_F6: key = K_F6; break;
172 case XK_F7: key = K_F7; break;
174 case XK_F8: key = K_F8; break;
176 case XK_F9: key = K_F9; break;
178 case XK_F10: key = K_F10; break;
180 case XK_F11: key = K_F11; break;
182 case XK_F12: key = K_F12; break;
184 case XK_BackSpace: key = K_BACKSPACE; break;
186 case XK_KP_Delete: key = K_KP_DEL; break;
187 case XK_Delete: key = K_DEL; break;
189 case XK_Pause: key = K_PAUSE; break;
192 case XK_Shift_R: key = K_SHIFT; break;
196 case XK_Control_R: key = K_CTRL; break;
200 case XK_ISO_Level3_Shift:
202 case XK_Meta_R: key = K_ALT; break;
204 case XK_KP_Begin: key = K_KP_5; break;
206 case XK_Insert:key = K_INS; break;
207 case XK_KP_Insert: key = K_KP_INS; break;
209 case XK_KP_Multiply: key = K_KP_MULTIPLY; break;
210 case XK_KP_Add: key = K_KP_PLUS; break;
211 case XK_KP_Subtract: key = K_KP_MINUS; break;
212 case XK_KP_Divide: key = K_KP_SLASH; break;
214 case XK_section: key = '~'; break;
220 if (keysym >= 'A' && keysym <= 'Z')
221 key = keysym - 'A' + 'a';
231 static Cursor CreateNullCursor(Display *display, Window root)
239 cursormask = XCreatePixmap(display, root, 1, 1, 1);
240 xgc.function = GXclear;
241 gc = XCreateGC(display, cursormask, GCFunction, &xgc);
242 XFillRectangle(display, cursormask, gc, 0, 0, 1, 1);
243 dummycolour.pixel = 0;
245 dummycolour.flags = 04;
246 cursor = XCreatePixmapCursor(display, cursormask, cursormask, &dummycolour,&dummycolour, 0,0);
247 XFreePixmap(display,cursormask);
252 void VID_SetMouse(qboolean fullscreengrab, qboolean relative, qboolean hidecursor)
254 qboolean usedgamouse;
256 if (!vidx11_display || !win)
260 fullscreengrab = relative = hidecursor = false;
262 usedgamouse = relative && vid_dgamouse.integer;
263 #if !defined(__APPLE__) && !defined(SUNOS)
264 if (!vid_x11_dgasupported)
266 if (fullscreengrab && vid_usingmouse && (vid_usingdgamouse != usedgamouse))
267 VID_SetMouse(false, false, false); // ungrab first!
270 if (vid_usingmousegrab != fullscreengrab)
272 vid_usingmousegrab = fullscreengrab;
273 cl_ignoremousemoves = 2;
276 XGrabPointer(vidx11_display, win, True, 0, GrabModeAsync, GrabModeAsync, win, None, CurrentTime);
277 if (vid_grabkeyboard.integer || vid_isfullscreen)
278 XGrabKeyboard(vidx11_display, win, False, GrabModeAsync, GrabModeAsync, CurrentTime);
282 XUngrabPointer(vidx11_display, CurrentTime);
283 XUngrabKeyboard(vidx11_display, CurrentTime);
291 XWindowAttributes attribs_1;
292 XSetWindowAttributes attribs_2;
294 XGetWindowAttributes(vidx11_display, win, &attribs_1);
295 attribs_2.event_mask = attribs_1.your_event_mask | KEY_MASK | MOUSE_MASK;
296 XChangeWindowAttributes(vidx11_display, win, CWEventMask, &attribs_2);
298 #if !defined(__APPLE__) && !defined(SUNOS)
299 vid_usingdgamouse = usedgamouse;
302 XF86DGADirectVideo(vidx11_display, DefaultScreen(vidx11_display), XF86DGADirectMouse);
303 XWarpPointer(vidx11_display, None, win, 0, 0, 0, 0, 0, 0);
307 XWarpPointer(vidx11_display, None, win, 0, 0, 0, 0, vid.width / 2, vid.height / 2);
309 cl_ignoremousemoves = 2;
310 vid_usingmouse = true;
317 #if !defined(__APPLE__) && !defined(SUNOS)
318 if (vid_usingdgamouse)
319 XF86DGADirectVideo(vidx11_display, DefaultScreen(vidx11_display), 0);
320 vid_usingdgamouse = false;
322 cl_ignoremousemoves = 2;
323 vid_usingmouse = false;
327 if (vid_usinghidecursor != hidecursor)
329 vid_usinghidecursor = hidecursor;
331 XDefineCursor(vidx11_display, win, CreateNullCursor(vidx11_display, win));
333 XUndefineCursor(vidx11_display, win);
337 static keynum_t buttonremap[18] =
359 static void HandleEvents(void)
364 qboolean dowarp = false;
369 while (XPending(vidx11_display))
371 XNextEvent(vidx11_display, &event);
377 key = XLateKey (&event.xkey, &ascii);
378 Key_Event(key, ascii, true);
383 key = XLateKey (&event.xkey, &ascii);
384 Key_Event(key, ascii, false);
391 #if !defined(__APPLE__) && !defined(SUNOS)
392 if (vid_usingdgamouse)
394 in_mouse_x += event.xmotion.x_root;
395 in_mouse_y += event.xmotion.y_root;
400 if (!event.xmotion.send_event)
402 in_mouse_x += event.xmotion.x - in_windowmouse_x;
403 in_mouse_y += event.xmotion.y - in_windowmouse_y;
404 if (abs(vid.width/2 - event.xmotion.x) + abs(vid.height/2 - event.xmotion.y))
405 //if (abs(vid.width/2 - event.xmotion.x) > vid.width / 4 || abs(vid.height/2 - event.xmotion.y) > vid.height / 4)
410 in_windowmouse_x = event.xmotion.x;
411 in_windowmouse_y = event.xmotion.y;
415 // mouse button pressed
416 if (event.xbutton.button <= 18)
417 Key_Event(buttonremap[event.xbutton.button - 1], 0, true);
419 Con_Printf("HandleEvents: ButtonPress gave value %d, 1-18 expected\n", event.xbutton.button);
423 // mouse button released
424 if (event.xbutton.button <= 18)
425 Key_Event(buttonremap[event.xbutton.button - 1], 0, false);
427 Con_Printf("HandleEvents: ButtonRelease gave value %d, 1-18 expected\n", event.xbutton.button);
432 win_x = event.xcreatewindow.x;
433 win_y = event.xcreatewindow.y;
436 case ConfigureNotify:
437 // window changed size/location
438 win_x = event.xconfigure.x;
439 win_y = event.xconfigure.y;
440 if(vid_resizable.integer < 2)
442 vid.width = event.xconfigure.width;
443 vid.height = event.xconfigure.height;
447 // window has been destroyed
451 // window manager messages
452 if ((event.xclient.format == 32) && ((unsigned int)event.xclient.data.l[0] == wm_delete_window_atom))
460 VID_RestoreSystemGamma();
465 // window iconified/rolledup/whatever
467 VID_RestoreSystemGamma();
472 // window is now the input focus
473 vid_activewindow = true;
478 // window is no longer the input focus
479 vid_activewindow = false;
480 VID_RestoreSystemGamma();
483 // mouse entered window
493 /* move the mouse to the window center again */
494 in_windowmouse_x = (int)(vid.width / 2);
495 in_windowmouse_y = (int)(vid.height / 2);
496 XWarpPointer(vidx11_display, None, win, 0, 0, 0, 0, (int)in_windowmouse_x, (int)in_windowmouse_y);
500 static void *prjobj = NULL;
502 static void GL_CloseLibrary(void)
508 qglXGetProcAddressARB = NULL;
511 gl_platformextensions = "";
514 static int GL_OpenLibrary(const char *name)
516 Con_Printf("Loading OpenGL driver %s\n", name);
518 if (!(prjobj = dlopen(name, RTLD_LAZY | RTLD_GLOBAL)))
520 Con_Printf("Unable to open symbol list for %s\n", name);
523 strlcpy(gl_driver, name, sizeof(gl_driver));
527 void *GL_GetProcAddress(const char *name)
530 if (qglXGetProcAddressARB != NULL)
531 p = (void *) qglXGetProcAddressARB((GLubyte *)name);
533 p = (void *) dlsym(prjobj, name);
537 void VID_Shutdown(void)
539 if (!ctx || !vidx11_display)
542 VID_SetMouse(false, false, false);
543 VID_RestoreSystemGamma();
545 // FIXME: glXDestroyContext here?
546 if (vid_isfullscreen)
547 XF86VidModeSwitchToMode(vidx11_display, vidx11_screen, &init_vidmode);
549 XDestroyWindow(vidx11_display, win);
550 XCloseDisplay(vidx11_display);
553 vid_isfullscreen = false;
554 vidx11_display = NULL;
562 void signal_handler(int sig)
564 Con_Printf("Received signal %d, exiting...\n", sig);
565 VID_RestoreSystemGamma();
571 signal(SIGHUP, signal_handler);
572 signal(SIGINT, signal_handler);
573 signal(SIGQUIT, signal_handler);
574 signal(SIGILL, signal_handler);
575 signal(SIGTRAP, signal_handler);
576 signal(SIGIOT, signal_handler);
577 signal(SIGBUS, signal_handler);
578 signal(SIGFPE, signal_handler);
579 signal(SIGSEGV, signal_handler);
580 signal(SIGTERM, signal_handler);
583 void VID_Finish (void)
585 vid_usevsync = vid_vsync.integer && !cls.timedemo && gl_videosyncavailable;
586 if (vid_usingvsync != vid_usevsync && gl_videosyncavailable)
588 vid_usingvsync = vid_usevsync;
589 if (qglXSwapIntervalSGI (vid_usevsync))
590 Con_Print("glXSwapIntervalSGI didn't accept the vid_vsync change, it will take effect on next vid_restart (GLX_SGI_swap_control does not allow turning off vsync)\n");
593 if (r_render.integer)
596 if (r_speeds.integer || gl_finish.integer)
598 qglFinish();CHECKGLERROR
600 qglXSwapBuffers(vidx11_display, win);CHECKGLERROR
603 if (vid_x11_hardwaregammasupported)
604 VID_UpdateGamma(false, vid_x11_gammarampsize);
607 int VID_SetGamma(unsigned short *ramps, int rampsize)
609 return XF86VidModeSetGammaRamp(vidx11_display, vidx11_screen, rampsize, ramps, ramps + rampsize, ramps + rampsize*2);
612 int VID_GetGamma(unsigned short *ramps, int rampsize)
614 return XF86VidModeGetGammaRamp(vidx11_display, vidx11_screen, rampsize, ramps, ramps + rampsize, ramps + rampsize*2);
619 #if !defined(__APPLE__) && !defined(SUNOS)
620 Cvar_RegisterVariable (&vid_dgamouse);
622 InitSig(); // trap evil signals
623 // COMMANDLINEOPTION: Input: -nomouse disables mouse support (see also vid_mouse cvar)
624 if (COM_CheckParm ("-nomouse"))
628 void VID_BuildGLXAttrib(int *attrib, qboolean stencil, qboolean stereobuffer, int samples)
630 *attrib++ = GLX_RGBA;
631 *attrib++ = GLX_RED_SIZE;*attrib++ = stencil ? 8 : 5;
632 *attrib++ = GLX_GREEN_SIZE;*attrib++ = stencil ? 8 : 5;
633 *attrib++ = GLX_BLUE_SIZE;*attrib++ = stencil ? 8 : 5;
634 *attrib++ = GLX_DOUBLEBUFFER;
635 *attrib++ = GLX_DEPTH_SIZE;*attrib++ = stencil ? 24 : 16;
636 // if stencil is enabled, ask for alpha too
639 *attrib++ = GLX_STENCIL_SIZE;*attrib++ = 8;
640 *attrib++ = GLX_ALPHA_SIZE;*attrib++ = 8;
643 *attrib++ = GLX_STEREO;
646 *attrib++ = GLX_SAMPLE_BUFFERS_ARB;
648 *attrib++ = GLX_SAMPLES_ARB;
654 int VID_InitMode(int fullscreen, int width, int height, int bpp, int refreshrate, int stereobuffer, int samples)
658 XSetWindowAttributes attr;
659 XClassHint *clshints;
664 XVisualInfo *visinfo;
665 int MajorVersion, MinorVersion;
666 const char *drivername;
668 #if defined(__APPLE__) && defined(__MACH__)
669 drivername = "/usr/X11R6/lib/libGL.1.dylib";
671 drivername = "libGL.so.1";
673 // COMMANDLINEOPTION: Linux GLX: -gl_driver <drivername> selects a GL driver library, default is libGL.so.1, useful only for using fxmesa or similar, if you don't know what this is for, you don't need it
674 // COMMANDLINEOPTION: BSD GLX: -gl_driver <drivername> selects a GL driver library, default is libGL.so.1, useful only for using fxmesa or similar, if you don't know what this is for, you don't need it
675 // LordHavoc: although this works on MacOSX, it's useless there (as there is only one system libGL)
676 i = COM_CheckParm("-gl_driver");
677 if (i && i < com_argc - 1)
678 drivername = com_argv[i + 1];
679 if (!GL_OpenLibrary(drivername))
681 Con_Printf("Unable to load GL driver \"%s\"\n", drivername);
685 if (!(vidx11_display = XOpenDisplay(NULL)))
687 Con_Print("Couldn't open the X display\n");
691 vidx11_screen = DefaultScreen(vidx11_display);
692 root = RootWindow(vidx11_display, vidx11_screen);
694 // Get video mode list
695 MajorVersion = MinorVersion = 0;
696 if (!XF86VidModeQueryVersion(vidx11_display, &MajorVersion, &MinorVersion))
700 Con_DPrintf("Using XFree86-VidModeExtension Version %d.%d\n", MajorVersion, MinorVersion);
704 if ((qglXChooseVisual = (XVisualInfo *(GLAPIENTRY *)(Display *dpy, int screen, int *attribList))GL_GetProcAddress("glXChooseVisual")) == NULL
705 || (qglXCreateContext = (GLXContext (GLAPIENTRY *)(Display *dpy, XVisualInfo *vis, GLXContext shareList, Bool direct))GL_GetProcAddress("glXCreateContext")) == NULL
706 || (qglXDestroyContext = (void (GLAPIENTRY *)(Display *dpy, GLXContext ctx))GL_GetProcAddress("glXDestroyContext")) == NULL
707 || (qglXMakeCurrent = (Bool (GLAPIENTRY *)(Display *dpy, GLXDrawable drawable, GLXContext ctx))GL_GetProcAddress("glXMakeCurrent")) == NULL
708 || (qglXSwapBuffers = (void (GLAPIENTRY *)(Display *dpy, GLXDrawable drawable))GL_GetProcAddress("glXSwapBuffers")) == NULL
709 || (qglXQueryExtensionsString = (const char *(GLAPIENTRY *)(Display *dpy, int screen))GL_GetProcAddress("glXQueryExtensionsString")) == NULL)
711 Con_Printf("glX functions not found in %s\n", gl_driver);
715 VID_BuildGLXAttrib(attrib, bpp == 32, stereobuffer, samples);
716 visinfo = qglXChooseVisual(vidx11_display, vidx11_screen, attrib);
717 if (!visinfo && (samples == 1))
719 /* Some Mesa drivers reject sample buffers with 1 sample, so try
720 * entirely without one */
721 VID_BuildGLXAttrib(attrib, bpp == 32, stereobuffer, 0);
722 visinfo = qglXChooseVisual(vidx11_display, vidx11_screen, attrib);
726 Con_Print("Couldn't get an RGB, Double-buffered, Depth visual\n");
732 int best_fit, best_dist, dist, x, y;
734 // Are we going fullscreen? If so, let's change video mode
737 XF86VidModeModeLine *current_vidmode;
738 XF86VidModeModeInfo **vidmodes;
741 // This nice hack comes from the SDL source code
742 current_vidmode = (XF86VidModeModeLine*)((char*)&init_vidmode + sizeof(init_vidmode.dotclock));
743 XF86VidModeGetModeLine(vidx11_display, vidx11_screen, (int*)&init_vidmode.dotclock, current_vidmode);
745 XF86VidModeGetAllModeLines(vidx11_display, vidx11_screen, &num_vidmodes, &vidmodes);
749 for (i = 0; i < num_vidmodes; i++)
751 if (width > vidmodes[i]->hdisplay || height > vidmodes[i]->vdisplay)
754 x = width - vidmodes[i]->hdisplay;
755 y = height - vidmodes[i]->vdisplay;
756 dist = (x * x) + (y * y);
757 if (dist < best_dist)
766 // LordHavoc: changed from ActualWidth/ActualHeight =,
767 // to width/height =, so the window will take the full area of
769 width = vidmodes[best_fit]->hdisplay;
770 height = vidmodes[best_fit]->vdisplay;
772 // change to the mode
773 XF86VidModeSwitchToMode(vidx11_display, vidx11_screen, vidmodes[best_fit]);
774 vid_isfullscreen = true;
776 // Move the viewport to top left
777 XF86VidModeSetViewPort(vidx11_display, vidx11_screen, 0, 0);
786 // LordHavoc: save the visual for use in gamma ramp settings later
787 vidx11_visual = visinfo->visual;
789 /* window attributes */
790 attr.background_pixel = 0;
791 attr.border_pixel = 0;
792 // LordHavoc: save the colormap for later, too
793 vidx11_colormap = attr.colormap = XCreateColormap(vidx11_display, root, visinfo->visual, AllocNone);
794 attr.event_mask = X_MASK;
795 if (vid_isfullscreen)
797 mask = CWBackPixel | CWColormap | CWSaveUnder | CWBackingStore | CWEventMask | CWOverrideRedirect;
798 attr.override_redirect = True;
799 attr.backing_store = NotUseful;
800 attr.save_under = False;
803 mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
805 win = XCreateWindow(vidx11_display, root, 0, 0, width, height, 0, visinfo->depth, InputOutput, visinfo->visual, mask, &attr);
807 wmhints = XAllocWMHints();
808 if(XpmCreatePixmapFromData(vidx11_display, win,
809 (gamemode == GAME_NEXUIZ) ? nexuiz_xpm : darkplaces_xpm,
810 &wmhints->icon_pixmap, &wmhints->icon_mask, NULL) == XpmSuccess)
811 wmhints->flags |= IconPixmapHint | IconMaskHint;
813 clshints = XAllocClassHint();
814 clshints->res_name = strdup(gamename);
815 clshints->res_class = strdup("DarkPlaces");
817 szhints = XAllocSizeHints();
818 if(vid_resizable.integer == 0)
820 szhints->min_width = szhints->max_width = width;
821 szhints->min_height = szhints->max_height = height;
822 szhints->flags |= PMinSize | PMaxSize;
825 XmbSetWMProperties(vidx11_display, win, gamename, gamename, (char **) com_argv, com_argc, szhints, wmhints, clshints);
829 //XStoreName(vidx11_display, win, gamename);
830 XMapWindow(vidx11_display, win);
832 // LordHavoc: making the close button on a window do the right thing
833 // seems to involve this mess, sigh...
834 wm_delete_window_atom = XInternAtom(vidx11_display, "WM_DELETE_WINDOW", false);
835 XSetWMProtocols(vidx11_display, win, &wm_delete_window_atom, 1);
837 if (vid_isfullscreen)
839 XMoveWindow(vidx11_display, win, 0, 0);
840 XRaiseWindow(vidx11_display, win);
841 XWarpPointer(vidx11_display, None, win, 0, 0, 0, 0, 0, 0);
842 XFlush(vidx11_display);
843 // Move the viewport to top left
844 XF86VidModeSetViewPort(vidx11_display, vidx11_screen, 0, 0);
847 //XSync(vidx11_display, False);
849 ctx = qglXCreateContext(vidx11_display, visinfo, NULL, True);
852 Con_Printf ("glXCreateContext failed\n");
856 if (!qglXMakeCurrent(vidx11_display, win, ctx))
858 Con_Printf ("glXMakeCurrent failed\n");
862 XSync(vidx11_display, False);
864 if ((qglGetString = (const GLubyte* (GLAPIENTRY *)(GLenum name))GL_GetProcAddress("glGetString")) == NULL)
866 Con_Printf ("glGetString not found in %s\n", gl_driver);
870 gl_extensions = (const char *)qglGetString(GL_EXTENSIONS);
872 gl_platformextensions = qglXQueryExtensionsString(vidx11_display, vidx11_screen);
874 gl_videosyncavailable = false;
876 // COMMANDLINEOPTION: Linux GLX: -nogetprocaddress disables GLX_ARB_get_proc_address (not required, more formal method of getting extension functions)
877 // COMMANDLINEOPTION: BSD GLX: -nogetprocaddress disables GLX_ARB_get_proc_address (not required, more formal method of getting extension functions)
878 // COMMANDLINEOPTION: MacOSX GLX: -nogetprocaddress disables GLX_ARB_get_proc_address (not required, more formal method of getting extension functions)
879 GL_CheckExtension("GLX_ARB_get_proc_address", getprocaddressfuncs, "-nogetprocaddress", false);
880 // COMMANDLINEOPTION: Linux GLX: -novideosync disables GLX_SGI_swap_control
881 // COMMANDLINEOPTION: BSD GLX: -novideosync disables GLX_SGI_swap_control
882 // COMMANDLINEOPTION: MacOSX GLX: -novideosync disables GLX_SGI_swap_control
883 gl_videosyncavailable = GL_CheckExtension("GLX_SGI_swap_control", swapcontrolfuncs, "-novideosync", false);
885 vid_usingmousegrab = false;
886 vid_usingmouse = false;
887 vid_usinghidecursor = false;
888 vid_usingvsync = false;
890 vid_activewindow = true;
891 vid_x11_hardwaregammasupported = XF86VidModeGetGammaRampSize(vidx11_display, vidx11_screen, &vid_x11_gammarampsize) != 0;
892 #if !defined(__APPLE__) && !defined(SUNOS)
893 vid_x11_dgasupported = XF86DGAQueryVersion(vidx11_display, &MajorVersion, &MinorVersion);
894 if (!vid_x11_dgasupported)
895 Con_Print( "Failed to detect XF86DGA Mouse extension\n" );
901 void Sys_SendKeyEvents(void)
903 static qboolean sound_active = true;
905 // enable/disable sound on focus gain/loss
906 if (!vid_hidden && (vid_activewindow || !snd_mutewhenidle.integer))
919 sound_active = false;