4 // This class handles the interaction between CG and the X server thread
7 * Copyright (c) 2001 Andreas Monitzer. All Rights Reserved.
8 * Copyright (c) 2002 Torrey T. Lyons. All Rights Reserved.
9 * Copyright (c) 2002 Apple Software, Inc. All Rights Reserved.
10 * Copyright (c) 2002 Apple Computer, Inc. All rights reserved.
12 * Permission is hereby granted, free of charge, to any person obtaining a
13 * copy of this software and associated documentation files (the
14 * "Software"), to deal in the Software without restriction, including
15 * without limitation the rights to use, copy, modify, merge, publish,
16 * distribute, sublicense, and/or sell copies of the Software, and to
17 * permit persons to whom the Software is furnished to do so, subject to
18 * the following conditions:
20 * The above copyright notice and this permission notice shall be included
21 * in all copies or substantial portions of the Software.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
26 * IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
27 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
28 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
29 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 * Except as contained in this notice, the name(s) of the above copyright
32 * holders shall not be used in advertising or otherwise to promote the
33 * sale, use or other dealings in this Software without prior written
36 /* $XFree86: xc/programs/Xserver/hw/darwin/quartz/XServer.m,v 1.3 2002/07/15 18:57:44 torrey Exp $ */
40 #include "X11Controller.h"
41 #define _APPLEDRI_SERVER_
43 #include "dri-surface.h"
50 char **envpGlobal; // argcGlobal and argvGlobal
51 // are from dix/globals.c
54 QuartzMessageMainThread (int type, int argc, ...)
61 memset (&xe, 0, sizeof (xe));
62 xe.u.u.type = ClientMessage;
63 xe.u.clientMessage.u.l.type = type;
65 argv = &xe.u.clientMessage.u.l.longs0;
68 if (argc > 0 && argc <= max_args)
70 va_start (args, argc);
71 for (i = 0; i < argc; i++)
72 argv[i] = (int) va_arg (args, int);
76 DarwinEnqueueEvent (&xe);
80 event_handler (unsigned int type, const void *arg,
81 unsigned int arg_size, void *data)
85 case XP_EVENT_DISPLAY_CHANGED:
86 QuartzMessageMainThread (kXquartzDisplayChanged, 0);
89 case XP_EVENT_WINDOW_STATE_CHANGED:
90 if (arg_size >= sizeof (xp_window_state_event))
92 const xp_window_state_event *ws_arg = arg;
93 QuartzMessageMainThread (kXquartzWindowState, 2,
94 ws_arg->id, ws_arg->state);
98 case XP_EVENT_WINDOW_MOVED:
99 if (arg_size == sizeof (xp_window_id))
101 xp_window_id id = * (xp_window_id *) arg;
103 QuartzMessageMainThread (kXquartzWindowMoved, 1, id);
107 case XP_EVENT_SURFACE_DESTROYED:
108 case XP_EVENT_SURFACE_CHANGED:
109 if (arg_size == sizeof (xp_surface_id))
113 if (type == XP_EVENT_SURFACE_DESTROYED)
114 kind = AppleDRISurfaceNotifyDestroyed;
116 kind = AppleDRISurfaceNotifyChanged;
118 DRISurfaceNotify (*(xp_surface_id *) arg, kind);
125 server_thread (void *arg)
127 extern int main (int argc, char **argv, char **envp);
129 /* Xinerama defaults to enabled */
130 noPanoramiXExtension = FALSE;
132 if (xp_init (XP_BACKGROUND_EVENTS | quartzXpluginOptions) != Success)
134 fprintf (stderr, "can't initialize window system\n");
138 xp_select_events (XP_EVENT_DISPLAY_CHANGED
139 | XP_EVENT_WINDOW_STATE_CHANGED
140 | XP_EVENT_WINDOW_MOVED
141 | XP_EVENT_SURFACE_CHANGED
142 | XP_EVENT_SURFACE_DESTROYED,
143 event_handler, NULL);
145 exit (main (argcGlobal, argvGlobal, envpGlobal));
150 * This function is called first from main(). We use it to connect to
151 * the cg window server and spawn the the thread that will listen for
154 void DarwinHandleGUI(
159 static Bool here_before;
161 extern void _InitHLTB (void);
168 DarwinInputPreInit ();
170 // Store command line arguments to pass back to main()
175 /* Initially I ran the X server on the main thread, and received
176 events on the second thread. But now we may be using Carbon,
177 that needs to run on the main thread. (Otherwise, when it's
178 prebound, it will initialize itself on the wrong thread)
180 grr.. but doing that means that if the X thread gets scheduled
181 before the main thread when we're _not_ prebound, things fail,
182 so initialize by hand. */
186 X11ControllerMain (argc, argv, server_thread, NULL);