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