#include #include #include "lx.h" #include "proto.h" #include "internal.h" typedef struct priv_QueryBestSize PRIV_QueryBestSize; struct priv_QueryBestSize { int *wp; int *hp; } ; static void done_QueryBestSize(LX_OP *op, const unsigned char *rep, void *pv) { PRIV_QueryBestSize *p; p = pv; do <"ret"> { if (r_card32(rep+4) != 0) { lx__protoerr(op->conn,"QueryBestSize response length wrong (%u, expecting 0)",r_card32(rep+4)); break <"ret">; } if (p->wp) *p->wp = r_card16(rep+8); if (p->hp) *p->hp = r_card16(rep+10); } while (0); free(p); } LX_OP *lx_QueryBestSize(LX_CONN *xc, LX_XID drawable, LX_SIZECLASS class, int w, int h, int *wp, int *hp) { unsigned char req[12]; PRIV_QueryBestSize *p; int protoclass; if ((xc->flags & XCF_FAIL) || (w < 0) || (w > 65535) || (h < 0) || (h > 65535)) { lx__bad_call(xc,"lx_QueryBestSize"); return(0); } lx__nochain(xc); protoclass = lx__sizeclass_to_proto(class); if (protoclass < 0) { lx__bad_call(xc,"lx_QueryBestSize"); return(0); } p = malloc(sizeof(PRIV_QueryBestSize)); if (! p) { lx__nomem_fail(xc); return(0); } p->wp = wp; p->hp = hp; req[0] = XP_REQ_QueryBestSize; req[1] = protoclass; w_card16(&req[2],3); w_card32(&req[4],drawable); w_card16(&req[8],w); w_card16(&req[10],h); return(lx__expect_reply(xc,&req[0],-1,&done_QueryBestSize,p)); }