Fix gamma again. Also some minor whitespace and slight code cleanup.

This commit is contained in:
Jeff Teunissen 2002-04-26 20:25:01 +00:00
parent ac73653741
commit 411ade4ce2

View file

@ -274,6 +274,8 @@ X11_OpenDisplay (void)
void void
X11_CloseDisplay (void) X11_CloseDisplay (void)
{ {
X11_RestoreGamma ();
if (nullcursor != None) { if (nullcursor != None) {
XFreeCursor (x_disp, nullcursor); XFreeCursor (x_disp, nullcursor);
nullcursor = None; nullcursor = None;
@ -331,14 +333,14 @@ X11_ForceMove (int x, int y)
XFlush(x_disp); XFlush(x_disp);
while (1) { while (1) {
XEvent ev; XEvent ev;
XMaskEvent(x_disp,StructureNotifyMask,&ev); XMaskEvent (x_disp,StructureNotifyMask,&ev);
if (ev.type==ConfigureNotify) { if (ev.type == ConfigureNotify) {
nx=ev.xconfigure.x; nx = ev.xconfigure.x;
ny=ev.xconfigure.y; ny = ev.xconfigure.y;
X11_ProcessEventProxy(&ev); X11_ProcessEventProxy (&ev);
break; break;
} }
X11_ProcessEventProxy(&ev); X11_ProcessEventProxy (&ev);
} }
//X11_GetWindowCoords (&nx, &ny); //X11_GetWindowCoords (&nx, &ny);
nx -= x; nx -= x;
@ -351,9 +353,9 @@ X11_ForceMove (int x, int y)
#if 0 // hopefully this isn't needed! enable if it is. #if 0 // hopefully this isn't needed! enable if it is.
if (x < 1 - vid.width) if (x < 1 - vid.width)
x=0; x = 0;
if (y < 1 - vid.height) if (y < 1 - vid.height)
y=0; y = 0;
#endif #endif
XMoveWindow (x_disp, x_win, x, y); XMoveWindow (x_disp, x_win, x, y);
@ -361,12 +363,12 @@ X11_ForceMove (int x, int y)
/* this is the best we can do. */ /* this is the best we can do. */
while (1) { while (1) {
XEvent ev; XEvent ev;
XMaskEvent(x_disp,StructureNotifyMask,&ev); XMaskEvent (x_disp, StructureNotifyMask, &ev);
if (ev.type==ConfigureNotify) { if (ev.type == ConfigureNotify) {
X11_ProcessEventProxy(&ev); X11_ProcessEventProxy (&ev);
break; break;
} }
X11_ProcessEventProxy(&ev); X11_ProcessEventProxy (&ev);
} }
} }
@ -454,7 +456,7 @@ void X11_UpdateFullscreen (cvar_t *fullscreen)
if (!fullscreen->int_val) { if (!fullscreen->int_val) {
X11_RestoreVidMode (); X11_RestoreVidMode ();
if (window_saved) { if (window_saved) {
X11_ForceMove(window_x, window_y); X11_ForceMove (window_x, window_y);
window_saved = 0; window_saved = 0;
} }
if (in_grab) { if (in_grab) {
@ -463,24 +465,27 @@ void X11_UpdateFullscreen (cvar_t *fullscreen)
return; return;
} else { } else {
if (in_grab) { if (in_grab) {
IN_UpdateGrab(in_grab); IN_UpdateGrab (in_grab);
} }
if (X11_GetWindowCoords (&window_x, &window_y)) if (X11_GetWindowCoords (&window_x, &window_y))
window_saved = 1; window_saved = 1;
X11_SetVidMode (scr_width, scr_height); X11_SetVidMode (scr_width, scr_height);
if (in_grab) { // FIXME: why are there two of these?
IN_UpdateGrab (in_grab);
}
if (!vidmode_active) { if (!vidmode_active) {
if (in_grab) {
IN_UpdateGrab (in_grab);
}
window_saved = 0; window_saved = 0;
return; return;
} }
if (in_grab) {
IN_UpdateGrab (in_grab); X11_ForceMove (0, 0);
} XWarpPointer (x_disp, None, x_win,
X11_ForceMove(0, 0); 0, 0, 0, 0,
XWarpPointer(x_disp,None,x_win,0,0,0,0,vid.width/2,vid.height/2); vid.width / 2, vid.height / 2);
X11_ForceViewPort (); X11_ForceViewPort ();
/* Done in X11_SetVidMode but moved the window since then */ /* Done in X11_SetVidMode but moved the window since then */
} }
@ -499,11 +504,11 @@ X11_Init_Cvars (void)
void void
X11_CreateWindow (int width, int height) X11_CreateWindow (int width, int height)
{ {
XSetWindowAttributes attr; XSetWindowAttributes attr;
XClassHint *ClassHint; XClassHint *ClassHint;
XSizeHints *SizeHints; XSizeHints *SizeHints;
char *resname; char *resname;
unsigned long mask; unsigned long mask;
/* window attributes */ /* window attributes */
attr.background_pixel = 0; attr.background_pixel = 0;
@ -542,6 +547,7 @@ X11_CreateWindow (int width, int height)
XSetClassHint (x_disp, x_win, ClassHint); XSetClassHint (x_disp, x_win, ClassHint);
XFree (ClassHint); XFree (ClassHint);
} }
// Make window respond to Delete events // Make window respond to Delete events
aWMDelete = XInternAtom (x_disp, "WM_DELETE_WINDOW", False); aWMDelete = XInternAtom (x_disp, "WM_DELETE_WINDOW", False);
XSetWMProtocols (x_disp, x_win, &aWMDelete, 1); XSetWMProtocols (x_disp, x_win, &aWMDelete, 1);
@ -549,17 +555,19 @@ X11_CreateWindow (int width, int height)
XMapWindow (x_disp, x_win); XMapWindow (x_disp, x_win);
while (1) { while (1) {
XEvent ev; XEvent ev;
XMaskEvent(x_disp,StructureNotifyMask,&ev);
if (ev.type==MapNotify) { XMaskEvent (x_disp, StructureNotifyMask, &ev);
X11_ProcessEventProxy(&ev); if (ev.type == MapNotify) {
X11_ProcessEventProxy (&ev);
break; break;
} }
X11_ProcessEventProxy(&ev); X11_ProcessEventProxy (&ev);
} }
vid_context_created = true; vid_context_created = true;
if (vid_fullscreen->int_val) { if (vid_fullscreen->int_val) {
X11_UpdateFullscreen(vid_fullscreen); X11_UpdateFullscreen (vid_fullscreen);
} }
XRaiseWindow (x_disp, x_win); XRaiseWindow (x_disp, x_win);
} }
@ -570,10 +578,9 @@ X11_RestoreVidMode (void)
#ifdef HAVE_VIDMODE #ifdef HAVE_VIDMODE
if (vidmode_active) { if (vidmode_active) {
X11_RestoreScreenSaver (); X11_RestoreScreenSaver ();
X11_RestoreGamma ();
XF86VidModeSwitchToMode (x_disp, x_screen, vidmodes[original_mode]); XF86VidModeSwitchToMode (x_disp, x_screen, vidmodes[original_mode]);
XFree (vidmodes); XFree (vidmodes);
vidmode_active=false; vidmode_active = false;
} }
#endif #endif
} }
@ -581,21 +588,21 @@ X11_RestoreVidMode (void)
void void
X11_GrabKeyboardBool(qboolean yes) X11_GrabKeyboardBool(qboolean yes)
{ {
static qboolean is_grabbed=false; static qboolean is_grabbed = false;
if (yes) { if (yes) {
if (!is_grabbed) { if (!is_grabbed) {
if (XGrabKeyboard (x_disp, x_win, 1, if (XGrabKeyboard (x_disp, x_win, 1,
GrabModeAsync, GrabModeAsync,
GrabModeAsync, GrabModeAsync,
CurrentTime)==GrabSuccess) { CurrentTime) == GrabSuccess) {
is_grabbed=true; is_grabbed = true;
XSetInputFocus(x_disp,x_win, RevertToPointerRoot,CurrentTime); XSetInputFocus (x_disp, x_win, RevertToPointerRoot, CurrentTime);
} }
} }
} else { } else {
XUngrabKeyboard (x_disp, CurrentTime); XUngrabKeyboard (x_disp, CurrentTime);
is_grabbed=false; is_grabbed = false;
} }
} }
@ -604,27 +611,30 @@ X11_GrabKeyboard (void)
{ {
XGrabKeyboard (x_disp, x_win, 1, GrabModeAsync, GrabModeAsync, XGrabKeyboard (x_disp, x_win, 1, GrabModeAsync, GrabModeAsync,
CurrentTime); CurrentTime);
XSetInputFocus(x_disp,x_win, RevertToPointerRoot,CurrentTime); XSetInputFocus (x_disp, x_win, RevertToPointerRoot, CurrentTime);
} }
void void
X11_GrabMouseBool(qboolean yes) X11_GrabMouseBool (qboolean yes)
{ {
static qboolean is_grabbed=false; static qboolean is_grabbed = false;
if (yes) { if (yes) {
if (!is_grabbed) { if (!is_grabbed) {
if (XGrabPointer (x_disp, x_win, True, MOUSE_MASK, if (XGrabPointer (x_disp, x_win, True, MOUSE_MASK,
GrabModeAsync, GrabModeAsync, GrabModeAsync, GrabModeAsync,
x_win, None, CurrentTime)==GrabSuccess) { x_win, None, CurrentTime) == GrabSuccess) {
is_grabbed=true; is_grabbed = true;
} }
} }
} else { return;
XUngrabPointer (x_disp, CurrentTime);
is_grabbed=false;
XWarpPointer(x_disp,x_win,x_win,0,0,0,0,vid.width/2,vid.height/2);
} }
XUngrabPointer (x_disp, CurrentTime);
is_grabbed = false;
XWarpPointer (x_disp, x_win, x_win,
0, 0, 0, 0,
vid.width / 2, vid.height / 2);
} }
void void
@ -637,8 +647,10 @@ X11_GrabMouse(void)
void void
X11_UngrabMouse(void) X11_UngrabMouse(void)
{ {
XUngrabPointer(x_disp,CurrentTime); XUngrabPointer (x_disp, CurrentTime);
XWarpPointer(x_disp,x_win,x_win,0,0,0,0,vid.width/2,vid.height/2); XWarpPointer (x_disp, x_win, x_win,
0, 0, 0, 0,
vid.width / 2, vid.height / 2);
} }
void void
@ -653,28 +665,28 @@ X11_Grabber(qboolean grab)
// static qboolean is_grabbed=false; // static qboolean is_grabbed=false;
if (!vid_context_created) { if (!vid_context_created) {
Con_Printf("No video context to grab to!\n"); Con_Printf ("No video context to grab to!\n");
return; return;
} }
X11_GrabMouseBool(grab); X11_GrabMouseBool (grab);
X11_GrabKeyboardBool(grab); X11_GrabKeyboardBool (grab);
#if 0 #if 0
if (grab) { if (grab) {
if (!is_grabbed) { if (!is_grabbed) {
X11_GrabKeyboard(); X11_GrabKeyboard ();
X11_GrabMouse(); X11_GrabMouse ();
is_grabbed=true; is_grabbed = true;
} }
} else { } else {
if (is_grabbed) { if (is_grabbed) {
X11_UngrabKeyboard(); X11_UngrabKeyboard ();
X11_UngrabMouse(); X11_UngrabMouse ();
is_grabbed=false; is_grabbed = false;
} }
} }
#endif #endif
XSync(x_disp,false); XSync (x_disp, false);
} }
void void
@ -688,10 +700,11 @@ qboolean
X11_GetWindowCoords (int *ax, int *ay) X11_GetWindowCoords (int *ax, int *ay)
{ {
#ifdef HAVE_VIDMODE #ifdef HAVE_VIDMODE
Window theroot, scrap; Window theroot, scrap;
int x, y; int x, y;
unsigned int width, height, bdwidth, depth; unsigned int width, height, bdwidth, depth;
XSync(x_disp,false);
XSync (x_disp, false);
if ((XGetGeometry (x_disp, x_win, &theroot, &x, &y, &width, &height, if ((XGetGeometry (x_disp, x_win, &theroot, &x, &y, &width, &height,
&bdwidth, &depth) == False)) { &bdwidth, &depth) == False)) {
Con_Printf ("XGetWindowAttributes failed in X11_GetWindowCoords.\n"); Con_Printf ("XGetWindowAttributes failed in X11_GetWindowCoords.\n");