XLbx.c revision caade7cc
1/* 2 * $Xorg: XLbx.c,v 1.3 2000/08/17 19:45:51 cpqbld Exp $ 3 * 4 * Copyright 1992 Network Computing Devices 5 * 6 * Permission to use, copy, modify, distribute, and sell this software and its 7 * documentation for any purpose is hereby granted without fee, provided that 8 * the above copyright notice appear in all copies and that both that 9 * copyright notice and this permission notice appear in supporting 10 * documentation, and that the name of NCD. not be used in advertising or 11 * publicity pertaining to distribution of the software without specific, 12 * written prior permission. NCD. makes no representations about the 13 * suitability of this software for any purpose. It is provided "as is" 14 * without express or implied warranty. 15 * 16 * NCD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL NCD. 18 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 19 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 20 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 21 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 22 * 23 * Author: Keith Packard, Network Computing Devices 24 */ 25/* $XFree86: xc/lib/Xext/XLbx.c,v 1.4 2002/10/16 00:37:27 dawes Exp $ */ 26 27#define NEED_EVENTS 28#define NEED_REPLIES 29#ifdef HAVE_CONFIG_H 30#include <config.h> 31#endif 32#include <stdio.h> 33#include <X11/Xlibint.h> 34#include <X11/extensions/XLbx.h> 35#include <X11/extensions/lbxstr.h> 36#include <X11/extensions/Xext.h> 37#include <X11/extensions/extutil.h> 38 39static XExtensionInfo _lbx_info_data; 40static XExtensionInfo *lbx_info = &_lbx_info_data; 41static /* const */ char *lbx_extension_name = LBXNAME; 42 43#define LbxCheckExtension(dpy,i,val) \ 44 XextCheckExtension (dpy, i, lbx_extension_name, val) 45 46static int close_display(Display *dpy, XExtCodes *codes); 47static char *error_string(Display *dpy, int code, XExtCodes *codes, 48 char *buf, int n); 49static /* const */ XExtensionHooks lbx_extension_hooks = { 50 NULL, /* create_gc */ 51 NULL, /* copy_gc */ 52 NULL, /* flush_gc */ 53 NULL, /* free_gc */ 54 NULL, /* create_font */ 55 NULL, /* free_font */ 56 close_display, /* close_display */ 57 NULL, /* wire_to_event */ 58 NULL, /* event_to_wire */ 59 NULL, /* error */ 60 error_string, /* error_string */ 61}; 62 63static /* const */ char *lbx_error_list[] = { 64 "BadLbxClient", /* BadLbxClient */ 65}; 66 67static XEXT_GENERATE_FIND_DISPLAY (find_display, lbx_info, lbx_extension_name, 68 &lbx_extension_hooks, LbxNumberEvents, NULL) 69 70static XEXT_GENERATE_CLOSE_DISPLAY (close_display, lbx_info) 71 72static XEXT_GENERATE_ERROR_STRING (error_string, lbx_extension_name, 73 LbxNumberErrors, lbx_error_list) 74 75 76Bool XLbxQueryExtension ( 77 Display *dpy, 78 int *requestp, int *event_basep, int *error_basep) 79{ 80 XExtDisplayInfo *info = find_display (dpy); 81 82 if (XextHasExtension(info)) { 83 *requestp = info->codes->major_opcode; 84 *event_basep = info->codes->first_event; 85 *error_basep = info->codes->first_error; 86 return True; 87 } else { 88 return False; 89 } 90} 91 92 93int XLbxGetEventBase(Display *dpy) 94{ 95 XExtDisplayInfo *info = find_display (dpy); 96 97 if (XextHasExtension(info)) { 98 return info->codes->first_event; 99 } else { 100 return -1; 101 } 102} 103 104 105Bool XLbxQueryVersion(Display *dpy, int *majorVersion, int *minorVersion) 106{ 107 XExtDisplayInfo *info = find_display (dpy); 108 xLbxQueryVersionReply rep; 109 register xLbxQueryVersionReq *req; 110 111 LbxCheckExtension (dpy, info, False); 112 113 LockDisplay(dpy); 114 GetReq(LbxQueryVersion, req); 115 req->reqType = info->codes->major_opcode; 116 req->lbxReqType = X_LbxQueryVersion; 117 if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { 118 UnlockDisplay(dpy); 119 SyncHandle(); 120 return False; 121 } 122 *majorVersion = rep.majorVersion; 123 *minorVersion = rep.minorVersion; 124 UnlockDisplay(dpy); 125 SyncHandle(); 126 return True; 127} 128 129/* all other requests will run after Xlib has lost the wire ... */ 130