Fixed black screen when using fullscreen mode on Mac OS X
[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         if (context == NULL)
382                 Sys_Error ("aglCreateContext failed");
383         if (fullscreen)
384         {
385                 if (!qaglSetFullScreen (context, width, height, 0, 0))
386                         Sys_Error("aglSetFullScreen failed");
387                 vid_isfullscreen = true;
388         }
389         else
390         {
391                 if (!qaglSetDrawable(context, GetWindowPort(window)))
392                         Sys_Error ("aglSetDrawable failed");
393         }
394         if (!qaglSetCurrentContext(context))
395                 Sys_Error ("aglSetCurrentContext failed");
396         qaglDestroyPixelFormat(pixelFormat);
397
398         scr_width = width;
399         scr_height = height;
400
401         if ((qglGetString = (const GLubyte* (GLAPIENTRY *)(GLenum name))GL_GetProcAddress("glGetString")) == NULL)
402                 Sys_Error("glGetString not found in %s", gl_driver);
403
404         gl_renderer = (const char *)qglGetString(GL_RENDERER);
405         gl_vendor = (const char *)qglGetString(GL_VENDOR);
406         gl_version = (const char *)qglGetString(GL_VERSION);
407         gl_extensions = (const char *)qglGetString(GL_EXTENSIONS);
408         gl_platform = "AGL";
409         gl_videosyncavailable = false;
410
411         vid_usingmouse = false;
412         vid_hidden = false;
413         vid_activewindow = true;
414         GL_Init();
415
416         SelectWindow(window);
417         ShowWindow(window);
418
419         return true;
420 }
421
422 static void Handle_KeyMod(UInt32 keymod)
423 {
424         static UInt32 prev_keymod = 0;
425         UInt32 modChanges = prev_keymod ^ keymod;
426
427         if ((modChanges & cmdKey) != 0)
428         {
429                 Key_Event(K_AUX1, '\0', (keymod & cmdKey) != 0);
430         }
431         if ((modChanges & shiftKey) != 0 || (modChanges & rightShiftKey) != 0)
432         {
433                 Key_Event(K_SHIFT, '\0', (keymod & shiftKey) != 0);
434         }
435         if ((modChanges & alphaLock) != 0)
436         {
437                 Key_Event(K_CAPSLOCK, '\0', (keymod & alphaLock) != 0);
438         }
439         if ((modChanges & optionKey) != 0 || (modChanges & rightOptionKey) != 0)
440         {
441                 Key_Event(K_ALT, '\0', (keymod & optionKey) != 0);
442         }
443         if ((modChanges & controlKey) != 0 || (modChanges & rightControlKey) != 0)
444         {
445                 Key_Event(K_CTRL, '\0', (keymod & controlKey) != 0);
446         }
447         if ((modChanges & kEventKeyModifierNumLockMask) != 0)
448         {
449                 Key_Event(K_NUMLOCK, '\0', (keymod & kEventKeyModifierNumLockMask) != 0);
450         }
451         if ((modChanges & kEventKeyModifierFnMask) != 0)
452         {
453                 Key_Event(K_AUX2, '\0', (keymod & kEventKeyModifierFnMask) != 0);
454         }
455
456         prev_keymod = keymod;
457 }
458
459 static void Handle_Key(unsigned char charcode, qboolean keypressed)
460 {
461         unsigned int keycode = 0;
462         char ascii = '\0';
463
464         switch (charcode)
465         {
466                 case kHomeCharCode:
467                         keycode = K_HOME;
468                         break;
469                 case kEnterCharCode:
470                         keycode = K_KP_ENTER;
471                         break;
472                 case kEndCharCode:
473                         keycode = K_END;
474                         break;
475                 case kBackspaceCharCode:
476                         keycode = K_BACKSPACE;
477                         break;
478                 case kTabCharCode:
479                         keycode = K_TAB;
480                         break;
481                 case kPageUpCharCode:
482                         keycode = K_PGUP;
483                         break;
484                 case kPageDownCharCode:
485                         keycode = K_PGDN;
486                         break;
487                 case kReturnCharCode:
488                         keycode = K_ENTER;
489                         break;
490                 case kEscapeCharCode:
491                         keycode = K_ESCAPE;
492                         break;
493                 case kLeftArrowCharCode:
494                         keycode = K_LEFTARROW;
495                         break;
496                 case kRightArrowCharCode:
497                         keycode = K_RIGHTARROW;
498                         break;
499                 case kUpArrowCharCode:
500                         keycode = K_UPARROW;
501                         break;
502                 case kDownArrowCharCode :
503                         keycode = K_DOWNARROW;
504                         break;
505                 case kDeleteCharCode:
506                         keycode = K_DEL;
507                         break;
508                 case 191:
509                         // char 191 is sent by the mouse buttons (?!)
510                         break;
511                 default:
512                         if ('A' <= charcode && charcode <= 'Z')
513                         {
514                                 keycode = charcode + ('a' - 'A');  // lowercase it
515                                 ascii = charcode;
516                         }
517                         else if (32 <= charcode && charcode <= 126)
518                         {
519                                 keycode = charcode;
520                                 ascii = charcode;
521                         }
522                         else
523                                 Con_Printf(">> UNKNOWN charcode: %d <<\n", charcode);
524         }
525
526         if (keycode != 0)
527                 Key_Event(keycode, ascii, keypressed);
528 }
529
530 void Sys_SendKeyEvents(void)
531 {
532         EventRef theEvent;
533         EventTargetRef theTarget;
534
535         // Start by processing the asynchronous events we received since the previous frame
536         VID_ProcessPendingAsyncEvents();
537
538         theTarget = GetEventDispatcherTarget();
539         while (ReceiveNextEvent(0, NULL, kEventDurationNoWait, true, &theEvent) == noErr)
540         {
541                 UInt32 eventClass = GetEventClass(theEvent);
542                 UInt32 eventKind = GetEventKind(theEvent);
543
544                 switch (eventClass)
545                 {
546                         case kEventClassMouse:
547                         {
548                                 EventMouseButton theButton;
549                                 int key;
550
551                                 switch (eventKind)
552                                 {
553                                         case kEventMouseDown:
554                                         case kEventMouseUp:
555                                                 GetEventParameter(theEvent, kEventParamMouseButton, typeMouseButton, NULL, sizeof(theButton), NULL, &theButton);
556                                                 switch (theButton)
557                                                 {
558                                                         default:
559                                                         case kEventMouseButtonPrimary:
560                                                                 key = K_MOUSE1;
561                                                                 //Con_Printf(">> kEventMouseButtonPrimary <<\n");
562                                                                 break;
563                                                         case kEventMouseButtonSecondary:
564                                                                 key = K_MOUSE2;
565                                                                 //Con_Printf(">> kEventMouseButtonSecondary <<\n");
566                                                                 break;
567                                                         case kEventMouseButtonTertiary:
568                                                                 key = K_MOUSE3;
569                                                                 //Con_Printf(">> kEventMouseButtonTertiary <<\n");
570                                                                 break;
571                                                 }
572                                                 Key_Event(key, '\0', eventKind == kEventMouseDown);
573                                                 break;
574
575                                         case kEventMouseMoved:
576                                         {
577                                                 HIPoint deltaPos;
578
579                                                 GetEventParameter(theEvent, kEventParamMouseDelta, typeHIPoint, NULL, sizeof(deltaPos), NULL, &deltaPos);
580                                                 //Con_Printf(">> kEventMouseMoved (%f, %f) <<\n", deltaPos.x, deltaPos.y);
581
582                                                 mouse_x += deltaPos.x;
583                                                 mouse_y += deltaPos.y;
584                                                 break;
585                                         }
586
587                                         case kEventMouseWheelMoved:
588                                         {
589                                                 SInt32 delta;
590                                                 unsigned int wheelEvent;
591
592                                                 GetEventParameter(theEvent, kEventParamMouseWheelDelta, typeSInt32, NULL, sizeof(delta), NULL, &delta);
593                                                 //Con_Printf(">> kEventMouseWheelMoved (delta: %d) <<\n", delta);
594
595                                                 wheelEvent = (delta > 0) ? K_MWHEELUP : K_MWHEELDOWN;
596                                                 Key_Event(wheelEvent, 0, true);
597                                                 Key_Event(wheelEvent, 0, false);
598                                                 break;
599                                         }
600
601                                         case kEventMouseDragged:
602                                                 //Con_Printf(">> kEventMouseDragged <<\n");
603                                                 break;
604
605                                         default:
606                                                 Con_Printf (">> kEventClassMouse (UNKNOWN eventKind: %d) <<\n", eventKind);
607                                                 break;
608                                 }
609                         }
610
611                         case kEventClassKeyboard:
612                         {
613                                 char keycode;
614
615                                 switch (eventKind)
616                                 {
617                                         case kEventRawKeyDown:
618                                                 GetEventParameter(theEvent, kEventParamKeyMacCharCodes, typeChar, NULL, sizeof(keycode), NULL, &keycode);
619                                                 Handle_Key(keycode, true);
620                                                 //Con_Printf(">> kEventRawKeyDown (%d) <<\n", keycode);
621                                                 break;
622
623                                         case kEventRawKeyRepeat:
624                                                 //Con_Printf(">> kEventRawKeyRepeat <<\n");
625                                                 break;
626
627                                         case kEventRawKeyUp:
628                                                 GetEventParameter(theEvent, kEventParamKeyMacCharCodes, typeChar, NULL, sizeof(keycode), NULL, &keycode);
629                                                 Handle_Key(keycode, false);
630                                                 //Con_Printf(">> kEventRawKeyUp (%d) <<\n", keycode);
631                                                 break;
632
633                                         case kEventRawKeyModifiersChanged:
634                                         {
635                                                 UInt32 keymod = 0;
636                                                 GetEventParameter(theEvent, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(keymod), NULL, &keymod);
637                                                 Handle_KeyMod(keymod);
638                                                 //Con_Printf(">> kEventRawKeyModifiersChanged (0x%08X) <<\n", keymod);
639                                                 break;
640                                         }
641
642                                         case kEventHotKeyPressed:
643                                                 //Con_Printf(">> kEventHotKeyPressed <<\n");
644                                                 break;
645
646                                         case kEventHotKeyReleased:
647                                                 //Con_Printf(">> kEventHotKeyReleased <<\n");
648                                                 break;
649
650                                         case kEventMouseWheelMoved:
651                                                 //Con_Printf(">> kEventMouseWheelMoved - via a keyboard event (!?) <<\n");
652                                                 break;
653
654                                         default:
655                                                 Con_Printf (">> kEventClassKeyboard (UNKNOWN eventKind: %d) <<\n", eventKind);
656                                                 break;
657                                 }
658                                 break;
659                         }
660
661                         case kEventClassTextInput:
662                                 Con_Printf(">> kEventClassTextInput (%d) <<\n", eventKind);
663                                 break;
664
665                         case kEventClassApplication:
666                                 switch (eventKind)
667                                 {
668                                         case kEventAppActivated :
669                                                 //Con_Printf(">> kEventAppActivated <<\n");
670                                                 vid_activewindow = true;
671                                                 break;
672                                         case kEventAppDeactivated:
673                                                 //Con_Printf(">> kEventAppDeactivated <<\n");
674                                                 vid_activewindow = false;
675                                                 VID_RestoreSystemGamma();
676                                                 break;
677                                         case kEventAppQuit:
678                                                 //Con_Printf(">> kEventAppQuit <<\n");
679                                                 Sys_Quit();
680                                                 break;
681                                         case kEventAppActiveWindowChanged:
682                                                 //Con_Printf(">> kEventAppActiveWindowChanged <<\n");
683                                                 break;
684                                         default:
685                                                 Con_Printf(">> kEventClassApplication (UNKNOWN eventKind: %d) <<\n", eventKind);
686                                                 break;
687                                 }
688                                 break;
689
690                         case kEventClassAppleEvent:
691                                 switch (eventKind)
692                                 {
693                                         case kEventAppleEvent :
694                                                 //Con_Printf(">> kEventAppleEvent <<\n");
695                                                 break;
696                                         default:
697                                                 Con_Printf(">> kEventClassAppleEvent (UNKNOWN eventKind: %d) <<\n", eventKind);
698                                                 break;
699                                 }
700                                 break;
701
702                         case kEventClassWindow:
703                                 switch (eventKind)
704                                 {
705                                         case kEventWindowUpdate :
706                                                 //Con_Printf(">> kEventWindowUpdate <<\n");
707                                                 break;
708                                         default:
709                                                 Con_Printf(">> kEventClassWindow (UNKNOWN eventKind: %d) <<\n", eventKind);
710                                                 break;
711                                 }
712                                 break;
713
714                         case kEventClassControl:
715                                 //Con_Printf(">> kEventClassControl (%d) <<\n", eventKind);
716                                 break;
717
718                         default:
719                                 /*Con_Printf(">> UNKNOWN eventClass: %c%c%c%c, eventKind: %d <<\n",
720                                                         eventClass >> 24, (eventClass >> 16) & 0xFF,
721                                                         (eventClass >> 8) & 0xFF, eventClass & 0xFF,
722                                                         eventKind);*/
723                                 break;
724                 }
725
726                 SendEventToEventTarget (theEvent, theTarget);
727                 ReleaseEvent(theEvent);
728         }
729 }
730
731 void IN_Move (void)
732 {
733         if (mouse_avail)
734         {
735                 in_mouse_x = mouse_x;
736                 in_mouse_y = mouse_y;
737         }
738         mouse_x = 0;
739         mouse_y = 0;
740 }