#define NEED_REPLIES
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "Xlibint.h"
#ifdef MIN
#undef MIN
#endif
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int XGetPointerMapping (
register Display *dpy,
unsigned char *map,
int nmaps)
{
unsigned char mapping[256];
long nbytes, remainder = 0;
xGetPointerMappingReply rep;
register xReq *req;
LockDisplay(dpy);
GetEmptyReq(GetPointerMapping, req);
if (! _XReply(dpy, (xReply *)&rep, 0, xFalse)) {
UnlockDisplay(dpy);
SyncHandle();
return 0;
}
nbytes = (long)rep.length << 2;
if (nbytes > sizeof mapping) {
remainder = nbytes - sizeof mapping;
nbytes = sizeof mapping;
}
_XRead (dpy, (char *)mapping, nbytes);
if (rep.nElts) {
memcpy ((char *) map, (char *) mapping,
MIN((int)rep.nElts, nmaps) );
}
if (remainder)
_XEatData(dpy, (unsigned long)remainder);
UnlockDisplay(dpy);
SyncHandle();
return ((int) rep.nElts);
}
KeySym *
XGetKeyboardMapping (Display *dpy,
#if NeedWidePrototypes
unsigned int first_keycode,
#else
KeyCode first_keycode,
#endif
int count,
int *keysyms_per_keycode)
{
long nbytes;
unsigned long nkeysyms;
register KeySym *mapping = NULL;
xGetKeyboardMappingReply rep;
register xGetKeyboardMappingReq *req;
LockDisplay(dpy);
GetReq(GetKeyboardMapping, req);
req->firstKeyCode = first_keycode;
req->count = count;
if (! _XReply(dpy, (xReply *)&rep, 0, xFalse)) {
UnlockDisplay(dpy);
SyncHandle();
return (KeySym *) NULL;
}
nkeysyms = (unsigned long) rep.length;
if (nkeysyms > 0) {
nbytes = nkeysyms * sizeof (KeySym);
mapping = (KeySym *) Xmalloc ((unsigned) nbytes);
nbytes = nkeysyms << 2;
if (! mapping) {
_XEatData(dpy, (unsigned long) nbytes);
UnlockDisplay(dpy);
SyncHandle();
return (KeySym *) NULL;
}
_XRead32 (dpy, (long *) mapping, nbytes);
}
*keysyms_per_keycode = rep.keySymsPerKeyCode;
UnlockDisplay(dpy);
SyncHandle();
return (mapping);
}