1 /* $XdotOrg: xc/programs/Xserver/hw/darwin/quartz/quartzCocoa.m,v 1.2 2004/04/23 19:15:17 eich Exp $ */
2 /**************************************************************
4 * Quartz-specific support for the Darwin X Server
5 * that requires Cocoa and Objective-C.
7 * This file is separate from the parts of Quartz support
8 * that use X include files to avoid symbol collisions.
10 **************************************************************/
12 * Copyright (c) 2001-2004 Torrey T. Lyons and Greg Parker.
13 * All Rights Reserved.
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:
22 * The above copyright notice and this permission notice shall be included in
23 * all copies or substantial portions of the Software.
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.
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.
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>
42 #include "quartzCommon.h"
48 #include <Cocoa/Cocoa.h>
50 #import "Preferences.h"
51 #include "pseudoramiX.h"
53 extern void FatalError(const char *, ...);
55 extern int noPanoramiXExtension;
59 * QuartzReadPreferences
60 * Read the user preferences from the Cocoa front end.
62 void QuartzReadPreferences(void)
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
75 // Use PseudoramiX instead of Xinerama
76 noPanoramiXExtension = TRUE;
77 noPseudoramiXExtension = ![Preferences xinerama];
79 quartzUseAGL = [Preferences useAGL];
81 noPanoramiXExtension = ![Preferences xinerama];
82 noPseudoramiXExtension = TRUE;
84 // Full screen can't use AGL for GLX
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);
96 display = (char *) malloc(8);
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.
109 void QuartzWriteCocoaPasteboard(
112 NSPasteboard *pasteboard;
113 NSArray *pasteboardTypes;
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.
134 char *QuartzReadCocoaPasteboard(void)
136 NSPasteboard *pasteboard;
137 NSArray *pasteboardTypes;
138 NSString *existingType;
141 pasteboardTypes = [NSArray arrayWithObject:NSStringPboardType];
142 pasteboard = [NSPasteboard generalPasteboard];
143 if (! pasteboard) return NULL;
145 existingType = [pasteboard availableTypeFromArray:pasteboardTypes];
147 NSString *string = [pasteboard stringForType:existingType];
150 if (! string) return NULL;
151 buffer = (char *) [string lossyCString];
152 text = (char *) malloc(strlen(buffer)+1);
154 strcpy(text, buffer);
162 * QuartzFSUseQDCursor
163 * Return whether the screen should use a QuickDraw cursor.
165 int QuartzFSUseQDCursor(
166 int depth) // screen depth
168 switch ([Preferences useQDCursor]) {
169 case qdCursor_Always:
173 case qdCursor_Not8Bit:
185 * Clean out any autoreleased objects.
187 void QuartzBlockHandler(
192 static NSAutoreleasePool *aPool = nil;
195 aPool = [[NSAutoreleasePool alloc] init];
200 * QuartzWakeupHandler
202 void QuartzWakeupHandler(