2004-08-22 22:29:09 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2005-06-15 04:36:20 +00:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
2004-08-22 22:29:09 +00:00
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
#include <termios.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/stat.h>
|
2005-04-19 19:31:15 +00:00
|
|
|
#ifdef __linux__
|
2004-08-22 22:29:09 +00:00
|
|
|
#include <sys/vt.h>
|
|
|
|
#endif
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <signal.h>
|
|
|
|
|
|
|
|
#include <dlfcn.h>
|
|
|
|
|
|
|
|
#include "quakedef.h"
|
|
|
|
#include "glquake.h"
|
|
|
|
|
|
|
|
#include <GL/glx.h>
|
2011-02-06 20:56:39 +00:00
|
|
|
#ifdef USE_EGL
|
2011-03-24 14:35:24 +00:00
|
|
|
#include "gl_videgl.h"
|
2011-02-06 20:56:39 +00:00
|
|
|
#endif
|
2004-08-22 22:29:09 +00:00
|
|
|
|
|
|
|
#include <X11/keysym.h>
|
|
|
|
#include <X11/cursorfont.h>
|
|
|
|
|
|
|
|
#ifdef USE_DGA
|
2011-02-06 20:56:39 +00:00
|
|
|
#include <X11/extensions/Xxf86dga.h>
|
2004-08-22 22:29:09 +00:00
|
|
|
#endif
|
|
|
|
|
2005-12-15 19:15:39 +00:00
|
|
|
#ifdef __linux__
|
|
|
|
#define WITH_VMODE //undefine this if the following include fails.
|
|
|
|
#endif
|
2004-08-22 22:29:09 +00:00
|
|
|
#ifdef WITH_VMODE
|
|
|
|
#include <X11/extensions/xf86vmode.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#define WARP_WIDTH 320
|
|
|
|
#define WARP_HEIGHT 200
|
|
|
|
|
|
|
|
static Display *vid_dpy = NULL;
|
2012-10-14 10:57:11 +00:00
|
|
|
static Cursor vid_nullcursor;
|
2004-08-22 22:29:09 +00:00
|
|
|
static Window vid_window;
|
|
|
|
static GLXContext ctx = NULL;
|
|
|
|
int scrnum;
|
|
|
|
|
2009-07-12 18:57:40 +00:00
|
|
|
static qboolean vidglx_fullscreen;
|
2004-08-22 22:29:09 +00:00
|
|
|
|
|
|
|
static float old_windowed_mouse = 0;
|
|
|
|
|
2007-10-17 14:09:43 +00:00
|
|
|
#ifdef USE_DGA
|
|
|
|
static int dgamouse = 0;
|
|
|
|
#endif
|
|
|
|
|
2004-08-22 22:29:09 +00:00
|
|
|
#define KEY_MASK (KeyPressMask | KeyReleaseMask)
|
|
|
|
#define MOUSE_MASK (ButtonPressMask | ButtonReleaseMask | \
|
|
|
|
PointerMotionMask)
|
|
|
|
|
2004-12-05 08:25:01 +00:00
|
|
|
#define X_MASK (KEY_MASK | MOUSE_MASK | ResizeRequest | StructureNotifyMask | FocusChangeMask | VisibilityChangeMask)
|
2004-08-22 22:29:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef WITH_VMODE
|
2005-04-18 05:41:39 +00:00
|
|
|
static int vidmode_ext = 0;
|
2004-08-22 22:29:09 +00:00
|
|
|
static XF86VidModeModeInfo **vidmodes;
|
|
|
|
static int num_vidmodes;
|
|
|
|
static qboolean vidmode_active = false;
|
2005-11-21 21:07:45 +00:00
|
|
|
static int vidmode_usemode = -1; //so that it can be reset if they switch away.
|
2005-01-24 03:07:16 +00:00
|
|
|
|
2005-07-28 15:52:31 +00:00
|
|
|
unsigned short originalramps[3][256];
|
2005-11-21 21:07:45 +00:00
|
|
|
qboolean originalapplied; //states that the origionalramps arrays are valid, and contain stuff that we should revert to on close
|
2004-08-22 22:29:09 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
extern cvar_t _windowed_mouse;
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
float gldepthmin, gldepthmax;
|
|
|
|
|
|
|
|
const char *gl_vendor;
|
|
|
|
const char *gl_renderer;
|
|
|
|
const char *gl_version;
|
|
|
|
const char *gl_extensions;
|
|
|
|
|
|
|
|
qboolean is8bit = false;
|
|
|
|
qboolean isPermedia = false;
|
|
|
|
qboolean mouseactive = false;
|
2005-01-24 03:07:16 +00:00
|
|
|
qboolean ActiveApp = false;
|
2004-08-22 22:29:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
static void *gllibrary;
|
|
|
|
|
|
|
|
XVisualInfo* (*qglXChooseVisual) (Display *dpy, int screen, int *attribList);
|
|
|
|
void (*qglXSwapBuffers) (Display *dpy, GLXDrawable drawable);
|
|
|
|
Bool (*qglXMakeCurrent) (Display *dpy, GLXDrawable drawable, GLXContext ctx);
|
|
|
|
GLXContext (*qglXCreateContext) (Display *dpy, XVisualInfo *vis, GLXContext shareList, Bool direct);
|
|
|
|
void (*qglXDestroyContext) (Display *dpy, GLXContext ctx);
|
|
|
|
void *(*qglXGetProcAddress) (char *name);
|
|
|
|
|
|
|
|
void GLX_CloseLibrary(void)
|
|
|
|
{
|
|
|
|
dlclose(gllibrary);
|
|
|
|
gllibrary = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
qboolean GLX_InitLibrary(char *driver)
|
|
|
|
{
|
|
|
|
if (driver && *driver)
|
2005-12-15 19:15:39 +00:00
|
|
|
gllibrary = dlopen(driver, RTLD_LAZY);
|
2004-08-22 22:29:09 +00:00
|
|
|
else
|
|
|
|
gllibrary = NULL;
|
2004-12-22 13:47:57 +00:00
|
|
|
if (!gllibrary) //I hate this.
|
2005-12-15 19:15:39 +00:00
|
|
|
gllibrary = dlopen("libGL.so.1", RTLD_LAZY);
|
2005-12-21 03:07:33 +00:00
|
|
|
if (!gllibrary)
|
|
|
|
gllibrary = dlopen("libGL.so", RTLD_LAZY);
|
2004-08-22 22:29:09 +00:00
|
|
|
if (!gllibrary)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
qglXChooseVisual = dlsym(gllibrary, "glXChooseVisual");
|
|
|
|
qglXSwapBuffers = dlsym(gllibrary, "glXSwapBuffers");
|
|
|
|
qglXMakeCurrent = dlsym(gllibrary, "glXMakeCurrent");
|
|
|
|
qglXCreateContext = dlsym(gllibrary, "glXCreateContext");
|
|
|
|
qglXDestroyContext = dlsym(gllibrary, "glXDestroyContext");
|
|
|
|
qglXGetProcAddress = dlsym(gllibrary, "glXGetProcAddress");
|
|
|
|
if (!qglXGetProcAddress)
|
|
|
|
qglXGetProcAddress = dlsym(gllibrary, "glXGetProcAddressARB");
|
|
|
|
|
|
|
|
if (!qglXSwapBuffers && !qglXDestroyContext && !qglXCreateContext && !qglXMakeCurrent && !qglXChooseVisual)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *GLX_GetSymbol(char *name)
|
|
|
|
{
|
|
|
|
void *symb;
|
2011-09-05 01:48:23 +00:00
|
|
|
|
2004-08-22 22:29:09 +00:00
|
|
|
if (qglXGetProcAddress)
|
|
|
|
symb = qglXGetProcAddress(name);
|
|
|
|
else
|
|
|
|
symb = NULL;
|
|
|
|
|
|
|
|
if (!symb)
|
|
|
|
symb = dlsym(gllibrary, name);
|
|
|
|
return symb;
|
|
|
|
}
|
|
|
|
|
2009-07-07 21:32:54 +00:00
|
|
|
static int XLateKey(XKeyEvent *ev, unsigned int *unicode)
|
2004-08-22 22:29:09 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
int key;
|
|
|
|
char buf[64];
|
2009-07-07 21:32:54 +00:00
|
|
|
KeySym keysym, shifted;
|
2004-08-22 22:29:09 +00:00
|
|
|
|
|
|
|
key = 0;
|
|
|
|
|
2009-07-07 21:32:54 +00:00
|
|
|
keysym = XLookupKeysym(ev, 0);
|
|
|
|
XLookupString(ev, buf, sizeof buf, &shifted, 0);
|
|
|
|
if (unicode)
|
|
|
|
*unicode = buf[0];
|
2004-08-22 22:29:09 +00:00
|
|
|
|
|
|
|
switch(keysym)
|
|
|
|
{
|
2005-06-15 04:36:20 +00:00
|
|
|
case XK_KP_Page_Up:
|
2004-08-22 22:29:09 +00:00
|
|
|
case XK_Page_Up: key = K_PGUP; break;
|
|
|
|
|
2005-06-15 04:36:20 +00:00
|
|
|
case XK_KP_Page_Down:
|
2004-08-22 22:29:09 +00:00
|
|
|
case XK_Page_Down: key = K_PGDN; break;
|
|
|
|
|
2005-06-15 04:36:20 +00:00
|
|
|
case XK_KP_Home:
|
2004-08-22 22:29:09 +00:00
|
|
|
case XK_Home: key = K_HOME; break;
|
|
|
|
|
2005-06-15 04:36:20 +00:00
|
|
|
case XK_KP_End:
|
2004-08-22 22:29:09 +00:00
|
|
|
case XK_End: key = K_END; break;
|
|
|
|
|
2005-06-15 04:36:20 +00:00
|
|
|
case XK_KP_Left:
|
2004-08-22 22:29:09 +00:00
|
|
|
case XK_Left: key = K_LEFTARROW; break;
|
|
|
|
|
2005-06-15 04:36:20 +00:00
|
|
|
case XK_KP_Right:
|
2004-08-22 22:29:09 +00:00
|
|
|
case XK_Right: key = K_RIGHTARROW; break;
|
|
|
|
|
2005-06-15 04:36:20 +00:00
|
|
|
case XK_KP_Down:
|
2004-08-22 22:29:09 +00:00
|
|
|
case XK_Down: key = K_DOWNARROW; break;
|
|
|
|
|
2005-06-15 04:36:20 +00:00
|
|
|
case XK_KP_Up:
|
2004-08-22 22:29:09 +00:00
|
|
|
case XK_Up: key = K_UPARROW; break;
|
|
|
|
|
|
|
|
case XK_Escape: key = K_ESCAPE; break;
|
|
|
|
|
2005-06-15 04:36:20 +00:00
|
|
|
case XK_KP_Enter:
|
2004-08-22 22:29:09 +00:00
|
|
|
case XK_Return: key = K_ENTER; break;
|
|
|
|
|
|
|
|
case XK_Tab: key = K_TAB; break;
|
|
|
|
|
|
|
|
case XK_F1: key = K_F1; break;
|
|
|
|
|
|
|
|
case XK_F2: key = K_F2; break;
|
|
|
|
|
|
|
|
case XK_F3: key = K_F3; break;
|
|
|
|
|
|
|
|
case XK_F4: key = K_F4; break;
|
|
|
|
|
|
|
|
case XK_F5: key = K_F5; break;
|
|
|
|
|
|
|
|
case XK_F6: key = K_F6; break;
|
|
|
|
|
|
|
|
case XK_F7: key = K_F7; break;
|
|
|
|
|
|
|
|
case XK_F8: key = K_F8; break;
|
|
|
|
|
|
|
|
case XK_F9: key = K_F9; break;
|
|
|
|
|
|
|
|
case XK_F10: key = K_F10; break;
|
|
|
|
|
|
|
|
case XK_F11: key = K_F11; break;
|
|
|
|
|
|
|
|
case XK_F12: key = K_F12; break;
|
|
|
|
|
|
|
|
case XK_BackSpace: key = K_BACKSPACE; break;
|
|
|
|
|
2005-06-15 04:36:20 +00:00
|
|
|
case XK_KP_Delete:
|
2004-08-22 22:29:09 +00:00
|
|
|
case XK_Delete: key = K_DEL; break;
|
|
|
|
|
|
|
|
case XK_Pause: key = K_PAUSE; break;
|
|
|
|
|
|
|
|
case XK_Shift_L:
|
|
|
|
case XK_Shift_R: key = K_SHIFT; break;
|
|
|
|
|
2005-06-15 04:36:20 +00:00
|
|
|
case XK_Execute:
|
|
|
|
case XK_Control_L:
|
2004-08-22 22:29:09 +00:00
|
|
|
case XK_Control_R: key = K_CTRL; break;
|
|
|
|
|
2005-06-15 04:36:20 +00:00
|
|
|
case XK_Alt_L:
|
|
|
|
case XK_Meta_L:
|
|
|
|
case XK_Alt_R:
|
2004-08-22 22:29:09 +00:00
|
|
|
case XK_Meta_R: key = K_ALT; break;
|
|
|
|
|
|
|
|
case XK_KP_Begin: key = '5'; break;
|
|
|
|
|
2005-06-15 04:36:20 +00:00
|
|
|
case XK_KP_Insert:
|
2004-08-22 22:29:09 +00:00
|
|
|
case XK_Insert:key = K_INS; break;
|
|
|
|
|
|
|
|
case XK_KP_Multiply: key = '*'; break;
|
|
|
|
case XK_KP_Add: key = '+'; break;
|
|
|
|
case XK_KP_Subtract: key = '-'; break;
|
|
|
|
case XK_KP_Divide: key = '/'; break;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
case 0x021: key = '1';break;/* [!] */
|
|
|
|
case 0x040: key = '2';break;/* [@] */
|
|
|
|
case 0x023: key = '3';break;/* [#] */
|
|
|
|
case 0x024: key = '4';break;/* [$] */
|
|
|
|
case 0x025: key = '5';break;/* [%] */
|
|
|
|
case 0x05e: key = '6';break;/* [^] */
|
|
|
|
case 0x026: key = '7';break;/* [&] */
|
|
|
|
case 0x02a: key = '8';break;/* [*] */
|
|
|
|
case 0x028: key = '9';;break;/* [(] */
|
|
|
|
case 0x029: key = '0';break;/* [)] */
|
|
|
|
case 0x05f: key = '-';break;/* [_] */
|
|
|
|
case 0x02b: key = '=';break;/* [+] */
|
|
|
|
case 0x07c: key = '\'';break;/* [|] */
|
|
|
|
case 0x07d: key = '[';break;/* [}] */
|
|
|
|
case 0x07b: key = ']';break;/* [{] */
|
|
|
|
case 0x022: key = '\'';break;/* ["] */
|
|
|
|
case 0x03a: key = ';';break;/* [:] */
|
|
|
|
case 0x03f: key = '/';break;/* [?] */
|
|
|
|
case 0x03e: key = '.';break;/* [>] */
|
|
|
|
case 0x03c: key = ',';break;/* [<] */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
default:
|
|
|
|
key = *(unsigned char*)buf;
|
|
|
|
if (key >= 'A' && key <= 'Z')
|
|
|
|
key = key - 'A' + 'a';
|
|
|
|
break;
|
2005-06-15 04:36:20 +00:00
|
|
|
}
|
2004-08-22 22:29:09 +00:00
|
|
|
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void install_grabs(void)
|
|
|
|
{
|
|
|
|
XGrabPointer(vid_dpy, vid_window,
|
|
|
|
True,
|
|
|
|
0,
|
|
|
|
GrabModeAsync, GrabModeAsync,
|
|
|
|
vid_window,
|
|
|
|
None,
|
|
|
|
CurrentTime);
|
|
|
|
|
|
|
|
#ifdef USE_DGA
|
2008-05-13 11:16:20 +00:00
|
|
|
// TODO: make this into a cvar, like "in_dgamouse", instead of parameters
|
|
|
|
// TODO: inform the user when DGA is enabled
|
|
|
|
if (!COM_CheckParm("-nodga") && !COM_CheckParm("-nomdga"))
|
|
|
|
{
|
|
|
|
XF86DGADirectVideo(vid_dpy, DefaultScreen(vid_dpy), XF86DGADirectMouse);
|
|
|
|
dgamouse = 1;
|
|
|
|
}
|
|
|
|
else
|
2004-08-22 22:29:09 +00:00
|
|
|
#endif
|
2008-05-13 11:16:20 +00:00
|
|
|
{
|
|
|
|
XWarpPointer(vid_dpy, None, vid_window,
|
|
|
|
0, 0, 0, 0,
|
|
|
|
vid.width / 2, vid.height / 2);
|
|
|
|
}
|
2004-08-22 22:29:09 +00:00
|
|
|
|
|
|
|
// XSync(vid_dpy, True);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void uninstall_grabs(void)
|
|
|
|
{
|
|
|
|
#ifdef USE_DGA
|
2011-01-27 01:34:08 +00:00
|
|
|
if (dgamouse)
|
|
|
|
{
|
|
|
|
XF86DGADirectVideo(vid_dpy, DefaultScreen(vid_dpy), 0);
|
|
|
|
dgamouse = 0;
|
|
|
|
}
|
2004-08-22 22:29:09 +00:00
|
|
|
#endif
|
|
|
|
|
2011-09-05 01:48:23 +00:00
|
|
|
if (vid_dpy)
|
|
|
|
XUngrabPointer(vid_dpy, CurrentTime);
|
2004-08-22 22:29:09 +00:00
|
|
|
|
|
|
|
// XSync(vid_dpy, True);
|
|
|
|
}
|
|
|
|
|
2005-01-24 03:07:16 +00:00
|
|
|
void ClearAllStates (void)
|
|
|
|
{
|
|
|
|
int i;
|
2005-06-15 04:36:20 +00:00
|
|
|
|
2005-01-24 03:07:16 +00:00
|
|
|
// send an up event for each key, to make sure the server clears them all
|
|
|
|
for (i=0 ; i<256 ; i++)
|
|
|
|
{
|
2010-08-14 03:17:33 +00:00
|
|
|
Key_Event (0, i, 0, false);
|
2005-01-24 03:07:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Key_ClearStates ();
|
|
|
|
// IN_ClearStates ();
|
|
|
|
}
|
|
|
|
|
2004-08-22 22:29:09 +00:00
|
|
|
static void GetEvent(void)
|
|
|
|
{
|
|
|
|
XEvent event;
|
|
|
|
int b;
|
2009-07-07 21:32:54 +00:00
|
|
|
unsigned int uc;
|
2004-08-22 22:29:09 +00:00
|
|
|
qboolean wantwindowed;
|
2008-02-05 00:38:41 +00:00
|
|
|
qboolean x11violations = true;
|
2004-08-22 22:29:09 +00:00
|
|
|
|
|
|
|
if (!vid_dpy)
|
|
|
|
return;
|
|
|
|
|
|
|
|
XNextEvent(vid_dpy, &event);
|
|
|
|
|
|
|
|
switch (event.type) {
|
2004-12-05 08:25:01 +00:00
|
|
|
case ResizeRequest:
|
2009-11-04 21:16:50 +00:00
|
|
|
vid.pixelwidth = event.xresizerequest.width;
|
|
|
|
vid.pixelheight = event.xresizerequest.height;
|
2004-12-05 08:25:01 +00:00
|
|
|
break;
|
|
|
|
case ConfigureNotify:
|
2009-11-04 21:16:50 +00:00
|
|
|
vid.pixelwidth = event.xconfigurerequest.width;
|
|
|
|
vid.pixelheight = event.xconfigurerequest.height;
|
2004-12-05 08:25:01 +00:00
|
|
|
break;
|
2004-08-22 22:29:09 +00:00
|
|
|
case KeyPress:
|
2009-07-07 21:32:54 +00:00
|
|
|
b = XLateKey(&event.xkey, &uc);
|
2010-08-14 03:17:33 +00:00
|
|
|
Key_Event(0, b, uc, true);
|
2009-07-07 21:32:54 +00:00
|
|
|
break;
|
2004-08-22 22:29:09 +00:00
|
|
|
case KeyRelease:
|
2009-07-07 21:32:54 +00:00
|
|
|
b = XLateKey(&event.xkey, NULL);
|
2010-08-14 03:17:33 +00:00
|
|
|
Key_Event(0, b, 0, false);
|
2004-08-22 22:29:09 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MotionNotify:
|
|
|
|
#ifdef USE_DGA
|
|
|
|
if (dgamouse && old_windowed_mouse)
|
|
|
|
{
|
2012-10-14 09:00:49 +00:00
|
|
|
IN_MouseMove(0, false, event.xmotion.x_root, event.xmotion.y_root, 0, 0);
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
if (old_windowed_mouse)
|
|
|
|
{
|
2012-10-14 09:00:49 +00:00
|
|
|
int cx = vid.pixelwidth/2, cy=vid.pixelheight/2;
|
|
|
|
IN_MouseMove(0, false, event.xmotion.x - cx, event.xmotion.y - cy, 0, 0);
|
2004-08-22 22:29:09 +00:00
|
|
|
|
2012-10-14 10:57:11 +00:00
|
|
|
/* move the mouse to the window center again (disabling warp first so we don't see it*/
|
2004-08-22 22:29:09 +00:00
|
|
|
XSelectInput(vid_dpy, vid_window, X_MASK & ~PointerMotionMask);
|
2005-06-15 04:36:20 +00:00
|
|
|
XWarpPointer(vid_dpy, None, vid_window, 0, 0, 0, 0,
|
2012-10-14 09:00:49 +00:00
|
|
|
cx, cy);
|
2004-08-22 22:29:09 +00:00
|
|
|
XSelectInput(vid_dpy, vid_window, X_MASK);
|
|
|
|
}
|
2012-10-14 10:57:11 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
IN_MouseMove(0, true, event.xmotion.x, event.xmotion.y, 0, 0);
|
|
|
|
}
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ButtonPress:
|
|
|
|
b=-1;
|
|
|
|
if (event.xbutton.button == 1)
|
2008-02-05 00:38:41 +00:00
|
|
|
b = K_MOUSE1;
|
2004-08-22 22:29:09 +00:00
|
|
|
else if (event.xbutton.button == 2)
|
2008-02-05 00:38:41 +00:00
|
|
|
b = K_MOUSE3;
|
2004-08-22 22:29:09 +00:00
|
|
|
else if (event.xbutton.button == 3)
|
2008-02-05 00:38:41 +00:00
|
|
|
b = K_MOUSE2;
|
|
|
|
//note, the x11 protocol does not support a mousewheel
|
|
|
|
//we only support it because we follow convention. the actual protocol specifies 4+5 as regular buttons
|
2005-11-21 21:07:45 +00:00
|
|
|
else if (event.xbutton.button == 4)
|
2008-02-05 00:38:41 +00:00
|
|
|
b = x11violations?K_MWHEELUP:K_MOUSE4;
|
2005-11-21 21:07:45 +00:00
|
|
|
else if (event.xbutton.button == 5)
|
2008-02-05 00:38:41 +00:00
|
|
|
b = x11violations?K_MWHEELDOWN:K_MOUSE5;
|
|
|
|
//note, the x11 protocol does not support more than 5 mouse buttons
|
|
|
|
//which is a bit of a shame, but hey.
|
|
|
|
else if (event.xbutton.button == 6)
|
|
|
|
b = x11violations?K_MOUSE4:-1;
|
|
|
|
else if (event.xbutton.button == 7)
|
|
|
|
b = x11violations?K_MOUSE5:-1;
|
|
|
|
else if (event.xbutton.button == 8)
|
|
|
|
b = x11violations?K_MOUSE6:-1;
|
|
|
|
else if (event.xbutton.button == 9)
|
|
|
|
b = x11violations?K_MOUSE7:-1;
|
|
|
|
else if (event.xbutton.button == 10)
|
|
|
|
b = x11violations?K_MOUSE8:-1;
|
|
|
|
else if (event.xbutton.button == 11)
|
|
|
|
b = x11violations?K_MOUSE9:-1;
|
|
|
|
else if (event.xbutton.button == 12)
|
|
|
|
b = x11violations?K_MOUSE10:-1;
|
|
|
|
|
2004-08-22 22:29:09 +00:00
|
|
|
if (b>=0)
|
2012-10-14 09:00:49 +00:00
|
|
|
IN_KeyEvent(0, true, b, 0);
|
2005-12-15 19:15:39 +00:00
|
|
|
#ifdef WITH_VMODE
|
2005-11-21 21:07:45 +00:00
|
|
|
if (vidmode_ext && vidmode_usemode>=0)
|
|
|
|
if (!ActiveApp)
|
|
|
|
{ //KDE doesn't seem to like us, in that you can't alt-tab back or click to activate.
|
|
|
|
//This allows us to steal input focus back from the window manager
|
|
|
|
XSetInputFocus(vid_dpy, vid_window, RevertToParent, CurrentTime);
|
|
|
|
}
|
2005-12-15 19:15:39 +00:00
|
|
|
#endif
|
2004-08-22 22:29:09 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ButtonRelease:
|
|
|
|
b=-1;
|
|
|
|
if (event.xbutton.button == 1)
|
2008-02-05 00:38:41 +00:00
|
|
|
b = K_MOUSE1;
|
2004-08-22 22:29:09 +00:00
|
|
|
else if (event.xbutton.button == 2)
|
2008-02-05 00:38:41 +00:00
|
|
|
b = K_MOUSE3;
|
2004-08-22 22:29:09 +00:00
|
|
|
else if (event.xbutton.button == 3)
|
2008-02-05 00:38:41 +00:00
|
|
|
b = K_MOUSE2;
|
|
|
|
//note, the x11 protocol does not support a mousewheel
|
|
|
|
//we only support it because we follow convention. the actual protocol specifies 4+5 as regular buttons
|
2005-11-21 21:07:45 +00:00
|
|
|
else if (event.xbutton.button == 4)
|
2008-02-05 00:38:41 +00:00
|
|
|
b = x11violations?K_MWHEELUP:K_MOUSE4;
|
2005-11-21 21:07:45 +00:00
|
|
|
else if (event.xbutton.button == 5)
|
2008-02-05 00:38:41 +00:00
|
|
|
b = x11violations?K_MWHEELDOWN:K_MOUSE5;
|
|
|
|
//note, the x11 protocol does not support more than 5 mouse buttons
|
|
|
|
//which is a bit of a shame, but hey.
|
|
|
|
else if (event.xbutton.button == 6)
|
|
|
|
b = x11violations?K_MOUSE4:-1;
|
|
|
|
else if (event.xbutton.button == 7)
|
|
|
|
b = x11violations?K_MOUSE5:-1;
|
|
|
|
else if (event.xbutton.button == 8)
|
|
|
|
b = x11violations?K_MOUSE6:-1;
|
|
|
|
else if (event.xbutton.button == 9)
|
|
|
|
b = x11violations?K_MOUSE7:-1;
|
|
|
|
else if (event.xbutton.button == 10)
|
|
|
|
b = x11violations?K_MOUSE8:-1;
|
|
|
|
else if (event.xbutton.button == 11)
|
|
|
|
b = x11violations?K_MOUSE9:-1;
|
|
|
|
else if (event.xbutton.button == 12)
|
|
|
|
b = x11violations?K_MOUSE10:-1;
|
|
|
|
|
2004-08-22 22:29:09 +00:00
|
|
|
if (b>=0)
|
2012-10-14 09:00:49 +00:00
|
|
|
IN_KeyEvent(0, false, b, 0);
|
2004-08-22 22:29:09 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FocusIn:
|
2005-01-24 03:07:16 +00:00
|
|
|
ActiveApp = true;
|
2005-12-15 19:15:39 +00:00
|
|
|
#ifdef WITH_VMODE
|
2005-11-21 21:07:45 +00:00
|
|
|
if (vidmode_ext && vidmode_usemode>=0)
|
|
|
|
{
|
|
|
|
if (!vidmode_active)
|
|
|
|
{
|
|
|
|
// change to the mode
|
|
|
|
XF86VidModeSwitchToMode(vid_dpy, scrnum, vidmodes[vidmode_usemode]);
|
|
|
|
vidmode_active = true;
|
|
|
|
// Move the viewport to top left
|
|
|
|
}
|
|
|
|
XF86VidModeSetViewPort(vid_dpy, scrnum, 0, 0);
|
|
|
|
}
|
2005-12-15 19:15:39 +00:00
|
|
|
#endif
|
2008-02-05 00:38:41 +00:00
|
|
|
Cvar_ForceCallback(&v_gamma);
|
2004-08-22 22:29:09 +00:00
|
|
|
break;
|
|
|
|
case FocusOut:
|
2005-01-24 03:07:16 +00:00
|
|
|
#ifdef WITH_VMODE
|
2005-07-28 15:52:31 +00:00
|
|
|
if (originalapplied)
|
|
|
|
XF86VidModeSetGammaRamp(vid_dpy, scrnum, 256, originalramps[0], originalramps[1], originalramps[2]);
|
2005-11-21 21:07:45 +00:00
|
|
|
|
|
|
|
if (!COM_CheckParm("-stayactive"))
|
|
|
|
{ //a parameter that leaves the program fullscreen if you taskswitch.
|
|
|
|
//sounds pointless, works great with two moniters. :D
|
|
|
|
if (originalapplied)
|
|
|
|
XF86VidModeSetGammaRamp(vid_dpy, scrnum, 256, originalramps[0], originalramps[1], originalramps[2]);
|
|
|
|
if (vidmode_active)
|
|
|
|
{
|
|
|
|
XF86VidModeSwitchToMode(vid_dpy, scrnum, vidmodes[0]);
|
|
|
|
vidmode_active = false;
|
|
|
|
}
|
|
|
|
}
|
2005-01-24 03:07:16 +00:00
|
|
|
#endif
|
2005-11-21 21:07:45 +00:00
|
|
|
|
2005-01-24 03:07:16 +00:00
|
|
|
ActiveApp = false;
|
|
|
|
ClearAllStates();
|
2005-11-21 21:07:45 +00:00
|
|
|
|
2011-01-29 19:53:38 +00:00
|
|
|
break;
|
|
|
|
case ClientMessage:
|
|
|
|
{
|
|
|
|
char *name = XGetAtomName(vid_dpy, event.xclient.message_type);
|
|
|
|
if (!strcmp(name, "WM_PROTOCOLS") && event.xclient.format == 32)
|
|
|
|
{
|
|
|
|
char *protname = XGetAtomName(vid_dpy, event.xclient.data.l[0]);
|
|
|
|
if (!strcmp(protname, "WM_DELETE_WINDOW"))
|
|
|
|
Cmd_ExecuteString("menu_quit", RESTRICT_LOCAL);
|
|
|
|
else
|
|
|
|
Con_Printf("Got message %s\n", protname);
|
|
|
|
XFree(protname);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Con_Printf("Got message %s\n", name);
|
|
|
|
XFree(name);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// Con_Printf("%x\n", event.type);
|
2004-08-22 22:29:09 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
wantwindowed = !!_windowed_mouse.value;
|
2005-01-24 03:07:16 +00:00
|
|
|
if (!ActiveApp)
|
2004-08-22 22:29:09 +00:00
|
|
|
wantwindowed = false;
|
2012-10-14 10:57:11 +00:00
|
|
|
if (Key_MouseShouldBeFree() && !vidglx_fullscreen)
|
2004-08-22 22:29:09 +00:00
|
|
|
wantwindowed = false;
|
|
|
|
|
|
|
|
if (old_windowed_mouse != wantwindowed)
|
|
|
|
{
|
|
|
|
old_windowed_mouse = wantwindowed;
|
|
|
|
|
|
|
|
if (!wantwindowed)
|
|
|
|
{
|
2005-11-21 21:07:45 +00:00
|
|
|
Con_DPrintf("uninstall grabs\n");
|
2004-08-22 22:29:09 +00:00
|
|
|
/* ungrab the pointer */
|
|
|
|
uninstall_grabs();
|
2012-10-14 10:57:11 +00:00
|
|
|
XUndefineCursor(vid_dpy, vid_window);
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-11-21 21:07:45 +00:00
|
|
|
Con_DPrintf("install grabs\n");
|
2004-08-22 22:29:09 +00:00
|
|
|
/* grab the pointer */
|
|
|
|
install_grabs();
|
2012-10-14 10:57:11 +00:00
|
|
|
/*hide the cursor*/
|
|
|
|
XDefineCursor(vid_dpy, vid_window, vid_nullcursor);
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GLVID_Shutdown(void)
|
|
|
|
{
|
2011-02-06 20:56:39 +00:00
|
|
|
#ifdef USE_EGL
|
|
|
|
EGL_Shutdown();
|
|
|
|
#else
|
2005-12-05 21:22:36 +00:00
|
|
|
printf("GLVID_Shutdown\n");
|
2011-09-05 01:48:23 +00:00
|
|
|
if (!vid_dpy)
|
2004-08-22 22:29:09 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
XUngrabKeyboard(vid_dpy, CurrentTime);
|
|
|
|
if (old_windowed_mouse)
|
|
|
|
uninstall_grabs();
|
|
|
|
|
2005-04-18 05:35:23 +00:00
|
|
|
if (ctx)
|
2011-09-05 01:48:23 +00:00
|
|
|
{
|
2005-04-18 05:35:23 +00:00
|
|
|
qglXDestroyContext(vid_dpy, ctx);
|
2011-09-05 01:48:23 +00:00
|
|
|
ctx = NULL;
|
|
|
|
}
|
2005-06-15 04:36:20 +00:00
|
|
|
|
2005-01-24 03:07:16 +00:00
|
|
|
#ifdef WITH_VMODE
|
2005-07-28 15:52:31 +00:00
|
|
|
if (originalapplied)
|
|
|
|
XF86VidModeSetGammaRamp(vid_dpy, scrnum, 256, originalramps[0], originalramps[1], originalramps[2]);
|
2005-01-24 03:07:16 +00:00
|
|
|
#endif
|
|
|
|
|
2004-08-22 22:29:09 +00:00
|
|
|
if (vid_window)
|
|
|
|
XDestroyWindow(vid_dpy, vid_window);
|
2012-10-14 10:57:11 +00:00
|
|
|
if (vid_nullcursor)
|
|
|
|
XFreeCursor(vid_dpy, vid_nullcursor);
|
2004-08-22 22:29:09 +00:00
|
|
|
#ifdef WITH_VMODE
|
|
|
|
if (vid_dpy) {
|
|
|
|
if (vidmode_active)
|
|
|
|
XF86VidModeSwitchToMode(vid_dpy, scrnum, vidmodes[0]);
|
|
|
|
vidmode_active = false;
|
2011-01-30 01:32:30 +00:00
|
|
|
|
|
|
|
if (vidmodes)
|
|
|
|
XFree(vidmodes);
|
|
|
|
vidmodes = NULL;
|
|
|
|
num_vidmodes = 0;
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
#endif
|
2005-12-05 21:22:36 +00:00
|
|
|
XCloseDisplay(vid_dpy);
|
|
|
|
vid_dpy = NULL;
|
2004-08-22 22:29:09 +00:00
|
|
|
vid_window = (Window)NULL;
|
2011-02-06 20:56:39 +00:00
|
|
|
#endif
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GLVID_DeInit(void) //FIXME:....
|
|
|
|
{
|
|
|
|
GLVID_Shutdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void signal_handler(int sig)
|
|
|
|
{
|
|
|
|
printf("Received signal %d, exiting...\n", sig);
|
|
|
|
Sys_Quit();
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void InitSig(void)
|
|
|
|
{
|
|
|
|
signal(SIGHUP, signal_handler);
|
|
|
|
signal(SIGINT, signal_handler);
|
|
|
|
signal(SIGQUIT, signal_handler);
|
|
|
|
signal(SIGILL, signal_handler);
|
|
|
|
signal(SIGTRAP, signal_handler);
|
|
|
|
#ifndef __CYGWIN__
|
|
|
|
signal(SIGIOT, signal_handler);
|
|
|
|
#endif
|
|
|
|
signal(SIGBUS, signal_handler);
|
|
|
|
signal(SIGFPE, signal_handler);
|
|
|
|
signal(SIGSEGV, signal_handler);
|
|
|
|
signal(SIGTERM, signal_handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Cursor CreateNullCursor(Display *display, Window root)
|
|
|
|
{
|
2005-06-15 04:36:20 +00:00
|
|
|
Pixmap cursormask;
|
2004-08-22 22:29:09 +00:00
|
|
|
XGCValues xgc;
|
|
|
|
GC gc;
|
|
|
|
XColor dummycolour;
|
|
|
|
Cursor cursor;
|
|
|
|
|
|
|
|
cursormask = XCreatePixmap(display, root, 1, 1, 1/*depth*/);
|
|
|
|
xgc.function = GXclear;
|
|
|
|
gc = XCreateGC(display, cursormask, GCFunction, &xgc);
|
|
|
|
XFillRectangle(display, cursormask, gc, 0, 0, 1, 1);
|
|
|
|
dummycolour.pixel = 0;
|
|
|
|
dummycolour.red = 0;
|
|
|
|
dummycolour.flags = 04;
|
|
|
|
cursor = XCreatePixmapCursor(display, cursormask, cursormask,
|
|
|
|
&dummycolour,&dummycolour, 0,0);
|
|
|
|
XFreePixmap(display,cursormask);
|
|
|
|
XFreeGC(display,gc);
|
|
|
|
return cursor;
|
|
|
|
}
|
|
|
|
|
2005-01-24 03:07:16 +00:00
|
|
|
void GLVID_ShiftPalette (unsigned char *palette)
|
2004-08-22 22:29:09 +00:00
|
|
|
{
|
2005-01-24 03:07:16 +00:00
|
|
|
#ifdef WITH_VMODE
|
|
|
|
extern qboolean gammaworks;
|
|
|
|
extern cvar_t vid_hardwaregamma;
|
|
|
|
extern unsigned short ramps[3][256];
|
2005-06-15 04:36:20 +00:00
|
|
|
|
2005-01-24 03:07:16 +00:00
|
|
|
// VID_SetPalette (palette);
|
|
|
|
|
2005-07-28 15:52:31 +00:00
|
|
|
if (originalapplied && ActiveApp && vid_hardwaregamma.value) //this is needed because ATI drivers don't work properly (or when task-switched out).
|
2005-01-24 03:07:16 +00:00
|
|
|
{
|
|
|
|
if (gammaworks)
|
|
|
|
{ //we have hardware gamma applied - if we're doing a BF, we don't want to reset to the default gamma (yuck)
|
|
|
|
XF86VidModeSetGammaRamp (vid_dpy, scrnum, 256, ramps[0], ramps[1], ramps[2]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
gammaworks = !!XF86VidModeSetGammaRamp (vid_dpy, scrnum, 256, ramps[0], ramps[1], ramps[2]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
gammaworks = false;
|
|
|
|
#endif
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GLVID_SetPalette (unsigned char *palette)
|
|
|
|
{
|
|
|
|
qbyte *pal;
|
|
|
|
unsigned r,g,b;
|
|
|
|
unsigned short i;
|
|
|
|
unsigned *table;
|
|
|
|
extern qbyte gammatable[256];
|
|
|
|
|
|
|
|
//
|
|
|
|
// 8 8 8 encoding
|
|
|
|
//
|
|
|
|
Con_Printf("Converting 8to24\n");
|
|
|
|
|
|
|
|
pal = palette;
|
|
|
|
table = d_8to24rgbtable;
|
|
|
|
for (i=0 ; i<256 ; i++)
|
|
|
|
{
|
|
|
|
r = gammatable[pal[0]];
|
|
|
|
g = gammatable[pal[1]];
|
|
|
|
b = gammatable[pal[2]];
|
|
|
|
pal += 3;
|
2005-06-15 04:36:20 +00:00
|
|
|
|
2005-12-06 21:52:38 +00:00
|
|
|
*table++ = BigLong((r<<24)|(g<<16)|(b<<8)|255);
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
2005-12-06 21:52:38 +00:00
|
|
|
|
|
|
|
d_8to24rgbtable[255] &= BigLong(0xffffff00); // 255 is transparent
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
GL_BeginRendering
|
|
|
|
|
|
|
|
=================
|
|
|
|
*/
|
2009-11-05 03:07:52 +00:00
|
|
|
void GL_BeginRendering (void)
|
2004-08-22 22:29:09 +00:00
|
|
|
{
|
2011-02-06 20:56:39 +00:00
|
|
|
#ifdef USE_EGL
|
|
|
|
EGL_BeginRendering();
|
|
|
|
#endif
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GL_EndRendering (void)
|
|
|
|
{
|
2011-02-06 20:56:39 +00:00
|
|
|
#ifdef USE_EGL
|
|
|
|
EGL_EndRendering();
|
|
|
|
#else
|
2004-08-22 22:29:09 +00:00
|
|
|
//return;
|
2005-01-07 03:14:10 +00:00
|
|
|
//we don't need the flush, XSawpBuffers does it for us.
|
|
|
|
//chances are, it's version is more suitable anyway. At least there's the chance that it might be.
|
2004-08-22 22:29:09 +00:00
|
|
|
qglXSwapBuffers(vid_dpy, vid_window);
|
2011-02-06 20:56:39 +00:00
|
|
|
#endif
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
qboolean GLVID_Is8bit(void)
|
|
|
|
{
|
|
|
|
return is8bit;
|
|
|
|
}
|
|
|
|
|
|
|
|
qboolean GLVID_Init (rendererstate_t *info, unsigned char *palette)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int attrib[] = {
|
|
|
|
GLX_RGBA,
|
|
|
|
GLX_RED_SIZE, 1,
|
|
|
|
GLX_GREEN_SIZE, 1,
|
|
|
|
GLX_BLUE_SIZE, 1,
|
|
|
|
GLX_DOUBLEBUFFER,
|
|
|
|
GLX_DEPTH_SIZE, 1,
|
2011-01-28 00:40:02 +00:00
|
|
|
GLX_STENCIL_SIZE, 8,
|
2004-08-22 22:29:09 +00:00
|
|
|
None
|
|
|
|
};
|
|
|
|
XSetWindowAttributes attr;
|
|
|
|
unsigned long mask;
|
|
|
|
Window root;
|
2011-02-06 20:56:39 +00:00
|
|
|
#ifdef USE_EGL
|
|
|
|
XVisualInfo vinfodef;
|
|
|
|
#endif
|
2004-08-22 22:29:09 +00:00
|
|
|
XVisualInfo *visinfo;
|
2009-11-04 21:16:50 +00:00
|
|
|
qboolean fullscreen = false;
|
2011-01-29 19:53:38 +00:00
|
|
|
Atom prots[1];
|
2004-08-22 22:29:09 +00:00
|
|
|
|
|
|
|
#ifdef WITH_VMODE
|
2005-11-21 21:07:45 +00:00
|
|
|
int MajorVersion, MinorVersion;
|
2004-08-22 22:29:09 +00:00
|
|
|
|
|
|
|
if (info->fullscreen)
|
|
|
|
fullscreen = true;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
S_Startup();
|
|
|
|
|
2011-02-06 20:56:39 +00:00
|
|
|
#ifdef USE_EGL
|
|
|
|
if (!EGL_LoadLibrary(info->glrenderer))
|
|
|
|
{
|
|
|
|
Con_Printf("couldn't load EGL library\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#else
|
2004-12-22 13:47:57 +00:00
|
|
|
if (!GLX_InitLibrary(info->glrenderer))
|
|
|
|
{
|
|
|
|
Con_Printf("Couldn't intialise GLX\nEither your drivers are not installed or you need to specify the library name with the gl_driver cvar\n");
|
|
|
|
return false;
|
|
|
|
}
|
2011-02-06 20:56:39 +00:00
|
|
|
#endif
|
2005-06-15 04:36:20 +00:00
|
|
|
|
2004-08-22 22:29:09 +00:00
|
|
|
// interpret command-line params
|
|
|
|
|
|
|
|
// set vid parameters
|
|
|
|
if ((i = COM_CheckParm("-conwidth")) != 0)
|
2010-07-11 10:53:13 +00:00
|
|
|
vid.width = Q_atoi(com_argv[i+1]);
|
2004-08-22 22:29:09 +00:00
|
|
|
else
|
2010-07-11 10:53:13 +00:00
|
|
|
vid.width = 640;
|
2004-08-22 22:29:09 +00:00
|
|
|
|
2010-07-11 10:53:13 +00:00
|
|
|
vid.width &= ~7; // make it a multiple of eight
|
2004-08-22 22:29:09 +00:00
|
|
|
|
2010-07-11 10:53:13 +00:00
|
|
|
if (vid.width < 320)
|
|
|
|
vid.width = 320;
|
2004-08-22 22:29:09 +00:00
|
|
|
|
|
|
|
// pick a conheight that matches with correct aspect
|
2010-07-11 10:53:13 +00:00
|
|
|
vid.height = vid.width*3 / 4;
|
2004-08-22 22:29:09 +00:00
|
|
|
|
|
|
|
if ((i = COM_CheckParm("-conheight")) != 0)
|
2010-07-11 10:53:13 +00:00
|
|
|
vid.height = Q_atoi(com_argv[i+1]);
|
|
|
|
if (vid.height < 200)
|
|
|
|
vid.height = 200;
|
2004-08-22 22:29:09 +00:00
|
|
|
if (!vid_dpy)
|
|
|
|
vid_dpy = XOpenDisplay(NULL);
|
|
|
|
if (!vid_dpy)
|
|
|
|
{
|
2007-09-23 15:28:06 +00:00
|
|
|
Con_Printf(CON_ERROR "Error: couldn't open the X display\n");
|
2006-04-15 03:31:23 +00:00
|
|
|
return false;
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
scrnum = DefaultScreen(vid_dpy);
|
|
|
|
root = RootWindow(vid_dpy, scrnum);
|
|
|
|
|
|
|
|
#ifdef WITH_VMODE //find out if it's supported on this pc.
|
|
|
|
MajorVersion = MinorVersion = 0;
|
2005-04-18 05:41:39 +00:00
|
|
|
if (COM_CheckParm("-novmode") || !XF86VidModeQueryVersion(vid_dpy, &MajorVersion, &MinorVersion))
|
2004-08-22 22:29:09 +00:00
|
|
|
{
|
2005-04-18 05:41:39 +00:00
|
|
|
vidmode_ext = 0;
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Con_Printf("Using XF86-VidModeExtension Ver. %d.%d\n", MajorVersion, MinorVersion);
|
2005-04-18 05:41:39 +00:00
|
|
|
vidmode_ext = MajorVersion;
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef WITH_VMODE
|
2005-11-21 21:07:45 +00:00
|
|
|
vidmode_usemode = -1;
|
2004-08-22 22:29:09 +00:00
|
|
|
if (vidmode_ext)
|
|
|
|
{
|
|
|
|
int best_fit, best_dist, dist, x, y;
|
|
|
|
|
|
|
|
XF86VidModeGetAllModeLines(vid_dpy, scrnum, &num_vidmodes, &vidmodes);
|
|
|
|
// Are we going fullscreen? If so, let's change video mode
|
|
|
|
if (fullscreen)
|
|
|
|
{
|
|
|
|
best_dist = 9999999;
|
|
|
|
best_fit = -1;
|
|
|
|
|
|
|
|
for (i = 0; i < num_vidmodes; i++)
|
|
|
|
{
|
|
|
|
if (info->width > vidmodes[i]->hdisplay ||
|
|
|
|
info->height > vidmodes[i]->vdisplay)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
x = info->width - vidmodes[i]->hdisplay;
|
|
|
|
y = info->height - vidmodes[i]->vdisplay;
|
|
|
|
dist = (x * x) + (y * y);
|
|
|
|
if (dist < best_dist)
|
|
|
|
{
|
|
|
|
best_dist = dist;
|
|
|
|
best_fit = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (best_fit != -1 && (!best_dist || COM_CheckParm("-fullscreen")))
|
|
|
|
{
|
|
|
|
// change to the mode
|
2005-11-21 21:07:45 +00:00
|
|
|
XF86VidModeSwitchToMode(vid_dpy, scrnum, vidmodes[vidmode_usemode=best_fit]);
|
2004-08-22 22:29:09 +00:00
|
|
|
vidmode_active = true;
|
|
|
|
// Move the viewport to top left
|
|
|
|
XF86VidModeSetViewPort(vid_dpy, scrnum, 0, 0);
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
fullscreen = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-07-12 18:57:40 +00:00
|
|
|
vidglx_fullscreen = fullscreen;
|
|
|
|
|
2011-02-06 20:56:39 +00:00
|
|
|
#ifdef USE_EGL
|
|
|
|
visinfo = &vinfodef;
|
|
|
|
if (!XMatchVisualInfo(vid_dpy, scrnum, info->bpp, TrueColor, visinfo))
|
|
|
|
// if (!XMatchVisualInfo(vid_dpy, scrnum, DefaultDepth(vid_dpy, scrnum), TrueColor, &visinfo))
|
|
|
|
{
|
|
|
|
Sys_Error("Couldn't choose visual for EGL\n");
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
visinfo = qglXChooseVisual(vid_dpy, scrnum, attrib);
|
|
|
|
if (!visinfo)
|
|
|
|
{
|
|
|
|
Sys_Error("qkHack: Error couldn't get an RGB, Double-buffered, Depth visual\n");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-08-22 22:29:09 +00:00
|
|
|
/* window attributes */
|
|
|
|
attr.background_pixel = 0;
|
|
|
|
attr.border_pixel = 0;
|
|
|
|
attr.colormap = XCreateColormap(vid_dpy, root, visinfo->visual, AllocNone);
|
|
|
|
attr.event_mask = X_MASK;
|
|
|
|
mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
|
|
|
|
|
|
|
|
#ifdef WITH_VMODE //get rid of borders
|
|
|
|
// fullscreen
|
|
|
|
if (vidmode_active) {
|
2005-06-15 04:36:20 +00:00
|
|
|
mask = CWBackPixel | CWColormap | CWSaveUnder | CWBackingStore |
|
2004-08-22 22:29:09 +00:00
|
|
|
CWEventMask | CWOverrideRedirect;
|
|
|
|
attr.override_redirect = True;
|
|
|
|
attr.backing_store = NotUseful;
|
|
|
|
attr.save_under = False;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
vid_window = XCreateWindow(vid_dpy, root, 0, 0, info->width, info->height,
|
|
|
|
0, visinfo->depth, InputOutput,
|
|
|
|
visinfo->visual, mask, &attr);
|
2011-02-06 20:56:39 +00:00
|
|
|
|
|
|
|
ActiveApp = false;
|
2011-01-29 19:53:38 +00:00
|
|
|
/*ask the window manager to stop triggering bugs in Xlib*/
|
|
|
|
prots[0] = XInternAtom(vid_dpy, "WM_DELETE_WINDOW", False);
|
|
|
|
XSetWMProtocols(vid_dpy, vid_window, prots, sizeof(prots)/sizeof(prots[0]));
|
|
|
|
/*set caption*/
|
------------------------------------------------------------------------
r4169 | acceptthis | 2013-01-17 08:55:12 +0000 (Thu, 17 Jan 2013) | 31 lines
removed MAX_VISEDICTS limit.
PEXT2_REPLACEMENTDELTAS tweaked, now has 4 million entity limit. still not enabled by default.
TE_BEAM now maps to a separate TEQW_BEAM to avoid conflicts with QW.
added android multitouch emulation for windows/rawinput (in_simulatemultitouch).
split topcolor/bottomcolor from scoreboard, for dp's colormap|1024 feature.
now using utf-8 for windows consoles.
qcc warnings/errors now give clickable console links for quick+easy editing.
disabled menutint when the currently active item changes contrast or gamma (for OneManClan).
Added support for drawfont/drawfontscale.
tweaked the qcvm a little to reduce the number of pointers.
.doll file loading. still experimental and will likely crash. requires csqc active, even if its a dummy progs. this will be fixed in time. Still other things that need cleaning up.
windows: gl_font "?" shows the standard windows font-selection dialog, and can be used to select windows fonts. not all work. and you probably don't want to use windings.
fixed splitscreen support when playing mvds. added mini-scoreboards to splitscreen.
editor/debugger now shows asm if there's no linenumber info. also, pressing f1 for help shows the shortcuts.
Added support for .framegroups files for psk(psa) and iqm formats.
True support for ezquake's colour codes. Mutually exclusive with background colours.
path command output slightly more readable.
added support for digest_hex (MD4, SHA1, CRC16).
skingroups now colourmap correctly.
Fix terrain colour hints, and litdata from the wrong bsp.
fix ftp dual-homed issue. support epsv command, and enable ipv6 (eprt still not supported).
remove d3d11 compilation from the makefile. the required headers are not provided by mingw, and are not available to the build bot, so don't bother.
fix v *= v.x and similar opcodes.
fteqcc: fixed support for áéÃóú type chars in names. utf-8 files now properly supported (even with the utf-8 bom/identifier). utf-16 also supported.
fteqcc: fixed '#if 1 == 3 && 4' parsing.
fteqcc: -Werror acts on the warning, rather than as a separate error. Line numbers are thus more readable.
fteqcc: copyright message now includes compile date instead.
fteqccgui: the treeview control is now coloured depending on whether there were warnings/errors in the last compile.
fteqccgui: the output window is now focused and scrolls down as compilation progresses.
pr_dumpplatform command dumps out some pragmas to convert more serious warnings to errors. This is to avoid the infamous 'fteqcc sucks cos my code sucks' issue.
rewrote prespawn/modelist/soundlist code. server tracks progress now.
------------------------------------------------------------------------
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4167 fc73d0e0-1445-4013-8a0c-d673dee63da5
2013-03-12 22:29:40 +00:00
|
|
|
XStoreName(vid_dpy, vid_window, FULLENGINENAME);
|
2011-01-29 19:53:38 +00:00
|
|
|
/*make it visibl*/
|
2004-08-22 22:29:09 +00:00
|
|
|
XMapWindow(vid_dpy, vid_window);
|
2011-01-29 19:53:38 +00:00
|
|
|
/*put it somewhere*/
|
2004-08-22 22:29:09 +00:00
|
|
|
XMoveWindow(vid_dpy, vid_window, 0, 0);
|
2011-02-06 20:56:39 +00:00
|
|
|
|
2011-01-30 01:32:30 +00:00
|
|
|
//XFree(visinfo);
|
2011-01-29 19:53:38 +00:00
|
|
|
|
2004-08-22 22:29:09 +00:00
|
|
|
#ifdef WITH_VMODE
|
|
|
|
if (vidmode_active) {
|
|
|
|
XRaiseWindow(vid_dpy, vid_window);
|
|
|
|
XWarpPointer(vid_dpy, None, vid_window, 0, 0, 0, 0, 0, 0);
|
|
|
|
XFlush(vid_dpy);
|
|
|
|
// Move the viewport to top left
|
|
|
|
XF86VidModeSetViewPort(vid_dpy, scrnum, 0, 0);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-10-14 10:57:11 +00:00
|
|
|
vid_nullcursor = CreateNullCursor(vid_dpy, vid_window);
|
2004-08-22 22:29:09 +00:00
|
|
|
|
|
|
|
XFlush(vid_dpy);
|
2005-06-15 04:36:20 +00:00
|
|
|
|
2011-02-06 20:56:39 +00:00
|
|
|
#ifndef USE_EGL
|
2005-01-24 03:07:16 +00:00
|
|
|
#ifdef WITH_VMODE
|
2005-04-18 05:41:39 +00:00
|
|
|
if (vidmode_ext >= 2)
|
|
|
|
{
|
|
|
|
int rampsize = 256;
|
|
|
|
XF86VidModeGetGammaRampSize(vid_dpy, scrnum, &rampsize);
|
|
|
|
if (rampsize != 256)
|
|
|
|
{
|
2005-07-28 15:52:31 +00:00
|
|
|
originalapplied = false;
|
2007-10-29 06:06:20 +00:00
|
|
|
Con_Printf("Gamma ramps are not of 256 components (but %i).\n", rampsize);
|
2005-04-18 05:41:39 +00:00
|
|
|
}
|
|
|
|
else
|
2005-07-28 15:52:31 +00:00
|
|
|
originalapplied = XF86VidModeGetGammaRamp(vid_dpy, scrnum, 256, originalramps[0], originalramps[1], originalramps[2]);
|
2005-04-18 05:41:39 +00:00
|
|
|
}
|
|
|
|
else
|
2005-07-28 15:52:31 +00:00
|
|
|
originalapplied = false;
|
2005-01-24 03:07:16 +00:00
|
|
|
#endif
|
2004-08-22 22:29:09 +00:00
|
|
|
|
|
|
|
ctx = qglXCreateContext(vid_dpy, visinfo, NULL, True);
|
2005-04-18 05:35:23 +00:00
|
|
|
if (!ctx)
|
|
|
|
{
|
|
|
|
Con_Printf("Failed to create GLX context.\n");
|
|
|
|
GLVID_Shutdown();
|
|
|
|
return false;
|
|
|
|
}
|
2004-08-22 22:29:09 +00:00
|
|
|
|
2005-04-19 19:31:15 +00:00
|
|
|
if (!qglXMakeCurrent(vid_dpy, vid_window, ctx))
|
|
|
|
{
|
|
|
|
Con_Printf("glXMakeCurrent failed\n");
|
|
|
|
GLVID_Shutdown();
|
|
|
|
return false;
|
|
|
|
}
|
2004-08-22 22:29:09 +00:00
|
|
|
|
2011-02-06 20:56:39 +00:00
|
|
|
GL_Init(&GLX_GetSymbol);
|
|
|
|
|
|
|
|
#else
|
|
|
|
EGL_Init(info, palette, vid_window);
|
|
|
|
GL_Init(&EGL_Proc);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
GLVID_SetPalette(palette);
|
|
|
|
GLVID_ShiftPalette(palette);
|
|
|
|
|
2011-12-05 15:23:40 +00:00
|
|
|
qglGetIntegerv(GL_STENCIL_BITS, &gl_stencilbits);
|
2011-02-06 20:56:39 +00:00
|
|
|
|
|
|
|
InitSig(); // trap evil signals
|
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
vid.pixelwidth = info->width;
|
|
|
|
vid.pixelheight = info->height;
|
2004-08-22 22:29:09 +00:00
|
|
|
|
2010-07-11 10:53:13 +00:00
|
|
|
if (vid.height > info->height)
|
|
|
|
vid.height = info->height;
|
|
|
|
if (vid.width > info->width)
|
|
|
|
vid.width = info->width;
|
2004-08-22 22:29:09 +00:00
|
|
|
|
|
|
|
vid.numpages = 2;
|
|
|
|
|
|
|
|
Con_SafePrintf ("Video mode %dx%d initialized.\n", info->width, info->height);
|
|
|
|
|
|
|
|
vid.recalc_refdef = 1; // force a surface cache flush
|
|
|
|
|
|
|
|
if (Cvar_Get("vidx_grabkeyboard", "0", 0, "Additional video options")->value)
|
2012-10-14 10:57:11 +00:00
|
|
|
XGrabKeyboard(vid_dpy, vid_window,
|
2004-08-22 22:29:09 +00:00
|
|
|
False,
|
|
|
|
GrabModeAsync, GrabModeAsync,
|
|
|
|
CurrentTime);
|
|
|
|
else
|
|
|
|
XSetInputFocus(vid_dpy, vid_window, RevertToParent, CurrentTime);
|
|
|
|
XRaiseWindow(vid_dpy, vid_window);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sys_SendKeyEvents(void)
|
|
|
|
{
|
|
|
|
if (vid_dpy && vid_window) {
|
2005-06-15 04:36:20 +00:00
|
|
|
while (XPending(vid_dpy))
|
2004-08-22 22:29:09 +00:00
|
|
|
GetEvent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Force_CenterView_f (void)
|
|
|
|
{
|
2012-07-06 21:34:23 +00:00
|
|
|
cl.playerview[0].viewangles[PITCH] = 0;
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
|
2006-05-10 22:12:20 +00:00
|
|
|
|
2012-10-14 09:00:49 +00:00
|
|
|
//these are done from the x11 event handler. we don't support evdev.
|
|
|
|
void INS_Move(float *movements, int pnum)
|
2004-08-22 22:29:09 +00:00
|
|
|
{
|
|
|
|
}
|
2012-10-14 09:00:49 +00:00
|
|
|
void INS_Commands(void)
|
2004-08-22 22:29:09 +00:00
|
|
|
{
|
|
|
|
}
|
2012-10-14 09:00:49 +00:00
|
|
|
void INS_Init(void)
|
2004-08-22 22:29:09 +00:00
|
|
|
{
|
|
|
|
}
|
2012-10-14 09:00:49 +00:00
|
|
|
void INS_ReInit(void)
|
2004-08-22 22:29:09 +00:00
|
|
|
{
|
|
|
|
}
|
2012-10-14 09:00:49 +00:00
|
|
|
void INS_Shutdown(void)
|
2004-08-22 22:29:09 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2004-11-29 05:52:57 +00:00
|
|
|
void GL_DoSwap(void) {}
|
2007-03-28 12:57:05 +00:00
|
|
|
|
|
|
|
void GLVID_SetCaption(char *text)
|
|
|
|
{
|
|
|
|
XStoreName(vid_dpy, vid_window, text);
|
|
|
|
}
|
|
|
|
|