Initial commit
[xorg_rtime.git] / xorg-server-1.4 / hw / darwin / quartz / quartzCocoa.m
blobc54c18acb3662aa8daa4f5ed83f2dece3fd9758b
1 /* $XdotOrg: xc/programs/Xserver/hw/darwin/quartz/quartzCocoa.m,v 1.2 2004/04/23 19:15:17 eich Exp $ */
2 /**************************************************************
3  *
4  * Quartz-specific support for the Darwin X Server
5  * that requires Cocoa and Objective-C.
6  *
7  * This file is separate from the parts of Quartz support
8  * that use X include files to avoid symbol collisions.
9  *
10  **************************************************************/
12  * Copyright (c) 2001-2004 Torrey T. Lyons and Greg Parker.
13  *                 All Rights Reserved.
14  *
15  * Permission is hereby granted, free of charge, to any person obtaining a
16  * copy of this software and associated documentation files (the "Software"),
17  * to deal in the Software without restriction, including without limitation
18  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
19  * and/or sell copies of the Software, and to permit persons to whom the
20  * Software is furnished to do so, subject to the following conditions:
21  *
22  * The above copyright notice and this permission notice shall be included in
23  * all copies or substantial portions of the Software.
24  *
25  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
28  * THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
29  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
30  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
31  * DEALINGS IN THE SOFTWARE.
32  *
33  * Except as contained in this notice, the name(s) of the above copyright
34  * holders shall not be used in advertising or otherwise to promote the sale,
35  * use or other dealings in this Software without prior written authorization.
36  */
37 /* $XFree86: xc/programs/Xserver/hw/darwin/quartz/quartzCocoa.m,v 1.5 2004/06/08 22:58:10 torrey Exp $ */
38 #ifdef HAVE_XORG_CONFIG_H
39 #include <xorg-config.h>
40 #endif
42 #include "quartzCommon.h"
44 #define BOOL xBOOL
45 #include "darwin.h"
46 #undef BOOL
48 #include <Cocoa/Cocoa.h>
50 #import "Preferences.h"
51 #include "pseudoramiX.h"
53 extern void FatalError(const char *, ...);
54 extern char *display;
55 extern int noPanoramiXExtension;
59  * QuartzReadPreferences
60  *  Read the user preferences from the Cocoa front end.
61  */
62 void QuartzReadPreferences(void)
64     char *fileString;
66     darwinFakeButtons = [Preferences fakeButtons];
67     darwinFakeMouse2Mask = [Preferences button2Mask];
68     darwinFakeMouse3Mask = [Preferences button3Mask];
69     darwinMouseAccelChange = [Preferences mouseAccelChange];
70     quartzUseSysBeep = [Preferences systemBeep];
71     quartzEnableKeyEquivalents = [Preferences enableKeyEquivalents];
73     // quartzRootless has already been set
74     if (quartzRootless) {
75         // Use PseudoramiX instead of Xinerama
76         noPanoramiXExtension = TRUE;
77         noPseudoramiXExtension = ![Preferences xinerama];
79         quartzUseAGL = [Preferences useAGL];
80     } else {
81         noPanoramiXExtension = ![Preferences xinerama];
82         noPseudoramiXExtension = TRUE;
84         // Full screen can't use AGL for GLX
85         quartzUseAGL = FALSE;
86     }
88     if ([Preferences useKeymapFile]) {
89         fileString = (char *) [[Preferences keymapFile] lossyCString];
90         darwinKeymapFile = (char *) malloc(strlen(fileString)+1);
91         if (! darwinKeymapFile)
92             FatalError("malloc failed in QuartzReadPreferences()!\n");
93         strcpy(darwinKeymapFile, fileString);
94     }
96     display = (char *) malloc(8);
97     if (! display)
98         FatalError("malloc failed in QuartzReadPreferences()!\n");
99     snprintf(display, 8, "%i", [Preferences display]);
101     darwinDesiredDepth = [Preferences depth] - 1;
106  * QuartzWriteCocoaPasteboard
107  *  Write text to the Mac OS X pasteboard.
108  */
109 void QuartzWriteCocoaPasteboard(
110     char *text)
112     NSPasteboard *pasteboard;
113     NSArray *pasteboardTypes;
114     NSString *string;
116     if (! text) return;
117     pasteboard = [NSPasteboard generalPasteboard];
118     if (! pasteboard) return;
119     string = [NSString stringWithCString:text];
120     if (! string) return;
121     pasteboardTypes = [NSArray arrayWithObject:NSStringPboardType];
123     // nil owner because we don't provide type translations
124     [pasteboard declareTypes:pasteboardTypes owner:nil];
125     [pasteboard setString:string forType:NSStringPboardType];
130  * QuartzReadCocoaPasteboard
131  *  Read text from the Mac OS X pasteboard and return it as a heap string.
132  *  The caller must free the string.
133  */
134 char *QuartzReadCocoaPasteboard(void)
136     NSPasteboard *pasteboard;
137     NSArray *pasteboardTypes;
138     NSString *existingType;
139     char *text = NULL;
141     pasteboardTypes = [NSArray arrayWithObject:NSStringPboardType];
142     pasteboard = [NSPasteboard generalPasteboard];
143     if (! pasteboard) return NULL;
145     existingType = [pasteboard availableTypeFromArray:pasteboardTypes];
146     if (existingType) {
147         NSString *string = [pasteboard stringForType:existingType];
148         char *buffer;
150         if (! string) return NULL;
151         buffer = (char *) [string lossyCString];
152         text = (char *) malloc(strlen(buffer)+1);
153         if (text)
154             strcpy(text, buffer);
155     }
157     return text;
162  * QuartzFSUseQDCursor
163  *  Return whether the screen should use a QuickDraw cursor.
164  */
165 int QuartzFSUseQDCursor(
166     int depth)  // screen depth
168     switch ([Preferences useQDCursor]) {
169         case qdCursor_Always:
170             return TRUE;
171         case qdCursor_Never:
172             return FALSE;
173         case qdCursor_Not8Bit:
174             if (depth > 8)
175                 return TRUE;
176             else
177                 return FALSE;
178     }
179     return TRUE;
184  * QuartzBlockHandler
185  *  Clean out any autoreleased objects.
186  */
187 void QuartzBlockHandler(
188     void *blockData,
189     void *pTimeout,
190     void *pReadmask)
192     static NSAutoreleasePool *aPool = nil;
194     [aPool release];
195     aPool = [[NSAutoreleasePool alloc] init];
200  * QuartzWakeupHandler
201  */
202 void QuartzWakeupHandler(
203     void *blockData,
204     int result,
205     void *pReadmask)
207     // nothing here