1 /* $XFree86: xc/lib/GL/dri/XF86dri.c,v 1.12 2001/08/27 17:40:57 dawes Exp $ */
2 /**************************************************************************
4 Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
5 Copyright 2000 VA Linux Systems, Inc.
6 Copyright (c) 2002 Apple Computer, Inc.
9 Permission is hereby granted, free of charge, to any person obtaining a
10 copy of this software and associated documentation files (the
11 "Software"), to deal in the Software without restriction, including
12 without limitation the rights to use, copy, modify, merge, publish,
13 distribute, sub license, and/or sell copies of the Software, and to
14 permit persons to whom the Software is furnished to do so, subject to
15 the following conditions:
17 The above copyright notice and this permission notice (including the
18 next paragraph) shall be included in all copies or substantial portions
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
24 IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
25 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
26 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
27 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 **************************************************************************/
31 /* THIS IS NOT AN X CONSORTIUM STANDARD */
35 #include <X11/Xlibint.h>
36 #include "applewmstr.h"
37 #include <X11/extensions/Xext.h>
41 static XExtensionInfo _applewm_info_data;
42 static XExtensionInfo *applewm_info = &_applewm_info_data;
43 static char *applewm_extension_name = APPLEWMNAME;
45 #define AppleWMCheckExtension(dpy,i,val) \
46 XextCheckExtension (dpy, i, applewm_extension_name, val)
48 /*****************************************************************************
50 * private utility routines *
52 *****************************************************************************/
54 static int close_display(Display *dpy, XExtCodes *extCodes);
55 static Bool wire_to_event();
56 static Status event_to_wire();
58 static /* const */ XExtensionHooks applewm_extension_hooks = {
63 NULL, /* create_font */
65 close_display, /* close_display */
66 wire_to_event, /* wire_to_event */
67 event_to_wire, /* event_to_wire */
69 NULL, /* error_string */
72 static XEXT_GENERATE_FIND_DISPLAY (find_display, applewm_info,
73 applewm_extension_name,
74 &applewm_extension_hooks,
75 AppleWMNumberEvents, NULL)
77 static XEXT_GENERATE_CLOSE_DISPLAY (close_display, applewm_info)
79 static Bool wire_to_event (dpy, re, event)
84 XExtDisplayInfo *info = find_display (dpy);
85 XAppleWMNotifyEvent *se;
86 xAppleWMNotifyEvent *sevent;
88 AppleWMCheckExtension (dpy, info, False);
90 switch ((event->u.u.type & 0x7f) - info->codes->first_event) {
91 case AppleWMControllerNotify:
92 case AppleWMActivationNotify:
93 case AppleWMPasteboardNotify:
94 se = (XAppleWMNotifyEvent *) re;
95 sevent = (xAppleWMNotifyEvent *) event;
96 se->type = sevent->type & 0x7f;
97 se->serial = _XSetLastRequestRead(dpy,(xGenericReply *) event);
98 se->send_event = (sevent->type & 0x80) != 0;
101 se->time = sevent->time;
102 se->kind = sevent->kind;
103 se->arg = sevent->arg;
109 static Status event_to_wire (dpy, re, event)
114 XExtDisplayInfo *info = find_display (dpy);
115 XAppleWMNotifyEvent *se;
116 xAppleWMNotifyEvent *sevent;
118 AppleWMCheckExtension (dpy, info, False);
120 switch ((re->type & 0x7f) - info->codes->first_event) {
121 case AppleWMControllerNotify:
122 case AppleWMActivationNotify:
123 case AppleWMPasteboardNotify:
124 se = (XAppleWMNotifyEvent *) re;
125 sevent = (xAppleWMNotifyEvent *) event;
126 sevent->type = se->type | (se->send_event ? 0x80 : 0);
127 sevent->sequenceNumber = se->serial & 0xffff;
128 sevent->kind = se->kind;
129 sevent->arg = se->arg;
130 sevent->time = se->time;
136 /*****************************************************************************
138 * public Apple-WM Extension routines *
140 *****************************************************************************/
144 #define TRACE(msg) fprintf(stderr, "AppleWM%s\n", msg);
150 Bool XAppleWMQueryExtension (dpy, event_basep, error_basep)
152 int *event_basep, *error_basep;
154 XExtDisplayInfo *info = find_display (dpy);
156 TRACE("QueryExtension...");
157 if (XextHasExtension(info)) {
158 *event_basep = info->codes->first_event;
159 *error_basep = info->codes->first_error;
160 TRACE("QueryExtension... return True");
163 TRACE("QueryExtension... return False");
168 Bool XAppleWMQueryVersion(dpy, majorVersion, minorVersion, patchVersion)
174 XExtDisplayInfo *info = find_display (dpy);
175 xAppleWMQueryVersionReply rep;
176 xAppleWMQueryVersionReq *req;
178 TRACE("QueryVersion...");
179 AppleWMCheckExtension (dpy, info, False);
182 GetReq(AppleWMQueryVersion, req);
183 req->reqType = info->codes->major_opcode;
184 req->wmReqType = X_AppleWMQueryVersion;
185 if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
188 TRACE("QueryVersion... return False");
191 *majorVersion = rep.majorVersion;
192 *minorVersion = rep.minorVersion;
193 *patchVersion = rep.patchVersion;
196 TRACE("QueryVersion... return True");
200 Bool XAppleWMDisableUpdate(dpy, screen)
204 XExtDisplayInfo *info = find_display (dpy);
205 xAppleWMDisableUpdateReq *req;
207 TRACE("DisableUpdate...");
208 AppleWMCheckExtension (dpy, info, False);
211 GetReq(AppleWMDisableUpdate, req);
212 req->reqType = info->codes->major_opcode;
213 req->wmReqType = X_AppleWMDisableUpdate;
214 req->screen = screen;
217 TRACE("DisableUpdate... return True");
221 Bool XAppleWMReenableUpdate(dpy, screen)
225 XExtDisplayInfo *info = find_display (dpy);
226 xAppleWMReenableUpdateReq *req;
228 TRACE("ReenableUpdate...");
229 AppleWMCheckExtension (dpy, info, False);
232 GetReq(AppleWMReenableUpdate, req);
233 req->reqType = info->codes->major_opcode;
234 req->wmReqType = X_AppleWMReenableUpdate;
235 req->screen = screen;
238 TRACE("ReenableUpdate... return True");
242 Bool XAppleWMSelectInput(dpy, mask)
246 XExtDisplayInfo *info = find_display (dpy);
247 xAppleWMSelectInputReq *req;
249 TRACE("SelectInput...");
250 AppleWMCheckExtension (dpy, info, False);
253 GetReq(AppleWMSelectInput, req);
254 req->reqType = info->codes->major_opcode;
255 req->wmReqType = X_AppleWMSelectInput;
259 TRACE("SetlectInput... return True");
263 Bool XAppleWMSetWindowMenuWithShortcuts(dpy, nitems, items, shortcuts)
267 const char *shortcuts;
269 XExtDisplayInfo *info = find_display (dpy);
270 xAppleWMSetWindowMenuReq *req;
271 int i, total_length, len;
274 TRACE("SetWindowMenu...");
275 AppleWMCheckExtension (dpy, info, False);
278 GetReq(AppleWMSetWindowMenu, req);
279 req->reqType = info->codes->major_opcode;
280 req->wmReqType = X_AppleWMSetWindowMenu;
281 req->nitems = nitems;
284 for (i = 0; i < nitems; i++)
285 total_length += strlen (items[i]) + 2;
287 ptr = buf = alloca (total_length);
288 for (i = 0; i < nitems; i++)
290 len = strlen (items[i]);
291 *ptr++ = shortcuts ? shortcuts[i] : 0;
292 memcpy (ptr, items[i], len);
297 req->length += (total_length + 3) >> 2;
298 Data (dpy, buf, total_length);
302 TRACE("SetlectInput... return True");
306 Bool XAppleWMSetWindowMenu(dpy, nitems, items)
311 return XAppleWMSetWindowMenuWithShortcuts (dpy, nitems, items, NULL);
314 Bool XAppleWMSetWindowMenuCheck(dpy, idx)
318 XExtDisplayInfo *info = find_display (dpy);
319 xAppleWMSetWindowMenuCheckReq *req;
321 TRACE("SetWindowMenuCheck...");
322 AppleWMCheckExtension (dpy, info, False);
325 GetReq(AppleWMSetWindowMenuCheck, req);
326 req->reqType = info->codes->major_opcode;
327 req->wmReqType = X_AppleWMSetWindowMenuCheck;
331 TRACE("SetWindowMenuCheck... return True");
335 Bool XAppleWMSetFrontProcess(dpy)
338 XExtDisplayInfo *info = find_display (dpy);
339 xAppleWMSetFrontProcessReq *req;
341 TRACE("SetFrontProcess...");
342 AppleWMCheckExtension (dpy, info, False);
345 GetReq(AppleWMSetFrontProcess, req);
346 req->reqType = info->codes->major_opcode;
347 req->wmReqType = X_AppleWMSetFrontProcess;
350 TRACE("SetFrontProcess... return True");
354 Bool XAppleWMSetWindowLevel(dpy, id, level)
359 XExtDisplayInfo *info = find_display (dpy);
360 xAppleWMSetWindowLevelReq *req;
362 TRACE("SetWindowLevel...");
363 AppleWMCheckExtension (dpy, info, False);
366 GetReq(AppleWMSetWindowLevel, req);
367 req->reqType = info->codes->major_opcode;
368 req->wmReqType = X_AppleWMSetWindowLevel;
373 TRACE("SetWindowLevel... return True");
377 Bool XAppleWMSetCanQuit(dpy, state)
381 XExtDisplayInfo *info = find_display (dpy);
382 xAppleWMSetCanQuitReq *req;
384 TRACE("SetCanQuit...");
385 AppleWMCheckExtension (dpy, info, False);
388 GetReq(AppleWMSetCanQuit, req);
389 req->reqType = info->codes->major_opcode;
390 req->wmReqType = X_AppleWMSetCanQuit;
394 TRACE("SetCanQuit... return True");
398 Bool XAppleWMFrameGetRect(dpy, frame_class, frame_rect,
399 ix, iy, iw, ih, ox, oy, ow, oh, rx, ry, rw, rh)
401 unsigned int frame_class, frame_rect;
402 short ix, iy, iw, ih;
403 short ox, oy, ow, oh;
404 short *rx, *ry, *rw, *rh;
406 XExtDisplayInfo *info = find_display (dpy);
407 xAppleWMFrameGetRectReply rep;
408 xAppleWMFrameGetRectReq *req;
410 TRACE("FrameGetRect...");
411 AppleWMCheckExtension (dpy, info, False);
414 GetReq(AppleWMFrameGetRect, req);
415 req->reqType = info->codes->major_opcode;
416 req->wmReqType = X_AppleWMFrameGetRect;
417 req->frame_class = frame_class;
418 req->frame_rect = frame_rect;
427 rep.x = rep.y = rep.w = rep.h = 0;
428 if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
431 TRACE("FrameGetRect... return False");
434 *rx = rep.x; *ry = rep.y;
435 *rw = rep.w; *rh = rep.h;
438 TRACE("FrameGetRect... return True");
442 unsigned int XAppleWMFrameHitTest(dpy, frame_class, px, py,
443 ix, iy, iw, ih, ox, oy, ow, oh)
445 unsigned int frame_class;
447 short ix, iy, iw, ih;
448 short ox, oy, ow, oh;
450 XExtDisplayInfo *info = find_display (dpy);
451 xAppleWMFrameHitTestReply rep;
452 xAppleWMFrameHitTestReq *req;
454 TRACE("FrameHitTest...");
455 AppleWMCheckExtension (dpy, info, False);
458 GetReq(AppleWMFrameHitTest, req);
459 req->reqType = info->codes->major_opcode;
460 req->wmReqType = X_AppleWMFrameHitTest;
461 req->frame_class = frame_class;
473 if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
476 TRACE("FrameHitTest... return False");
481 TRACE("FrameHiTest... return True");
485 Bool XAppleWMFrameDraw(dpy, screen, window,
486 frame_class, frame_attr,
487 ix, iy, iw, ih, ox, oy, ow, oh,
488 title_length, title_bytes)
492 unsigned int frame_class, frame_attr;
493 short ix, iy, iw, ih;
494 short ox, oy, ow, oh;
495 unsigned int title_length;
496 const unsigned char *title_bytes;
498 XExtDisplayInfo *info = find_display (dpy);
499 xAppleWMFrameDrawReq *req;
501 TRACE("FrameDraw...");
502 AppleWMCheckExtension (dpy, info, False);
505 GetReq(AppleWMFrameDraw, req);
506 req->reqType = info->codes->major_opcode;
507 req->wmReqType = X_AppleWMFrameDraw;
508 req->screen = screen;
509 req->window = window;
510 req->frame_class = frame_class;
511 req->frame_attr = frame_attr;
520 req->title_length = title_length;
522 req->length += (title_length + 3)>>2;
523 Data (dpy, title_bytes, title_length);
527 TRACE("FrameDraw... return True");