// Copyright status: this file is in the public domain. #include #include "lx.h" #include "proto.h" #include "internal.h" typedef struct priv_SetModifierMapping PRIV_SetModifierMapping; struct priv_SetModifierMapping { LX_MAPPINGSTATUS *statp; } ; static void done_SetModifierMapping(LX_CONN *xc, const unsigned char *rep, void *pv) { PRIV_SetModifierMapping *p; LX_MAPPINGSTATUS s; p = pv; do <"ret"> { if (r_card32(rep+4) != 0) { lx__protoerr(xc,"SetModifierMapping response length wrong (%u, expecting 0)",r_card32(rep+4)); break <"ret">; } s = lx__proto_to_mappingstatus(rep[1]); if (s == LX__map_error) { lx__protoerr(xc,"SetModifierMapping reply has invalid status value %d",rep[1]); break <"ret">; } if (p->statp) *p->statp = s; } while (0); free(p); } LX_OP *lx_SetModifierMapping(LX_CONN *xc, int num, const LX_KEYCODE *keycodesp, LX_MAPPINGSTATUS *statp) { unsigned char req[4+(255*8)]; PRIV_SetModifierMapping *p; int i; if ((xc->flags & XCF_FAIL) || (num > 255)) { lx__bad_call(xc,"lx_SetModifierMapping"); return(0); } lx__nochain(xc); p = malloc(sizeof(PRIV_SetModifierMapping)); if (! p) { lx__nomem_fail(xc); return(0); } p->statp = statp; req[0] = LX_CORE_SetModifierMapping; req[1] = num; w_card16(&req[2],1+(2*num)); for (i=(8*num)-1;i>=0;i--) req[4+i] = keycodesp[i]; return(lx__expect_reply(xc,&req[0],4+(8*num),&done_SetModifierMapping,p)); }