aboutsummaryrefslogtreecommitdiff
path: root/nx-X11/lib/Xevie/Xevie.c
blob: 9698881b56d77a24bd38e5e008efca2557cd4597 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/* $XdotOrg: xc/lib/Xevie/Xevie.c,v 1.3 2005/07/03 07:00:56 daniels Exp $ */
/************************************************************

Copyright 2003 Sun Microsystems, Inc.

All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, and/or sell copies of the Software, and to permit persons
to whom the Software is furnished to do so, provided that the above
copyright notice(s) and this permission notice appear in all copies of
the Software and that both the above copyright notice(s) and this
permission notice appear in supporting documentation.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

Except as contained in this notice, the name of a copyright holder
shall not be used in advertising or otherwise to promote the sale, use
or other dealings in this Software without prior written authorization
of the copyright holder.

************************************************************/

#define NEED_EVENTS
#define NEED_REPLIES
#include <X11/Xlibint.h>
#include <X11/extensions/Xevie.h>
#include <X11/extensions/Xeviestr.h>
#include <X11/extensions/Xext.h>
#include <X11/extensions/extutil.h>

static XExtensionInfo _xevie_info_data;
static XExtensionInfo *xevie_info = &_xevie_info_data;
static char *xevie_extension_name = XEVIENAME;
static int major_opcode = 0;
static long xevie_mask = 0;


/*****************************************************************************
 *                                                                           *
 *			   private utility routines                          *
 *                                                                           *
 *****************************************************************************/

static int close_display();
static /* const */ XExtensionHooks xevie_extension_hooks = {
    NULL,                               /* create_gc */
    NULL,                               /* copy_gc */
    NULL,                               /* flush_gc */
    NULL,                               /* free_gc */
    NULL,                               /* create_font */
    NULL,                               /* free_font */
    close_display,                      /* close_display */
    NULL,                               /* wire_to_event */
    NULL,                               /* event_to_wire */
    NULL,                               /* error */
    NULL,                               /* error_string */
};

static XEXT_GENERATE_FIND_DISPLAY (find_display, xevie_info,
                                   xevie_extension_name,
                                   &xevie_extension_hooks,
                                   0, NULL)

static XEXT_GENERATE_CLOSE_DISPLAY (close_display, xevie_info)

/*****************************************************************************
 *                                                                           *
 *		    public Xevie Extension routines                           *
 *                                                                           *
 *****************************************************************************/

Status
XevieQueryVersion(dpy, major_version_return, minor_version_return)
    Display* dpy;
    int* major_version_return; 
    int* minor_version_return;
{
    XExtDisplayInfo *info = find_display (dpy);
    xXevieQueryVersionReply rep;
    xXevieQueryVersionReq *req;

    XextCheckExtension(dpy, info, xevie_extension_name, False);

    major_opcode = info->codes->major_opcode;
    LockDisplay(dpy);
    GetReq(XevieQueryVersion, req);
    req->reqType = major_opcode;
    req->xevieReqType = X_XevieQueryVersion;
    req->client_major_version = XEVIE_MAJOR_VERSION;
    req->client_minor_version = XEVIE_MINOR_VERSION;
    if (!_XReply(dpy, (xReply *)&rep, 0, xTrue)) {
	UnlockDisplay(dpy);
	SyncHandle();
	return False;
    }
    *major_version_return = rep.server_major_version;
    *minor_version_return = rep.server_minor_version;
    UnlockDisplay(dpy);
    SyncHandle();
    return True;
}

/* Win32 reserves 20 colormap entries for its desktop */
#ifndef TYP_RESERVED_ENTRIES
#define TYP_RESERVED_ENTRIES 20
#endif

Status 
#if NeedFunctionPrototypes
XevieStart(
    Display* dpy)
#else
XevieStart(dpy)
    Display* dpy;
#endif
{
    XExtDisplayInfo *info = find_display (dpy);
    xXevieStartReply rep;
    xXevieStartReq *req;

    XextCheckExtension(dpy, info, xevie_extension_name, False);

    major_opcode = info->codes->major_opcode; 
    LockDisplay(dpy);
    GetReq(XevieStart, req);
    req->reqType = major_opcode;
    req->xevieReqType = X_XevieStart;
    if (_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
    }
    UnlockDisplay(dpy);
    SyncHandle();
    return(rep.pad1);
}

Status
XevieEnd(dpy)
    Display* dpy;
{
    XExtDisplayInfo *info = find_display (dpy);
    xXevieEndReply rep;
    xXevieEndReq *req;

    XextCheckExtension (dpy, info, xevie_extension_name, False); 

    LockDisplay(dpy);
    GetReq(XevieEnd, req);
    req->reqType = info->codes->major_opcode;
    req->xevieReqType = X_XevieEnd;

    if (_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
    }
    UnlockDisplay(dpy);
    SyncHandle();
    return True;
}

Status
XevieSendEvent(dpy, event, dataType)
    Display* dpy;
    XEvent*  event;
    char     dataType;
{
    xXevieSendReply rep;
    xXevieSendReq *req;

    LockDisplay(dpy);
    GetReq(XevieSend, req);
    req->reqType = major_opcode;
    req->xevieReqType = X_XevieSend;
    req->dataType = dataType;
    _XEventToWire(dpy, event, &req->event);
    if (_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
    }
    UnlockDisplay(dpy);
    SyncHandle();
    return True;
}

Status
XevieSelectInput(dpy, event_mask)
    Display* dpy;
    long     event_mask;
{
    xXevieSelectInputReply rep;
    xXevieSelectInputReq *req;

    LockDisplay(dpy);
    GetReq(XevieSelectInput, req);
    req->reqType = major_opcode;
    req->xevieReqType = X_XevieSelectInput;
    req->event_mask = event_mask;
    xevie_mask = event_mask;    
    if (_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
    }
    UnlockDisplay(dpy);
    SyncHandle();
    return True;
}