#define NEED_EVENTS
#define NEED_REPLIES
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <X11/Xlibint.h>
#include <X11/extensions/Xext.h>
#include <X11/extensions/extutil.h>
#define NEED_DBE_PROTOCOL
#include <X11/extensions/Xdbe.h>
static XExtensionInfo _dbe_info_data;
static XExtensionInfo *dbe_info = &_dbe_info_data;
static char *dbe_extension_name = DBE_PROTOCOL_NAME;
#define DbeCheckExtension(dpy,i,val) \
XextCheckExtension (dpy, i, dbe_extension_name, val)
#define DbeSimpleCheckExtension(dpy,i) \
XextSimpleCheckExtension (dpy, i, dbe_extension_name)
#if !defined(UNIXCPP)
#define DbeGetReq(name,req,info) GetReq (name, req); \
req->reqType = info->codes->major_opcode; \
req->dbeReqType = X_##name;
#else
#define DbeGetReq(name,req,info) GetReq (name, req); \
req->reqType = info->codes->major_opcode; \
req->dbeReqType = X_name;
#endif
static int close_display(Display *dpy, XExtCodes *codes);
static char *error_string(Display *dpy, int code, XExtCodes *codes,
char *buf, int n);
static XExtensionHooks dbe_extension_hooks = {
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
close_display,
NULL,
NULL,
NULL,
error_string,
};
static char *dbe_error_list[] = {
"BadBuffer",
};
static XEXT_GENERATE_FIND_DISPLAY (find_display, dbe_info,
dbe_extension_name,
&dbe_extension_hooks,
DbeNumberEvents, NULL)
static XEXT_GENERATE_CLOSE_DISPLAY (close_display, dbe_info)
static XEXT_GENERATE_ERROR_STRING (error_string, dbe_extension_name,
DbeNumberErrors,
dbe_error_list)
Status XdbeQueryExtension (
Display *dpy,
int *major_version_return,
int *minor_version_return)
{
XExtDisplayInfo *info = find_display (dpy);
xDbeGetVersionReply rep;
register xDbeGetVersionReq *req;
if (!XextHasExtension (info))
return (Status)0;
LockDisplay (dpy);
DbeGetReq (DbeGetVersion, req, info);
req->majorVersion = DBE_MAJOR_VERSION;
req->minorVersion = DBE_MINOR_VERSION;
if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
UnlockDisplay (dpy);
SyncHandle ();
return (Status)0;
}
*major_version_return = rep.majorVersion;
*minor_version_return = rep.minorVersion;
UnlockDisplay (dpy);
SyncHandle ();
if (*major_version_return != DBE_MAJOR_VERSION)
return (Status)0;
else
return (Status)1;
}
XdbeBackBuffer XdbeAllocateBackBufferName(
Display *dpy,
Window window,
XdbeSwapAction swap_action)
{
XExtDisplayInfo *info = find_display (dpy);
register xDbeAllocateBackBufferNameReq *req;
XdbeBackBuffer buffer;
DbeCheckExtension (dpy, info, (XdbeBackBuffer)0);
buffer = XAllocID (dpy);
LockDisplay(dpy);
DbeGetReq(DbeAllocateBackBufferName, req, info);
req->window = window;
req->swapAction = (unsigned char)swap_action;
req->buffer = buffer;
UnlockDisplay (dpy);
SyncHandle ();
return buffer;
}
Status XdbeDeallocateBackBufferName (
Display *dpy,
XdbeBackBuffer buffer)
{
XExtDisplayInfo *info = find_display (dpy);
register xDbeDeallocateBackBufferNameReq *req;
DbeCheckExtension (dpy, info, (Status)0 );
LockDisplay (dpy);
DbeGetReq (DbeDeallocateBackBufferName, req, info);
req->buffer = buffer;
UnlockDisplay (dpy);
SyncHandle ();
return (Status)1;
}
Status XdbeSwapBuffers (
Display *dpy,
XdbeSwapInfo *swap_info,
int num_windows)
{
XExtDisplayInfo *info = find_display (dpy);
register xDbeSwapBuffersReq *req;
int i;
DbeCheckExtension (dpy, info, (Status)0 );
LockDisplay (dpy);
DbeGetReq (DbeSwapBuffers, req, info);
req->length += 2*num_windows;
req->n = num_windows;
for (i = 0; i < num_windows; i++)
{
char tmp[4];
Data32 (dpy, (long *)&swap_info[i].swap_window, 4);
tmp[0] = swap_info[i].swap_action;
Data (dpy, (char *)tmp, 4);
}
UnlockDisplay (dpy);
SyncHandle ();
return (Status)1;
}
Status XdbeBeginIdiom (Display *dpy)
{
XExtDisplayInfo *info = find_display(dpy);
register xDbeBeginIdiomReq *req;
DbeCheckExtension (dpy, info, (Status)0 );
LockDisplay (dpy);
DbeGetReq (DbeBeginIdiom, req, info);
UnlockDisplay (dpy);
SyncHandle ();
return (Status)1;
}
Status XdbeEndIdiom (Display *dpy)
{
XExtDisplayInfo *info = find_display(dpy);
register xDbeEndIdiomReq *req;
DbeCheckExtension (dpy, info, (Status)0 );
LockDisplay (dpy);
DbeGetReq (DbeEndIdiom, req, info);
UnlockDisplay (dpy);
SyncHandle ();
return (Status)1;
}
XdbeScreenVisualInfo *XdbeGetVisualInfo (
Display *dpy,
Drawable *screen_specifiers,
int *num_screens)
{
XExtDisplayInfo *info = find_display(dpy);
register xDbeGetVisualInfoReq *req;
xDbeGetVisualInfoReply rep;
XdbeScreenVisualInfo *scrVisInfo;
int i;
DbeCheckExtension (dpy, info, (XdbeScreenVisualInfo *)NULL);
LockDisplay (dpy);
DbeGetReq(DbeGetVisualInfo, req, info);
req->length = 2 + *num_screens;
req->n = *num_screens;
Data32 (dpy, screen_specifiers, (*num_screens * sizeof (CARD32)));
if (!_XReply (dpy, (xReply *) &rep, 0, xFalse)) {
UnlockDisplay (dpy);
SyncHandle ();
return NULL;
}
if (*num_screens == 0)
*num_screens = rep.m;
if (!(scrVisInfo =
(XdbeScreenVisualInfo *)Xmalloc(
(unsigned)(*num_screens * sizeof(XdbeScreenVisualInfo))))) {
UnlockDisplay (dpy);
SyncHandle ();
return NULL;
}
for (i = 0; i < *num_screens; i++)
{
int nbytes;
int j;
long c;
_XRead32 (dpy, &c, sizeof(CARD32));
scrVisInfo[i].count = c;
nbytes = scrVisInfo[i].count * sizeof(XdbeVisualInfo);
if (!(scrVisInfo[i].visinfo = (XdbeVisualInfo *)Xmalloc(
(unsigned)nbytes))) {
for (j = 0; j < i; j++) {
Xfree ((char *)scrVisInfo[j].visinfo);
}
Xfree ((char *)scrVisInfo);
UnlockDisplay (dpy);
SyncHandle ();
return NULL;
}
for (j = 0; j < scrVisInfo[i].count; j++) {
xDbeVisInfo xvi;
_XRead (dpy, (char *)&xvi, sizeof(xDbeVisInfo));
scrVisInfo[i].visinfo[j].visual = xvi.visualID;
scrVisInfo[i].visinfo[j].depth = xvi.depth;
scrVisInfo[i].visinfo[j].perflevel = xvi.perfLevel;
}
}
UnlockDisplay (dpy);
SyncHandle ();
return scrVisInfo;
}
void XdbeFreeVisualInfo(XdbeScreenVisualInfo *visual_info)
{
if (visual_info == NULL) {
return;
}
if (visual_info->visinfo) {
XFree(visual_info->visinfo);
}
XFree(visual_info);
}
XdbeBackBufferAttributes *XdbeGetBackBufferAttributes(
Display *dpy,
XdbeBackBuffer buffer)
{
XExtDisplayInfo *info = find_display(dpy);
register xDbeGetBackBufferAttributesReq *req;
xDbeGetBackBufferAttributesReply rep;
XdbeBackBufferAttributes *attr;
DbeCheckExtension(dpy, info, (XdbeBackBufferAttributes *)NULL);
if (!(attr =
(XdbeBackBufferAttributes *)Xmalloc(sizeof(XdbeBackBufferAttributes)))) {
return NULL;
}
LockDisplay(dpy);
DbeGetReq(DbeGetBackBufferAttributes, req, info);
req->buffer = buffer;
if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
UnlockDisplay (dpy);
SyncHandle ();
Xfree(attr);
return NULL;
}
attr->window = rep.attributes;
UnlockDisplay (dpy);
SyncHandle ();
return attr;
}