#define NEED_REPLIES
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <X11/extensions/Printstr.h>
#include <X11/Xlibint.h>
#include "XpExtUtil.h"
#define _XpPadOut(len) (((len) + 3) & ~3)
XPContext
XpCreateContext (
Display *dpy,
char *printer_name
)
{
xPrintCreateContextReq *req;
char *locale;
int locale_len;
XExtDisplayInfo *info = (XExtDisplayInfo *) xp_find_display (dpy);
if (XpCheckExtInit(dpy, XP_DONT_CHECK) == -1)
return ( (XPContext) None );
locale = XpGetLocaleNetString();
LockDisplay (dpy);
GetReq(PrintCreateContext,req);
req->reqType = info->codes->major_opcode;
req->printReqType = X_PrintCreateContext;
req->contextID = XAllocID(dpy);
req->printerNameLen = strlen(printer_name);
if ( locale == (char *) NULL )
req->localeLen = 0;
else if ( *locale == (char) NULL )
req->localeLen = 0;
else {
locale_len = strlen( locale );
req->length += _XpPadOut(locale_len) >> 2;
req->localeLen = (unsigned long) locale_len;
}
req->length += _XpPadOut(req->printerNameLen) >> 2;
Data( dpy, (char *) printer_name, (long) req->printerNameLen );
if (req->localeLen)
Data( dpy, (char *) locale, (long) req->localeLen );
UnlockDisplay(dpy);
SyncHandle();
XFree(locale);
return ( (XPContext) req->contextID );
}
void
XpSetContext (
Display *dpy,
XPContext print_context
)
{
xPrintSetContextReq *req;
XExtDisplayInfo *info = (XExtDisplayInfo *) xp_find_display (dpy);
if (XpCheckExtInit(dpy, XP_DONT_CHECK) == -1)
return;
LockDisplay (dpy);
GetReq(PrintSetContext,req);
req->reqType = info->codes->major_opcode;
req->printReqType = X_PrintSetContext;
req->printContext = print_context;
UnlockDisplay(dpy);
SyncHandle();
return;
}
XPContext
XpGetContext (
Display *dpy
)
{
xPrintGetContextReq *req;
xPrintGetContextReply rep;
XExtDisplayInfo *info = (XExtDisplayInfo *) xp_find_display (dpy);
if (XpCheckExtInit(dpy, XP_DONT_CHECK) == -1)
return ( (XPContext) None );
LockDisplay (dpy);
GetReq(PrintGetContext,req);
req->reqType = info->codes->major_opcode;
req->printReqType = X_PrintGetContext;
if (! _XReply (dpy, (xReply *) &rep, 0, xTrue)) {
UnlockDisplay(dpy);
SyncHandle();
return ( (XPContext) None );
}
UnlockDisplay(dpy);
SyncHandle();
return ( (XPContext) rep.printContext );
}
void
XpDestroyContext (
Display *dpy,
XPContext print_context
)
{
xPrintDestroyContextReq *req;
XExtDisplayInfo *info = (XExtDisplayInfo *) xp_find_display (dpy);
if (XpCheckExtInit(dpy, XP_DONT_CHECK) == -1)
return;
LockDisplay (dpy);
GetReq(PrintDestroyContext,req);
req->reqType = info->codes->major_opcode;
req->printReqType = X_PrintDestroyContext;
req->printContext = print_context;
UnlockDisplay(dpy);
SyncHandle();
return;
}
Screen *
XpGetScreenOfContext (
Display *dpy,
XPContext print_context
)
{
xPrintGetContextScreenReq *req;
xPrintGetContextScreenReply rep;
XExtDisplayInfo *info = (XExtDisplayInfo *) xp_find_display (dpy);
int i;
Screen *checkScr = NULL;
int ok;
if (XpCheckExtInit(dpy, XP_DONT_CHECK) == -1)
return ( (Screen *) NULL );
LockDisplay (dpy);
GetReq(PrintGetContextScreen,req);
req->reqType = info->codes->major_opcode;
req->printReqType = X_PrintGetContextScreen;
req->printContext = print_context;
if (! _XReply (dpy, (xReply *) &rep, 0, xTrue)) {
UnlockDisplay(dpy);
SyncHandle();
return ( (Screen *) NULL );
}
ok = False;
for ( i = 0; i < XScreenCount(dpy); i++ ) {
checkScr = XScreenOfDisplay(dpy, i);
if ( XRootWindowOfScreen( checkScr ) == (Window) rep.rootWindow ) {
ok = True;
break;
}
}
if (!ok)
checkScr = (Screen *) NULL;
UnlockDisplay(dpy);
SyncHandle();
return ( (Screen *) checkScr );
}