2000-05-23 06:36:33 +00:00
|
|
|
/*
|
|
|
|
context_x11.c
|
|
|
|
|
|
|
|
general x11 context layer
|
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
Copyright (C) 2000 Zephaniah E. Hull <warp@whitestar.soark.net>
|
|
|
|
Copyright (C) 1999,2000 contributors of the QuakeForge project
|
|
|
|
Please see the file "AUTHORS" for a list of contributors
|
|
|
|
|
|
|
|
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
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
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:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
$Id$
|
|
|
|
*/
|
|
|
|
|
2001-02-07 05:45:59 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2000-12-08 06:51:37 +00:00
|
|
|
# include "config.h"
|
2001-02-07 05:45:59 +00:00
|
|
|
#endif
|
2000-05-23 06:36:33 +00:00
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/types.h>
|
2001-02-07 05:45:59 +00:00
|
|
|
|
2000-05-23 06:36:33 +00:00
|
|
|
#ifdef HAVE_UNISTD_H
|
2001-02-07 05:45:59 +00:00
|
|
|
# include <unistd.h>
|
2000-05-23 06:36:33 +00:00
|
|
|
#endif
|
2001-02-07 05:45:59 +00:00
|
|
|
|
2000-05-23 06:36:33 +00:00
|
|
|
#include <signal.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/ipc.h>
|
|
|
|
#include <sys/shm.h>
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/Xutil.h>
|
|
|
|
#include <X11/Xatom.h>
|
|
|
|
#include <X11/keysym.h>
|
|
|
|
#include <X11/extensions/XShm.h>
|
|
|
|
#include <errno.h>
|
2000-10-10 22:00:35 +00:00
|
|
|
#include <limits.h>
|
2000-10-22 07:14:47 +00:00
|
|
|
#include <sys/poll.h>
|
2000-05-23 06:36:33 +00:00
|
|
|
|
2000-09-24 03:43:06 +00:00
|
|
|
#ifdef HAVE_VIDMODE
|
|
|
|
# include <X11/extensions/xf86vmode.h>
|
|
|
|
#endif
|
|
|
|
|
2000-12-30 02:16:36 +00:00
|
|
|
#include "console.h"
|
2000-09-24 03:43:06 +00:00
|
|
|
#include "context_x11.h"
|
2000-12-30 02:16:36 +00:00
|
|
|
#include "cvar.h"
|
2000-09-24 03:43:06 +00:00
|
|
|
#include "dga_check.h"
|
2000-12-30 02:16:36 +00:00
|
|
|
#include "input.h"
|
2000-10-11 09:54:27 +00:00
|
|
|
#include "qargs.h"
|
2000-09-24 03:43:06 +00:00
|
|
|
#include "qtypes.h"
|
|
|
|
#include "sys.h"
|
2000-12-30 02:16:36 +00:00
|
|
|
#include "va.h"
|
|
|
|
#include "vid.h"
|
2000-05-23 06:36:33 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
static void (*event_handlers[LASTEvent]) (XEvent *);
|
2001-04-23 03:52:20 +00:00
|
|
|
qboolean oktodraw = false;
|
|
|
|
int x_shmeventtype;
|
2000-05-23 06:36:33 +00:00
|
|
|
|
2001-04-23 03:52:20 +00:00
|
|
|
static int x_disp_ref_count = 0;
|
2000-05-23 06:36:33 +00:00
|
|
|
|
2001-04-23 03:52:20 +00:00
|
|
|
Display *x_disp = NULL;
|
|
|
|
int x_screen;
|
|
|
|
Window x_root = None;
|
2000-12-08 06:51:37 +00:00
|
|
|
XVisualInfo *x_visinfo;
|
2001-04-23 03:52:20 +00:00
|
|
|
Visual *x_vis;
|
|
|
|
Window x_win;
|
|
|
|
Cursor nullcursor = None;
|
2000-09-24 03:43:06 +00:00
|
|
|
static Atom aWMDelete = 0;
|
|
|
|
|
|
|
|
#define X_MASK (VisibilityChangeMask | StructureNotifyMask | ExposureMask)
|
|
|
|
|
|
|
|
#ifdef HAVE_VIDMODE
|
|
|
|
static XF86VidModeModeInfo **vidmodes;
|
2001-04-23 03:52:20 +00:00
|
|
|
static int nummodes;
|
2001-02-14 02:36:27 +00:00
|
|
|
static int original_mode = 0;
|
2000-09-24 03:43:06 +00:00
|
|
|
#endif
|
2001-02-09 22:36:30 +00:00
|
|
|
|
2001-02-09 21:50:42 +00:00
|
|
|
static qboolean vidmode_avail = false;
|
|
|
|
static qboolean vidmode_active = false;
|
2000-09-24 03:43:06 +00:00
|
|
|
|
2001-04-23 03:52:20 +00:00
|
|
|
cvar_t *vid_fullscreen;
|
|
|
|
cvar_t *vid_system_gamma;
|
|
|
|
qboolean vid_gamma_avail;
|
|
|
|
qboolean vid_fullscreen_active;
|
|
|
|
static double x_gamma;
|
2000-09-24 03:43:06 +00:00
|
|
|
|
2001-04-23 03:52:20 +00:00
|
|
|
static int xss_timeout;
|
|
|
|
static int xss_interval;
|
|
|
|
static int xss_blanking;
|
|
|
|
static int xss_exposures;
|
2000-05-23 06:36:33 +00:00
|
|
|
|
|
|
|
qboolean
|
2001-04-23 03:52:20 +00:00
|
|
|
X11_AddEvent (int event, void (*event_handler) (XEvent *))
|
2000-05-23 06:36:33 +00:00
|
|
|
{
|
|
|
|
if (event >= LASTEvent) {
|
2000-12-08 06:51:37 +00:00
|
|
|
printf ("event: %d, LASTEvent: %d\n", event, LASTEvent);
|
2000-05-23 06:36:33 +00:00
|
|
|
return false;
|
|
|
|
}
|
2001-04-23 03:52:20 +00:00
|
|
|
|
|
|
|
if (event_handlers[event])
|
2000-05-23 06:36:33 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
event_handlers[event] = event_handler;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
qboolean
|
2001-04-23 03:52:20 +00:00
|
|
|
X11_RemoveEvent (int event, void (*event_handler) (XEvent *))
|
2000-05-23 06:36:33 +00:00
|
|
|
{
|
|
|
|
if (event >= LASTEvent)
|
|
|
|
return false;
|
2001-04-23 03:52:20 +00:00
|
|
|
|
2000-05-23 06:36:33 +00:00
|
|
|
if (event_handlers[event] != event_handler)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
event_handlers[event] = NULL;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-04-23 03:52:20 +00:00
|
|
|
X11_ProcessEvent (void)
|
2000-05-23 06:36:33 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
XEvent x_event;
|
2000-05-23 06:36:33 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
XNextEvent (x_disp, &x_event);
|
|
|
|
if (x_event.type >= LASTEvent) {
|
2000-05-23 06:36:33 +00:00
|
|
|
// FIXME: KLUGE!!!!!!
|
|
|
|
if (x_event.type == x_shmeventtype)
|
|
|
|
oktodraw = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (event_handlers[x_event.type])
|
2000-10-11 09:54:27 +00:00
|
|
|
event_handlers[x_event.type] (&x_event);
|
2000-05-23 06:36:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-04-23 03:52:20 +00:00
|
|
|
X11_ProcessEvents (void)
|
2000-05-23 06:36:33 +00:00
|
|
|
{
|
|
|
|
/* Get events from X server. */
|
2000-10-11 09:54:27 +00:00
|
|
|
while (XPending (x_disp)) {
|
2001-04-23 03:52:20 +00:00
|
|
|
X11_ProcessEvent ();
|
2000-05-23 06:36:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ========================================================================
|
|
|
|
// Tragic death handler
|
|
|
|
// ========================================================================
|
|
|
|
|
|
|
|
static void
|
2000-10-11 09:54:27 +00:00
|
|
|
TragicDeath (int sig)
|
2000-05-23 06:36:33 +00:00
|
|
|
{
|
2000-10-11 09:54:27 +00:00
|
|
|
printf ("Received signal %d, exiting...\n", sig);
|
|
|
|
Sys_Quit ();
|
|
|
|
exit (sig);
|
2000-12-08 06:51:37 +00:00
|
|
|
// XCloseDisplay(x_disp);
|
|
|
|
// VID_Shutdown();
|
|
|
|
// Sys_Error("This death brought to you by the number %d\n", signal_num);
|
2000-05-23 06:36:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-04-23 03:52:20 +00:00
|
|
|
X11_OpenDisplay (void)
|
2000-05-23 06:36:33 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
if (!x_disp) {
|
2000-11-21 09:17:29 +00:00
|
|
|
x_disp = XOpenDisplay (NULL);
|
2000-12-08 06:51:37 +00:00
|
|
|
if (!x_disp) {
|
2001-04-23 03:52:20 +00:00
|
|
|
Sys_Error ("X11_OpenDisplay: Could not open display [%s]\n",
|
2000-12-08 06:51:37 +00:00
|
|
|
XDisplayName (NULL));
|
2000-05-23 06:36:33 +00:00
|
|
|
}
|
|
|
|
|
2000-09-24 03:43:06 +00:00
|
|
|
x_screen = DefaultScreen (x_disp);
|
|
|
|
x_root = RootWindow (x_disp, x_screen);
|
|
|
|
|
2000-05-23 06:36:33 +00:00
|
|
|
// catch signals
|
2000-12-08 06:51:37 +00:00
|
|
|
signal (SIGHUP, TragicDeath);
|
|
|
|
signal (SIGINT, TragicDeath);
|
|
|
|
signal (SIGQUIT, TragicDeath);
|
|
|
|
signal (SIGILL, TragicDeath);
|
|
|
|
signal (SIGTRAP, TragicDeath);
|
|
|
|
signal (SIGIOT, TragicDeath);
|
|
|
|
signal (SIGBUS, TragicDeath);
|
2001-04-23 03:52:20 +00:00
|
|
|
// signal(SIGFPE, TragicDeath);
|
2000-12-08 06:51:37 +00:00
|
|
|
signal (SIGSEGV, TragicDeath);
|
|
|
|
signal (SIGTERM, TragicDeath);
|
2000-05-23 06:36:33 +00:00
|
|
|
|
|
|
|
// for debugging only
|
2000-12-08 06:51:37 +00:00
|
|
|
XSynchronize (x_disp, True);
|
2000-05-23 06:36:33 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
x_disp_ref_count = 1;
|
2000-05-23 06:36:33 +00:00
|
|
|
} else {
|
|
|
|
x_disp_ref_count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-04-23 03:52:20 +00:00
|
|
|
X11_CloseDisplay (void)
|
2000-05-23 06:36:33 +00:00
|
|
|
{
|
2000-09-24 03:43:06 +00:00
|
|
|
if (nullcursor != None) {
|
2000-11-21 09:17:29 +00:00
|
|
|
XFreeCursor (x_disp, nullcursor);
|
2000-09-24 03:43:06 +00:00
|
|
|
nullcursor = None;
|
|
|
|
}
|
2000-11-21 09:17:29 +00:00
|
|
|
|
2000-05-23 06:36:33 +00:00
|
|
|
if (!--x_disp_ref_count) {
|
2000-11-21 09:17:29 +00:00
|
|
|
XCloseDisplay (x_disp);
|
2000-10-29 07:58:43 +00:00
|
|
|
x_disp = 0;
|
2000-05-23 06:36:33 +00:00
|
|
|
}
|
|
|
|
}
|
2000-09-24 03:43:06 +00:00
|
|
|
|
|
|
|
/*
|
2001-04-23 03:52:20 +00:00
|
|
|
X11_CreateNullCursor
|
2000-09-24 03:43:06 +00:00
|
|
|
|
2001-04-23 03:52:20 +00:00
|
|
|
Create an empty cursor (in other words, make it disappear)
|
2000-09-24 03:43:06 +00:00
|
|
|
*/
|
|
|
|
void
|
2001-04-23 03:52:20 +00:00
|
|
|
X11_CreateNullCursor (void)
|
2000-09-24 03:43:06 +00:00
|
|
|
{
|
2001-04-23 03:52:20 +00:00
|
|
|
Pixmap cursormask;
|
|
|
|
XGCValues xgc;
|
|
|
|
GC gc;
|
|
|
|
XColor dummycolour;
|
2000-09-24 03:43:06 +00:00
|
|
|
|
2000-11-21 09:17:29 +00:00
|
|
|
if (nullcursor != None)
|
|
|
|
return;
|
2000-09-24 03:43:06 +00:00
|
|
|
|
2000-11-21 09:17:29 +00:00
|
|
|
cursormask = XCreatePixmap (x_disp, x_root, 1, 1, 1);
|
2000-09-24 03:43:06 +00:00
|
|
|
xgc.function = GXclear;
|
2000-12-08 06:51:37 +00:00
|
|
|
|
|
|
|
gc = XCreateGC (x_disp, cursormask, GCFunction, &xgc);
|
|
|
|
|
2000-11-21 09:17:29 +00:00
|
|
|
XFillRectangle (x_disp, cursormask, gc, 0, 0, 1, 1);
|
2000-12-08 06:51:37 +00:00
|
|
|
|
2000-09-24 03:43:06 +00:00
|
|
|
dummycolour.pixel = 0;
|
|
|
|
dummycolour.red = 0;
|
|
|
|
dummycolour.flags = 04;
|
2000-11-21 09:17:29 +00:00
|
|
|
nullcursor = XCreatePixmapCursor (x_disp, cursormask, cursormask,
|
2000-12-08 06:51:37 +00:00
|
|
|
&dummycolour, &dummycolour, 0, 0);
|
|
|
|
XFreePixmap (x_disp, cursormask);
|
|
|
|
XFreeGC (x_disp, gc);
|
2000-11-21 09:17:29 +00:00
|
|
|
XDefineCursor (x_disp, x_win, nullcursor);
|
2000-09-24 03:43:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-04-23 03:52:20 +00:00
|
|
|
X11_SetVidMode (int width, int height)
|
2000-09-24 03:43:06 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
const char *str = getenv ("MESA_GLX_FX");
|
|
|
|
|
2001-02-09 21:50:42 +00:00
|
|
|
if (str && (tolower (*str) == 'f')) {
|
|
|
|
Cvar_Set (vid_fullscreen, "1");
|
2000-09-24 03:43:06 +00:00
|
|
|
}
|
2000-11-17 21:23:26 +00:00
|
|
|
|
|
|
|
XGetScreenSaver (x_disp, &xss_timeout, &xss_interval, &xss_blanking,
|
2000-12-08 06:51:37 +00:00
|
|
|
&xss_exposures);
|
2000-09-24 03:43:06 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_VIDMODE
|
2001-02-09 21:50:42 +00:00
|
|
|
vidmode_avail = VID_CheckVMode (x_disp, NULL, NULL);
|
2000-09-24 03:43:06 +00:00
|
|
|
|
2001-04-23 03:52:20 +00:00
|
|
|
if (vidmode_avail) {
|
|
|
|
vid_gamma_avail = ((x_gamma = X11_GetGamma ()) > 0);
|
|
|
|
}
|
|
|
|
|
2001-02-09 21:50:42 +00:00
|
|
|
if (vid_fullscreen->int_val && vidmode_avail) {
|
|
|
|
|
2001-02-14 02:49:37 +00:00
|
|
|
int i, dotclock;
|
2001-02-14 02:36:27 +00:00
|
|
|
int best_mode = 0;
|
|
|
|
qboolean found_mode = false;
|
|
|
|
XF86VidModeModeLine orig_data;
|
2000-11-17 21:23:26 +00:00
|
|
|
|
2001-02-09 22:36:30 +00:00
|
|
|
XF86VidModeGetAllModeLines (x_disp, x_screen, &nummodes, &vidmodes);
|
2001-02-14 02:49:37 +00:00
|
|
|
XF86VidModeGetModeLine (x_disp, x_screen, &dotclock, &orig_data);
|
2001-02-11 16:05:52 +00:00
|
|
|
|
2001-02-09 22:36:30 +00:00
|
|
|
for (i = 0; i < nummodes; i++) {
|
2001-02-14 02:36:27 +00:00
|
|
|
if ((vidmodes[i]->hdisplay == orig_data.hdisplay) &&
|
|
|
|
(vidmodes[i]->vdisplay == orig_data.vdisplay)) {
|
2001-02-09 22:36:30 +00:00
|
|
|
original_mode = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-10-24 18:10:01 +00:00
|
|
|
for (i = 0; i < nummodes; i++) {
|
2001-02-09 21:50:42 +00:00
|
|
|
if ((vidmodes[i]->hdisplay == vid.width) &&
|
|
|
|
(vidmodes[i]->vdisplay == vid.height)) {
|
|
|
|
found_mode = true;
|
|
|
|
best_mode = i;
|
|
|
|
break;
|
2000-09-24 03:43:06 +00:00
|
|
|
}
|
|
|
|
}
|
2001-02-09 21:50:42 +00:00
|
|
|
|
|
|
|
if (found_mode) {
|
|
|
|
Con_Printf ("VID: Chose video mode: %dx%d\n", vid.width, vid.height);
|
|
|
|
|
|
|
|
XSetScreenSaver (x_disp, 0, xss_interval, xss_blanking, xss_exposures);
|
|
|
|
XF86VidModeSwitchToMode (x_disp, x_screen, vidmodes[best_mode]);
|
2001-04-23 03:52:20 +00:00
|
|
|
X11_ForceViewPort ();
|
2001-02-09 21:50:42 +00:00
|
|
|
vidmode_active = true;
|
|
|
|
} else {
|
|
|
|
Con_Printf ("VID: Mode %dx%d can't go fullscreen.\n", vid.width, vid.height);
|
2001-04-23 03:52:20 +00:00
|
|
|
vid_gamma_avail = vidmode_avail = vidmode_active = false;
|
2001-02-09 21:50:42 +00:00
|
|
|
}
|
2000-10-24 18:10:01 +00:00
|
|
|
}
|
2000-09-24 03:43:06 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2000-10-29 15:35:24 +00:00
|
|
|
void
|
2001-04-23 03:52:20 +00:00
|
|
|
X11_Init_Cvars (void)
|
2000-10-29 15:35:24 +00:00
|
|
|
{
|
2000-10-31 04:16:20 +00:00
|
|
|
vid_fullscreen = Cvar_Get ("vid_fullscreen", "0", CVAR_ROM,
|
|
|
|
"Toggles fullscreen game mode");
|
2001-04-23 03:52:20 +00:00
|
|
|
vid_system_gamma = Cvar_Get ("vid_system_gamma", "1", CVAR_ARCHIVE,
|
|
|
|
"Use system gamma control if available");
|
2000-10-29 15:35:24 +00:00
|
|
|
}
|
|
|
|
|
2000-09-24 03:43:06 +00:00
|
|
|
void
|
2001-04-23 03:52:20 +00:00
|
|
|
X11_CreateWindow (int width, int height)
|
2000-09-24 03:43:06 +00:00
|
|
|
{
|
|
|
|
XSetWindowAttributes attr;
|
2000-12-08 06:51:37 +00:00
|
|
|
XClassHint *ClassHint;
|
|
|
|
XSizeHints *SizeHints;
|
|
|
|
char *resname;
|
|
|
|
unsigned long mask;
|
2000-09-24 03:43:06 +00:00
|
|
|
|
|
|
|
/* window attributes */
|
|
|
|
attr.background_pixel = 0;
|
|
|
|
attr.border_pixel = 0;
|
2000-12-08 06:51:37 +00:00
|
|
|
attr.colormap = XCreateColormap (x_disp, x_root, x_vis, AllocNone);
|
2000-09-24 03:43:06 +00:00
|
|
|
attr.event_mask = X_MASK;
|
|
|
|
mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
|
|
|
|
|
2001-02-09 21:50:42 +00:00
|
|
|
if (vidmode_active && vid_fullscreen->int_val) {
|
2000-12-08 06:51:37 +00:00
|
|
|
attr.override_redirect = 1;
|
|
|
|
mask |= CWOverrideRedirect;
|
2000-09-24 03:43:06 +00:00
|
|
|
}
|
|
|
|
|
2000-10-11 09:54:27 +00:00
|
|
|
x_win = XCreateWindow (x_disp, x_root, 0, 0, width, height,
|
2000-12-08 06:51:37 +00:00
|
|
|
0, x_visinfo->depth, InputOutput,
|
|
|
|
x_vis, mask, &attr);
|
2000-10-11 09:54:27 +00:00
|
|
|
|
|
|
|
// Set window size hints
|
|
|
|
SizeHints = XAllocSizeHints ();
|
|
|
|
if (SizeHints) {
|
|
|
|
SizeHints->flags = (PMinSize | PMaxSize);
|
|
|
|
SizeHints->min_width = width;
|
|
|
|
SizeHints->min_height = height;
|
|
|
|
SizeHints->max_width = width;
|
|
|
|
SizeHints->max_height = height;
|
|
|
|
XSetWMNormalHints (x_disp, x_win, SizeHints);
|
|
|
|
|
|
|
|
XFree (SizeHints);
|
|
|
|
}
|
2000-10-03 07:10:48 +00:00
|
|
|
// Set window title
|
2001-04-23 03:52:20 +00:00
|
|
|
X11_SetCaption (va ("%s %s", PROGRAM, VERSION));
|
2000-10-11 09:54:27 +00:00
|
|
|
|
2000-10-03 07:10:48 +00:00
|
|
|
// Set icon name
|
|
|
|
XSetIconName (x_disp, x_win, PROGRAM);
|
2000-09-24 03:43:06 +00:00
|
|
|
|
2000-10-11 09:54:27 +00:00
|
|
|
// Set window class
|
|
|
|
ClassHint = XAllocClassHint ();
|
|
|
|
if (ClassHint) {
|
|
|
|
resname = strrchr (com_argv[0], '/');
|
|
|
|
|
2000-11-09 00:56:43 +00:00
|
|
|
ClassHint->res_name = (resname ? resname + 1 : com_argv[0]);
|
|
|
|
ClassHint->res_class = PACKAGE;
|
2000-10-11 09:54:27 +00:00
|
|
|
XSetClassHint (x_disp, x_win, ClassHint);
|
|
|
|
XFree (ClassHint);
|
|
|
|
}
|
|
|
|
// Make window respond to Delete events
|
|
|
|
aWMDelete = XInternAtom (x_disp, "WM_DELETE_WINDOW", False);
|
|
|
|
XSetWMProtocols (x_disp, x_win, &aWMDelete, 1);
|
2000-12-08 06:51:37 +00:00
|
|
|
|
2001-02-10 05:08:25 +00:00
|
|
|
if (vidmode_active && vid_fullscreen->int_val) {
|
2000-10-24 18:10:01 +00:00
|
|
|
XMoveWindow (x_disp, x_win, 0, 0);
|
2000-11-21 09:17:29 +00:00
|
|
|
XWarpPointer (x_disp, None, x_win, 0, 0, 0, 0,
|
2000-12-08 06:51:37 +00:00
|
|
|
vid.width + 2, vid.height + 2);
|
2001-04-23 03:52:20 +00:00
|
|
|
X11_ForceViewPort ();
|
2000-10-22 07:14:47 +00:00
|
|
|
}
|
2000-10-24 18:10:01 +00:00
|
|
|
|
|
|
|
XMapWindow (x_disp, x_win);
|
2001-02-10 05:08:25 +00:00
|
|
|
if (vidmode_active && vid_fullscreen->int_val) {
|
2001-02-02 05:42:35 +00:00
|
|
|
XGrabPointer (x_disp, x_win, True, 0, GrabModeAsync, GrabModeAsync, x_win, None, CurrentTime);
|
|
|
|
}
|
2000-10-24 18:10:01 +00:00
|
|
|
XRaiseWindow (x_disp, x_win);
|
2000-09-24 03:43:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-04-23 03:52:20 +00:00
|
|
|
X11_RestoreVidMode (void)
|
2000-09-24 03:43:06 +00:00
|
|
|
{
|
|
|
|
XSetScreenSaver (x_disp, xss_timeout, xss_interval, xss_blanking,
|
2000-12-08 06:51:37 +00:00
|
|
|
xss_exposures);
|
2000-09-24 03:43:06 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_VIDMODE
|
2001-02-09 21:50:42 +00:00
|
|
|
if (vidmode_active) {
|
2001-04-23 03:52:20 +00:00
|
|
|
X11_SetGamma (x_gamma);
|
2001-02-09 22:36:30 +00:00
|
|
|
XF86VidModeSwitchToMode (x_disp, x_screen, vidmodes[original_mode]);
|
2000-11-21 09:17:29 +00:00
|
|
|
XFree (vidmodes);
|
2000-09-24 03:43:06 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-04-23 03:52:20 +00:00
|
|
|
X11_GrabKeyboard (void)
|
2000-09-24 03:43:06 +00:00
|
|
|
{
|
|
|
|
#ifdef HAVE_VIDMODE
|
2001-02-09 21:50:42 +00:00
|
|
|
if (vidmode_active && vid_fullscreen->int_val) {
|
2000-11-21 09:17:29 +00:00
|
|
|
XGrabKeyboard (x_disp, x_win, 1, GrabModeAsync, GrabModeAsync,
|
2000-12-08 06:51:37 +00:00
|
|
|
CurrentTime);
|
2000-09-24 03:43:06 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2000-10-03 07:10:48 +00:00
|
|
|
|
|
|
|
void
|
2001-04-23 03:52:20 +00:00
|
|
|
X11_SetCaption (char *text)
|
2000-10-03 07:10:48 +00:00
|
|
|
{
|
|
|
|
if (x_disp && x_win && text)
|
|
|
|
XStoreName (x_disp, x_win, text);
|
|
|
|
}
|
2000-10-28 05:08:11 +00:00
|
|
|
|
|
|
|
void
|
2001-04-23 03:52:20 +00:00
|
|
|
X11_ForceViewPort (void)
|
2000-10-28 05:08:11 +00:00
|
|
|
{
|
|
|
|
#ifdef HAVE_VIDMODE
|
2000-12-08 06:51:37 +00:00
|
|
|
int x, y;
|
2000-10-28 05:08:11 +00:00
|
|
|
|
2001-02-10 05:08:25 +00:00
|
|
|
if (vidmode_active && vid_fullscreen->int_val) {
|
2000-10-28 05:08:11 +00:00
|
|
|
do {
|
|
|
|
XF86VidModeSetViewPort (x_disp, x_screen, 0, 0);
|
|
|
|
poll (0, 0, 50);
|
|
|
|
XF86VidModeGetViewPort (x_disp, x_screen, &x, &y);
|
|
|
|
} while (x || y);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2001-04-23 03:52:20 +00:00
|
|
|
|
|
|
|
double
|
|
|
|
X11_GetGamma (void)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_VIDMODE
|
|
|
|
# ifdef X_XF86VidModeGetGamma
|
|
|
|
XF86VidModeGamma xgamma;
|
|
|
|
|
|
|
|
if (vidmode_avail && vid_system_gamma->int_val) {
|
|
|
|
if (XF86VidModeGetGamma (x_disp, x_screen, &xgamma)) {
|
|
|
|
return ((xgamma.red + xgamma.green + xgamma.blue) / 3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
return -1.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
qboolean
|
|
|
|
X11_SetGamma (double gamma)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_VIDMODE
|
|
|
|
# ifdef X_XF86VidModeSetGamma
|
|
|
|
XF86VidModeGamma xgamma;
|
|
|
|
|
|
|
|
if (vidmode_avail && vid_system_gamma->int_val) {
|
|
|
|
xgamma.red = xgamma.green = xgamma.blue = (float) gamma;
|
|
|
|
if (XF86VidModeSetGamma (x_disp, x_screen, &xgamma))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
return false;
|
|
|
|
}
|