// Copyright status: this file is in the public domain. #include #include "lx.h" #include "proto.h" #include "internal.h" typedef struct priv_GrabKeyboard PRIV_GrabKeyboard; struct priv_GrabKeyboard { LX_GRABSTATUS *statusp; } ; static void done_GrabKeyboard(LX_CONN *xc, const unsigned char *rep, void *pv, unsigned int flags) { PRIV_GrabKeyboard *p; LX_GRABSTATUS gs; p = pv; do <"ret"> { if (r_card32(rep+4) != 0) { lx__protoerr(xc,"GrabKeyboard response length wrong (%u, expecting 0)",r_card32(rep+4)); break <"ret">; } gs = lx__proto_to_grabstatus(rep[1]); if (gs == LX__map_error) { lx__protoerr(xc,"GrabKeyboard response has invalid status value %d",rep[1]); break <"ret">; } if (p->statusp && !(flags & REPLY_NOWRITE)) *p->statusp = gs; } while (0); free(p); } LX_OP *lx_GrabKeyboard( LX_CONN *xc, LX_XID grabwin, int ownerevents, LX_GRABMODE ptrmode, LX_GRABMODE kbdmode, LX_TIME time, LX_GRABSTATUS *statusp ) { unsigned char req[16]; PRIV_GrabKeyboard *p; int proto_pmode; int proto_kmode; if (xc->flags & XCF_FAIL) { lx__bad_call(xc,"lx_GrabKeyboard"); return(0); } lx__nochain(xc); proto_pmode = lx__grabmode_to_proto(ptrmode); proto_kmode = lx__grabmode_to_proto(kbdmode); if ((proto_pmode < 0) || (proto_kmode < 0)) { lx__bad_call(xc,"lx_GrabKeyboard"); return(0); } p = malloc(sizeof(PRIV_GrabKeyboard)); if (! p) { lx__nomem_fail(xc); return(0); } p->statusp = statusp; req[0] = LX_CORE_GrabKeyboard; req[1] = lx__boolean_to_proto(ownerevents); w_card16(&req[2],4); w_card32(&req[4],grabwin); w_card32(&req[8],time); req[12] = proto_pmode; req[13] = proto_kmode; req[14] = 0; // unused req[15] = 0; // unused return(lx__expect_reply(xc,&req[0],-1,&done_GrabKeyboard,p)); }