]> icculus.org git repositories - divverent/darkplaces.git/blob - vid_agl.c
78616057133df6590e322543efa702733750ab67
[divverent/darkplaces.git] / vid_agl.c
1 /*
2         vid_agl.c
3
4         Mac OS X OpenGL and input module, using Carbon and AGL
5
6         Copyright (C) 2005  Mathieu Olivier
7
8         This program is free software; you can redistribute it and/or modify
9         it under the terms of the GNU General Public License as published by
10         the Free Software Foundation; either version 2 of the License, or
11         (at your option) any later version.
12
13         This program is distributed in the hope that it will be useful,
14         but WITHOUT ANY WARRANTY; without even the implied warranty of
15         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16         GNU General Public License for more details.
17
18         You should have received a copy of the GNU General Public License
19         along with this program; if not, write to the Free Software
20         Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21 */
22
23
24 #include <dlfcn.h>
25 #include <signal.h>
26 #include <AGL/agl.h>
27 #include <Carbon/Carbon.h>
28 #include "quakedef.h"
29
30
31 // Tell startup code that we have a client
32 int cl_available = true;
33
34 // AGL prototypes
35 AGLPixelFormat (*qaglChoosePixelFormat) (const AGLDevice *gdevs, GLint ndev, const GLint *attribList);
36 AGLContext (*qaglCreateContext) (AGLPixelFormat pix, AGLContext share);
37 GLboolean (*qaglDestroyContext) (AGLContext ctx);
38 void (*qaglDestroyPixelFormat) (AGLPixelFormat pix);
39 GLboolean (*qaglSetCurrentContext) (AGLContext ctx);
40 GLboolean (*qaglSetDrawable) (AGLContext ctx, AGLDrawable draw);
41 GLboolean (*qaglSetFullScreen) (AGLContext ctx, GLsizei width, GLsizei height, GLsizei freq, GLint device);
42 void (*qaglSwapBuffers) (AGLContext ctx);
43
44 static qboolean mouse_avail = true;
45 static qboolean vid_usingmouse = false;
46 static float mouse_x, mouse_y;
47
48 static qboolean vid_isfullscreen = false;
49
50 static int scr_width, scr_height;
51
52 static AGLContext context;
53 static  WindowRef window;
54
55
56 void VID_GetWindowSize (int *x, int *y, int *width, int *height)
57 {
58         *x = *y = 0;
59         *width = scr_width;
60         *height = scr_height;
61 }
62
63 static void IN_Activate( qboolean grab )
64 {
65         if (grab)
66         {
67                 if (!vid_usingmouse && mouse_avail && window)
68                 {
69                         Rect winBounds;
70                         CGPoint winCenter;
71
72                         SelectWindow(window);
73                         HideCursor();
74
75                         // Put the mouse cursor at the center of the window
76                         GetWindowBounds (window, kWindowContentRgn, &winBounds);
77                         winCenter.x = (winBounds.left + winBounds.right) / 2;
78                         winCenter.y = (winBounds.top + winBounds.bottom) / 2;
79                         CGWarpMouseCursorPosition(winCenter);
80
81                         // Lock the mouse pointer at its current position
82                         CGAssociateMouseAndMouseCursorPosition(false);
83
84                         mouse_x = mouse_y = 0;
85                         vid_usingmouse = true;
86                 }
87         }
88         else
89         {
90                 if (vid_usingmouse)
91                 {
92                         CGAssociateMouseAndMouseCursorPosition(true);
93                         ShowCursor();
94
95                         vid_usingmouse = false;
96                 }
97         }
98 }
99
100 void VID_Finish (void)
101 {
102         qboolean vid_usemouse;
103
104         // handle the mouse state when windowed if that's changed
105         vid_usemouse = false;
106         if (vid_mouse.integer && !key_consoleactive && !cls.demoplayback)
107                 vid_usemouse = true;
108         if (!vid_activewindow)
109                 vid_usemouse = false;
110         if (vid_isfullscreen)
111                 vid_usemouse = true;
112         IN_Activate(vid_usemouse);
113
114         if (r_render.integer)
115         {
116                 if (r_speeds.integer || gl_finish.integer)
117                         qglFinish();
118                 qaglSwapBuffers(context);
119         }
120 }
121
122 int VID_SetGamma(unsigned short *ramps)
123 {
124         // TODO
125         return false;
126 }
127
128 int VID_GetGamma(unsigned short *ramps)
129 {
130         // TODO
131         return false;
132 }
133
134 void signal_handler(int sig)
135 {
136         printf("Received signal %d, exiting...\n", sig);
137         VID_RestoreSystemGamma();
138         Sys_Quit();
139         exit(0);
140 }
141
142 void InitSig(void)
143 {
144         signal(SIGHUP, signal_handler);
145         signal(SIGINT, signal_handler);
146         signal(SIGQUIT, signal_handler);
147         signal(SIGILL, signal_handler);
148         signal(SIGTRAP, signal_handler);
149         signal(SIGIOT, signal_handler);
150         signal(SIGBUS, signal_handler);
151         signal(SIGFPE, signal_handler);
152         signal(SIGSEGV, signal_handler);
153         signal(SIGTERM, signal_handler);
154 }
155
156 void VID_Init(void)
157 {
158         InitSig(); // trap evil signals
159 // COMMANDLINEOPTION: Input: -nomouse disables mouse support (see also vid_mouse cvar)
160         if (COM_CheckParm ("-nomouse") || COM_CheckParm("-safe"))
161                 mouse_avail = false;
162 }
163
164 static void *prjobj = NULL;
165
166 static void GL_CloseLibrary(void)
167 {
168         if (prjobj)
169                 dlclose(prjobj);
170         prjobj = NULL;
171         gl_driver[0] = 0;
172         gl_extensions = "";
173         gl_platform = "";
174         gl_platformextensions = "";
175 }
176
177 static int GL_OpenLibrary(void)
178 {
179         const char *name = "/System/Library/Frameworks/AGL.framework/AGL";
180
181         Con_Printf("Loading OpenGL driver %s\n", name);
182         GL_CloseLibrary();
183         if (!(prjobj = dlopen(name, RTLD_LAZY)))
184         {
185                 Con_Printf("Unable to open symbol list for %s\n", name);
186                 return false;
187         }
188         strcpy(gl_driver, name);
189         return true;
190 }
191
192 void *GL_GetProcAddress(const char *name)
193 {
194         return dlsym(prjobj, name);
195 }
196
197 void VID_Shutdown(void)
198 {
199         if (context == NULL || window == NULL)
200                 return;
201
202         IN_Activate(false);
203         VID_RestoreSystemGamma();
204
205         if (context != NULL)
206         {
207                 qaglDestroyContext(context);
208                 context = NULL;
209         }
210
211         if (window != NULL)
212         {
213                 DisposeWindow(window);
214                 window = NULL;
215         }
216
217         vid_hidden = true;
218         vid_isfullscreen = false;
219
220         GL_CloseLibrary();
221         Key_ClearStates ();
222 }
223
224 // Since the event handler can be called at any time, we store the events for later processing
225 static qboolean AsyncEvent_Quitting = false;
226 static qboolean AsyncEvent_Collapsed = false;
227 static OSStatus MainWindowEventHandler (EventHandlerCallRef nextHandler, EventRef event, void *userData)
228 {
229         OSStatus err = noErr;
230
231         switch (GetEventKind (event))
232         {
233                 case kEventWindowClosed:
234                         //Con_Printf(">> kEventWindowClosed (received) <<\n");
235                         AsyncEvent_Quitting = true;
236                         break;
237
238                 // Docked (start)
239                 case kEventWindowCollapsing:
240                         //Con_Printf(">> kEventWindowCollapsing (received) <<\n");
241                         AsyncEvent_Collapsed = true;
242                         break;
243
244                 // Undocked / restored (end)
245                 case kEventWindowExpanded:
246                         //Con_Printf(">> kEventWindowExpanded (received) <<\n");
247                         AsyncEvent_Collapsed = false;
248                         break;
249
250                 default:
251                         err = eventNotHandledErr;
252                         break;
253         }
254
255         return err;
256 }
257
258 static void VID_ProcessPendingAsyncEvents (void)
259 {
260         // Collapsed / expanded
261         if (AsyncEvent_Collapsed != vid_hidden)
262         {
263                 /*
264                 if (vid_hidden)
265                         Con_Printf(">> kEventWindowExpanded (processed) <<\n");
266                 else
267                         Con_Printf(">> kEventWindowCollapsing (processed) <<\n");
268                 */
269
270                 vid_hidden = !vid_hidden;
271                 vid_activewindow = false;
272                 VID_RestoreSystemGamma();
273         }
274
275         // Closed
276         if (AsyncEvent_Quitting)
277         {
278                 //Con_Printf(">> kEventWindowClosed (processed) <<\n");
279                 Sys_Quit();
280         }
281 }
282
283 static void VID_BuildAGLAttrib(GLint *attrib, int stencil, qboolean fullscreen)
284 {
285         *attrib++ = AGL_RGBA;
286         *attrib++ = AGL_RED_SIZE;*attrib++ = 1;
287         *attrib++ = AGL_GREEN_SIZE;*attrib++ = 1;
288         *attrib++ = AGL_BLUE_SIZE;*attrib++ = 1;
289         *attrib++ = AGL_DOUBLEBUFFER;
290         *attrib++ = AGL_DEPTH_SIZE;*attrib++ = 1;
291         // if stencil is enabled, ask for alpha too
292         if (stencil)
293         {
294                 *attrib++ = AGL_STENCIL_SIZE;*attrib++ = 8;
295                 *attrib++ = AGL_ALPHA_SIZE;*attrib++ = 1;
296         }
297         if (fullscreen)
298                 *attrib++ = AGL_FULLSCREEN;
299         *attrib++ = AGL_NONE;
300 }
301
302 int VID_InitMode(int fullscreen, int width, int height, int bpp)
303 {
304     const EventTypeSpec winEvents[] =
305         {
306                 { kEventClassWindow, kEventWindowClosed },
307                 { kEventClassWindow, kEventWindowCollapsing },
308                 { kEventClassWindow, kEventWindowExpanded },
309         };
310         OSStatus carbonError;
311         Rect windowBounds;
312         GDHandle screen;
313         AGLPixelFormat pixelFormat;
314         GLint attributes [32];
315
316         if (!GL_OpenLibrary())
317         {
318                 Con_Printf("Unable to load GL driver\n");
319                 return false;
320         }
321
322         if ((qaglChoosePixelFormat = (AGLPixelFormat (*) (const AGLDevice *gdevs, GLint ndev, const GLint *attribList))GL_GetProcAddress("aglChoosePixelFormat")) == NULL
323          || (qaglCreateContext = (AGLContext (*) (AGLPixelFormat pix, AGLContext share))GL_GetProcAddress("aglCreateContext")) == NULL
324          || (qaglDestroyContext = (GLboolean (*) (AGLContext ctx))GL_GetProcAddress("aglDestroyContext")) == NULL
325          || (qaglDestroyPixelFormat = (void (*) (AGLPixelFormat pix))GL_GetProcAddress("aglDestroyPixelFormat")) == NULL
326          || (qaglSetCurrentContext = (GLboolean (*) (AGLContext ctx))GL_GetProcAddress("aglSetCurrentContext")) == NULL
327          || (qaglSetDrawable = (GLboolean (*) (AGLContext ctx, AGLDrawable draw))GL_GetProcAddress("aglSetDrawable")) == NULL
328          || (qaglSetFullScreen = (GLboolean (*) (AGLContext ctx, GLsizei width, GLsizei height, GLsizei freq, GLint device))GL_GetProcAddress("aglSetFullScreen")) == NULL
329          || (qaglSwapBuffers = (void (*) (AGLContext ctx))GL_GetProcAddress("aglSwapBuffers")) == NULL
330         )
331         {
332                 Con_Printf("AGL functions not found\n");
333                 ReleaseWindow(window);
334                 return false;
335         }
336
337         // Ignore the events from the previous window
338         AsyncEvent_Quitting = false;
339         AsyncEvent_Collapsed = false;
340
341         // Create the window
342         SetRect(&windowBounds, 0, 0, width, height);
343         OffsetRect(&windowBounds, 100, 100);  // move it a bit towards the center of the screen
344         carbonError = CreateNewWindow(kDocumentWindowClass, kWindowStandardFloatingAttributes | kWindowStandardHandlerAttribute, &windowBounds, &window);
345         if (carbonError != noErr || window == NULL)
346         {
347                 Con_Printf("Unable to create window (error %d)\n", carbonError);
348                 return false;
349         }
350
351         // Set the window title
352         CFStringRef windowTitle = CFSTR("DarkPlaces AGL");
353         SetWindowTitleWithCFString(window, windowTitle);
354         CFRelease(windowTitle);
355
356         // Install the callback function for the window events we can't get
357         // through ReceiveNextEvent (i.e. close, collapse, and expand)
358         InstallWindowEventHandler (window, NewEventHandlerUPP (MainWindowEventHandler),
359                                                            GetEventTypeCount(winEvents), winEvents, window, NULL);
360
361         screen = GetGWorldDevice(GetWindowPort(window));
362         if (screen == NULL)
363         {
364                 Con_Printf("Unable to get GDevice for window\n");
365                 ReleaseWindow(window);
366                 return false;
367         }
368
369         // Create and set pixel format
370         VID_BuildAGLAttrib(attributes, bpp == 32, fullscreen);
371         pixelFormat = qaglChoosePixelFormat(&screen, 1, attributes);
372         if (pixelFormat == NULL)
373         {
374                 Con_Printf("Unable to create pixel format\n");
375                 ReleaseWindow(window);
376                 return false;
377         }
378
379         // Set context and show the window
380         context = qaglCreateContext(pixelFormat, NULL);
381         qaglDestroyPixelFormat(pixelFormat);
382         if (context == NULL)
383                 Sys_Error ("aglCreateContext failed");
384         if (!qaglSetDrawable(context, GetWindowPort(window)))
385                 Sys_Error ("aglSetDrawable failed");
386         if (!qaglSetCurrentContext(context))
387                 Sys_Error ("aglSetCurrentContext failed");
388
389         scr_width = width;
390         scr_height = height;
391
392         if ((qglGetString = (const GLubyte* (GLAPIENTRY *)(GLenum name))GL_GetProcAddress("glGetString")) == NULL)
393                 Sys_Error("glGetString not found in %s", gl_driver);
394
395         if (fullscreen)
396         {
397                 if (!qaglSetFullScreen (context, width, height, 0, 0))
398                         Sys_Error("aglSetFullScreen failed");
399                 vid_isfullscreen = true;
400         }
401
402         gl_renderer = (const char *)qglGetString(GL_RENDERER);
403         gl_vendor = (const char *)qglGetString(GL_VENDOR);
404         gl_version = (const char *)qglGetString(GL_VERSION);
405         gl_extensions = (const char *)qglGetString(GL_EXTENSIONS);
406         gl_platform = "AGL";
407         gl_videosyncavailable = false;
408
409         vid_usingmouse = false;
410         vid_hidden = false;
411         vid_activewindow = true;
412         GL_Init();
413
414         SelectWindow(window);
415         ShowWindow(window);
416
417         return true;
418 }
419
420 static void Handle_KeyMod(UInt32 keymod)
421 {
422         static UInt32 prev_keymod = 0;
423         UInt32 modChanges = prev_keymod ^ keymod;
424
425         if ((modChanges & cmdKey) != 0)
426         {
427                 Key_Event(K_AUX1, '\0', (keymod & cmdKey) != 0);
428         }
429         if ((modChanges & shiftKey) != 0 || (modChanges & rightShiftKey) != 0)
430         {
431                 Key_Event(K_SHIFT, '\0', (keymod & shiftKey) != 0);
432         }
433         if ((modChanges & alphaLock) != 0)
434         {
435                 Key_Event(K_CAPSLOCK, '\0', (keymod & alphaLock) != 0);
436         }
437         if ((modChanges & optionKey) != 0 || (modChanges & rightOptionKey) != 0)
438         {
439                 Key_Event(K_ALT, '\0', (keymod & optionKey) != 0);
440         }
441         if ((modChanges & controlKey) != 0 || (modChanges & rightControlKey) != 0)
442         {
443                 Key_Event(K_CTRL, '\0', (keymod & controlKey) != 0);
444         }
445         if ((modChanges & kEventKeyModifierNumLockMask) != 0)
446         {
447                 Key_Event(K_NUMLOCK, '\0', (keymod & kEventKeyModifierNumLockMask) != 0);
448         }
449         if ((modChanges & kEventKeyModifierFnMask) != 0)
450         {
451                 Key_Event(K_AUX2, '\0', (keymod & kEventKeyModifierFnMask) != 0);
452         }
453
454         prev_keymod = keymod;
455 }
456
457 static void Handle_Key(unsigned char charcode, qboolean keypressed)
458 {
459         unsigned int keycode = 0;
460         char ascii = '\0';
461
462         switch (charcode)
463         {
464                 case kHomeCharCode:
465                         keycode = K_HOME;
466                         break;
467                 case kEnterCharCode:
468                         keycode = K_KP_ENTER;
469                         break;
470                 case kEndCharCode:
471                         keycode = K_END;
472                         break;
473                 case kBackspaceCharCode:
474                         keycode = K_BACKSPACE;
475                         break;
476                 case kTabCharCode:
477                         keycode = K_TAB;
478                         break;
479                 case kPageUpCharCode:
480                         keycode = K_PGUP;
481                         break;
482                 case kPageDownCharCode:
483                         keycode = K_PGDN;
484                         break;
485                 case kReturnCharCode:
486                         keycode = K_ENTER;
487                         break;
488                 case kEscapeCharCode:
489                         keycode = K_ESCAPE;
490                         break;
491                 case kLeftArrowCharCode:
492                         keycode = K_LEFTARROW;
493                         break;
494                 case kRightArrowCharCode:
495                         keycode = K_RIGHTARROW;
496                         break;
497                 case kUpArrowCharCode:
498                         keycode = K_UPARROW;
499                         break;
500                 case kDownArrowCharCode :
501                         keycode = K_DOWNARROW;
502                         break;
503                 case kDeleteCharCode:
504                         keycode = K_DEL;
505                         break;
506                 case 191:
507                         // char 191 is sent by the mouse buttons (?!)
508                         break;
509                 default:
510                         if ('A' <= charcode && charcode <= 'Z')
511                         {
512                                 keycode = charcode + ('a' - 'A');  // lowercase it
513                                 ascii = charcode;
514                         }
515                         else if (32 <= charcode && charcode <= 126)
516                         {
517                                 keycode = charcode;
518                                 ascii = charcode;
519                         }
520                         else
521                                 Con_Printf(">> UNKNOWN charcode: %d <<\n", charcode);
522         }
523
524         if (keycode != 0)
525                 Key_Event(keycode, ascii, keypressed);
526 }
527
528 void Sys_SendKeyEvents(void)
529 {
530         EventRef theEvent;
531         EventTargetRef theTarget;
532
533         // Start by processing the asynchronous events we received since the previous frame
534         VID_ProcessPendingAsyncEvents();
535
536         theTarget = GetEventDispatcherTarget();
537         while (ReceiveNextEvent(0, NULL, kEventDurationNoWait, true, &theEvent) == noErr)
538         {
539                 UInt32 eventClass = GetEventClass(theEvent);
540                 UInt32 eventKind = GetEventKind(theEvent);
541
542                 switch (eventClass)
543                 {
544                         case kEventClassMouse:
545                         {
546                                 EventMouseButton theButton;
547                                 int key;
548
549                                 switch (eventKind)
550                                 {
551                                         case kEventMouseDown:
552                                         case kEventMouseUp:
553                                                 GetEventParameter(theEvent, kEventParamMouseButton, typeMouseButton, NULL, sizeof(theButton), NULL, &theButton);
554                                                 switch (theButton)
555                                                 {
556                                                         default:
557                                                         case kEventMouseButtonPrimary:
558                                                                 key = K_MOUSE1;
559                                                                 //Con_Printf(">> kEventMouseButtonPrimary <<\n");
560                                                                 break;
561                                                         case kEventMouseButtonSecondary:
562                                                                 key = K_MOUSE2;
563                                                                 //Con_Printf(">> kEventMouseButtonSecondary <<\n");
564                                                                 break;
565                                                         case kEventMouseButtonTertiary:
566                                                                 key = K_MOUSE3;
567                                                                 //Con_Printf(">> kEventMouseButtonTertiary <<\n");
568                                                                 break;
569                                                 }
570                                                 Key_Event(key, '\0', eventKind == kEventMouseDown);
571                                                 break;
572
573                                         case kEventMouseMoved:
574                                         {
575                                                 HIPoint deltaPos;
576
577                                                 GetEventParameter(theEvent, kEventParamMouseDelta, typeHIPoint, NULL, sizeof(deltaPos), NULL, &deltaPos);
578                                                 //Con_Printf(">> kEventMouseMoved (%f, %f) <<\n", deltaPos.x, deltaPos.y);
579
580                                                 mouse_x += deltaPos.x;
581                                                 mouse_y += deltaPos.y;
582                                                 break;
583                                         }
584
585                                         case kEventMouseWheelMoved:
586                                         {
587                                                 SInt32 delta;
588                                                 unsigned int wheelEvent;
589
590                                                 GetEventParameter(theEvent, kEventParamMouseWheelDelta, typeSInt32, NULL, sizeof(delta), NULL, &delta);
591                                                 //Con_Printf(">> kEventMouseWheelMoved (delta: %d) <<\n", delta);
592
593                                                 wheelEvent = (delta > 0) ? K_MWHEELUP : K_MWHEELDOWN;
594                                                 Key_Event(wheelEvent, 0, true);
595                                                 Key_Event(wheelEvent, 0, false);
596                                                 break;
597                                         }
598
599                                         case kEventMouseDragged:
600                                                 //Con_Printf(">> kEventMouseDragged <<\n");
601                                                 break;
602
603                                         default:
604                                                 Con_Printf (">> kEventClassMouse (UNKNOWN eventKind: %d) <<\n", eventKind);
605                                                 break;
606                                 }
607                         }
608
609                         case kEventClassKeyboard:
610                         {
611                                 char keycode;
612
613                                 switch (eventKind)
614                                 {
615                                         case kEventRawKeyDown:
616                                                 GetEventParameter(theEvent, kEventParamKeyMacCharCodes, typeChar, NULL, sizeof(keycode), NULL, &keycode);
617                                                 Handle_Key(keycode, true);
618                                                 //Con_Printf(">> kEventRawKeyDown (%d) <<\n", keycode);
619                                                 break;
620
621                                         case kEventRawKeyRepeat:
622                                                 //Con_Printf(">> kEventRawKeyRepeat <<\n");
623                                                 break;
624
625                                         case kEventRawKeyUp:
626                                                 GetEventParameter(theEvent, kEventParamKeyMacCharCodes, typeChar, NULL, sizeof(keycode), NULL, &keycode);
627                                                 Handle_Key(keycode, false);
628                                                 //Con_Printf(">> kEventRawKeyUp (%d) <<\n", keycode);
629                                                 break;
630
631                                         case kEventRawKeyModifiersChanged:
632                                         {
633                                                 UInt32 keymod = 0;
634                                                 GetEventParameter(theEvent, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(keymod), NULL, &keymod);
635                                                 Handle_KeyMod(keymod);
636                                                 //Con_Printf(">> kEventRawKeyModifiersChanged (0x%08X) <<\n", keymod);
637                                                 break;
638                                         }
639
640                                         case kEventHotKeyPressed:
641                                                 //Con_Printf(">> kEventHotKeyPressed <<\n");
642                                                 break;
643
644                                         case kEventHotKeyReleased:
645                                                 //Con_Printf(">> kEventHotKeyReleased <<\n");
646                                                 break;
647
648                                         case kEventMouseWheelMoved:
649                                                 //Con_Printf(">> kEventMouseWheelMoved - via a keyboard event (!?) <<\n");
650                                                 break;
651
652                                         default:
653                                                 Con_Printf (">> kEventClassKeyboard (UNKNOWN eventKind: %d) <<\n", eventKind);
654                                                 break;
655                                 }
656                                 break;
657                         }
658
659                         case kEventClassTextInput:
660                                 Con_Printf(">> kEventClassTextInput (%d) <<\n", eventKind);
661                                 break;
662
663                         case kEventClassApplication:
664                                 switch (eventKind)
665                                 {
666                                         case kEventAppActivated :
667                                                 //Con_Printf(">> kEventAppActivated <<\n");
668                                                 vid_activewindow = true;
669                                                 break;
670                                         case kEventAppDeactivated:
671                                                 //Con_Printf(">> kEventAppDeactivated <<\n");
672                                                 vid_activewindow = false;
673                                                 VID_RestoreSystemGamma();
674                                                 break;
675                                         case kEventAppQuit:
676                                                 //Con_Printf(">> kEventAppQuit <<\n");
677                                                 Sys_Quit();
678                                                 break;
679                                         case kEventAppActiveWindowChanged:
680                                                 //Con_Printf(">> kEventAppActiveWindowChanged <<\n");
681                                                 break;
682                                         default:
683                                                 Con_Printf(">> kEventClassApplication (UNKNOWN eventKind: %d) <<\n", eventKind);
684                                                 break;
685                                 }
686                                 break;
687
688                         case kEventClassAppleEvent:
689                                 switch (eventKind)
690                                 {
691                                         case kEventAppleEvent :
692                                                 //Con_Printf(">> kEventAppleEvent <<\n");
693                                                 break;
694                                         default:
695                                                 Con_Printf(">> kEventClassAppleEvent (UNKNOWN eventKind: %d) <<\n", eventKind);
696                                                 break;
697                                 }
698                                 break;
699
700                         case kEventClassWindow:
701                                 switch (eventKind)
702                                 {
703                                         case kEventWindowUpdate :
704                                                 //Con_Printf(">> kEventWindowUpdate <<\n");
705                                                 break;
706                                         default:
707                                                 Con_Printf(">> kEventClassWindow (UNKNOWN eventKind: %d) <<\n", eventKind);
708                                                 break;
709                                 }
710                                 break;
711
712                         case kEventClassControl:
713                                 //Con_Printf(">> kEventClassControl (%d) <<\n", eventKind);
714                                 break;
715
716                         default:
717                                 /*Con_Printf(">> UNKNOWN eventClass: %c%c%c%c, eventKind: %d <<\n",
718                                                         eventClass >> 24, (eventClass >> 16) & 0xFF,
719                                                         (eventClass >> 8) & 0xFF, eventClass & 0xFF,
720                                                         eventKind);*/
721                                 break;
722                 }
723
724                 SendEventToEventTarget (theEvent, theTarget);
725                 ReleaseEvent(theEvent);
726         }
727 }
728
729 void IN_Move (void)
730 {
731         if (mouse_avail)
732         {
733                 in_mouse_x = mouse_x;
734                 in_mouse_y = mouse_y;
735         }
736         mouse_x = 0;
737         mouse_y = 0;
738 }