some whitespace changes
[divverent/darkplaces.git] / vid_glx.c
1 /*
2 Copyright (C) 1996-1997 Id Software, Inc.
3
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.
8
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.  
12
13 See the GNU General Public License for more details.
14
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.
18 */
19
20 #include <termios.h>
21 #include <sys/ioctl.h>
22 #include <sys/stat.h>
23 #include <sys/vt.h>
24 #include <stdarg.h>
25 #include <stdio.h>
26 #include <signal.h>
27
28 #include <dlfcn.h>
29
30 #include "quakedef.h"
31
32 #include <GL/glx.h>
33
34 #include <X11/keysym.h>
35 #include <X11/cursorfont.h>
36
37 #include <X11/extensions/XShm.h>
38 #include <X11/extensions/xf86dga.h>
39 #include <X11/extensions/xf86vmode.h>
40
41 static Display *dpy = NULL;
42 static int scrnum;
43 static Window win;
44 static GLXContext ctx = NULL;
45
46 #define KEY_MASK (KeyPressMask | KeyReleaseMask)
47 #define MOUSE_MASK (ButtonPressMask | ButtonReleaseMask | \
48                     PointerMotionMask | ButtonMotionMask )
49 #define X_MASK (KEY_MASK | MOUSE_MASK | VisibilityChangeMask | StructureNotifyMask )
50
51
52 viddef_t        vid;                            // global video state
53
54 static qboolean         mouse_avail = true;
55 static qboolean         mouse_active = false;
56 // static qboolean              dga_active;
57 static float    mouse_x, mouse_y;
58 static float    old_mouse_x, old_mouse_y;
59 static int p_mouse_x, p_mouse_y;
60
61 static cvar_t in_mouse = {"in_mouse", "1", false};
62 static cvar_t in_dga = {"in_dga", "1", false};
63 static cvar_t in_dga_mouseaccel = {"in_dga_mouseaccel", "1", false};
64 static cvar_t m_filter = {"m_filter", "0"};
65
66 qboolean vidmode_ext = false;
67
68 static int win_x, win_y;
69
70 static int scr_width, scr_height;
71
72 static XF86VidModeModeInfo **vidmodes;
73 //static int default_dotclock_vidmode;
74 static int num_vidmodes;
75 static qboolean vidmode_active = false;
76
77 /*-----------------------------------------------------------------------*/
78
79 float           gldepthmin, gldepthmax;
80
81 const char *gl_vendor;
82 const char *gl_renderer;
83 const char *gl_version;
84 const char *gl_extensions;
85
86 /*-----------------------------------------------------------------------*/
87 static int
88 XLateKey(XKeyEvent *ev/*, qboolean modified*/)
89 {
90 //      char tmp[2];
91         int key = 0;
92         KeySym keysym;
93
94         keysym = XLookupKeysym(ev, 0);
95
96         switch(keysym) {
97                 case XK_KP_Page_Up:     key = KP_PGUP; break;
98                 case XK_Page_Up:        key = K_PGUP; break;
99
100                 case XK_KP_Page_Down:   key = KP_PGDN; break;
101                 case XK_Page_Down:      key = K_PGDN; break;
102
103                 case XK_KP_Home:        key = KP_HOME; break;
104                 case XK_Home:           key = K_HOME; break;
105
106                 case XK_KP_End:         key = KP_END; break;
107                 case XK_End:            key = K_END; break;
108
109                 case XK_KP_Left:        key = KP_LEFTARROW; break;
110                 case XK_Left:           key = K_LEFTARROW; break;
111
112                 case XK_KP_Right:       key = KP_RIGHTARROW; break;
113                 case XK_Right:          key = K_RIGHTARROW; break;
114
115                 case XK_KP_Down:        key = KP_DOWNARROW; break;
116                 case XK_Down:           key = K_DOWNARROW; break;
117
118                 case XK_KP_Up:          key = KP_UPARROW; break;
119                 case XK_Up:                     key = K_UPARROW; break;
120
121                 case XK_Escape:         key = K_ESCAPE; break;
122
123                 case XK_KP_Enter:       key = KP_ENTER; break;
124                 case XK_Return:         key = K_ENTER; break;
125
126                 case XK_Tab:            key = K_TAB; break;
127
128                 case XK_F1:                     key = K_F1; break;
129                 case XK_F2:                     key = K_F2; break;
130                 case XK_F3:                     key = K_F3; break;
131                 case XK_F4:                     key = K_F4; break;
132                 case XK_F5:                     key = K_F5; break;
133                 case XK_F6:                     key = K_F6; break;
134                 case XK_F7:                     key = K_F7; break;
135                 case XK_F8:                     key = K_F8; break;
136                 case XK_F9:                     key = K_F9; break;
137                 case XK_F10:            key = K_F10; break;
138                 case XK_F11:            key = K_F11; break;
139                 case XK_F12:            key = K_F12; break;
140
141                 case XK_BackSpace:      key = K_BACKSPACE; break;
142
143                 case XK_KP_Delete:      key = KP_DEL; break;
144                 case XK_Delete:         key = K_DEL; break;
145
146                 case XK_Pause:          key = K_PAUSE; break;
147
148                 case XK_Shift_L:
149                 case XK_Shift_R:        key = K_SHIFT; break;
150
151                 case XK_Execute:
152                 case XK_Control_L:
153                 case XK_Control_R:      key = K_CTRL; break;
154
155                 case XK_Mode_switch:
156                 case XK_Alt_L:
157                 case XK_Meta_L:
158                 case XK_Alt_R:
159                 case XK_Meta_R:         key = K_ALT; break;
160
161                 case XK_Caps_Lock:      key = K_CAPSLOCK; break;
162                 case XK_KP_Begin:       key = KP_5; break;
163
164                 case XK_Insert:         key = K_INS; break;
165                 case XK_KP_Insert:      key = KP_INS; break;
166
167                 case XK_KP_Multiply:    key = KP_MULTIPLY; break;
168                 case XK_KP_Add:         key = KP_PLUS; break;
169                 case XK_KP_Subtract:    key = KP_MINUS; break;
170                 case XK_KP_Divide:      key = KP_DIVIDE; break;
171
172                 /* For Sun keyboards */
173                 case XK_F27:            key = K_HOME; break;
174                 case XK_F29:            key = K_PGUP; break;
175                 case XK_F33:            key = K_END; break;
176                 case XK_F35:            key = K_PGDN; break;
177
178                 default:
179                         if (keysym < 128) {
180                                 /* ASCII keys */
181                                 key = keysym;
182                                 if (/*!modified && */((key >= 'A') && (key <= 'Z'))) {
183                                         key = key + ('a' - 'A');
184                                 }
185                         }
186                         break;
187         }
188
189         return key;
190 }
191
192 static Cursor CreateNullCursor(Display *display, Window root)
193 {
194     Pixmap cursormask; 
195     XGCValues xgc;
196     GC gc;
197     XColor dummycolour;
198     Cursor cursor;
199
200     cursormask = XCreatePixmap(display, root, 1, 1, 1/*depth*/);
201     xgc.function = GXclear;
202     gc =  XCreateGC(display, cursormask, GCFunction, &xgc);
203     XFillRectangle(display, cursormask, gc, 0, 0, 1, 1);
204     dummycolour.pixel = 0;
205     dummycolour.red = 0;
206     dummycolour.flags = 04;
207     cursor = XCreatePixmapCursor(display, cursormask, cursormask,
208           &dummycolour,&dummycolour, 0,0);
209     XFreePixmap(display,cursormask);
210     XFreeGC(display,gc);
211     return cursor;
212 }
213
214 static void install_grabs(void)
215 {
216         XWindowAttributes attribs_1;
217         XSetWindowAttributes attribs_2;
218
219         XGetWindowAttributes(dpy, win, &attribs_1);
220         attribs_2.event_mask = attribs_1.your_event_mask | KEY_MASK | MOUSE_MASK;
221         XChangeWindowAttributes(dpy, win, CWEventMask, &attribs_2);
222
223 // inviso cursor
224         XDefineCursor(dpy, win, CreateNullCursor(dpy, win));
225
226         XGrabPointer(dpy, win,  True, 0, GrabModeAsync, GrabModeAsync,
227                      win, None, CurrentTime);
228
229         if (in_dga.value) {
230                 int MajorVersion, MinorVersion;
231
232                 if (!XF86DGAQueryVersion(dpy, &MajorVersion, &MinorVersion)) { 
233                         // unable to query, probalby not supported
234                         Con_Printf( "Failed to detect XF86DGA Mouse\n" );
235                         in_dga.value = 0;
236                 } else {
237                         in_dga.value = 1;
238                         XF86DGADirectVideo(dpy, DefaultScreen(dpy), XF86DGADirectMouse);
239                         XWarpPointer(dpy, None, win, 0, 0, 0, 0, 0, 0);
240                 }
241         } else {
242                 XWarpPointer(dpy, None, win,
243                                          0, 0, 0, 0,
244                                          vid.width / 2, vid.height / 2);
245         }
246
247         XGrabKeyboard(dpy, win, False, GrabModeAsync, GrabModeAsync, CurrentTime);
248
249         mouse_active = true;
250         mouse_x = mouse_y = 0;
251
252 //      XSync(dpy, True);
253 }
254
255 static void uninstall_grabs(void)
256 {
257         if (!dpy || !win)
258                 return;
259
260         if (in_dga.value == 1) {
261                 XF86DGADirectVideo(dpy, DefaultScreen(dpy), 0);
262         }
263
264         XUngrabPointer(dpy, CurrentTime);
265         XUngrabKeyboard(dpy, CurrentTime);
266
267 // inviso cursor
268         XUndefineCursor(dpy, win);
269
270         mouse_active = false;
271 }
272
273 static void HandleEvents(void)
274 {
275         XEvent event;
276 //      KeySym ks;
277         int b;
278         qboolean dowarp = false;
279
280         if (!dpy)
281                 return;
282
283         while (XPending(dpy)) {
284                 XNextEvent(dpy, &event);
285
286                 switch (event.type) {
287                 case KeyPress:
288                 case KeyRelease:
289                         Key_Event(XLateKey(&event.xkey), event.type == KeyPress);
290                         break;
291
292                 case MotionNotify:
293                         if (in_dga.value == 1) {
294                                 mouse_x += event.xmotion.x_root * in_dga_mouseaccel.value;
295                                 mouse_y += event.xmotion.y_root * in_dga_mouseaccel.value;
296                         } else {
297                                 if (!p_mouse_x && !p_mouse_y) {
298                                         Con_Printf("event->xmotion.x: %d\n", event.xmotion.x);
299                                         Con_Printf("event->xmotion.y: %d\n", event.xmotion.y);
300                                 }
301                                 if (vid_fullscreen.value || vid_mouse.value) {
302                                         if (!event.xmotion.send_event) {
303                                                 mouse_x += (event.xmotion.x - p_mouse_x);
304                                                 mouse_y += (event.xmotion.y - p_mouse_y);
305                                                 if (abs(vid.width/2 - event.xmotion.x) > vid.width / 4
306                                                 || abs(vid.height/2 - event.xmotion.y) > vid.height / 4) {
307                                                         dowarp = true;
308                                                 }
309                                         }
310                                 } else {
311                                         mouse_x += (event.xmotion.x - p_mouse_x);
312                                         mouse_y += (event.xmotion.y - p_mouse_y);
313                                 }
314                                 p_mouse_x = event.xmotion.x;
315                                 p_mouse_y = event.xmotion.y;
316                         }
317                         break;
318
319                 case ButtonPress:
320                         b=-1;
321                         if (event.xbutton.button == 1)
322                                 b = 0;
323                         else if (event.xbutton.button == 2)
324                                 b = 2;
325                         else if (event.xbutton.button == 3)
326                                 b = 1;
327                         if (b>=0)
328                                 Key_Event(K_MOUSE1 + b, true);
329                         break;
330
331                 case ButtonRelease:
332                         b=-1;
333                         if (event.xbutton.button == 1)
334                                 b = 0;
335                         else if (event.xbutton.button == 2)
336                                 b = 2;
337                         else if (event.xbutton.button == 3)
338                                 b = 1;
339                         if (b>=0)
340                                 Key_Event(K_MOUSE1 + b, false);
341                         break;
342
343                 case CreateNotify :
344                         win_x = event.xcreatewindow.x;
345                         win_y = event.xcreatewindow.y;
346                         break;
347
348                 case ConfigureNotify :
349                         win_x = event.xconfigure.x;
350                         win_y = event.xconfigure.y;
351                         break;
352                 }
353         }
354
355         if (dowarp) {
356                 /* move the mouse to the window center again */
357                 p_mouse_x = vid.width / 2;
358                 p_mouse_y = vid.height / 2;
359                 XWarpPointer(dpy, None, win, 0, 0, 0, 0, p_mouse_x, p_mouse_y);
360         }
361
362 }
363
364 static void IN_DeactivateMouse( void ) 
365 {
366         if (!mouse_avail || !dpy || !win)
367                 return;
368
369         if (mouse_active) {
370                 uninstall_grabs();
371                 mouse_active = false;
372         }
373 }
374
375 static void IN_ActivateMouse( void ) 
376 {
377         if (!mouse_avail || !dpy || !win)
378                 return;
379
380         if (!mouse_active) {
381                 mouse_x = mouse_y = 0; // don't spazz
382                 install_grabs();
383                 mouse_active = true;
384         }
385 }
386
387
388 void VID_Shutdown(void)
389 {
390         if (!ctx || !dpy)
391                 return;
392
393         if (dpy) {
394                 uninstall_grabs();
395
396                 if (vidmode_active)
397                         XF86VidModeSwitchToMode(dpy, scrnum, vidmodes[0]);
398 /* Disabled, causes a segfault during shutdown.
399                 if (ctx)
400                         glXDestroyContext(dpy, ctx);
401 */
402                 if (win)
403                         XDestroyWindow(dpy, win);
404                 XCloseDisplay(dpy);
405         }
406         vidmode_active = false;
407         dpy = NULL;
408         win = 0;
409         ctx = NULL;
410 }
411
412 void signal_handler(int sig)
413 {
414         printf("Received signal %d, exiting...\n", sig);
415         Sys_Quit();
416         exit(0);
417 }
418
419 void InitSig(void)
420 {
421         signal(SIGHUP, signal_handler);
422         signal(SIGINT, signal_handler);
423         signal(SIGQUIT, signal_handler);
424         signal(SIGILL, signal_handler);
425         signal(SIGTRAP, signal_handler);
426         signal(SIGIOT, signal_handler);
427         signal(SIGBUS, signal_handler);
428         signal(SIGFPE, signal_handler);
429         signal(SIGSEGV, signal_handler);
430         signal(SIGTERM, signal_handler);
431 }
432
433 void VID_CheckMultitexture(void) 
434 {
435         void *prjobj;
436         qglMTexCoord2f = NULL;
437         qglSelectTexture = NULL;
438         // Check to see if multitexture is disabled
439         if (COM_CheckParm("-nomtex"))
440         {
441                 Con_Printf("...multitexture disabled\n");
442                 return;
443         }
444         if ((prjobj = dlopen(NULL, RTLD_LAZY)) == NULL)
445         {
446                 Con_Printf("Unable to open symbol list for main program.\n");
447                 return;
448         }
449         // Test for ARB_multitexture
450         if (!COM_CheckParm("-SGISmtex") && strstr(gl_extensions, "GL_ARB_multitexture "))
451         {
452                 Con_Printf("...using GL_ARB_multitexture\n");
453                 qglMTexCoord2f = (void *) dlsym(prjobj, "glMultiTexCoord2fARB");
454                 qglSelectTexture = (void *) dlsym(prjobj, "glActiveTextureARB");
455                 gl_mtexable = true;
456                 gl_mtex_enum = GL_TEXTURE0_ARB;
457         }
458         else if (strstr(gl_extensions, "GL_SGIS_multitexture ")) // Test for SGIS_multitexture (if ARB_multitexture not found)
459         {
460                 Con_Printf("...using GL_SGIS_multitexture\n");
461                 qglMTexCoord2f = (void *) dlsym(prjobj, "glMTexCoord2fSGIS");
462                 qglSelectTexture = (void *) dlsym(prjobj, "glSelectTextureSGIS");
463                 gl_mtexable = true;
464                 gl_mtex_enum = TEXTURE0_SGIS;
465         }
466         else
467                 Con_Printf("...multitexture disabled (not detected)\n");
468         dlclose(prjobj);
469 }
470
471 void VID_CheckCVA(void)
472 {
473         void *prjobj;
474         qglLockArraysEXT = NULL;
475         qglUnlockArraysEXT = NULL;
476         gl_supportslockarrays = false;
477         if (COM_CheckParm("-nocva"))
478         {
479                 Con_Printf("...compiled vertex arrays disabled\n");
480                 return;
481         }
482         if ((prjobj = dlopen(NULL, RTLD_LAZY)) == NULL)
483         {
484                 Con_Printf("Unable to open symbol list for main program.\n");
485                 return;
486         }
487         if (strstr(gl_extensions, "GL_EXT_compiled_vertex_array"))
488         {
489                 Con_Printf("...using compiled vertex arrays\n");
490                 qglLockArraysEXT = (void *) dlsym(prjobj, "glLockArraysEXT");
491                 qglUnlockArraysEXT = (void *) dlsym(prjobj, "glUnlockArraysEXT");
492                 gl_supportslockarrays = true;
493         }
494         dlclose(prjobj);
495 }
496
497 /*
498 =================
499 GL_BeginRendering
500
501 =================
502 */
503 void GL_BeginRendering (int *x, int *y, int *width, int *height)
504 {
505         *x = *y = 0;
506         *width = scr_width;
507         *height = scr_height;
508
509 //      glViewport (*x, *y, *width, *height);
510 }
511
512
513 void GL_EndRendering (void)
514 {
515         if (!r_render.value)
516                 return;
517         glFlush();
518         glXSwapBuffers(dpy, win);
519 }
520
521 int VID_SetGamma(float prescale, float gamma, float scale, float base)
522 {
523         return FALSE;
524 }
525
526 void VID_Init()
527 {
528         int i;
529         int attrib[] = {
530                 GLX_RGBA,
531                 GLX_RED_SIZE, 1,
532                 GLX_GREEN_SIZE, 1,
533                 GLX_BLUE_SIZE, 1,
534                 GLX_DOUBLEBUFFER,
535                 GLX_DEPTH_SIZE, 1,
536                 None
537         };
538 //      char    gldir[MAX_OSPATH];
539         int width = 640, height = 480;
540         XSetWindowAttributes attr;
541         unsigned long mask;
542         Window root;
543         XVisualInfo *visinfo;
544         qboolean fullscreen = true;
545         int MajorVersion, MinorVersion;
546         int actualWidth, actualHeight;
547
548         Cvar_RegisterVariable (&in_mouse);
549         Cvar_RegisterVariable (&in_dga);
550         Cvar_RegisterVariable (&in_dga_mouseaccel);
551         Cvar_RegisterVariable (&m_filter);
552         
553 // interpret command-line params
554
555 // set vid parameters
556         if ((i = COM_CheckParm("-window")) != 0)
557                 fullscreen = false;
558
559         if ((i = COM_CheckParm("-width")) != 0)
560                 width = atoi(com_argv[i+1]);
561
562         if ((i = COM_CheckParm("-height")) != 0)
563                 height = atoi(com_argv[i+1]);
564
565         if ((i = COM_CheckParm("-conwidth")) != 0)
566                 vid.conwidth = atoi(com_argv[i+1]);
567         else
568                 vid.conwidth = 640;
569
570         vid.conwidth &= 0xfff8; // make it a multiple of eight
571
572         if (vid.conwidth < 320)
573                 vid.conwidth = 320;
574
575         // pick a conheight that matches with correct aspect
576         vid.conheight = vid.conwidth*3 / 4;
577
578         if ((i = COM_CheckParm("-conheight")) != 0)
579                 vid.conheight = atoi(com_argv[i+1]);
580         if (vid.conheight < 200)
581                 vid.conheight = 200;
582
583         if (!(dpy = XOpenDisplay(NULL))) {
584                 fprintf(stderr, "Error couldn't open the X display\n");
585                 exit(1);
586         }
587
588         scrnum = DefaultScreen(dpy);
589         root = RootWindow(dpy, scrnum);
590
591         // Get video mode list
592         MajorVersion = MinorVersion = 0;
593         if (!XF86VidModeQueryVersion(dpy, &MajorVersion, &MinorVersion)) { 
594                 vidmode_ext = false;
595         } else {
596                 Con_Printf("Using XFree86-VidModeExtension Version %d.%d\n", MajorVersion, MinorVersion);
597                 vidmode_ext = true;
598         }
599
600         visinfo = glXChooseVisual(dpy, scrnum, attrib);
601         if (!visinfo) {
602                 fprintf(stderr, "qkHack: Error couldn't get an RGB, Double-buffered, Depth visual\n");
603                 exit(1);
604         }
605
606         if (vidmode_ext) {
607                 int best_fit, best_dist, dist, x, y;
608                 
609                 XF86VidModeGetAllModeLines(dpy, scrnum, &num_vidmodes, &vidmodes);
610
611                 // Are we going fullscreen?  If so, let's change video mode
612                 if (fullscreen) {
613                         best_dist = 9999999;
614                         best_fit = -1;
615
616                         for (i = 0; i < num_vidmodes; i++) {
617                                 if (width > vidmodes[i]->hdisplay ||
618                                         height > vidmodes[i]->vdisplay)
619                                         continue;
620
621                                 x = width - vidmodes[i]->hdisplay;
622                                 y = height - vidmodes[i]->vdisplay;
623                                 dist = (x * x) + (y * y);
624                                 if (dist < best_dist) {
625                                         best_dist = dist;
626                                         best_fit = i;
627                                 }
628                         }
629
630                         if (best_fit != -1) {
631                                 actualWidth = vidmodes[best_fit]->hdisplay;
632                                 actualHeight = vidmodes[best_fit]->vdisplay;
633
634                                 // change to the mode
635                                 XF86VidModeSwitchToMode(dpy, scrnum, vidmodes[best_fit]);
636                                 vidmode_active = true;
637
638                                 // Move the viewport to top left
639                                 XF86VidModeSetViewPort(dpy, scrnum, 0, 0);
640                         } else
641                                 fullscreen = 0;
642                 }
643         }
644
645         /* window attributes */
646         attr.background_pixel = 0;
647         attr.border_pixel = 0;
648         attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone);
649         attr.event_mask = X_MASK;
650         if (vidmode_active) {
651                 mask = CWBackPixel | CWColormap | CWSaveUnder | CWBackingStore | 
652                         CWEventMask | CWOverrideRedirect;
653                 attr.override_redirect = True;
654                 attr.backing_store = NotUseful;
655                 attr.save_under = False;
656         } else
657                 mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
658
659         win = XCreateWindow(dpy, root, 0, 0, width, height,
660                                                 0, visinfo->depth, InputOutput,
661                                                 visinfo->visual, mask, &attr);
662         XMapWindow(dpy, win);
663
664         if (vidmode_active) {
665                 XMoveWindow(dpy, win, 0, 0);
666                 XRaiseWindow(dpy, win);
667                 XWarpPointer(dpy, None, win, 0, 0, 0, 0, 0, 0);
668                 XFlush(dpy);
669                 // Move the viewport to top left
670                 XF86VidModeSetViewPort(dpy, scrnum, 0, 0);
671         }
672
673         XFlush(dpy);
674
675         ctx = glXCreateContext(dpy, visinfo, NULL, True);
676
677         glXMakeCurrent(dpy, win, ctx);
678
679         scr_width = width;
680         scr_height = height;
681
682         if (vid.conheight > height)
683                 vid.conheight = height;
684         if (vid.conwidth > width)
685                 vid.conwidth = width;
686         vid.width = vid.conwidth;
687         vid.height = vid.conheight;
688
689         vid.aspect = ((float)vid.height / (float)vid.width) * (320.0 / 240.0);
690
691         InitSig(); // trap evil signals
692
693         GL_Init();
694
695         Con_SafePrintf ("Video mode %dx%d initialized.\n", width, height);
696
697         vid.recalc_refdef = 1;                          // force a surface cache flush
698
699         install_grabs();
700 }
701
702 void Sys_SendKeyEvents(void)
703 {
704         HandleEvents();
705 }
706
707 void Force_CenterView_f (void)
708 {
709         cl.viewangles[PITCH] = 0;
710 }
711
712 void IN_Init(void)
713 {
714 }
715
716 void IN_Shutdown(void)
717 {
718 }
719
720 /*
721 ===========
722 IN_Commands
723 ===========
724 */
725 void IN_Commands (void)
726 {
727         if (!dpy || !win)
728                 return;
729
730         if (vidmode_active || key_dest == key_game)
731                 IN_ActivateMouse();
732         else
733                 IN_DeactivateMouse ();
734 }
735
736 /*
737 ===========
738 IN_Move
739 ===========
740 */
741 void IN_MouseMove (usercmd_t *cmd)
742 {
743         if (!mouse_avail)
744                 return;
745
746         if (!mouse_avail)
747                 return;
748
749         if (m_filter.value) {
750                 mouse_x = (mouse_x + old_mouse_x) * 0.5;
751                 mouse_y = (mouse_y + old_mouse_y) * 0.5;
752
753                 old_mouse_x = mouse_x;
754                 old_mouse_y = mouse_y;
755         }
756
757         mouse_x *= sensitivity.value;
758         mouse_y *= sensitivity.value;
759         
760         if (in_strafe.state & 1)
761                 cmd->sidemove += m_side.value * mouse_x;
762         else
763                 cl.viewangles[YAW] -= m_yaw.value * mouse_x;
764                 
765 /*        if (freelook)*/
766                 V_StopPitchDrift ();
767
768         if (/*freelook && */!(in_strafe.state & 1)) {
769                 cl.viewangles[PITCH] += m_pitch.value * mouse_y;
770                 cl.viewangles[PITCH] = bound (-70, cl.viewangles[PITCH], 80);
771         } else {
772                 if ((in_strafe.state & 1) && noclip_anglehack)
773                         cmd->upmove -= m_forward.value * mouse_y;
774                 else
775                         cmd->forwardmove -= m_forward.value * mouse_y;
776         }
777         mouse_x = mouse_y = 0.0;
778 }
779
780 void IN_Move (usercmd_t *cmd)
781 {
782         IN_MouseMove(cmd);
783 }
784
785