This repository has been archived by the owner on Feb 11, 2021. It is now read-only.
/
xme.c
412 lines (341 loc) · 10.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/*
* Copyright 1993-2001 by Xi Graphics, Inc.
* All Rights Reserved.
*
* Please see the LICENSE file accompanying this distribution for licensing
* information.
*
* Please send any bug fixes and modifications to src@xig.com.
*
* $XiGId: xme.c,v 1.2 2001/11/30 21:56:59 jon Exp $
*
*/
#define NEED_EVENTS
#define NEED_REPLIES
17
#include <X11/Xlibint.h>
18
19
20
#include <X11/Xthreads.h>
#include <X11/Xmd.h>
#include <X11/Xproto.h>
21
#include "../extensions/Xext.h"
22
#include "../extensions/extutil.h"
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
/*****************************************************************************/
#define XIGMISC_PROTOCOL_NAME "XiG-SUNDRY-NONSTANDARD"
#define XIGMISC_MAJOR_VERSION 2
#define XIGMISC_MINOR_VERSION 0
#define XiGMiscNumberEvents 0
#define X_XiGMiscQueryVersion 0
#define X_XiGMiscQueryViews 1
#define X_XiGMiscQueryResolutions 2
#define X_XiGMiscChangeResolution 3
#define X_XiGMiscFullScreen 4
#define sz_xXiGMiscQueryVersionReq 8
#define sz_xXiGMiscQueryViewsReq 8
#define sz_xXiGMiscQueryResolutionsReq 8
#define sz_xXiGMiscChangeResolutionReq 16
#define sz_xXiGMiscFullScreenReq 16
#define sz_xXiGMiscQueryVersionReply 32
#define sz_xXiGMiscQueryViewsReply 32
#define sz_xXiGMiscQueryResolutionsReply 32
#define sz_xXiGMiscQueryFullScreenReply 32
/*******************************************************************/
52
53
54
55
56
57
58
typedef struct
{
CARD8 reqType; /* always codes->major_opcode */
CARD8 xigmiscReqType; /* always X_XiGMiscQueryVersion */
CARD16 length;
CARD16 major;
CARD16 minor;
59
60
} xXiGMiscQueryVersionReq;
61
62
63
64
65
66
67
68
typedef struct
{
CARD8 reqType; /* always codes->major_opcode */
CARD8 xigmiscReqType; /* always X_XiGMiscQueryViews */
CARD16 length;
CARD8 screen;
CARD8 pad0;
CARD16 pad1;
69
70
} xXiGMiscQueryViewsReq;
71
72
73
74
75
76
77
78
typedef struct
{
CARD8 reqType; /* always codes->major_opcode */
CARD8 xigmiscReqType; /* always X_XiGMiscQueryResolutions */
CARD16 length;
CARD8 screen;
CARD8 view;
CARD16 pad0;
79
80
} xXiGMiscQueryResolutionsReq;
81
82
83
84
85
86
87
88
89
90
91
typedef struct
{
CARD8 reqType; /* always codes->major_opcode */
CARD8 xigmiscReqType; /* always X_XiGMiscChangeResolution */
CARD16 length;
CARD8 screen;
CARD8 view;
CARD16 pad0;
CARD16 width;
CARD16 height;
INT32 refresh;
92
93
} xXiGMiscChangeResolutionReq;
94
95
96
97
98
99
100
101
102
103
typedef struct
{
CARD8 reqType; /* always codes->major_opcode */
CARD8 xigmiscReqType; /* always X_XiGMiscFullScreen */
CARD16 length;
CARD8 screen;
CARD8 pad0;
CARD16 pad1;
CARD32 window;
CARD32 cmap;
104
105
106
107
} xXiGMiscFullScreenReq;
/*******************************************************************/
108
109
110
111
112
113
114
115
116
117
118
119
120
typedef struct
{
BYTE type; /* X_Reply */
CARD8 pad0;
CARD16 sequenceNumber;
CARD32 length;
CARD16 major;
CARD16 minor;
CARD32 pad1;
CARD32 pad2;
CARD32 pad3;
CARD32 pad4;
CARD32 pad5;
121
122
} xXiGMiscQueryVersionReply;
123
124
125
126
127
128
129
130
131
132
133
134
typedef struct
{
BYTE type; /* X_Reply */
CARD8 pad0;
CARD16 sequenceNumber;
CARD32 length;
CARD32 nviews;
CARD32 pad1;
CARD32 pad2;
CARD32 pad3;
CARD32 pad4;
CARD32 pad5;
135
136
} xXiGMiscQueryViewsReply;
137
138
139
140
141
142
143
144
145
146
147
148
149
typedef struct
{
BYTE type; /* X_Reply */
CARD8 pad0;
CARD16 sequenceNumber;
CARD32 length;
CARD16 active;
CARD16 nresolutions;
CARD32 pad1;
CARD32 pad2;
CARD32 pad3;
CARD32 pad4;
CARD32 pad5;
150
151
} xXiGMiscQueryResolutionsReply;
152
153
154
155
156
157
158
159
160
161
162
163
typedef struct
{
BYTE type; /* X_Reply */
BOOL success;
CARD16 sequenceNumber;
CARD32 length;
CARD32 pad1;
CARD32 pad2;
CARD32 pad3;
CARD32 pad4;
CARD32 pad5;
CARD32 pad6;
164
165
166
167
} xXiGMiscFullScreenReply;
/*******************************************************************/
168
169
170
171
172
173
typedef struct
{
INT16 x;
INT16 y;
CARD16 w;
CARD16 h;
174
175
} XiGMiscViewInfo;
176
177
178
179
180
typedef struct
{
CARD16 width;
CARD16 height;
INT32 refresh;
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
212
213
214
} XiGMiscResolutionInfo;
/*****************************************************************************/
static XExtensionInfo *xigmisc_info = NULL;
static char *xigmisc_extension_name = XIGMISC_PROTOCOL_NAME;
#define XiGMiscCheckExtension(dpy,i,val) \
XextCheckExtension (dpy, i, xigmisc_extension_name, val)
#define XiGMiscSimpleCheckExtension(dpy,i) \
XextSimpleCheckExtension (dpy, i, xigmisc_extension_name)
#if defined(__STDC__) && !defined(UNIXCPP)
#define XiGMiscGetReq(name,req,info) GetReq (name, req); \
req->reqType = info->codes->major_opcode; \
req->xigmiscReqType = X_##name;
#define XiGMiscGetReqExtra(name,n,req,info) GetReqExtra (name, n, req); \
req->reqType = info->codes->major_opcode; \
req->xigmicReqType = X_##name;
#else
#define XiGMiscGetReq(name,req,info) GetReq (name, req); \
req->reqType = info->codes->major_opcode; \
req->xigmiscReqType = X_/**/name;
#define XiGMiscGetReqExtra(name,n,req,info) GetReqExtra (name, n, req); \
req->reqType = info->codes->major_opcode; \
req->xigmiscReqType = X_/**/name;
#endif
/*
* find_display - locate the display info block
*/
215
static int XiGMiscCloseDisplay ();
216
217
static XExtensionHooks xigmisc_extension_hooks = {
218
219
220
221
222
223
224
225
226
227
228
NULL, /* create_gc */
NULL, /* copy_gc */
NULL, /* flush_gc */
NULL, /* free_gc */
NULL, /* create_font */
NULL, /* free_font */
XiGMiscCloseDisplay, /* close_display */
NULL, /* wire_to_event */
NULL, /* event_to_wire */
NULL, /* error */
NULL, /* error_string */
229
230
231
};
232
233
234
235
236
237
static
XEXT_GENERATE_CLOSE_DISPLAY (XiGMiscCloseDisplay, xigmisc_info)
static XEXT_GENERATE_FIND_DISPLAY (XiGMiscFindDisplay, xigmisc_info,
xigmisc_extension_name,
&xigmisc_extension_hooks,
XiGMiscNumberEvents, NULL)
238
/*****************************************************************************/
239
Bool XiGMiscQueryVersion (Display * dpy, int *major, int *minor)
240
{
241
242
243
244
int opcode, event, error;
xXiGMiscQueryVersionReq *req;
xXiGMiscQueryVersionReply rep;
XExtDisplayInfo *info = XiGMiscFindDisplay (dpy);
245
246
247
248
if (!XQueryExtension
(dpy, XIGMISC_PROTOCOL_NAME, &opcode, &event, &error))
return xFalse;
249
250
XiGMiscCheckExtension (dpy, info, xFalse);
251
252
253
LockDisplay (dpy);
XiGMiscGetReq (XiGMiscQueryVersion, req, info);
254
255
256
req->major = XIGMISC_MAJOR_VERSION;
req->minor = XIGMISC_MINOR_VERSION;
257
258
259
260
261
262
if (!_XReply (dpy, (xReply *) & rep, 0, xTrue)) {
UnlockDisplay (dpy);
SyncHandle ();
return xFalse;
}
263
264
265
266
267
*major = rep.major;
*minor = rep.minor;
UnlockDisplay (dpy);
SyncHandle ();
268
269
return xTrue;
270
271
}
272
273
int
XiGMiscQueryViews (Display * dpy, int screen, XiGMiscViewInfo ** pviews)
274
{
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
int n, size;
XiGMiscViewInfo *views;
xXiGMiscQueryViewsReq *req;
xXiGMiscQueryViewsReply rep;
XExtDisplayInfo *info = XiGMiscFindDisplay (dpy);
XiGMiscCheckExtension (dpy, info, 0);
LockDisplay (dpy);
XiGMiscGetReq (XiGMiscQueryViews, req, info);
req->screen = screen;
if (!_XReply (dpy, (xReply *) & rep, 0, xFalse)) {
UnlockDisplay (dpy);
SyncHandle ();
return 0;
290
291
}
292
n = rep.nviews;
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
if (n > 0) {
size = sizeof (XiGMiscViewInfo) * n;
views = (XiGMiscViewInfo *) Xmalloc (size);
if (!views) {
_XEatData (dpy, (unsigned long) size);
UnlockDisplay (dpy);
SyncHandle ();
return 0;
}
_XReadPad (dpy, (void *) views, size);
*pviews = views;
}
308
309
310
UnlockDisplay (dpy);
SyncHandle ();
311
312
return n;
313
314
}
315
316
317
int
XiGMiscQueryResolutions (Display * dpy, int screen, int view, int *pactive,
XiGMiscResolutionInfo ** presolutions)
318
{
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
int n, size;
XiGMiscResolutionInfo *resolutions;
xXiGMiscQueryResolutionsReq *req;
xXiGMiscQueryResolutionsReply rep;
XExtDisplayInfo *info = XiGMiscFindDisplay (dpy);
XiGMiscCheckExtension (dpy, info, 0);
LockDisplay (dpy);
XiGMiscGetReq (XiGMiscQueryResolutions, req, info);
req->screen = screen;
req->view = view;
if (!_XReply (dpy, (xReply *) & rep, 0, xFalse)) {
UnlockDisplay (dpy);
SyncHandle ();
return 0;
335
336
}
337
n = rep.nresolutions;
338
339
340
341
342
343
344
345
346
347
if (n > 0) {
size = sizeof (XiGMiscResolutionInfo) * n;
resolutions = (XiGMiscResolutionInfo *) Xmalloc (size);
if (!resolutions) {
_XEatData (dpy, (unsigned long) size);
UnlockDisplay (dpy);
SyncHandle ();
return 0;
}
348
349
_XReadPad (dpy, (void *) resolutions, size);
350
351
352
353
354
355
356
357
358
*presolutions = resolutions;
*pactive = rep.active;
}
UnlockDisplay (dpy);
SyncHandle ();
return n;
359
360
}
361
362
363
void
XiGMiscChangeResolution (Display * dpy, int screen, int view, int width,
int height, int refresh)
364
{
365
366
xXiGMiscChangeResolutionReq *req;
XExtDisplayInfo *info = XiGMiscFindDisplay (dpy);
367
368
XiGMiscSimpleCheckExtension (dpy, info);
369
370
371
372
373
374
375
376
LockDisplay (dpy);
XiGMiscGetReq (XiGMiscChangeResolution, req, info);
req->screen = screen;
req->view = view;
req->width = width;
req->height = height;
req->refresh = refresh;
377
378
379
UnlockDisplay (dpy);
SyncHandle ();
380
381
382
}
383
384
Bool
XiGMiscFullScreen (Display * dpy, int screen, XID window, XID cmap)
385
{
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
xXiGMiscFullScreenReq *req;
xXiGMiscFullScreenReply rep;
XExtDisplayInfo *info = XiGMiscFindDisplay (dpy);
XiGMiscCheckExtension (dpy, info, xFalse);
LockDisplay (dpy);
XiGMiscGetReq (XiGMiscFullScreen, req, info);
req->screen = screen;
req->pad0 = 0;
req->pad1 = 0;
req->window = window;
req->cmap = cmap;
if (!_XReply (dpy, (xReply *) & rep, 0, xTrue)) {
UnlockDisplay (dpy);
SyncHandle ();
return xFalse;
}
UnlockDisplay (dpy);
SyncHandle ();
return (rep.success ? xTrue : xFalse);
410
411
}
412
/* vi: set ts=4 sw=4 expandtab: */