Commit 3c5880e7 authored by Alan Coopersmith's avatar Alan Coopersmith Committed by Ulrich Sibiller

Reindent XKB code to X.Org standard style

parent 3cd82252
...@@ -32,45 +32,47 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. ...@@ -32,45 +32,47 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <nx-X11/extensions/XKBproto.h> #include <nx-X11/extensions/XKBproto.h>
#include "XKBlibint.h" #include "XKBlibint.h"
XkbInternAtomFunc _XkbInternAtomFunc= XInternAtom; XkbInternAtomFunc _XkbInternAtomFunc = XInternAtom;
XkbGetAtomNameFunc _XkbGetAtomNameFunc= XGetAtomName; XkbGetAtomNameFunc _XkbGetAtomNameFunc = XGetAtomName;
Bool Bool
XkbQueryExtension( Display *dpy, XkbQueryExtension(Display *dpy,
int * opcodeReturn, int *opcodeReturn,
int * eventBaseReturn, int *eventBaseReturn,
int * errorBaseReturn, int *errorBaseReturn,
int * majorReturn, int *majorReturn,
int * minorReturn) int *minorReturn)
{ {
if (!XkbUseExtension(dpy,majorReturn,minorReturn)) if (!XkbUseExtension(dpy, majorReturn, minorReturn))
return False; return False;
if (opcodeReturn) if (opcodeReturn)
*opcodeReturn = dpy->xkb_info->codes->major_opcode; *opcodeReturn = dpy->xkb_info->codes->major_opcode;
if (eventBaseReturn) if (eventBaseReturn)
*eventBaseReturn = dpy->xkb_info->codes->first_event; *eventBaseReturn = dpy->xkb_info->codes->first_event;
if (errorBaseReturn) if (errorBaseReturn)
*errorBaseReturn = dpy->xkb_info->codes->first_error; *errorBaseReturn = dpy->xkb_info->codes->first_error;
if (majorReturn) if (majorReturn)
*majorReturn = dpy->xkb_info->srv_major; *majorReturn = dpy->xkb_info->srv_major;
if (minorReturn) if (minorReturn)
*minorReturn = dpy->xkb_info->srv_minor; *minorReturn = dpy->xkb_info->srv_minor;
return True; return True;
} }
Bool Bool
XkbLibraryVersion(int *libMajorRtrn,int *libMinorRtrn) XkbLibraryVersion(int *libMajorRtrn, int *libMinorRtrn)
{ {
int supported; int supported;
if (*libMajorRtrn != XkbMajorVersion) { if (*libMajorRtrn != XkbMajorVersion) {
/* version 0.65 is (almost) compatible with 1.00 */ /* version 0.65 is (almost) compatible with 1.00 */
if ((XkbMajorVersion==1)&&(((*libMajorRtrn)==0)&&((*libMinorRtrn)==65))) if ((XkbMajorVersion == 1) &&
supported= True; (((*libMajorRtrn) == 0) && ((*libMinorRtrn) == 65)))
else supported= False; supported = True;
else
supported = False;
} }
else { else {
supported = True; supported = True;
} }
*libMajorRtrn = XkbMajorVersion; *libMajorRtrn = XkbMajorVersion;
...@@ -79,49 +81,52 @@ int supported; ...@@ -79,49 +81,52 @@ int supported;
} }
Bool Bool
XkbSelectEvents( Display * dpy, XkbSelectEvents(Display *dpy,
unsigned int deviceSpec, unsigned int deviceSpec,
unsigned int affect, unsigned int affect,
unsigned int selectAll) unsigned int selectAll)
{ {
register xkbSelectEventsReq *req; register xkbSelectEventsReq *req;
XkbInfoPtr xkbi; XkbInfoPtr xkbi;
if ((dpy->flags & XlibDisplayNoXkb) || if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return False; return False;
LockDisplay(dpy); LockDisplay(dpy);
xkbi = dpy->xkb_info; xkbi = dpy->xkb_info;
xkbi->selected_events&= ~affect; xkbi->selected_events &= ~affect;
xkbi->selected_events|= (affect&selectAll); xkbi->selected_events |= (affect & selectAll);
GetReq(kbSelectEvents, req); GetReq(kbSelectEvents, req);
req->reqType = xkbi->codes->major_opcode; req->reqType = xkbi->codes->major_opcode;
req->xkbReqType = X_kbSelectEvents; req->xkbReqType = X_kbSelectEvents;
req->deviceSpec = deviceSpec; req->deviceSpec = deviceSpec;
req->affectWhich = (CARD16)affect; req->affectWhich = (CARD16) affect;
req->clear = affect&(~selectAll); req->clear = affect & (~selectAll);
req->selectAll = affect&selectAll; req->selectAll = affect & selectAll;
if (affect&XkbMapNotifyMask) { if (affect & XkbMapNotifyMask) {
req->affectMap= XkbAllMapComponentsMask; req->affectMap = XkbAllMapComponentsMask;
/* the implicit support needs the client info */ /* the implicit support needs the client info */
/* even if the client itself doesn't want it */ /* even if the client itself doesn't want it */
if (selectAll&XkbMapNotifyMask) if (selectAll & XkbMapNotifyMask)
req->map= XkbAllMapEventsMask; req->map = XkbAllMapEventsMask;
else req->map= XkbAllClientInfoMask; else
if (selectAll&XkbMapNotifyMask) req->map = XkbAllClientInfoMask;
xkbi->selected_map_details= XkbAllMapEventsMask; if (selectAll & XkbMapNotifyMask)
else xkbi->selected_map_details= 0; xkbi->selected_map_details = XkbAllMapEventsMask;
else
xkbi->selected_map_details = 0;
} }
if (affect&XkbNewKeyboardNotifyMask) { if (affect & XkbNewKeyboardNotifyMask) {
if (selectAll&XkbNewKeyboardNotifyMask) if (selectAll & XkbNewKeyboardNotifyMask)
xkbi->selected_nkn_details= XkbAllNewKeyboardEventsMask; xkbi->selected_nkn_details = XkbAllNewKeyboardEventsMask;
else xkbi->selected_nkn_details= 0; else
if (!(xkbi->xlib_ctrls&XkbLC_IgnoreNewKeyboards)) { xkbi->selected_nkn_details = 0;
/* we want it, even if the client doesn't. Don't mess */ if (!(xkbi->xlib_ctrls & XkbLC_IgnoreNewKeyboards)) {
/* around with details -- ask for all of them and throw */ /* we want it, even if the client doesn't. Don't mess */
/* away the ones we don't need */ /* around with details -- ask for all of them and throw */
req->selectAll|= XkbNewKeyboardNotifyMask; /* away the ones we don't need */
} req->selectAll |= XkbNewKeyboardNotifyMask;
}
} }
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
...@@ -129,91 +134,94 @@ XkbSelectEvents( Display * dpy, ...@@ -129,91 +134,94 @@ XkbSelectEvents( Display * dpy,
} }
Bool Bool
XkbSelectEventDetails( Display * dpy, XkbSelectEventDetails(Display *dpy,
unsigned deviceSpec, unsigned deviceSpec,
unsigned eventType, unsigned eventType,
unsigned long int affect, unsigned long int affect,
unsigned long int details) unsigned long int details)
{ {
register xkbSelectEventsReq *req; register xkbSelectEventsReq *req;
XkbInfoPtr xkbi; XkbInfoPtr xkbi;
int size = 0; int size = 0;
char *out; char *out;
union { union {
CARD8 *c8; CARD8 *c8;
CARD16 *c16; CARD16 *c16;
CARD32 *c32; CARD32 *c32;
} u; } u;
if ((dpy->flags & XlibDisplayNoXkb) || if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return False; return False;
LockDisplay(dpy); LockDisplay(dpy);
xkbi = dpy->xkb_info; xkbi = dpy->xkb_info;
if (affect&details) xkbi->selected_events|= (1<<eventType); if (affect & details)
else xkbi->selected_events&= ~(1<<eventType); xkbi->selected_events |= (1 << eventType);
else
xkbi->selected_events &= ~(1 << eventType);
GetReq(kbSelectEvents, req); GetReq(kbSelectEvents, req);
req->reqType = xkbi->codes->major_opcode; req->reqType = xkbi->codes->major_opcode;
req->xkbReqType = X_kbSelectEvents; req->xkbReqType = X_kbSelectEvents;
req->deviceSpec = deviceSpec; req->deviceSpec = deviceSpec;
req->clear= req->selectAll= 0; req->clear = req->selectAll = 0;
if (eventType==XkbMapNotify) { if (eventType == XkbMapNotify) {
/* we need all of the client info, even if the application */ /* we need all of the client info, even if the application */
/* doesn't. Make sure that we always request the stuff */ /* doesn't. Make sure that we always request the stuff */
/* that the implicit support needs, and just filter out anything */ /* that the implicit support needs, and just filter out anything */
/* the client doesn't want later */ /* the client doesn't want later */
req->affectWhich = 0; req->affectWhich = 0;
req->selectAll = 0; req->selectAll = 0;
req->clear = 0; req->clear = 0;
req->affectMap = (CARD16)affect; req->affectMap = (CARD16) affect;
req->map = (CARD16)details|(XkbAllClientInfoMask&affect); req->map = (CARD16) details | (XkbAllClientInfoMask & affect);
req->affectWhich = XkbMapNotifyMask; req->affectWhich = XkbMapNotifyMask;
xkbi->selected_map_details&= ~affect; xkbi->selected_map_details &= ~affect;
xkbi->selected_map_details|= (details&affect); xkbi->selected_map_details |= (details & affect);
} }
else { else {
req->affectMap = req->map = 0; req->affectMap = req->map = 0;
req->affectWhich= (1<<eventType); req->affectWhich = (1 << eventType);
switch (eventType) { switch (eventType) {
case XkbNewKeyboardNotify: case XkbNewKeyboardNotify:
xkbi->selected_nkn_details&= ~affect; xkbi->selected_nkn_details &= ~affect;
xkbi->selected_nkn_details|= (details&affect); xkbi->selected_nkn_details |= (details & affect);
if (!(xkbi->xlib_ctrls&XkbLC_IgnoreNewKeyboards)) if (!(xkbi->xlib_ctrls & XkbLC_IgnoreNewKeyboards))
details= (affect&XkbAllNewKeyboardEventsMask); details = (affect & XkbAllNewKeyboardEventsMask);
case XkbStateNotify: case XkbStateNotify:
case XkbNamesNotify: case XkbNamesNotify:
case XkbAccessXNotify: case XkbAccessXNotify:
case XkbExtensionDeviceNotify: case XkbExtensionDeviceNotify:
size= 2; size = 2;
req->length+= 1; req->length += 1;
break; break;
case XkbControlsNotify: case XkbControlsNotify:
case XkbIndicatorStateNotify: case XkbIndicatorStateNotify:
case XkbIndicatorMapNotify: case XkbIndicatorMapNotify:
size= 4; size = 4;
req->length+= 2; req->length += 2;
break; break;
case XkbBellNotify: case XkbBellNotify:
case XkbActionMessage: case XkbActionMessage:
case XkbCompatMapNotify: case XkbCompatMapNotify:
size= 1; size = 1;
req->length+= 1; req->length += 1;
break; break;
} }
BufAlloc(char *,out,(((size*2)+(unsigned)3)/4)*4); BufAlloc(char *, out, (((size * 2) + (unsigned) 3) / 4) * 4);
u.c8= (CARD8 *)out;
if (size==2) { u.c8 = (CARD8 *) out;
u.c16[0]= (CARD16)affect; if (size == 2) {
u.c16[1]= (CARD16)details; u.c16[0] = (CARD16) affect;
} u.c16[1] = (CARD16) details;
else if (size==4) { }
u.c32[0]= (CARD32)affect; else if (size == 4) {
u.c32[1]= (CARD32)details; u.c32[0] = (CARD32) affect;
} u.c32[1] = (CARD32) details;
else { }
u.c8[0]= (CARD8)affect; else {
u.c8[1]= (CARD8)details; u.c8[0] = (CARD8) affect;
} u.c8[1] = (CARD8) details;
}
} }
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
...@@ -221,24 +229,24 @@ XkbSelectEventDetails( Display * dpy, ...@@ -221,24 +229,24 @@ XkbSelectEventDetails( Display * dpy,
} }
Bool Bool
XkbLockModifiers( Display * dpy, XkbLockModifiers(Display *dpy,
unsigned int deviceSpec, unsigned int deviceSpec,
unsigned int affect, unsigned int affect,
unsigned int values) unsigned int values)
{ {
register xkbLatchLockStateReq *req; register xkbLatchLockStateReq *req;
XkbInfoPtr xkbi; XkbInfoPtr xkbi;
if ((dpy->flags & XlibDisplayNoXkb) || if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return False; return False;
LockDisplay(dpy); LockDisplay(dpy);
xkbi = dpy->xkb_info; xkbi = dpy->xkb_info;
GetReq(kbLatchLockState, req); GetReq(kbLatchLockState, req);
req->reqType = xkbi->codes->major_opcode; req->reqType = xkbi->codes->major_opcode;
req->xkbReqType = X_kbLatchLockState; req->xkbReqType = X_kbLatchLockState;
req->deviceSpec = deviceSpec; req->deviceSpec = deviceSpec;
req->affectModLocks= affect; req->affectModLocks = affect;
req->modLocks = values; req->modLocks = values;
req->lockGroup = False; req->lockGroup = False;
req->groupLock = 0; req->groupLock = 0;
...@@ -252,17 +260,17 @@ XkbLockModifiers( Display * dpy, ...@@ -252,17 +260,17 @@ XkbLockModifiers( Display * dpy,
} }
Bool Bool
XkbLatchModifiers( Display * dpy, XkbLatchModifiers(Display *dpy,
unsigned int deviceSpec, unsigned int deviceSpec,
unsigned int affect, unsigned int affect,
unsigned int values) unsigned int values)
{ {
register xkbLatchLockStateReq *req; register xkbLatchLockStateReq *req;
XkbInfoPtr xkbi; XkbInfoPtr xkbi;
if ((dpy->flags & XlibDisplayNoXkb) || if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return False; return False;
LockDisplay(dpy); LockDisplay(dpy);
xkbi = dpy->xkb_info; xkbi = dpy->xkb_info;
GetReq(kbLatchLockState, req); GetReq(kbLatchLockState, req);
...@@ -270,7 +278,7 @@ XkbLatchModifiers( Display * dpy, ...@@ -270,7 +278,7 @@ XkbLatchModifiers( Display * dpy,
req->xkbReqType = X_kbLatchLockState; req->xkbReqType = X_kbLatchLockState;
req->deviceSpec = deviceSpec; req->deviceSpec = deviceSpec;
req->affectModLatches= affect; req->affectModLatches = affect;
req->modLatches = values; req->modLatches = values;
req->latchGroup = False; req->latchGroup = False;
req->groupLatch = 0; req->groupLatch = 0;
...@@ -285,21 +293,21 @@ XkbLatchModifiers( Display * dpy, ...@@ -285,21 +293,21 @@ XkbLatchModifiers( Display * dpy,
} }
Bool Bool
XkbLockGroup(Display *dpy,unsigned int deviceSpec,unsigned int group) XkbLockGroup(Display *dpy, unsigned int deviceSpec, unsigned int group)
{ {
register xkbLatchLockStateReq *req; register xkbLatchLockStateReq *req;
XkbInfoPtr xkbi; XkbInfoPtr xkbi;
if ((dpy->flags & XlibDisplayNoXkb) || if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return False; return False;
LockDisplay(dpy); LockDisplay(dpy);
xkbi = dpy->xkb_info; xkbi = dpy->xkb_info;
GetReq(kbLatchLockState, req); GetReq(kbLatchLockState, req);
req->reqType = xkbi->codes->major_opcode; req->reqType = xkbi->codes->major_opcode;
req->xkbReqType = X_kbLatchLockState; req->xkbReqType = X_kbLatchLockState;
req->deviceSpec = deviceSpec; req->deviceSpec = deviceSpec;
req->affectModLocks= 0; req->affectModLocks = 0;
req->modLocks = 0; req->modLocks = 0;
req->lockGroup = True; req->lockGroup = True;
req->groupLock = group; req->groupLock = group;
...@@ -313,14 +321,14 @@ XkbLockGroup(Display *dpy,unsigned int deviceSpec,unsigned int group) ...@@ -313,14 +321,14 @@ XkbLockGroup(Display *dpy,unsigned int deviceSpec,unsigned int group)
} }
Bool Bool
XkbLatchGroup(Display *dpy,unsigned int deviceSpec,unsigned int group) XkbLatchGroup(Display *dpy, unsigned int deviceSpec, unsigned int group)
{ {
register xkbLatchLockStateReq *req; register xkbLatchLockStateReq *req;
XkbInfoPtr xkbi; XkbInfoPtr xkbi;
if ((dpy->flags & XlibDisplayNoXkb) || if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return False; return False;
LockDisplay(dpy); LockDisplay(dpy);
xkbi = dpy->xkb_info; xkbi = dpy->xkb_info;
GetReq(kbLatchLockState, req); GetReq(kbLatchLockState, req);
...@@ -328,7 +336,7 @@ XkbLatchGroup(Display *dpy,unsigned int deviceSpec,unsigned int group) ...@@ -328,7 +336,7 @@ XkbLatchGroup(Display *dpy,unsigned int deviceSpec,unsigned int group)
req->xkbReqType = X_kbLatchLockState; req->xkbReqType = X_kbLatchLockState;
req->deviceSpec = deviceSpec; req->deviceSpec = deviceSpec;
req->affectModLatches= 0; req->affectModLatches = 0;
req->modLatches = 0; req->modLatches = 0;
req->latchGroup = True; req->latchGroup = True;
req->groupLatch = group; req->groupLatch = group;
...@@ -343,15 +351,15 @@ XkbLatchGroup(Display *dpy,unsigned int deviceSpec,unsigned int group) ...@@ -343,15 +351,15 @@ XkbLatchGroup(Display *dpy,unsigned int deviceSpec,unsigned int group)
} }
unsigned unsigned
XkbSetXlibControls(Display *dpy,unsigned affect,unsigned values) XkbSetXlibControls(Display *dpy, unsigned affect, unsigned values)
{ {
if (!dpy->xkb_info) if (!dpy->xkb_info)
XkbUseExtension(dpy,NULL,NULL); XkbUseExtension(dpy, NULL, NULL);
if (!dpy->xkb_info) if (!dpy->xkb_info)
return 0; return 0;
affect&= XkbLC_AllControls; affect &= XkbLC_AllControls;
dpy->xkb_info->xlib_ctrls&= ~affect; dpy->xkb_info->xlib_ctrls &= ~affect;
dpy->xkb_info->xlib_ctrls|= (affect&values); dpy->xkb_info->xlib_ctrls |= (affect & values);
return dpy->xkb_info->xlib_ctrls; return dpy->xkb_info->xlib_ctrls;
} }
...@@ -359,9 +367,9 @@ unsigned ...@@ -359,9 +367,9 @@ unsigned
XkbGetXlibControls(Display *dpy) XkbGetXlibControls(Display *dpy)
{ {
if (!dpy->xkb_info) if (!dpy->xkb_info)
XkbUseExtension(dpy,NULL,NULL); XkbUseExtension(dpy, NULL, NULL);
if (!dpy->xkb_info) if (!dpy->xkb_info)
return 0; return 0;
return dpy->xkb_info->xlib_ctrls; return dpy->xkb_info->xlib_ctrls;
} }
...@@ -371,155 +379,157 @@ XkbXlibControlsImplemented(void) ...@@ -371,155 +379,157 @@ XkbXlibControlsImplemented(void)
#ifdef __sgi #ifdef __sgi
return XkbLC_AllControls; return XkbLC_AllControls;
#else #else
return XkbLC_AllControls&~XkbLC_AllComposeControls; return XkbLC_AllControls & ~XkbLC_AllComposeControls;
#endif #endif
} }
Bool Bool
XkbSetDebuggingFlags( Display * dpy, XkbSetDebuggingFlags(Display *dpy,
unsigned int mask, unsigned int mask,
unsigned int flags, unsigned int flags,
char * msg, char *msg,
unsigned int ctrls_mask, unsigned int ctrls_mask,
unsigned int ctrls, unsigned int ctrls,
unsigned int * rtrn_flags, unsigned int *rtrn_flags,
unsigned int * rtrn_ctrls) unsigned int *rtrn_ctrls)
{ {
register xkbSetDebuggingFlagsReq *req; register xkbSetDebuggingFlagsReq *req;
xkbSetDebuggingFlagsReply rep; xkbSetDebuggingFlagsReply rep;
XkbInfoPtr xkbi; XkbInfoPtr xkbi;
if ((dpy->flags & XlibDisplayNoXkb) || if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return False; return False;
LockDisplay(dpy); LockDisplay(dpy);
xkbi = dpy->xkb_info; xkbi = dpy->xkb_info;
GetReq(kbSetDebuggingFlags, req); GetReq(kbSetDebuggingFlags, req);
req->reqType= xkbi->codes->major_opcode; req->reqType = xkbi->codes->major_opcode;
req->xkbReqType= X_kbSetDebuggingFlags; req->xkbReqType = X_kbSetDebuggingFlags;
req->affectFlags= mask; req->affectFlags = mask;
req->flags= flags; req->flags = flags;
req->affectCtrls= ctrls_mask; req->affectCtrls = ctrls_mask;
req->ctrls= ctrls; req->ctrls = ctrls;
if (msg) { if (msg) {
char *out; char *out;
req->msgLength= (unsigned short)strlen(msg)+1;
req->length+= (req->msgLength+(unsigned)3)>>2; req->msgLength = (unsigned short) strlen(msg) + 1;
BufAlloc(char *,out,((req->msgLength+(unsigned)3)/4)*4); req->length += (req->msgLength + (unsigned) 3) >> 2;
memcpy(out,msg,req->msgLength); BufAlloc(char *, out, ((req->msgLength + (unsigned) 3) / 4) * 4);
memcpy(out, msg, req->msgLength);
} }
else req->msgLength= 0; else
if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { req->msgLength = 0;
UnlockDisplay(dpy); if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) {
SyncHandle(); UnlockDisplay(dpy);
return False; SyncHandle();
return False;
} }
if (rtrn_flags) if (rtrn_flags)
*rtrn_flags= rep.currentFlags; *rtrn_flags = rep.currentFlags;
if (rtrn_ctrls) if (rtrn_ctrls)
*rtrn_ctrls= rep.currentCtrls; *rtrn_ctrls = rep.currentCtrls;
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
return True; return True;
} }
Bool Bool
XkbComputeEffectiveMap( XkbDescPtr xkb, XkbComputeEffectiveMap(XkbDescPtr xkb,
XkbKeyTypePtr type, XkbKeyTypePtr type,
unsigned char * map_rtrn) unsigned char *map_rtrn)
{ {
register int i; register int i;
unsigned tmp; unsigned tmp;
XkbKTMapEntryPtr entry = NULL; XkbKTMapEntryPtr entry = NULL;
if ((!xkb)||(!type)||(!xkb->server)) if ((!xkb) || (!type) || (!xkb->server))
return False; return False;
if (type->mods.vmods!=0) { if (type->mods.vmods != 0) {
if (!XkbVirtualModsToReal(xkb,type->mods.vmods,&tmp)) if (!XkbVirtualModsToReal(xkb, type->mods.vmods, &tmp))
return False; return False;
type->mods.mask= tmp|type->mods.real_mods; type->mods.mask = tmp | type->mods.real_mods;
entry= type->map; entry = type->map;
for (i=0;i<type->map_count;i++,entry++) { for (i = 0; i < type->map_count; i++, entry++) {
tmp= 0; tmp = 0;
if (entry->mods.vmods!=0) { if (entry->mods.vmods != 0) {
if (!XkbVirtualModsToReal(xkb,entry->mods.vmods,&tmp)) if (!XkbVirtualModsToReal(xkb, entry->mods.vmods, &tmp))
return False; return False;
if (tmp==0) { if (tmp == 0) {
entry->active= False; entry->active = False;
continue; continue;
} }
} }
entry->active= True; entry->active = True;
entry->mods.mask= (entry->mods.real_mods|tmp)&type->mods.mask; entry->mods.mask = (entry->mods.real_mods | tmp) & type->mods.mask;
} }
} }
else { else {
type->mods.mask= type->mods.real_mods; type->mods.mask = type->mods.real_mods;
} }
if (map_rtrn!=NULL) { if (map_rtrn != NULL) {
bzero(map_rtrn,type->mods.mask+1); bzero(map_rtrn, type->mods.mask + 1);
for (i=0;i<type->map_count;i++) { for (i = 0; i < type->map_count; i++) {
if (entry && entry->active) { if (entry && entry->active) {
map_rtrn[type->map[i].mods.mask]= type->map[i].level; map_rtrn[type->map[i].mods.mask] = type->map[i].level;
} }
} }
} }
return True; return True;
} }
Status Status
XkbGetState(Display *dpy,unsigned deviceSpec,XkbStatePtr rtrn) XkbGetState(Display *dpy, unsigned deviceSpec, XkbStatePtr rtrn)
{ {
register xkbGetStateReq *req; register xkbGetStateReq *req;
xkbGetStateReply rep; xkbGetStateReply rep;
XkbInfoPtr xkbi; XkbInfoPtr xkbi;
if ((dpy->flags & XlibDisplayNoXkb) || if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return BadAccess; return BadAccess;
LockDisplay(dpy); LockDisplay(dpy);
xkbi = dpy->xkb_info; xkbi = dpy->xkb_info;
GetReq(kbGetState, req); GetReq(kbGetState, req);
req->reqType = xkbi->codes->major_opcode; req->reqType = xkbi->codes->major_opcode;
req->xkbReqType = X_kbGetState; req->xkbReqType = X_kbGetState;
req->deviceSpec = deviceSpec; req->deviceSpec = deviceSpec;
if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) {
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
return BadImplementation; return BadImplementation;
} }
rtrn->mods= rep.mods; rtrn->mods = rep.mods;
rtrn->base_mods= rep.baseMods; rtrn->base_mods = rep.baseMods;
rtrn->latched_mods= rep.latchedMods; rtrn->latched_mods = rep.latchedMods;
rtrn->locked_mods= rep.lockedMods; rtrn->locked_mods = rep.lockedMods;
rtrn->group= rep.group; rtrn->group = rep.group;
rtrn->base_group= rep.baseGroup; rtrn->base_group = rep.baseGroup;
rtrn->latched_group= rep.latchedGroup; rtrn->latched_group = rep.latchedGroup;
rtrn->locked_group= rep.lockedGroup; rtrn->locked_group = rep.lockedGroup;
rtrn->compat_state= rep.compatState; rtrn->compat_state = rep.compatState;
rtrn->grab_mods= rep.grabMods; rtrn->grab_mods = rep.grabMods;
rtrn->compat_grab_mods= rep.compatGrabMods; rtrn->compat_grab_mods = rep.compatGrabMods;
rtrn->lookup_mods= rep.lookupMods; rtrn->lookup_mods = rep.lookupMods;
rtrn->compat_lookup_mods= rep.compatLookupMods; rtrn->compat_lookup_mods = rep.compatLookupMods;
rtrn->ptr_buttons= rep.ptrBtnState; rtrn->ptr_buttons = rep.ptrBtnState;
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
return Success; return Success;
} }
Bool Bool
XkbSetDetectableAutoRepeat(Display *dpy,Bool detectable,Bool *supported) XkbSetDetectableAutoRepeat(Display *dpy, Bool detectable, Bool *supported)
{ {
register xkbPerClientFlagsReq * req; register xkbPerClientFlagsReq *req;
xkbPerClientFlagsReply rep; xkbPerClientFlagsReply rep;
XkbInfoPtr xkbi; XkbInfoPtr xkbi;
if ((dpy->flags & XlibDisplayNoXkb) || if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return False; return False;
LockDisplay(dpy); LockDisplay(dpy);
xkbi = dpy->xkb_info; xkbi = dpy->xkb_info;
GetReq(kbPerClientFlags, req); GetReq(kbPerClientFlags, req);
...@@ -528,31 +538,32 @@ XkbInfoPtr xkbi; ...@@ -528,31 +538,32 @@ XkbInfoPtr xkbi;
req->deviceSpec = XkbUseCoreKbd; req->deviceSpec = XkbUseCoreKbd;
req->change = XkbPCF_DetectableAutoRepeatMask; req->change = XkbPCF_DetectableAutoRepeatMask;
if (detectable) if (detectable)
req->value = XkbPCF_DetectableAutoRepeatMask; req->value = XkbPCF_DetectableAutoRepeatMask;
else req->value = 0; else
req->ctrlsToChange = req->autoCtrls= req->autoCtrlValues= 0; req->value = 0;
if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { req->ctrlsToChange = req->autoCtrls = req->autoCtrlValues = 0;
UnlockDisplay(dpy); if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) {
SyncHandle(); UnlockDisplay(dpy);
return False; SyncHandle();
return False;
} }
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
if (supported!=NULL) if (supported != NULL)
*supported= ((rep.supported&XkbPCF_DetectableAutoRepeatMask)!=0); *supported = ((rep.supported & XkbPCF_DetectableAutoRepeatMask) != 0);
return ((rep.value&XkbPCF_DetectableAutoRepeatMask)!=0); return ((rep.value & XkbPCF_DetectableAutoRepeatMask) != 0);
} }
Bool Bool
XkbGetDetectableAutoRepeat(Display *dpy,Bool *supported) XkbGetDetectableAutoRepeat(Display *dpy, Bool *supported)
{ {
register xkbPerClientFlagsReq * req; register xkbPerClientFlagsReq *req;
xkbPerClientFlagsReply rep; xkbPerClientFlagsReply rep;
XkbInfoPtr xkbi; XkbInfoPtr xkbi;
if ((dpy->flags & XlibDisplayNoXkb) || if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return False; return False;
LockDisplay(dpy); LockDisplay(dpy);
xkbi = dpy->xkb_info; xkbi = dpy->xkb_info;
GetReq(kbPerClientFlags, req); GetReq(kbPerClientFlags, req);
...@@ -561,32 +572,32 @@ XkbInfoPtr xkbi; ...@@ -561,32 +572,32 @@ XkbInfoPtr xkbi;
req->deviceSpec = XkbUseCoreKbd; req->deviceSpec = XkbUseCoreKbd;
req->change = 0; req->change = 0;
req->value = 0; req->value = 0;
req->ctrlsToChange = req->autoCtrls= req->autoCtrlValues= 0; req->ctrlsToChange = req->autoCtrls = req->autoCtrlValues = 0;
if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) {
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
return False; return False;
} }
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
if (supported!=NULL) if (supported != NULL)
*supported= ((rep.supported&XkbPCF_DetectableAutoRepeatMask)!=0); *supported = ((rep.supported & XkbPCF_DetectableAutoRepeatMask) != 0);
return ((rep.value&XkbPCF_DetectableAutoRepeatMask)!=0); return ((rep.value & XkbPCF_DetectableAutoRepeatMask) != 0);
} }
Bool Bool
XkbSetAutoResetControls( Display * dpy, XkbSetAutoResetControls(Display *dpy,
unsigned changes, unsigned changes,
unsigned * auto_ctrls, unsigned *auto_ctrls,
unsigned * auto_values) unsigned *auto_values)
{ {
register xkbPerClientFlagsReq * req; register xkbPerClientFlagsReq *req;
xkbPerClientFlagsReply rep; xkbPerClientFlagsReply rep;
XkbInfoPtr xkbi; XkbInfoPtr xkbi;
if ((dpy->flags & XlibDisplayNoXkb) || if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return False; return False;
LockDisplay(dpy); LockDisplay(dpy);
xkbi = dpy->xkb_info; xkbi = dpy->xkb_info;
GetReq(kbPerClientFlags, req); GetReq(kbPerClientFlags, req);
...@@ -595,33 +606,33 @@ XkbInfoPtr xkbi; ...@@ -595,33 +606,33 @@ XkbInfoPtr xkbi;
req->change = XkbPCF_AutoResetControlsMask; req->change = XkbPCF_AutoResetControlsMask;
req->deviceSpec = XkbUseCoreKbd; req->deviceSpec = XkbUseCoreKbd;
req->value = XkbPCF_AutoResetControlsMask; req->value = XkbPCF_AutoResetControlsMask;
req->ctrlsToChange= changes; req->ctrlsToChange = changes;
req->autoCtrls= *auto_ctrls; req->autoCtrls = *auto_ctrls;
req->autoCtrlValues= *auto_values; req->autoCtrlValues = *auto_values;
if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) {
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
return False; return False;
} }
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
*auto_ctrls= rep.autoCtrls; *auto_ctrls = rep.autoCtrls;
*auto_values= rep.autoCtrlValues; *auto_values = rep.autoCtrlValues;
return ((rep.value&XkbPCF_AutoResetControlsMask)!=0); return ((rep.value & XkbPCF_AutoResetControlsMask) != 0);
} }
Bool Bool
XkbGetAutoResetControls( Display * dpy, XkbGetAutoResetControls(Display *dpy,
unsigned * auto_ctrls, unsigned *auto_ctrls,
unsigned * auto_ctrl_values) unsigned *auto_ctrl_values)
{ {
register xkbPerClientFlagsReq * req; register xkbPerClientFlagsReq *req;
xkbPerClientFlagsReply rep; xkbPerClientFlagsReply rep;
XkbInfoPtr xkbi; XkbInfoPtr xkbi;
if ((dpy->flags & XlibDisplayNoXkb) || if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return False; return False;
LockDisplay(dpy); LockDisplay(dpy);
xkbi = dpy->xkb_info; xkbi = dpy->xkb_info;
GetReq(kbPerClientFlags, req); GetReq(kbPerClientFlags, req);
...@@ -630,35 +641,35 @@ XkbInfoPtr xkbi; ...@@ -630,35 +641,35 @@ XkbInfoPtr xkbi;
req->deviceSpec = XkbUseCoreKbd; req->deviceSpec = XkbUseCoreKbd;
req->change = 0; req->change = 0;
req->value = 0; req->value = 0;
req->ctrlsToChange = req->autoCtrls= req->autoCtrlValues= 0; req->ctrlsToChange = req->autoCtrls = req->autoCtrlValues = 0;
if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) {
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
return False; return False;
} }
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
if (auto_ctrls) if (auto_ctrls)
*auto_ctrls= rep.autoCtrls; *auto_ctrls = rep.autoCtrls;
if (auto_ctrl_values) if (auto_ctrl_values)
*auto_ctrl_values= rep.autoCtrlValues; *auto_ctrl_values = rep.autoCtrlValues;
return ((rep.value&XkbPCF_AutoResetControlsMask)!=0); return ((rep.value & XkbPCF_AutoResetControlsMask) != 0);
} }
Bool Bool
XkbSetPerClientControls( Display * dpy, XkbSetPerClientControls(Display *dpy, unsigned change, unsigned *values)
unsigned change,
unsigned * values)
{ {
register xkbPerClientFlagsReq * req; register xkbPerClientFlagsReq *req;
xkbPerClientFlagsReply rep; xkbPerClientFlagsReply rep;
XkbInfoPtr xkbi; XkbInfoPtr xkbi;
unsigned value_hold = *values; unsigned value_hold = *values;
if ((dpy->flags & XlibDisplayNoXkb) || if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)) || (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)) ||
(change & ~(XkbPCF_GrabsUseXKBStateMask|XkbPCF_LookupStateWhenGrabbed|XkbPCF_SendEventUsesXKBState))) (change & ~(XkbPCF_GrabsUseXKBStateMask |
return False; XkbPCF_LookupStateWhenGrabbed |
XkbPCF_SendEventUsesXKBState)))
return False;
LockDisplay(dpy); LockDisplay(dpy);
xkbi = dpy->xkb_info; xkbi = dpy->xkb_info;
GetReq(kbPerClientFlags, req); GetReq(kbPerClientFlags, req);
...@@ -667,30 +678,31 @@ unsigned value_hold = *values; ...@@ -667,30 +678,31 @@ unsigned value_hold = *values;
req->change = change; req->change = change;
req->deviceSpec = XkbUseCoreKbd; req->deviceSpec = XkbUseCoreKbd;
req->value = *values; req->value = *values;
req->ctrlsToChange = req->autoCtrls = req->autoCtrlValues= 0; req->ctrlsToChange = req->autoCtrls = req->autoCtrlValues = 0;
if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) {
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
return False; return False;
} }
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
*values = rep.value; *values = rep.value;
return ((rep.value&value_hold)!=0); return ((rep.value & value_hold) != 0);
} }
Bool Bool
XkbGetPerClientControls( Display * dpy, XkbGetPerClientControls(Display *dpy, unsigned *ctrls)
unsigned * ctrls)
{ {
register xkbPerClientFlagsReq * req; register xkbPerClientFlagsReq *req;
xkbPerClientFlagsReply rep; xkbPerClientFlagsReply rep;
XkbInfoPtr xkbi; XkbInfoPtr xkbi;
if ((dpy->flags & XlibDisplayNoXkb) || if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)) || (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)) ||
(*ctrls & ~(XkbPCF_GrabsUseXKBStateMask|XkbPCF_LookupStateWhenGrabbed|XkbPCF_SendEventUsesXKBState))) (*ctrls & ~(XkbPCF_GrabsUseXKBStateMask |
return False; XkbPCF_LookupStateWhenGrabbed |
XkbPCF_SendEventUsesXKBState)))
return False;
LockDisplay(dpy); LockDisplay(dpy);
xkbi = dpy->xkb_info; xkbi = dpy->xkb_info;
GetReq(kbPerClientFlags, req); GetReq(kbPerClientFlags, req);
...@@ -699,69 +711,71 @@ XkbInfoPtr xkbi; ...@@ -699,69 +711,71 @@ XkbInfoPtr xkbi;
req->deviceSpec = XkbUseCoreKbd; req->deviceSpec = XkbUseCoreKbd;
req->change = 0; req->change = 0;
req->value = 0; req->value = 0;
req->ctrlsToChange = req->autoCtrls= req->autoCtrlValues= 0; req->ctrlsToChange = req->autoCtrls = req->autoCtrlValues = 0;
if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) {
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
return False; return False;
} }
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
if (ctrls) if (ctrls)
*ctrls= (rep.value & (XkbPCF_GrabsUseXKBStateMask | *ctrls = (rep.value & (XkbPCF_GrabsUseXKBStateMask |
XkbPCF_LookupStateWhenGrabbed | XkbPCF_LookupStateWhenGrabbed |
XkbPCF_SendEventUsesXKBState)); XkbPCF_SendEventUsesXKBState));
return (True); return (True);
} }
Display * Display *
XkbOpenDisplay( char * name, XkbOpenDisplay(char *name,
int * ev_rtrn, int *ev_rtrn,
int * err_rtrn, int *err_rtrn,
int * major_rtrn, int *major_rtrn,
int * minor_rtrn, int *minor_rtrn,
int * reason) int *reason)
{ {
Display* dpy; Display *dpy;
int major_num,minor_num; int major_num, minor_num;
if ((major_rtrn!=NULL) && (minor_rtrn!=NULL)) { if ((major_rtrn != NULL) && (minor_rtrn != NULL)) {
if (!XkbLibraryVersion(major_rtrn,minor_rtrn)) { if (!XkbLibraryVersion(major_rtrn, minor_rtrn)) {
if (reason!=NULL) if (reason != NULL)
*reason= XkbOD_BadLibraryVersion; *reason = XkbOD_BadLibraryVersion;
return NULL; return NULL;
} }
} }
else { else {
major_num= XkbMajorVersion; major_num = XkbMajorVersion;
minor_num= XkbMinorVersion; minor_num = XkbMinorVersion;
major_rtrn= &major_num; major_rtrn = &major_num;
minor_rtrn= &minor_num; minor_rtrn = &minor_num;
} }
dpy= XOpenDisplay(name); dpy = XOpenDisplay(name);
if (dpy==NULL) { if (dpy == NULL) {
if (reason!=NULL) if (reason != NULL)
*reason= XkbOD_ConnectionRefused; *reason = XkbOD_ConnectionRefused;
return NULL; return NULL;
} }
if (!XkbQueryExtension(dpy,NULL,ev_rtrn,err_rtrn,major_rtrn,minor_rtrn)) { if (!XkbQueryExtension(dpy, NULL, ev_rtrn, err_rtrn,
if (reason!=NULL) { major_rtrn, minor_rtrn)) {
if ((*major_rtrn!=0)||(*minor_rtrn!=0)) if (reason != NULL) {
*reason= XkbOD_BadServerVersion; if ((*major_rtrn != 0) || (*minor_rtrn != 0))
else *reason= XkbOD_NonXkbServer; *reason = XkbOD_BadServerVersion;
} else
XCloseDisplay(dpy); *reason = XkbOD_NonXkbServer;
return NULL; }
XCloseDisplay(dpy);
return NULL;
} }
if (reason!=NULL) if (reason != NULL)
*reason= XkbOD_Success; *reason = XkbOD_Success;
return dpy; return dpy;
} }
void void
XkbSetAtomFuncs(XkbInternAtomFunc getAtom,XkbGetAtomNameFunc getName) XkbSetAtomFuncs(XkbInternAtomFunc getAtom, XkbGetAtomNameFunc getName)
{ {
_XkbInternAtomFunc= (getAtom?getAtom:XInternAtom); _XkbInternAtomFunc = (getAtom ? getAtom : XInternAtom);
_XkbGetAtomNameFunc= (getName?getName:XGetAtomName); _XkbGetAtomNameFunc = (getName ? getName : XGetAtomName);
return; return;
} }
...@@ -43,73 +43,73 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. ...@@ -43,73 +43,73 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
/*ARGSUSED*/ /*ARGSUSED*/
Status Status
XkbAllocCompatMap(XkbDescPtr xkb,unsigned which,unsigned nSI) XkbAllocCompatMap(XkbDescPtr xkb, unsigned which, unsigned nSI)
{ {
XkbCompatMapPtr compat; XkbCompatMapPtr compat;
XkbSymInterpretRec *prev_interpret; XkbSymInterpretRec *prev_interpret;
if (!xkb) if (!xkb)
return BadMatch; return BadMatch;
if (xkb->compat) { if (xkb->compat) {
if (xkb->compat->size_si>=nSI) if (xkb->compat->size_si >= nSI)
return Success; return Success;
compat= xkb->compat; compat = xkb->compat;
compat->size_si= nSI; compat->size_si = nSI;
if (compat->sym_interpret==NULL) if (compat->sym_interpret == NULL)
compat->num_si= 0; compat->num_si = 0;
prev_interpret = compat->sym_interpret; prev_interpret = compat->sym_interpret;
compat->sym_interpret= _XkbTypedRealloc(compat->sym_interpret, compat->sym_interpret = _XkbTypedRealloc(compat->sym_interpret,
nSI,XkbSymInterpretRec); nSI, XkbSymInterpretRec);
if (compat->sym_interpret==NULL) { if (compat->sym_interpret == NULL) {
_XkbFree(prev_interpret); _XkbFree(prev_interpret);
compat->size_si= compat->num_si= 0; compat->size_si = compat->num_si = 0;
return BadAlloc; return BadAlloc;
} }
if (compat->num_si!=0) { if (compat->num_si != 0) {
_XkbClearElems(compat->sym_interpret,compat->num_si, _XkbClearElems(compat->sym_interpret, compat->num_si,
compat->size_si-1,XkbSymInterpretRec); compat->size_si - 1, XkbSymInterpretRec);
} }
return Success; return Success;
} }
compat= _XkbTypedCalloc(1,XkbCompatMapRec); compat = _XkbTypedCalloc(1, XkbCompatMapRec);
if (compat==NULL) if (compat == NULL)
return BadAlloc; return BadAlloc;
if (nSI>0) { if (nSI > 0) {
compat->sym_interpret= _XkbTypedCalloc(nSI,XkbSymInterpretRec); compat->sym_interpret = _XkbTypedCalloc(nSI, XkbSymInterpretRec);
if (!compat->sym_interpret) { if (!compat->sym_interpret) {
_XkbFree(compat); _XkbFree(compat);
return BadAlloc; return BadAlloc;
} }
} }
compat->size_si= nSI; compat->size_si = nSI;
compat->num_si= 0; compat->num_si = 0;
bzero((char *)&compat->groups[0],XkbNumKbdGroups*sizeof(XkbModsRec)); bzero((char *) &compat->groups[0], XkbNumKbdGroups * sizeof(XkbModsRec));
xkb->compat= compat; xkb->compat = compat;
return Success; return Success;
} }
void void
XkbFreeCompatMap(XkbDescPtr xkb,unsigned which,Bool freeMap) XkbFreeCompatMap(XkbDescPtr xkb, unsigned which, Bool freeMap)
{ {
register XkbCompatMapPtr compat; register XkbCompatMapPtr compat;
if ((xkb==NULL)||(xkb->compat==NULL)) if ((xkb == NULL) || (xkb->compat == NULL))
return; return;
compat= xkb->compat; compat = xkb->compat;
if (freeMap) if (freeMap)
which= XkbAllCompatMask; which = XkbAllCompatMask;
if (which&XkbGroupCompatMask) if (which & XkbGroupCompatMask)
bzero((char *)&compat->groups[0],XkbNumKbdGroups*sizeof(XkbModsRec)); bzero(&compat->groups[0], XkbNumKbdGroups * sizeof(XkbModsRec));
if (which&XkbSymInterpMask) { if (which & XkbSymInterpMask) {
if ((compat->sym_interpret)&&(compat->size_si>0)) if ((compat->sym_interpret) && (compat->size_si > 0))
_XkbFree(compat->sym_interpret); _XkbFree(compat->sym_interpret);
compat->size_si= compat->num_si= 0; compat->size_si = compat->num_si = 0;
compat->sym_interpret= NULL; compat->sym_interpret = NULL;
} }
if (freeMap) { if (freeMap) {
_XkbFree(compat); _XkbFree(compat);
xkb->compat= NULL; xkb->compat = NULL;
} }
return; return;
} }
...@@ -117,127 +117,133 @@ register XkbCompatMapPtr compat; ...@@ -117,127 +117,133 @@ register XkbCompatMapPtr compat;
/***===================================================================***/ /***===================================================================***/
Status Status
XkbAllocNames(XkbDescPtr xkb,unsigned which,int nTotalRG,int nTotalAliases) XkbAllocNames(XkbDescPtr xkb, unsigned which, int nTotalRG, int nTotalAliases)
{ {
XkbNamesPtr names; XkbNamesPtr names;
if (xkb==NULL) if (xkb == NULL)
return BadMatch; return BadMatch;
if (xkb->names==NULL) { if (xkb->names == NULL) {
xkb->names = _XkbTypedCalloc(1,XkbNamesRec); xkb->names = _XkbTypedCalloc(1, XkbNamesRec);
if (xkb->names==NULL) if (xkb->names == NULL)
return BadAlloc; return BadAlloc;
} }
names= xkb->names; names = xkb->names;
if ((which&XkbKTLevelNamesMask)&&(xkb->map!=NULL)&&(xkb->map->types!=NULL)){ if ((which & XkbKTLevelNamesMask) && (xkb->map != NULL) &&
register int i; (xkb->map->types != NULL)) {
XkbKeyTypePtr type; register int i;
XkbKeyTypePtr type;
type= xkb->map->types;
for (i=0;i<xkb->map->num_types;i++,type++) { type = xkb->map->types;
if (type->level_names==NULL) { for (i = 0; i < xkb->map->num_types; i++, type++) {
type->level_names= _XkbTypedCalloc(type->num_levels,Atom); if (type->level_names == NULL) {
if (type->level_names==NULL) type->level_names = _XkbTypedCalloc(type->num_levels, Atom);
return BadAlloc; if (type->level_names == NULL)
} return BadAlloc;
} }
}
} }
if ((which&XkbKeyNamesMask)&&(names->keys==NULL)) { if ((which & XkbKeyNamesMask) && (names->keys == NULL)) {
if ((!XkbIsLegalKeycode(xkb->min_key_code))|| if ((!XkbIsLegalKeycode(xkb->min_key_code)) ||
(!XkbIsLegalKeycode(xkb->max_key_code))|| (!XkbIsLegalKeycode(xkb->max_key_code)) ||
(xkb->max_key_code<xkb->min_key_code)) (xkb->max_key_code < xkb->min_key_code))
return BadValue; return BadValue;
names->keys= _XkbTypedCalloc((xkb->max_key_code+1),XkbKeyNameRec); names->keys = _XkbTypedCalloc((xkb->max_key_code + 1), XkbKeyNameRec);
if (names->keys==NULL) if (names->keys == NULL)
return BadAlloc; return BadAlloc;
} }
if ((which&XkbKeyAliasesMask)&&(nTotalAliases>0)) { if ((which & XkbKeyAliasesMask) && (nTotalAliases > 0)) {
if (names->key_aliases==NULL) { if (names->key_aliases == NULL) {
names->key_aliases= _XkbTypedCalloc(nTotalAliases,XkbKeyAliasRec); names->key_aliases = _XkbTypedCalloc(nTotalAliases, XkbKeyAliasRec);
} }
else if (nTotalAliases>names->num_key_aliases) { else if (nTotalAliases > names->num_key_aliases) {
XkbKeyAliasRec *prev_aliases = names->key_aliases; XkbKeyAliasRec *prev_aliases = names->key_aliases;
names->key_aliases= _XkbTypedRealloc(names->key_aliases, names->key_aliases = _XkbTypedRealloc(names->key_aliases,
nTotalAliases,XkbKeyAliasRec); nTotalAliases,
if (names->key_aliases!=NULL) { XkbKeyAliasRec);
_XkbClearElems(names->key_aliases,names->num_key_aliases, if (names->key_aliases != NULL) {
nTotalAliases-1,XkbKeyAliasRec); _XkbClearElems(names->key_aliases, names->num_key_aliases,
} else { nTotalAliases - 1, XkbKeyAliasRec);
_XkbFree(prev_aliases); }
} else {
} _XkbFree(prev_aliases);
if (names->key_aliases==NULL) { }
names->num_key_aliases= 0; }
return BadAlloc; if (names->key_aliases == NULL) {
} names->num_key_aliases = 0;
names->num_key_aliases= nTotalAliases; return BadAlloc;
}
names->num_key_aliases = nTotalAliases;
} }
if ((which&XkbRGNamesMask)&&(nTotalRG>0)) { if ((which & XkbRGNamesMask) && (nTotalRG > 0)) {
if (names->radio_groups==NULL) { if (names->radio_groups == NULL) {
names->radio_groups= _XkbTypedCalloc(nTotalRG,Atom); names->radio_groups = _XkbTypedCalloc(nTotalRG, Atom);
} }
else if (nTotalRG>names->num_rg) { else if (nTotalRG > names->num_rg) {
Atom *prev_radio_groups = names->radio_groups; Atom *prev_radio_groups = names->radio_groups;
names->radio_groups= _XkbTypedRealloc(names->radio_groups,nTotalRG, names->radio_groups =
Atom); _XkbTypedRealloc(names->radio_groups, nTotalRG, Atom);
if (names->radio_groups!=NULL) { if (names->radio_groups != NULL) {
_XkbClearElems(names->radio_groups,names->num_rg,nTotalRG-1, _XkbClearElems(names->radio_groups, names->num_rg, nTotalRG - 1,
Atom); Atom);
} else { }
_XkbFree(prev_radio_groups); else {
} _XkbFree(prev_radio_groups);
} }
if (names->radio_groups==NULL) }
return BadAlloc; if (names->radio_groups == NULL)
names->num_rg= nTotalRG; return BadAlloc;
names->num_rg = nTotalRG;
} }
return Success; return Success;
} }
void void
XkbFreeNames(XkbDescPtr xkb,unsigned which,Bool freeMap) XkbFreeNames(XkbDescPtr xkb, unsigned which, Bool freeMap)
{ {
XkbNamesPtr names; XkbNamesPtr names;
if ((xkb==NULL)||(xkb->names==NULL)) if ((xkb == NULL) || (xkb->names == NULL))
return; return;
names= xkb->names; names = xkb->names;
if (freeMap) if (freeMap)
which= XkbAllNamesMask; which = XkbAllNamesMask;
if (which&XkbKTLevelNamesMask) { if (which & XkbKTLevelNamesMask) {
XkbClientMapPtr map= xkb->map; XkbClientMapPtr map = xkb->map;
if ((map!=NULL)&&(map->types!=NULL)) {
register int i; if ((map != NULL) && (map->types != NULL)) {
register XkbKeyTypePtr type; register int i;
type= map->types; register XkbKeyTypePtr type;
for (i=0;i<map->num_types;i++,type++) {
if (type->level_names!=NULL) { type = map->types;
_XkbFree(type->level_names); for (i = 0; i < map->num_types; i++, type++) {
type->level_names= NULL; if (type->level_names != NULL) {
} _XkbFree(type->level_names);
} type->level_names = NULL;
} }
}
}
} }
if ((which&XkbKeyNamesMask)&&(names->keys!=NULL)) { if ((which & XkbKeyNamesMask) && (names->keys != NULL)) {
_XkbFree(names->keys); _XkbFree(names->keys);
names->keys= NULL; names->keys = NULL;
names->num_keys= 0; names->num_keys = 0;
} }
if ((which&XkbKeyAliasesMask)&&(names->key_aliases)){ if ((which & XkbKeyAliasesMask) && (names->key_aliases)) {
_XkbFree(names->key_aliases); _XkbFree(names->key_aliases);
names->key_aliases=NULL; names->key_aliases = NULL;
names->num_key_aliases=0; names->num_key_aliases = 0;
} }
if ((which&XkbRGNamesMask)&&(names->radio_groups)) { if ((which & XkbRGNamesMask) && (names->radio_groups)) {
_XkbFree(names->radio_groups); _XkbFree(names->radio_groups);
names->radio_groups= NULL; names->radio_groups = NULL;
names->num_rg= 0; names->num_rg = 0;
} }
if (freeMap) { if (freeMap) {
_XkbFree(names); _XkbFree(names);
xkb->names= NULL; xkb->names = NULL;
} }
return; return;
} }
...@@ -246,26 +252,26 @@ XkbNamesPtr names; ...@@ -246,26 +252,26 @@ XkbNamesPtr names;
/*ARGSUSED*/ /*ARGSUSED*/
Status Status
XkbAllocControls(XkbDescPtr xkb,unsigned which) XkbAllocControls(XkbDescPtr xkb, unsigned which)
{ {
if (xkb==NULL) if (xkb == NULL)
return BadMatch; return BadMatch;
if (xkb->ctrls==NULL) { if (xkb->ctrls == NULL) {
xkb->ctrls= _XkbTypedCalloc(1,XkbControlsRec); xkb->ctrls = _XkbTypedCalloc(1, XkbControlsRec);
if (!xkb->ctrls) if (!xkb->ctrls)
return BadAlloc; return BadAlloc;
} }
return Success; return Success;
} }
/*ARGSUSED*/ /*ARGSUSED*/
void void
XkbFreeControls(XkbDescPtr xkb,unsigned which,Bool freeMap) XkbFreeControls(XkbDescPtr xkb, unsigned which, Bool freeMap)
{ {
if (freeMap && (xkb!=NULL) && (xkb->ctrls!=NULL)) { if (freeMap && (xkb != NULL) && (xkb->ctrls != NULL)) {
_XkbFree(xkb->ctrls); _XkbFree(xkb->ctrls);
xkb->ctrls= NULL; xkb->ctrls = NULL;
} }
return; return;
} }
...@@ -275,12 +281,12 @@ XkbFreeControls(XkbDescPtr xkb,unsigned which,Bool freeMap) ...@@ -275,12 +281,12 @@ XkbFreeControls(XkbDescPtr xkb,unsigned which,Bool freeMap)
Status Status
XkbAllocIndicatorMaps(XkbDescPtr xkb) XkbAllocIndicatorMaps(XkbDescPtr xkb)
{ {
if (xkb==NULL) if (xkb == NULL)
return BadMatch; return BadMatch;
if (xkb->indicators==NULL) { if (xkb->indicators == NULL) {
xkb->indicators= _XkbTypedCalloc(1,XkbIndicatorRec); xkb->indicators = _XkbTypedCalloc(1, XkbIndicatorRec);
if (!xkb->indicators) if (!xkb->indicators)
return BadAlloc; return BadAlloc;
} }
return Success; return Success;
} }
...@@ -288,199 +294,206 @@ XkbAllocIndicatorMaps(XkbDescPtr xkb) ...@@ -288,199 +294,206 @@ XkbAllocIndicatorMaps(XkbDescPtr xkb)
void void
XkbFreeIndicatorMaps(XkbDescPtr xkb) XkbFreeIndicatorMaps(XkbDescPtr xkb)
{ {
if ((xkb!=NULL)&&(xkb->indicators!=NULL)) { if ((xkb != NULL) && (xkb->indicators != NULL)) {
_XkbFree(xkb->indicators); _XkbFree(xkb->indicators);
xkb->indicators= NULL; xkb->indicators = NULL;
} }
return; return;
} }
/***====================================================================***/ /***====================================================================***/
XkbDescRec * XkbDescRec *
XkbAllocKeyboard(void) XkbAllocKeyboard(void)
{ {
XkbDescRec *xkb; XkbDescRec *xkb;
xkb = _XkbTypedCalloc(1,XkbDescRec); xkb = _XkbTypedCalloc(1, XkbDescRec);
if (xkb) if (xkb)
xkb->device_spec= XkbUseCoreKbd; xkb->device_spec = XkbUseCoreKbd;
return xkb; return xkb;
} }
void void
XkbFreeKeyboard(XkbDescPtr xkb,unsigned which,Bool freeAll) XkbFreeKeyboard(XkbDescPtr xkb, unsigned which, Bool freeAll)
{ {
if (xkb==NULL) if (xkb == NULL)
return; return;
if (freeAll) if (freeAll)
which= XkbAllComponentsMask; which = XkbAllComponentsMask;
if (which&XkbClientMapMask) if (which & XkbClientMapMask)
XkbFreeClientMap(xkb,XkbAllClientInfoMask,True); XkbFreeClientMap(xkb, XkbAllClientInfoMask, True);
if (which&XkbServerMapMask) if (which & XkbServerMapMask)
XkbFreeServerMap(xkb,XkbAllServerInfoMask,True); XkbFreeServerMap(xkb, XkbAllServerInfoMask, True);
if (which&XkbCompatMapMask) if (which & XkbCompatMapMask)
XkbFreeCompatMap(xkb,XkbAllCompatMask,True); XkbFreeCompatMap(xkb, XkbAllCompatMask, True);
if (which&XkbIndicatorMapMask) if (which & XkbIndicatorMapMask)
XkbFreeIndicatorMaps(xkb); XkbFreeIndicatorMaps(xkb);
if (which&XkbNamesMask) if (which & XkbNamesMask)
XkbFreeNames(xkb,XkbAllNamesMask,True); XkbFreeNames(xkb, XkbAllNamesMask, True);
if ((which&XkbGeometryMask) && (xkb->geom!=NULL)) if ((which & XkbGeometryMask) && (xkb->geom != NULL))
XkbFreeGeometry(xkb->geom,XkbGeomAllMask,True); XkbFreeGeometry(xkb->geom, XkbGeomAllMask, True);
if (which&XkbControlsMask) if (which & XkbControlsMask)
XkbFreeControls(xkb,XkbAllControlsMask,True); XkbFreeControls(xkb, XkbAllControlsMask, True);
if (freeAll) if (freeAll)
_XkbFree(xkb); _XkbFree(xkb);
return; return;
} }
/***====================================================================***/ /***====================================================================***/
XkbDeviceLedInfoPtr XkbDeviceLedInfoPtr
XkbAddDeviceLedInfo(XkbDeviceInfoPtr devi,unsigned ledClass,unsigned ledId) XkbAddDeviceLedInfo(XkbDeviceInfoPtr devi, unsigned ledClass, unsigned ledId)
{ {
XkbDeviceLedInfoPtr devli; XkbDeviceLedInfoPtr devli;
register int i; register int i;
if ((!devi)||(!XkbSingleXIClass(ledClass))||(!XkbSingleXIId(ledId))) if ((!devi) || (!XkbSingleXIClass(ledClass)) || (!XkbSingleXIId(ledId)))
return NULL; return NULL;
for (i=0,devli=devi->leds;i<devi->num_leds;i++,devli++) { for (i = 0, devli = devi->leds; i < devi->num_leds; i++, devli++) {
if ((devli->led_class==ledClass)&&(devli->led_id==ledId)) if ((devli->led_class == ledClass) && (devli->led_id == ledId))
return devli; return devli;
} }
if (devi->num_leds>=devi->sz_leds) { if (devi->num_leds >= devi->sz_leds) {
XkbDeviceLedInfoRec *prev_leds = devi->leds; XkbDeviceLedInfoRec *prev_leds = devi->leds;
if (devi->sz_leds>0) devi->sz_leds*= 2; if (devi->sz_leds > 0)
else devi->sz_leds= 1; devi->sz_leds *= 2;
devi->leds= _XkbTypedRealloc(devi->leds,devi->sz_leds, else
XkbDeviceLedInfoRec); devi->sz_leds = 1;
if (!devi->leds) { devi->leds = _XkbTypedRealloc(devi->leds, devi->sz_leds,
_XkbFree(prev_leds); XkbDeviceLedInfoRec);
devi->sz_leds= devi->num_leds= 0; if (!devi->leds) {
return NULL; _XkbFree(prev_leds);
} devi->sz_leds = devi->num_leds = 0;
i= devi->num_leds; return NULL;
for (devli=&devi->leds[i];i<devi->sz_leds;i++,devli++) { }
bzero(devli,sizeof(XkbDeviceLedInfoRec)); i = devi->num_leds;
devli->led_class= XkbXINone; for (devli = &devi->leds[i]; i < devi->sz_leds; i++, devli++) {
devli->led_id= XkbXINone; bzero(devli, sizeof(XkbDeviceLedInfoRec));
} devli->led_class = XkbXINone;
devli->led_id = XkbXINone;
}
} }
devli= &devi->leds[devi->num_leds++]; devli = &devi->leds[devi->num_leds++];
bzero(devli,sizeof(XkbDeviceLedInfoRec)); bzero(devli, sizeof(XkbDeviceLedInfoRec));
devli->led_class= ledClass; devli->led_class = ledClass;
devli->led_id= ledId; devli->led_id = ledId;
return devli; return devli;
} }
Status Status
XkbResizeDeviceButtonActions(XkbDeviceInfoPtr devi,unsigned newTotal) XkbResizeDeviceButtonActions(XkbDeviceInfoPtr devi, unsigned newTotal)
{ {
XkbAction *prev_btn_acts; XkbAction *prev_btn_acts;
if ((!devi)||(newTotal>255)) if ((!devi) || (newTotal > 255))
return BadValue; return BadValue;
if ((devi->btn_acts!=NULL)&&(newTotal==devi->num_btns)) if ((devi->btn_acts != NULL) && (newTotal == devi->num_btns))
return Success; return Success;
if (newTotal==0) { if (newTotal == 0) {
if (devi->btn_acts!=NULL) { if (devi->btn_acts != NULL) {
_XkbFree(devi->btn_acts); _XkbFree(devi->btn_acts);
devi->btn_acts= NULL; devi->btn_acts = NULL;
} }
devi->num_btns= 0; devi->num_btns = 0;
return Success; return Success;
} }
prev_btn_acts = devi->btn_acts; prev_btn_acts = devi->btn_acts;
devi->btn_acts= _XkbTypedRealloc(devi->btn_acts,newTotal,XkbAction); devi->btn_acts = _XkbTypedRealloc(devi->btn_acts, newTotal, XkbAction);
if (devi->btn_acts==NULL) { if (devi->btn_acts == NULL) {
_XkbFree(prev_btn_acts); _XkbFree(prev_btn_acts);
devi->num_btns= 0; devi->num_btns = 0;
return BadAlloc; return BadAlloc;
} }
if (newTotal>devi->num_btns) { if (newTotal > devi->num_btns) {
XkbAction *act; XkbAction *act;
act= &devi->btn_acts[devi->num_btns];
bzero((char *)act,(newTotal-devi->num_btns)*sizeof(XkbAction)); act = &devi->btn_acts[devi->num_btns];
bzero((char *) act, (newTotal - devi->num_btns) * sizeof(XkbAction));
} }
devi->num_btns= newTotal; devi->num_btns = newTotal;
return Success; return Success;
} }
/*ARGSUSED*/ /*ARGSUSED*/
XkbDeviceInfoPtr XkbDeviceInfoPtr
XkbAllocDeviceInfo(unsigned deviceSpec,unsigned nButtons,unsigned szLeds) XkbAllocDeviceInfo(unsigned deviceSpec, unsigned nButtons, unsigned szLeds)
{ {
XkbDeviceInfoPtr devi; XkbDeviceInfoPtr devi;
devi= _XkbTypedCalloc(1,XkbDeviceInfoRec); devi = _XkbTypedCalloc(1, XkbDeviceInfoRec);
if (devi!=NULL) { if (devi != NULL) {
devi->device_spec= deviceSpec; devi->device_spec = deviceSpec;
devi->has_own_state= False; devi->has_own_state = False;
devi->num_btns= 0; devi->num_btns = 0;
devi->btn_acts= NULL; devi->btn_acts = NULL;
if (nButtons>0) { if (nButtons > 0) {
devi->num_btns= nButtons; devi->num_btns = nButtons;
devi->btn_acts= _XkbTypedCalloc(nButtons,XkbAction); devi->btn_acts = _XkbTypedCalloc(nButtons, XkbAction);
if (!devi->btn_acts) { if (!devi->btn_acts) {
_XkbFree(devi); _XkbFree(devi);
return NULL; return NULL;
} }
} }
devi->dflt_kbd_fb= XkbXINone; devi->dflt_kbd_fb = XkbXINone;
devi->dflt_led_fb= XkbXINone; devi->dflt_led_fb = XkbXINone;
devi->num_leds= 0; devi->num_leds = 0;
devi->sz_leds= 0; devi->sz_leds = 0;
devi->leds= NULL; devi->leds = NULL;
if (szLeds>0) { if (szLeds > 0) {
devi->sz_leds= szLeds; devi->sz_leds = szLeds;
devi->leds= _XkbTypedCalloc(szLeds,XkbDeviceLedInfoRec); devi->leds = _XkbTypedCalloc(szLeds, XkbDeviceLedInfoRec);
if (!devi->leds) { if (!devi->leds) {
if (devi->btn_acts) if (devi->btn_acts)
_XkbFree(devi->btn_acts); _XkbFree(devi->btn_acts);
_XkbFree(devi); _XkbFree(devi);
return NULL; return NULL;
} }
} }
} }
return devi; return devi;
} }
void void
XkbFreeDeviceInfo(XkbDeviceInfoPtr devi,unsigned which,Bool freeDevI) XkbFreeDeviceInfo(XkbDeviceInfoPtr devi, unsigned which, Bool freeDevI)
{ {
if (devi) { if (devi) {
if (freeDevI) { if (freeDevI) {
which= XkbXI_AllDeviceFeaturesMask; which = XkbXI_AllDeviceFeaturesMask;
if (devi->name) { if (devi->name) {
_XkbFree(devi->name); _XkbFree(devi->name);
devi->name= NULL; devi->name = NULL;
} }
} }
if ((which&XkbXI_ButtonActionsMask)&&(devi->btn_acts)) { if ((which & XkbXI_ButtonActionsMask) && (devi->btn_acts)) {
_XkbFree(devi->btn_acts); _XkbFree(devi->btn_acts);
devi->num_btns= 0; devi->num_btns = 0;
devi->btn_acts= NULL; devi->btn_acts = NULL;
} }
if ((which&XkbXI_IndicatorsMask)&&(devi->leds)) { if ((which & XkbXI_IndicatorsMask) && (devi->leds)) {
register int i; register int i;
if ((which&XkbXI_IndicatorsMask)==XkbXI_IndicatorsMask) {
_XkbFree(devi->leds); if ((which & XkbXI_IndicatorsMask) == XkbXI_IndicatorsMask) {
devi->sz_leds= devi->num_leds= 0; _XkbFree(devi->leds);
devi->leds= NULL; devi->sz_leds = devi->num_leds = 0;
} devi->leds = NULL;
else { }
XkbDeviceLedInfoPtr devli; else {
for (i=0,devli=devi->leds;i<devi->num_leds;i++,devli++) { XkbDeviceLedInfoPtr devli;
if (which&XkbXI_IndicatorMapsMask)
bzero((char *)&devli->maps[0],sizeof(devli->maps)); for (i = 0, devli = devi->leds; i < devi->num_leds;
else bzero((char *)&devli->names[0],sizeof(devli->names)); i++, devli++) {
} if (which & XkbXI_IndicatorMapsMask)
} bzero((char *) &devli->maps[0], sizeof(devli->maps));
} else
if (freeDevI) bzero((char *) &devli->names[0], sizeof(devli->names));
_XkbFree(devi); }
}
}
if (freeDevI)
_XkbFree(devi);
} }
return; return;
} }
...@@ -34,145 +34,146 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. ...@@ -34,145 +34,146 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
Bool Bool
XkbDeviceBell( Display * dpy, XkbDeviceBell(Display *dpy,
Window window, Window window,
int deviceID, int deviceID,
int bellClass, int bellClass,
int bellID, int bellID,
int percent, int percent,
Atom name) Atom name)
{ {
register xkbBellReq *req; register xkbBellReq *req;
XkbInfoPtr xkbi; XkbInfoPtr xkbi;
if ((dpy->flags & XlibDisplayNoXkb) || if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return False; return False;
LockDisplay(dpy); LockDisplay(dpy);
xkbi = dpy->xkb_info; xkbi = dpy->xkb_info;
GetReq(kbBell,req); GetReq(kbBell, req);
req->reqType = xkbi->codes->major_opcode; req->reqType = xkbi->codes->major_opcode;
req->xkbReqType = X_kbBell; req->xkbReqType = X_kbBell;
req->deviceSpec = deviceID; req->deviceSpec = deviceID;
req->window = (CARD32)window; req->window = (CARD32) window;
req->bellClass = (CARD16)bellClass; req->bellClass = (CARD16) bellClass;
req->bellID = (CARD16)bellID; req->bellID = (CARD16) bellID;
req->percent = percent; req->percent = percent;
req->forceSound = False; req->forceSound = False;
req->eventOnly = False; req->eventOnly = False;
req->pitch = 0; req->pitch = 0;
req->duration = 0; req->duration = 0;
req->name = (CARD32)name; req->name = (CARD32) name;
req->pad1= 0; req->pad2= 0; req->pad1 = 0;
req->pad2 = 0;
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
return True; return True;
} }
Bool Bool
XkbForceDeviceBell( Display * dpy, XkbForceDeviceBell(Display *dpy,
int deviceID, int deviceID,
int bellClass, int bellClass,
int bellID, int bellID,
int percent) int percent)
{ {
register xkbBellReq *req; register xkbBellReq *req;
XkbInfoPtr xkbi; XkbInfoPtr xkbi;
if ((dpy->flags & XlibDisplayNoXkb) || if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return False; return False;
LockDisplay(dpy); LockDisplay(dpy);
xkbi = dpy->xkb_info; xkbi = dpy->xkb_info;
GetReq(kbBell,req); GetReq(kbBell, req);
req->reqType = xkbi->codes->major_opcode; req->reqType = xkbi->codes->major_opcode;
req->xkbReqType = X_kbBell; req->xkbReqType = X_kbBell;
req->deviceSpec = deviceID; req->deviceSpec = deviceID;
req->window = (CARD32)None; req->window = (CARD32) None;
req->bellClass = (CARD16)bellClass; req->bellClass = (CARD16) bellClass;
req->bellID = (CARD16)bellID; req->bellID = (CARD16) bellID;
req->percent = percent; req->percent = percent;
req->forceSound = True; req->forceSound = True;
req->eventOnly = False; req->eventOnly = False;
req->pitch = 0; req->pitch = 0;
req->duration = 0; req->duration = 0;
req->name = None; req->name = None;
req->pad1= 0; req->pad2= 0; req->pad1 = 0;
req->pad2 = 0;
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
return True; return True;
} }
Bool Bool
XkbDeviceBellEvent( Display * dpy, XkbDeviceBellEvent(Display *dpy,
Window window, Window window,
int deviceID, int deviceID,
int bellClass, int bellClass,
int bellID, int bellID,
int percent, int percent,
Atom name) Atom name)
{ {
register xkbBellReq *req; register xkbBellReq *req;
XkbInfoPtr xkbi; XkbInfoPtr xkbi;
if ((dpy->flags & XlibDisplayNoXkb) || if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return False; return False;
LockDisplay(dpy); LockDisplay(dpy);
xkbi = dpy->xkb_info; xkbi = dpy->xkb_info;
GetReq(kbBell,req); GetReq(kbBell, req);
req->reqType = xkbi->codes->major_opcode; req->reqType = xkbi->codes->major_opcode;
req->xkbReqType = X_kbBell; req->xkbReqType = X_kbBell;
req->deviceSpec = deviceID; req->deviceSpec = deviceID;
req->window = (CARD32)window; req->window = (CARD32) window;
req->bellClass = (CARD16)bellClass; req->bellClass = (CARD16) bellClass;
req->bellID = (CARD16)bellID; req->bellID = (CARD16) bellID;
req->percent = percent; req->percent = percent;
req->forceSound = False; req->forceSound = False;
req->eventOnly = True; req->eventOnly = True;
req->pitch = 0; req->pitch = 0;
req->duration = 0; req->duration = 0;
req->name = (CARD32)name; req->name = (CARD32) name;
req->pad1= 0; req->pad2= 0; req->pad1 = 0;
req->pad2 = 0;
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
return True; return True;
} }
Bool Bool
XkbBell(Display *dpy,Window window,int percent,Atom name) XkbBell(Display *dpy, Window window, int percent, Atom name)
{ {
if ((dpy->flags & XlibDisplayNoXkb) || if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) { (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) {
XBell(dpy,percent); XBell(dpy, percent);
return False; return False;
} }
return XkbDeviceBell(dpy,window,XkbUseCoreKbd,XkbDfltXIClass,XkbDfltXIId, return XkbDeviceBell(dpy, window, XkbUseCoreKbd,
percent,name); XkbDfltXIClass, XkbDfltXIId, percent, name);
} }
Bool Bool
XkbForceBell(Display *dpy,int percent) XkbForceBell(Display *dpy, int percent)
{ {
if ((dpy->flags & XlibDisplayNoXkb) || if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) { (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) {
XBell(dpy,percent); XBell(dpy, percent);
return False; return False;
} }
return XkbForceDeviceBell(dpy,XkbUseCoreKbd,XkbDfltXIClass,XkbDfltXIId, return XkbForceDeviceBell(dpy, XkbUseCoreKbd, XkbDfltXIClass, XkbDfltXIId,
percent); percent);
} }
Bool Bool
XkbBellEvent(Display *dpy,Window window,int percent,Atom name) XkbBellEvent(Display *dpy, Window window, int percent, Atom name)
{ {
if ((dpy->flags & XlibDisplayNoXkb) || if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) { (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) {
return False; return False;
} }
/* class 0 = KbdFeedbackClass (X Input Extension) */ /* class 0 = KbdFeedbackClass (X Input Extension) */
return XkbDeviceBellEvent(dpy,window,XkbUseCoreKbd, return XkbDeviceBellEvent(dpy, window, XkbUseCoreKbd,
XkbDfltXIClass,XkbDfltXIId, XkbDfltXIClass, XkbDfltXIId, percent, name);
percent,name);
} }
...@@ -26,7 +26,7 @@ from The Open Group. ...@@ -26,7 +26,7 @@ from The Open Group.
*/ */
/* the new monsters ate the old ones */ /* the new monsters ate the old ones */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include <config.h> #include <config.h>
...@@ -42,112 +42,116 @@ from The Open Group. ...@@ -42,112 +42,116 @@ from The Open Group.
#include "XKBlibint.h" #include "XKBlibint.h"
#ifdef USE_OWN_COMPOSE #ifdef USE_OWN_COMPOSE
#define COMPOSE_NO_CONST_MEMBERS #define COMPOSE_NO_CONST_MEMBERS
#include "imComp.h" #include "imComp.h"
#endif #endif
#define AllMods (ShiftMask|LockMask|ControlMask| \ #define AllMods (ShiftMask|LockMask|ControlMask| \
Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask) Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask)
static int _XkbLoadDpy( static int _XkbLoadDpy(Display *dpy);
Display *dpy
);
struct _XKeytrans { struct _XKeytrans {
struct _XKeytrans *next;/* next on list */ struct _XKeytrans *next; /* next on list */
char *string; /* string to return when the time comes */ char *string; /* string to return when the time comes */
int len; /* length of string (since NULL is legit)*/ int len; /* length of string (since NULL is legit) */
KeySym key; /* keysym rebound */ KeySym key; /* keysym rebound */
unsigned int state; /* modifier state */ unsigned int state; /* modifier state */
KeySym *modifiers; /* modifier keysyms you want */ KeySym *modifiers; /* modifier keysyms you want */
int mlen; /* length of modifier list */ int mlen; /* length of modifier list */
}; };
KeySym KeySym
XkbKeycodeToKeysym(Display *dpy, XkbKeycodeToKeysym(Display *dpy,
#if NeedWidePrototypes #if NeedWidePrototypes
unsigned int kc, unsigned int kc,
#else #else
KeyCode kc, KeyCode kc,
#endif #endif
int group, int group,
int level) int level)
{ {
XkbDescRec *xkb; XkbDescRec *xkb;
if (_XkbUnavailable(dpy)) if (_XkbUnavailable(dpy))
return NoSymbol; return NoSymbol;
_XkbCheckPendingRefresh(dpy,dpy->xkb_info); _XkbCheckPendingRefresh(dpy, dpy->xkb_info);
xkb = dpy->xkb_info->desc; xkb = dpy->xkb_info->desc;
if ((kc<xkb->min_key_code)||(kc>xkb->max_key_code)) if ((kc < xkb->min_key_code) || (kc > xkb->max_key_code))
return NoSymbol; return NoSymbol;
if ((group<0)||(level<0)||(group>=XkbKeyNumGroups(xkb,kc))) if ((group < 0) || (level < 0) || (group >= XkbKeyNumGroups(xkb, kc)))
return NoSymbol; return NoSymbol;
if (level>=XkbKeyGroupWidth(xkb,kc,group)) { if (level >= XkbKeyGroupWidth(xkb, kc, group)) {
/* for compatibility with the core protocol, _always_ allow */ /* for compatibility with the core protocol, _always_ allow */
/* two symbols in the first two groups. If either of the */ /* two symbols in the first two groups. If either of the */
/* two is of type ONE_LEVEL, just replicate the first symbol */ /* two is of type ONE_LEVEL, just replicate the first symbol */
if ((group>XkbGroup2Index)||(XkbKeyGroupWidth(xkb,kc,group)!=1)|| if ((group > XkbGroup2Index) || (XkbKeyGroupWidth(xkb, kc, group) != 1)
(level!=1)) { || (level != 1)) {
return NoSymbol; return NoSymbol;
} }
level= 0; level = 0;
} }
return XkbKeySymEntry(xkb,kc,level,group); return XkbKeySymEntry(xkb, kc, level, group);
} }
KeySym KeySym
XKeycodeToKeysym(Display *dpy, XKeycodeToKeysym(Display *dpy,
#if NeedWidePrototypes #if NeedWidePrototypes
unsigned int kc, unsigned int kc,
#else #else
KeyCode kc, KeyCode kc,
#endif #endif
int col) int col)
{ {
XkbDescRec *xkb; XkbDescRec *xkb;
if (_XkbUnavailable(dpy)) if (_XkbUnavailable(dpy))
return _XKeycodeToKeysym(dpy, kc, col); return _XKeycodeToKeysym(dpy, kc, col);
_XkbCheckPendingRefresh(dpy,dpy->xkb_info); _XkbCheckPendingRefresh(dpy, dpy->xkb_info);
xkb = dpy->xkb_info->desc; xkb = dpy->xkb_info->desc;
if ((kc<xkb->min_key_code)||(kc>xkb->max_key_code)) if ((kc < xkb->min_key_code) || (kc > xkb->max_key_code))
return NoSymbol; return NoSymbol;
if (col>3) { if (col > 3) {
int lastSym,tmp,nGrp; int lastSym, tmp, nGrp;
lastSym= 3; lastSym = 3;
nGrp= XkbKeyNumGroups(xkb,kc); nGrp = XkbKeyNumGroups(xkb, kc);
if ((nGrp>0)&&((tmp=XkbKeyGroupWidth(xkb,kc,XkbGroup1Index))>2)) { if ((nGrp > 0) &&
if (col<=(lastSym+tmp-2)) ((tmp = XkbKeyGroupWidth(xkb, kc, XkbGroup1Index)) > 2)) {
return XkbKeycodeToKeysym(dpy,kc,XkbGroup1Index,col-lastSym+2); if (col <= (lastSym + tmp - 2))
lastSym+= tmp-2; return XkbKeycodeToKeysym(dpy, kc, XkbGroup1Index,
} col - lastSym + 2);
if ((nGrp>1)&&((tmp=XkbKeyGroupWidth(xkb,kc,XkbGroup2Index))>2)) { lastSym += tmp - 2;
if (col<=(lastSym+tmp-2)) }
return XkbKeycodeToKeysym(dpy,kc,XkbGroup2Index,col-lastSym+2); if ((nGrp > 1) &&
lastSym+= tmp-2; ((tmp = XkbKeyGroupWidth(xkb, kc, XkbGroup2Index)) > 2)) {
} if (col <= (lastSym + tmp - 2))
if (nGrp>2) { return XkbKeycodeToKeysym(dpy, kc, XkbGroup2Index,
tmp= XkbKeyGroupWidth(xkb,kc,XkbGroup3Index); col - lastSym + 2);
if (col<=lastSym+tmp) lastSym += tmp - 2;
return XkbKeycodeToKeysym(dpy,kc,XkbGroup3Index,col-lastSym); }
lastSym+= tmp; if (nGrp > 2) {
} tmp = XkbKeyGroupWidth(xkb, kc, XkbGroup3Index);
if (nGrp>3) { if (col <= lastSym + tmp)
tmp= XkbKeyGroupWidth(xkb,kc,XkbGroup4Index); return XkbKeycodeToKeysym(dpy, kc, XkbGroup3Index,
if (col<=lastSym+tmp) col - lastSym);
return XkbKeycodeToKeysym(dpy,kc,XkbGroup4Index,col-lastSym); lastSym += tmp;
} }
return NoSymbol; if (nGrp > 3) {
tmp = XkbKeyGroupWidth(xkb, kc, XkbGroup4Index);
if (col <= lastSym + tmp)
return XkbKeycodeToKeysym(dpy, kc, XkbGroup4Index,
col - lastSym);
}
return NoSymbol;
} }
return XkbKeycodeToKeysym(dpy,kc,(col>>1),(col&1)); return XkbKeycodeToKeysym(dpy, kc, (col >> 1), (col & 1));
} }
KeyCode KeyCode
...@@ -156,21 +160,21 @@ XKeysymToKeycode(Display *dpy, KeySym ks) ...@@ -156,21 +160,21 @@ XKeysymToKeycode(Display *dpy, KeySym ks)
register int i, j, gotOne; register int i, j, gotOne;
if (_XkbUnavailable(dpy)) if (_XkbUnavailable(dpy))
return _XKeysymToKeycode(dpy,ks); return _XKeysymToKeycode(dpy, ks);
_XkbCheckPendingRefresh(dpy,dpy->xkb_info); _XkbCheckPendingRefresh(dpy, dpy->xkb_info);
j= 0; j = 0;
do { do {
register XkbDescRec *xkb = dpy->xkb_info->desc; register XkbDescRec *xkb = dpy->xkb_info->desc;
gotOne= 0; gotOne = 0;
for (i = dpy->min_keycode; i <= dpy->max_keycode; i++) { for (i = dpy->min_keycode; i <= dpy->max_keycode; i++) {
if ( j<(int)XkbKeyNumSyms(xkb,i) ) { if (j < (int) XkbKeyNumSyms(xkb, i)) {
gotOne = 1; gotOne = 1;
if ((XkbKeySym(xkb,i,j)==ks)) if ((XkbKeySym(xkb, i, j) == ks))
return i; return i;
} }
} }
j++; j++;
} while (gotOne); } while (gotOne);
return 0; return 0;
} }
...@@ -178,50 +182,51 @@ XKeysymToKeycode(Display *dpy, KeySym ks) ...@@ -178,50 +182,51 @@ XKeysymToKeycode(Display *dpy, KeySym ks)
static int static int
_XkbComputeModmap(Display *dpy) _XkbComputeModmap(Display *dpy)
{ {
register XkbDescPtr xkb; register XkbDescPtr xkb;
xkb= dpy->xkb_info->desc; xkb = dpy->xkb_info->desc;
if (XkbGetUpdatedMap(dpy,XkbModifierMapMask,xkb)==Success) if (XkbGetUpdatedMap(dpy, XkbModifierMapMask, xkb) == Success)
return 1; return 1;
return 0; return 0;
} }
unsigned unsigned
XkbKeysymToModifiers(Display *dpy,KeySym ks) XkbKeysymToModifiers(Display *dpy, KeySym ks)
{ {
XkbDescRec *xkb; XkbDescRec *xkb;
register int i,j; register int i, j;
register KeySym *pSyms; register KeySym *pSyms;
CARD8 mods; CARD8 mods;
if (_XkbUnavailable(dpy)) if (_XkbUnavailable(dpy))
return _XKeysymToModifiers(dpy,ks); return _XKeysymToModifiers(dpy, ks);
_XkbCheckPendingRefresh(dpy,dpy->xkb_info); _XkbCheckPendingRefresh(dpy, dpy->xkb_info);
if (_XkbNeedModmap(dpy->xkb_info)&&(!_XkbComputeModmap(dpy))) if (_XkbNeedModmap(dpy->xkb_info) && (!_XkbComputeModmap(dpy)))
return _XKeysymToModifiers(dpy,ks); return _XKeysymToModifiers(dpy, ks);
xkb= dpy->xkb_info->desc; xkb = dpy->xkb_info->desc;
mods= 0; mods = 0;
for (i = xkb->min_key_code; i <= (int)xkb->max_key_code; i++) { for (i = xkb->min_key_code; i <= (int) xkb->max_key_code; i++) {
pSyms= XkbKeySymsPtr(xkb,i); pSyms = XkbKeySymsPtr(xkb, i);
for (j=XkbKeyNumSyms(xkb,i)-1;j>=0;j--) { for (j = XkbKeyNumSyms(xkb, i) - 1; j >= 0; j--) {
if (pSyms[j]==ks) { if (pSyms[j] == ks) {
mods|= xkb->map->modmap[i]; mods |= xkb->map->modmap[i];
break; break;
} }
} }
} }
return mods; return mods;
} }
KeySym KeySym
XLookupKeysym(register XKeyEvent *event, int col) XLookupKeysym(register XKeyEvent * event, int col)
{ {
Display *dpy = event->display; Display *dpy = event->display;
if (_XkbUnavailable(dpy)) if (_XkbUnavailable(dpy))
return _XLookupKeysym(event, col); return _XLookupKeysym(event, col);
_XkbCheckPendingRefresh(dpy,dpy->xkb_info); _XkbCheckPendingRefresh(dpy, dpy->xkb_info);
return XKeycodeToKeysym(dpy, event->keycode, col); return XKeycodeToKeysym(dpy, event->keycode, col);
} }
...@@ -231,159 +236,165 @@ XLookupKeysym(register XKeyEvent *event, int col) ...@@ -231,159 +236,165 @@ XLookupKeysym(register XKeyEvent *event, int col)
* version will continue to work in a shared library environment. * version will continue to work in a shared library environment.
*/ */
int int
XkbTranslateKey( register Display * dpy, XkbTranslateKey(register Display *dpy,
KeyCode key, KeyCode key,
register unsigned int mods, register unsigned int mods,
unsigned int * mods_rtrn, unsigned int *mods_rtrn,
KeySym * keysym_rtrn); KeySym *keysym_rtrn);
int int
XkbTranslateKey( register Display * dpy, XkbTranslateKey(register Display *dpy,
KeyCode key, KeyCode key,
register unsigned int mods, register unsigned int mods,
unsigned int * mods_rtrn, unsigned int *mods_rtrn,
KeySym * keysym_rtrn) KeySym *keysym_rtrn)
{ {
return XkbLookupKeySym(dpy,key,mods,mods_rtrn,keysym_rtrn); return XkbLookupKeySym(dpy, key, mods, mods_rtrn, keysym_rtrn);
} }
Bool Bool
XkbLookupKeySym( register Display * dpy, XkbLookupKeySym(register Display *dpy,
KeyCode key, KeyCode key,
register unsigned int mods, register unsigned int mods,
unsigned int * mods_rtrn, unsigned int *mods_rtrn,
KeySym * keysym_rtrn) KeySym *keysym_rtrn)
{ {
if (_XkbUnavailable(dpy)) if (_XkbUnavailable(dpy))
return _XTranslateKey(dpy, key, mods, mods_rtrn, keysym_rtrn); return _XTranslateKey(dpy, key, mods, mods_rtrn, keysym_rtrn);
_XkbCheckPendingRefresh(dpy,dpy->xkb_info); _XkbCheckPendingRefresh(dpy, dpy->xkb_info);
return XkbTranslateKeyCode(dpy->xkb_info->desc,key,mods,mods_rtrn, return XkbTranslateKeyCode(dpy->xkb_info->desc, key, mods, mods_rtrn,
keysym_rtrn); keysym_rtrn);
} }
Bool Bool
XkbTranslateKeyCode( register XkbDescPtr xkb, XkbTranslateKeyCode(register XkbDescPtr xkb,
KeyCode key, KeyCode key,
register unsigned int mods, register unsigned int mods,
unsigned int * mods_rtrn, unsigned int *mods_rtrn,
KeySym * keysym_rtrn) KeySym *keysym_rtrn)
{ {
XkbKeyTypeRec *type; XkbKeyTypeRec *type;
int col,nKeyGroups; int col, nKeyGroups;
unsigned preserve,effectiveGroup; unsigned preserve, effectiveGroup;
KeySym *syms; KeySym *syms;
if (mods_rtrn!=NULL) if (mods_rtrn != NULL)
*mods_rtrn = 0; *mods_rtrn = 0;
nKeyGroups= XkbKeyNumGroups(xkb,key); nKeyGroups = XkbKeyNumGroups(xkb, key);
if ((!XkbKeycodeInRange(xkb,key))||(nKeyGroups==0)) { if ((!XkbKeycodeInRange(xkb, key)) || (nKeyGroups == 0)) {
if (keysym_rtrn!=NULL) if (keysym_rtrn != NULL)
*keysym_rtrn = NoSymbol; *keysym_rtrn = NoSymbol;
return False; return False;
} }
syms = XkbKeySymsPtr(xkb,key); syms = XkbKeySymsPtr(xkb, key);
/* find the offset of the effective group */ /* find the offset of the effective group */
col = 0; col = 0;
effectiveGroup= XkbGroupForCoreState(mods); effectiveGroup = XkbGroupForCoreState(mods);
if ( effectiveGroup>=nKeyGroups ) { if (effectiveGroup >= nKeyGroups) {
unsigned groupInfo= XkbKeyGroupInfo(xkb,key); unsigned groupInfo = XkbKeyGroupInfo(xkb, key);
switch (XkbOutOfRangeGroupAction(groupInfo)) {
default: switch (XkbOutOfRangeGroupAction(groupInfo)) {
effectiveGroup %= nKeyGroups; default:
break; effectiveGroup %= nKeyGroups;
case XkbClampIntoRange: break;
effectiveGroup = nKeyGroups-1; case XkbClampIntoRange:
break; effectiveGroup = nKeyGroups - 1;
case XkbRedirectIntoRange: break;
effectiveGroup = XkbOutOfRangeGroupNumber(groupInfo); case XkbRedirectIntoRange:
if (effectiveGroup>=nKeyGroups) effectiveGroup = XkbOutOfRangeGroupNumber(groupInfo);
effectiveGroup= 0; if (effectiveGroup >= nKeyGroups)
break; effectiveGroup = 0;
} break;
}
} }
col= effectiveGroup*XkbKeyGroupsWidth(xkb,key); col = effectiveGroup * XkbKeyGroupsWidth(xkb, key);
type = XkbKeyKeyType(xkb,key,effectiveGroup); type = XkbKeyKeyType(xkb, key, effectiveGroup);
preserve= 0; preserve = 0;
if (type->map) { /* find the column (shift level) within the group */ if (type->map) { /* find the column (shift level) within the group */
register int i; register int i;
register XkbKTMapEntryPtr entry; register XkbKTMapEntryPtr entry;
for (i=0,entry=type->map;i<type->map_count;i++,entry++) {
if ((entry->active)&&((mods&type->mods.mask)==entry->mods.mask)) { for (i = 0, entry = type->map; i < type->map_count; i++, entry++) {
col+= entry->level; if ((entry->active) &&
if (type->preserve) ((mods & type->mods.mask) == entry->mods.mask)) {
preserve= type->preserve[i].mask; col += entry->level;
break; if (type->preserve)
} preserve = type->preserve[i].mask;
} break;
}
}
} }
if (keysym_rtrn!=NULL) if (keysym_rtrn != NULL)
*keysym_rtrn= syms[col]; *keysym_rtrn = syms[col];
if (mods_rtrn) { if (mods_rtrn) {
*mods_rtrn= type->mods.mask&(~preserve); *mods_rtrn = type->mods.mask & (~preserve);
/* The Motif VTS doesn't get the help callback called if help /* The Motif VTS doesn't get the help callback called if help
* is bound to Shift+<whatever>, and it appears as though it * is bound to Shift+<whatever>, and it appears as though it
* is XkbTranslateKeyCode that is causing the problem. The * is XkbTranslateKeyCode that is causing the problem. The
* core X version of XTranslateKey always OR's in ShiftMask * core X version of XTranslateKey always OR's in ShiftMask
* and LockMask for mods_rtrn, so this "fix" keeps this behavior * and LockMask for mods_rtrn, so this "fix" keeps this behavior
* and solves the VTS problem. * and solves the VTS problem.
*/ */
if ((xkb->dpy)&&(xkb->dpy->xkb_info)&& if ((xkb->dpy) && (xkb->dpy->xkb_info) &&
(xkb->dpy->xkb_info->xlib_ctrls&XkbLC_AlwaysConsumeShiftAndLock)) { (xkb->dpy->xkb_info->
*mods_rtrn|= (ShiftMask|LockMask); xlib_ctrls & XkbLC_AlwaysConsumeShiftAndLock)) {
} *mods_rtrn |= (ShiftMask | LockMask);
}
} }
return (syms[col]!=NoSymbol); return (syms[col] != NoSymbol);
} }
Status Status
XkbRefreshKeyboardMapping(register XkbMapNotifyEvent *event) XkbRefreshKeyboardMapping(register XkbMapNotifyEvent * event)
{ {
Display *dpy = event->display; Display *dpy = event->display;
XkbInfoPtr xkbi; XkbInfoPtr xkbi;
if (_XkbUnavailable(dpy)) { if (_XkbUnavailable(dpy)) {
_XRefreshKeyboardMapping((XMappingEvent *)event); _XRefreshKeyboardMapping((XMappingEvent *) event);
return Success; return Success;
} }
xkbi= dpy->xkb_info; xkbi = dpy->xkb_info;
if (((event->type&0x7f)-xkbi->codes->first_event)!=XkbEventCode) if (((event->type & 0x7f) - xkbi->codes->first_event) != XkbEventCode)
return BadMatch; return BadMatch;
if (event->xkb_type==XkbNewKeyboardNotify) { if (event->xkb_type == XkbNewKeyboardNotify) {
_XkbReloadDpy(dpy); _XkbReloadDpy(dpy);
return Success; return Success;
} }
if (event->xkb_type==XkbMapNotify) { if (event->xkb_type == XkbMapNotify) {
XkbMapChangesRec changes; XkbMapChangesRec changes;
Status rtrn; Status rtrn;
if (xkbi->flags&XkbMapPending) if (xkbi->flags & XkbMapPending)
changes= xkbi->changes; changes = xkbi->changes;
else bzero(&changes,sizeof(changes)); else
XkbNoteMapChanges(&changes,event,XKB_XLIB_MAP_MASK); bzero(&changes, sizeof(changes));
if ((rtrn=XkbGetMapChanges(dpy,xkbi->desc,&changes))!=Success) { XkbNoteMapChanges(&changes, event, XKB_XLIB_MAP_MASK);
if ((rtrn = XkbGetMapChanges(dpy, xkbi->desc, &changes)) != Success) {
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr,"Internal Error! XkbGetMapChanges failed:\n"); fprintf(stderr, "Internal Error! XkbGetMapChanges failed:\n");
#endif #endif
xkbi->changes= changes; xkbi->changes = changes;
} }
else if (xkbi->flags&XkbMapPending) { else if (xkbi->flags & XkbMapPending) {
xkbi->flags&= ~XkbMapPending; xkbi->flags &= ~XkbMapPending;
bzero(&xkbi->changes,sizeof(XkbMapChangesRec)); bzero(&xkbi->changes, sizeof(XkbMapChangesRec));
} }
return rtrn; return rtrn;
} }
return BadMatch; return BadMatch;
} }
int int
XRefreshKeyboardMapping(register XMappingEvent *event) XRefreshKeyboardMapping(register XMappingEvent * event)
{ {
XkbEvent *xkbevent = (XkbEvent *)event; XkbEvent *xkbevent = (XkbEvent *) event;
Display *dpy = event->display; Display *dpy = event->display;
XkbMapChangesRec changes; XkbMapChangesRec changes;
XkbInfoPtr xkbi; XkbInfoPtr xkbi;
...@@ -392,99 +403,106 @@ XRefreshKeyboardMapping(register XMappingEvent *event) ...@@ -392,99 +403,106 @@ XRefreshKeyboardMapping(register XMappingEvent *event)
(void) _XRefreshKeyboardMapping(event); (void) _XRefreshKeyboardMapping(event);
if (_XkbUnavailable(dpy)) if (_XkbUnavailable(dpy))
return 1; return 1;
xkbi = dpy->xkb_info; xkbi = dpy->xkb_info;
if (((event->type&0x7f)-xkbi->codes->first_event)==XkbEventCode) if (((event->type & 0x7f) - xkbi->codes->first_event) == XkbEventCode)
return XkbRefreshKeyboardMapping(&xkbevent->map); return XkbRefreshKeyboardMapping(&xkbevent->map);
if (xkbi->flags&XkbXlibNewKeyboard) { if (xkbi->flags & XkbXlibNewKeyboard) {
_XkbReloadDpy(dpy); _XkbReloadDpy(dpy);
return 1; return 1;
} }
if ((xkbi->flags&XkbMapPending)||(event->request==MappingKeyboard)) { if ((xkbi->flags & XkbMapPending) || (event->request == MappingKeyboard)) {
if (xkbi->flags&XkbMapPending) { if (xkbi->flags & XkbMapPending) {
changes= xkbi->changes; changes = xkbi->changes;
_XkbNoteCoreMapChanges(&changes,event,XKB_XLIB_MAP_MASK); _XkbNoteCoreMapChanges(&changes, event, XKB_XLIB_MAP_MASK);
} }
else { else {
bzero(&changes,sizeof(changes)); bzero(&changes, sizeof(changes));
changes.changed= XkbKeySymsMask; changes.changed = XkbKeySymsMask;
if (xkbi->desc->min_key_code<xkbi->desc->max_key_code) { if (xkbi->desc->min_key_code < xkbi->desc->max_key_code) {
changes.first_key_sym= xkbi->desc->min_key_code; changes.first_key_sym = xkbi->desc->min_key_code;
changes.num_key_syms= xkbi->desc->max_key_code- changes.num_key_syms = xkbi->desc->max_key_code -
xkbi->desc->min_key_code+1; xkbi->desc->min_key_code + 1;
} }
else { else {
changes.first_key_sym= event->first_keycode; changes.first_key_sym = event->first_keycode;
changes.num_key_syms= event->count; changes.num_key_syms = event->count;
} }
} }
if (XkbGetMapChanges(dpy,xkbi->desc, &changes)!=Success) { if (XkbGetMapChanges(dpy, xkbi->desc, &changes) != Success) {
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr,"Internal Error! XkbGetMapChanges failed:\n"); fprintf(stderr, "Internal Error! XkbGetMapChanges failed:\n");
if (changes.changed&XkbKeyTypesMask) { if (changes.changed & XkbKeyTypesMask) {
int first= changes.first_type; int first = changes.first_type;
int last= changes.first_type+changes.num_types-1; int last = changes.first_type + changes.num_types - 1;
fprintf(stderr," types: %d..%d\n",first,last);
} fprintf(stderr, " types: %d..%d\n", first, last);
if (changes.changed&XkbKeySymsMask) { }
int first= changes.first_key_sym; if (changes.changed & XkbKeySymsMask) {
int last= changes.first_key_sym+changes.num_key_syms-1; int first = changes.first_key_sym;
fprintf(stderr," symbols: %d..%d\n",first,last); int last = changes.first_key_sym + changes.num_key_syms - 1;
}
if (changes.changed&XkbKeyActionsMask) { fprintf(stderr, " symbols: %d..%d\n", first, last);
int last,first= changes.first_key_act; }
last= changes.first_key_act+changes.num_key_acts-1; if (changes.changed & XkbKeyActionsMask) {
fprintf(stderr," acts: %d..%d\n",first,last); int last, first = changes.first_key_act;
}
if (changes.changed&XkbKeyBehaviorsMask) { last = changes.first_key_act + changes.num_key_acts - 1;
int last,first= changes.first_key_behavior; fprintf(stderr, " acts: %d..%d\n", first, last);
last= first+changes.num_key_behaviors-1; }
fprintf(stderr," behaviors: %d..%d\n",first,last); if (changes.changed & XkbKeyBehaviorsMask) {
} int last, first = changes.first_key_behavior;
if (changes.changed&XkbVirtualModsMask) { last = first + changes.num_key_behaviors - 1;
fprintf(stderr,"virtual mods: 0x%04x\n", fprintf(stderr, " behaviors: %d..%d\n", first, last);
changes.vmods); }
} if (changes.changed & XkbVirtualModsMask) {
if (changes.changed&XkbExplicitComponentsMask) { fprintf(stderr, "virtual mods: 0x%04x\n", changes.vmods);
int last,first= changes.first_key_explicit; }
last= first+changes.num_key_explicit-1; if (changes.changed & XkbExplicitComponentsMask) {
fprintf(stderr," explicit: %d..%d\n",first,last); int last, first = changes.first_key_explicit;
}
last = first + changes.num_key_explicit - 1;
fprintf(stderr, " explicit: %d..%d\n", first, last);
}
#endif #endif
} }
LockDisplay(dpy); LockDisplay(dpy);
if (xkbi->flags&XkbMapPending) { if (xkbi->flags & XkbMapPending) {
xkbi->flags&= ~XkbMapPending; xkbi->flags &= ~XkbMapPending;
bzero(&xkbi->changes,sizeof(XkbMapChangesRec)); bzero(&xkbi->changes, sizeof(XkbMapChangesRec));
} }
UnlockDisplay(dpy); UnlockDisplay(dpy);
} }
if (event->request==MappingModifier) { if (event->request == MappingModifier) {
LockDisplay(dpy); LockDisplay(dpy);
if (xkbi->desc->map->modmap) { if (xkbi->desc->map->modmap) {
_XkbFree(xkbi->desc->map->modmap); _XkbFree(xkbi->desc->map->modmap);
xkbi->desc->map->modmap= NULL; xkbi->desc->map->modmap = NULL;
} }
if (dpy->key_bindings) { if (dpy->key_bindings) {
register struct _XKeytrans *p; register struct _XKeytrans *p;
for (p = dpy->key_bindings; p; p = p->next) {
register int i; for (p = dpy->key_bindings; p; p = p->next) {
p->state= 0; register int i;
if (p->mlen>0) {
for (i = 0; i < p->mlen; i++) { p->state = 0;
p->state|= XkbKeysymToModifiers(dpy,p->modifiers[i]); if (p->mlen > 0) {
} for (i = 0; i < p->mlen; i++) {
if (p->state) p->state &= AllMods; p->state |= XkbKeysymToModifiers(dpy, p->modifiers[i]);
else p->state = AnyModifier; }
} if (p->state)
} p->state &= AllMods;
} else
UnlockDisplay(dpy); p->state = AnyModifier;
}
}
}
UnlockDisplay(dpy);
} }
return 1; return 1;
} }
...@@ -493,35 +511,36 @@ static int ...@@ -493,35 +511,36 @@ static int
_XkbLoadDpy(Display *dpy) _XkbLoadDpy(Display *dpy)
{ {
XkbInfoPtr xkbi; XkbInfoPtr xkbi;
unsigned query,oldEvents; unsigned query, oldEvents;
XkbDescRec *desc; XkbDescRec *desc;
if (!XkbUseExtension(dpy,NULL,NULL)) if (!XkbUseExtension(dpy, NULL, NULL))
return 0; return 0;
xkbi = dpy->xkb_info; xkbi = dpy->xkb_info;
query = XkbAllClientInfoMask; query = XkbAllClientInfoMask;
desc = XkbGetMap(dpy,query,XkbUseCoreKbd); desc = XkbGetMap(dpy, query, XkbUseCoreKbd);
if (!desc) { if (!desc) {
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr,"Warning! XkbGetMap failed!\n"); fprintf(stderr, "Warning! XkbGetMap failed!\n");
#endif #endif
return 0; return 0;
} }
LockDisplay(dpy); LockDisplay(dpy);
xkbi->desc = desc; xkbi->desc = desc;
UnlockDisplay(dpy); UnlockDisplay(dpy);
oldEvents= xkbi->selected_events; oldEvents = xkbi->selected_events;
if (!(xkbi->xlib_ctrls&XkbLC_IgnoreNewKeyboards)) { if (!(xkbi->xlib_ctrls & XkbLC_IgnoreNewKeyboards)) {
XkbSelectEventDetails(dpy,xkbi->desc->device_spec,XkbNewKeyboardNotify, XkbSelectEventDetails(dpy, xkbi->desc->device_spec,
XkbNKN_KeycodesMask|XkbNKN_DeviceIDMask, XkbNewKeyboardNotify,
XkbNKN_KeycodesMask|XkbNKN_DeviceIDMask); XkbNKN_KeycodesMask | XkbNKN_DeviceIDMask,
XkbNKN_KeycodesMask | XkbNKN_DeviceIDMask);
} }
XkbSelectEventDetails(dpy,xkbi->desc->device_spec,XkbMapNotify, XkbSelectEventDetails(dpy, xkbi->desc->device_spec, XkbMapNotify,
XkbAllClientInfoMask,XkbAllClientInfoMask); XkbAllClientInfoMask, XkbAllClientInfoMask);
LockDisplay(dpy); LockDisplay(dpy);
xkbi->selected_events= oldEvents; xkbi->selected_events = oldEvents;
UnlockDisplay(dpy); UnlockDisplay(dpy);
return 1; return 1;
} }
...@@ -531,166 +550,175 @@ _XkbReloadDpy(Display *dpy) ...@@ -531,166 +550,175 @@ _XkbReloadDpy(Display *dpy)
{ {
XkbInfoPtr xkbi; XkbInfoPtr xkbi;
XkbDescRec *desc; XkbDescRec *desc;
unsigned oldDeviceID; unsigned oldDeviceID;
if (_XkbUnavailable(dpy)) if (_XkbUnavailable(dpy))
return; return;
xkbi = dpy->xkb_info; xkbi = dpy->xkb_info;
LockDisplay(dpy); LockDisplay(dpy);
if (xkbi->desc) { if (xkbi->desc) {
oldDeviceID= xkbi->desc->device_spec; oldDeviceID = xkbi->desc->device_spec;
XkbFreeKeyboard(xkbi->desc,XkbAllComponentsMask,True); XkbFreeKeyboard(xkbi->desc, XkbAllComponentsMask, True);
xkbi->desc= NULL; xkbi->desc = NULL;
xkbi->flags&= ~(XkbMapPending|XkbXlibNewKeyboard); xkbi->flags &= ~(XkbMapPending | XkbXlibNewKeyboard);
xkbi->changes.changed= 0; xkbi->changes.changed = 0;
} }
else oldDeviceID= XkbUseCoreKbd; else
oldDeviceID = XkbUseCoreKbd;
UnlockDisplay(dpy); UnlockDisplay(dpy);
desc = XkbGetMap(dpy,XkbAllClientInfoMask,XkbUseCoreKbd); desc = XkbGetMap(dpy, XkbAllClientInfoMask, XkbUseCoreKbd);
if (!desc) if (!desc)
return; return;
LockDisplay(dpy); LockDisplay(dpy);
xkbi->desc = desc; xkbi->desc = desc;
UnlockDisplay(dpy); UnlockDisplay(dpy);
if (desc->device_spec!=oldDeviceID) { if (desc->device_spec != oldDeviceID) {
/* transfer(?) event masks here */ /* transfer(?) event masks here */
#ifdef NOTYET #ifdef NOTYET
unsigned oldEvents; unsigned oldEvents;
oldEvents= xkbi->selected_events;
XkbSelectEventDetails(dpy,xkbi->desc->device_spec,XkbMapNotify, oldEvents = xkbi->selected_events;
XkbAllMapComponentsMask,XkbAllClientInfoMask); XkbSelectEventDetails(dpy, xkbi->desc->device_spec, XkbMapNotify,
LockDisplay(dpy); XkbAllMapComponentsMask, XkbAllClientInfoMask);
xkbi->selected_events= oldEvents; LockDisplay(dpy);
UnlockDisplay(dpy); xkbi->selected_events = oldEvents;
UnlockDisplay(dpy);
#endif #endif
} }
return; return;
} }
int int
XkbTranslateKeySym( register Display * dpy, XkbTranslateKeySym(register Display *dpy,
register KeySym * sym_rtrn, register KeySym *sym_rtrn,
unsigned int mods, unsigned int mods,
char * buffer, char *buffer,
int nbytes, int nbytes,
int * extra_rtrn) int *extra_rtrn)
{ {
register XkbInfoPtr xkb; register XkbInfoPtr xkb;
XkbKSToMBFunc cvtr; XkbKSToMBFunc cvtr;
XPointer priv; XPointer priv;
char tmp[4]; char tmp[4];
int n; int n;
xkb= dpy->xkb_info; xkb = dpy->xkb_info;
if (!xkb->cvt.KSToMB) { if (!xkb->cvt.KSToMB) {
_XkbGetConverters(_XkbGetCharset(),&xkb->cvt); _XkbGetConverters(_XkbGetCharset(), &xkb->cvt);
_XkbGetConverters("ISO8859-1",&xkb->latin1cvt); _XkbGetConverters("ISO8859-1", &xkb->latin1cvt);
} }
if (extra_rtrn) if (extra_rtrn)
*extra_rtrn= 0; *extra_rtrn = 0;
if ((buffer==NULL)||(nbytes==0)) { if ((buffer == NULL) || (nbytes == 0)) {
buffer= tmp; buffer = tmp;
nbytes= 4; nbytes = 4;
} }
/* see if symbol rebound, if so, return that string. */ /* see if symbol rebound, if so, return that string. */
n = XkbLookupKeyBinding(dpy,*sym_rtrn,mods,buffer,nbytes,extra_rtrn); n = XkbLookupKeyBinding(dpy, *sym_rtrn, mods, buffer, nbytes, extra_rtrn);
if (n) if (n)
return n; return n;
if ( nbytes>0 ) if (nbytes > 0)
buffer[0]= '\0'; buffer[0] = '\0';
if ( xkb->cvt.KSToUpper && (mods&LockMask) ) { if (xkb->cvt.KSToUpper && (mods & LockMask)) {
*sym_rtrn = (*xkb->cvt.KSToUpper)(*sym_rtrn); *sym_rtrn = (*xkb->cvt.KSToUpper) (*sym_rtrn);
} }
if (xkb->xlib_ctrls & XkbLC_ForceLatin1Lookup) { if (xkb->xlib_ctrls & XkbLC_ForceLatin1Lookup) {
cvtr = xkb->latin1cvt.KSToMB; cvtr = xkb->latin1cvt.KSToMB;
priv = xkb->latin1cvt.KSToMBPriv; priv = xkb->latin1cvt.KSToMBPriv;
} else { }
cvtr = xkb->cvt.KSToMB; else {
priv = xkb->cvt.KSToMBPriv; cvtr = xkb->cvt.KSToMB;
priv = xkb->cvt.KSToMBPriv;
} }
n = (*cvtr)(priv,*sym_rtrn,buffer,nbytes,extra_rtrn); n = (*cvtr) (priv, *sym_rtrn, buffer, nbytes, extra_rtrn);
if ((!xkb->cvt.KSToUpper)&&( mods&LockMask )) { if ((!xkb->cvt.KSToUpper) && (mods & LockMask)) {
register int i; register int i;
int change; int change;
char ch; char ch;
for (i=change=0;i<n;i++) {
ch= toupper(buffer[i]); for (i = change = 0; i < n; i++) {
change= (change||(buffer[i]!=ch)); ch = toupper(buffer[i]);
buffer[i] = ch; change = (change || (buffer[i] != ch));
} buffer[i] = ch;
if (change) { }
if (n==1) if (change) {
*sym_rtrn=(*xkb->cvt.MBToKS)(xkb->cvt.MBToKSPriv,buffer,n,NULL); if (n == 1)
else *sym_rtrn= NoSymbol; *sym_rtrn =
} (*xkb->cvt.MBToKS) (xkb->cvt.MBToKSPriv, buffer, n, NULL);
else
*sym_rtrn = NoSymbol;
}
} }
if ( mods&ControlMask ) { if (mods & ControlMask) {
if ( n==1 ) { if (n == 1) {
buffer[0]= XkbToControl(buffer[0]); buffer[0] = XkbToControl(buffer[0]);
if ( nbytes>1 ) if (nbytes > 1)
buffer[1]= '\0'; buffer[1] = '\0';
return 1; return 1;
} }
if ( nbytes > 0 ) if (nbytes > 0)
buffer[0]= '\0'; buffer[0] = '\0';
return 0; return 0;
} }
return n; return n;
} }
int int
XLookupString ( register XKeyEvent * event, XLookupString(register XKeyEvent *event,
char * buffer, char *buffer,
int nbytes, int nbytes,
KeySym * keysym, KeySym *keysym,
XComposeStatus * status) XComposeStatus *status)
{ {
KeySym dummy; KeySym dummy;
int rtrnLen; int rtrnLen;
unsigned int new_mods; unsigned int new_mods;
Display *dpy = event->display; Display *dpy = event->display;
if (keysym==NULL) if (keysym == NULL)
keysym= &dummy; keysym = &dummy;
if (!XkbLookupKeySym(dpy,event->keycode,event->state, &new_mods,keysym)) if (!XkbLookupKeySym(dpy, event->keycode, event->state, &new_mods, keysym))
return 0; return 0;
new_mods= (event->state&(~new_mods)); new_mods = (event->state & (~new_mods));
/* find the group where a symbol can be converted to control one */ /* find the group where a symbol can be converted to control one */
if (new_mods&ControlMask && *keysym > 0x7F && if (new_mods & ControlMask && *keysym > 0x7F &&
(dpy->xkb_info->xlib_ctrls & XkbLC_ControlFallback)) { (dpy->xkb_info->xlib_ctrls & XkbLC_ControlFallback)) {
XKeyEvent tmp_ev = *event; XKeyEvent tmp_ev = *event;
KeySym tmp_keysym; KeySym tmp_keysym;
unsigned int tmp_new_mods; unsigned int tmp_new_mods;
if (_XkbUnavailable(dpy)) {
tmp_ev.state= event->state ^ dpy->mode_switch; if (_XkbUnavailable(dpy)) {
tmp_ev.state = event->state ^ dpy->mode_switch;
if (XkbLookupKeySym(dpy, tmp_ev.keycode, tmp_ev.state, if (XkbLookupKeySym(dpy, tmp_ev.keycode, tmp_ev.state,
&tmp_new_mods, &tmp_keysym) && &tmp_new_mods, &tmp_keysym) &&
tmp_keysym != NoSymbol && tmp_keysym < 0x80 ) { tmp_keysym != NoSymbol && tmp_keysym < 0x80) {
*keysym = tmp_keysym; *keysym = tmp_keysym;
} }
} else { }
else {
int n = XkbKeyNumGroups(dpy->xkb_info->desc, tmp_ev.keycode); int n = XkbKeyNumGroups(dpy->xkb_info->desc, tmp_ev.keycode);
int i; int i;
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
if (XkbGroupForCoreState(event->state) == i) if (XkbGroupForCoreState(event->state) == i)
continue; continue;
tmp_ev.state= XkbBuildCoreState(tmp_ev.state, i); tmp_ev.state = XkbBuildCoreState(tmp_ev.state, i);
if (XkbLookupKeySym(dpy, tmp_ev.keycode, tmp_ev.state, if (XkbLookupKeySym(dpy, tmp_ev.keycode, tmp_ev.state,
&tmp_new_mods, &tmp_keysym) && &tmp_new_mods, &tmp_keysym) &&
tmp_keysym != NoSymbol && tmp_keysym < 0x80 ) { tmp_keysym != NoSymbol && tmp_keysym < 0x80) {
*keysym = tmp_keysym; *keysym = tmp_keysym;
new_mods= (event->state&(~tmp_new_mods)); new_mods = (event->state & (~tmp_new_mods));
break; break;
} }
} }
...@@ -698,96 +726,99 @@ XLookupString ( register XKeyEvent * event, ...@@ -698,96 +726,99 @@ XLookupString ( register XKeyEvent * event,
} }
#ifdef USE_OWN_COMPOSE #ifdef USE_OWN_COMPOSE
if ( status ) { if (status) {
static int been_here= 0; static int been_here = 0;
if ( !been_here ) {
XimCompInitTables(); if (!been_here) {
been_here = 1; XimCompInitTables();
} been_here = 1;
if ( !XimCompLegalStatus(status) ) { }
status->compose_ptr = NULL; if (!XimCompLegalStatus(status)) {
status->chars_matched = 0; status->compose_ptr = NULL;
} status->chars_matched = 0;
if ( ((status->chars_matched>0)&&(status->compose_ptr!=NULL)) || }
XimCompIsComposeKey(*keysym,event->keycode,status) ) { if (((status->chars_matched > 0) && (status->compose_ptr != NULL)) ||
XimCompRtrn rtrn; XimCompIsComposeKey(*keysym, event->keycode, status)) {
XimCompRtrn rtrn;
switch (XimCompProcessSym(status,*keysym,&rtrn)) {
case XIM_COMP_IGNORE: switch (XimCompProcessSym(status, *keysym, &rtrn)) {
break; case XIM_COMP_IGNORE:
case XIM_COMP_IN_PROGRESS: break;
if ( keysym!=NULL ) case XIM_COMP_IN_PROGRESS:
*keysym = NoSymbol; if (keysym != NULL)
*keysym = NoSymbol;
#ifndef NO_COMPOSE_LED #ifndef NO_COMPOSE_LED
if ( dpy->xkb_info->xlib_ctrls&XkbLC_ComposeLED ) { if (dpy->xkb_info->xlib_ctrls & XkbLC_ComposeLED) {
XkbSetNamedIndicator(dpy,dpy->xkb_info->composeLED, XkbSetNamedIndicator(dpy, dpy->xkb_info->composeLED,
True,True,False,NULL); True, True, False, NULL);
} }
#endif #endif
return 0; return 0;
case XIM_COMP_FAIL: case XIM_COMP_FAIL:
{ {
static Atom _ComposeFail= None; static Atom _ComposeFail = None;
int n = 0, len= 0; int n = 0, len = 0;
#ifndef NO_COMPOSE_LED #ifndef NO_COMPOSE_LED
if ( dpy->xkb_info->xlib_ctrls&XkbLC_ComposeLED ) { if (dpy->xkb_info->xlib_ctrls & XkbLC_ComposeLED) {
XkbSetNamedIndicator(dpy,dpy->xkb_info->composeLED, XkbSetNamedIndicator(dpy, dpy->xkb_info->composeLED,
True,False,False,NULL); True, False, False, NULL);
} }
#endif #endif
#ifndef NO_BELL_ON_COMPOSE_FAIL #ifndef NO_BELL_ON_COMPOSE_FAIL
if (dpy->xkb_info->xlib_ctrls&XkbLC_BeepOnComposeFail) { if (dpy->xkb_info->xlib_ctrls & XkbLC_BeepOnComposeFail) {
if (_ComposeFail==None) if (_ComposeFail == None)
_ComposeFail= XInternAtom(dpy,"ComposeFail",0); _ComposeFail = XInternAtom(dpy, "ComposeFail", 0);
XkbBell(dpy,event->window,0,_ComposeFail); XkbBell(dpy, event->window, 0, _ComposeFail);
} }
#endif #endif
for (n=len=0;rtrn.sym[n]!=XK_VoidSymbol;n++) { for (n = len = 0; rtrn.sym[n] != XK_VoidSymbol; n++) {
if ( nbytes-len > 0 ) { if (nbytes - len > 0) {
len+= XkbTranslateKeySym(dpy,&rtrn.sym[n],new_mods, len += XkbTranslateKeySym(dpy, &rtrn.sym[n], new_mods,
buffer+len,nbytes-len, buffer + len, nbytes - len,
NULL); NULL);
} }
} }
if ( keysym!=NULL ) { if (keysym != NULL) {
if ( n==1 ) *keysym = rtrn.sym[0]; if (n == 1)
else *keysym = NoSymbol; *keysym = rtrn.sym[0];
} else
return len; *keysym = NoSymbol;
} }
case XIM_COMP_SUCCEED: return len;
{ }
int len,n = 0; case XIM_COMP_SUCCEED:
{
int len, n = 0;
#ifndef NO_COMPOSE_LED #ifndef NO_COMPOSE_LED
if ( dpy->xkb_info->xlib_ctrls&XkbLC_ComposeLED ) { if (dpy->xkb_info->xlib_ctrls & XkbLC_ComposeLED) {
XkbSetNamedIndicator(dpy,dpy->xkb_info->composeLED, XkbSetNamedIndicator(dpy, dpy->xkb_info->composeLED,
True,False,False,NULL); True, False, False, NULL);
} }
#endif #endif
*keysym = rtrn.matchSym; *keysym = rtrn.matchSym;
if ( rtrn.str[0]!='\0' ) { if (rtrn.str[0] != '\0') {
strncpy(buffer,rtrn.str,nbytes-1); strncpy(buffer, rtrn.str, nbytes - 1);
buffer[nbytes-1]= '\0'; buffer[nbytes - 1] = '\0';
len = (int)strlen(buffer); len = (int) strlen(buffer);
} }
else { else {
len = XkbTranslateKeySym(dpy,keysym,new_mods, len = XkbTranslateKeySym(dpy, keysym, new_mods,
buffer,nbytes, buffer, nbytes, NULL);
NULL); }
} for (n = 0; rtrn.sym[n] != XK_VoidSymbol; n++) {
for (n=0;rtrn.sym[n]!=XK_VoidSymbol;n++) { if (nbytes - len > 0) {
if ( nbytes-len > 0 ) { len += XkbTranslateKeySym(dpy, &rtrn.sym[n],
len+= XkbTranslateKeySym(dpy,&rtrn.sym[n], event->state,
event->state, buffer + len, nbytes - len,
buffer+len,nbytes-len, NULL);
NULL); }
} }
} return len;
return len; }
} }
} }
}
} }
#endif #endif
...@@ -795,54 +826,61 @@ XLookupString ( register XKeyEvent * event, ...@@ -795,54 +826,61 @@ XLookupString ( register XKeyEvent * event,
/* that were used to compute the symbol here, but pre-XKB XLookupString */ /* that were used to compute the symbol here, but pre-XKB XLookupString */
/* did not and we have to remain compatible. Sigh. */ /* did not and we have to remain compatible. Sigh. */
if (_XkbUnavailable(dpy) || if (_XkbUnavailable(dpy) ||
(dpy->xkb_info->xlib_ctrls&XkbLC_ConsumeLookupMods)==0) (dpy->xkb_info->xlib_ctrls & XkbLC_ConsumeLookupMods) == 0)
new_mods= event->state; new_mods = event->state;
rtrnLen= XkbLookupKeyBinding(dpy,*keysym,new_mods,buffer,nbytes,NULL); rtrnLen = XkbLookupKeyBinding(dpy, *keysym, new_mods, buffer, nbytes, NULL);
if (rtrnLen>0) if (rtrnLen > 0)
return rtrnLen; return rtrnLen;
return XkbTranslateKeySym(dpy,keysym,new_mods,buffer,nbytes,NULL); return XkbTranslateKeySym(dpy, keysym, new_mods, buffer, nbytes, NULL);
} }
int int
XkbLookupKeyBinding( Display * dpy, XkbLookupKeyBinding(Display *dpy,
register KeySym sym, register KeySym sym,
unsigned int mods, unsigned int mods,
char * buffer, char *buffer,
int nbytes, int nbytes,
int * extra_rtrn) int *extra_rtrn)
{ {
register struct _XKeytrans *p; register struct _XKeytrans *p;
if (extra_rtrn) if (extra_rtrn)
*extra_rtrn= 0; *extra_rtrn = 0;
for (p = dpy->key_bindings; p; p = p->next) { for (p = dpy->key_bindings; p; p = p->next) {
if (((mods & AllMods) == p->state) && (sym == p->key)) { if (((mods & AllMods) == p->state) && (sym == p->key)) {
int tmp = p->len; int tmp = p->len;
if (tmp > nbytes) {
if (extra_rtrn) if (tmp > nbytes) {
*extra_rtrn= (tmp-nbytes); if (extra_rtrn)
tmp = nbytes; *extra_rtrn = (tmp - nbytes);
} tmp = nbytes;
memcpy (buffer, p->string, tmp); }
if (tmp < nbytes) buffer[tmp]= '\0'; memcpy(buffer, p->string, tmp);
return tmp; if (tmp < nbytes)
} buffer[tmp] = '\0';
return tmp;
}
} }
return 0; return 0;
} }
char char
XkbToControl( char ch ) XkbToControl(char ch)
{ {
register char c = ch; register char c = ch;
if ((c >= '@' && c < '\177') || c == ' ') c &= 0x1F; if ((c >= '@' && c < '\177') || c == ' ')
else if (c == '2') c = '\000'; c &= 0x1F;
else if (c >= '3' && c <= '7') c -= ('3' - '\033'); else if (c == '2')
else if (c == '8') c = '\177'; c = '\000';
else if (c == '/') c = '_' & 0x1F; else if (c >= '3' && c <= '7')
c -= ('3' - '\033');
else if (c == '8')
c = '\177';
else if (c == '/')
c = '_' & 0x1F;
return c; return c;
} }
...@@ -34,191 +34,197 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. ...@@ -34,191 +34,197 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "XKBlibint.h" #include "XKBlibint.h"
Status Status
_XkbReadGetCompatMapReply( Display * dpy, _XkbReadGetCompatMapReply(Display *dpy,
xkbGetCompatMapReply * rep, xkbGetCompatMapReply *rep,
XkbDescPtr xkb, XkbDescPtr xkb,
int * nread_rtrn) int *nread_rtrn)
{ {
register int i; register int i;
XkbReadBufferRec buf; XkbReadBufferRec buf;
if (!_XkbInitReadBuffer(dpy,&buf,(int)rep->length*4)) if (!_XkbInitReadBuffer(dpy, &buf, (int) rep->length * 4))
return BadAlloc; return BadAlloc;
if (nread_rtrn) if (nread_rtrn)
*nread_rtrn= (int)rep->length*4; *nread_rtrn = (int) rep->length * 4;
i= rep->firstSI+rep->nSI; i = rep->firstSI + rep->nSI;
if ((!xkb->compat)&& if ((!xkb->compat) &&
(XkbAllocCompatMap(xkb,XkbAllCompatMask,i)!=Success)) (XkbAllocCompatMap(xkb, XkbAllCompatMask, i) != Success))
return BadAlloc; return BadAlloc;
if (rep->nSI!=0) { if (rep->nSI != 0) {
XkbSymInterpretRec *syms; XkbSymInterpretRec *syms;
xkbSymInterpretWireDesc *wire; xkbSymInterpretWireDesc *wire;
wire= (xkbSymInterpretWireDesc *)_XkbGetReadBufferPtr(&buf, wire = (xkbSymInterpretWireDesc *) _XkbGetReadBufferPtr(&buf,
rep->nSI*SIZEOF(xkbSymInterpretWireDesc)); rep->nSI * SIZEOF (xkbSymInterpretWireDesc));
if (wire==NULL) if (wire == NULL)
goto BAILOUT; goto BAILOUT;
syms= &xkb->compat->sym_interpret[rep->firstSI]; syms = &xkb->compat->sym_interpret[rep->firstSI];
for (i=0;i<rep->nSI;i++,syms++,wire++) { for (i = 0; i < rep->nSI; i++, syms++, wire++) {
syms->sym= wire->sym; syms->sym = wire->sym;
syms->mods= wire->mods; syms->mods = wire->mods;
syms->match= wire->match; syms->match = wire->match;
syms->virtual_mod= wire->virtualMod; syms->virtual_mod = wire->virtualMod;
syms->flags= wire->flags; syms->flags = wire->flags;
syms->act= *((XkbAnyAction *)&wire->act); syms->act = *((XkbAnyAction *) &wire->act);
} }
xkb->compat->num_si+= rep->nSI; xkb->compat->num_si += rep->nSI;
} }
if (rep->groups&XkbAllGroupsMask) { if (rep->groups & XkbAllGroupsMask) {
register unsigned bit,nGroups; register unsigned bit, nGroups;
xkbModsWireDesc * wire; xkbModsWireDesc *wire;
for (i=0,nGroups=0,bit=1;i<XkbNumKbdGroups;i++,bit<<=1) {
if (rep->groups&bit) for (i = 0, nGroups = 0, bit = 1; i < XkbNumKbdGroups; i++, bit <<= 1) {
nGroups++; if (rep->groups & bit)
} nGroups++;
wire= (xkbModsWireDesc *)_XkbGetReadBufferPtr(&buf, }
nGroups*SIZEOF(xkbModsWireDesc)); wire = (xkbModsWireDesc *)
if (wire==NULL) _XkbGetReadBufferPtr(&buf, nGroups * SIZEOF(xkbModsWireDesc));
goto BAILOUT; if (wire == NULL)
for (i=0,bit=1;i<XkbNumKbdGroups;i++,bit<<=1) { goto BAILOUT;
if ((rep->groups&bit)==0) for (i = 0, bit = 1; i < XkbNumKbdGroups; i++, bit <<= 1) {
continue; if ((rep->groups & bit) == 0)
xkb->compat->groups[i].mask= wire->mask; continue;
xkb->compat->groups[i].real_mods= wire->realMods; xkb->compat->groups[i].mask = wire->mask;
xkb->compat->groups[i].vmods= wire->virtualMods; xkb->compat->groups[i].real_mods = wire->realMods;
wire++; xkb->compat->groups[i].vmods = wire->virtualMods;
} wire++;
}
} }
i= _XkbFreeReadBuffer(&buf); i = _XkbFreeReadBuffer(&buf);
if (i) if (i)
fprintf(stderr,"CompatMapReply! Bad length (%d extra bytes)\n",i); fprintf(stderr, "CompatMapReply! Bad length (%d extra bytes)\n", i);
if (i || buf.error) if (i || buf.error)
return BadLength; return BadLength;
return Success; return Success;
BAILOUT: BAILOUT:
_XkbFreeReadBuffer(&buf); _XkbFreeReadBuffer(&buf);
return BadLength; return BadLength;
} }
Status Status
XkbGetCompatMap(Display *dpy,unsigned which,XkbDescPtr xkb) XkbGetCompatMap(Display *dpy, unsigned which, XkbDescPtr xkb)
{ {
register xkbGetCompatMapReq *req; register xkbGetCompatMapReq *req;
xkbGetCompatMapReply rep; xkbGetCompatMapReply rep;
Status status; Status status;
XkbInfoPtr xkbi; XkbInfoPtr xkbi;
if ( (!dpy) || (!xkb) || (dpy->flags & XlibDisplayNoXkb) || if ((!dpy) || (!xkb) || (dpy->flags & XlibDisplayNoXkb) ||
((xkb->dpy!=NULL)&&(xkb->dpy!=dpy)) || ((xkb->dpy != NULL) && (xkb->dpy != dpy)) ||
(!dpy->xkb_info && (!XkbUseExtension(dpy,NULL,NULL)))) (!dpy->xkb_info && (!XkbUseExtension(dpy, NULL, NULL))))
return BadAccess; return BadAccess;
LockDisplay(dpy); LockDisplay(dpy);
xkbi = dpy->xkb_info; xkbi = dpy->xkb_info;
GetReq(kbGetCompatMap, req); GetReq(kbGetCompatMap, req);
req->reqType = xkbi->codes->major_opcode; req->reqType = xkbi->codes->major_opcode;
req->xkbReqType = X_kbGetCompatMap; req->xkbReqType = X_kbGetCompatMap;
req->deviceSpec = xkb->device_spec; req->deviceSpec = xkb->device_spec;
if (which&XkbSymInterpMask) if (which & XkbSymInterpMask)
req->getAllSI= True; req->getAllSI = True;
else req->getAllSI= False; else
req->firstSI= req->nSI= 0; req->getAllSI = False;
req->firstSI = req->nSI = 0;
if (which&XkbGroupCompatMask)
req->groups= XkbAllGroupsMask; if (which & XkbGroupCompatMask)
else req->groups= 0; req->groups = XkbAllGroupsMask;
else
if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { req->groups = 0;
UnlockDisplay(dpy);
SyncHandle(); if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) {
return BadLength; UnlockDisplay(dpy);
SyncHandle();
return BadLength;
} }
if (xkb->dpy==NULL) if (xkb->dpy == NULL)
xkb->dpy= dpy; xkb->dpy = dpy;
if (xkb->device_spec==XkbUseCoreKbd) if (xkb->device_spec == XkbUseCoreKbd)
xkb->device_spec= rep.deviceID; xkb->device_spec = rep.deviceID;
status = _XkbReadGetCompatMapReply(dpy,&rep,xkb,NULL); status = _XkbReadGetCompatMapReply(dpy, &rep, xkb, NULL);
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
return status; return status;
} }
static Bool static Bool
_XkbWriteSetCompatMap(Display *dpy,xkbSetCompatMapReq *req,XkbDescPtr xkb) _XkbWriteSetCompatMap(Display *dpy, xkbSetCompatMapReq *req, XkbDescPtr xkb)
{ {
CARD16 firstSI; CARD16 firstSI;
CARD16 nSI; CARD16 nSI;
int size; int size;
register int i,nGroups; register int i, nGroups;
register unsigned bit; register unsigned bit;
unsigned groups; unsigned groups;
char * buf; char *buf;
firstSI = req->firstSI; firstSI = req->firstSI;
nSI = req->nSI; nSI = req->nSI;
size= nSI*SIZEOF(xkbSymInterpretWireDesc); size = nSI * SIZEOF(xkbSymInterpretWireDesc);
nGroups= 0; nGroups = 0;
groups= req->groups; groups = req->groups;
if (groups&XkbAllGroupsMask) { if (groups & XkbAllGroupsMask) {
for (i=0,bit=1;i<XkbNumKbdGroups;i++,bit<<=1) { for (i = 0, bit = 1; i < XkbNumKbdGroups; i++, bit <<= 1) {
if (groups&bit) if (groups & bit)
nGroups++; nGroups++;
} }
size+= SIZEOF(xkbModsWireDesc)*nGroups; size += SIZEOF(xkbModsWireDesc) * nGroups;
} }
req->length+= size/4; req->length += size / 4;
BufAlloc(char *,buf,size); BufAlloc(char *, buf, size);
if (!buf) if (!buf)
return False; return False;
if (nSI) { if (nSI) {
XkbSymInterpretPtr sym= &xkb->compat->sym_interpret[firstSI]; XkbSymInterpretPtr sym = &xkb->compat->sym_interpret[firstSI];
xkbSymInterpretWireDesc *wire= (xkbSymInterpretWireDesc *)buf; xkbSymInterpretWireDesc *wire = (xkbSymInterpretWireDesc *) buf;
for (i=0;i<nSI;i++,wire++,sym++) {
wire->sym= (CARD32)sym->sym; for (i = 0; i < nSI; i++, wire++, sym++) {
wire->mods= sym->mods; wire->sym = (CARD32) sym->sym;
wire->match= sym->match; wire->mods = sym->mods;
wire->flags= sym->flags; wire->match = sym->match;
wire->virtualMod= sym->virtual_mod; wire->flags = sym->flags;
memcpy(&wire->act,&sym->act,sz_xkbActionWireDesc); wire->virtualMod = sym->virtual_mod;
} memcpy(&wire->act, &sym->act, sz_xkbActionWireDesc);
buf+= nSI*SIZEOF(xkbSymInterpretWireDesc); }
buf += nSI * SIZEOF(xkbSymInterpretWireDesc);
} }
if (groups&XkbAllGroupsMask) { if (groups & XkbAllGroupsMask) {
xkbModsWireDesc * out; xkbModsWireDesc *out;
out= (xkbModsWireDesc *)buf; out = (xkbModsWireDesc *) buf;
for (i=0,bit=1;i<XkbNumKbdGroups;i++,bit<<=1) { for (i = 0, bit = 1; i < XkbNumKbdGroups; i++, bit <<= 1) {
if ((groups&bit)!=0) { if ((groups & bit) != 0) {
out->mask= xkb->compat->groups[i].mask; out->mask = xkb->compat->groups[i].mask;
out->realMods= xkb->compat->groups[i].real_mods; out->realMods = xkb->compat->groups[i].real_mods;
out->virtualMods= xkb->compat->groups[i].vmods; out->virtualMods = xkb->compat->groups[i].vmods;
out++; out++;
} }
} }
buf+= nGroups*SIZEOF(xkbModsWireDesc); buf += nGroups * SIZEOF(xkbModsWireDesc);
} }
return True; return True;
} }
Bool Bool
XkbSetCompatMap(Display *dpy,unsigned which,XkbDescPtr xkb,Bool updateActions) XkbSetCompatMap(Display *dpy, unsigned which, XkbDescPtr xkb,
Bool updateActions)
{ {
register xkbSetCompatMapReq *req; register xkbSetCompatMapReq *req;
Status ok; Status ok;
XkbInfoPtr xkbi; XkbInfoPtr xkbi;
if ((dpy->flags & XlibDisplayNoXkb) || (dpy!=xkb->dpy) || if ((dpy->flags & XlibDisplayNoXkb) || (dpy != xkb->dpy) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return False; return False;
if ((!xkb->compat) || if ((!xkb->compat) ||
((which&XkbSymInterpMask)&&(!xkb->compat->sym_interpret))) ((which & XkbSymInterpMask) && (!xkb->compat->sym_interpret)))
return False; return False;
LockDisplay(dpy); LockDisplay(dpy);
xkbi = dpy->xkb_info; xkbi = dpy->xkb_info;
GetReq(kbSetCompatMap, req); GetReq(kbSetCompatMap, req);
...@@ -226,22 +232,22 @@ XkbSetCompatMap(Display *dpy,unsigned which,XkbDescPtr xkb,Bool updateActions) ...@@ -226,22 +232,22 @@ XkbSetCompatMap(Display *dpy,unsigned which,XkbDescPtr xkb,Bool updateActions)
req->xkbReqType = X_kbSetCompatMap; req->xkbReqType = X_kbSetCompatMap;
req->deviceSpec = xkb->device_spec; req->deviceSpec = xkb->device_spec;
req->recomputeActions = updateActions; req->recomputeActions = updateActions;
if (which&XkbSymInterpMask) { if (which & XkbSymInterpMask) {
req->truncateSI = True; req->truncateSI = True;
req->firstSI= 0; req->firstSI = 0;
req->nSI= xkb->compat->num_si; req->nSI = xkb->compat->num_si;
} }
else { else {
req->truncateSI = False; req->truncateSI = False;
req->firstSI= 0; req->firstSI = 0;
req->nSI= 0; req->nSI = 0;
} }
if (which&XkbGroupCompatMask) if (which & XkbGroupCompatMask)
req->groups= XkbAllGroupsMask; req->groups = XkbAllGroupsMask;
else req->groups= 0; else
ok= _XkbWriteSetCompatMap(dpy,req,xkb); req->groups = 0;
ok = _XkbWriteSetCompatMap(dpy, req, xkb);
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
return ok; return ok;
} }
...@@ -34,32 +34,32 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. ...@@ -34,32 +34,32 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
static xkbSetControlsReq * static xkbSetControlsReq *
_XkbGetSetControlsReq(Display *dpy,XkbInfoPtr xkbi,unsigned int deviceSpec) _XkbGetSetControlsReq(Display *dpy, XkbInfoPtr xkbi, unsigned int deviceSpec)
{ {
xkbSetControlsReq *req; xkbSetControlsReq *req;
GetReq(kbSetControls,req); GetReq(kbSetControls, req);
bzero(req,SIZEOF(xkbSetControlsReq)); bzero(req, SIZEOF(xkbSetControlsReq));
req->reqType = xkbi->codes->major_opcode; req->reqType = xkbi->codes->major_opcode;
req->length = (SIZEOF(xkbSetControlsReq)>>2); req->length = (SIZEOF(xkbSetControlsReq) >> 2);
req->xkbReqType = X_kbSetControls; req->xkbReqType = X_kbSetControls;
req->deviceSpec = deviceSpec; req->deviceSpec = deviceSpec;
return req; return req;
} }
Bool Bool
XkbSetAutoRepeatRate( Display *dpy, XkbSetAutoRepeatRate(Display *dpy,
unsigned int deviceSpec, unsigned int deviceSpec,
unsigned int timeout, unsigned int timeout,
unsigned int interval) unsigned int interval)
{ {
register xkbSetControlsReq *req; register xkbSetControlsReq *req;
if ((dpy->flags & XlibDisplayNoXkb) || if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return False; return False;
LockDisplay(dpy); LockDisplay(dpy);
req= _XkbGetSetControlsReq(dpy,dpy->xkb_info,deviceSpec); req = _XkbGetSetControlsReq(dpy, dpy->xkb_info, deviceSpec);
req->changeCtrls = XkbRepeatKeysMask; req->changeCtrls = XkbRepeatKeysMask;
req->repeatDelay = timeout; req->repeatDelay = timeout;
req->repeatInterval = interval; req->repeatInterval = interval;
...@@ -69,29 +69,29 @@ XkbSetAutoRepeatRate( Display *dpy, ...@@ -69,29 +69,29 @@ XkbSetAutoRepeatRate( Display *dpy,
} }
Bool Bool
XkbGetAutoRepeatRate( Display * dpy, XkbGetAutoRepeatRate(Display *dpy,
unsigned int deviceSpec, unsigned int deviceSpec,
unsigned int * timeoutp, unsigned int *timeoutp,
unsigned int * intervalp) unsigned int *intervalp)
{ {
register xkbGetControlsReq *req; register xkbGetControlsReq *req;
xkbGetControlsReply rep; xkbGetControlsReply rep;
XkbInfoPtr xkbi; XkbInfoPtr xkbi;
if ((dpy->flags & XlibDisplayNoXkb) || if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return False; return False;
LockDisplay(dpy); LockDisplay(dpy);
xkbi = dpy->xkb_info; xkbi = dpy->xkb_info;
GetReq(kbGetControls, req); GetReq(kbGetControls, req);
req->reqType = xkbi->codes->major_opcode; req->reqType = xkbi->codes->major_opcode;
req->xkbReqType = X_kbGetControls; req->xkbReqType = X_kbGetControls;
req->deviceSpec = deviceSpec; req->deviceSpec = deviceSpec;
if (!_XReply(dpy, (xReply *)&rep, if (!_XReply(dpy, (xReply *) &rep,
(SIZEOF(xkbGetControlsReply)-SIZEOF(xReply))>>2, xFalse)) { (SIZEOF(xkbGetControlsReply) - SIZEOF(xReply)) >> 2, xFalse)) {
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
return False; return False;
} }
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
...@@ -101,24 +101,24 @@ XkbGetAutoRepeatRate( Display * dpy, ...@@ -101,24 +101,24 @@ XkbGetAutoRepeatRate( Display * dpy,
} }
Bool Bool
XkbSetServerInternalMods( Display * dpy, XkbSetServerInternalMods(Display *dpy,
unsigned deviceSpec, unsigned deviceSpec,
unsigned affectReal, unsigned affectReal,
unsigned realValues, unsigned realValues,
unsigned affectVirtual, unsigned affectVirtual,
unsigned virtualValues) unsigned virtualValues)
{ {
register xkbSetControlsReq *req; register xkbSetControlsReq *req;
if ((dpy->flags & XlibDisplayNoXkb) || if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return False; return False;
LockDisplay(dpy); LockDisplay(dpy);
req= _XkbGetSetControlsReq(dpy,dpy->xkb_info,deviceSpec); req = _XkbGetSetControlsReq(dpy, dpy->xkb_info, deviceSpec);
req->affectInternalMods = affectReal; req->affectInternalMods = affectReal;
req->internalMods = realValues; req->internalMods = realValues;
req->affectInternalVMods= affectVirtual; req->affectInternalVMods = affectVirtual;
req->internalVMods= virtualValues; req->internalVMods = virtualValues;
req->changeCtrls = XkbInternalModsMask; req->changeCtrls = XkbInternalModsMask;
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
...@@ -126,24 +126,24 @@ XkbSetServerInternalMods( Display * dpy, ...@@ -126,24 +126,24 @@ XkbSetServerInternalMods( Display * dpy,
} }
Bool Bool
XkbSetIgnoreLockMods( Display * dpy, XkbSetIgnoreLockMods(Display *dpy,
unsigned int deviceSpec, unsigned int deviceSpec,
unsigned affectReal, unsigned affectReal,
unsigned realValues, unsigned realValues,
unsigned affectVirtual, unsigned affectVirtual,
unsigned virtualValues) unsigned virtualValues)
{ {
register xkbSetControlsReq *req; register xkbSetControlsReq *req;
if ((dpy->flags & XlibDisplayNoXkb) || if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return False; return False;
LockDisplay(dpy); LockDisplay(dpy);
req= _XkbGetSetControlsReq(dpy,dpy->xkb_info,deviceSpec); req = _XkbGetSetControlsReq(dpy, dpy->xkb_info, deviceSpec);
req->affectIgnoreLockMods= affectReal; req->affectIgnoreLockMods = affectReal;
req->ignoreLockMods = realValues; req->ignoreLockMods = realValues;
req->affectIgnoreLockVMods= affectVirtual; req->affectIgnoreLockVMods = affectVirtual;
req->ignoreLockVMods= virtualValues; req->ignoreLockVMods = virtualValues;
req->changeCtrls = XkbIgnoreLockModsMask; req->changeCtrls = XkbIgnoreLockModsMask;
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
...@@ -151,20 +151,20 @@ XkbSetIgnoreLockMods( Display * dpy, ...@@ -151,20 +151,20 @@ XkbSetIgnoreLockMods( Display * dpy,
} }
Bool Bool
XkbChangeEnabledControls( Display * dpy, XkbChangeEnabledControls(Display *dpy,
unsigned deviceSpec, unsigned deviceSpec,
unsigned affect, unsigned affect,
unsigned values) unsigned values)
{ {
register xkbSetControlsReq *req; register xkbSetControlsReq *req;
if ((dpy->flags & XlibDisplayNoXkb) || if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return False; return False;
LockDisplay(dpy); LockDisplay(dpy);
req= _XkbGetSetControlsReq(dpy,dpy->xkb_info,deviceSpec); req = _XkbGetSetControlsReq(dpy, dpy->xkb_info, deviceSpec);
req->affectEnabledCtrls= affect; req->affectEnabledCtrls = affect;
req->enabledCtrls= (affect&values); req->enabledCtrls = (affect & values);
req->changeCtrls = XkbControlsEnabledMask; req->changeCtrls = XkbControlsEnabledMask;
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
...@@ -176,91 +176,90 @@ XkbGetControls(Display *dpy, unsigned long which, XkbDescPtr xkb) ...@@ -176,91 +176,90 @@ XkbGetControls(Display *dpy, unsigned long which, XkbDescPtr xkb)
{ {
register xkbGetControlsReq *req; register xkbGetControlsReq *req;
xkbGetControlsReply rep; xkbGetControlsReply rep;
XkbControlsPtr ctrls; XkbControlsPtr ctrls;
XkbInfoPtr xkbi; XkbInfoPtr xkbi;
if ((dpy->flags & XlibDisplayNoXkb) || if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return BadAccess; return BadAccess;
if ((!xkb) || (!which)) if ((!xkb) || (!which))
return BadMatch; return BadMatch;
LockDisplay(dpy); LockDisplay(dpy);
xkbi = dpy->xkb_info; xkbi = dpy->xkb_info;
GetReq(kbGetControls, req); GetReq(kbGetControls, req);
if (!xkb->ctrls) { if (!xkb->ctrls) {
xkb->ctrls = _XkbTypedCalloc(1,XkbControlsRec); xkb->ctrls = _XkbTypedCalloc(1, XkbControlsRec);
if (!xkb->ctrls) { if (!xkb->ctrls) {
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
return BadAlloc; return BadAlloc;
} }
} }
req->reqType = xkbi->codes->major_opcode; req->reqType = xkbi->codes->major_opcode;
req->xkbReqType = X_kbGetControls; req->xkbReqType = X_kbGetControls;
req->deviceSpec = xkb->device_spec; req->deviceSpec = xkb->device_spec;
if (!_XReply(dpy, (xReply *)&rep, if (!_XReply(dpy, (xReply *) &rep,
(SIZEOF(xkbGetControlsReply)-SIZEOF(xReply))>>2, xFalse)) { (SIZEOF(xkbGetControlsReply) - SIZEOF(xReply)) >> 2, xFalse)) {
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
return BadImplementation; return BadImplementation;
} }
if (xkb->device_spec==XkbUseCoreKbd) if (xkb->device_spec == XkbUseCoreKbd)
xkb->device_spec= rep.deviceID; xkb->device_spec = rep.deviceID;
ctrls= xkb->ctrls; ctrls = xkb->ctrls;
if (which&XkbControlsEnabledMask) if (which & XkbControlsEnabledMask)
ctrls->enabled_ctrls = rep.enabledCtrls; ctrls->enabled_ctrls = rep.enabledCtrls;
ctrls->num_groups= rep.numGroups; ctrls->num_groups = rep.numGroups;
if (which&XkbGroupsWrapMask) if (which & XkbGroupsWrapMask)
ctrls->groups_wrap= rep.groupsWrap; ctrls->groups_wrap = rep.groupsWrap;
if (which&XkbInternalModsMask) { if (which & XkbInternalModsMask) {
ctrls->internal.mask = rep.internalMods; ctrls->internal.mask = rep.internalMods;
ctrls->internal.real_mods = rep.internalRealMods; ctrls->internal.real_mods = rep.internalRealMods;
ctrls->internal.vmods = rep.internalVMods; ctrls->internal.vmods = rep.internalVMods;
} }
if (which&XkbIgnoreLockModsMask) { if (which & XkbIgnoreLockModsMask) {
ctrls->ignore_lock.mask = rep.ignoreLockMods; ctrls->ignore_lock.mask = rep.ignoreLockMods;
ctrls->ignore_lock.real_mods = rep.ignoreLockRealMods; ctrls->ignore_lock.real_mods = rep.ignoreLockRealMods;
ctrls->ignore_lock.vmods = rep.ignoreLockVMods; ctrls->ignore_lock.vmods = rep.ignoreLockVMods;
} }
if (which&XkbRepeatKeysMask) { if (which & XkbRepeatKeysMask) {
ctrls->repeat_delay = rep.repeatDelay; ctrls->repeat_delay = rep.repeatDelay;
ctrls->repeat_interval = rep.repeatInterval; ctrls->repeat_interval = rep.repeatInterval;
} }
if (which&XkbSlowKeysMask) if (which & XkbSlowKeysMask)
ctrls->slow_keys_delay = rep.slowKeysDelay; ctrls->slow_keys_delay = rep.slowKeysDelay;
if (which&XkbBounceKeysMask) if (which & XkbBounceKeysMask)
ctrls->debounce_delay = rep.debounceDelay; ctrls->debounce_delay = rep.debounceDelay;
if (which&XkbMouseKeysMask) { if (which & XkbMouseKeysMask) {
ctrls->mk_dflt_btn = rep.mkDfltBtn; ctrls->mk_dflt_btn = rep.mkDfltBtn;
} }
if (which&XkbMouseKeysAccelMask) { if (which & XkbMouseKeysAccelMask) {
ctrls->mk_delay = rep.mkDelay; ctrls->mk_delay = rep.mkDelay;
ctrls->mk_interval = rep.mkInterval; ctrls->mk_interval = rep.mkInterval;
ctrls->mk_time_to_max = rep.mkTimeToMax; ctrls->mk_time_to_max = rep.mkTimeToMax;
ctrls->mk_max_speed = rep.mkMaxSpeed; ctrls->mk_max_speed = rep.mkMaxSpeed;
ctrls->mk_curve = rep.mkCurve; ctrls->mk_curve = rep.mkCurve;
} }
if (which&XkbAccessXKeysMask) if (which & XkbAccessXKeysMask)
ctrls->ax_options= rep.axOptions; ctrls->ax_options = rep.axOptions;
if (which&XkbStickyKeysMask) { if (which & XkbStickyKeysMask) {
ctrls->ax_options &= ~XkbAX_SKOptionsMask; ctrls->ax_options &= ~XkbAX_SKOptionsMask;
ctrls->ax_options |= rep.axOptions & XkbAX_SKOptionsMask; ctrls->ax_options |= rep.axOptions & XkbAX_SKOptionsMask;
} }
if (which&XkbAccessXFeedbackMask) { if (which & XkbAccessXFeedbackMask) {
ctrls->ax_options &= ~XkbAX_FBOptionsMask; ctrls->ax_options &= ~XkbAX_FBOptionsMask;
ctrls->ax_options |= rep.axOptions & XkbAX_FBOptionsMask; ctrls->ax_options |= rep.axOptions & XkbAX_FBOptionsMask;
} }
if (which&XkbAccessXTimeoutMask) { if (which & XkbAccessXTimeoutMask) {
ctrls->ax_timeout = rep.axTimeout; ctrls->ax_timeout = rep.axTimeout;
ctrls->axt_ctrls_mask = rep.axtCtrlsMask; ctrls->axt_ctrls_mask = rep.axtCtrlsMask;
ctrls->axt_ctrls_values = rep.axtCtrlsValues; ctrls->axt_ctrls_values = rep.axtCtrlsValues;
ctrls->axt_opts_mask = rep.axtOptsMask; ctrls->axt_opts_mask = rep.axtOptsMask;
ctrls->axt_opts_values= rep.axtOptsValues; ctrls->axt_opts_values = rep.axtOptsValues;
} }
if (which&XkbPerKeyRepeatMask) { if (which & XkbPerKeyRepeatMask) {
memcpy(ctrls->per_key_repeat,rep.perKeyRepeat, memcpy(ctrls->per_key_repeat, rep.perKeyRepeat, XkbPerKeyBitArraySize);
XkbPerKeyBitArraySize);
} }
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
...@@ -271,66 +270,66 @@ Bool ...@@ -271,66 +270,66 @@ Bool
XkbSetControls(Display *dpy, unsigned long which, XkbDescPtr xkb) XkbSetControls(Display *dpy, unsigned long which, XkbDescPtr xkb)
{ {
register xkbSetControlsReq *req; register xkbSetControlsReq *req;
XkbControlsPtr ctrls; XkbControlsPtr ctrls;
if ((dpy->flags & XlibDisplayNoXkb) || if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return False; return False;
if ((!xkb)||(!xkb->ctrls)) if ((!xkb) || (!xkb->ctrls))
return False; return False;
ctrls= xkb->ctrls; ctrls = xkb->ctrls;
LockDisplay(dpy); LockDisplay(dpy);
req= _XkbGetSetControlsReq(dpy,dpy->xkb_info,xkb->device_spec); req = _XkbGetSetControlsReq(dpy, dpy->xkb_info, xkb->device_spec);
req->changeCtrls = (CARD32)which; req->changeCtrls = (CARD32) which;
if (which&XkbInternalModsMask) { if (which & XkbInternalModsMask) {
req->affectInternalMods= ~0; req->affectInternalMods = ~0;
req->internalMods= ctrls->internal.real_mods; req->internalMods = ctrls->internal.real_mods;
req->affectInternalVMods = ~0; req->affectInternalVMods = ~0;
req->internalVMods= ctrls->internal.vmods; req->internalVMods = ctrls->internal.vmods;
} }
if (which&XkbIgnoreLockModsMask) { if (which & XkbIgnoreLockModsMask) {
req->affectIgnoreLockMods= ~0; req->affectIgnoreLockMods = ~0;
req->ignoreLockMods= ctrls->ignore_lock.real_mods; req->ignoreLockMods = ctrls->ignore_lock.real_mods;
req->affectIgnoreLockVMods= ~0; req->affectIgnoreLockVMods = ~0;
req->ignoreLockVMods= ctrls->ignore_lock.vmods; req->ignoreLockVMods = ctrls->ignore_lock.vmods;
} }
if (which&XkbControlsEnabledMask) { if (which & XkbControlsEnabledMask) {
req->affectEnabledCtrls= XkbAllBooleanCtrlsMask; req->affectEnabledCtrls = XkbAllBooleanCtrlsMask;
req->enabledCtrls= ctrls->enabled_ctrls; req->enabledCtrls = ctrls->enabled_ctrls;
} }
if (which&XkbRepeatKeysMask) { if (which & XkbRepeatKeysMask) {
req->repeatDelay = ctrls->repeat_delay; req->repeatDelay = ctrls->repeat_delay;
req->repeatInterval = ctrls->repeat_interval; req->repeatInterval = ctrls->repeat_interval;
} }
if (which&XkbSlowKeysMask) if (which & XkbSlowKeysMask)
req->slowKeysDelay = ctrls->slow_keys_delay; req->slowKeysDelay = ctrls->slow_keys_delay;
if (which&XkbBounceKeysMask) if (which & XkbBounceKeysMask)
req->debounceDelay = ctrls->debounce_delay; req->debounceDelay = ctrls->debounce_delay;
if (which&XkbMouseKeysMask) { if (which & XkbMouseKeysMask) {
req->mkDfltBtn = ctrls->mk_dflt_btn; req->mkDfltBtn = ctrls->mk_dflt_btn;
} }
if (which&XkbGroupsWrapMask) if (which & XkbGroupsWrapMask)
req->groupsWrap= ctrls->groups_wrap; req->groupsWrap = ctrls->groups_wrap;
if (which&(XkbAccessXKeysMask|XkbStickyKeysMask|XkbAccessXFeedbackMask)) if (which &
req->axOptions= ctrls->ax_options; (XkbAccessXKeysMask | XkbStickyKeysMask | XkbAccessXFeedbackMask))
if (which&XkbMouseKeysAccelMask) { req->axOptions = ctrls->ax_options;
req->mkDelay = ctrls->mk_delay; if (which & XkbMouseKeysAccelMask) {
req->mkInterval = ctrls->mk_interval; req->mkDelay = ctrls->mk_delay;
req->mkTimeToMax = ctrls->mk_time_to_max; req->mkInterval = ctrls->mk_interval;
req->mkMaxSpeed = ctrls->mk_max_speed; req->mkTimeToMax = ctrls->mk_time_to_max;
req->mkCurve = ctrls->mk_curve; req->mkMaxSpeed = ctrls->mk_max_speed;
req->mkCurve = ctrls->mk_curve;
} }
if (which&XkbAccessXTimeoutMask) { if (which & XkbAccessXTimeoutMask) {
req->axTimeout = ctrls->ax_timeout; req->axTimeout = ctrls->ax_timeout;
req->axtCtrlsMask = ctrls->axt_ctrls_mask; req->axtCtrlsMask = ctrls->axt_ctrls_mask;
req->axtCtrlsValues = ctrls->axt_ctrls_values; req->axtCtrlsValues = ctrls->axt_ctrls_values;
req->axtOptsMask = ctrls->axt_opts_mask; req->axtOptsMask = ctrls->axt_opts_mask;
req->axtOptsValues=ctrls->axt_opts_values; req->axtOptsValues = ctrls->axt_opts_values;
} }
if (which&XkbPerKeyRepeatMask) { if (which & XkbPerKeyRepeatMask) {
memcpy(req->perKeyRepeat,ctrls->per_key_repeat, memcpy(req->perKeyRepeat, ctrls->per_key_repeat, XkbPerKeyBitArraySize);
XkbPerKeyBitArraySize);
} }
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
...@@ -340,13 +339,13 @@ XkbSetControls(Display *dpy, unsigned long which, XkbDescPtr xkb) ...@@ -340,13 +339,13 @@ XkbSetControls(Display *dpy, unsigned long which, XkbDescPtr xkb)
/***====================================================================***/ /***====================================================================***/
void void
XkbNoteControlsChanges( XkbControlsChangesPtr old, XkbNoteControlsChanges(XkbControlsChangesPtr old,
XkbControlsNotifyEvent * new, XkbControlsNotifyEvent *new,
unsigned int wanted) unsigned int wanted)
{ {
old->changed_ctrls|= (new->changed_ctrls&wanted); old->changed_ctrls |= (new->changed_ctrls & wanted);
if (new->changed_ctrls&XkbControlsEnabledMask&wanted) if (new->changed_ctrls & XkbControlsEnabledMask & wanted)
old->enabled_ctrls_changes^= new->enabled_ctrl_changes; old->enabled_ctrls_changes ^= new->enabled_ctrl_changes;
/* num_groups_changed?? */ /* num_groups_changed?? */
return; return;
} }
...@@ -60,94 +60,99 @@ _XkbHandleSpecialSym(KeySym keysym, char *buffer, int nbytes, int *extra_rtrn) ...@@ -60,94 +60,99 @@ _XkbHandleSpecialSym(KeySym keysym, char *buffer, int nbytes, int *extra_rtrn)
/* try to convert to Latin-1, handling ctrl */ /* try to convert to Latin-1, handling ctrl */
if (!(((keysym >= XK_BackSpace) && (keysym <= XK_Clear)) || if (!(((keysym >= XK_BackSpace) && (keysym <= XK_Clear)) ||
(keysym == XK_Return) || (keysym == XK_Escape) || (keysym == XK_Return) || (keysym == XK_Escape) ||
(keysym == XK_KP_Space) || (keysym == XK_KP_Tab) || (keysym == XK_KP_Space) || (keysym == XK_KP_Tab) ||
(keysym == XK_KP_Enter) || (keysym == XK_KP_Enter) ||
((keysym >= XK_KP_Multiply) && (keysym <= XK_KP_9)) || ((keysym >= XK_KP_Multiply) && (keysym <= XK_KP_9)) ||
(keysym == XK_KP_Equal) || (keysym == XK_KP_Equal) || (keysym == XK_Delete)))
(keysym == XK_Delete))) return 0;
return 0;
if (nbytes < 1) {
if (nbytes<1) { if (extra_rtrn)
if (extra_rtrn) *extra_rtrn = 1;
*extra_rtrn= 1; return 0;
return 0;
} }
/* if X keysym, convert to ascii by grabbing low 7 bits */ /* if X keysym, convert to ascii by grabbing low 7 bits */
if (keysym == XK_KP_Space) if (keysym == XK_KP_Space)
buffer[0] = XK_space & 0x7F; /* patch encoding botch */ buffer[0] = XK_space & 0x7F; /* patch encoding botch */
else if (keysym == XK_hyphen) else if (keysym == XK_hyphen)
buffer[0] = (char)(XK_minus & 0xFF); /* map to equiv character */ buffer[0] = (char) (XK_minus & 0xFF); /* map to equiv character */
else buffer[0] = (char)(keysym & 0x7F); else
buffer[0] = (char) (keysym & 0x7F);
return 1; return 1;
} }
/*ARGSUSED*/ /*ARGSUSED*/
static int static int
_XkbKSToKnownSet ( XPointer priv, _XkbKSToKnownSet(XPointer priv,
KeySym keysym, KeySym keysym,
char * buffer, char *buffer,
int nbytes, int nbytes,
int * extra_rtrn) int *extra_rtrn)
{ {
char tbuf[8],*buf; char tbuf[8], *buf;
if (extra_rtrn) if (extra_rtrn)
*extra_rtrn= 0; *extra_rtrn = 0;
/* convert "dead" diacriticals for dumb applications */ /* convert "dead" diacriticals for dumb applications */
if ( (keysym&0xffffff00)== 0xfe00 ) { if ((keysym & 0xffffff00) == 0xfe00) {
switch ( keysym ) { switch (keysym) {
case XK_dead_grave: keysym = XK_grave; break; case XK_dead_grave: keysym = XK_grave; break;
case XK_dead_acute: keysym = XK_acute; break; case XK_dead_acute: keysym = XK_acute; break;
case XK_dead_circumflex: keysym = XK_asciicircum; break; case XK_dead_circumflex: keysym = XK_asciicircum; break;
case XK_dead_tilde: keysym = XK_asciitilde; break; case XK_dead_tilde: keysym = XK_asciitilde; break;
case XK_dead_macron: keysym = XK_macron; break; case XK_dead_macron: keysym = XK_macron; break;
case XK_dead_breve: keysym = XK_breve; break; case XK_dead_breve: keysym = XK_breve; break;
case XK_dead_abovedot: keysym = XK_abovedot; break; case XK_dead_abovedot: keysym = XK_abovedot; break;
case XK_dead_diaeresis: keysym = XK_diaeresis; break; case XK_dead_diaeresis: keysym = XK_diaeresis; break;
case XK_dead_abovering: keysym = XK_degree; break; case XK_dead_abovering: keysym = XK_degree; break;
case XK_dead_doubleacute: keysym = XK_doubleacute; break; case XK_dead_doubleacute: keysym = XK_doubleacute; break;
case XK_dead_caron: keysym = XK_caron; break; case XK_dead_caron: keysym = XK_caron; break;
case XK_dead_cedilla: keysym = XK_cedilla; break; case XK_dead_cedilla: keysym = XK_cedilla; break;
case XK_dead_ogonek : keysym = XK_ogonek; break; case XK_dead_ogonek: keysym = XK_ogonek; break;
case XK_dead_iota: keysym = XK_Greek_iota; break; case XK_dead_iota: keysym = XK_Greek_iota; break;
#ifdef XK_KATAKANA #ifdef XK_KATAKANA
case XK_dead_voiced_sound: keysym = XK_voicedsound; break; case XK_dead_voiced_sound: keysym = XK_voicedsound; break;
case XK_dead_semivoiced_sound:keysym = XK_semivoicedsound; break; case XK_dead_semivoiced_sound: keysym = XK_semivoicedsound; break;
#endif #endif
} }
} }
if (nbytes<1) buf= tbuf; if (nbytes < 1)
else buf= buffer; buf = tbuf;
else
buf = buffer;
if ((keysym&0xffffff00)==0xff00) { if ((keysym & 0xffffff00) == 0xff00) {
return _XkbHandleSpecialSym(keysym, buf, nbytes, extra_rtrn); return _XkbHandleSpecialSym(keysym, buf, nbytes, extra_rtrn);
} }
return _XimGetCharCode (priv, keysym, (unsigned char *)buf, nbytes); return _XimGetCharCode(priv, keysym, (unsigned char *) buf, nbytes);
} }
typedef struct _XkbToKS { typedef struct _XkbToKS {
unsigned prefix; unsigned prefix;
char *map; char *map;
} XkbToKS; } XkbToKS;
/*ARGSUSED*/ /*ARGSUSED*/
static KeySym static KeySym
_XkbKnownSetToKS(XPointer priv,char *buffer,int nbytes,Status *status) _XkbKnownSetToKS(XPointer priv, char *buffer, int nbytes, Status *status)
{ {
if (nbytes!=1) if (nbytes != 1)
return NoSymbol; return NoSymbol;
if (((buffer[0]&0x80)==0)&&(buffer[0]>=32)) if (((buffer[0] & 0x80) == 0) && (buffer[0] >= 32))
return buffer[0]; return buffer[0];
else if ((buffer[0]&0x7f)>=32) { else if ((buffer[0] & 0x7f) >= 32) {
XkbToKS *map= (XkbToKS *)priv; XkbToKS *map = (XkbToKS *) priv;
if ( map ) {
if ( map->map ) return map->prefix|map->map[buffer[0]&0x7f]; if (map) {
else return map->prefix|buffer[0]; if (map->map)
} return map->prefix | map->map[buffer[0] & 0x7f];
return buffer[0]; else
return map->prefix | buffer[0];
}
return buffer[0];
} }
return NoSymbol; return NoSymbol;
} }
...@@ -155,7 +160,7 @@ _XkbKnownSetToKS(XPointer priv,char *buffer,int nbytes,Status *status) ...@@ -155,7 +160,7 @@ _XkbKnownSetToKS(XPointer priv,char *buffer,int nbytes,Status *status)
static KeySym static KeySym
__XkbDefaultToUpper(KeySym sym) __XkbDefaultToUpper(KeySym sym)
{ {
KeySym lower,upper; KeySym lower, upper;
XConvertCase(sym, &lower, &upper); XConvertCase(sym, &lower, &upper);
return upper; return upper;
...@@ -172,13 +177,13 @@ Strcmp(char *str1, char *str2) ...@@ -172,13 +177,13 @@ Strcmp(char *str1, char *str2)
* unchecked strings from the environment can end up here, so check * unchecked strings from the environment can end up here, so check
* the length before copying. * the length before copying.
*/ */
if (strlen(str1) >= sizeof(str)) /* almost certain it's a mismatch */ if (strlen(str1) >= sizeof(str)) /* almost certain it's a mismatch */
return 1; return 1;
for (s = str; (c = *str1++); ) { for (s = str; (c = *str1++);) {
if (isupper(c)) if (isupper(c))
c = tolower(c); c = tolower(c);
*s++ = c; *s++ = c;
} }
*s = '\0'; *s = '\0';
return (strcmp(str, str2)); return (strcmp(str, str2));
...@@ -186,9 +191,10 @@ Strcmp(char *str1, char *str2) ...@@ -186,9 +191,10 @@ Strcmp(char *str1, char *str2)
#endif #endif
int int
_XkbGetConverters(const char *encoding_name, XkbConverters *cvt_rtrn) _XkbGetConverters(const char *encoding_name, XkbConverters * cvt_rtrn)
{ {
if ( !cvt_rtrn ) return 0; if (!cvt_rtrn)
return 0;
cvt_rtrn->KSToMB = _XkbKSToKnownSet; cvt_rtrn->KSToMB = _XkbKSToKnownSet;
cvt_rtrn->KSToMBPriv = _XimGetLocaleCode(encoding_name); cvt_rtrn->KSToMBPriv = _XimGetLocaleCode(encoding_name);
...@@ -214,9 +220,14 @@ _XkbGetConverters(const char *encoding_name, XkbConverters *cvt_rtrn) ...@@ -214,9 +220,14 @@ _XkbGetConverters(const char *encoding_name, XkbConverters *cvt_rtrn)
*/ */
#define CHARSET_FILE "/usr/lib/X11/input/charsets" #define CHARSET_FILE "/usr/lib/X11/input/charsets"
static char *_XkbKnownLanguages = "c=ascii:da,de,en,es,fr,is,it,nl,no,pt,sv=iso8859-1:hu,pl,cs=iso8859-2:eo=iso8859-3:sp=iso8859-5:ar,ara=iso8859-6:el=iso8859-7:he=iso8859-8:tr=iso8859-9:lt,lv=iso8859-13:et,fi=iso8859-15:ru=koi8-r:uk=koi8-u:th,th_TH,th_TH.iso8859-11=iso8859-11:th_TH.TIS620=tis620:hy=armscii-8:vi=tcvn-5712:ka=georgian-academy:be,bg=microsoft-cp1251"; static char *_XkbKnownLanguages =
"c=ascii:da,de,en,es,fr,is,it,nl,no,pt,sv=iso8859-1:hu,pl,cs=iso8859-2:"
char * "eo=iso8859-3:sp=iso8859-5:ar,ara=iso8859-6:el=iso8859-7:he=iso8859-8:"
"tr=iso8859-9:lt,lv=iso8859-13:et,fi=iso8859-15:ru=koi8-r:uk=koi8-u:"
"th,th_TH,th_TH.iso8859-11=iso8859-11:th_TH.TIS620=tis620:hy=armscii-8:"
"vi=tcvn-5712:ka=georgian-academy:be,bg=microsoft-cp1251";
char *
_XkbGetCharset(void) _XkbGetCharset(void)
{ {
/* /*
...@@ -225,49 +236,51 @@ _XkbGetCharset(void) ...@@ -225,49 +236,51 @@ _XkbGetCharset(void)
*/ */
static char buf[100] = { 0 }; static char buf[100] = { 0 };
char lang[256]; char lang[256];
char *start,*tmp,*end,*next,*set; char *start, *tmp, *end, *next, *set;
char *country,*charset; char *country, *charset;
char *locale; char *locale;
tmp = getenv( "_XKB_CHARSET" ); tmp = getenv("_XKB_CHARSET");
if ( tmp ) if (tmp)
return tmp; return tmp;
locale = setlocale(LC_CTYPE,NULL); locale = setlocale(LC_CTYPE, NULL);
if ( locale == NULL ) if (locale == NULL)
return NULL; return NULL;
if (strlen(locale) >= sizeof(lang)) if (strlen(locale) >= sizeof(lang))
return NULL; return NULL;
for (tmp = lang; *tmp = *locale++; tmp++) { for (tmp = lang; *tmp = *locale++; tmp++) {
if (isupper(*tmp)) if (isupper(*tmp))
*tmp = tolower(*tmp); *tmp = tolower(*tmp);
} }
country = strchr( lang, '_'); country = strchr(lang, '_');
if ( country ) { if (country) {
*country++ = '\0'; *country++ = '\0';
charset = strchr( country, '.' ); charset = strchr(country, '.');
if ( charset ) *charset++ = '\0'; if (charset)
if ( charset ) { *charset++ = '\0';
strncpy(buf,charset,99); if (charset) {
buf[99] = '\0'; strncpy(buf, charset, 99);
return buf; buf[99] = '\0';
} return buf;
}
} }
else { else {
charset = NULL; charset = NULL;
} }
if ((tmp = getenv("_XKB_LOCALE_CHARSETS"))!=NULL) { if ((tmp = getenv("_XKB_LOCALE_CHARSETS")) != NULL) {
start = _XkbAlloc(strlen(tmp) + 1); start = _XkbAlloc(strlen(tmp) + 1);
strcpy(start, tmp); strcpy(start, tmp);
tmp = start; tmp = start;
} else { }
struct stat sbuf; else {
FILE *file; struct stat sbuf;
FILE *file;
#ifndef __UNIXOS2__ #ifndef __UNIXOS2__
char *cf = CHARSET_FILE; char *cf = CHARSET_FILE;
#else #else
char *cf = __XOS2RedirRoot(CHARSET_FILE); char *cf = __XOS2RedirRoot(CHARSET_FILE);
#endif #endif
...@@ -276,62 +289,61 @@ _XkbGetCharset(void) ...@@ -276,62 +289,61 @@ _XkbGetCharset(void)
# define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG) # define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
#endif #endif
if ( (stat(cf,&sbuf)==0) && S_ISREG(sbuf.st_mode) && if ((stat(cf, &sbuf) == 0) && S_ISREG(sbuf.st_mode) &&
(file = fopen(cf,"r")) ) { (file = fopen(cf, "r"))) {
tmp = _XkbAlloc(sbuf.st_size+1); tmp = _XkbAlloc(sbuf.st_size + 1);
if (tmp!=NULL) { if (tmp != NULL) {
sbuf.st_size = (long)fread(tmp,1,sbuf.st_size,file); sbuf.st_size = (long) fread(tmp, 1, sbuf.st_size, file);
tmp[sbuf.st_size] = '\0'; tmp[sbuf.st_size] = '\0';
} }
fclose(file); fclose(file);
} }
} }
if ( tmp == NULL ) { if (tmp == NULL) {
tmp = _XkbAlloc(strlen(_XkbKnownLanguages) + 1); tmp = _XkbAlloc(strlen(_XkbKnownLanguages) + 1);
if (!tmp) if (!tmp)
return NULL; return NULL;
strcpy(tmp, _XkbKnownLanguages); strcpy(tmp, _XkbKnownLanguages);
} }
start = tmp; start = tmp;
do { do {
if ( (set=strchr(tmp,'=')) == NULL ) if ((set = strchr(tmp, '=')) == NULL)
break; break;
*set++ = '\0'; *set++ = '\0';
if ( (next=strchr(set,':')) != NULL ) if ((next = strchr(set, ':')) != NULL)
*next++ = '\0'; *next++ = '\0';
while ( tmp && *tmp ) { while (tmp && *tmp) {
if ( (end=strchr(tmp,',')) != NULL ) if ((end = strchr(tmp, ',')) != NULL)
*end++ = '\0'; *end++ = '\0';
if ( Strcmp( tmp, lang ) == 0 ) { if (Strcmp(tmp, lang) == 0) {
strncpy(buf,set,100); strncpy(buf, set, 100);
buf[99] = '\0'; buf[99] = '\0';
Xfree(start); Xfree(start);
return buf; return buf;
} }
tmp = end; tmp = end;
} }
tmp = next; tmp = next;
} while ( tmp && *tmp ); } while (tmp && *tmp);
Xfree(start); Xfree(start);
return NULL; return NULL;
} }
#else #else
char * char *
_XkbGetCharset(void) _XkbGetCharset(void)
{ {
char *tmp; char *tmp;
XLCd lcd; XLCd lcd;
tmp = getenv( "_XKB_CHARSET" ); tmp = getenv("_XKB_CHARSET");
if ( tmp ) if (tmp)
return tmp; return tmp;
lcd = _XlcCurrentLC(); lcd = _XlcCurrentLC();
if ( lcd ) if (lcd)
return XLC_PUBLIC(lcd,encoding_name); return XLC_PUBLIC(lcd, encoding_name);
return NULL; return NULL;
} }
#endif #endif
...@@ -37,68 +37,73 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. ...@@ -37,68 +37,73 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
/***====================================================================***/ /***====================================================================***/
extern void extern void
XkbNoteDeviceChanges( XkbDeviceChangesPtr old, XkbNoteDeviceChanges(XkbDeviceChangesPtr old,
XkbExtensionDeviceNotifyEvent * new, XkbExtensionDeviceNotifyEvent *new,
unsigned int wanted) unsigned int wanted)
{ {
if ((!old)||(!new)||(!wanted)||((new->reason&wanted)==0)) if ((!old) || (!new) || (!wanted) || ((new->reason & wanted) == 0))
return; return;
if ((wanted&new->reason)&XkbXI_ButtonActionsMask) { if ((wanted & new->reason) & XkbXI_ButtonActionsMask) {
if (old->changed&XkbXI_ButtonActionsMask) { if (old->changed & XkbXI_ButtonActionsMask) {
int first,last,newLast; int first, last, newLast;
if (new->first_btn<old->first_btn)
first= new->first_btn; if (new->first_btn < old->first_btn)
else first= old->first_btn; first = new->first_btn;
last= old->first_btn+old->num_btns-1; else
newLast= new->first_btn+new->num_btns-1; first = old->first_btn;
if (newLast>last) last = old->first_btn + old->num_btns - 1;
last= newLast; newLast = new->first_btn + new->num_btns - 1;
old->first_btn= first; if (newLast > last)
old->num_btns= (last-first)+1; last = newLast;
} old->first_btn = first;
else { old->num_btns = (last - first) + 1;
old->changed|= XkbXI_ButtonActionsMask; }
old->first_btn= new->first_btn; else {
old->num_btns= new->num_btns; old->changed |= XkbXI_ButtonActionsMask;
} old->first_btn = new->first_btn;
old->num_btns = new->num_btns;
}
} }
if ((wanted&new->reason)&XkbXI_IndicatorsMask) { if ((wanted & new->reason) & XkbXI_IndicatorsMask) {
XkbDeviceLedChangesPtr this; XkbDeviceLedChangesPtr this;
if (old->changed&XkbXI_IndicatorsMask) {
XkbDeviceLedChangesPtr found; if (old->changed & XkbXI_IndicatorsMask) {
found= NULL; XkbDeviceLedChangesPtr found;
for (this= &old->leds;this&&(!found);this=this->next) {
if ((this->led_class==new->led_class)&& found = NULL;
(this->led_id==new->led_id)) { for (this = &old->leds; this && (!found); this = this->next) {
found= this; if ((this->led_class == new->led_class) &&
} (this->led_id == new->led_id)) {
} found = this;
if (!found) { }
found= _XkbTypedCalloc(1,XkbDeviceLedChangesRec); }
if (!found) if (!found) {
return; found = _XkbTypedCalloc(1, XkbDeviceLedChangesRec);
found->next= old->leds.next; if (!found)
found->led_class= new->led_class; return;
found->led_id= new->led_id; found->next = old->leds.next;
old->leds.next= found; found->led_class = new->led_class;
} found->led_id = new->led_id;
if ((wanted&new->reason)&XkbXI_IndicatorNamesMask) old->leds.next = found;
found->defined= new->leds_defined; }
} if ((wanted & new->reason) & XkbXI_IndicatorNamesMask)
else { found->defined = new->leds_defined;
old->changed|= ((wanted&new->reason)&XkbXI_IndicatorsMask); }
old->leds.led_class= new->led_class; else {
old->leds.led_id= new->led_id; old->changed |= ((wanted & new->reason) & XkbXI_IndicatorsMask);
old->leds.defined= new->leds_defined; old->leds.led_class = new->led_class;
if (old->leds.next) { old->leds.led_id = new->led_id;
XkbDeviceLedChangesPtr next; old->leds.defined = new->leds_defined;
for (this=old->leds.next;this;this=next) { if (old->leds.next) {
next= this->next; XkbDeviceLedChangesPtr next;
_XkbFree(this);
} for (this = old->leds.next; this; this = next) {
old->leds.next= NULL; next = this->next;
} _XkbFree(this);
} }
old->leds.next = NULL;
}
}
} }
return; return;
} }
...@@ -106,162 +111,168 @@ XkbNoteDeviceChanges( XkbDeviceChangesPtr old, ...@@ -106,162 +111,168 @@ XkbNoteDeviceChanges( XkbDeviceChangesPtr old,
/***====================================================================***/ /***====================================================================***/
static Status static Status
_XkbReadDeviceLedInfo( XkbReadBufferPtr buf, _XkbReadDeviceLedInfo(XkbReadBufferPtr buf,
unsigned present, unsigned present,
XkbDeviceInfoPtr devi) XkbDeviceInfoPtr devi)
{ {
register unsigned i,bit; register unsigned i, bit;
XkbDeviceLedInfoPtr devli; XkbDeviceLedInfoPtr devli;
xkbDeviceLedsWireDesc * wireli; xkbDeviceLedsWireDesc *wireli;
wireli= _XkbGetTypedRdBufPtr(buf,1,xkbDeviceLedsWireDesc); wireli = _XkbGetTypedRdBufPtr(buf, 1, xkbDeviceLedsWireDesc);
if (!wireli) if (!wireli)
return BadLength; return BadLength;
devli= XkbAddDeviceLedInfo(devi,wireli->ledClass,wireli->ledID); devli = XkbAddDeviceLedInfo(devi, wireli->ledClass, wireli->ledID);
if (!devli) if (!devli)
return BadAlloc; return BadAlloc;
devli->phys_indicators= wireli->physIndicators; devli->phys_indicators = wireli->physIndicators;
if (present&XkbXI_IndicatorStateMask) if (present & XkbXI_IndicatorStateMask)
devli->state= wireli->state; devli->state = wireli->state;
if (present&XkbXI_IndicatorNamesMask) { if (present & XkbXI_IndicatorNamesMask) {
devli->names_present= wireli->namesPresent; devli->names_present = wireli->namesPresent;
if (devli->names_present) { if (devli->names_present) {
for (i=0,bit=1;i<XkbNumIndicators;i++,bit<<=1) { for (i = 0, bit = 1; i < XkbNumIndicators; i++, bit <<= 1) {
if (wireli->namesPresent&bit) { if (wireli->namesPresent & bit) {
if (!_XkbCopyFromReadBuffer(buf,(char *)&devli->names[i],4)) if (!_XkbCopyFromReadBuffer(buf,
return BadLength; (char *) &devli->names[i], 4))
} return BadLength;
} }
} }
}
} }
if (present&XkbXI_IndicatorMapsMask) { if (present & XkbXI_IndicatorMapsMask) {
devli->maps_present= wireli->mapsPresent; devli->maps_present = wireli->mapsPresent;
if (devli->maps_present) { if (devli->maps_present) {
XkbIndicatorMapPtr im; XkbIndicatorMapPtr im;
xkbIndicatorMapWireDesc * wireim; xkbIndicatorMapWireDesc *wireim;
for (i=0,bit=1;i<XkbNumIndicators;i++,bit<<=1) {
if (wireli->mapsPresent&bit) { for (i = 0, bit = 1; i < XkbNumIndicators; i++, bit <<= 1) {
wireim= _XkbGetTypedRdBufPtr(buf,1,xkbIndicatorMapWireDesc); if (wireli->mapsPresent & bit) {
if (!wireim) wireim =
return BadAlloc; _XkbGetTypedRdBufPtr(buf, 1, xkbIndicatorMapWireDesc);
im= &devli->maps[i]; if (!wireim)
im->flags= wireim->flags; return BadAlloc;
im->which_groups= wireim->whichGroups; im = &devli->maps[i];
im->groups= wireim->groups; im->flags = wireim->flags;
im->which_mods= wireim->whichMods; im->which_groups = wireim->whichGroups;
im->mods.mask= wireim->mods; im->groups = wireim->groups;
im->mods.real_mods= wireim->realMods; im->which_mods = wireim->whichMods;
im->mods.vmods= wireim->virtualMods; im->mods.mask = wireim->mods;
im->ctrls= wireim->ctrls; im->mods.real_mods = wireim->realMods;
} im->mods.vmods = wireim->virtualMods;
} im->ctrls = wireim->ctrls;
} }
}
}
} }
return Success; return Success;
} }
static Status static Status
_XkbReadGetDeviceInfoReply( Display * dpy, _XkbReadGetDeviceInfoReply(Display *dpy,
xkbGetDeviceInfoReply * rep, xkbGetDeviceInfoReply *rep,
XkbDeviceInfoPtr devi) XkbDeviceInfoPtr devi)
{ {
XkbReadBufferRec buf; XkbReadBufferRec buf;
XkbAction * act; XkbAction *act;
int tmp; int tmp;
if (!_XkbInitReadBuffer(dpy,&buf,(int)rep->length*4)) if (!_XkbInitReadBuffer(dpy, &buf, (int) rep->length * 4))
return BadAlloc; return BadAlloc;
if ((rep->totalBtns>0)&&(rep->totalBtns!=devi->num_btns)) { if ((rep->totalBtns > 0) && (rep->totalBtns != devi->num_btns)) {
tmp= XkbResizeDeviceButtonActions(devi,rep->totalBtns); tmp = XkbResizeDeviceButtonActions(devi, rep->totalBtns);
if (tmp!=Success) if (tmp != Success)
return tmp; return tmp;
} }
if (rep->nBtnsWanted>0) { if (rep->nBtnsWanted > 0) {
if (((unsigned short) rep->firstBtnWanted + rep->nBtnsWanted) if (((unsigned short) rep->firstBtnWanted + rep->nBtnsWanted)
>= devi->num_btns) >= devi->num_btns)
goto BAILOUT; goto BAILOUT;
act= &devi->btn_acts[rep->firstBtnWanted]; act = &devi->btn_acts[rep->firstBtnWanted];
bzero((char *)act,(rep->nBtnsWanted*sizeof(XkbAction))); bzero((char *) act, (rep->nBtnsWanted * sizeof(XkbAction)));
} }
if (devi->name!=NULL) if (devi->name != NULL)
_XkbFree(devi->name); _XkbFree(devi->name);
if (!_XkbGetReadBufferCountedString(&buf,&devi->name)) if (!_XkbGetReadBufferCountedString(&buf, &devi->name))
goto BAILOUT; goto BAILOUT;
if (rep->nBtnsRtrn>0) { if (rep->nBtnsRtrn > 0) {
int size; int size;
if (((unsigned short) rep->firstBtnRtrn + rep->nBtnsRtrn)
>= devi->num_btns) if (((unsigned short) rep->firstBtnRtrn + rep->nBtnsRtrn)
goto BAILOUT; >= devi->num_btns)
act= &devi->btn_acts[rep->firstBtnRtrn]; goto BAILOUT;
size= rep->nBtnsRtrn*SIZEOF(xkbActionWireDesc); act = &devi->btn_acts[rep->firstBtnRtrn];
if (!_XkbCopyFromReadBuffer(&buf,(char *)act,size)) size = rep->nBtnsRtrn * SIZEOF(xkbActionWireDesc);
goto BAILOUT; if (!_XkbCopyFromReadBuffer(&buf, (char *) act, size))
goto BAILOUT;
} }
if (rep->nDeviceLedFBs>0) { if (rep->nDeviceLedFBs > 0) {
register int i; register int i;
for (i=0;i<rep->nDeviceLedFBs;i++) {
if ((tmp= _XkbReadDeviceLedInfo(&buf,rep->present,devi))!=Success) for (i = 0; i < rep->nDeviceLedFBs; i++) {
return tmp; if ((tmp = _XkbReadDeviceLedInfo(&buf, rep->present, devi))
} != Success)
return tmp;
}
} }
tmp= _XkbFreeReadBuffer(&buf); tmp = _XkbFreeReadBuffer(&buf);
if (tmp) if (tmp)
fprintf(stderr,"GetDeviceInfo! Bad length (%d extra bytes)\n",tmp); fprintf(stderr, "GetDeviceInfo! Bad length (%d extra bytes)\n", tmp);
if (tmp || buf.error) if (tmp || buf.error)
return BadLength; return BadLength;
return Success; return Success;
BAILOUT: BAILOUT:
_XkbFreeReadBuffer(&buf); _XkbFreeReadBuffer(&buf);
return BadLength; return BadLength;
} }
XkbDeviceInfoPtr XkbDeviceInfoPtr
XkbGetDeviceInfo( Display * dpy, XkbGetDeviceInfo(Display *dpy,
unsigned which, unsigned which,
unsigned deviceSpec, unsigned deviceSpec,
unsigned class, unsigned class,
unsigned id) unsigned id)
{ {
register xkbGetDeviceInfoReq * req; register xkbGetDeviceInfoReq *req;
xkbGetDeviceInfoReply rep; xkbGetDeviceInfoReply rep;
Status status; Status status;
XkbDeviceInfoPtr devi; XkbDeviceInfoPtr devi;
if ((dpy->flags & XlibDisplayNoXkb) || if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return NULL; return NULL;
LockDisplay(dpy); LockDisplay(dpy);
GetReq(kbGetDeviceInfo, req); GetReq(kbGetDeviceInfo, req);
req->reqType = dpy->xkb_info->codes->major_opcode; req->reqType = dpy->xkb_info->codes->major_opcode;
req->xkbReqType = X_kbGetDeviceInfo; req->xkbReqType = X_kbGetDeviceInfo;
req->deviceSpec = deviceSpec; req->deviceSpec = deviceSpec;
req->wanted= which; req->wanted = which;
req->allBtns= ((which&XkbXI_ButtonActionsMask)!=0); req->allBtns = ((which & XkbXI_ButtonActionsMask) != 0);
req->firstBtn= req->nBtns= 0; req->firstBtn = req->nBtns = 0;
req->ledClass= class; req->ledClass = class;
req->ledID= id; req->ledID = id;
if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) {
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
return NULL; return NULL;
} }
devi= XkbAllocDeviceInfo(rep.deviceID,rep.totalBtns,rep.nDeviceLedFBs); devi = XkbAllocDeviceInfo(rep.deviceID, rep.totalBtns, rep.nDeviceLedFBs);
if (devi) { if (devi) {
devi->supported= rep.supported; devi->supported = rep.supported;
devi->unsupported= rep.unsupported; devi->unsupported = rep.unsupported;
devi->type= rep.devType; devi->type = rep.devType;
devi->has_own_state= rep.hasOwnState; devi->has_own_state = rep.hasOwnState;
devi->dflt_kbd_fb = rep.dfltKbdFB; devi->dflt_kbd_fb = rep.dfltKbdFB;
devi->dflt_led_fb = rep.dfltLedFB; devi->dflt_led_fb = rep.dfltLedFB;
status= _XkbReadGetDeviceInfoReply(dpy,&rep,devi); status = _XkbReadGetDeviceInfoReply(dpy, &rep, devi);
if (status!=Success) { if (status != Success) {
XkbFreeDeviceInfo(devi,XkbXI_AllDeviceFeaturesMask,True); XkbFreeDeviceInfo(devi, XkbXI_AllDeviceFeaturesMask, True);
devi= NULL; devi = NULL;
} }
} }
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
...@@ -269,59 +280,61 @@ XkbGetDeviceInfo( Display * dpy, ...@@ -269,59 +280,61 @@ XkbGetDeviceInfo( Display * dpy,
} }
Status Status
XkbGetDeviceInfoChanges( Display * dpy, XkbGetDeviceInfoChanges(Display *dpy,
XkbDeviceInfoPtr devi, XkbDeviceInfoPtr devi,
XkbDeviceChangesPtr changes) XkbDeviceChangesPtr changes)
{ {
register xkbGetDeviceInfoReq * req; register xkbGetDeviceInfoReq *req;
xkbGetDeviceInfoReply rep; xkbGetDeviceInfoReply rep;
Status status; Status status;
if ((dpy->flags & XlibDisplayNoXkb) || if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return BadMatch; return BadMatch;
if ((changes->changed&XkbXI_AllDeviceFeaturesMask)==0) if ((changes->changed & XkbXI_AllDeviceFeaturesMask) == 0)
return Success; return Success;
changes->changed&= ~XkbXI_AllDeviceFeaturesMask; changes->changed &= ~XkbXI_AllDeviceFeaturesMask;
status= Success; status = Success;
LockDisplay(dpy); LockDisplay(dpy);
while ((changes->changed)&&(status==Success)) { while ((changes->changed) && (status == Success)) {
GetReq(kbGetDeviceInfo, req); GetReq(kbGetDeviceInfo, req);
req->reqType = dpy->xkb_info->codes->major_opcode; req->reqType = dpy->xkb_info->codes->major_opcode;
req->xkbReqType = X_kbGetDeviceInfo; req->xkbReqType = X_kbGetDeviceInfo;
req->deviceSpec = devi->device_spec; req->deviceSpec = devi->device_spec;
req->wanted= changes->changed; req->wanted = changes->changed;
req->allBtns= False; req->allBtns = False;
if (changes->changed&XkbXI_ButtonActionsMask) { if (changes->changed & XkbXI_ButtonActionsMask) {
req->firstBtn= changes->first_btn; req->firstBtn = changes->first_btn;
req->nBtns= changes->num_btns; req->nBtns = changes->num_btns;
changes->changed&= ~XkbXI_ButtonActionsMask; changes->changed &= ~XkbXI_ButtonActionsMask;
} }
else req->firstBtn= req->nBtns= 0; else
if (changes->changed&XkbXI_IndicatorsMask) { req->firstBtn = req->nBtns = 0;
req->ledClass= changes->leds.led_class; if (changes->changed & XkbXI_IndicatorsMask) {
req->ledID= changes->leds.led_id; req->ledClass = changes->leds.led_class;
if (changes->leds.next==NULL) req->ledID = changes->leds.led_id;
changes->changed&= ~XkbXI_IndicatorsMask; if (changes->leds.next == NULL)
else { changes->changed &= ~XkbXI_IndicatorsMask;
XkbDeviceLedChangesPtr next; else {
next= changes->leds.next; XkbDeviceLedChangesPtr next;
changes->leds= *next;
_XkbFree(next); next = changes->leds.next;
} changes->leds = *next;
} _XkbFree(next);
else { }
req->ledClass= XkbDfltXIClass; }
req->ledID= XkbDfltXIId; else {
} req->ledClass = XkbDfltXIClass;
if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { req->ledID = XkbDfltXIId;
status= BadLength; }
break; if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) {
} status = BadLength;
devi->supported|= rep.supported; break;
devi->unsupported|= rep.unsupported; }
devi->type= rep.devType; devi->supported |= rep.supported;
status= _XkbReadGetDeviceInfoReply(dpy,&rep,devi); devi->unsupported |= rep.unsupported;
devi->type = rep.devType;
status = _XkbReadGetDeviceInfoReply(dpy, &rep, devi);
} }
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
...@@ -329,83 +342,84 @@ XkbGetDeviceInfoChanges( Display * dpy, ...@@ -329,83 +342,84 @@ XkbGetDeviceInfoChanges( Display * dpy,
} }
Status Status
XkbGetDeviceButtonActions( Display * dpy, XkbGetDeviceButtonActions(Display *dpy,
XkbDeviceInfoPtr devi, XkbDeviceInfoPtr devi,
Bool all, Bool all,
unsigned int first, unsigned int first,
unsigned int num) unsigned int num)
{ {
register xkbGetDeviceInfoReq * req; register xkbGetDeviceInfoReq *req;
xkbGetDeviceInfoReply rep; xkbGetDeviceInfoReply rep;
Status status; Status status;
if ((dpy->flags & XlibDisplayNoXkb) || if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return BadMatch; return BadMatch;
if (!devi) if (!devi)
return BadValue; return BadValue;
LockDisplay(dpy); LockDisplay(dpy);
GetReq(kbGetDeviceInfo, req); GetReq(kbGetDeviceInfo, req);
req->reqType = dpy->xkb_info->codes->major_opcode; req->reqType = dpy->xkb_info->codes->major_opcode;
req->xkbReqType = X_kbGetDeviceInfo; req->xkbReqType = X_kbGetDeviceInfo;
req->deviceSpec = devi->device_spec; req->deviceSpec = devi->device_spec;
req->wanted= XkbXI_ButtonActionsMask; req->wanted = XkbXI_ButtonActionsMask;
req->allBtns= all; req->allBtns = all;
req->firstBtn= first; req->firstBtn = first;
req->nBtns= num; req->nBtns = num;
req->ledClass= XkbDfltXIClass; req->ledClass = XkbDfltXIClass;
req->ledID= XkbDfltXIId; req->ledID = XkbDfltXIId;
if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) {
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
return BadLength; return BadLength;
} }
devi->type= rep.devType; devi->type = rep.devType;
devi->supported= rep.supported; devi->supported = rep.supported;
devi->unsupported= rep.unsupported; devi->unsupported = rep.unsupported;
status= _XkbReadGetDeviceInfoReply(dpy,&rep,devi); status = _XkbReadGetDeviceInfoReply(dpy, &rep, devi);
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
return status; return status;
} }
Status Status
XkbGetDeviceLedInfo( Display * dpy, XkbGetDeviceLedInfo(Display *dpy,
XkbDeviceInfoPtr devi, XkbDeviceInfoPtr devi,
unsigned int ledClass, unsigned int ledClass,
unsigned int ledId, unsigned int ledId,
unsigned int which) unsigned int which)
{ {
register xkbGetDeviceInfoReq * req; register xkbGetDeviceInfoReq *req;
xkbGetDeviceInfoReply rep; xkbGetDeviceInfoReply rep;
Status status; Status status;
if ((dpy->flags & XlibDisplayNoXkb) || if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return BadMatch; return BadMatch;
if (((which&XkbXI_IndicatorsMask)==0)||(which&(~XkbXI_IndicatorsMask))) if (((which & XkbXI_IndicatorsMask) == 0) ||
return BadMatch; (which & (~XkbXI_IndicatorsMask)))
return BadMatch;
if (!devi) if (!devi)
return BadValue; return BadValue;
LockDisplay(dpy); LockDisplay(dpy);
GetReq(kbGetDeviceInfo, req); GetReq(kbGetDeviceInfo, req);
req->reqType = dpy->xkb_info->codes->major_opcode; req->reqType = dpy->xkb_info->codes->major_opcode;
req->xkbReqType = X_kbGetDeviceInfo; req->xkbReqType = X_kbGetDeviceInfo;
req->deviceSpec = devi->device_spec; req->deviceSpec = devi->device_spec;
req->wanted= which; req->wanted = which;
req->allBtns= False; req->allBtns = False;
req->firstBtn= req->nBtns= 0; req->firstBtn = req->nBtns = 0;
req->ledClass= ledClass; req->ledClass = ledClass;
req->ledID= ledId; req->ledID = ledId;
if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) {
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
return BadLength; return BadLength;
} }
devi->type= rep.devType; devi->type = rep.devType;
devi->supported= rep.supported; devi->supported = rep.supported;
devi->unsupported= rep.unsupported; devi->unsupported = rep.unsupported;
status= _XkbReadGetDeviceInfoReply(dpy,&rep,devi); status = _XkbReadGetDeviceInfoReply(dpy, &rep, devi);
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
return status; return status;
...@@ -414,297 +428,303 @@ XkbGetDeviceLedInfo( Display * dpy, ...@@ -414,297 +428,303 @@ XkbGetDeviceLedInfo( Display * dpy,
/***====================================================================***/ /***====================================================================***/
typedef struct _LedInfoStuff { typedef struct _LedInfoStuff {
Bool used; Bool used;
XkbDeviceLedInfoPtr devli; XkbDeviceLedInfoPtr devli;
} LedInfoStuff; } LedInfoStuff;
typedef struct _SetLedStuff { typedef struct _SetLedStuff {
unsigned wanted; unsigned wanted;
int num_info; int num_info;
int dflt_class; int dflt_class;
LedInfoStuff * dflt_kbd_fb; LedInfoStuff *dflt_kbd_fb;
LedInfoStuff * dflt_led_fb; LedInfoStuff *dflt_led_fb;
LedInfoStuff * info; LedInfoStuff *info;
} SetLedStuff; } SetLedStuff;
static void static void
_InitLedStuff(SetLedStuff *stuff,unsigned wanted,XkbDeviceInfoPtr devi) _InitLedStuff(SetLedStuff *stuff, unsigned wanted, XkbDeviceInfoPtr devi)
{ {
int i; int i;
register XkbDeviceLedInfoPtr devli; register XkbDeviceLedInfoPtr devli;
bzero(stuff,sizeof(SetLedStuff)); bzero(stuff, sizeof(SetLedStuff));
stuff->wanted= wanted; stuff->wanted = wanted;
stuff->dflt_class= XkbXINone; stuff->dflt_class = XkbXINone;
if ((devi->num_leds<1)||((wanted&XkbXI_IndicatorsMask)==0)) if ((devi->num_leds < 1) || ((wanted & XkbXI_IndicatorsMask) == 0))
return; return;
stuff->info= _XkbTypedCalloc(devi->num_leds,LedInfoStuff); stuff->info = _XkbTypedCalloc(devi->num_leds, LedInfoStuff);
if (!stuff->info) if (!stuff->info)
return; return;
stuff->num_info= devi->num_leds; stuff->num_info = devi->num_leds;
for (devli=&devi->leds[0],i=0;i<devi->num_leds;i++,devli++) { for (devli = &devi->leds[0], i = 0; i < devi->num_leds; i++, devli++) {
stuff->info[i].devli= devli; stuff->info[i].devli = devli;
if (devli->led_class==KbdFeedbackClass) { if (devli->led_class == KbdFeedbackClass) {
stuff->dflt_class= KbdFeedbackClass; stuff->dflt_class = KbdFeedbackClass;
if (stuff->dflt_kbd_fb==NULL) if (stuff->dflt_kbd_fb == NULL)
stuff->dflt_kbd_fb= &stuff->info[i]; stuff->dflt_kbd_fb = &stuff->info[i];
} }
else if (devli->led_class==LedFeedbackClass) { else if (devli->led_class == LedFeedbackClass) {
if (stuff->dflt_class==XkbXINone) if (stuff->dflt_class == XkbXINone)
stuff->dflt_class= LedFeedbackClass; stuff->dflt_class = LedFeedbackClass;
if (stuff->dflt_led_fb==NULL) if (stuff->dflt_led_fb == NULL)
stuff->dflt_led_fb= &stuff->info[i]; stuff->dflt_led_fb = &stuff->info[i];
} }
} }
return; return;
} }
static void static void
_FreeLedStuff(SetLedStuff *stuff) _FreeLedStuff(SetLedStuff * stuff)
{ {
if ((stuff->num_info>0)&&(stuff->info!=NULL)) if ((stuff->num_info > 0) && (stuff->info != NULL))
_XkbFree(stuff->info); _XkbFree(stuff->info);
bzero(stuff,sizeof(SetLedStuff)); bzero(stuff, sizeof(SetLedStuff));
return; return;
} }
static int static int
_XkbSizeLedInfo(unsigned changed,XkbDeviceLedInfoPtr devli) _XkbSizeLedInfo(unsigned changed, XkbDeviceLedInfoPtr devli)
{ {
register int i,size; register int i, size;
register unsigned bit,namesNeeded,mapsNeeded; register unsigned bit, namesNeeded, mapsNeeded;
size= SIZEOF(xkbDeviceLedsWireDesc); size = SIZEOF(xkbDeviceLedsWireDesc);
namesNeeded= mapsNeeded= 0; namesNeeded = mapsNeeded = 0;
if (changed&XkbXI_IndicatorNamesMask) if (changed & XkbXI_IndicatorNamesMask)
namesNeeded= devli->names_present; namesNeeded = devli->names_present;
if (changed&XkbXI_IndicatorMapsMask) if (changed & XkbXI_IndicatorMapsMask)
mapsNeeded= devli->maps_present; mapsNeeded = devli->maps_present;
if ((namesNeeded)||(mapsNeeded)) { if ((namesNeeded) || (mapsNeeded)) {
for (i=0,bit=1;i<XkbNumIndicators;i++,bit<<=1) { for (i = 0, bit = 1; i < XkbNumIndicators; i++, bit <<= 1) {
if (namesNeeded&bit) if (namesNeeded & bit)
size+= 4; /* atoms are 4 bytes on the wire */ size += 4; /* atoms are 4 bytes on the wire */
if (mapsNeeded&bit) if (mapsNeeded & bit)
size+= SIZEOF(xkbIndicatorMapWireDesc); size += SIZEOF(xkbIndicatorMapWireDesc);
} }
} }
return size; return size;
} }
static Bool static Bool
_SizeMatches( SetLedStuff * stuff, _SizeMatches(SetLedStuff *stuff,
XkbDeviceLedChangesPtr changes, XkbDeviceLedChangesPtr changes,
int * sz_rtrn, int *sz_rtrn,
int * nleds_rtrn) int *nleds_rtrn)
{ {
int i,nMatch,class,id; int i, nMatch, class, id;
LedInfoStuff * linfo; LedInfoStuff *linfo;
Bool match; Bool match;
nMatch= 0; nMatch = 0;
class= changes->led_class; class = changes->led_class;
id= changes->led_id; id = changes->led_id;
if (class==XkbDfltXIClass) if (class == XkbDfltXIClass)
class= stuff->dflt_class; class = stuff->dflt_class;
for (i=0,linfo=&stuff->info[0];i<stuff->num_info;i++,linfo++) { for (i = 0, linfo = &stuff->info[0]; i < stuff->num_info; i++, linfo++) {
XkbDeviceLedInfoPtr devli; XkbDeviceLedInfoPtr devli;
LedInfoStuff * dflt; LedInfoStuff *dflt;
devli= linfo->devli; devli = linfo->devli;
match= ((class==devli->led_class)||(class==XkbAllXIClasses)); match = ((class == devli->led_class) || (class == XkbAllXIClasses));
if (devli->led_class==KbdFeedbackClass) dflt= stuff->dflt_kbd_fb; if (devli->led_class == KbdFeedbackClass)
else dflt= stuff->dflt_led_fb; dflt = stuff->dflt_kbd_fb;
match = (match && (id == devli->led_id)) || else
(id == XkbAllXIIds) || dflt = stuff->dflt_led_fb;
((id == XkbDfltXIId) && match = (match && (id == devli->led_id)) ||
(linfo == dflt)); (id == XkbAllXIIds) ||
if (match) { ((id == XkbDfltXIId) && (linfo == dflt));
if (!linfo->used) { if (match) {
*sz_rtrn+= _XkbSizeLedInfo(stuff->wanted,devli); if (!linfo->used) {
*nleds_rtrn+= 1; *sz_rtrn += _XkbSizeLedInfo(stuff->wanted, devli);
linfo->used= True; *nleds_rtrn += 1;
if ((class!=XkbAllXIClasses)&&(id!=XkbAllXIIds)) linfo->used = True;
return True; if ((class != XkbAllXIClasses) && (id != XkbAllXIIds))
} return True;
nMatch++; }
linfo->used= True; nMatch++;
} linfo->used = True;
}
} }
return (nMatch>0); return (nMatch > 0);
} }
/***====================================================================***/ /***====================================================================***/
static Status static Status
_XkbSetDeviceInfoSize( XkbDeviceInfoPtr devi, _XkbSetDeviceInfoSize(XkbDeviceInfoPtr devi,
XkbDeviceChangesPtr changes, XkbDeviceChangesPtr changes,
SetLedStuff * stuff, SetLedStuff *stuff,
int * sz_rtrn, int *sz_rtrn,
int * num_leds_rtrn) int *num_leds_rtrn)
{ {
*sz_rtrn= 0; *sz_rtrn = 0;
if ((changes->changed&XkbXI_ButtonActionsMask)&&(changes->num_btns>0)) { if ((changes->changed & XkbXI_ButtonActionsMask) && (changes->num_btns > 0)) {
if (!XkbXI_LegalDevBtn(devi,(changes->first_btn+changes->num_btns-1))) if (!XkbXI_LegalDevBtn
return BadMatch; (devi, (changes->first_btn + changes->num_btns - 1)))
*sz_rtrn+= changes->num_btns*SIZEOF(xkbActionWireDesc); return BadMatch;
*sz_rtrn += changes->num_btns * SIZEOF(xkbActionWireDesc);
} }
else { else {
changes->changed&= ~XkbXI_ButtonActionsMask; changes->changed &= ~XkbXI_ButtonActionsMask;
changes->first_btn= changes->num_btns= 0; changes->first_btn = changes->num_btns = 0;
} }
if ((changes->changed&XkbXI_IndicatorsMask)&& if ((changes->changed & XkbXI_IndicatorsMask) &&
XkbLegalXILedClass(changes->leds.led_class)) { XkbLegalXILedClass(changes->leds.led_class)) {
XkbDeviceLedChangesPtr leds; XkbDeviceLedChangesPtr leds;
for (leds=&changes->leds;leds!=NULL;leds= leds->next) { for (leds = &changes->leds; leds != NULL; leds = leds->next) {
if (!_SizeMatches(stuff,leds,sz_rtrn,num_leds_rtrn)) if (!_SizeMatches(stuff, leds, sz_rtrn, num_leds_rtrn))
return BadMatch; return BadMatch;
} }
} }
else { else {
changes->changed&= ~XkbXI_IndicatorsMask; changes->changed &= ~XkbXI_IndicatorsMask;
*num_leds_rtrn= 0; *num_leds_rtrn = 0;
} }
return Success; return Success;
} }
static char * static char *
_XkbWriteLedInfo(char *wire,unsigned changed,XkbDeviceLedInfoPtr devli) _XkbWriteLedInfo(char *wire, unsigned changed, XkbDeviceLedInfoPtr devli)
{ {
register int i; register int i;
register unsigned bit,namesNeeded,mapsNeeded; register unsigned bit, namesNeeded, mapsNeeded;
xkbDeviceLedsWireDesc * lwire; xkbDeviceLedsWireDesc *lwire;
namesNeeded= mapsNeeded= 0; namesNeeded = mapsNeeded = 0;
if (changed&XkbXI_IndicatorNamesMask) if (changed & XkbXI_IndicatorNamesMask)
namesNeeded= devli->names_present; namesNeeded = devli->names_present;
if (changed&XkbXI_IndicatorMapsMask) if (changed & XkbXI_IndicatorMapsMask)
mapsNeeded= devli->maps_present; mapsNeeded = devli->maps_present;
lwire= (xkbDeviceLedsWireDesc *)wire; lwire = (xkbDeviceLedsWireDesc *) wire;
lwire->ledClass= devli->led_class; lwire->ledClass = devli->led_class;
lwire->ledID= devli->led_id; lwire->ledID = devli->led_id;
lwire->namesPresent= namesNeeded; lwire->namesPresent = namesNeeded;
lwire->mapsPresent= mapsNeeded; lwire->mapsPresent = mapsNeeded;
lwire->physIndicators= devli->phys_indicators; lwire->physIndicators = devli->phys_indicators;
lwire->state= devli->state; lwire->state = devli->state;
wire= (char *)&lwire[1]; wire = (char *) &lwire[1];
if (namesNeeded) { if (namesNeeded) {
CARD32 *awire; CARD32 *awire;
awire= (CARD32 *)wire;
for (i=0,bit=1;i<XkbNumIndicators;i++,bit<<=1) { awire = (CARD32 *) wire;
if (namesNeeded&bit) { for (i = 0, bit = 1; i < XkbNumIndicators; i++, bit <<= 1) {
*awire= (CARD32)devli->names[i]; if (namesNeeded & bit) {
awire++; *awire = (CARD32) devli->names[i];
} awire++;
} }
wire= (char *)awire; }
wire = (char *) awire;
} }
if (mapsNeeded) { if (mapsNeeded) {
xkbIndicatorMapWireDesc *mwire; xkbIndicatorMapWireDesc *mwire;
mwire= (xkbIndicatorMapWireDesc *)wire; mwire = (xkbIndicatorMapWireDesc *) wire;
for (i=0,bit=1;i<XkbNumIndicators;i++,bit<<=1) { for (i = 0, bit = 1; i < XkbNumIndicators; i++, bit <<= 1) {
if (mapsNeeded&bit) { if (mapsNeeded & bit) {
XkbIndicatorMapPtr map; XkbIndicatorMapPtr map;
map= &devli->maps[i];
mwire->flags= map->flags; map = &devli->maps[i];
mwire->whichGroups= map->which_groups; mwire->flags = map->flags;
mwire->groups= map->groups; mwire->whichGroups = map->which_groups;
mwire->whichMods= map->which_mods; mwire->groups = map->groups;
mwire->mods= map->mods.mask; mwire->whichMods = map->which_mods;
mwire->realMods= map->mods.real_mods; mwire->mods = map->mods.mask;
mwire->virtualMods= map->mods.vmods; mwire->realMods = map->mods.real_mods;
mwire->ctrls= map->ctrls; mwire->virtualMods = map->mods.vmods;
mwire++; mwire->ctrls = map->ctrls;
} mwire++;
} }
wire= (char *)mwire; }
wire = (char *) mwire;
} }
return wire; return wire;
} }
static int static int
_XkbWriteSetDeviceInfo( char * wire, _XkbWriteSetDeviceInfo(char *wire,
XkbDeviceChangesPtr changes, XkbDeviceChangesPtr changes,
SetLedStuff * stuff, SetLedStuff *stuff,
XkbDeviceInfoPtr devi) XkbDeviceInfoPtr devi)
{ {
char *start; char *start;
start= wire; start = wire;
if (changes->changed&XkbXI_ButtonActionsMask) { if (changes->changed & XkbXI_ButtonActionsMask) {
int size; int size;
size= changes->num_btns*SIZEOF(xkbActionWireDesc);
memcpy(wire,(char *)&devi->btn_acts[changes->first_btn],size); size = changes->num_btns * SIZEOF(xkbActionWireDesc);
wire+= size; memcpy(wire, (char *) &devi->btn_acts[changes->first_btn], size);
wire += size;
} }
if (changes->changed&XkbXI_IndicatorsMask) { if (changes->changed & XkbXI_IndicatorsMask) {
register int i; register int i;
register LedInfoStuff *linfo; register LedInfoStuff *linfo;
for (i=0,linfo=&stuff->info[0];i<stuff->num_info;i++,linfo++) { for (i = 0, linfo = &stuff->info[0]; i < stuff->num_info; i++, linfo++) {
if (linfo->used) { if (linfo->used) {
register char *new_wire; register char *new_wire;
new_wire= _XkbWriteLedInfo(wire,stuff->wanted,linfo->devli);
if (!new_wire) new_wire = _XkbWriteLedInfo(wire, stuff->wanted, linfo->devli);
return wire-start; if (!new_wire)
wire= new_wire; return wire - start;
} wire = new_wire;
} }
}
} }
return wire-start; return wire - start;
} }
Bool Bool
XkbSetDeviceInfo( Display * dpy, XkbSetDeviceInfo(Display *dpy, unsigned which, XkbDeviceInfoPtr devi)
unsigned which,
XkbDeviceInfoPtr devi)
{ {
register xkbSetDeviceInfoReq *req; register xkbSetDeviceInfoReq *req;
Status ok = 0; Status ok = 0;
int size,nLeds; int size, nLeds;
XkbInfoPtr xkbi; XkbInfoPtr xkbi;
XkbDeviceChangesRec changes; XkbDeviceChangesRec changes;
SetLedStuff lstuff; SetLedStuff lstuff;
if ((dpy->flags & XlibDisplayNoXkb) || if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return False; return False;
if ((!devi) || (which&(~XkbXI_AllDeviceFeaturesMask)) || if ((!devi) || (which & (~XkbXI_AllDeviceFeaturesMask)) ||
((which&XkbXI_ButtonActionsMask)&&(!XkbXI_DevHasBtnActs(devi)))|| ((which & XkbXI_ButtonActionsMask) && (!XkbXI_DevHasBtnActs(devi))) ||
((which&XkbXI_IndicatorsMask)&&(!XkbXI_DevHasLeds(devi)))) ((which & XkbXI_IndicatorsMask) && (!XkbXI_DevHasLeds(devi))))
return False; return False;
bzero((char *)&changes,sizeof(XkbDeviceChangesRec)); bzero((char *) &changes, sizeof(XkbDeviceChangesRec));
changes.changed= which; changes.changed = which;
changes.first_btn= 0; changes.first_btn = 0;
changes.num_btns= devi->num_btns; changes.num_btns = devi->num_btns;
changes.leds.led_class= XkbAllXIClasses; changes.leds.led_class = XkbAllXIClasses;
changes.leds.led_id= XkbAllXIIds; changes.leds.led_id = XkbAllXIIds;
changes.leds.defined= 0; changes.leds.defined = 0;
size= nLeds= 0; size = nLeds = 0;
_InitLedStuff(&lstuff,changes.changed,devi); _InitLedStuff(&lstuff, changes.changed, devi);
if (_XkbSetDeviceInfoSize(devi,&changes,&lstuff,&size,&nLeds)!=Success) if (_XkbSetDeviceInfoSize(devi, &changes, &lstuff, &size, &nLeds) !=
return False; Success)
return False;
LockDisplay(dpy); LockDisplay(dpy);
xkbi = dpy->xkb_info; xkbi = dpy->xkb_info;
GetReq(kbSetDeviceInfo, req); GetReq(kbSetDeviceInfo, req);
req->length+= size/4; req->length += size / 4;
req->reqType= xkbi->codes->major_opcode; req->reqType = xkbi->codes->major_opcode;
req->xkbReqType= X_kbSetDeviceInfo; req->xkbReqType = X_kbSetDeviceInfo;
req->deviceSpec= devi->device_spec; req->deviceSpec = devi->device_spec;
req->firstBtn= changes.first_btn; req->firstBtn = changes.first_btn;
req->nBtns= changes.num_btns; req->nBtns = changes.num_btns;
req->change= changes.changed; req->change = changes.changed;
req->nDeviceLedFBs= nLeds; req->nDeviceLedFBs = nLeds;
if (size>0) { if (size > 0) {
char * wire; char *wire;
BufAlloc(char *,wire,size);
ok= (wire!=NULL)&& BufAlloc(char *, wire, size);
(_XkbWriteSetDeviceInfo(wire,&changes,&lstuff,devi)==size); ok = (wire != NULL) &&
(_XkbWriteSetDeviceInfo(wire, &changes, &lstuff, devi) == size);
} }
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
...@@ -714,45 +734,47 @@ XkbSetDeviceInfo( Display * dpy, ...@@ -714,45 +734,47 @@ XkbSetDeviceInfo( Display * dpy,
} }
Bool Bool
XkbChangeDeviceInfo( Display * dpy, XkbChangeDeviceInfo(Display *dpy,
XkbDeviceInfoPtr devi, XkbDeviceInfoPtr devi,
XkbDeviceChangesPtr changes) XkbDeviceChangesPtr changes)
{ {
register xkbSetDeviceInfoReq *req; register xkbSetDeviceInfoReq *req;
Status ok = 0; Status ok = 0;
int size,nLeds; int size, nLeds;
XkbInfoPtr xkbi; XkbInfoPtr xkbi;
SetLedStuff lstuff; SetLedStuff lstuff;
if ((dpy->flags & XlibDisplayNoXkb) || if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return False; return False;
if ((!devi) || (changes->changed&(~XkbXI_AllDeviceFeaturesMask)) || if ((!devi) || (changes->changed & (~XkbXI_AllDeviceFeaturesMask)) ||
((changes->changed&XkbXI_ButtonActionsMask)&& ((changes->changed & XkbXI_ButtonActionsMask) &&
(!XkbXI_DevHasBtnActs(devi)))|| (!XkbXI_DevHasBtnActs(devi))) ||
((changes->changed&XkbXI_IndicatorsMask)&&(!XkbXI_DevHasLeds(devi)))) ((changes->changed & XkbXI_IndicatorsMask) &&
return False; (!XkbXI_DevHasLeds(devi))))
return False;
size= nLeds= 0;
_InitLedStuff(&lstuff,changes->changed,devi); size = nLeds = 0;
if (_XkbSetDeviceInfoSize(devi,changes,&lstuff,&size,&nLeds)!=Success) _InitLedStuff(&lstuff, changes->changed, devi);
return False; if (_XkbSetDeviceInfoSize(devi, changes, &lstuff, &size, &nLeds) != Success)
return False;
LockDisplay(dpy); LockDisplay(dpy);
xkbi = dpy->xkb_info; xkbi = dpy->xkb_info;
GetReq(kbSetDeviceInfo, req); GetReq(kbSetDeviceInfo, req);
req->length+= size/4; req->length += size / 4;
req->reqType= xkbi->codes->major_opcode; req->reqType = xkbi->codes->major_opcode;
req->xkbReqType= X_kbSetDeviceInfo; req->xkbReqType = X_kbSetDeviceInfo;
req->deviceSpec= devi->device_spec; req->deviceSpec = devi->device_spec;
req->firstBtn= changes->first_btn; req->firstBtn = changes->first_btn;
req->nBtns= changes->num_btns; req->nBtns = changes->num_btns;
req->change= changes->changed; req->change = changes->changed;
req->nDeviceLedFBs= nLeds; req->nDeviceLedFBs = nLeds;
if (size>0) { if (size > 0) {
char * wire; char *wire;
BufAlloc(char *,wire,size);
ok= (wire!=NULL)&& BufAlloc(char *, wire, size);
(_XkbWriteSetDeviceInfo(wire,changes,&lstuff,devi)==size); ok = (wire != NULL) &&
(_XkbWriteSetDeviceInfo(wire, changes, &lstuff, devi) == size);
} }
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
...@@ -762,62 +784,64 @@ XkbChangeDeviceInfo( Display * dpy, ...@@ -762,62 +784,64 @@ XkbChangeDeviceInfo( Display * dpy,
} }
Bool Bool
XkbSetDeviceLedInfo( Display * dpy, XkbSetDeviceLedInfo(Display *dpy,
XkbDeviceInfoPtr devi, XkbDeviceInfoPtr devi,
unsigned ledClass, unsigned ledClass,
unsigned ledID, unsigned ledID,
unsigned which) unsigned which)
{ {
return False; return False;
} }
Bool Bool
XkbSetDeviceButtonActions( Display * dpy, XkbSetDeviceButtonActions(Display *dpy,
XkbDeviceInfoPtr devi, XkbDeviceInfoPtr devi,
unsigned int first, unsigned int first,
unsigned int nBtns) unsigned int nBtns)
{ {
register xkbSetDeviceInfoReq *req; register xkbSetDeviceInfoReq *req;
Status ok = 0; Status ok = 0;
int size,nLeds; int size, nLeds;
XkbInfoPtr xkbi; XkbInfoPtr xkbi;
XkbDeviceChangesRec changes; XkbDeviceChangesRec changes;
SetLedStuff lstuff; SetLedStuff lstuff;
if ((dpy->flags & XlibDisplayNoXkb) || if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return False; return False;
if ((!devi)||(!XkbXI_DevHasBtnActs(devi))||(first+nBtns>devi->num_btns)) if ((!devi) || (!XkbXI_DevHasBtnActs(devi)) ||
return False; (first + nBtns > devi->num_btns))
if (nBtns==0) return False;
return True; if (nBtns == 0)
return True;
bzero((char *)&changes,sizeof(XkbDeviceChangesRec));
changes.changed= XkbXI_ButtonActionsMask; bzero((char *) &changes, sizeof(XkbDeviceChangesRec));
changes.first_btn= first; changes.changed = XkbXI_ButtonActionsMask;
changes.num_btns= nBtns; changes.first_btn = first;
changes.leds.led_class= XkbXINone; changes.num_btns = nBtns;
changes.leds.led_id= XkbXINone; changes.leds.led_class = XkbXINone;
changes.leds.defined= 0; changes.leds.led_id = XkbXINone;
size= nLeds= 0; changes.leds.defined = 0;
if (_XkbSetDeviceInfoSize(devi,&changes,NULL,&size,&nLeds)!=Success) size = nLeds = 0;
return False; if (_XkbSetDeviceInfoSize(devi, &changes, NULL, &size, &nLeds) != Success)
return False;
LockDisplay(dpy); LockDisplay(dpy);
xkbi = dpy->xkb_info; xkbi = dpy->xkb_info;
GetReq(kbSetDeviceInfo, req); GetReq(kbSetDeviceInfo, req);
req->length+= size/4; req->length += size / 4;
req->reqType= xkbi->codes->major_opcode; req->reqType = xkbi->codes->major_opcode;
req->xkbReqType= X_kbSetDeviceInfo; req->xkbReqType = X_kbSetDeviceInfo;
req->deviceSpec= devi->device_spec; req->deviceSpec = devi->device_spec;
req->firstBtn= changes.first_btn; req->firstBtn = changes.first_btn;
req->nBtns= changes.num_btns; req->nBtns = changes.num_btns;
req->change= changes.changed; req->change = changes.changed;
req->nDeviceLedFBs= nLeds; req->nDeviceLedFBs = nLeds;
if (size>0) { if (size > 0) {
char * wire; char *wire;
BufAlloc(char *,wire,size);
ok= (wire!=NULL)&& BufAlloc(char *, wire, size);
(_XkbWriteSetDeviceInfo(wire,&changes,&lstuff,devi)==size); ok = (wire != NULL) &&
(_XkbWriteSetDeviceInfo(wire, &changes, &lstuff, devi) == size);
} }
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
......
...@@ -40,92 +40,94 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. ...@@ -40,92 +40,94 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
/***====================================================================***/ /***====================================================================***/
static void static void
_XkbFreeGeomLeafElems( Bool freeAll, _XkbFreeGeomLeafElems(Bool freeAll,
int first, int first,
int count, int count,
unsigned short * num_inout, unsigned short *num_inout,
unsigned short * sz_inout, unsigned short *sz_inout,
char ** elems, char **elems,
unsigned int elem_sz) unsigned int elem_sz)
{ {
if ((freeAll)||(*elems==NULL)) { if ((freeAll) || (*elems == NULL)) {
*num_inout= *sz_inout= 0; *num_inout = *sz_inout = 0;
if (*elems!=NULL) { if (*elems != NULL) {
_XkbFree(*elems); _XkbFree(*elems);
*elems= NULL; *elems = NULL;
} }
return; return;
} }
if ((first>=(*num_inout))||(first<0)||(count<1)) if ((first >= (*num_inout)) || (first < 0) || (count < 1))
return; return;
if (first+count>=(*num_inout)) { if (first + count >= (*num_inout)) {
/* truncating the array is easy */ /* truncating the array is easy */
(*num_inout)= first; (*num_inout) = first;
} }
else { else {
char * ptr; char *ptr;
int extra; int extra;
ptr= *elems;
extra= ((*num_inout)-(first+count))*elem_sz; ptr = *elems;
if (extra>0) extra = ((*num_inout) - (first + count)) * elem_sz;
memmove(&ptr[first*elem_sz],&ptr[(first+count)*elem_sz],extra); if (extra > 0)
(*num_inout)-= count; memmove(&ptr[first * elem_sz], &ptr[(first + count) * elem_sz],
extra);
(*num_inout) -= count;
} }
return; return;
} }
typedef void (*ContentsClearFunc)( typedef void (*ContentsClearFunc) (
char * /* priv */ char * /* priv */
); );
static void static void
_XkbFreeGeomNonLeafElems( Bool freeAll, _XkbFreeGeomNonLeafElems(Bool freeAll,
int first, int first,
int count, int count,
unsigned short * num_inout, unsigned short *num_inout,
unsigned short * sz_inout, unsigned short *sz_inout,
char ** elems, char **elems,
unsigned int elem_sz, unsigned int elem_sz,
ContentsClearFunc freeFunc) ContentsClearFunc freeFunc)
{ {
register int i; register int i;
register char *ptr; register char *ptr;
if (freeAll) { if (freeAll) {
first= 0; first = 0;
count= (*num_inout); count = (*num_inout);
} }
else if ((first>=(*num_inout))||(first<0)||(count<1)) else if ((first >= (*num_inout)) || (first < 0) || (count < 1))
return; return;
else if (first+count>(*num_inout)) else if (first + count > (*num_inout))
count= (*num_inout)-first; count = (*num_inout) - first;
if (*elems==NULL) if (*elems == NULL)
return; return;
if (freeFunc) { if (freeFunc) {
ptr= *elems; ptr = *elems;
ptr+= first*elem_sz; ptr += first * elem_sz;
for (i=0;i<count;i++) { for (i = 0; i < count; i++) {
(*freeFunc)(ptr); (*freeFunc) (ptr);
ptr+= elem_sz; ptr += elem_sz;
} }
} }
if (freeAll) { if (freeAll) {
(*num_inout)= (*sz_inout)= 0; (*num_inout) = (*sz_inout) = 0;
if (*elems) { if (*elems) {
_XkbFree(*elems); _XkbFree(*elems);
*elems= NULL; *elems = NULL;
} }
} }
else if (first+count>=(*num_inout)) else if (first + count >= (*num_inout))
*num_inout= first; *num_inout = first;
else { else {
i= ((*num_inout)-(first+count))*elem_sz; i = ((*num_inout) - (first + count)) * elem_sz;
ptr= *elems; ptr = *elems;
memmove(&ptr[first*elem_sz],&ptr[(first+count)*elem_sz],i); memmove(&ptr[first * elem_sz], &ptr[(first + count) * elem_sz], i);
(*num_inout)-= count; (*num_inout) -= count;
} }
return; return;
} }
...@@ -135,44 +137,38 @@ register char *ptr; ...@@ -135,44 +137,38 @@ register char *ptr;
static void static void
_XkbClearProperty(char *prop_in) _XkbClearProperty(char *prop_in)
{ {
XkbPropertyPtr prop= (XkbPropertyPtr)prop_in; XkbPropertyPtr prop = (XkbPropertyPtr) prop_in;
if (prop->name) { if (prop->name) {
_XkbFree(prop->name); _XkbFree(prop->name);
prop->name= NULL; prop->name = NULL;
} }
if (prop->value) { if (prop->value) {
_XkbFree(prop->value); _XkbFree(prop->value);
prop->value= NULL; prop->value = NULL;
} }
return; return;
} }
void void
XkbFreeGeomProperties( XkbGeometryPtr geom, XkbFreeGeomProperties(XkbGeometryPtr geom, int first, int count, Bool freeAll)
int first, {
int count, _XkbFreeGeomNonLeafElems(freeAll, first, count,
Bool freeAll) &geom->num_properties, &geom->sz_properties,
{ (char **) &geom->properties,
_XkbFreeGeomNonLeafElems(freeAll,first,count, sizeof(XkbPropertyRec), _XkbClearProperty);
&geom->num_properties,&geom->sz_properties,
(char **)&geom->properties,
sizeof(XkbPropertyRec),_XkbClearProperty);
return; return;
} }
/***====================================================================***/ /***====================================================================***/
void void
XkbFreeGeomKeyAliases( XkbGeometryPtr geom, XkbFreeGeomKeyAliases(XkbGeometryPtr geom, int first, int count, Bool freeAll)
int first, {
int count, _XkbFreeGeomLeafElems(freeAll, first, count,
Bool freeAll) &geom->num_key_aliases, &geom->sz_key_aliases,
{ (char **) &geom->key_aliases,
_XkbFreeGeomLeafElems(freeAll,first,count, sizeof(XkbKeyAliasRec));
&geom->num_key_aliases,&geom->sz_key_aliases,
(char **)&geom->key_aliases,
sizeof(XkbKeyAliasRec));
return; return;
} }
...@@ -181,32 +177,32 @@ XkbFreeGeomKeyAliases( XkbGeometryPtr geom, ...@@ -181,32 +177,32 @@ XkbFreeGeomKeyAliases( XkbGeometryPtr geom,
static void static void
_XkbClearColor(char *color_in) _XkbClearColor(char *color_in)
{ {
XkbColorPtr color= (XkbColorPtr)color_in; XkbColorPtr color = (XkbColorPtr) color_in;
if (color->spec) if (color->spec)
_XkbFree(color->spec); _XkbFree(color->spec);
return; return;
} }
void void
XkbFreeGeomColors(XkbGeometryPtr geom,int first,int count,Bool freeAll) XkbFreeGeomColors(XkbGeometryPtr geom, int first, int count, Bool freeAll)
{ {
_XkbFreeGeomNonLeafElems(freeAll,first,count, _XkbFreeGeomNonLeafElems(freeAll, first, count,
&geom->num_colors,&geom->sz_colors, &geom->num_colors, &geom->sz_colors,
(char **)&geom->colors, (char **) &geom->colors,
sizeof(XkbColorRec),_XkbClearColor); sizeof(XkbColorRec), _XkbClearColor);
return; return;
} }
/***====================================================================***/ /***====================================================================***/
void void
XkbFreeGeomPoints(XkbOutlinePtr outline,int first,int count,Bool freeAll) XkbFreeGeomPoints(XkbOutlinePtr outline, int first, int count, Bool freeAll)
{ {
_XkbFreeGeomLeafElems(freeAll,first,count, _XkbFreeGeomLeafElems(freeAll, first, count,
&outline->num_points,&outline->sz_points, &outline->num_points, &outline->sz_points,
(char **)&outline->points, (char **) &outline->points,
sizeof(XkbPointRec)); sizeof(XkbPointRec));
return; return;
} }
...@@ -215,20 +211,20 @@ XkbFreeGeomPoints(XkbOutlinePtr outline,int first,int count,Bool freeAll) ...@@ -215,20 +211,20 @@ XkbFreeGeomPoints(XkbOutlinePtr outline,int first,int count,Bool freeAll)
static void static void
_XkbClearOutline(char *outline_in) _XkbClearOutline(char *outline_in)
{ {
XkbOutlinePtr outline= (XkbOutlinePtr)outline_in; XkbOutlinePtr outline = (XkbOutlinePtr) outline_in;
if (outline->points!=NULL) if (outline->points != NULL)
XkbFreeGeomPoints(outline,0,outline->num_points,True); XkbFreeGeomPoints(outline, 0, outline->num_points, True);
return; return;
} }
void void
XkbFreeGeomOutlines(XkbShapePtr shape,int first,int count,Bool freeAll) XkbFreeGeomOutlines(XkbShapePtr shape, int first, int count, Bool freeAll)
{ {
_XkbFreeGeomNonLeafElems(freeAll,first,count, _XkbFreeGeomNonLeafElems(freeAll, first, count,
&shape->num_outlines,&shape->sz_outlines, &shape->num_outlines, &shape->sz_outlines,
(char **)&shape->outlines, (char **) &shape->outlines,
sizeof(XkbOutlineRec),_XkbClearOutline); sizeof(XkbOutlineRec), _XkbClearOutline);
return; return;
} }
...@@ -238,32 +234,32 @@ XkbFreeGeomOutlines(XkbShapePtr shape,int first,int count,Bool freeAll) ...@@ -238,32 +234,32 @@ XkbFreeGeomOutlines(XkbShapePtr shape,int first,int count,Bool freeAll)
static void static void
_XkbClearShape(char *shape_in) _XkbClearShape(char *shape_in)
{ {
XkbShapePtr shape= (XkbShapePtr)shape_in; XkbShapePtr shape = (XkbShapePtr) shape_in;
if (shape->outlines) if (shape->outlines)
XkbFreeGeomOutlines(shape,0,shape->num_outlines,True); XkbFreeGeomOutlines(shape, 0, shape->num_outlines, True);
return; return;
} }
void void
XkbFreeGeomShapes(XkbGeometryPtr geom,int first,int count,Bool freeAll) XkbFreeGeomShapes(XkbGeometryPtr geom, int first, int count, Bool freeAll)
{ {
_XkbFreeGeomNonLeafElems(freeAll,first,count, _XkbFreeGeomNonLeafElems(freeAll, first, count,
&geom->num_shapes,&geom->sz_shapes, &geom->num_shapes, &geom->sz_shapes,
(char **)&geom->shapes, (char **) &geom->shapes,
sizeof(XkbShapeRec),_XkbClearShape); sizeof(XkbShapeRec), _XkbClearShape);
return; return;
} }
/***====================================================================***/ /***====================================================================***/
void void
XkbFreeGeomOverlayKeys(XkbOverlayRowPtr row,int first,int count,Bool freeAll) XkbFreeGeomOverlayKeys(XkbOverlayRowPtr row, int first, int count, Bool freeAll)
{ {
_XkbFreeGeomLeafElems(freeAll,first,count, _XkbFreeGeomLeafElems(freeAll, first, count,
&row->num_keys,&row->sz_keys, &row->num_keys, &row->sz_keys,
(char **)&row->keys, (char **) &row->keys,
sizeof(XkbOverlayKeyRec)); sizeof(XkbOverlayKeyRec));
return; return;
} }
...@@ -272,20 +268,21 @@ XkbFreeGeomOverlayKeys(XkbOverlayRowPtr row,int first,int count,Bool freeAll) ...@@ -272,20 +268,21 @@ XkbFreeGeomOverlayKeys(XkbOverlayRowPtr row,int first,int count,Bool freeAll)
static void static void
_XkbClearOverlayRow(char *row_in) _XkbClearOverlayRow(char *row_in)
{ {
XkbOverlayRowPtr row= (XkbOverlayRowPtr)row_in; XkbOverlayRowPtr row = (XkbOverlayRowPtr) row_in;
if (row->keys!=NULL) if (row->keys != NULL)
XkbFreeGeomOverlayKeys(row,0,row->num_keys,True); XkbFreeGeomOverlayKeys(row, 0, row->num_keys, True);
return; return;
} }
void void
XkbFreeGeomOverlayRows(XkbOverlayPtr overlay,int first,int count,Bool freeAll) XkbFreeGeomOverlayRows(XkbOverlayPtr overlay, int first, int count,
Bool freeAll)
{ {
_XkbFreeGeomNonLeafElems(freeAll,first,count, _XkbFreeGeomNonLeafElems(freeAll, first, count,
&overlay->num_rows,&overlay->sz_rows, &overlay->num_rows, &overlay->sz_rows,
(char **)&overlay->rows, (char **) &overlay->rows,
sizeof(XkbOverlayRowRec),_XkbClearOverlayRow); sizeof(XkbOverlayRowRec), _XkbClearOverlayRow);
return; return;
} }
...@@ -294,32 +291,32 @@ XkbFreeGeomOverlayRows(XkbOverlayPtr overlay,int first,int count,Bool freeAll) ...@@ -294,32 +291,32 @@ XkbFreeGeomOverlayRows(XkbOverlayPtr overlay,int first,int count,Bool freeAll)
static void static void
_XkbClearOverlay(char *overlay_in) _XkbClearOverlay(char *overlay_in)
{ {
XkbOverlayPtr overlay= (XkbOverlayPtr)overlay_in; XkbOverlayPtr overlay = (XkbOverlayPtr) overlay_in;
if (overlay->rows!=NULL) if (overlay->rows != NULL)
XkbFreeGeomOverlayRows(overlay,0,overlay->num_rows,True); XkbFreeGeomOverlayRows(overlay, 0, overlay->num_rows, True);
return; return;
} }
void void
XkbFreeGeomOverlays(XkbSectionPtr section,int first,int count,Bool freeAll) XkbFreeGeomOverlays(XkbSectionPtr section, int first, int count, Bool freeAll)
{ {
_XkbFreeGeomNonLeafElems(freeAll,first,count, _XkbFreeGeomNonLeafElems(freeAll, first, count,
&section->num_overlays,&section->sz_overlays, &section->num_overlays, &section->sz_overlays,
(char **)&section->overlays, (char **) &section->overlays,
sizeof(XkbOverlayRec),_XkbClearOverlay); sizeof(XkbOverlayRec), _XkbClearOverlay);
return; return;
} }
/***====================================================================***/ /***====================================================================***/
void void
XkbFreeGeomKeys(XkbRowPtr row,int first,int count,Bool freeAll) XkbFreeGeomKeys(XkbRowPtr row, int first, int count, Bool freeAll)
{ {
_XkbFreeGeomLeafElems(freeAll,first,count, _XkbFreeGeomLeafElems(freeAll, first, count,
&row->num_keys,&row->sz_keys, &row->num_keys, &row->sz_keys,
(char **)&row->keys, (char **) &row->keys,
sizeof(XkbKeyRec)); sizeof(XkbKeyRec));
return; return;
} }
...@@ -328,20 +325,20 @@ XkbFreeGeomKeys(XkbRowPtr row,int first,int count,Bool freeAll) ...@@ -328,20 +325,20 @@ XkbFreeGeomKeys(XkbRowPtr row,int first,int count,Bool freeAll)
static void static void
_XkbClearRow(char *row_in) _XkbClearRow(char *row_in)
{ {
XkbRowPtr row= (XkbRowPtr)row_in; XkbRowPtr row = (XkbRowPtr) row_in;
if (row->keys!=NULL) if (row->keys != NULL)
XkbFreeGeomKeys(row,0,row->num_keys,True); XkbFreeGeomKeys(row, 0, row->num_keys, True);
return; return;
} }
void void
XkbFreeGeomRows(XkbSectionPtr section,int first,int count,Bool freeAll) XkbFreeGeomRows(XkbSectionPtr section, int first, int count, Bool freeAll)
{ {
_XkbFreeGeomNonLeafElems(freeAll,first,count, _XkbFreeGeomNonLeafElems(freeAll, first, count,
&section->num_rows,&section->sz_rows, &section->num_rows, &section->sz_rows,
(char **)&section->rows, (char **) &section->rows,
sizeof(XkbRowRec),_XkbClearRow); sizeof(XkbRowRec), _XkbClearRow);
} }
/***====================================================================***/ /***====================================================================***/
...@@ -349,24 +346,24 @@ XkbFreeGeomRows(XkbSectionPtr section,int first,int count,Bool freeAll) ...@@ -349,24 +346,24 @@ XkbFreeGeomRows(XkbSectionPtr section,int first,int count,Bool freeAll)
static void static void
_XkbClearSection(char *section_in) _XkbClearSection(char *section_in)
{ {
XkbSectionPtr section= (XkbSectionPtr)section_in; XkbSectionPtr section = (XkbSectionPtr) section_in;
if (section->rows!=NULL) if (section->rows != NULL)
XkbFreeGeomRows(section,0,section->num_rows,True); XkbFreeGeomRows(section, 0, section->num_rows, True);
if (section->doodads!=NULL) { if (section->doodads != NULL) {
XkbFreeGeomDoodads(section->doodads,section->num_doodads,True); XkbFreeGeomDoodads(section->doodads, section->num_doodads, True);
section->doodads= NULL; section->doodads = NULL;
} }
return; return;
} }
void void
XkbFreeGeomSections(XkbGeometryPtr geom,int first,int count,Bool freeAll) XkbFreeGeomSections(XkbGeometryPtr geom, int first, int count, Bool freeAll)
{ {
_XkbFreeGeomNonLeafElems(freeAll,first,count, _XkbFreeGeomNonLeafElems(freeAll, first, count,
&geom->num_sections,&geom->sz_sections, &geom->num_sections, &geom->sz_sections,
(char **)&geom->sections, (char **) &geom->sections,
sizeof(XkbSectionRec),_XkbClearSection); sizeof(XkbSectionRec), _XkbClearSection);
return; return;
} }
...@@ -375,77 +372,77 @@ XkbFreeGeomSections(XkbGeometryPtr geom,int first,int count,Bool freeAll) ...@@ -375,77 +372,77 @@ XkbFreeGeomSections(XkbGeometryPtr geom,int first,int count,Bool freeAll)
static void static void
_XkbClearDoodad(char *doodad_in) _XkbClearDoodad(char *doodad_in)
{ {
XkbDoodadPtr doodad= (XkbDoodadPtr)doodad_in; XkbDoodadPtr doodad = (XkbDoodadPtr) doodad_in;
switch (doodad->any.type) { switch (doodad->any.type) {
case XkbTextDoodad: case XkbTextDoodad:
{ {
if (doodad->text.text!=NULL) { if (doodad->text.text != NULL) {
_XkbFree(doodad->text.text); _XkbFree(doodad->text.text);
doodad->text.text= NULL; doodad->text.text = NULL;
} }
if (doodad->text.font!=NULL) { if (doodad->text.font != NULL) {
_XkbFree(doodad->text.font); _XkbFree(doodad->text.font);
doodad->text.font= NULL; doodad->text.font = NULL;
} }
} }
break; break;
case XkbLogoDoodad: case XkbLogoDoodad:
{ {
if (doodad->logo.logo_name!=NULL) { if (doodad->logo.logo_name != NULL) {
_XkbFree(doodad->logo.logo_name); _XkbFree(doodad->logo.logo_name);
doodad->logo.logo_name= NULL; doodad->logo.logo_name = NULL;
} }
} }
break; break;
} }
return; return;
} }
void void
XkbFreeGeomDoodads(XkbDoodadPtr doodads,int nDoodads,Bool freeAll) XkbFreeGeomDoodads(XkbDoodadPtr doodads, int nDoodads, Bool freeAll)
{ {
register int i; register int i;
register XkbDoodadPtr doodad; register XkbDoodadPtr doodad;
if (doodads) { if (doodads) {
for (i=0,doodad= doodads;i<nDoodads;i++,doodad++) { for (i = 0, doodad = doodads; i < nDoodads; i++, doodad++) {
_XkbClearDoodad((char *)doodad); _XkbClearDoodad((char *) doodad);
} }
if (freeAll) if (freeAll)
_XkbFree(doodads); _XkbFree(doodads);
} }
return; return;
} }
void void
XkbFreeGeometry(XkbGeometryPtr geom,unsigned which,Bool freeMap) XkbFreeGeometry(XkbGeometryPtr geom, unsigned which, Bool freeMap)
{ {
if (geom==NULL) if (geom == NULL)
return; return;
if (freeMap) if (freeMap)
which= XkbGeomAllMask; which = XkbGeomAllMask;
if ((which&XkbGeomPropertiesMask)&&(geom->properties!=NULL)) if ((which & XkbGeomPropertiesMask) && (geom->properties != NULL))
XkbFreeGeomProperties(geom,0,geom->num_properties,True); XkbFreeGeomProperties(geom, 0, geom->num_properties, True);
if ((which&XkbGeomColorsMask)&&(geom->colors!=NULL)) if ((which & XkbGeomColorsMask) && (geom->colors != NULL))
XkbFreeGeomColors(geom,0,geom->num_colors,True); XkbFreeGeomColors(geom, 0, geom->num_colors, True);
if ((which&XkbGeomShapesMask)&&(geom->shapes!=NULL)) if ((which & XkbGeomShapesMask) && (geom->shapes != NULL))
XkbFreeGeomShapes(geom,0,geom->num_shapes,True); XkbFreeGeomShapes(geom, 0, geom->num_shapes, True);
if ((which&XkbGeomSectionsMask)&&(geom->sections!=NULL)) if ((which & XkbGeomSectionsMask) && (geom->sections != NULL))
XkbFreeGeomSections(geom,0,geom->num_sections,True); XkbFreeGeomSections(geom, 0, geom->num_sections, True);
if ((which&XkbGeomDoodadsMask)&&(geom->doodads!= NULL)) { if ((which & XkbGeomDoodadsMask) && (geom->doodads != NULL)) {
XkbFreeGeomDoodads(geom->doodads,geom->num_doodads,True); XkbFreeGeomDoodads(geom->doodads, geom->num_doodads, True);
geom->doodads= NULL; geom->doodads = NULL;
geom->num_doodads= geom->sz_doodads= 0; geom->num_doodads = geom->sz_doodads = 0;
} }
if ((which&XkbGeomKeyAliasesMask)&&(geom->key_aliases!=NULL)) if ((which & XkbGeomKeyAliasesMask) && (geom->key_aliases != NULL))
XkbFreeGeomKeyAliases(geom,0,geom->num_key_aliases,True); XkbFreeGeomKeyAliases(geom, 0, geom->num_key_aliases, True);
if (freeMap) { if (freeMap) {
if (geom->label_font!=NULL) { if (geom->label_font != NULL) {
_XkbFree(geom->label_font); _XkbFree(geom->label_font);
geom->label_font= NULL; geom->label_font = NULL;
} }
_XkbFree(geom); _XkbFree(geom);
} }
return; return;
} }
...@@ -453,336 +450,339 @@ XkbFreeGeometry(XkbGeometryPtr geom,unsigned which,Bool freeMap) ...@@ -453,336 +450,339 @@ XkbFreeGeometry(XkbGeometryPtr geom,unsigned which,Bool freeMap)
/***====================================================================***/ /***====================================================================***/
static Status static Status
_XkbGeomAlloc( XPointer * old, _XkbGeomAlloc(XPointer *old,
unsigned short * num, unsigned short *num,
unsigned short * total, unsigned short *total,
int num_new, int num_new,
size_t sz_elem) size_t sz_elem)
{ {
if (num_new<1) if (num_new < 1)
return Success; return Success;
if ((*old)==NULL) if ((*old) == NULL)
*num= *total= 0; *num = *total = 0;
if ((*num)+num_new<=(*total)) if ((*num) + num_new <= (*total))
return Success; return Success;
*total= (*num)+num_new; *total = (*num) + num_new;
if ((*old)!=NULL) if ((*old) != NULL)
(*old)= (XPointer)_XkbRealloc((*old),(*total)*sz_elem); (*old) = (XPointer) _XkbRealloc((*old), (*total) * sz_elem);
else (*old)= (XPointer)_XkbCalloc((*total),sz_elem); else
if ((*old)==NULL) { (*old) = (XPointer) _XkbCalloc((*total), sz_elem);
*total= *num= 0; if ((*old) == NULL) {
return BadAlloc; *total = *num = 0;
} return BadAlloc;
}
if (*num>0) {
char *tmp= (char *)(*old); if (*num > 0) {
bzero(&tmp[sz_elem*(*num)],(num_new*sz_elem)); char *tmp = (char *) (*old);
bzero(&tmp[sz_elem * (*num)], (num_new * sz_elem));
} }
return Success; return Success;
} }
#define _XkbAllocProps(g,n) _XkbGeomAlloc((XPointer *)&(g)->properties,\ #define _XkbAllocProps(g, n) _XkbGeomAlloc((XPointer *)&(g)->properties, \
&(g)->num_properties,&(g)->sz_properties,\ &(g)->num_properties, &(g)->sz_properties, \
(n),sizeof(XkbPropertyRec)) (n), sizeof(XkbPropertyRec))
#define _XkbAllocColors(g,n) _XkbGeomAlloc((XPointer *)&(g)->colors,\ #define _XkbAllocColors(g, n) _XkbGeomAlloc((XPointer *)&(g)->colors, \
&(g)->num_colors,&(g)->sz_colors,\ &(g)->num_colors, &(g)->sz_colors, \
(n),sizeof(XkbColorRec)) (n), sizeof(XkbColorRec))
#define _XkbAllocShapes(g,n) _XkbGeomAlloc((XPointer *)&(g)->shapes,\ #define _XkbAllocShapes(g, n) _XkbGeomAlloc((XPointer *)&(g)->shapes, \
&(g)->num_shapes,&(g)->sz_shapes,\ &(g)->num_shapes, &(g)->sz_shapes, \
(n),sizeof(XkbShapeRec)) (n), sizeof(XkbShapeRec))
#define _XkbAllocSections(g,n) _XkbGeomAlloc((XPointer *)&(g)->sections,\ #define _XkbAllocSections(g, n) _XkbGeomAlloc((XPointer *)&(g)->sections, \
&(g)->num_sections,&(g)->sz_sections,\ &(g)->num_sections, &(g)->sz_sections, \
(n),sizeof(XkbSectionRec)) (n), sizeof(XkbSectionRec))
#define _XkbAllocDoodads(g,n) _XkbGeomAlloc((XPointer *)&(g)->doodads,\ #define _XkbAllocDoodads(g, n) _XkbGeomAlloc((XPointer *)&(g)->doodads, \
&(g)->num_doodads,&(g)->sz_doodads,\ &(g)->num_doodads, &(g)->sz_doodads, \
(n),sizeof(XkbDoodadRec)) (n), sizeof(XkbDoodadRec))
#define _XkbAllocKeyAliases(g,n) _XkbGeomAlloc((XPointer *)&(g)->key_aliases,\ #define _XkbAllocKeyAliases(g, n) _XkbGeomAlloc((XPointer *)&(g)->key_aliases, \
&(g)->num_key_aliases,&(g)->sz_key_aliases,\ &(g)->num_key_aliases, &(g)->sz_key_aliases, \
(n),sizeof(XkbKeyAliasRec)) (n), sizeof(XkbKeyAliasRec))
#define _XkbAllocOutlines(s,n) _XkbGeomAlloc((XPointer *)&(s)->outlines,\ #define _XkbAllocOutlines(s, n) _XkbGeomAlloc((XPointer *)&(s)->outlines, \
&(s)->num_outlines,&(s)->sz_outlines,\ &(s)->num_outlines, &(s)->sz_outlines, \
(n),sizeof(XkbOutlineRec)) (n), sizeof(XkbOutlineRec))
#define _XkbAllocRows(s,n) _XkbGeomAlloc((XPointer *)&(s)->rows,\ #define _XkbAllocRows(s, n) _XkbGeomAlloc((XPointer *)&(s)->rows, \
&(s)->num_rows,&(s)->sz_rows,\ &(s)->num_rows, &(s)->sz_rows, \
(n),sizeof(XkbRowRec)) (n), sizeof(XkbRowRec))
#define _XkbAllocPoints(o,n) _XkbGeomAlloc((XPointer *)&(o)->points,\ #define _XkbAllocPoints(o, n) _XkbGeomAlloc((XPointer *)&(o)->points, \
&(o)->num_points,&(o)->sz_points,\ &(o)->num_points, &(o)->sz_points, \
(n),sizeof(XkbPointRec)) (n), sizeof(XkbPointRec))
#define _XkbAllocKeys(r,n) _XkbGeomAlloc((XPointer *)&(r)->keys,\ #define _XkbAllocKeys(r, n) _XkbGeomAlloc((XPointer *)&(r)->keys, \
&(r)->num_keys,&(r)->sz_keys,\ &(r)->num_keys, &(r)->sz_keys, \
(n),sizeof(XkbKeyRec)) (n), sizeof(XkbKeyRec))
#define _XkbAllocOverlays(s,n) _XkbGeomAlloc((XPointer *)&(s)->overlays,\ #define _XkbAllocOverlays(s, n) _XkbGeomAlloc((XPointer *)&(s)->overlays, \
&(s)->num_overlays,&(s)->sz_overlays,\ &(s)->num_overlays, &(s)->sz_overlays, \
(n),sizeof(XkbOverlayRec)) (n), sizeof(XkbOverlayRec))
#define _XkbAllocOverlayRows(o,n) _XkbGeomAlloc((XPointer *)&(o)->rows,\ #define _XkbAllocOverlayRows(o, n) _XkbGeomAlloc((XPointer *)&(o)->rows, \
&(o)->num_rows,&(o)->sz_rows,\ &(o)->num_rows, &(o)->sz_rows, \
(n),sizeof(XkbOverlayRowRec)) (n), sizeof(XkbOverlayRowRec))
#define _XkbAllocOverlayKeys(r,n) _XkbGeomAlloc((XPointer *)&(r)->keys,\ #define _XkbAllocOverlayKeys(r, n) _XkbGeomAlloc((XPointer *)&(r)->keys, \
&(r)->num_keys,&(r)->sz_keys,\ &(r)->num_keys, &(r)->sz_keys, \
(n),sizeof(XkbOverlayKeyRec)) (n), sizeof(XkbOverlayKeyRec))
Status Status
XkbAllocGeomProps(XkbGeometryPtr geom,int nProps) XkbAllocGeomProps(XkbGeometryPtr geom, int nProps)
{ {
return _XkbAllocProps(geom,nProps); return _XkbAllocProps(geom, nProps);
} }
Status Status
XkbAllocGeomColors(XkbGeometryPtr geom,int nColors) XkbAllocGeomColors(XkbGeometryPtr geom, int nColors)
{ {
return _XkbAllocColors(geom,nColors); return _XkbAllocColors(geom, nColors);
} }
Status Status
XkbAllocGeomKeyAliases(XkbGeometryPtr geom,int nKeyAliases) XkbAllocGeomKeyAliases(XkbGeometryPtr geom, int nKeyAliases)
{ {
return _XkbAllocKeyAliases(geom,nKeyAliases); return _XkbAllocKeyAliases(geom, nKeyAliases);
} }
Status Status
XkbAllocGeomShapes(XkbGeometryPtr geom,int nShapes) XkbAllocGeomShapes(XkbGeometryPtr geom, int nShapes)
{ {
return _XkbAllocShapes(geom,nShapes); return _XkbAllocShapes(geom, nShapes);
} }
Status Status
XkbAllocGeomSections(XkbGeometryPtr geom,int nSections) XkbAllocGeomSections(XkbGeometryPtr geom, int nSections)
{ {
return _XkbAllocSections(geom,nSections); return _XkbAllocSections(geom, nSections);
} }
Status Status
XkbAllocGeomOverlays(XkbSectionPtr section,int nOverlays) XkbAllocGeomOverlays(XkbSectionPtr section, int nOverlays)
{ {
return _XkbAllocOverlays(section,nOverlays); return _XkbAllocOverlays(section, nOverlays);
} }
Status Status
XkbAllocGeomOverlayRows(XkbOverlayPtr overlay,int nRows) XkbAllocGeomOverlayRows(XkbOverlayPtr overlay, int nRows)
{ {
return _XkbAllocOverlayRows(overlay,nRows); return _XkbAllocOverlayRows(overlay, nRows);
} }
Status Status
XkbAllocGeomOverlayKeys(XkbOverlayRowPtr row,int nKeys) XkbAllocGeomOverlayKeys(XkbOverlayRowPtr row, int nKeys)
{ {
return _XkbAllocOverlayKeys(row,nKeys); return _XkbAllocOverlayKeys(row, nKeys);
} }
Status Status
XkbAllocGeomDoodads(XkbGeometryPtr geom,int nDoodads) XkbAllocGeomDoodads(XkbGeometryPtr geom, int nDoodads)
{ {
return _XkbAllocDoodads(geom,nDoodads); return _XkbAllocDoodads(geom, nDoodads);
} }
Status Status
XkbAllocGeomSectionDoodads(XkbSectionPtr section,int nDoodads) XkbAllocGeomSectionDoodads(XkbSectionPtr section, int nDoodads)
{ {
return _XkbAllocDoodads(section,nDoodads); return _XkbAllocDoodads(section, nDoodads);
} }
Status Status
XkbAllocGeomOutlines(XkbShapePtr shape,int nOL) XkbAllocGeomOutlines(XkbShapePtr shape, int nOL)
{ {
return _XkbAllocOutlines(shape,nOL); return _XkbAllocOutlines(shape, nOL);
} }
Status Status
XkbAllocGeomRows(XkbSectionPtr section,int nRows) XkbAllocGeomRows(XkbSectionPtr section, int nRows)
{ {
return _XkbAllocRows(section,nRows); return _XkbAllocRows(section, nRows);
} }
Status Status
XkbAllocGeomPoints(XkbOutlinePtr ol,int nPts) XkbAllocGeomPoints(XkbOutlinePtr ol, int nPts)
{ {
return _XkbAllocPoints(ol,nPts); return _XkbAllocPoints(ol, nPts);
} }
Status Status
XkbAllocGeomKeys(XkbRowPtr row,int nKeys) XkbAllocGeomKeys(XkbRowPtr row, int nKeys)
{ {
return _XkbAllocKeys(row,nKeys); return _XkbAllocKeys(row, nKeys);
} }
Status Status
XkbAllocGeometry(XkbDescPtr xkb,XkbGeometrySizesPtr sizes) XkbAllocGeometry(XkbDescPtr xkb, XkbGeometrySizesPtr sizes)
{ {
XkbGeometryPtr geom; XkbGeometryPtr geom;
Status rtrn; Status rtrn;
if (xkb->geom==NULL) { if (xkb->geom == NULL) {
xkb->geom= _XkbTypedCalloc(1,XkbGeometryRec); xkb->geom = _XkbTypedCalloc(1, XkbGeometryRec);
if (!xkb->geom) if (!xkb->geom)
return BadAlloc; return BadAlloc;
} }
geom= xkb->geom; geom = xkb->geom;
if ((sizes->which&XkbGeomPropertiesMask)&& if ((sizes->which & XkbGeomPropertiesMask) &&
((rtrn=_XkbAllocProps(geom,sizes->num_properties))!=Success)) { ((rtrn = _XkbAllocProps(geom, sizes->num_properties)) != Success)) {
goto BAIL; goto BAIL;
} }
if ((sizes->which&XkbGeomColorsMask)&& if ((sizes->which & XkbGeomColorsMask) &&
((rtrn=_XkbAllocColors(geom,sizes->num_colors))!=Success)) { ((rtrn = _XkbAllocColors(geom, sizes->num_colors)) != Success)) {
goto BAIL; goto BAIL;
} }
if ((sizes->which&XkbGeomShapesMask)&& if ((sizes->which & XkbGeomShapesMask) &&
((rtrn=_XkbAllocShapes(geom,sizes->num_shapes))!=Success)) { ((rtrn = _XkbAllocShapes(geom, sizes->num_shapes)) != Success)) {
goto BAIL; goto BAIL;
} }
if ((sizes->which&XkbGeomSectionsMask)&& if ((sizes->which & XkbGeomSectionsMask) &&
((rtrn=_XkbAllocSections(geom,sizes->num_sections))!=Success)) { ((rtrn = _XkbAllocSections(geom, sizes->num_sections)) != Success)) {
goto BAIL; goto BAIL;
} }
if ((sizes->which&XkbGeomDoodadsMask)&& if ((sizes->which & XkbGeomDoodadsMask) &&
((rtrn=_XkbAllocDoodads(geom,sizes->num_doodads))!=Success)) { ((rtrn = _XkbAllocDoodads(geom, sizes->num_doodads)) != Success)) {
goto BAIL; goto BAIL;
} }
if ((sizes->which&XkbGeomKeyAliasesMask)&& if ((sizes->which & XkbGeomKeyAliasesMask) &&
((rtrn=_XkbAllocKeyAliases(geom,sizes->num_key_aliases))!=Success)) { ((rtrn = _XkbAllocKeyAliases(geom, sizes->num_key_aliases))
goto BAIL; != Success)) {
goto BAIL;
} }
return Success; return Success;
BAIL: BAIL:
XkbFreeGeometry(geom,XkbGeomAllMask,True); XkbFreeGeometry(geom, XkbGeomAllMask, True);
xkb->geom= NULL; xkb->geom = NULL;
return rtrn; return rtrn;
} }
/***====================================================================***/ /***====================================================================***/
XkbPropertyPtr XkbPropertyPtr
XkbAddGeomProperty(XkbGeometryPtr geom,char *name,char *value) XkbAddGeomProperty(XkbGeometryPtr geom, char *name, char *value)
{ {
register int i; register int i;
register XkbPropertyPtr prop; register XkbPropertyPtr prop;
if ((!geom)||(!name)||(!value)) if ((!geom) || (!name) || (!value))
return NULL; return NULL;
for (i=0,prop=geom->properties;i<geom->num_properties;i++,prop++) { for (i = 0, prop = geom->properties; i < geom->num_properties; i++, prop++) {
if ((prop->name)&&(strcmp(name,prop->name)==0)) { if ((prop->name) && (strcmp(name, prop->name) == 0)) {
if (prop->value) if (prop->value)
_XkbFree(prop->value); _XkbFree(prop->value);
prop->value= strdup(value); prop->value = strdup(value);
return prop; return prop;
} }
} }
if ((geom->num_properties>=geom->sz_properties)&& if ((geom->num_properties >= geom->sz_properties) &&
(_XkbAllocProps(geom,1)!=Success)) { (_XkbAllocProps(geom, 1) != Success)) {
return NULL; return NULL;
} }
prop= &geom->properties[geom->num_properties]; prop = &geom->properties[geom->num_properties];
prop->name= strdup(name); prop->name = strdup(name);
if (!prop->name) if (!prop->name)
return NULL; return NULL;
prop->value= strdup(value); prop->value = strdup(value);
if (!prop->value) { if (!prop->value) {
_XkbFree(prop->name); _XkbFree(prop->name);
prop->name= NULL; prop->name = NULL;
return NULL; return NULL;
} }
geom->num_properties++; geom->num_properties++;
return prop; return prop;
} }
XkbKeyAliasPtr XkbKeyAliasPtr
XkbAddGeomKeyAlias(XkbGeometryPtr geom,char *aliasStr,char *realStr) XkbAddGeomKeyAlias(XkbGeometryPtr geom, char *aliasStr, char *realStr)
{ {
register int i; register int i;
register XkbKeyAliasPtr alias; register XkbKeyAliasPtr alias;
if ((!geom)||(!aliasStr)||(!realStr)||(!aliasStr[0])||(!realStr[0])) if ((!geom) || (!aliasStr) || (!realStr) || (!aliasStr[0]) || (!realStr[0]))
return NULL; return NULL;
for (i=0,alias=geom->key_aliases;i<geom->num_key_aliases;i++,alias++) { for (i = 0, alias = geom->key_aliases; i < geom->num_key_aliases;
if (strncmp(alias->alias,aliasStr,XkbKeyNameLength)==0) { i++, alias++) {
bzero(alias->real,XkbKeyNameLength); if (strncmp(alias->alias, aliasStr, XkbKeyNameLength) == 0) {
strncpy(alias->real,realStr,XkbKeyNameLength); bzero(alias->real, XkbKeyNameLength);
return alias; strncpy(alias->real, realStr, XkbKeyNameLength);
} return alias;
} }
if ((geom->num_key_aliases>=geom->sz_key_aliases)&& }
(_XkbAllocKeyAliases(geom,1)!=Success)) { if ((geom->num_key_aliases >= geom->sz_key_aliases) &&
return NULL; (_XkbAllocKeyAliases(geom, 1) != Success)) {
} return NULL;
alias= &geom->key_aliases[geom->num_key_aliases]; }
bzero(alias,sizeof(XkbKeyAliasRec)); alias = &geom->key_aliases[geom->num_key_aliases];
strncpy(alias->alias,aliasStr,XkbKeyNameLength); bzero(alias, sizeof(XkbKeyAliasRec));
strncpy(alias->real,realStr,XkbKeyNameLength); strncpy(alias->alias, aliasStr, XkbKeyNameLength);
strncpy(alias->real, realStr, XkbKeyNameLength);
geom->num_key_aliases++; geom->num_key_aliases++;
return alias; return alias;
} }
XkbColorPtr XkbColorPtr
XkbAddGeomColor(XkbGeometryPtr geom,char *spec,unsigned int pixel) XkbAddGeomColor(XkbGeometryPtr geom, char *spec, unsigned int pixel)
{ {
register int i; register int i;
register XkbColorPtr color; register XkbColorPtr color;
if ((!geom)||(!spec)) if ((!geom) || (!spec))
return NULL; return NULL;
for (i=0,color=geom->colors;i<geom->num_colors;i++,color++) { for (i = 0, color = geom->colors; i < geom->num_colors; i++, color++) {
if ((color->spec)&&(strcmp(color->spec,spec)==0)) { if ((color->spec) && (strcmp(color->spec, spec) == 0)) {
color->pixel= pixel; color->pixel = pixel;
return color; return color;
} }
} }
if ((geom->num_colors>=geom->sz_colors)&& if ((geom->num_colors >= geom->sz_colors) &&
(_XkbAllocColors(geom,1)!=Success)) { (_XkbAllocColors(geom, 1) != Success)) {
return NULL; return NULL;
} }
color= &geom->colors[geom->num_colors]; color = &geom->colors[geom->num_colors];
color->pixel= pixel; color->pixel = pixel;
color->spec= strdup(spec); color->spec = strdup(spec);
if (!color->spec) if (!color->spec)
return NULL; return NULL;
geom->num_colors++; geom->num_colors++;
return color; return color;
} }
XkbOutlinePtr XkbOutlinePtr
XkbAddGeomOutline(XkbShapePtr shape,int sz_points) XkbAddGeomOutline(XkbShapePtr shape, int sz_points)
{ {
XkbOutlinePtr outline; XkbOutlinePtr outline;
if ((!shape)||(sz_points<0)) if ((!shape) || (sz_points < 0))
return NULL; return NULL;
if ((shape->num_outlines>=shape->sz_outlines)&& if ((shape->num_outlines >= shape->sz_outlines) &&
(_XkbAllocOutlines(shape,1)!=Success)) { (_XkbAllocOutlines(shape, 1) != Success)) {
return NULL; return NULL;
} }
outline= &shape->outlines[shape->num_outlines]; outline = &shape->outlines[shape->num_outlines];
bzero(outline,sizeof(XkbOutlineRec)); bzero(outline, sizeof(XkbOutlineRec));
if ((sz_points>0)&&(_XkbAllocPoints(outline,sz_points)!=Success)) if ((sz_points > 0) && (_XkbAllocPoints(outline, sz_points) != Success))
return NULL; return NULL;
shape->num_outlines++; shape->num_outlines++;
return outline; return outline;
} }
XkbShapePtr XkbShapePtr
XkbAddGeomShape(XkbGeometryPtr geom,Atom name,int sz_outlines) XkbAddGeomShape(XkbGeometryPtr geom, Atom name, int sz_outlines)
{ {
XkbShapePtr shape; XkbShapePtr shape;
register int i; register int i;
if ((!geom)||(!name)||(sz_outlines<0)) if ((!geom) || (!name) || (sz_outlines < 0))
return NULL; return NULL;
if (geom->num_shapes>0) { if (geom->num_shapes > 0) {
for (shape=geom->shapes,i=0;i<geom->num_shapes;i++,shape++) { for (shape = geom->shapes, i = 0; i < geom->num_shapes; i++, shape++) {
if (name==shape->name) if (name == shape->name)
return shape; return shape;
} }
} }
if ((geom->num_shapes>=geom->sz_shapes)&& if ((geom->num_shapes >= geom->sz_shapes) &&
(_XkbAllocShapes(geom,1)!=Success)) (_XkbAllocShapes(geom, 1) != Success))
return NULL; return NULL;
shape= &geom->shapes[geom->num_shapes]; shape = &geom->shapes[geom->num_shapes];
bzero(shape,sizeof(XkbShapeRec)); bzero(shape, sizeof(XkbShapeRec));
if ((sz_outlines>0)&&(_XkbAllocOutlines(shape,sz_outlines)!=Success)) if ((sz_outlines > 0) && (_XkbAllocOutlines(shape, sz_outlines) != Success))
return NULL; return NULL;
shape->name= name; shape->name = name;
shape->primary= shape->approx= NULL; shape->primary = shape->approx = NULL;
geom->num_shapes++; geom->num_shapes++;
return shape; return shape;
} }
...@@ -790,203 +790,209 @@ register int i; ...@@ -790,203 +790,209 @@ register int i;
XkbKeyPtr XkbKeyPtr
XkbAddGeomKey(XkbRowPtr row) XkbAddGeomKey(XkbRowPtr row)
{ {
XkbKeyPtr key; XkbKeyPtr key;
if (!row) if (!row)
return NULL; return NULL;
if ((row->num_keys>=row->sz_keys)&&(_XkbAllocKeys(row,1)!=Success)) if ((row->num_keys >= row->sz_keys) && (_XkbAllocKeys(row, 1) != Success))
return NULL; return NULL;
key= &row->keys[row->num_keys++]; key = &row->keys[row->num_keys++];
bzero(key,sizeof(XkbKeyRec)); bzero(key, sizeof(XkbKeyRec));
return key; return key;
} }
XkbRowPtr XkbRowPtr
XkbAddGeomRow(XkbSectionPtr section,int sz_keys) XkbAddGeomRow(XkbSectionPtr section, int sz_keys)
{ {
XkbRowPtr row; XkbRowPtr row;
if ((!section)||(sz_keys<0)) if ((!section) || (sz_keys < 0))
return NULL; return NULL;
if ((section->num_rows>=section->sz_rows)&& if ((section->num_rows >= section->sz_rows) &&
(_XkbAllocRows(section,1)!=Success)) (_XkbAllocRows(section, 1) != Success))
return NULL; return NULL;
row= &section->rows[section->num_rows]; row = &section->rows[section->num_rows];
bzero(row,sizeof(XkbRowRec)); bzero(row, sizeof(XkbRowRec));
if ((sz_keys>0)&&(_XkbAllocKeys(row,sz_keys)!=Success)) if ((sz_keys > 0) && (_XkbAllocKeys(row, sz_keys) != Success))
return NULL; return NULL;
section->num_rows++; section->num_rows++;
return row; return row;
} }
XkbSectionPtr XkbSectionPtr
XkbAddGeomSection( XkbGeometryPtr geom, XkbAddGeomSection(XkbGeometryPtr geom,
Atom name, Atom name,
int sz_rows, int sz_rows,
int sz_doodads, int sz_doodads,
int sz_over) int sz_over)
{ {
register int i; register int i;
XkbSectionPtr section; XkbSectionPtr section;
if ((!geom)||(name==None)||(sz_rows<0)) if ((!geom) || (name == None) || (sz_rows < 0))
return NULL; return NULL;
for (i=0,section=geom->sections;i<geom->num_sections;i++,section++) { for (i = 0, section = geom->sections; i < geom->num_sections;
if (section->name!=name) i++, section++) {
continue; if (section->name != name)
if (((sz_rows>0)&&(_XkbAllocRows(section,sz_rows)!=Success))|| continue;
((sz_doodads>0)&&(_XkbAllocDoodads(section,sz_doodads)!=Success))|| if (((sz_rows > 0) && (_XkbAllocRows(section, sz_rows) != Success)) ||
((sz_over>0)&&(_XkbAllocOverlays(section,sz_over)!=Success))) ((sz_doodads > 0) &&
return NULL; (_XkbAllocDoodads(section, sz_doodads) != Success)) ||
return section; ((sz_over > 0) && (_XkbAllocOverlays(section, sz_over) != Success)))
} return NULL;
if ((geom->num_sections>=geom->sz_sections)&& return section;
(_XkbAllocSections(geom,1)!=Success)) }
return NULL; if ((geom->num_sections >= geom->sz_sections) &&
section= &geom->sections[geom->num_sections]; (_XkbAllocSections(geom, 1) != Success))
if ((sz_rows>0)&&(_XkbAllocRows(section,sz_rows)!=Success)) return NULL;
return NULL; section = &geom->sections[geom->num_sections];
if ((sz_doodads>0)&&(_XkbAllocDoodads(section,sz_doodads)!=Success)) { if ((sz_rows > 0) && (_XkbAllocRows(section, sz_rows) != Success))
if (section->rows) { return NULL;
_XkbFree(section->rows); if ((sz_doodads > 0) && (_XkbAllocDoodads(section, sz_doodads) != Success)) {
section->rows= NULL; if (section->rows) {
section->sz_rows= section->num_rows= 0; _XkbFree(section->rows);
} section->rows = NULL;
return NULL; section->sz_rows = section->num_rows = 0;
} }
section->name= name; return NULL;
}
section->name = name;
geom->num_sections++; geom->num_sections++;
return section; return section;
} }
XkbDoodadPtr XkbDoodadPtr
XkbAddGeomDoodad(XkbGeometryPtr geom,XkbSectionPtr section,Atom name) XkbAddGeomDoodad(XkbGeometryPtr geom, XkbSectionPtr section, Atom name)
{ {
XkbDoodadPtr old,doodad; XkbDoodadPtr old, doodad;
register int i,nDoodads; register int i, nDoodads;
if ((!geom)||(name==None)) if ((!geom) || (name == None))
return NULL; return NULL;
if ((section!=NULL)&&(section->num_doodads>0)) { if ((section != NULL) && (section->num_doodads > 0)) {
old= section->doodads; old = section->doodads;
nDoodads= section->num_doodads; nDoodads = section->num_doodads;
} }
else { else {
old= geom->doodads; old = geom->doodads;
nDoodads= geom->num_doodads; nDoodads = geom->num_doodads;
} }
for (i=0,doodad=old;i<nDoodads;i++,doodad++) { for (i = 0, doodad = old; i < nDoodads; i++, doodad++) {
if (doodad->any.name==name) if (doodad->any.name == name)
return doodad; return doodad;
} }
if (section) { if (section) {
if ((section->num_doodads>=geom->sz_doodads)&& if ((section->num_doodads >= geom->sz_doodads) &&
(_XkbAllocDoodads(section,1)!=Success)) { (_XkbAllocDoodads(section, 1) != Success)) {
return NULL; return NULL;
} }
doodad= &section->doodads[section->num_doodads++]; doodad = &section->doodads[section->num_doodads++];
} }
else { else {
if ((geom->num_doodads>=geom->sz_doodads)&& if ((geom->num_doodads >= geom->sz_doodads) &&
(_XkbAllocDoodads(geom,1)!=Success)) (_XkbAllocDoodads(geom, 1) != Success))
return NULL; return NULL;
doodad= &geom->doodads[geom->num_doodads++]; doodad = &geom->doodads[geom->num_doodads++];
} }
bzero(doodad,sizeof(XkbDoodadRec)); bzero(doodad, sizeof(XkbDoodadRec));
doodad->any.name= name; doodad->any.name = name;
return doodad; return doodad;
} }
XkbOverlayKeyPtr XkbOverlayKeyPtr
XkbAddGeomOverlayKey( XkbOverlayPtr overlay, XkbAddGeomOverlayKey(XkbOverlayPtr overlay,
XkbOverlayRowPtr row, XkbOverlayRowPtr row,
char * over, char *over,
char * under) char *under)
{ {
register int i; register int i;
XkbOverlayKeyPtr key; XkbOverlayKeyPtr key;
XkbSectionPtr section; XkbSectionPtr section;
XkbRowPtr row_under; XkbRowPtr row_under;
Bool found; Bool found;
if ((!overlay)||(!row)||(!over)||(!under)) if ((!overlay) || (!row) || (!over) || (!under))
return NULL; return NULL;
section= overlay->section_under; section = overlay->section_under;
if (row->row_under>=section->num_rows) if (row->row_under >= section->num_rows)
return NULL; return NULL;
row_under= &section->rows[row->row_under]; row_under = &section->rows[row->row_under];
for (i=0,found=False;i<row_under->num_keys;i++) { for (i = 0, found = False; i < row_under->num_keys; i++) {
if (strncmp(under,row_under->keys[i].name.name,XkbKeyNameLength)==0) { if (strncmp(under, row_under->keys[i].name.name, XkbKeyNameLength) == 0) {
found= True; found = True;
break; break;
} }
} }
if (!found) if (!found)
return NULL; return NULL;
if ((row->num_keys>=row->sz_keys)&&(_XkbAllocOverlayKeys(row,1)!=Success)) if ((row->num_keys >= row->sz_keys) &&
return NULL; (_XkbAllocOverlayKeys(row, 1) != Success))
key= &row->keys[row->num_keys]; return NULL;
strncpy(key->under.name,under,XkbKeyNameLength); key = &row->keys[row->num_keys];
strncpy(key->over.name,over,XkbKeyNameLength); strncpy(key->under.name, under, XkbKeyNameLength);
strncpy(key->over.name, over, XkbKeyNameLength);
row->num_keys++; row->num_keys++;
return key; return key;
} }
XkbOverlayRowPtr XkbOverlayRowPtr
XkbAddGeomOverlayRow(XkbOverlayPtr overlay,int row_under,int sz_keys) XkbAddGeomOverlayRow(XkbOverlayPtr overlay, int row_under, int sz_keys)
{ {
register int i; register int i;
XkbOverlayRowPtr row; XkbOverlayRowPtr row;
if ((!overlay)||(sz_keys<0)) if ((!overlay) || (sz_keys < 0))
return NULL; return NULL;
if (row_under>=overlay->section_under->num_rows) if (row_under >= overlay->section_under->num_rows)
return NULL; return NULL;
for (i=0;i<overlay->num_rows;i++) { for (i = 0; i < overlay->num_rows; i++) {
if (overlay->rows[i].row_under==row_under) { if (overlay->rows[i].row_under == row_under) {
row= &overlay->rows[i]; row = &overlay->rows[i];
if ((row->sz_keys<sz_keys)&& if ((row->sz_keys < sz_keys) &&
(_XkbAllocOverlayKeys(row,sz_keys)!=Success)) { (_XkbAllocOverlayKeys(row, sz_keys) != Success)) {
return NULL; return NULL;
} }
return &overlay->rows[i]; return &overlay->rows[i];
} }
} }
if ((overlay->num_rows>=overlay->sz_rows)&& if ((overlay->num_rows >= overlay->sz_rows) &&
(_XkbAllocOverlayRows(overlay,1)!=Success)) (_XkbAllocOverlayRows(overlay, 1) != Success))
return NULL; return NULL;
row= &overlay->rows[overlay->num_rows]; row = &overlay->rows[overlay->num_rows];
bzero(row,sizeof(XkbOverlayRowRec)); bzero(row, sizeof(XkbOverlayRowRec));
if ((sz_keys>0)&&(_XkbAllocOverlayKeys(row,sz_keys)!=Success)) if ((sz_keys > 0) && (_XkbAllocOverlayKeys(row, sz_keys) != Success))
return NULL; return NULL;
row->row_under= row_under; row->row_under = row_under;
overlay->num_rows++; overlay->num_rows++;
return row; return row;
} }
XkbOverlayPtr XkbOverlayPtr
XkbAddGeomOverlay(XkbSectionPtr section,Atom name,int sz_rows) XkbAddGeomOverlay(XkbSectionPtr section, Atom name, int sz_rows)
{ {
register int i; register int i;
XkbOverlayPtr overlay; XkbOverlayPtr overlay;
if ((!section)||(name==None)||(sz_rows==0)) if ((!section) || (name == None) || (sz_rows == 0))
return NULL; return NULL;
for (i=0,overlay=section->overlays;i<section->num_overlays;i++,overlay++) { for (i = 0, overlay = section->overlays; i < section->num_overlays;
if (overlay->name==name) { i++, overlay++) {
if ((sz_rows>0)&&(_XkbAllocOverlayRows(overlay,sz_rows)!=Success)) if (overlay->name == name) {
return NULL; if ((sz_rows > 0) &&
return overlay; (_XkbAllocOverlayRows(overlay, sz_rows) != Success))
} return NULL;
} return overlay;
if ((section->num_overlays>=section->sz_overlays)&& }
(_XkbAllocOverlays(section,1)!=Success)) }
return NULL; if ((section->num_overlays >= section->sz_overlays) &&
overlay= &section->overlays[section->num_overlays]; (_XkbAllocOverlays(section, 1) != Success))
if ((sz_rows>0)&&(_XkbAllocOverlayRows(overlay,sz_rows)!=Success)) return NULL;
return NULL; overlay = &section->overlays[section->num_overlays];
overlay->name= name; if ((sz_rows > 0) && (_XkbAllocOverlayRows(overlay, sz_rows) != Success))
overlay->section_under= section; return NULL;
overlay->name = name;
overlay->section_under = section;
section->num_overlays++; section->num_overlays++;
return overlay; return overlay;
} }
...@@ -47,149 +47,160 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. ...@@ -47,149 +47,160 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
/***====================================================================***/ /***====================================================================***/
static void static void
_XkbCheckBounds(XkbBoundsPtr bounds,int x,int y) _XkbCheckBounds(XkbBoundsPtr bounds, int x, int y)
{ {
if (x<bounds->x1) bounds->x1= x; if (x < bounds->x1)
if (x>bounds->x2) bounds->x2= x; bounds->x1 = x;
if (y<bounds->y1) bounds->y1= y; if (x > bounds->x2)
if (y>bounds->y2) bounds->y2= y; bounds->x2 = x;
if (y < bounds->y1)
bounds->y1 = y;
if (y > bounds->y2)
bounds->y2 = y;
return; return;
} }
Bool Bool
XkbComputeShapeBounds(XkbShapePtr shape) XkbComputeShapeBounds(XkbShapePtr shape)
{ {
register int o,p; register int o, p;
XkbOutlinePtr outline; XkbOutlinePtr outline;
XkbPointPtr pt; XkbPointPtr pt;
if ((!shape)||(shape->num_outlines<1)) if ((!shape) || (shape->num_outlines < 1))
return False; return False;
shape->bounds.x1= shape->bounds.y1= MAXSHORT; shape->bounds.x1 = shape->bounds.y1 = MAXSHORT;
shape->bounds.x2= shape->bounds.y2= MINSHORT; shape->bounds.x2 = shape->bounds.y2 = MINSHORT;
for (outline=shape->outlines,o=0;o<shape->num_outlines;o++,outline++) { for (outline = shape->outlines, o = 0; o < shape->num_outlines;
for (pt=outline->points,p=0;p<outline->num_points;p++,pt++) { o++, outline++) {
_XkbCheckBounds(&shape->bounds,pt->x,pt->y); for (pt = outline->points, p = 0; p < outline->num_points; p++, pt++) {
} _XkbCheckBounds(&shape->bounds, pt->x, pt->y);
if (outline->num_points<2) { }
_XkbCheckBounds(&shape->bounds,0,0); if (outline->num_points < 2) {
_XkbCheckBounds(&shape->bounds, 0, 0);
} }
} }
return True; return True;
} }
Bool Bool
XkbComputeShapeTop(XkbShapePtr shape,XkbBoundsPtr bounds) XkbComputeShapeTop(XkbShapePtr shape, XkbBoundsPtr bounds)
{ {
register int p; register int p;
XkbOutlinePtr outline; XkbOutlinePtr outline;
XkbPointPtr pt; XkbPointPtr pt;
if ((!shape)||(shape->num_outlines<1)) if ((!shape) || (shape->num_outlines < 1))
return False; return False;
if (shape->approx) outline= shape->approx; if (shape->approx)
else outline= &shape->outlines[shape->num_outlines-1]; outline = shape->approx;
if (outline->num_points<2) { else
bounds->x1= bounds->y1= 0; outline = &shape->outlines[shape->num_outlines - 1];
bounds->x2= bounds->y2= 0; if (outline->num_points < 2) {
bounds->x1 = bounds->y1 = 0;
bounds->x2 = bounds->y2 = 0;
} }
else { else {
bounds->x1= bounds->y1= MAXSHORT; bounds->x1 = bounds->y1 = MAXSHORT;
bounds->x2= bounds->y2= MINSHORT; bounds->x2 = bounds->y2 = MINSHORT;
} }
for (pt=outline->points,p=0;p<outline->num_points;p++,pt++) { for (pt = outline->points, p = 0; p < outline->num_points; p++, pt++) {
_XkbCheckBounds(bounds,pt->x,pt->y); _XkbCheckBounds(bounds, pt->x, pt->y);
} }
return True; return True;
} }
Bool Bool
XkbComputeRowBounds(XkbGeometryPtr geom,XkbSectionPtr section,XkbRowPtr row) XkbComputeRowBounds(XkbGeometryPtr geom, XkbSectionPtr section, XkbRowPtr row)
{ {
register int k,pos; register int k, pos;
XkbKeyPtr key; XkbKeyPtr key;
XkbBoundsPtr bounds,sbounds; XkbBoundsPtr bounds, sbounds;
if ((!geom)||(!section)||(!row)) if ((!geom) || (!section) || (!row))
return False; return False;
bounds= &row->bounds; bounds = &row->bounds;
bzero(bounds,sizeof(XkbBoundsRec)); bzero(bounds, sizeof(XkbBoundsRec));
for (key=row->keys,pos=k=0;k<row->num_keys;k++,key++) { for (key = row->keys, pos = k = 0; k < row->num_keys; k++, key++) {
sbounds= &XkbKeyShape(geom,key)->bounds; sbounds = &XkbKeyShape(geom, key)->bounds;
_XkbCheckBounds(bounds,pos,0); _XkbCheckBounds(bounds, pos, 0);
if (!row->vertical) { if (!row->vertical) {
if (key->gap!=0) { if (key->gap != 0) {
pos+= key->gap; pos += key->gap;
_XkbCheckBounds(bounds,pos,0); _XkbCheckBounds(bounds, pos, 0);
} }
_XkbCheckBounds(bounds,pos+sbounds->x1,sbounds->y1); _XkbCheckBounds(bounds, pos + sbounds->x1, sbounds->y1);
_XkbCheckBounds(bounds,pos+sbounds->x2,sbounds->y2); _XkbCheckBounds(bounds, pos + sbounds->x2, sbounds->y2);
pos+= sbounds->x2; pos += sbounds->x2;
} }
else { else {
if (key->gap!=0) { if (key->gap != 0) {
pos+= key->gap; pos += key->gap;
_XkbCheckBounds(bounds,0,pos); _XkbCheckBounds(bounds, 0, pos);
} }
_XkbCheckBounds(bounds,pos+sbounds->x1,sbounds->y1); _XkbCheckBounds(bounds, pos + sbounds->x1, sbounds->y1);
_XkbCheckBounds(bounds,pos+sbounds->x2,sbounds->y2); _XkbCheckBounds(bounds, pos + sbounds->x2, sbounds->y2);
pos+= sbounds->y2; pos += sbounds->y2;
} }
} }
return True; return True;
} }
Bool Bool
XkbComputeSectionBounds(XkbGeometryPtr geom,XkbSectionPtr section) XkbComputeSectionBounds(XkbGeometryPtr geom, XkbSectionPtr section)
{ {
register int i; register int i;
XkbShapePtr shape; XkbShapePtr shape;
XkbRowPtr row; XkbRowPtr row;
XkbDoodadPtr doodad; XkbDoodadPtr doodad;
XkbBoundsPtr bounds,rbounds; XkbBoundsPtr bounds, rbounds;
if ((!geom)||(!section)) if ((!geom) || (!section))
return False; return False;
bounds= &section->bounds; bounds = &section->bounds;
bzero(bounds,sizeof(XkbBoundsRec)); bzero(bounds, sizeof(XkbBoundsRec));
for (i=0,row=section->rows;i<section->num_rows;i++,row++) { for (i = 0, row = section->rows; i < section->num_rows; i++, row++) {
if (!XkbComputeRowBounds(geom,section,row)) if (!XkbComputeRowBounds(geom, section, row))
return False; return False;
rbounds= &row->bounds; rbounds = &row->bounds;
_XkbCheckBounds(bounds,row->left+rbounds->x1,row->top+rbounds->y1); _XkbCheckBounds(bounds, row->left + rbounds->x1,
_XkbCheckBounds(bounds,row->left+rbounds->x2,row->top+rbounds->y2); row->top + rbounds->y1);
_XkbCheckBounds(bounds, row->left + rbounds->x2,
row->top + rbounds->y2);
} }
for (i=0,doodad=section->doodads;i<section->num_doodads;i++,doodad++) { for (i = 0, doodad = section->doodads; i < section->num_doodads;
static XkbBoundsRec tbounds; i++, doodad++) {
switch (doodad->any.type) { static XkbBoundsRec tbounds;
case XkbOutlineDoodad:
case XkbSolidDoodad: switch (doodad->any.type) {
shape= XkbShapeDoodadShape(geom,&doodad->shape); case XkbOutlineDoodad:
rbounds= &shape->bounds; case XkbSolidDoodad:
break; shape = XkbShapeDoodadShape(geom, &doodad->shape);
case XkbTextDoodad: rbounds = &shape->bounds;
tbounds.x1= doodad->text.left; break;
tbounds.y1= doodad->text.top; case XkbTextDoodad:
tbounds.x2= tbounds.x1+doodad->text.width; tbounds.x1 = doodad->text.left;
tbounds.y2= tbounds.y1+doodad->text.height; tbounds.y1 = doodad->text.top;
rbounds= &tbounds; tbounds.x2 = tbounds.x1 + doodad->text.width;
break; tbounds.y2 = tbounds.y1 + doodad->text.height;
case XkbIndicatorDoodad: rbounds = &tbounds;
shape= XkbIndicatorDoodadShape(geom,&doodad->indicator); break;
rbounds= &shape->bounds; case XkbIndicatorDoodad:
break; shape = XkbIndicatorDoodadShape(geom, &doodad->indicator);
case XkbLogoDoodad: rbounds = &shape->bounds;
shape= XkbLogoDoodadShape(geom,&doodad->logo); break;
rbounds= &shape->bounds; case XkbLogoDoodad:
break; shape = XkbLogoDoodadShape(geom, &doodad->logo);
default: rbounds = &shape->bounds;
tbounds.x1= tbounds.x2= doodad->any.left; break;
tbounds.y1= tbounds.y2= doodad->any.top; default:
rbounds= &tbounds; tbounds.x1 = tbounds.x2 = doodad->any.left;
break; tbounds.y1 = tbounds.y2 = doodad->any.top;
} rbounds = &tbounds;
_XkbCheckBounds(bounds,rbounds->x1,rbounds->y1); break;
_XkbCheckBounds(bounds,rbounds->x2,rbounds->y2); }
_XkbCheckBounds(bounds, rbounds->x1, rbounds->y1);
_XkbCheckBounds(bounds, rbounds->x2, rbounds->y2);
} }
return True; return True;
} }
...@@ -197,39 +208,42 @@ XkbBoundsPtr bounds,rbounds; ...@@ -197,39 +208,42 @@ XkbBoundsPtr bounds,rbounds;
/***====================================================================***/ /***====================================================================***/
char * char *
XkbFindOverlayForKey(XkbGeometryPtr geom,XkbSectionPtr wanted,char *under) XkbFindOverlayForKey(XkbGeometryPtr geom, XkbSectionPtr wanted, char *under)
{ {
int s; int s;
XkbSectionPtr section; XkbSectionPtr section;
if ((geom==NULL)||(under==NULL)||(geom->num_sections<1)) if ((geom == NULL) || (under == NULL) || (geom->num_sections < 1))
return NULL; return NULL;
if (wanted) if (wanted)
section= wanted; section = wanted;
else section= geom->sections; else
section = geom->sections;
for (s=0;s<geom->num_sections;s++,section++) {
XkbOverlayPtr ol; for (s = 0; s < geom->num_sections; s++, section++) {
int o; XkbOverlayPtr ol;
int o;
if (section->num_overlays<1)
continue; if (section->num_overlays < 1)
for (o=0,ol=section->overlays;o<section->num_overlays;o++,ol++) { continue;
XkbOverlayRowPtr row; for (o = 0, ol = section->overlays; o < section->num_overlays;
int r; o++, ol++) {
XkbOverlayRowPtr row;
for (r=0,row=ol->rows;r<ol->num_rows;r++,row++) { int r;
XkbOverlayKeyPtr key;
int k; for (r = 0, row = ol->rows; r < ol->num_rows; r++, row++) {
for (k=0,key=row->keys;k<row->num_keys;k++,key++) { XkbOverlayKeyPtr key;
if (strncmp(under,key->under.name,XkbKeyNameLength)==0) int k;
return key->over.name;
} for (k = 0, key = row->keys; k < row->num_keys; k++, key++) {
} if (strncmp(under, key->under.name, XkbKeyNameLength) == 0)
} return key->over.name;
if (wanted!=NULL) }
break; }
}
if (wanted != NULL)
break;
} }
return NULL; return NULL;
} }
...@@ -237,463 +251,476 @@ XkbSectionPtr section; ...@@ -237,463 +251,476 @@ XkbSectionPtr section;
/***====================================================================***/ /***====================================================================***/
static Status static Status
_XkbReadGeomProperties( XkbReadBufferPtr buf, _XkbReadGeomProperties(XkbReadBufferPtr buf,
XkbGeometryPtr geom, XkbGeometryPtr geom,
xkbGetGeometryReply * rep) xkbGetGeometryReply *rep)
{ {
Status rtrn; Status rtrn;
if (rep->nProperties<1) if (rep->nProperties < 1)
return Success; return Success;
if ((rtrn=XkbAllocGeomProps(geom,rep->nProperties))==Success) { if ((rtrn = XkbAllocGeomProps(geom, rep->nProperties)) == Success) {
register int i; register int i;
register Bool ok; register Bool ok;
char *name,*value; char *name, *value;
ok= True;
for (i=0;(i<rep->nProperties)&&ok;i++) { ok = True;
name=NULL; for (i = 0; (i < rep->nProperties) && ok; i++) {
value=NULL; name = NULL;
ok= _XkbGetReadBufferCountedString(buf,&name)&&ok; value = NULL;
ok= _XkbGetReadBufferCountedString(buf,&value)&&ok; ok = _XkbGetReadBufferCountedString(buf, &name) && ok;
ok= ok&&(XkbAddGeomProperty(geom,name,value)!=NULL); ok = _XkbGetReadBufferCountedString(buf, &value) && ok;
if (name) ok = ok && (XkbAddGeomProperty(geom, name, value) != NULL);
_XkbFree(name); if (name)
if (value) _XkbFree(name);
_XkbFree(value); if (value)
} _XkbFree(value);
if (ok) rtrn= Success; }
else rtrn= BadLength; if (ok)
rtrn = Success;
else
rtrn = BadLength;
} }
return rtrn; return rtrn;
} }
static Status static Status
_XkbReadGeomKeyAliases( XkbReadBufferPtr buf, _XkbReadGeomKeyAliases(XkbReadBufferPtr buf,
XkbGeometryPtr geom, XkbGeometryPtr geom,
xkbGetGeometryReply * rep) xkbGetGeometryReply *rep)
{ {
Status rtrn; Status rtrn;
if (rep->nKeyAliases<1) if (rep->nKeyAliases < 1)
return Success; return Success;
if ((rtrn=XkbAllocGeomKeyAliases(geom,rep->nKeyAliases))==Success) { if ((rtrn = XkbAllocGeomKeyAliases(geom, rep->nKeyAliases)) == Success) {
if (!_XkbCopyFromReadBuffer(buf,(char *)geom->key_aliases, if (!_XkbCopyFromReadBuffer(buf, (char *) geom->key_aliases,
(rep->nKeyAliases*XkbKeyNameLength*2))) (rep->nKeyAliases * XkbKeyNameLength * 2)))
return BadLength; return BadLength;
geom->num_key_aliases= rep->nKeyAliases; geom->num_key_aliases = rep->nKeyAliases;
return Success; return Success;
} }
else { /* alloc failed, just skip the aliases */ else { /* alloc failed, just skip the aliases */
_XkbSkipReadBufferData(buf,(rep->nKeyAliases*XkbKeyNameLength*2)); _XkbSkipReadBufferData(buf, (rep->nKeyAliases * XkbKeyNameLength * 2));
} }
return rtrn; return rtrn;
} }
static Status static Status
_XkbReadGeomColors( XkbReadBufferPtr buf, _XkbReadGeomColors(XkbReadBufferPtr buf,
XkbGeometryPtr geom, XkbGeometryPtr geom,
xkbGetGeometryReply * rep) xkbGetGeometryReply *rep)
{ {
Status rtrn; Status rtrn;
if (rep->nColors<1) if (rep->nColors < 1)
return Success; return Success;
if ((rtrn=XkbAllocGeomColors(geom,rep->nColors))==Success) { if ((rtrn = XkbAllocGeomColors(geom, rep->nColors)) == Success) {
register int i; register int i;
char *spec; char *spec;
for (i=0;i<rep->nColors;i++) {
spec = NULL; for (i = 0; i < rep->nColors; i++) {
if (!_XkbGetReadBufferCountedString(buf,&spec)) spec = NULL;
rtrn = BadLength; if (!_XkbGetReadBufferCountedString(buf, &spec))
else if (XkbAddGeomColor(geom,spec,geom->num_colors)==NULL) rtrn = BadLength;
rtrn = BadAlloc; else if (XkbAddGeomColor(geom, spec, geom->num_colors) == NULL)
if (spec) rtrn = BadAlloc;
_XkbFree(spec); if (spec)
if (rtrn != Success) _XkbFree(spec);
return rtrn; if (rtrn != Success)
} return rtrn;
return Success; }
return Success;
} }
return rtrn; return rtrn;
} }
static Status static Status
_XkbReadGeomShapes( XkbReadBufferPtr buf, _XkbReadGeomShapes(XkbReadBufferPtr buf,
XkbGeometryPtr geom, XkbGeometryPtr geom,
xkbGetGeometryReply * rep) xkbGetGeometryReply *rep)
{ {
register int i; register int i;
Status rtrn; Status rtrn;
if (rep->nShapes<1) if (rep->nShapes < 1)
return Success; return Success;
if ((rtrn=XkbAllocGeomShapes(geom,rep->nShapes))!=Success) if ((rtrn = XkbAllocGeomShapes(geom, rep->nShapes)) != Success)
return rtrn; return rtrn;
for (i=0;i<rep->nShapes;i++) { for (i = 0; i < rep->nShapes; i++) {
xkbShapeWireDesc *shapeWire; xkbShapeWireDesc *shapeWire;
XkbShapePtr shape; XkbShapePtr shape;
register int o; register int o;
shapeWire= (xkbShapeWireDesc *)
_XkbGetReadBufferPtr(buf,SIZEOF(xkbShapeWireDesc)); shapeWire = (xkbShapeWireDesc *)
if (!shapeWire) _XkbGetReadBufferPtr(buf, SIZEOF(xkbShapeWireDesc));
return BadLength; if (!shapeWire)
shape= XkbAddGeomShape(geom,shapeWire->name,shapeWire->nOutlines); return BadLength;
if (!shape) shape = XkbAddGeomShape(geom, shapeWire->name, shapeWire->nOutlines);
return BadAlloc; if (!shape)
for (o=0;o<shapeWire->nOutlines;o++) { return BadAlloc;
xkbOutlineWireDesc *olWire; for (o = 0; o < shapeWire->nOutlines; o++) {
XkbOutlinePtr ol; xkbOutlineWireDesc *olWire;
register int p; XkbOutlinePtr ol;
XkbPointPtr pt; register int p;
olWire= (xkbOutlineWireDesc *) XkbPointPtr pt;
_XkbGetReadBufferPtr(buf,SIZEOF(xkbOutlineWireDesc));
if (!olWire) olWire = (xkbOutlineWireDesc *)
return BadLength; _XkbGetReadBufferPtr(buf, SIZEOF(xkbOutlineWireDesc));
ol= XkbAddGeomOutline(shape,olWire->nPoints); if (!olWire)
if (!ol) return BadLength;
return BadAlloc; ol = XkbAddGeomOutline(shape, olWire->nPoints);
ol->corner_radius= olWire->cornerRadius; if (!ol)
for (p=0,pt=ol->points;p<olWire->nPoints;p++,pt++) { return BadAlloc;
xkbPointWireDesc * ptWire; ol->corner_radius = olWire->cornerRadius;
ptWire= (xkbPointWireDesc *) for (p = 0, pt = ol->points; p < olWire->nPoints; p++, pt++) {
_XkbGetReadBufferPtr(buf,SIZEOF(xkbPointWireDesc)); xkbPointWireDesc *ptWire;
if (!ptWire)
return BadLength; ptWire = (xkbPointWireDesc *)
pt->x= ptWire->x; _XkbGetReadBufferPtr(buf, SIZEOF(xkbPointWireDesc));
pt->y= ptWire->y; if (!ptWire)
} return BadLength;
ol->num_points= olWire->nPoints; pt->x = ptWire->x;
} pt->y = ptWire->y;
if ((shapeWire->primaryNdx!=XkbNoShape) && }
(shapeWire->primaryNdx < shapeWire->nOutlines)) ol->num_points = olWire->nPoints;
shape->primary= &shape->outlines[shapeWire->primaryNdx]; }
else if ((shapeWire->primaryNdx != XkbNoShape) &&
shape->primary= NULL; (shapeWire->primaryNdx < shapeWire->nOutlines))
if ((shapeWire->approxNdx!=XkbNoShape) && shape->primary = &shape->outlines[shapeWire->primaryNdx];
(shapeWire->approxNdx < shapeWire->nOutlines)) else
shape->approx= &shape->outlines[shapeWire->approxNdx]; shape->primary = NULL;
else if ((shapeWire->approxNdx != XkbNoShape) &&
shape->approx= NULL; (shapeWire->approxNdx < shapeWire->nOutlines))
XkbComputeShapeBounds(shape); shape->approx = &shape->outlines[shapeWire->approxNdx];
else
shape->approx = NULL;
XkbComputeShapeBounds(shape);
} }
return Success; return Success;
} }
static Status static Status
_XkbReadGeomDoodad( XkbReadBufferPtr buf, _XkbReadGeomDoodad(XkbReadBufferPtr buf,
XkbGeometryPtr geom, XkbGeometryPtr geom,
XkbSectionPtr section) XkbSectionPtr section)
{ {
XkbDoodadPtr doodad; XkbDoodadPtr doodad;
xkbDoodadWireDesc * doodadWire; xkbDoodadWireDesc *doodadWire;
doodadWire= (xkbDoodadWireDesc *) doodadWire = (xkbDoodadWireDesc *)
_XkbGetReadBufferPtr(buf,SIZEOF(xkbDoodadWireDesc)); _XkbGetReadBufferPtr(buf, SIZEOF(xkbDoodadWireDesc));
if (!doodadWire) if (!doodadWire)
return BadLength; return BadLength;
doodad= XkbAddGeomDoodad(geom,section,doodadWire->any.name); doodad = XkbAddGeomDoodad(geom, section, doodadWire->any.name);
if (!doodad) if (!doodad)
return BadAlloc; return BadAlloc;
doodad->any.type= doodadWire->any.type; doodad->any.type = doodadWire->any.type;
doodad->any.priority= doodadWire->any.priority; doodad->any.priority = doodadWire->any.priority;
doodad->any.top= doodadWire->any.top; doodad->any.top = doodadWire->any.top;
doodad->any.left= doodadWire->any.left; doodad->any.left = doodadWire->any.left;
doodad->any.angle= doodadWire->any.angle; doodad->any.angle = doodadWire->any.angle;
switch (doodad->any.type) { switch (doodad->any.type) {
case XkbOutlineDoodad: case XkbOutlineDoodad:
case XkbSolidDoodad: case XkbSolidDoodad:
doodad->shape.color_ndx= doodadWire->shape.colorNdx; doodad->shape.color_ndx = doodadWire->shape.colorNdx;
doodad->shape.shape_ndx= doodadWire->shape.shapeNdx; doodad->shape.shape_ndx = doodadWire->shape.shapeNdx;
break; break;
case XkbTextDoodad: case XkbTextDoodad:
doodad->text.width= doodadWire->text.width; doodad->text.width = doodadWire->text.width;
doodad->text.height= doodadWire->text.height; doodad->text.height = doodadWire->text.height;
doodad->text.color_ndx= doodadWire->text.colorNdx; doodad->text.color_ndx = doodadWire->text.colorNdx;
if (!_XkbGetReadBufferCountedString(buf,&doodad->text.text)) if (!_XkbGetReadBufferCountedString(buf, &doodad->text.text))
return BadLength; return BadLength;
if (!_XkbGetReadBufferCountedString(buf,&doodad->text.font)) if (!_XkbGetReadBufferCountedString(buf, &doodad->text.font))
return BadLength; return BadLength;
break; break;
case XkbIndicatorDoodad: case XkbIndicatorDoodad:
doodad->indicator.shape_ndx= doodadWire->indicator.shapeNdx; doodad->indicator.shape_ndx = doodadWire->indicator.shapeNdx;
doodad->indicator.on_color_ndx= doodadWire->indicator.onColorNdx; doodad->indicator.on_color_ndx = doodadWire->indicator.onColorNdx;
doodad->indicator.off_color_ndx= doodadWire->indicator.offColorNdx; doodad->indicator.off_color_ndx = doodadWire->indicator.offColorNdx;
break; break;
case XkbLogoDoodad: case XkbLogoDoodad:
doodad->logo.color_ndx= doodadWire->logo.colorNdx; doodad->logo.color_ndx = doodadWire->logo.colorNdx;
doodad->logo.shape_ndx= doodadWire->logo.shapeNdx; doodad->logo.shape_ndx = doodadWire->logo.shapeNdx;
if (!_XkbGetReadBufferCountedString(buf,&doodad->logo.logo_name)) if (!_XkbGetReadBufferCountedString(buf, &doodad->logo.logo_name))
return BadLength; return BadLength;
break; break;
default: default:
return BadValue; return BadValue;
} }
return Success; return Success;
} }
static Status static Status
_XkbReadGeomOverlay( XkbReadBufferPtr buf, _XkbReadGeomOverlay(XkbReadBufferPtr buf,
XkbGeometryPtr geom, XkbGeometryPtr geom,
XkbSectionPtr section) XkbSectionPtr section)
{ {
XkbOverlayPtr ol; XkbOverlayPtr ol;
xkbOverlayWireDesc * olWire; xkbOverlayWireDesc *olWire;
register int r; register int r;
olWire= (xkbOverlayWireDesc *) olWire = (xkbOverlayWireDesc *)
_XkbGetReadBufferPtr(buf,SIZEOF(xkbOverlayWireDesc)); _XkbGetReadBufferPtr(buf, SIZEOF(xkbOverlayWireDesc));
if (olWire==NULL) if (olWire == NULL)
return BadLength; return BadLength;
ol= XkbAddGeomOverlay(section,olWire->name,olWire->nRows); ol = XkbAddGeomOverlay(section, olWire->name, olWire->nRows);
if (ol==NULL) if (ol == NULL)
return BadLength; return BadLength;
for (r=0;r<olWire->nRows;r++) { for (r = 0; r < olWire->nRows; r++) {
register int k; register int k;
XkbOverlayRowPtr row; XkbOverlayRowPtr row;
xkbOverlayRowWireDesc * rowWire; xkbOverlayRowWireDesc *rowWire;
xkbOverlayKeyWireDesc * keyWire; xkbOverlayKeyWireDesc *keyWire;
rowWire= (xkbOverlayRowWireDesc *)
_XkbGetReadBufferPtr(buf,SIZEOF(xkbOverlayRowWireDesc)); rowWire = (xkbOverlayRowWireDesc *)
if (rowWire==NULL) _XkbGetReadBufferPtr(buf, SIZEOF(xkbOverlayRowWireDesc));
return BadLength; if (rowWire == NULL)
row= XkbAddGeomOverlayRow(ol,rowWire->rowUnder,rowWire->nKeys); return BadLength;
row->row_under= rowWire->rowUnder; row = XkbAddGeomOverlayRow(ol, rowWire->rowUnder, rowWire->nKeys);
if (!row) row->row_under = rowWire->rowUnder;
return BadAlloc; if (!row)
if (rowWire->nKeys<1) return BadAlloc;
continue; if (rowWire->nKeys < 1)
keyWire= (xkbOverlayKeyWireDesc *) continue;
_XkbGetReadBufferPtr(buf, keyWire = (xkbOverlayKeyWireDesc *)
SIZEOF(xkbOverlayKeyWireDesc)*rowWire->nKeys); _XkbGetReadBufferPtr(buf,
if (keyWire==NULL) SIZEOF(xkbOverlayKeyWireDesc) * rowWire->nKeys);
return BadLength; if (keyWire == NULL)
for (k=0;k<rowWire->nKeys;k++,keyWire++,row->num_keys++) { return BadLength;
memcpy(row->keys[row->num_keys].over.name,keyWire->over, for (k = 0; k < rowWire->nKeys; k++, keyWire++, row->num_keys++) {
XkbKeyNameLength); memcpy(row->keys[row->num_keys].over.name, keyWire->over,
memcpy(row->keys[row->num_keys].under.name,keyWire->under, XkbKeyNameLength);
XkbKeyNameLength); memcpy(row->keys[row->num_keys].under.name, keyWire->under,
} XkbKeyNameLength);
}
} }
return Success; return Success;
} }
static Status static Status
_XkbReadGeomSections( XkbReadBufferPtr buf, _XkbReadGeomSections(XkbReadBufferPtr buf,
XkbGeometryPtr geom, XkbGeometryPtr geom,
xkbGetGeometryReply * rep) xkbGetGeometryReply *rep)
{ {
register int s; register int s;
XkbSectionPtr section; XkbSectionPtr section;
xkbSectionWireDesc * sectionWire; xkbSectionWireDesc *sectionWire;
Status rtrn; Status rtrn;
if (rep->nSections<1) if (rep->nSections < 1)
return Success; return Success;
if ((rtrn=XkbAllocGeomSections(geom,rep->nSections))!=Success) if ((rtrn = XkbAllocGeomSections(geom, rep->nSections)) != Success)
return rtrn; return rtrn;
for (s=0;s<rep->nSections;s++) { for (s = 0; s < rep->nSections; s++) {
sectionWire= (xkbSectionWireDesc *) sectionWire = (xkbSectionWireDesc *)
_XkbGetReadBufferPtr(buf,SIZEOF(xkbSectionWireDesc)); _XkbGetReadBufferPtr(buf, SIZEOF(xkbSectionWireDesc));
if (!sectionWire) if (!sectionWire)
return BadLength; return BadLength;
section= XkbAddGeomSection(geom,sectionWire->name,sectionWire->nRows, section = XkbAddGeomSection(geom, sectionWire->name, sectionWire->nRows,
sectionWire->nDoodads, sectionWire->nDoodads,
sectionWire->nOverlays); sectionWire->nOverlays);
if (!section) if (!section)
return BadAlloc; return BadAlloc;
section->top= sectionWire->top; section->top = sectionWire->top;
section->left= sectionWire->left; section->left = sectionWire->left;
section->width= sectionWire->width; section->width = sectionWire->width;
section->height= sectionWire->height; section->height = sectionWire->height;
section->angle= sectionWire->angle; section->angle = sectionWire->angle;
section->priority= sectionWire->priority; section->priority = sectionWire->priority;
if (sectionWire->nRows>0) { if (sectionWire->nRows > 0) {
register int r; register int r;
XkbRowPtr row; XkbRowPtr row;
xkbRowWireDesc * rowWire; xkbRowWireDesc *rowWire;
for (r=0;r<sectionWire->nRows;r++) {
rowWire= (xkbRowWireDesc *) for (r = 0; r < sectionWire->nRows; r++) {
_XkbGetReadBufferPtr(buf,SIZEOF(xkbRowWireDesc)); rowWire = (xkbRowWireDesc *)
if (!rowWire) _XkbGetReadBufferPtr(buf, SIZEOF(xkbRowWireDesc));
return BadLength; if (!rowWire)
row= XkbAddGeomRow(section,rowWire->nKeys); return BadLength;
if (!row) row = XkbAddGeomRow(section, rowWire->nKeys);
return BadAlloc; if (!row)
row->top= rowWire->top; return BadAlloc;
row->left= rowWire->left; row->top = rowWire->top;
row->vertical= rowWire->vertical; row->left = rowWire->left;
if (rowWire->nKeys>0) { row->vertical = rowWire->vertical;
register int k; if (rowWire->nKeys > 0) {
XkbKeyPtr key; register int k;
xkbKeyWireDesc * keyWire; XkbKeyPtr key;
for (k=0;k<rowWire->nKeys;k++) { xkbKeyWireDesc *keyWire;
keyWire= (xkbKeyWireDesc *)
_XkbGetReadBufferPtr(buf,SIZEOF(xkbKeyWireDesc)); for (k = 0; k < rowWire->nKeys; k++) {
if (!keyWire) keyWire = (xkbKeyWireDesc *)
return BadLength; _XkbGetReadBufferPtr(buf, SIZEOF(xkbKeyWireDesc));
key= XkbAddGeomKey(row); if (!keyWire)
if (!key) return BadLength;
return BadAlloc; key = XkbAddGeomKey(row);
memcpy(key->name.name,keyWire->name,XkbKeyNameLength); if (!key)
key->gap= keyWire->gap; return BadAlloc;
key->shape_ndx= keyWire->shapeNdx; memcpy(key->name.name, keyWire->name, XkbKeyNameLength);
key->color_ndx= keyWire->colorNdx; key->gap = keyWire->gap;
} key->shape_ndx = keyWire->shapeNdx;
} key->color_ndx = keyWire->colorNdx;
} }
} }
if (sectionWire->nDoodads>0) { }
register int d; }
for (d=0;d<sectionWire->nDoodads;d++) { if (sectionWire->nDoodads > 0) {
if ((rtrn=_XkbReadGeomDoodad(buf,geom,section))!=Success) register int d;
return rtrn;
} for (d = 0; d < sectionWire->nDoodads; d++) {
} if ((rtrn = _XkbReadGeomDoodad(buf, geom, section)) != Success)
if (sectionWire->nOverlays>0) { return rtrn;
register int o; }
for (o=0;o<sectionWire->nOverlays;o++) { }
if ((rtrn=_XkbReadGeomOverlay(buf,geom,section))!=Success) if (sectionWire->nOverlays > 0) {
return rtrn; register int o;
}
} for (o = 0; o < sectionWire->nOverlays; o++) {
if ((rtrn = _XkbReadGeomOverlay(buf, geom, section)) != Success)
return rtrn;
}
}
} }
return Success; return Success;
} }
static Status static Status
_XkbReadGeomDoodads( XkbReadBufferPtr buf, _XkbReadGeomDoodads(XkbReadBufferPtr buf,
XkbGeometryPtr geom, XkbGeometryPtr geom,
xkbGetGeometryReply * rep) xkbGetGeometryReply *rep)
{ {
register int d; register int d;
Status rtrn; Status rtrn;
if (rep->nDoodads<1) if (rep->nDoodads < 1)
return Success; return Success;
if ((rtrn=XkbAllocGeomDoodads(geom,rep->nDoodads))!=Success) if ((rtrn = XkbAllocGeomDoodads(geom, rep->nDoodads)) != Success)
return rtrn; return rtrn;
for (d=0;d<rep->nDoodads;d++) { for (d = 0; d < rep->nDoodads; d++) {
if ((rtrn=_XkbReadGeomDoodad(buf,geom,NULL))!=Success) if ((rtrn = _XkbReadGeomDoodad(buf, geom, NULL)) != Success)
return rtrn; return rtrn;
} }
return Success; return Success;
} }
Status Status
_XkbReadGetGeometryReply( Display * dpy, _XkbReadGetGeometryReply(Display *dpy,
xkbGetGeometryReply * rep, xkbGetGeometryReply *rep,
XkbDescPtr xkb, XkbDescPtr xkb,
int * nread_rtrn) int *nread_rtrn)
{ {
XkbGeometryPtr geom; XkbGeometryPtr geom;
geom= _XkbTypedCalloc(1,XkbGeometryRec); geom = _XkbTypedCalloc(1, XkbGeometryRec);
if (!geom) if (!geom)
return BadAlloc; return BadAlloc;
if (xkb->geom) if (xkb->geom)
XkbFreeGeometry(xkb->geom,XkbGeomAllMask,True); XkbFreeGeometry(xkb->geom, XkbGeomAllMask, True);
xkb->geom= geom; xkb->geom = geom;
geom->name= rep->name; geom->name = rep->name;
geom->width_mm= rep->widthMM; geom->width_mm = rep->widthMM;
geom->height_mm= rep->heightMM; geom->height_mm = rep->heightMM;
if (rep->length) { if (rep->length) {
XkbReadBufferRec buf; XkbReadBufferRec buf;
int left; int left;
if (_XkbInitReadBuffer(dpy,&buf,(int)rep->length*4)) {
Status status= Success; if (_XkbInitReadBuffer(dpy, &buf, (int) rep->length * 4)) {
if (nread_rtrn) Status status = Success;
*nread_rtrn= (int)rep->length*4;
if (!_XkbGetReadBufferCountedString(&buf,&geom->label_font)) if (nread_rtrn)
status= BadLength; *nread_rtrn = (int) rep->length * 4;
if (status==Success) if (!_XkbGetReadBufferCountedString(&buf, &geom->label_font))
status= _XkbReadGeomProperties(&buf,geom,rep); status = BadLength;
if (status==Success) if (status == Success)
status= _XkbReadGeomColors(&buf,geom,rep); status = _XkbReadGeomProperties(&buf, geom, rep);
if (status==Success) if (status == Success)
status= _XkbReadGeomShapes(&buf,geom,rep); status = _XkbReadGeomColors(&buf, geom, rep);
if (status==Success) if (status == Success)
status= _XkbReadGeomSections(&buf,geom,rep); status = _XkbReadGeomShapes(&buf, geom, rep);
if (status==Success) if (status == Success)
status= _XkbReadGeomDoodads(&buf,geom,rep); status = _XkbReadGeomSections(&buf, geom, rep);
if (status==Success) if (status == Success)
status= _XkbReadGeomKeyAliases(&buf,geom,rep); status = _XkbReadGeomDoodads(&buf, geom, rep);
left= _XkbFreeReadBuffer(&buf); if (status == Success)
if ((rep->baseColorNdx > geom->num_colors) || status = _XkbReadGeomKeyAliases(&buf, geom, rep);
(rep->labelColorNdx > geom->num_colors)) left = _XkbFreeReadBuffer(&buf);
status = BadLength; if ((rep->baseColorNdx > geom->num_colors) ||
if ((status!=Success) || left || buf.error) { (rep->labelColorNdx > geom->num_colors))
if (status==Success) status = BadLength;
status= BadLength; if ((status != Success) || left || buf.error) {
XkbFreeGeometry(geom,XkbGeomAllMask,True); if (status == Success)
xkb->geom= NULL; status = BadLength;
return status; XkbFreeGeometry(geom, XkbGeomAllMask, True);
} xkb->geom = NULL;
geom->base_color= &geom->colors[rep->baseColorNdx]; return status;
geom->label_color= &geom->colors[rep->labelColorNdx]; }
} geom->base_color = &geom->colors[rep->baseColorNdx];
else { geom->label_color = &geom->colors[rep->labelColorNdx];
XkbFreeGeometry(geom,XkbGeomAllMask,True); }
xkb->geom= NULL; else {
return BadAlloc; XkbFreeGeometry(geom, XkbGeomAllMask, True);
} xkb->geom = NULL;
return BadAlloc;
}
} }
return Success; return Success;
} }
Status Status
XkbGetGeometry(Display *dpy,XkbDescPtr xkb) XkbGetGeometry(Display *dpy, XkbDescPtr xkb)
{ {
xkbGetGeometryReq *req; xkbGetGeometryReq *req;
xkbGetGeometryReply rep; xkbGetGeometryReply rep;
Status status; Status status;
if ( (!xkb) || (dpy->flags & XlibDisplayNoXkb) || if ((!xkb) || (dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return BadAccess; return BadAccess;
LockDisplay(dpy); LockDisplay(dpy);
GetReq(kbGetGeometry, req); GetReq(kbGetGeometry, req);
req->reqType = dpy->xkb_info->codes->major_opcode; req->reqType = dpy->xkb_info->codes->major_opcode;
req->xkbReqType = X_kbGetGeometry; req->xkbReqType = X_kbGetGeometry;
req->deviceSpec = xkb->device_spec; req->deviceSpec = xkb->device_spec;
req->name= None; req->name = None;
if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) if (!_XReply(dpy, (xReply *) &rep, 0, xFalse))
status = BadImplementation; status = BadImplementation;
else if (!rep.found) else if (!rep.found)
status = BadName; status = BadName;
else else
status = _XkbReadGetGeometryReply(dpy,&rep,xkb,NULL); status = _XkbReadGetGeometryReply(dpy, &rep, xkb, NULL);
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
return status; return status;
} }
Status Status
XkbGetNamedGeometry(Display *dpy,XkbDescPtr xkb,Atom name) XkbGetNamedGeometry(Display *dpy, XkbDescPtr xkb, Atom name)
{ {
xkbGetGeometryReq *req; xkbGetGeometryReq *req;
xkbGetGeometryReply rep; xkbGetGeometryReply rep;
Status status; Status status;
if ( (name==None) || (dpy->flags & XlibDisplayNoXkb) || if ((name == None) || (dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)) ) (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return BadAccess; return BadAccess;
LockDisplay(dpy); LockDisplay(dpy);
GetReq(kbGetGeometry, req); GetReq(kbGetGeometry, req);
req->reqType = dpy->xkb_info->codes->major_opcode; req->reqType = dpy->xkb_info->codes->major_opcode;
req->xkbReqType = X_kbGetGeometry; req->xkbReqType = X_kbGetGeometry;
req->deviceSpec = xkb->device_spec; req->deviceSpec = xkb->device_spec;
req->name= (CARD32)name; req->name = (CARD32) name;
if ((!_XReply(dpy, (xReply *)&rep, 0, xFalse))||(!rep.found)) if ((!_XReply(dpy, (xReply *) &rep, 0, xFalse)) || (!rep.found))
status = BadImplementation; status = BadImplementation;
else if (!rep.found) else if (!rep.found)
status = BadName; status = BadName;
else else
status = _XkbReadGetGeometryReply(dpy,&rep,xkb,NULL); status = _XkbReadGetGeometryReply(dpy, &rep, xkb, NULL);
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
return status; return status;
} }
...@@ -35,32 +35,32 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. ...@@ -35,32 +35,32 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
/***====================================================================***/ /***====================================================================***/
XkbDescPtr XkbDescPtr
XkbGetKeyboardByName( Display * dpy, XkbGetKeyboardByName(Display *dpy,
unsigned deviceSpec, unsigned deviceSpec,
XkbComponentNamesPtr names, XkbComponentNamesPtr names,
unsigned want, unsigned want,
unsigned need, unsigned need,
Bool load) Bool load)
{ {
register xkbGetKbdByNameReq * req; register xkbGetKbdByNameReq *req;
xkbGetKbdByNameReply rep; xkbGetKbdByNameReply rep;
int len,extraLen; int len, extraLen;
char * str; char *str;
XkbDescPtr xkb; XkbDescPtr xkb;
int mapLen,codesLen,typesLen,compatLen; int mapLen, codesLen, typesLen, compatLen;
int symsLen,geomLen; int symsLen, geomLen;
XkbInfoPtr xkbi; XkbInfoPtr xkbi;
if ( (dpy==NULL) || (dpy->flags & XlibDisplayNoXkb) || if ((dpy == NULL) || (dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)) ) (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return NULL; return NULL;
xkbi= dpy->xkb_info; xkbi = dpy->xkb_info;
xkb = (XkbDescRec *)_XkbCalloc(1,sizeof(XkbDescRec)); xkb = (XkbDescRec *) _XkbCalloc(1, sizeof(XkbDescRec));
if (!xkb) if (!xkb)
return NULL; return NULL;
xkb->device_spec = deviceSpec; xkb->device_spec = deviceSpec;
xkb->map = (XkbClientMapRec *)_XkbCalloc(1,sizeof(XkbClientMapRec)); xkb->map = (XkbClientMapRec *) _XkbCalloc(1, sizeof(XkbClientMapRec));
xkb->dpy = dpy; xkb->dpy = dpy;
LockDisplay(dpy); LockDisplay(dpy);
...@@ -68,147 +68,155 @@ XkbGetKeyboardByName( Display * dpy, ...@@ -68,147 +68,155 @@ XkbGetKeyboardByName( Display * dpy,
req->reqType = xkbi->codes->major_opcode; req->reqType = xkbi->codes->major_opcode;
req->xkbReqType = X_kbGetKbdByName; req->xkbReqType = X_kbGetKbdByName;
req->deviceSpec = xkb->device_spec; req->deviceSpec = xkb->device_spec;
req->want= want; req->want = want;
req->need= need; req->need = need;
req->load= load; req->load = load;
mapLen= codesLen= typesLen= compatLen= symsLen= geomLen= 0; mapLen = codesLen = typesLen = compatLen = symsLen = geomLen = 0;
if (names) { if (names) {
if (names->keymap) if (names->keymap)
mapLen= (int)strlen(names->keymap); mapLen = (int) strlen(names->keymap);
if (names->keycodes) if (names->keycodes)
codesLen= (int)strlen(names->keycodes); codesLen = (int) strlen(names->keycodes);
if (names->types) if (names->types)
typesLen= (int)strlen(names->types); typesLen = (int) strlen(names->types);
if (names->compat) if (names->compat)
compatLen= (int)strlen(names->compat); compatLen = (int) strlen(names->compat);
if (names->symbols) if (names->symbols)
symsLen= (int)strlen(names->symbols); symsLen = (int) strlen(names->symbols);
if (names->geometry) if (names->geometry)
geomLen= (int)strlen(names->geometry); geomLen = (int) strlen(names->geometry);
if (mapLen>255) mapLen= 255; if (mapLen > 255)
if (codesLen>255) codesLen= 255; mapLen = 255;
if (typesLen>255) typesLen= 255; if (codesLen > 255)
if (compatLen>255) compatLen= 255; codesLen = 255;
if (symsLen>255) symsLen= 255; if (typesLen > 255)
if (geomLen>255) geomLen= 255; typesLen = 255;
if (compatLen > 255)
compatLen = 255;
if (symsLen > 255)
symsLen = 255;
if (geomLen > 255)
geomLen = 255;
} }
else mapLen= codesLen= typesLen= compatLen= symsLen= geomLen= 0; else
mapLen = codesLen = typesLen = compatLen = symsLen = geomLen = 0;
len= mapLen+codesLen+typesLen+compatLen+symsLen+geomLen+6;
len= XkbPaddedSize(len); len = mapLen + codesLen + typesLen + compatLen + symsLen + geomLen + 6;
req->length+= len/4; len = XkbPaddedSize(len);
BufAlloc(char *,str,len); req->length += len / 4;
*str++= mapLen; BufAlloc(char *, str, len);
if (mapLen>0) {
memcpy(str,names->keymap,mapLen); *str++ = mapLen;
str+= mapLen; if (mapLen > 0) {
memcpy(str, names->keymap, mapLen);
str += mapLen;
} }
*str++= codesLen; *str++ = codesLen;
if (codesLen>0) { if (codesLen > 0) {
memcpy(str,names->keycodes,codesLen); memcpy(str, names->keycodes, codesLen);
str+= codesLen; str += codesLen;
} }
*str++= typesLen; *str++ = typesLen;
if (typesLen>0) { if (typesLen > 0) {
memcpy(str,names->types,typesLen); memcpy(str, names->types, typesLen);
str+= typesLen; str += typesLen;
} }
*str++= compatLen; *str++ = compatLen;
if (compatLen>0) { if (compatLen > 0) {
memcpy(str,names->compat,compatLen); memcpy(str, names->compat, compatLen);
str+= compatLen; str += compatLen;
} }
*str++= symsLen; *str++ = symsLen;
if (symsLen>0) { if (symsLen > 0) {
memcpy(str,names->symbols,symsLen); memcpy(str, names->symbols, symsLen);
str+= symsLen; str += symsLen;
} }
*str++= geomLen; *str++ = geomLen;
if (geomLen>0) { if (geomLen > 0) {
memcpy(str,names->geometry,geomLen); memcpy(str, names->geometry, geomLen);
str+= geomLen; str += geomLen;
} }
if ((!_XReply(dpy, (xReply *)&rep, 0, xFalse))||(!rep.reported)) if ((!_XReply(dpy, (xReply *) &rep, 0, xFalse)) || (!rep.reported))
goto BAILOUT; goto BAILOUT;
extraLen= (int)rep.length*4; extraLen = (int) rep.length * 4;
xkb->device_spec= rep.deviceID; xkb->device_spec = rep.deviceID;
xkb->min_key_code = rep.minKeyCode; xkb->min_key_code = rep.minKeyCode;
xkb->max_key_code = rep.maxKeyCode; xkb->max_key_code = rep.maxKeyCode;
if (rep.reported&(XkbGBN_SymbolsMask|XkbGBN_TypesMask)) { if (rep.reported & (XkbGBN_SymbolsMask | XkbGBN_TypesMask)) {
xkbGetMapReply mrep; xkbGetMapReply mrep;
Status status; Status status;
int nread= 0; int nread = 0;
_XRead(dpy, (char *)&mrep, SIZEOF(xkbGetMapReply)); _XRead(dpy, (char *) &mrep, SIZEOF(xkbGetMapReply));
extraLen-= SIZEOF(xkbGetMapReply); extraLen -= SIZEOF(xkbGetMapReply);
status= _XkbReadGetMapReply(dpy,&mrep,xkb,&nread); status = _XkbReadGetMapReply(dpy, &mrep, xkb, &nread);
extraLen-= nread; extraLen -= nread;
if (status!=Success) if (status != Success)
goto BAILOUT; goto BAILOUT;
} }
if (rep.reported&XkbGBN_CompatMapMask) { if (rep.reported & XkbGBN_CompatMapMask) {
xkbGetCompatMapReply crep; xkbGetCompatMapReply crep;
Status status; Status status;
int nread= 0; int nread = 0;
_XRead(dpy, (char *)&crep, SIZEOF(xkbGetCompatMapReply)); _XRead(dpy, (char *) &crep, SIZEOF(xkbGetCompatMapReply));
extraLen-= SIZEOF(xkbGetCompatMapReply); extraLen -= SIZEOF(xkbGetCompatMapReply);
status= _XkbReadGetCompatMapReply(dpy,&crep,xkb,&nread); status = _XkbReadGetCompatMapReply(dpy, &crep, xkb, &nread);
extraLen-= nread; extraLen -= nread;
if (status!=Success) if (status != Success)
goto BAILOUT; goto BAILOUT;
} }
if (rep.reported&XkbGBN_IndicatorMapMask) { if (rep.reported & XkbGBN_IndicatorMapMask) {
xkbGetIndicatorMapReply irep; xkbGetIndicatorMapReply irep;
Status status; Status status;
int nread= 0; int nread = 0;
_XRead(dpy, (char *)&irep, SIZEOF(xkbGetIndicatorMapReply)); _XRead(dpy, (char *) &irep, SIZEOF(xkbGetIndicatorMapReply));
extraLen-= SIZEOF(xkbGetIndicatorMapReply); extraLen -= SIZEOF(xkbGetIndicatorMapReply);
status= _XkbReadGetIndicatorMapReply(dpy,&irep,xkb,&nread); status = _XkbReadGetIndicatorMapReply(dpy, &irep, xkb, &nread);
extraLen-= nread; extraLen -= nread;
if (status!=Success) if (status != Success)
goto BAILOUT; goto BAILOUT;
} }
if (rep.reported&(XkbGBN_KeyNamesMask|XkbGBN_OtherNamesMask)) { if (rep.reported & (XkbGBN_KeyNamesMask | XkbGBN_OtherNamesMask)) {
xkbGetNamesReply nrep; xkbGetNamesReply nrep;
Status status; Status status;
int nread= 0; int nread = 0;
_XRead(dpy, (char *)&nrep, SIZEOF(xkbGetNamesReply)); _XRead(dpy, (char *) &nrep, SIZEOF(xkbGetNamesReply));
extraLen-= SIZEOF(xkbGetNamesReply); extraLen -= SIZEOF(xkbGetNamesReply);
status= _XkbReadGetNamesReply(dpy,&nrep,xkb,&nread); status = _XkbReadGetNamesReply(dpy, &nrep, xkb, &nread);
extraLen-= nread; extraLen -= nread;
if (status!=Success) if (status != Success)
goto BAILOUT; goto BAILOUT;
} }
if (rep.reported&XkbGBN_GeometryMask) { if (rep.reported & XkbGBN_GeometryMask) {
xkbGetGeometryReply grep; xkbGetGeometryReply grep;
Status status; Status status;
int nread= 0; int nread = 0;
_XRead(dpy, (char *)&grep, SIZEOF(xkbGetGeometryReply)); _XRead(dpy, (char *) &grep, SIZEOF(xkbGetGeometryReply));
extraLen-= SIZEOF(xkbGetGeometryReply); extraLen -= SIZEOF(xkbGetGeometryReply);
status= _XkbReadGetGeometryReply(dpy,&grep,xkb,&nread); status = _XkbReadGetGeometryReply(dpy, &grep, xkb, &nread);
extraLen-= nread; extraLen -= nread;
if (status!=Success) if (status != Success)
goto BAILOUT; goto BAILOUT;
} }
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
return xkb; return xkb;
BAILOUT: BAILOUT:
if (xkb!=NULL) if (xkb != NULL)
XkbFreeKeyboard(xkb,XkbAllComponentsMask,xTrue); XkbFreeKeyboard(xkb, XkbAllComponentsMask, xTrue);
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
return NULL; return NULL;
} }
XkbDescPtr XkbDescPtr
XkbGetKeyboard(Display *dpy,unsigned which,unsigned deviceSpec) XkbGetKeyboard(Display *dpy, unsigned which, unsigned deviceSpec)
{ {
return XkbGetKeyboardByName(dpy,deviceSpec,NULL,which,which,False); return XkbGetKeyboardByName(dpy, deviceSpec, NULL, which, which, False);
} }
...@@ -33,428 +33,444 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. ...@@ -33,428 +33,444 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "XKBlibint.h" #include "XKBlibint.h"
static Status static Status
_XkbReadKeyTypes(XkbReadBufferPtr buf,XkbDescPtr xkb,xkbGetMapReply *rep) _XkbReadKeyTypes(XkbReadBufferPtr buf, XkbDescPtr xkb, xkbGetMapReply *rep)
{ {
int i,n,lastMapCount; int i, n, lastMapCount;
XkbKeyTypePtr type; XkbKeyTypePtr type;
if ( rep->nTypes>0 ) { if (rep->nTypes > 0) {
n = rep->firstType+rep->nTypes; n = rep->firstType + rep->nTypes;
if (xkb->map->num_types>=n) if (xkb->map->num_types >= n)
n= xkb->map->num_types; n = xkb->map->num_types;
else if (XkbAllocClientMap(xkb,XkbKeyTypesMask,n)!=Success) else if (XkbAllocClientMap(xkb, XkbKeyTypesMask, n) != Success)
return BadAlloc; return BadAlloc;
type = &xkb->map->types[rep->firstType]; type = &xkb->map->types[rep->firstType];
for (i=0;i<(int)rep->nTypes;i++,type++) { for (i = 0; i < (int) rep->nTypes; i++, type++) {
xkbKeyTypeWireDesc *desc; xkbKeyTypeWireDesc *desc;
register int ndx; register int ndx;
ndx= i+rep->firstType; ndx = i + rep->firstType;
if (ndx>=xkb->map->num_types) if (ndx >= xkb->map->num_types)
xkb->map->num_types= ndx+1; xkb->map->num_types = ndx + 1;
desc= (xkbKeyTypeWireDesc *)_XkbGetReadBufferPtr(buf, desc = (xkbKeyTypeWireDesc *)
SIZEOF(xkbKeyTypeWireDesc)); _XkbGetReadBufferPtr(buf, SIZEOF(xkbKeyTypeWireDesc));
if (desc==NULL) if (desc == NULL)
return BadLength; return BadLength;
lastMapCount= type->map_count; lastMapCount = type->map_count;
if ( desc->nMapEntries>0 ) { if (desc->nMapEntries > 0) {
if ((type->map==NULL)||(desc->nMapEntries>type->map_count)) { if ((type->map == NULL) ||
XkbKTMapEntryRec *prev_map = type->map; (desc->nMapEntries > type->map_count)) {
XkbKTMapEntryRec *prev_map = type->map;
type->map= _XkbTypedRealloc(type->map,desc->nMapEntries,
XkbKTMapEntryRec); type->map = _XkbTypedRealloc(type->map, desc->nMapEntries,
if (type->map==NULL) { XkbKTMapEntryRec);
_XkbFree(prev_map); if (type->map == NULL) {
return BadAlloc; _XkbFree(prev_map);
} return BadAlloc;
} }
} }
else if (type->map!=NULL) { }
Xfree(type->map); else if (type->map != NULL) {
type->map_count= 0; Xfree(type->map);
type->map= NULL; type->map_count = 0;
} type->map = NULL;
}
if ( desc->preserve && (desc->nMapEntries>0) ) {
if ((!type->preserve)|| if (desc->preserve && (desc->nMapEntries > 0)) {
(desc->nMapEntries>lastMapCount)) { if ((!type->preserve) || (desc->nMapEntries > lastMapCount)) {
XkbModsRec *prev_preserve = type->preserve; XkbModsRec *prev_preserve = type->preserve;
type->preserve= _XkbTypedRealloc(type->preserve, type->preserve = _XkbTypedRealloc(type->preserve,
desc->nMapEntries, desc->nMapEntries,
XkbModsRec); XkbModsRec);
if (type->preserve==NULL) { if (type->preserve == NULL) {
_XkbFree(prev_preserve); _XkbFree(prev_preserve);
return BadAlloc; return BadAlloc;
} }
} }
} }
else if (type->preserve!=NULL) { else if (type->preserve != NULL) {
Xfree(type->preserve); Xfree(type->preserve);
type->preserve= NULL; type->preserve = NULL;
} }
type->mods.mask = desc->mask; type->mods.mask = desc->mask;
type->mods.real_mods = desc->realMods; type->mods.real_mods = desc->realMods;
type->mods.vmods = desc->virtualMods; type->mods.vmods = desc->virtualMods;
type->num_levels = desc->numLevels; type->num_levels = desc->numLevels;
type->map_count = desc->nMapEntries; type->map_count = desc->nMapEntries;
if (desc->nMapEntries>0) { if (desc->nMapEntries > 0) {
register xkbKTMapEntryWireDesc *wire; register xkbKTMapEntryWireDesc *wire;
register XkbKTMapEntryPtr entry; register XkbKTMapEntryPtr entry;
register int size; register int size;
size= type->map_count*SIZEOF(xkbKTMapEntryWireDesc); size = type->map_count * SIZEOF(xkbKTMapEntryWireDesc);
wire= (xkbKTMapEntryWireDesc *)_XkbGetReadBufferPtr(buf,size); wire =
if (wire==NULL) (xkbKTMapEntryWireDesc *) _XkbGetReadBufferPtr(buf, size);
return BadLength; if (wire == NULL)
entry= type->map; return BadLength;
for (n=0;n<type->map_count;n++,wire++,entry++) { entry = type->map;
entry->active= wire->active; for (n = 0; n < type->map_count; n++, wire++, entry++) {
entry->level= wire->level; entry->active = wire->active;
entry->mods.mask= wire->mask; entry->level = wire->level;
entry->mods.real_mods= wire->realMods; entry->mods.mask = wire->mask;
entry->mods.vmods= wire->virtualMods; entry->mods.real_mods = wire->realMods;
} entry->mods.vmods = wire->virtualMods;
}
if (desc->preserve) {
register xkbModsWireDesc * pwire; if (desc->preserve) {
register XkbModsPtr preserve; register xkbModsWireDesc *pwire;
register int sz; register XkbModsPtr preserve;
register int sz;
sz= desc->nMapEntries*SIZEOF(xkbModsWireDesc);
pwire=(xkbModsWireDesc *)_XkbGetReadBufferPtr(buf,sz); sz = desc->nMapEntries * SIZEOF(xkbModsWireDesc);
if (pwire==NULL) pwire = (xkbModsWireDesc *) _XkbGetReadBufferPtr(buf, sz);
return BadLength; if (pwire == NULL)
preserve= type->preserve; return BadLength;
for (n=0;n<desc->nMapEntries;n++,pwire++,preserve++) { preserve = type->preserve;
preserve->mask= pwire->mask; for (n = 0; n < desc->nMapEntries; n++, pwire++, preserve++) {
preserve->vmods= pwire->virtualMods; preserve->mask = pwire->mask;
preserve->real_mods= pwire->realMods; preserve->vmods = pwire->virtualMods;
} preserve->real_mods = pwire->realMods;
} }
} }
} }
}
} }
return Success; return Success;
} }
static Status static Status
_XkbReadKeySyms(XkbReadBufferPtr buf,XkbDescPtr xkb,xkbGetMapReply *rep) _XkbReadKeySyms(XkbReadBufferPtr buf, XkbDescPtr xkb, xkbGetMapReply *rep)
{ {
register int i; register int i;
XkbClientMapPtr map; XkbClientMapPtr map;
int size = xkb->max_key_code + 1; int size = xkb->max_key_code + 1;
if (((unsigned short)rep->firstKeySym + rep->nKeySyms) > size) if (((unsigned short) rep->firstKeySym + rep->nKeySyms) > size)
return BadLength; return BadLength;
map= xkb->map; map = xkb->map;
if (map->key_sym_map==NULL) { if (map->key_sym_map == NULL) {
register int offset; register int offset;
XkbSymMapPtr oldMap; XkbSymMapPtr oldMap;
xkbSymMapWireDesc *newMap; xkbSymMapWireDesc *newMap;
map->key_sym_map= _XkbTypedCalloc(size,XkbSymMapRec);
if (map->key_sym_map==NULL) map->key_sym_map = _XkbTypedCalloc(size, XkbSymMapRec);
return BadAlloc; if (map->key_sym_map == NULL)
if (map->syms==NULL) { return BadAlloc;
int sz; if (map->syms == NULL) {
sz= (rep->totalSyms*12)/10; int sz;
sz= ((sz+(unsigned)128)/128)*128;
map->syms = _XkbTypedCalloc(sz,KeySym); sz = (rep->totalSyms * 12) / 10;
if (map->syms==NULL) sz = ((sz + (unsigned) 128) / 128) * 128;
return BadAlloc; map->syms = _XkbTypedCalloc(sz, KeySym);
map->size_syms = sz; if (map->syms == NULL)
} return BadAlloc;
offset = 1; map->size_syms = sz;
oldMap = &map->key_sym_map[rep->firstKeySym]; }
for (i=0;i<(int)rep->nKeySyms;i++,oldMap++) { offset = 1;
newMap= (xkbSymMapWireDesc *) oldMap = &map->key_sym_map[rep->firstKeySym];
_XkbGetReadBufferPtr(buf,SIZEOF(xkbSymMapWireDesc)); for (i = 0; i < (int) rep->nKeySyms; i++, oldMap++) {
if (newMap==NULL) newMap = (xkbSymMapWireDesc *)
return BadLength; _XkbGetReadBufferPtr(buf, SIZEOF(xkbSymMapWireDesc));
oldMap->kt_index[0]= newMap->ktIndex[0]; if (newMap == NULL)
oldMap->kt_index[1]= newMap->ktIndex[1]; return BadLength;
oldMap->kt_index[2]= newMap->ktIndex[2]; oldMap->kt_index[0] = newMap->ktIndex[0];
oldMap->kt_index[3]= newMap->ktIndex[3]; oldMap->kt_index[1] = newMap->ktIndex[1];
oldMap->group_info= newMap->groupInfo; oldMap->kt_index[2] = newMap->ktIndex[2];
oldMap->width= newMap->width; oldMap->kt_index[3] = newMap->ktIndex[3];
oldMap->offset= offset; oldMap->group_info = newMap->groupInfo;
if (offset+newMap->nSyms>=map->size_syms) { oldMap->width = newMap->width;
register int sz; oldMap->offset = offset;
KeySym *prev_syms = map->syms; if (offset + newMap->nSyms >= map->size_syms) {
register int sz;
sz= map->size_syms+128; KeySym *prev_syms = map->syms;
map->syms= _XkbTypedRealloc(map->syms,sz,KeySym);
if (map->syms==NULL) { sz = map->size_syms + 128;
_XkbFree(prev_syms); map->syms = _XkbTypedRealloc(map->syms, sz, KeySym);
map->size_syms= 0; if (map->syms == NULL) {
return BadAlloc; _XkbFree(prev_syms);
} map->size_syms = 0;
map->size_syms= sz; return BadAlloc;
} }
if (newMap->nSyms>0) { map->size_syms = sz;
_XkbReadBufferCopyKeySyms(buf,(KeySym *)&map->syms[offset], }
newMap->nSyms); if (newMap->nSyms > 0) {
offset+= newMap->nSyms; _XkbReadBufferCopyKeySyms(buf, (KeySym *) &map->syms[offset],
} newMap->nSyms);
else { offset += newMap->nSyms;
map->syms[offset]= 0; }
} else {
} map->syms[offset] = 0;
map->num_syms= offset; }
}
map->num_syms = offset;
} }
else { else {
xkbSymMapWireDesc * newMap; xkbSymMapWireDesc *newMap;
XkbSymMapPtr oldMap; XkbSymMapPtr oldMap;
KeySym * newSyms; KeySym *newSyms;
int tmp; int tmp;
oldMap = &map->key_sym_map[rep->firstKeySym]; oldMap = &map->key_sym_map[rep->firstKeySym];
for (i=0;i<(int)rep->nKeySyms;i++,oldMap++) { for (i = 0; i < (int) rep->nKeySyms; i++, oldMap++) {
newMap= (xkbSymMapWireDesc *) newMap = (xkbSymMapWireDesc *)
_XkbGetReadBufferPtr(buf,SIZEOF(xkbSymMapWireDesc)); _XkbGetReadBufferPtr(buf, SIZEOF(xkbSymMapWireDesc));
if (newMap==NULL) if (newMap == NULL)
return BadLength; return BadLength;
if (newMap->nSyms>0) if (newMap->nSyms > 0)
tmp= newMap->nSyms; tmp = newMap->nSyms;
else tmp= 0; else
tmp = 0;
newSyms = XkbResizeKeySyms(xkb,i+rep->firstKeySym,tmp);
if (newSyms==NULL) newSyms = XkbResizeKeySyms(xkb, i + rep->firstKeySym, tmp);
return BadAlloc; if (newSyms == NULL)
if (newMap->nSyms>0) return BadAlloc;
_XkbReadBufferCopyKeySyms(buf,newSyms,newMap->nSyms); if (newMap->nSyms > 0)
else newSyms[0]= NoSymbol; _XkbReadBufferCopyKeySyms(buf, newSyms, newMap->nSyms);
oldMap->kt_index[0] = newMap->ktIndex[0]; else
oldMap->kt_index[1] = newMap->ktIndex[1]; newSyms[0] = NoSymbol;
oldMap->kt_index[2] = newMap->ktIndex[2]; oldMap->kt_index[0] = newMap->ktIndex[0];
oldMap->kt_index[3] = newMap->ktIndex[3]; oldMap->kt_index[1] = newMap->ktIndex[1];
oldMap->group_info = newMap->groupInfo; oldMap->kt_index[2] = newMap->ktIndex[2];
oldMap->width = newMap->width; oldMap->kt_index[3] = newMap->ktIndex[3];
} oldMap->group_info = newMap->groupInfo;
oldMap->width = newMap->width;
}
} }
return Success; return Success;
} }
static Status static Status
_XkbReadKeyActions(XkbReadBufferPtr buf,XkbDescPtr info,xkbGetMapReply *rep) _XkbReadKeyActions(XkbReadBufferPtr buf, XkbDescPtr info, xkbGetMapReply *rep)
{ {
int i; int i;
CARD8 numDescBuf[248]; CARD8 numDescBuf[248];
CARD8* numDesc = NULL; CARD8 *numDesc = NULL;
register int nKeyActs; register int nKeyActs;
Status ret = Success; Status ret = Success;
if ( (nKeyActs=rep->nKeyActs)>0 ) { if ((nKeyActs = rep->nKeyActs) > 0) {
XkbSymMapPtr symMap; XkbSymMapPtr symMap;
if (nKeyActs < sizeof numDescBuf) numDesc = numDescBuf; if (nKeyActs < sizeof numDescBuf)
else numDesc = Xmalloc (nKeyActs * sizeof(CARD8)); numDesc = numDescBuf;
else
if (!_XkbCopyFromReadBuffer(buf, (char *)numDesc, nKeyActs)) { numDesc = Xmalloc(nKeyActs * sizeof(CARD8));
ret = BadLength;
goto done; if (!_XkbCopyFromReadBuffer(buf, (char *) numDesc, nKeyActs)) {
} ret = BadLength;
i= XkbPaddedSize(nKeyActs)-nKeyActs; goto done;
if ((i>0)&&(!_XkbSkipReadBufferData(buf,i))) { }
ret = BadLength; i = XkbPaddedSize(nKeyActs) - nKeyActs;
goto done; if ((i > 0) && (!_XkbSkipReadBufferData(buf, i))) {
} ret = BadLength;
symMap = &info->map->key_sym_map[rep->firstKeyAct]; goto done;
for (i=0;i<(int)rep->nKeyActs;i++,symMap++) { }
if (numDesc[i]==0) { symMap = &info->map->key_sym_map[rep->firstKeyAct];
if ((i + rep->firstKeyAct) > (info->max_key_code + 1)) { for (i = 0; i < (int) rep->nKeyActs; i++, symMap++) {
ret = BadLength; if (numDesc[i] == 0) {
goto done; if ((i + rep->firstKeyAct) > (info->max_key_code + 1)) {
} ret = BadLength;
info->server->key_acts[i+rep->firstKeyAct]= 0; goto done;
} }
else { info->server->key_acts[i + rep->firstKeyAct] = 0;
XkbAction *newActs; }
/* 8/16/93 (ef) -- XXX! Verify size here (numdesc must be */ else {
/* either zero or XkbKeyNumSyms(info,key) */ XkbAction *newActs;
newActs=XkbResizeKeyActions(info,i+rep->firstKeyAct,
numDesc[i]); /* 8/16/93 (ef) -- XXX! Verify size here (numdesc must be */
if (newActs==NULL) { /* either zero or XkbKeyNumSyms(info,key) */
ret = BadAlloc; newActs = XkbResizeKeyActions(info, i + rep->firstKeyAct,
goto done; numDesc[i]);
} if (newActs == NULL) {
if (!_XkbCopyFromReadBuffer(buf,(char *)newActs, ret = BadAlloc;
(int)(numDesc[i]*sizeof(XkbAction)))) { goto done;
ret = BadLength; }
goto done; if (!_XkbCopyFromReadBuffer(buf, (char *) newActs,
} (int) (numDesc[i] * sizeof(XkbAction)))) {
} ret = BadLength;
} goto done;
}
}
}
} }
done: done:
if (numDesc != NULL && numDesc != numDescBuf) Xfree (numDesc); if (numDesc != NULL && numDesc != numDescBuf)
Xfree(numDesc);
return ret; return ret;
} }
static Status static Status
_XkbReadKeyBehaviors(XkbReadBufferPtr buf,XkbDescPtr xkb,xkbGetMapReply *rep) _XkbReadKeyBehaviors(XkbReadBufferPtr buf, XkbDescPtr xkb, xkbGetMapReply *rep)
{ {
register int i; register int i;
xkbBehaviorWireDesc *wire; xkbBehaviorWireDesc *wire;
if ( rep->totalKeyBehaviors>0 ) { if (rep->totalKeyBehaviors > 0) {
int size = xkb->max_key_code + 1; int size = xkb->max_key_code + 1;
if ( ((int) rep->firstKeyBehavior + rep->nKeyBehaviors) > size)
return BadLength; if (((int) rep->firstKeyBehavior + rep->nKeyBehaviors) > size)
if ( xkb->server->behaviors == NULL ) { return BadLength;
xkb->server->behaviors = _XkbTypedCalloc(size,XkbBehavior); if (xkb->server->behaviors == NULL) {
if (xkb->server->behaviors==NULL) xkb->server->behaviors = _XkbTypedCalloc(size, XkbBehavior);
return BadAlloc; if (xkb->server->behaviors == NULL)
} return BadAlloc;
else { }
bzero(&xkb->server->behaviors[rep->firstKeyBehavior], else {
(rep->nKeyBehaviors*sizeof(XkbBehavior))); bzero(&xkb->server->behaviors[rep->firstKeyBehavior],
} (rep->nKeyBehaviors * sizeof(XkbBehavior)));
for (i=0;i<rep->totalKeyBehaviors;i++) { }
wire= (xkbBehaviorWireDesc *)_XkbGetReadBufferPtr(buf, for (i = 0; i < rep->totalKeyBehaviors; i++) {
SIZEOF(xkbBehaviorWireDesc)); wire = (xkbBehaviorWireDesc *) _XkbGetReadBufferPtr(buf,
if (wire==NULL || wire->key >= size) SIZEOF(xkbBehaviorWireDesc));
return BadLength; if (wire == NULL || wire->key >= size)
xkb->server->behaviors[wire->key].type= wire->type; return BadLength;
xkb->server->behaviors[wire->key].data= wire->data; xkb->server->behaviors[wire->key].type = wire->type;
} xkb->server->behaviors[wire->key].data = wire->data;
}
} }
return Success; return Success;
} }
static Status static Status
_XkbReadVirtualMods(XkbReadBufferPtr buf,XkbDescPtr xkb,xkbGetMapReply *rep) _XkbReadVirtualMods(XkbReadBufferPtr buf, XkbDescPtr xkb, xkbGetMapReply *rep)
{ {
if ( rep->virtualMods ) { if (rep->virtualMods) {
register int i,bit,nVMods; register int i, bit, nVMods;
register char *data; register char *data;
for (i=nVMods=0,bit=1;i<XkbNumVirtualMods;i++,bit<<=1) { for (i = nVMods = 0, bit = 1; i < XkbNumVirtualMods; i++, bit <<= 1) {
if (rep->virtualMods&bit) if (rep->virtualMods & bit)
nVMods++; nVMods++;
} }
data= _XkbGetReadBufferPtr(buf,XkbPaddedSize(nVMods)); data = _XkbGetReadBufferPtr(buf, XkbPaddedSize(nVMods));
if (data==NULL) if (data == NULL)
return BadLength; return BadLength;
for (i=0,bit=1;(i<XkbNumVirtualMods)&&(nVMods>0);i++,bit<<=1) { for (i = 0, bit = 1; (i < XkbNumVirtualMods) && (nVMods > 0);
if (rep->virtualMods&bit) { i++, bit <<= 1) {
xkb->server->vmods[i]= *data++; if (rep->virtualMods & bit) {
nVMods--; xkb->server->vmods[i] = *data++;
} nVMods--;
} }
}
} }
return Success; return Success;
} }
static Status static Status
_XkbReadExplicitComponents( XkbReadBufferPtr buf, _XkbReadExplicitComponents(XkbReadBufferPtr buf,
XkbDescPtr xkb, XkbDescPtr xkb,
xkbGetMapReply * rep) xkbGetMapReply *rep)
{ {
register int i; register int i;
unsigned char *wire; unsigned char *wire;
if ( rep->totalKeyExplicit>0 ) { if (rep->totalKeyExplicit > 0) {
int size = xkb->max_key_code + 1; int size = xkb->max_key_code + 1;
if ( ((int) rep->firstKeyExplicit + rep->nKeyExplicit) > size)
return BadLength; if (((int) rep->firstKeyExplicit + rep->nKeyExplicit) > size)
if ( xkb->server->explicit == NULL ) { return BadLength;
xkb->server->explicit = _XkbTypedCalloc(size,unsigned char); if (xkb->server->explicit == NULL) {
if (xkb->server->explicit==NULL) xkb->server->explicit = _XkbTypedCalloc(size, unsigned char);
return BadAlloc;
} if (xkb->server->explicit == NULL)
else { return BadAlloc;
bzero(&xkb->server->explicit[rep->firstKeyExplicit], }
rep->nKeyExplicit); else {
} bzero(&xkb->server->explicit[rep->firstKeyExplicit],
i= XkbPaddedSize(2*rep->totalKeyExplicit); rep->nKeyExplicit);
wire=(unsigned char *)_XkbGetReadBufferPtr(buf,i); }
if (!wire) i = XkbPaddedSize(2 * rep->totalKeyExplicit);
return BadLength; wire = (unsigned char *) _XkbGetReadBufferPtr(buf, i);
for (i=0;i<rep->totalKeyExplicit;i++,wire+=2) { if (!wire)
if (wire[0] > xkb->max_key_code || wire[1] > xkb->max_key_code) return BadLength;
return BadLength; for (i = 0; i < rep->totalKeyExplicit; i++, wire += 2) {
xkb->server->explicit[wire[0]]= wire[1]; if (wire[0] > xkb->max_key_code || wire[1] > xkb->max_key_code)
} return BadLength;
xkb->server->explicit[wire[0]] = wire[1];
}
} }
return Success; return Success;
} }
static Status static Status
_XkbReadModifierMap(XkbReadBufferPtr buf,XkbDescPtr xkb,xkbGetMapReply *rep) _XkbReadModifierMap(XkbReadBufferPtr buf, XkbDescPtr xkb, xkbGetMapReply *rep)
{ {
register int i; register int i;
unsigned char *wire; unsigned char *wire;
if ( rep->totalModMapKeys>0 ) { if (rep->totalModMapKeys > 0) {
if ( ((int)rep->firstModMapKey + rep->nModMapKeys) > if (((int) rep->firstModMapKey + rep->nModMapKeys) >
(xkb->max_key_code + 1)) (xkb->max_key_code + 1))
return BadLength; return BadLength;
if ((xkb->map->modmap==NULL)&& if ((xkb->map->modmap == NULL) &&
(XkbAllocClientMap(xkb,XkbModifierMapMask,0)!=Success)) { (XkbAllocClientMap(xkb, XkbModifierMapMask, 0) != Success)) {
return BadAlloc; return BadAlloc;
} }
else { else {
bzero(&xkb->map->modmap[rep->firstModMapKey],rep->nModMapKeys); bzero(&xkb->map->modmap[rep->firstModMapKey], rep->nModMapKeys);
} }
i= XkbPaddedSize(2*rep->totalModMapKeys); i = XkbPaddedSize(2 * rep->totalModMapKeys);
wire=(unsigned char *)_XkbGetReadBufferPtr(buf,i); wire = (unsigned char *) _XkbGetReadBufferPtr(buf, i);
if (!wire) if (!wire)
return BadLength; return BadLength;
for (i=0;i<rep->totalModMapKeys;i++,wire+=2) { for (i = 0; i < rep->totalModMapKeys; i++, wire += 2) {
if (wire[0] > xkb->max_key_code || wire[1] > xkb->max_key_code) if (wire[0] > xkb->max_key_code || wire[1] > xkb->max_key_code)
return BadLength; return BadLength;
xkb->map->modmap[wire[0]]= wire[1]; xkb->map->modmap[wire[0]] = wire[1];
} }
} }
return Success; return Success;
} }
static Status static Status
_XkbReadVirtualModMap(XkbReadBufferPtr buf,XkbDescPtr xkb,xkbGetMapReply *rep) _XkbReadVirtualModMap(XkbReadBufferPtr buf,
XkbDescPtr xkb,
xkbGetMapReply *rep)
{ {
register int i; register int i;
xkbVModMapWireDesc * wire; xkbVModMapWireDesc *wire;
XkbServerMapPtr srv; XkbServerMapPtr srv;
if ( rep->totalVModMapKeys>0 ) { if (rep->totalVModMapKeys > 0) {
if (((int) rep->firstVModMapKey + rep->nVModMapKeys) if (((int) rep->firstVModMapKey + rep->nVModMapKeys)
> xkb->max_key_code + 1) > xkb->max_key_code + 1)
return BadLength; return BadLength;
if (((xkb->server==NULL)||(xkb->server->vmodmap==NULL))&& if (((xkb->server == NULL) || (xkb->server->vmodmap == NULL)) &&
(XkbAllocServerMap(xkb,XkbVirtualModMapMask,0)!=Success)) { (XkbAllocServerMap(xkb, XkbVirtualModMapMask, 0) != Success)) {
return BadAlloc; return BadAlloc;
} }
else { else {
srv= xkb->server; srv = xkb->server;
if (rep->nVModMapKeys > rep->firstVModMapKey) if (rep->nVModMapKeys > rep->firstVModMapKey)
bzero((char *)&srv->vmodmap[rep->firstVModMapKey], bzero((char *) &srv->vmodmap[rep->firstVModMapKey],
(rep->nVModMapKeys - rep->firstVModMapKey) * (rep->nVModMapKeys - rep->firstVModMapKey) *
sizeof(unsigned short)); sizeof(unsigned short));
} }
srv= xkb->server; srv = xkb->server;
i= rep->totalVModMapKeys*SIZEOF(xkbVModMapWireDesc); i = rep->totalVModMapKeys * SIZEOF(xkbVModMapWireDesc);
wire=(xkbVModMapWireDesc *)_XkbGetReadBufferPtr(buf,i); wire = (xkbVModMapWireDesc *) _XkbGetReadBufferPtr(buf, i);
if (!wire) if (!wire)
return BadLength; return BadLength;
for (i=0;i<rep->totalVModMapKeys;i++,wire++) { for (i = 0; i < rep->totalVModMapKeys; i++, wire++) {
if ((wire->key>=xkb->min_key_code)&&(wire->key<=xkb->max_key_code)) if ((wire->key >= xkb->min_key_code) &&
srv->vmodmap[wire->key]= wire->vmods; (wire->key <= xkb->max_key_code))
} srv->vmodmap[wire->key] = wire->vmods;
}
} }
return Success; return Success;
} }
static xkbGetMapReq * static xkbGetMapReq *
_XkbGetGetMapReq(Display *dpy,XkbDescPtr xkb) _XkbGetGetMapReq(Display *dpy, XkbDescPtr xkb)
{ {
xkbGetMapReq *req; xkbGetMapReq *req;
GetReq(kbGetMap, req); GetReq(kbGetMap, req);
req->reqType = dpy->xkb_info->codes->major_opcode; req->reqType = dpy->xkb_info->codes->major_opcode;
...@@ -473,142 +489,147 @@ xkbGetMapReq *req; ...@@ -473,142 +489,147 @@ xkbGetMapReq *req;
} }
Status Status
_XkbReadGetMapReply( Display * dpy, _XkbReadGetMapReply(Display *dpy,
xkbGetMapReply *rep, xkbGetMapReply *rep,
XkbDescPtr xkb, XkbDescPtr xkb,
int * nread_rtrn) int *nread_rtrn)
{ {
int extraData; int extraData;
unsigned mask; unsigned mask;
if ( xkb->device_spec == XkbUseCoreKbd ) if (xkb->device_spec == XkbUseCoreKbd)
xkb->device_spec= rep->deviceID; xkb->device_spec = rep->deviceID;
if ( rep->maxKeyCode < rep->minKeyCode ) if (rep->maxKeyCode < rep->minKeyCode)
return BadImplementation; return BadImplementation;
xkb->min_key_code = rep->minKeyCode; xkb->min_key_code = rep->minKeyCode;
xkb->max_key_code = rep->maxKeyCode; xkb->max_key_code = rep->maxKeyCode;
if (!xkb->map) { if (!xkb->map) {
mask= rep->present&XkbAllClientInfoMask; mask = rep->present & XkbAllClientInfoMask;
if (mask&&(XkbAllocClientMap(xkb,mask,rep->nTypes)!=Success)) if (mask && (XkbAllocClientMap(xkb, mask, rep->nTypes) != Success))
return BadAlloc; return BadAlloc;
} }
if (!xkb->server) { if (!xkb->server) {
mask= rep->present&XkbAllServerInfoMask; mask = rep->present & XkbAllServerInfoMask;
if (mask&&(XkbAllocServerMap(xkb,mask,rep->totalActs)!=Success)) if (mask && (XkbAllocServerMap(xkb, mask, rep->totalActs) != Success))
return BadAlloc; return BadAlloc;
} }
extraData= (int)(rep->length*4); extraData = (int) (rep->length * 4);
extraData-= (SIZEOF(xkbGetMapReply)-SIZEOF(xGenericReply)); extraData -= (SIZEOF(xkbGetMapReply) - SIZEOF(xGenericReply));
if (rep->length) { if (rep->length) {
XkbReadBufferRec buf; XkbReadBufferRec buf;
int left; int left;
if (_XkbInitReadBuffer(dpy,&buf,extraData)) {
Status status= Success; if (_XkbInitReadBuffer(dpy, &buf, extraData)) {
if (nread_rtrn!=NULL) Status status = Success;
*nread_rtrn= extraData;
if (status==Success) if (nread_rtrn != NULL)
status= _XkbReadKeyTypes(&buf,xkb,rep); *nread_rtrn = extraData;
if (status==Success) if (status == Success)
status= _XkbReadKeySyms(&buf,xkb,rep); status = _XkbReadKeyTypes(&buf, xkb, rep);
if (status==Success) if (status == Success)
status= _XkbReadKeyActions(&buf,xkb,rep); status = _XkbReadKeySyms(&buf, xkb, rep);
if (status==Success) if (status == Success)
status= _XkbReadKeyBehaviors(&buf,xkb,rep); status = _XkbReadKeyActions(&buf, xkb, rep);
if (status==Success) if (status == Success)
status= _XkbReadVirtualMods(&buf,xkb,rep); status = _XkbReadKeyBehaviors(&buf, xkb, rep);
if (status==Success) if (status == Success)
status= _XkbReadExplicitComponents(&buf,xkb,rep); status = _XkbReadVirtualMods(&buf, xkb, rep);
if (status==Success) if (status == Success)
status= _XkbReadModifierMap(&buf,xkb,rep); status = _XkbReadExplicitComponents(&buf, xkb, rep);
if (status==Success) if (status == Success)
status= _XkbReadVirtualModMap(&buf,xkb,rep); status = _XkbReadModifierMap(&buf, xkb, rep);
left= _XkbFreeReadBuffer(&buf); if (status == Success)
if (status!=Success) return status; status = _XkbReadVirtualModMap(&buf, xkb, rep);
else if ( left || buf.error ) return BadLength; left = _XkbFreeReadBuffer(&buf);
} if (status != Success)
else return BadAlloc; return status;
else if (left || buf.error)
return BadLength;
}
else
return BadAlloc;
} }
return Success; return Success;
} }
static Status static Status
_XkbHandleGetMapReply(Display *dpy,XkbDescPtr xkb) _XkbHandleGetMapReply(Display *dpy, XkbDescPtr xkb)
{ {
xkbGetMapReply rep; xkbGetMapReply rep;
if (!_XReply(dpy, (xReply *)&rep, if (!_XReply(dpy, (xReply *) &rep,
( (SIZEOF(xkbGetMapReply)-SIZEOF(xGenericReply)) >> 2 ), ((SIZEOF(xkbGetMapReply) - SIZEOF(xGenericReply)) >> 2),
xFalse)) { xFalse)) {
return BadImplementation; return BadImplementation;
} }
return _XkbReadGetMapReply(dpy,&rep,xkb,NULL); return _XkbReadGetMapReply(dpy, &rep, xkb, NULL);
} }
Status Status
XkbGetUpdatedMap(Display *dpy,unsigned which,XkbDescPtr xkb) XkbGetUpdatedMap(Display *dpy, unsigned which, XkbDescPtr xkb)
{ {
if ((dpy->flags & XlibDisplayNoXkb) || if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return BadAccess; return BadAccess;
if (which) { if (which) {
register xkbGetMapReq *req; register xkbGetMapReq *req;
Status status; Status status;
LockDisplay(dpy); LockDisplay(dpy);
req = _XkbGetGetMapReq(dpy, xkb); req = _XkbGetGetMapReq(dpy, xkb);
req->full = which; req->full = which;
status= _XkbHandleGetMapReply(dpy, xkb); status = _XkbHandleGetMapReply(dpy, xkb);
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
return status; return status;
} }
return Success; return Success;
} }
XkbDescPtr XkbDescPtr
XkbGetMap(Display *dpy,unsigned which,unsigned deviceSpec) XkbGetMap(Display *dpy, unsigned which, unsigned deviceSpec)
{ {
XkbDescPtr xkb; XkbDescPtr xkb;
xkb = _XkbTypedCalloc(1,XkbDescRec); xkb = _XkbTypedCalloc(1, XkbDescRec);
if (xkb) { if (xkb) {
xkb->device_spec = deviceSpec; xkb->device_spec = deviceSpec;
xkb->map = _XkbTypedCalloc(1,XkbClientMapRec); xkb->map = _XkbTypedCalloc(1, XkbClientMapRec);
if ((xkb->map==NULL)|| if ((xkb->map == NULL) ||
((which)&&(XkbGetUpdatedMap(dpy,which,xkb)!=Success))) { ((which) && (XkbGetUpdatedMap(dpy, which, xkb) != Success))) {
if (xkb->map) { if (xkb->map) {
Xfree(xkb->map); Xfree(xkb->map);
xkb->map= NULL; xkb->map = NULL;
} }
Xfree(xkb); Xfree(xkb);
return NULL; return NULL;
} }
xkb->dpy= dpy; xkb->dpy = dpy;
} }
return xkb; return xkb;
} }
Status Status
XkbGetKeyTypes(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb) XkbGetKeyTypes(Display *dpy, unsigned first, unsigned num, XkbDescPtr xkb)
{ {
register xkbGetMapReq *req; register xkbGetMapReq *req;
Status status; Status status;
if ((dpy->flags & XlibDisplayNoXkb) || if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return BadAccess; return BadAccess;
if ((num<1)||(num>XkbMaxKeyTypes)) if ((num < 1) || (num > XkbMaxKeyTypes))
return BadValue; return BadValue;
LockDisplay(dpy); LockDisplay(dpy);
req = _XkbGetGetMapReq(dpy, xkb); req = _XkbGetGetMapReq(dpy, xkb);
req->firstType = first; req->firstType = first;
req->nTypes = num; req->nTypes = num;
status= _XkbHandleGetMapReply(dpy, xkb); status = _XkbHandleGetMapReply(dpy, xkb);
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
...@@ -616,24 +637,24 @@ XkbGetKeyTypes(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb) ...@@ -616,24 +637,24 @@ XkbGetKeyTypes(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb)
} }
Status Status
XkbGetKeyActions(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb) XkbGetKeyActions(Display *dpy, unsigned first, unsigned num, XkbDescPtr xkb)
{ {
register xkbGetMapReq *req; register xkbGetMapReq *req;
Status status; Status status;
if ((dpy->flags & XlibDisplayNoXkb) || if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return BadAccess; return BadAccess;
if ((num<1)||(num>XkbMaxKeyCount)) if ((num < 1) || (num > XkbMaxKeyCount))
return BadValue; return BadValue;
LockDisplay(dpy); LockDisplay(dpy);
req = _XkbGetGetMapReq(dpy, xkb); req = _XkbGetGetMapReq(dpy, xkb);
req->firstKeyAct = first; req->firstKeyAct = first;
req->nKeyActs = num; req->nKeyActs = num;
status= _XkbHandleGetMapReply(dpy, xkb); status = _XkbHandleGetMapReply(dpy, xkb);
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
...@@ -641,24 +662,24 @@ XkbGetKeyActions(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb) ...@@ -641,24 +662,24 @@ XkbGetKeyActions(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb)
} }
Status Status
XkbGetKeySyms(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb) XkbGetKeySyms(Display *dpy, unsigned first, unsigned num, XkbDescPtr xkb)
{ {
register xkbGetMapReq *req; register xkbGetMapReq *req;
Status status; Status status;
if ((dpy->flags & XlibDisplayNoXkb) || if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return BadAccess; return BadAccess;
if ((num<1)||(num>XkbMaxKeyCount)) if ((num < 1) || (num > XkbMaxKeyCount))
return BadValue; return BadValue;
LockDisplay(dpy); LockDisplay(dpy);
req = _XkbGetGetMapReq(dpy, xkb); req = _XkbGetGetMapReq(dpy, xkb);
req->firstKeySym = first; req->firstKeySym = first;
req->nKeySyms = num; req->nKeySyms = num;
status= _XkbHandleGetMapReply(dpy, xkb); status = _XkbHandleGetMapReply(dpy, xkb);
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
...@@ -667,24 +688,24 @@ XkbGetKeySyms(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb) ...@@ -667,24 +688,24 @@ XkbGetKeySyms(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb)
} }
Status Status
XkbGetKeyBehaviors(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb) XkbGetKeyBehaviors(Display *dpy, unsigned first, unsigned num, XkbDescPtr xkb)
{ {
register xkbGetMapReq *req; register xkbGetMapReq *req;
Status status; Status status;
if ((dpy->flags & XlibDisplayNoXkb) || if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return BadAccess; return BadAccess;
if ((num<1)||(num>XkbMaxKeyCount)) if ((num < 1) || (num > XkbMaxKeyCount))
return BadValue; return BadValue;
LockDisplay(dpy); LockDisplay(dpy);
req = _XkbGetGetMapReq(dpy, xkb); req = _XkbGetGetMapReq(dpy, xkb);
req->firstKeyBehavior = first; req->firstKeyBehavior = first;
req->nKeyBehaviors = num; req->nKeyBehaviors = num;
status= _XkbHandleGetMapReply(dpy, xkb); status = _XkbHandleGetMapReply(dpy, xkb);
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
...@@ -692,20 +713,20 @@ XkbGetKeyBehaviors(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb) ...@@ -692,20 +713,20 @@ XkbGetKeyBehaviors(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb)
} }
Status Status
XkbGetVirtualMods(Display *dpy,unsigned which,XkbDescPtr xkb) XkbGetVirtualMods(Display *dpy, unsigned which, XkbDescPtr xkb)
{ {
register xkbGetMapReq *req; register xkbGetMapReq *req;
Status status; Status status;
if ((dpy->flags & XlibDisplayNoXkb) || if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return BadAccess; return BadAccess;
LockDisplay(dpy); LockDisplay(dpy);
req = _XkbGetGetMapReq(dpy, xkb); req = _XkbGetGetMapReq(dpy, xkb);
req->virtualMods = which; req->virtualMods = which;
status= _XkbHandleGetMapReply(dpy, xkb); status = _XkbHandleGetMapReply(dpy, xkb);
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
...@@ -713,32 +734,34 @@ XkbGetVirtualMods(Display *dpy,unsigned which,XkbDescPtr xkb) ...@@ -713,32 +734,34 @@ XkbGetVirtualMods(Display *dpy,unsigned which,XkbDescPtr xkb)
} }
Status Status
XkbGetKeyExplicitComponents( Display * dpy, XkbGetKeyExplicitComponents(Display *dpy,
unsigned first, unsigned first,
unsigned num, unsigned num,
XkbDescPtr xkb) XkbDescPtr xkb)
{ {
register xkbGetMapReq *req; register xkbGetMapReq *req;
Status status; Status status;
if ((dpy->flags & XlibDisplayNoXkb) || if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return BadAccess; return BadAccess;
if ((num<1)||(num>XkbMaxKeyCount)) if ((num < 1) || (num > XkbMaxKeyCount))
return BadValue; return BadValue;
LockDisplay(dpy); LockDisplay(dpy);
req = _XkbGetGetMapReq(dpy, xkb); req = _XkbGetGetMapReq(dpy, xkb);
req->firstKeyExplicit = first; req->firstKeyExplicit = first;
req->nKeyExplicit = num; req->nKeyExplicit = num;
if ((xkb!=NULL) && (xkb->server!=NULL) && (xkb->server->explicit!=NULL)) { if ((xkb != NULL) && (xkb->server != NULL) &&
if ((num>0)&&(first>=xkb->min_key_code)&&(first+num<=xkb->max_key_code)) (xkb->server->explicit != NULL)) {
bzero(&xkb->server->explicit[first],num); if ((num > 0) && (first >= xkb->min_key_code) &&
(first + num <= xkb->max_key_code))
bzero(&xkb->server->explicit[first], num);
} }
if (xkb) if (xkb)
status= _XkbHandleGetMapReply(dpy, xkb); status = _XkbHandleGetMapReply(dpy, xkb);
else else
status = BadMatch; status = BadMatch;
...@@ -748,29 +771,33 @@ XkbGetKeyExplicitComponents( Display * dpy, ...@@ -748,29 +771,33 @@ XkbGetKeyExplicitComponents( Display * dpy,
} }
Status Status
XkbGetKeyModifierMap(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb) XkbGetKeyModifierMap(Display *dpy,
unsigned first,
unsigned num,
XkbDescPtr xkb)
{ {
register xkbGetMapReq *req; register xkbGetMapReq *req;
Status status; Status status;
if ((dpy->flags & XlibDisplayNoXkb) || if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return BadAccess; return BadAccess;
if ((num<1)||(num>XkbMaxKeyCount)) if ((num < 1) || (num > XkbMaxKeyCount))
return BadValue; return BadValue;
LockDisplay(dpy); LockDisplay(dpy);
req = _XkbGetGetMapReq(dpy, xkb); req = _XkbGetGetMapReq(dpy, xkb);
req->firstModMapKey = first; req->firstModMapKey = first;
req->nModMapKeys = num; req->nModMapKeys = num;
if ((xkb!=NULL) && (xkb->map!=NULL) && (xkb->map->modmap!=NULL)) { if ((xkb != NULL) && (xkb->map != NULL) && (xkb->map->modmap != NULL)) {
if ((num>0)&&(first>=xkb->min_key_code)&&(first+num<=xkb->max_key_code)) if ((num > 0) && (first >= xkb->min_key_code) &&
bzero(&xkb->map->modmap[first],num); (first + num <= xkb->max_key_code))
bzero(&xkb->map->modmap[first], num);
} }
if (xkb) if (xkb)
status= _XkbHandleGetMapReply(dpy, xkb); status = _XkbHandleGetMapReply(dpy, xkb);
else else
status = BadMatch; status = BadMatch;
...@@ -780,30 +807,32 @@ XkbGetKeyModifierMap(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb) ...@@ -780,30 +807,32 @@ XkbGetKeyModifierMap(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb)
} }
Status Status
XkbGetKeyVirtualModMap(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb) XkbGetKeyVirtualModMap(Display *dpy, unsigned first, unsigned num,
XkbDescPtr xkb)
{ {
register xkbGetMapReq *req; register xkbGetMapReq *req;
Status status; Status status;
if ((dpy->flags & XlibDisplayNoXkb) || if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return BadAccess; return BadAccess;
if ((num<1)||(num>XkbMaxKeyCount)) if ((num < 1) || (num > XkbMaxKeyCount))
return BadValue; return BadValue;
LockDisplay(dpy); LockDisplay(dpy);
req = _XkbGetGetMapReq(dpy, xkb); req = _XkbGetGetMapReq(dpy, xkb);
req->firstVModMapKey = first; req->firstVModMapKey = first;
req->nVModMapKeys = num; req->nVModMapKeys = num;
if ((xkb!=NULL) && (xkb->map!=NULL) && (xkb->map->modmap!=NULL)) { if ((xkb != NULL) && (xkb->map != NULL) && (xkb->map->modmap != NULL)) {
if ((num>0)&&(first>=xkb->min_key_code)&&(first+num<=xkb->max_key_code)) if ((num > 0) && (first >= xkb->min_key_code) &&
bzero(&xkb->server->vmodmap[first],num*sizeof(unsigned short)); (first + num <= xkb->max_key_code))
bzero(&xkb->server->vmodmap[first], num * sizeof(unsigned short));
} }
if (xkb) if (xkb)
status= _XkbHandleGetMapReply(dpy, xkb); status = _XkbHandleGetMapReply(dpy, xkb);
else else
status = BadMatch; status = BadMatch;
...@@ -813,40 +842,40 @@ XkbGetKeyVirtualModMap(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb) ...@@ -813,40 +842,40 @@ XkbGetKeyVirtualModMap(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb)
} }
Status Status
XkbGetMapChanges(Display *dpy,XkbDescPtr xkb,XkbMapChangesPtr changes) XkbGetMapChanges(Display *dpy, XkbDescPtr xkb, XkbMapChangesPtr changes)
{ {
xkbGetMapReq *req; xkbGetMapReq *req;
if ((dpy->flags & XlibDisplayNoXkb) || if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return BadAccess; return BadAccess;
LockDisplay(dpy); LockDisplay(dpy);
if (changes->changed) { if (changes->changed) {
Status status= Success; Status status = Success;
req = _XkbGetGetMapReq(dpy, xkb);
req->full = 0; req = _XkbGetGetMapReq(dpy, xkb);
req->partial = changes->changed; req->full = 0;
req->firstType = changes->first_type; req->partial = changes->changed;
req->nTypes = changes->num_types; req->firstType = changes->first_type;
req->firstKeySym = changes->first_key_sym; req->nTypes = changes->num_types;
req->nKeySyms = changes->num_key_syms; req->firstKeySym = changes->first_key_sym;
req->firstKeyAct = changes->first_key_act; req->nKeySyms = changes->num_key_syms;
req->nKeyActs = changes->num_key_acts; req->firstKeyAct = changes->first_key_act;
req->firstKeyBehavior = changes->first_key_behavior; req->nKeyActs = changes->num_key_acts;
req->nKeyBehaviors = changes->num_key_behaviors; req->firstKeyBehavior = changes->first_key_behavior;
req->virtualMods = changes->vmods; req->nKeyBehaviors = changes->num_key_behaviors;
req->firstKeyExplicit = changes->first_key_explicit; req->virtualMods = changes->vmods;
req->nKeyExplicit = changes->num_key_explicit; req->firstKeyExplicit = changes->first_key_explicit;
req->firstModMapKey = changes->first_modmap_key; req->nKeyExplicit = changes->num_key_explicit;
req->nModMapKeys = changes->num_modmap_keys; req->firstModMapKey = changes->first_modmap_key;
req->firstVModMapKey = changes->first_vmodmap_key; req->nModMapKeys = changes->num_modmap_keys;
req->nVModMapKeys = changes->num_vmodmap_keys; req->firstVModMapKey = changes->first_vmodmap_key;
status= _XkbHandleGetMapReply(dpy, xkb); req->nVModMapKeys = changes->num_vmodmap_keys;
UnlockDisplay(dpy); status = _XkbHandleGetMapReply(dpy, xkb);
SyncHandle(); UnlockDisplay(dpy);
return status; SyncHandle();
return status;
} }
UnlockDisplay(dpy); UnlockDisplay(dpy);
return Success; return Success;
} }
...@@ -35,18 +35,18 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. ...@@ -35,18 +35,18 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
/***====================================================================***/ /***====================================================================***/
static void static void
_FreeComponentNames(int num,XkbComponentNamePtr names) _FreeComponentNames(int num, XkbComponentNamePtr names)
{ {
int i; int i;
XkbComponentNamePtr tmp; XkbComponentNamePtr tmp;
if ((num<1)||(names==NULL)) if ((num < 1) || (names == NULL))
return; return;
for (i=0,tmp=names;i<num;i++,tmp++) { for (i = 0, tmp = names; i < num; i++, tmp++) {
if (tmp->name) { if (tmp->name) {
_XkbFree(tmp->name); _XkbFree(tmp->name);
tmp->name= NULL; tmp->name = NULL;
} }
} }
_XkbFree(names); _XkbFree(names);
return; return;
...@@ -55,172 +55,180 @@ XkbComponentNamePtr tmp; ...@@ -55,172 +55,180 @@ XkbComponentNamePtr tmp;
/***====================================================================***/ /***====================================================================***/
static XkbComponentNamePtr static XkbComponentNamePtr
_ReadListing(XkbReadBufferPtr buf,int count,Status *status_rtrn) _ReadListing(XkbReadBufferPtr buf, int count, Status * status_rtrn)
{ {
XkbComponentNamePtr first,this; XkbComponentNamePtr first, this;
register int i; register int i;
CARD16 * flags; CARD16 *flags;
int slen,wlen; int slen, wlen;
char * str; char *str;
if (count<1) if (count < 1)
return NULL; return NULL;
first= _XkbTypedCalloc(count,XkbComponentNameRec); first = _XkbTypedCalloc(count, XkbComponentNameRec);
if (!first) if (!first)
return NULL; return NULL;
for (this=first,i=0;i<count;i++,this++) { for (this = first, i = 0; i < count; i++, this++) {
flags= (CARD16 *)_XkbGetReadBufferPtr(buf,2*sizeof(CARD16)); flags = (CARD16 *) _XkbGetReadBufferPtr(buf, 2 * sizeof(CARD16));
if (!flags) if (!flags)
goto BAILOUT; goto BAILOUT;
this->flags= flags[0]; this->flags = flags[0];
slen= flags[1]; slen = flags[1];
wlen= ((slen+1)/2)*2; /* pad to 2 byte boundary */ wlen = ((slen + 1) / 2) * 2; /* pad to 2 byte boundary */
this->name= _XkbTypedCalloc(slen+1,char); this->name = _XkbTypedCalloc(slen + 1, char);
if (!this->name)
goto BAILOUT; if (!this->name)
str= (char *)_XkbGetReadBufferPtr(buf,wlen); goto BAILOUT;
if (!str) str = (char *) _XkbGetReadBufferPtr(buf, wlen);
goto BAILOUT; if (!str)
memcpy(this->name,str,slen); goto BAILOUT;
memcpy(this->name, str, slen);
} }
return first; return first;
BAILOUT: BAILOUT:
*status_rtrn= BadAlloc; *status_rtrn = BadAlloc;
_FreeComponentNames(i,first); _FreeComponentNames(i, first);
return NULL; return NULL;
} }
/***====================================================================***/ /***====================================================================***/
XkbComponentListPtr XkbComponentListPtr
XkbListComponents( Display * dpy, XkbListComponents(Display *dpy,
unsigned deviceSpec, unsigned deviceSpec,
XkbComponentNamesPtr ptrns, XkbComponentNamesPtr ptrns,
int * max_inout) int *max_inout)
{ {
register xkbListComponentsReq* req; register xkbListComponentsReq *req;
xkbListComponentsReply rep; xkbListComponentsReply rep;
XkbInfoPtr xkbi; XkbInfoPtr xkbi;
XkbComponentListPtr list; XkbComponentListPtr list;
XkbReadBufferRec buf; XkbReadBufferRec buf;
int left; int left;
char * str; char *str;
int extraLen,len,mapLen,codesLen,typesLen,compatLen,symsLen,geomLen; int extraLen, len, mapLen, codesLen, typesLen, compatLen, symsLen, geomLen;
if ( (dpy==NULL) || (dpy->flags & XlibDisplayNoXkb) || if ((dpy == NULL) || (dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)) || (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)) ||
(ptrns==NULL) || (max_inout==NULL)) (ptrns == NULL) || (max_inout == NULL))
return NULL; return NULL;
xkbi= dpy->xkb_info; xkbi = dpy->xkb_info;
LockDisplay(dpy); LockDisplay(dpy);
GetReq(kbListComponents, req); GetReq(kbListComponents, req);
req->reqType = xkbi->codes->major_opcode; req->reqType = xkbi->codes->major_opcode;
req->xkbReqType = X_kbListComponents; req->xkbReqType = X_kbListComponents;
req->deviceSpec = deviceSpec; req->deviceSpec = deviceSpec;
req->maxNames = *max_inout; req->maxNames = *max_inout;
mapLen= codesLen= typesLen= compatLen= symsLen= geomLen= 0; mapLen = codesLen = typesLen = compatLen = symsLen = geomLen = 0;
if (ptrns->keymap) if (ptrns->keymap)
mapLen= (int)strlen(ptrns->keymap); mapLen = (int) strlen(ptrns->keymap);
if (ptrns->keycodes) if (ptrns->keycodes)
codesLen= (int)strlen(ptrns->keycodes); codesLen = (int) strlen(ptrns->keycodes);
if (ptrns->types) if (ptrns->types)
typesLen= (int)strlen(ptrns->types); typesLen = (int) strlen(ptrns->types);
if (ptrns->compat) if (ptrns->compat)
compatLen= (int)strlen(ptrns->compat); compatLen = (int) strlen(ptrns->compat);
if (ptrns->symbols) if (ptrns->symbols)
symsLen= (int)strlen(ptrns->symbols); symsLen = (int) strlen(ptrns->symbols);
if (ptrns->geometry) if (ptrns->geometry)
geomLen= (int)strlen(ptrns->geometry); geomLen = (int) strlen(ptrns->geometry);
if (mapLen>255) mapLen= 255; if (mapLen > 255)
if (codesLen>255) codesLen= 255; mapLen = 255;
if (typesLen>255) typesLen= 255; if (codesLen > 255)
if (compatLen>255) compatLen= 255; codesLen = 255;
if (symsLen>255) symsLen= 255; if (typesLen > 255)
if (geomLen>255) geomLen= 255; typesLen = 255;
if (compatLen > 255)
len= mapLen+codesLen+typesLen+compatLen+symsLen+geomLen+6; compatLen = 255;
len= XkbPaddedSize(len); if (symsLen > 255)
req->length+= len/4; symsLen = 255;
BufAlloc(char *,str,len); if (geomLen > 255)
*str++= mapLen; geomLen = 255;
if (mapLen>0) {
memcpy(str,ptrns->keymap,mapLen); len = mapLen + codesLen + typesLen + compatLen + symsLen + geomLen + 6;
str+= mapLen; len = XkbPaddedSize(len);
req->length += len / 4;
BufAlloc(char *, str, len);
*str++ = mapLen;
if (mapLen > 0) {
memcpy(str, ptrns->keymap, mapLen);
str += mapLen;
} }
*str++= codesLen; *str++ = codesLen;
if (codesLen>0) { if (codesLen > 0) {
memcpy(str,ptrns->keycodes,codesLen); memcpy(str, ptrns->keycodes, codesLen);
str+= codesLen; str += codesLen;
} }
*str++= typesLen; *str++ = typesLen;
if (typesLen>0) { if (typesLen > 0) {
memcpy(str,ptrns->types,typesLen); memcpy(str, ptrns->types, typesLen);
str+= typesLen; str += typesLen;
} }
*str++= compatLen; *str++ = compatLen;
if (compatLen>0) { if (compatLen > 0) {
memcpy(str,ptrns->compat,compatLen); memcpy(str, ptrns->compat, compatLen);
str+= compatLen; str += compatLen;
} }
*str++= symsLen; *str++ = symsLen;
if (symsLen>0) { if (symsLen > 0) {
memcpy(str,ptrns->symbols,symsLen); memcpy(str, ptrns->symbols, symsLen);
str+= symsLen; str += symsLen;
} }
*str++= geomLen; *str++ = geomLen;
if (geomLen>0) { if (geomLen > 0) {
memcpy(str,ptrns->geometry,geomLen); memcpy(str, ptrns->geometry, geomLen);
str+= geomLen; str += geomLen;
} }
if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) if (!_XReply(dpy, (xReply *) &rep, 0, xFalse))
goto BAILOUT; goto BAILOUT;
extraLen= (int)rep.length*4; extraLen = (int) rep.length * 4;
*max_inout= rep.extra; *max_inout = rep.extra;
if (extraLen==0) { /* no matches, but we don't want to report a failure */ if (extraLen == 0) { /* no matches, but we don't want to report a failure */
list= _XkbTypedCalloc(1,XkbComponentListRec); list = _XkbTypedCalloc(1, XkbComponentListRec);
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
return list; return list;
} }
if (_XkbInitReadBuffer(dpy,&buf,extraLen)) { if (_XkbInitReadBuffer(dpy, &buf, extraLen)) {
Status status; Status status;
status= Success; status = Success;
list= _XkbTypedCalloc(1,XkbComponentListRec); list = _XkbTypedCalloc(1, XkbComponentListRec);
if (!list) { if (!list) {
_XkbFreeReadBuffer(&buf); _XkbFreeReadBuffer(&buf);
goto BAILOUT; goto BAILOUT;
} }
list->num_keymaps= rep.nKeymaps; list->num_keymaps = rep.nKeymaps;
list->num_keycodes= rep.nKeycodes; list->num_keycodes = rep.nKeycodes;
list->num_types= rep.nTypes; list->num_types = rep.nTypes;
list->num_compat= rep.nCompatMaps; list->num_compat = rep.nCompatMaps;
list->num_symbols= rep.nSymbols; list->num_symbols = rep.nSymbols;
list->num_geometry= rep.nGeometries; list->num_geometry = rep.nGeometries;
if ((status==Success)&&(list->num_keymaps>0)) if ((status == Success) && (list->num_keymaps > 0))
list->keymaps= _ReadListing(&buf,list->num_keymaps,&status); list->keymaps = _ReadListing(&buf, list->num_keymaps, &status);
if ((status==Success)&&(list->num_keycodes>0)) if ((status == Success) && (list->num_keycodes > 0))
list->keycodes= _ReadListing(&buf,list->num_keycodes,&status); list->keycodes = _ReadListing(&buf, list->num_keycodes, &status);
if ((status==Success)&&(list->num_types>0)) if ((status == Success) && (list->num_types > 0))
list->types= _ReadListing(&buf,list->num_types,&status); list->types = _ReadListing(&buf, list->num_types, &status);
if ((status==Success)&&(list->num_compat>0)) if ((status == Success) && (list->num_compat > 0))
list->compat= _ReadListing(&buf,list->num_compat,&status); list->compat = _ReadListing(&buf, list->num_compat, &status);
if ((status==Success)&&(list->num_symbols>0)) if ((status == Success) && (list->num_symbols > 0))
list->symbols= _ReadListing(&buf,list->num_symbols,&status); list->symbols = _ReadListing(&buf, list->num_symbols, &status);
if ((status==Success)&&(list->num_geometry>0)) if ((status == Success) && (list->num_geometry > 0))
list->geometry= _ReadListing(&buf,list->num_geometry,&status); list->geometry = _ReadListing(&buf, list->num_geometry, &status);
left= _XkbFreeReadBuffer(&buf); left = _XkbFreeReadBuffer(&buf);
if ((status!=Success)||(buf.error)||(left>2)) { if ((status != Success) || (buf.error) || (left > 2)) {
XkbFreeComponentList(list); XkbFreeComponentList(list);
goto BAILOUT; goto BAILOUT;
} }
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
return list; return list;
} }
BAILOUT: BAILOUT:
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
return NULL; return NULL;
...@@ -230,20 +238,20 @@ void ...@@ -230,20 +238,20 @@ void
XkbFreeComponentList(XkbComponentListPtr list) XkbFreeComponentList(XkbComponentListPtr list)
{ {
if (list) { if (list) {
if (list->keymaps) if (list->keymaps)
_FreeComponentNames(list->num_keymaps,list->keymaps); _FreeComponentNames(list->num_keymaps, list->keymaps);
if (list->keycodes) if (list->keycodes)
_FreeComponentNames(list->num_keycodes,list->keycodes); _FreeComponentNames(list->num_keycodes, list->keycodes);
if (list->types) if (list->types)
_FreeComponentNames(list->num_types,list->types); _FreeComponentNames(list->num_types, list->types);
if (list->compat) if (list->compat)
_FreeComponentNames(list->num_compat,list->compat); _FreeComponentNames(list->num_compat, list->compat);
if (list->symbols) if (list->symbols)
_FreeComponentNames(list->num_symbols,list->symbols); _FreeComponentNames(list->num_symbols, list->symbols);
if (list->geometry) if (list->geometry)
_FreeComponentNames(list->num_geometry,list->geometry); _FreeComponentNames(list->num_geometry, list->geometry);
bzero((char *)list,sizeof(XkbComponentListRec)); bzero((char *) list, sizeof(XkbComponentListRec));
_XkbFree(list); _XkbFree(list);
} }
return; return;
} }
...@@ -41,176 +41,182 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. ...@@ -41,176 +41,182 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
/***====================================================================***/ /***====================================================================***/
Status Status
XkbAllocClientMap(XkbDescPtr xkb,unsigned which,unsigned nTotalTypes) XkbAllocClientMap(XkbDescPtr xkb, unsigned which, unsigned nTotalTypes)
{ {
register int i; register int i;
XkbClientMapPtr map; XkbClientMapPtr map;
if ((xkb==NULL)||((nTotalTypes>0)&&(nTotalTypes<XkbNumRequiredTypes))) if ((xkb == NULL) ||
return BadValue; ((nTotalTypes > 0) && (nTotalTypes < XkbNumRequiredTypes)))
if ((which&XkbKeySymsMask)&& return BadValue;
((!XkbIsLegalKeycode(xkb->min_key_code))|| if ((which & XkbKeySymsMask) &&
(!XkbIsLegalKeycode(xkb->max_key_code))|| ((!XkbIsLegalKeycode(xkb->min_key_code)) ||
(xkb->max_key_code<xkb->min_key_code))) { (!XkbIsLegalKeycode(xkb->max_key_code)) ||
(xkb->max_key_code < xkb->min_key_code))) {
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr,"bad keycode (%d,%d) in XkbAllocClientMap\n", fprintf(stderr, "bad keycode (%d,%d) in XkbAllocClientMap\n",
xkb->min_key_code,xkb->max_key_code); xkb->min_key_code, xkb->max_key_code);
#endif #endif
return BadValue; return BadValue;
} }
if (xkb->map==NULL) { if (xkb->map == NULL) {
map= _XkbTypedCalloc(1,XkbClientMapRec); map = _XkbTypedCalloc(1, XkbClientMapRec);
if (map==NULL) if (map == NULL)
return BadAlloc; return BadAlloc;
xkb->map= map; xkb->map = map;
} }
else map= xkb->map; else
map = xkb->map;
if ((which&XkbKeyTypesMask)&&(nTotalTypes>0)) {
if (map->types==NULL) { if ((which & XkbKeyTypesMask) && (nTotalTypes > 0)) {
map->types= _XkbTypedCalloc(nTotalTypes,XkbKeyTypeRec); if (map->types == NULL) {
if (map->types==NULL) map->types = _XkbTypedCalloc(nTotalTypes, XkbKeyTypeRec);
return BadAlloc; if (map->types == NULL)
map->num_types= 0; return BadAlloc;
map->size_types= nTotalTypes; map->num_types = 0;
} map->size_types = nTotalTypes;
else if (map->size_types<nTotalTypes) { }
XkbKeyTypeRec *prev_types = map->types; else if (map->size_types < nTotalTypes) {
XkbKeyTypeRec *prev_types = map->types;
map->types= _XkbTypedRealloc(map->types,nTotalTypes,XkbKeyTypeRec);
if (map->types==NULL) { map->types =
_XkbFree(prev_types); _XkbTypedRealloc(map->types, nTotalTypes, XkbKeyTypeRec);
map->num_types= map->size_types= 0; if (map->types == NULL) {
return BadAlloc; _XkbFree(prev_types);
} map->num_types = map->size_types = 0;
map->size_types= nTotalTypes; return BadAlloc;
bzero(&map->types[map->num_types], }
((map->size_types-map->num_types)*sizeof(XkbKeyTypeRec))); map->size_types = nTotalTypes;
} bzero(&map->types[map->num_types],
} ((map->size_types - map->num_types) * sizeof(XkbKeyTypeRec)));
if (which&XkbKeySymsMask) { }
int nKeys= XkbNumKeys(xkb); }
if (map->syms==NULL) { if (which & XkbKeySymsMask) {
map->size_syms= (nKeys*15)/10; int nKeys = XkbNumKeys(xkb);
map->syms= _XkbTypedCalloc(map->size_syms,KeySym);
if (!map->syms) { if (map->syms == NULL) {
map->size_syms= 0; map->size_syms = (nKeys * 15) / 10;
return BadAlloc; map->syms = _XkbTypedCalloc(map->size_syms, KeySym);
} if (!map->syms) {
map->num_syms= 1; map->size_syms = 0;
map->syms[0]= NoSymbol; return BadAlloc;
} }
if (map->key_sym_map==NULL) { map->num_syms = 1;
i= xkb->max_key_code+1; map->syms[0] = NoSymbol;
map->key_sym_map= _XkbTypedCalloc(i,XkbSymMapRec); }
if (map->key_sym_map==NULL) if (map->key_sym_map == NULL) {
return BadAlloc; i = xkb->max_key_code + 1;
} map->key_sym_map = _XkbTypedCalloc(i, XkbSymMapRec);
} if (map->key_sym_map == NULL)
if (which&XkbModifierMapMask) { return BadAlloc;
if ((!XkbIsLegalKeycode(xkb->min_key_code))|| }
(!XkbIsLegalKeycode(xkb->max_key_code))|| }
(xkb->max_key_code<xkb->min_key_code)) if (which & XkbModifierMapMask) {
return BadMatch; if ((!XkbIsLegalKeycode(xkb->min_key_code)) ||
if (map->modmap==NULL) { (!XkbIsLegalKeycode(xkb->max_key_code)) ||
i= xkb->max_key_code+1; (xkb->max_key_code < xkb->min_key_code))
map->modmap= _XkbTypedCalloc(i,unsigned char); return BadMatch;
if (map->modmap==NULL) if (map->modmap == NULL) {
return BadAlloc; i = xkb->max_key_code + 1;
} map->modmap = _XkbTypedCalloc(i, unsigned char);
if (map->modmap == NULL)
return BadAlloc;
}
} }
return Success; return Success;
} }
Status Status
XkbAllocServerMap(XkbDescPtr xkb,unsigned which,unsigned nNewActions) XkbAllocServerMap(XkbDescPtr xkb, unsigned which, unsigned nNewActions)
{ {
register int i; register int i;
XkbServerMapPtr map; XkbServerMapPtr map;
if (xkb==NULL) if (xkb == NULL)
return BadMatch; return BadMatch;
if (xkb->server==NULL) { if (xkb->server == NULL) {
map= _XkbTypedCalloc(1,XkbServerMapRec); map = _XkbTypedCalloc(1, XkbServerMapRec);
if (map==NULL) if (map == NULL)
return BadAlloc; return BadAlloc;
for (i=0;i<XkbNumVirtualMods;i++) { for (i = 0; i < XkbNumVirtualMods; i++) {
map->vmods[i]= XkbNoModifierMask; map->vmods[i] = XkbNoModifierMask;
} }
xkb->server= map; xkb->server = map;
} }
else map= xkb->server; else
if (which&XkbExplicitComponentsMask) { map = xkb->server;
if ((!XkbIsLegalKeycode(xkb->min_key_code))|| if (which & XkbExplicitComponentsMask) {
(!XkbIsLegalKeycode(xkb->max_key_code))|| if ((!XkbIsLegalKeycode(xkb->min_key_code)) ||
(xkb->max_key_code<xkb->min_key_code)) (!XkbIsLegalKeycode(xkb->max_key_code)) ||
return BadMatch; (xkb->max_key_code < xkb->min_key_code))
if (map->explicit==NULL) { return BadMatch;
i= xkb->max_key_code+1; if (map->explicit == NULL) {
map->explicit= _XkbTypedCalloc(i,unsigned char); i = xkb->max_key_code + 1;
if (map->explicit==NULL) map->explicit = _XkbTypedCalloc(i, unsigned char);
return BadAlloc; if (map->explicit == NULL)
} return BadAlloc;
} }
if (which&XkbKeyActionsMask) { }
if ((!XkbIsLegalKeycode(xkb->min_key_code))|| if (which & XkbKeyActionsMask) {
(!XkbIsLegalKeycode(xkb->max_key_code))|| if ((!XkbIsLegalKeycode(xkb->min_key_code)) ||
(xkb->max_key_code<xkb->min_key_code)) (!XkbIsLegalKeycode(xkb->max_key_code)) ||
return BadMatch; (xkb->max_key_code < xkb->min_key_code))
if (nNewActions<1) return BadMatch;
nNewActions= 1; if (nNewActions < 1)
if (map->acts==NULL) { nNewActions = 1;
map->acts= _XkbTypedCalloc((nNewActions+1),XkbAction); if (map->acts == NULL) {
if (map->acts==NULL) map->acts = _XkbTypedCalloc((nNewActions + 1), XkbAction);
return BadAlloc; if (map->acts == NULL)
map->num_acts= 1; return BadAlloc;
map->size_acts= nNewActions+1; map->num_acts = 1;
} map->size_acts = nNewActions + 1;
else if ((map->size_acts-map->num_acts)<nNewActions) { }
unsigned need; else if ((map->size_acts - map->num_acts) < nNewActions) {
XkbAction *prev_acts = map->acts; unsigned need;
need= map->num_acts+nNewActions; XkbAction *prev_acts = map->acts;
map->acts= _XkbTypedRealloc(map->acts,need,XkbAction);
if (map->acts==NULL) { need = map->num_acts + nNewActions;
_XkbFree(prev_acts); map->acts = _XkbTypedRealloc(map->acts, need, XkbAction);
map->num_acts= map->size_acts= 0; if (map->acts == NULL) {
return BadAlloc; _XkbFree(prev_acts);
} map->num_acts = map->size_acts = 0;
map->size_acts= need; return BadAlloc;
bzero(&map->acts[map->num_acts], }
((map->size_acts-map->num_acts)*sizeof(XkbAction))); map->size_acts = need;
} bzero(&map->acts[map->num_acts],
if (map->key_acts==NULL) { ((map->size_acts - map->num_acts) * sizeof(XkbAction)));
i= xkb->max_key_code+1; }
map->key_acts= _XkbTypedCalloc(i,unsigned short); if (map->key_acts == NULL) {
if (map->key_acts==NULL) i = xkb->max_key_code + 1;
return BadAlloc; map->key_acts = _XkbTypedCalloc(i, unsigned short);
} if (map->key_acts == NULL)
} return BadAlloc;
if (which&XkbKeyBehaviorsMask) { }
if ((!XkbIsLegalKeycode(xkb->min_key_code))|| }
(!XkbIsLegalKeycode(xkb->max_key_code))|| if (which & XkbKeyBehaviorsMask) {
(xkb->max_key_code<xkb->min_key_code)) if ((!XkbIsLegalKeycode(xkb->min_key_code)) ||
return BadMatch; (!XkbIsLegalKeycode(xkb->max_key_code)) ||
if (map->behaviors==NULL) { (xkb->max_key_code < xkb->min_key_code))
i= xkb->max_key_code+1; return BadMatch;
map->behaviors= _XkbTypedCalloc(i,XkbBehavior); if (map->behaviors == NULL) {
if (map->behaviors==NULL) i = xkb->max_key_code + 1;
return BadAlloc; map->behaviors = _XkbTypedCalloc(i, XkbBehavior);
} if (map->behaviors == NULL)
} return BadAlloc;
if (which&XkbVirtualModMapMask) { }
if ((!XkbIsLegalKeycode(xkb->min_key_code))|| }
(!XkbIsLegalKeycode(xkb->max_key_code))|| if (which & XkbVirtualModMapMask) {
(xkb->max_key_code<xkb->min_key_code)) if ((!XkbIsLegalKeycode(xkb->min_key_code)) ||
return BadMatch; (!XkbIsLegalKeycode(xkb->max_key_code)) ||
if (map->vmodmap==NULL) { (xkb->max_key_code < xkb->min_key_code))
i= xkb->max_key_code+1; return BadMatch;
map->vmodmap= _XkbTypedCalloc(i,unsigned short); if (map->vmodmap == NULL) {
if (map->vmodmap==NULL) i = xkb->max_key_code + 1;
return BadAlloc; map->vmodmap = _XkbTypedCalloc(i, unsigned short);
} if (map->vmodmap == NULL)
return BadAlloc;
}
} }
return Success; return Success;
} }
...@@ -218,211 +224,220 @@ XkbServerMapPtr map; ...@@ -218,211 +224,220 @@ XkbServerMapPtr map;
/***====================================================================***/ /***====================================================================***/
Status Status
XkbCopyKeyType(XkbKeyTypePtr from,XkbKeyTypePtr into) XkbCopyKeyType(XkbKeyTypePtr from, XkbKeyTypePtr into)
{ {
if ((!from)||(!into)) if ((!from) || (!into))
return BadMatch; return BadMatch;
if (into->map) { if (into->map) {
_XkbFree(into->map); _XkbFree(into->map);
into->map= NULL; into->map = NULL;
} }
if (into->preserve) { if (into->preserve) {
_XkbFree(into->preserve); _XkbFree(into->preserve);
into->preserve= NULL; into->preserve = NULL;
} }
if (into->level_names) { if (into->level_names) {
_XkbFree(into->level_names); _XkbFree(into->level_names);
into->level_names= NULL; into->level_names = NULL;
} }
*into= *from; *into = *from;
if ((from->map)&&(into->map_count>0)) { if ((from->map) && (into->map_count > 0)) {
into->map= _XkbTypedCalloc(into->map_count,XkbKTMapEntryRec); into->map = _XkbTypedCalloc(into->map_count, XkbKTMapEntryRec);
if (!into->map) if (!into->map)
return BadAlloc; return BadAlloc;
memcpy(into->map,from->map,into->map_count*sizeof(XkbKTMapEntryRec)); memcpy(into->map, from->map,
} into->map_count * sizeof(XkbKTMapEntryRec));
if ((from->preserve)&&(into->map_count>0)) { }
into->preserve= _XkbTypedCalloc(into->map_count,XkbModsRec); if ((from->preserve) && (into->map_count > 0)) {
if (!into->preserve) into->preserve = _XkbTypedCalloc(into->map_count, XkbModsRec);
return BadAlloc; if (!into->preserve)
memcpy(into->preserve,from->preserve, return BadAlloc;
into->map_count*sizeof(XkbModsRec)); memcpy(into->preserve, from->preserve,
} into->map_count * sizeof(XkbModsRec));
if ((from->level_names)&&(into->num_levels>0)) { }
into->level_names= _XkbTypedCalloc(into->num_levels,Atom); if ((from->level_names) && (into->num_levels > 0)) {
if (!into->level_names) into->level_names = _XkbTypedCalloc(into->num_levels, Atom);
return BadAlloc; if (!into->level_names)
memcpy(into->level_names,from->level_names, return BadAlloc;
into->num_levels*sizeof(Atom)); memcpy(into->level_names, from->level_names,
into->num_levels * sizeof(Atom));
} }
return Success; return Success;
} }
Status Status
XkbCopyKeyTypes(XkbKeyTypePtr from,XkbKeyTypePtr into,int num_types) XkbCopyKeyTypes(XkbKeyTypePtr from, XkbKeyTypePtr into, int num_types)
{ {
register int i,rtrn; register int i, rtrn;
if ((!from)||(!into)||(num_types<0)) if ((!from) || (!into) || (num_types < 0))
return BadMatch; return BadMatch;
for (i=0;i<num_types;i++) { for (i = 0; i < num_types; i++) {
if ((rtrn= XkbCopyKeyType(from++,into++))!=Success) if ((rtrn = XkbCopyKeyType(from++, into++)) != Success)
return rtrn; return rtrn;
} }
return Success; return Success;
} }
XkbKeyTypePtr XkbKeyTypePtr
XkbAddKeyType( XkbDescPtr xkb, XkbAddKeyType(XkbDescPtr xkb,
Atom name, Atom name,
int map_count, int map_count,
Bool want_preserve, Bool want_preserve,
int num_lvls) int num_lvls)
{ {
register int i; register int i;
unsigned tmp; unsigned tmp;
XkbKeyTypePtr type; XkbKeyTypePtr type;
XkbClientMapPtr map; XkbClientMapPtr map;
if ((!xkb)||(num_lvls<1)) if ((!xkb) || (num_lvls < 1))
return NULL; return NULL;
map= xkb->map; map = xkb->map;
if ((map)&&(map->types)) { if ((map) && (map->types)) {
for (i=0;i<map->num_types;i++) { for (i = 0; i < map->num_types; i++) {
if (map->types[i].name==name) { if (map->types[i].name == name) {
Status status; Status status;
status=XkbResizeKeyType(xkb,i,map_count,want_preserve,num_lvls);
return (status==Success?&map->types[i]:NULL); status =
} XkbResizeKeyType(xkb, i, map_count, want_preserve,
} num_lvls);
} return (status == Success ? &map->types[i] : NULL);
if ((!map)||(!map->types)||(!map->num_types<XkbNumRequiredTypes)) { }
tmp= XkbNumRequiredTypes+1; }
if (XkbAllocClientMap(xkb,XkbKeyTypesMask,tmp)!=Success) }
return NULL; if ((!map) || (!map->types) || (!map->num_types < XkbNumRequiredTypes)) {
tmp = XkbNumRequiredTypes + 1;
if (XkbAllocClientMap(xkb, XkbKeyTypesMask, tmp) != Success)
return NULL;
if (!map) if (!map)
map = xkb->map; map = xkb->map;
tmp= 0; tmp = 0;
if (map->num_types<=XkbKeypadIndex) if (map->num_types <= XkbKeypadIndex)
tmp|= XkbKeypadMask; tmp |= XkbKeypadMask;
if (map->num_types<=XkbAlphabeticIndex) if (map->num_types <= XkbAlphabeticIndex)
tmp|= XkbAlphabeticMask; tmp |= XkbAlphabeticMask;
if (map->num_types<=XkbTwoLevelIndex) if (map->num_types <= XkbTwoLevelIndex)
tmp|= XkbTwoLevelMask; tmp |= XkbTwoLevelMask;
if (map->num_types<=XkbOneLevelIndex) if (map->num_types <= XkbOneLevelIndex)
tmp|= XkbOneLevelMask; tmp |= XkbOneLevelMask;
if (XkbInitCanonicalKeyTypes(xkb,tmp,XkbNoModifier)==Success) { if (XkbInitCanonicalKeyTypes(xkb, tmp, XkbNoModifier) == Success) {
for (i=0;i<map->num_types;i++) { for (i = 0; i < map->num_types; i++) {
Status status; Status status;
if (map->types[i].name!=name)
continue; if (map->types[i].name != name)
status=XkbResizeKeyType(xkb,i,map_count,want_preserve,num_lvls); continue;
return (status==Success?&map->types[i]:NULL); status = XkbResizeKeyType(xkb, i, map_count, want_preserve,
} num_lvls);
} return (status == Success ? &map->types[i] : NULL);
} }
if ((map->num_types<=map->size_types)&& }
(XkbAllocClientMap(xkb,XkbKeyTypesMask,map->num_types+1)!=Success)) { }
return NULL; if ((map->num_types <= map->size_types) &&
} (XkbAllocClientMap(xkb, XkbKeyTypesMask, map->num_types + 1) !=
type= &map->types[map->num_types]; Success)) {
return NULL;
}
type = &map->types[map->num_types];
map->num_types++; map->num_types++;
bzero((char *)type,sizeof(XkbKeyTypeRec)); bzero((char *) type, sizeof(XkbKeyTypeRec));
type->num_levels= num_lvls; type->num_levels = num_lvls;
type->map_count= map_count; type->map_count = map_count;
type->name= name; type->name = name;
if (map_count>0) { if (map_count > 0) {
type->map= _XkbTypedCalloc(map_count,XkbKTMapEntryRec); type->map = _XkbTypedCalloc(map_count, XkbKTMapEntryRec);
if (!type->map) { if (!type->map) {
map->num_types--; map->num_types--;
return NULL; return NULL;
} }
if (want_preserve) { if (want_preserve) {
type->preserve= _XkbTypedCalloc(map_count,XkbModsRec); type->preserve = _XkbTypedCalloc(map_count, XkbModsRec);
if (!type->preserve) { if (!type->preserve) {
_XkbFree(type->map); _XkbFree(type->map);
map->num_types--; map->num_types--;
return NULL; return NULL;
} }
} }
} }
return type; return type;
} }
Status Status
XkbResizeKeyType( XkbDescPtr xkb, XkbResizeKeyType(XkbDescPtr xkb,
int type_ndx, int type_ndx,
int map_count, int map_count,
Bool want_preserve, Bool want_preserve,
int new_num_lvls) int new_num_lvls)
{ {
XkbKeyTypePtr type; XkbKeyTypePtr type;
KeyCode matchingKeys[XkbMaxKeyCount],nMatchingKeys; KeyCode matchingKeys[XkbMaxKeyCount], nMatchingKeys;
if ((type_ndx<0)||(type_ndx>=xkb->map->num_types)||(map_count<0)|| if ((type_ndx < 0) || (type_ndx >= xkb->map->num_types) || (map_count < 0)
(new_num_lvls<1)) || (new_num_lvls < 1))
return BadValue; return BadValue;
switch (type_ndx) { switch (type_ndx) {
case XkbOneLevelIndex: case XkbOneLevelIndex:
if (new_num_lvls!=1) if (new_num_lvls != 1)
return BadMatch; return BadMatch;
break; break;
case XkbTwoLevelIndex: case XkbTwoLevelIndex:
case XkbAlphabeticIndex: case XkbAlphabeticIndex:
case XkbKeypadIndex: case XkbKeypadIndex:
if (new_num_lvls!=2) if (new_num_lvls != 2)
return BadMatch; return BadMatch;
break; break;
} }
type= &xkb->map->types[type_ndx]; type = &xkb->map->types[type_ndx];
if (map_count==0) { if (map_count == 0) {
if (type->map!=NULL) if (type->map != NULL)
_XkbFree(type->map); _XkbFree(type->map);
type->map= NULL; type->map = NULL;
if (type->preserve!=NULL) if (type->preserve != NULL)
_XkbFree(type->preserve); _XkbFree(type->preserve);
type->preserve= NULL; type->preserve = NULL;
type->map_count= 0; type->map_count = 0;
} }
else { else {
XkbKTMapEntryRec *prev_map = type->map; XkbKTMapEntryRec *prev_map = type->map;
if ((map_count>type->map_count)||(type->map==NULL)) if ((map_count > type->map_count) || (type->map == NULL))
type->map=_XkbTypedRealloc(type->map,map_count,XkbKTMapEntryRec); type->map =
if (!type->map) { _XkbTypedRealloc(type->map, map_count, XkbKTMapEntryRec);
if (prev_map) if (!type->map) {
_XkbFree(prev_map); if (prev_map)
return BadAlloc; _XkbFree(prev_map);
} return BadAlloc;
if (want_preserve) { }
XkbModsRec *prev_preserve = type->preserve; if (want_preserve) {
XkbModsRec *prev_preserve = type->preserve;
if ((map_count>type->map_count)||(type->preserve==NULL)) {
type->preserve= _XkbTypedRealloc(type->preserve,map_count, if ((map_count > type->map_count) || (type->preserve == NULL)) {
XkbModsRec); type->preserve = _XkbTypedRealloc(type->preserve, map_count,
} XkbModsRec);
if (!type->preserve) { }
if (prev_preserve) if (!type->preserve) {
_XkbFree(prev_preserve); if (prev_preserve)
return BadAlloc; _XkbFree(prev_preserve);
} return BadAlloc;
} }
else if (type->preserve!=NULL) { }
_XkbFree(type->preserve); else if (type->preserve != NULL) {
type->preserve= NULL; _XkbFree(type->preserve);
} type->preserve = NULL;
type->map_count= map_count; }
} type->map_count = map_count;
}
if ((new_num_lvls>type->num_levels)||(type->level_names==NULL)) {
Atom * prev_level_names = type->level_names; if ((new_num_lvls > type->num_levels) || (type->level_names == NULL)) {
Atom *prev_level_names = type->level_names;
type->level_names=_XkbTypedRealloc(type->level_names,new_num_lvls,Atom);
if (!type->level_names) { type->level_names =
if (prev_level_names) _XkbTypedRealloc(type->level_names, new_num_lvls, Atom);
_XkbFree(prev_level_names); if (!type->level_names) {
return BadAlloc; if (prev_level_names)
} _XkbFree(prev_level_names);
return BadAlloc;
}
} }
/* /*
* Here's the theory: * Here's the theory:
...@@ -445,156 +460,165 @@ KeyCode matchingKeys[XkbMaxKeyCount],nMatchingKeys; ...@@ -445,156 +460,165 @@ KeyCode matchingKeys[XkbMaxKeyCount],nMatchingKeys;
* The possibilities marked with '+' require us to examine the key types * The possibilities marked with '+' require us to examine the key types
* associated with each group for the key. * associated with each group for the key.
*/ */
bzero(matchingKeys,XkbMaxKeyCount*sizeof(KeyCode)); bzero(matchingKeys, XkbMaxKeyCount * sizeof(KeyCode));
nMatchingKeys= 0; nMatchingKeys = 0;
if (new_num_lvls>type->num_levels) { if (new_num_lvls > type->num_levels) {
int nTotal; int nTotal;
KeySym * newSyms; KeySym *newSyms;
int width,match,nResize; int width, match, nResize;
register int i,g,nSyms; register int i, g, nSyms;
nResize= 0; nResize = 0;
for (nTotal=1,i=xkb->min_key_code;i<=xkb->max_key_code;i++) { for (nTotal = 1, i = xkb->min_key_code; i <= xkb->max_key_code; i++) {
width= XkbKeyGroupsWidth(xkb,i); width = XkbKeyGroupsWidth(xkb, i);
if (width<type->num_levels) if (width < type->num_levels)
continue; continue;
for (match=0,g=XkbKeyNumGroups(xkb,i)-1;(g>=0)&&(!match);g--) { for (match = 0, g = XkbKeyNumGroups(xkb, i) - 1;
if (XkbKeyKeyTypeIndex(xkb,i,g)==type_ndx) { (g >= 0) && (!match); g--) {
matchingKeys[nMatchingKeys++]= i; if (XkbKeyKeyTypeIndex(xkb, i, g) == type_ndx) {
match= 1; matchingKeys[nMatchingKeys++] = i;
} match = 1;
} }
if ((!match)||(width>=new_num_lvls)) }
nTotal+= XkbKeyNumSyms(xkb,i); if ((!match) || (width >= new_num_lvls))
else { nTotal += XkbKeyNumSyms(xkb, i);
nTotal+= XkbKeyNumGroups(xkb,i)*new_num_lvls; else {
nResize++; nTotal += XkbKeyNumGroups(xkb, i) * new_num_lvls;
} nResize++;
} }
if (nResize>0) { }
int nextMatch; if (nResize > 0) {
xkb->map->size_syms= (nTotal*12)/10; int nextMatch;
newSyms = _XkbTypedCalloc(xkb->map->size_syms,KeySym);
if (newSyms==NULL) xkb->map->size_syms = (nTotal * 12) / 10;
return BadAlloc; newSyms = _XkbTypedCalloc(xkb->map->size_syms, KeySym);
nextMatch= 0; if (newSyms == NULL)
nSyms= 1; return BadAlloc;
for (i=xkb->min_key_code;i<=xkb->max_key_code;i++) { nextMatch = 0;
if (matchingKeys[nextMatch]==i) { nSyms = 1;
KeySym *pOld; for (i = xkb->min_key_code; i <= xkb->max_key_code; i++) {
nextMatch++; if (matchingKeys[nextMatch] == i) {
width= XkbKeyGroupsWidth(xkb,i); KeySym *pOld;
pOld= XkbKeySymsPtr(xkb,i);
for (g=XkbKeyNumGroups(xkb,i)-1;g>=0;g--) { nextMatch++;
memcpy(&newSyms[nSyms+(new_num_lvls*g)],&pOld[width*g], width = XkbKeyGroupsWidth(xkb, i);
width*sizeof(KeySym)); pOld = XkbKeySymsPtr(xkb, i);
} for (g = XkbKeyNumGroups(xkb, i) - 1; g >= 0; g--) {
xkb->map->key_sym_map[i].offset= nSyms; memcpy(&newSyms[nSyms + (new_num_lvls * g)],
nSyms+= XkbKeyNumGroups(xkb,i)*new_num_lvls; &pOld[width * g], width * sizeof(KeySym));
} }
else { xkb->map->key_sym_map[i].offset = nSyms;
memcpy(&newSyms[nSyms],XkbKeySymsPtr(xkb,i), nSyms += XkbKeyNumGroups(xkb, i) * new_num_lvls;
XkbKeyNumSyms(xkb,i)*sizeof(KeySym)); }
xkb->map->key_sym_map[i].offset= nSyms; else {
nSyms+= XkbKeyNumSyms(xkb,i); memcpy(&newSyms[nSyms], XkbKeySymsPtr(xkb, i),
} XkbKeyNumSyms(xkb, i) * sizeof(KeySym));
} xkb->map->key_sym_map[i].offset = nSyms;
type->num_levels= new_num_lvls; nSyms += XkbKeyNumSyms(xkb, i);
_XkbFree(xkb->map->syms); }
xkb->map->syms= newSyms; }
xkb->map->num_syms= nSyms; type->num_levels = new_num_lvls;
return Success; _XkbFree(xkb->map->syms);
} xkb->map->syms = newSyms;
} xkb->map->num_syms = nSyms;
else if (new_num_lvls<type->num_levels) { return Success;
int width,match; }
register int g,i; }
for (i=xkb->min_key_code;i<=xkb->max_key_code;i++) { else if (new_num_lvls < type->num_levels) {
width= XkbKeyGroupsWidth(xkb,i); int width, match;
if (width<type->num_levels) register int g, i;
continue;
for (match=0,g=XkbKeyNumGroups(xkb,i)-1;(g>=0)&&(!match);g--) { for (i = xkb->min_key_code; i <= xkb->max_key_code; i++) {
if (XkbKeyKeyTypeIndex(xkb,i,g)==type_ndx) { width = XkbKeyGroupsWidth(xkb, i);
matchingKeys[nMatchingKeys++]= i; if (width < type->num_levels)
match= 1; continue;
} for (match = 0, g = XkbKeyNumGroups(xkb, i) - 1;
} (g >= 0) && (!match); g--) {
} if (XkbKeyKeyTypeIndex(xkb, i, g) == type_ndx) {
} matchingKeys[nMatchingKeys++] = i;
if (nMatchingKeys>0) { match = 1;
int key,firstClear; }
register int i,g; }
if (new_num_lvls>type->num_levels) }
firstClear= type->num_levels; }
else firstClear= new_num_lvls; if (nMatchingKeys > 0) {
for (i=0;i<nMatchingKeys;i++) { int key, firstClear;
KeySym * pSyms; register int i, g;
int width,nClear;
if (new_num_lvls > type->num_levels)
key= matchingKeys[i]; firstClear = type->num_levels;
width= XkbKeyGroupsWidth(xkb,key); else
nClear= width-firstClear; firstClear = new_num_lvls;
pSyms= XkbKeySymsPtr(xkb,key); for (i = 0; i < nMatchingKeys; i++) {
for (g=XkbKeyNumGroups(xkb,key)-1;g>=0;g--) { KeySym *pSyms;
if (XkbKeyKeyTypeIndex(xkb,key,g)==type_ndx) { int width, nClear;
if (nClear>0)
bzero(&pSyms[g*width+firstClear],nClear*sizeof(KeySym)); key = matchingKeys[i];
} width = XkbKeyGroupsWidth(xkb, key);
} nClear = width - firstClear;
} pSyms = XkbKeySymsPtr(xkb, key);
} for (g = XkbKeyNumGroups(xkb, key) - 1; g >= 0; g--) {
type->num_levels= new_num_lvls; if (XkbKeyKeyTypeIndex(xkb, key, g) == type_ndx) {
if (nClear > 0)
bzero(&pSyms[g * width + firstClear],
nClear * sizeof(KeySym));
}
}
}
}
type->num_levels = new_num_lvls;
return Success; return Success;
} }
KeySym * KeySym *
XkbResizeKeySyms(XkbDescPtr xkb,int key,int needed) XkbResizeKeySyms(XkbDescPtr xkb, int key, int needed)
{ {
register int i,nSyms,nKeySyms; register int i, nSyms, nKeySyms;
unsigned nOldSyms; unsigned nOldSyms;
KeySym *newSyms; KeySym *newSyms;
if (needed==0) { if (needed == 0) {
xkb->map->key_sym_map[key].offset= 0; xkb->map->key_sym_map[key].offset = 0;
return xkb->map->syms; return xkb->map->syms;
} }
nOldSyms= XkbKeyNumSyms(xkb,key); nOldSyms = XkbKeyNumSyms(xkb, key);
if (nOldSyms>=(unsigned)needed) { if (nOldSyms >= (unsigned) needed) {
return XkbKeySymsPtr(xkb,key); return XkbKeySymsPtr(xkb, key);
} }
if (xkb->map->size_syms-xkb->map->num_syms>=(unsigned)needed) { if (xkb->map->size_syms - xkb->map->num_syms >= (unsigned) needed) {
if (nOldSyms>0) { if (nOldSyms > 0) {
memcpy(&xkb->map->syms[xkb->map->num_syms],XkbKeySymsPtr(xkb,key), memcpy(&xkb->map->syms[xkb->map->num_syms], XkbKeySymsPtr(xkb, key),
nOldSyms*sizeof(KeySym)); nOldSyms * sizeof(KeySym));
} }
if ((needed-nOldSyms)>0) { if ((needed - nOldSyms) > 0) {
bzero(&xkb->map->syms[xkb->map->num_syms+XkbKeyNumSyms(xkb,key)], bzero(&xkb->map->syms[xkb->map->num_syms + XkbKeyNumSyms(xkb, key)],
(needed-nOldSyms)*sizeof(KeySym)); (needed - nOldSyms) * sizeof(KeySym));
} }
xkb->map->key_sym_map[key].offset = xkb->map->num_syms; xkb->map->key_sym_map[key].offset = xkb->map->num_syms;
xkb->map->num_syms+= needed; xkb->map->num_syms += needed;
return &xkb->map->syms[xkb->map->key_sym_map[key].offset]; return &xkb->map->syms[xkb->map->key_sym_map[key].offset];
} }
xkb->map->size_syms+= (needed>32?needed:32); xkb->map->size_syms += (needed > 32 ? needed : 32);
newSyms = _XkbTypedCalloc(xkb->map->size_syms,KeySym); newSyms = _XkbTypedCalloc(xkb->map->size_syms, KeySym);
if (newSyms==NULL) if (newSyms == NULL)
return NULL; return NULL;
newSyms[0]= NoSymbol; newSyms[0] = NoSymbol;
nSyms = 1; nSyms = 1;
for (i=xkb->min_key_code;i<=(int)xkb->max_key_code;i++) { for (i = xkb->min_key_code; i <= (int) xkb->max_key_code; i++) {
int nCopy; int nCopy;
nCopy= nKeySyms= XkbKeyNumSyms(xkb,i); nCopy = nKeySyms = XkbKeyNumSyms(xkb, i);
if ((nKeySyms==0)&&(i!=key)) if ((nKeySyms == 0) && (i != key))
continue; continue;
if (i==key) if (i == key)
nKeySyms= needed; nKeySyms = needed;
if (nCopy!=0) if (nCopy != 0)
memcpy(&newSyms[nSyms],XkbKeySymsPtr(xkb,i),nCopy*sizeof(KeySym)); memcpy(&newSyms[nSyms], XkbKeySymsPtr(xkb, i),
if (nKeySyms>nCopy) nCopy * sizeof(KeySym));
bzero(&newSyms[nSyms+nCopy],(nKeySyms-nCopy)*sizeof(KeySym)); if (nKeySyms > nCopy)
xkb->map->key_sym_map[i].offset = nSyms; bzero(&newSyms[nSyms + nCopy], (nKeySyms - nCopy) * sizeof(KeySym));
nSyms+= nKeySyms; xkb->map->key_sym_map[i].offset = nSyms;
nSyms += nKeySyms;
} }
_XkbFree(xkb->map->syms); _XkbFree(xkb->map->syms);
xkb->map->syms = newSyms; xkb->map->syms = newSyms;
...@@ -603,404 +627,410 @@ KeySym *newSyms; ...@@ -603,404 +627,410 @@ KeySym *newSyms;
} }
static unsigned static unsigned
_ExtendRange( unsigned int old_flags, _ExtendRange(unsigned int old_flags,
unsigned int flag, unsigned int flag,
KeyCode newKC, KeyCode newKC,
KeyCode * old_min, KeyCode *old_min,
unsigned char * old_num) unsigned char *old_num)
{ {
if ((old_flags&flag)==0) { if ((old_flags & flag) == 0) {
old_flags|= flag; old_flags |= flag;
*old_min= newKC; *old_min = newKC;
*old_num= 1; *old_num = 1;
} }
else { else {
int last= (*old_min)+(*old_num)-1; int last = (*old_min) + (*old_num) - 1;
if (newKC<*old_min) {
*old_min= newKC; if (newKC < *old_min) {
*old_num= (last-newKC)+1; *old_min = newKC;
} *old_num = (last - newKC) + 1;
else if (newKC>last) { }
*old_num= (newKC-(*old_min))+1; else if (newKC > last) {
} *old_num = (newKC - (*old_min)) + 1;
}
} }
return old_flags; return old_flags;
} }
Status Status
XkbChangeKeycodeRange( XkbDescPtr xkb, XkbChangeKeycodeRange(XkbDescPtr xkb,
int minKC, int minKC,
int maxKC, int maxKC,
XkbChangesPtr changes) XkbChangesPtr changes)
{ {
int tmp; int tmp;
if ((!xkb)||(minKC<XkbMinLegalKeyCode)||(maxKC>XkbMaxLegalKeyCode)) if ((!xkb) || (minKC < XkbMinLegalKeyCode) || (maxKC > XkbMaxLegalKeyCode))
return BadValue; return BadValue;
if (minKC>maxKC) if (minKC > maxKC)
return BadMatch; return BadMatch;
if (minKC<xkb->min_key_code) { if (minKC < xkb->min_key_code) {
if (changes) if (changes)
changes->map.min_key_code= minKC; changes->map.min_key_code = minKC;
tmp= xkb->min_key_code-minKC; tmp = xkb->min_key_code - minKC;
if (xkb->map) { if (xkb->map) {
if (xkb->map->key_sym_map) { if (xkb->map->key_sym_map) {
bzero((char *)&xkb->map->key_sym_map[minKC], bzero((char *) &xkb->map->key_sym_map[minKC],
tmp*sizeof(XkbSymMapRec)); tmp * sizeof(XkbSymMapRec));
if (changes) { if (changes) {
changes->map.changed= _ExtendRange(changes->map.changed, changes->map.changed = _ExtendRange(changes->map.changed,
XkbKeySymsMask,minKC, XkbKeySymsMask, minKC,
&changes->map.first_key_sym, &changes->map.first_key_sym,
&changes->map.num_key_syms); &changes->map.num_key_syms);
} }
} }
if (xkb->map->modmap) { if (xkb->map->modmap) {
bzero((char *)&xkb->map->modmap[minKC],tmp); bzero((char *) &xkb->map->modmap[minKC], tmp);
if (changes) { if (changes) {
changes->map.changed= _ExtendRange(changes->map.changed, changes->map.changed = _ExtendRange(changes->map.changed,
XkbModifierMapMask,minKC, XkbModifierMapMask, minKC,
&changes->map.first_modmap_key, &changes->map.first_modmap_key,
&changes->map.num_modmap_keys); &changes->map.num_modmap_keys);
} }
} }
} }
if (xkb->server) { if (xkb->server) {
if (xkb->server->behaviors) { if (xkb->server->behaviors) {
bzero((char *)&xkb->server->behaviors[minKC], bzero((char *) &xkb->server->behaviors[minKC],
tmp*sizeof(XkbBehavior)); tmp * sizeof(XkbBehavior));
if (changes) { if (changes) {
changes->map.changed= _ExtendRange(changes->map.changed, changes->map.changed = _ExtendRange(changes->map.changed,
XkbKeyBehaviorsMask,minKC, XkbKeyBehaviorsMask, minKC,
&changes->map.first_key_behavior, &changes->map.first_key_behavior,
&changes->map.num_key_behaviors); &changes->map.num_key_behaviors);
} }
} }
if (xkb->server->key_acts) { if (xkb->server->key_acts) {
bzero((char *)&xkb->server->key_acts[minKC], bzero((char *) &xkb->server->key_acts[minKC],
tmp*sizeof(unsigned short)); tmp * sizeof(unsigned short));
if (changes) { if (changes) {
changes->map.changed= _ExtendRange(changes->map.changed, changes->map.changed = _ExtendRange(changes->map.changed,
XkbKeyActionsMask,minKC, XkbKeyActionsMask, minKC,
&changes->map.first_key_act, &changes->map.first_key_act,
&changes->map.num_key_acts); &changes->map.num_key_acts);
} }
} }
if (xkb->server->vmodmap) { if (xkb->server->vmodmap) {
bzero((char *)&xkb->server->vmodmap[minKC], bzero((char *) &xkb->server->vmodmap[minKC],
tmp*sizeof(unsigned short)); tmp * sizeof(unsigned short));
if (changes) { if (changes) {
changes->map.changed= _ExtendRange(changes->map.changed, changes->map.changed = _ExtendRange(changes->map.changed,
XkbVirtualModMapMask,minKC, XkbVirtualModMapMask, minKC,
&changes->map.first_modmap_key, &changes->map.first_modmap_key,
&changes->map.num_vmodmap_keys); &changes->map.num_vmodmap_keys);
} }
} }
} }
if ((xkb->names)&&(xkb->names->keys)) { if ((xkb->names) && (xkb->names->keys)) {
bzero((char *)&xkb->names->keys[minKC],tmp*sizeof(XkbKeyNameRec)); bzero((char *) &xkb->names->keys[minKC],
if (changes) { tmp * sizeof(XkbKeyNameRec));
changes->names.changed= _ExtendRange(changes->names.changed, if (changes) {
XkbKeyNamesMask,minKC, changes->names.changed = _ExtendRange(changes->names.changed,
&changes->names.first_key, XkbKeyNamesMask, minKC,
&changes->names.num_keys); &changes->names.first_key,
} &changes->names.num_keys);
} }
xkb->min_key_code= minKC; }
} xkb->min_key_code = minKC;
if (maxKC>xkb->max_key_code) { }
if (changes) if (maxKC > xkb->max_key_code) {
changes->map.max_key_code= maxKC; if (changes)
tmp= maxKC-xkb->max_key_code; changes->map.max_key_code = maxKC;
if (xkb->map) { tmp = maxKC - xkb->max_key_code;
if (xkb->map->key_sym_map) { if (xkb->map) {
XkbSymMapRec *prev_key_sym_map = xkb->map->key_sym_map; if (xkb->map->key_sym_map) {
XkbSymMapRec *prev_key_sym_map = xkb->map->key_sym_map;
xkb->map->key_sym_map= _XkbTypedRealloc(xkb->map->key_sym_map,
(maxKC+1),XkbSymMapRec); xkb->map->key_sym_map = _XkbTypedRealloc(xkb->map->key_sym_map,
if (!xkb->map->key_sym_map) { (maxKC + 1), XkbSymMapRec);
_XkbFree(prev_key_sym_map); if (!xkb->map->key_sym_map) {
return BadAlloc; _XkbFree(prev_key_sym_map);
} return BadAlloc;
}
#ifdef NXAGENT_SERVER #ifdef NXAGENT_SERVER
bzero((char *)&xkb->map->key_sym_map[xkb->max_key_code+1], bzero((char *) &xkb->map->key_sym_map[xkb->max_key_code + 1],
tmp*sizeof(XkbSymMapRec)); tmp * sizeof(XkbSymMapRec));
#else #else
bzero((char *)&xkb->map->key_sym_map[xkb->max_key_code], bzero((char *) &xkb->map->key_sym_map[xkb->max_key_code],
tmp*sizeof(XkbSymMapRec)); tmp * sizeof(XkbSymMapRec));
#endif #endif
if (changes) { if (changes) {
changes->map.changed= _ExtendRange(changes->map.changed, changes->map.changed = _ExtendRange(changes->map.changed,
XkbKeySymsMask,maxKC, XkbKeySymsMask, maxKC,
&changes->map.first_key_sym, &changes->map.first_key_sym,
&changes->map.num_key_syms); &changes->map.num_key_syms);
} }
} }
if (xkb->map->modmap) { if (xkb->map->modmap) {
unsigned char *prev_modmap = xkb->map->modmap; unsigned char *prev_modmap = xkb->map->modmap;
xkb->map->modmap= _XkbTypedRealloc(xkb->map->modmap, xkb->map->modmap = _XkbTypedRealloc(xkb->map->modmap,
(maxKC+1),unsigned char); (maxKC + 1), unsigned char);
if (!xkb->map->modmap) { if (!xkb->map->modmap) {
_XkbFree(prev_modmap); _XkbFree(prev_modmap);
return BadAlloc; return BadAlloc;
} }
#ifdef NXAGENT_SERVER #ifdef NXAGENT_SERVER
bzero((char *)&xkb->map->modmap[xkb->max_key_code+1],tmp); bzero((char *) &xkb->map->modmap[xkb->max_key_code + 1], tmp);
#else #else
bzero((char *)&xkb->map->modmap[xkb->max_key_code],tmp); bzero((char *) &xkb->map->modmap[xkb->max_key_code], tmp);
#endif #endif
if (changes) { if (changes) {
changes->map.changed= _ExtendRange(changes->map.changed, changes->map.changed = _ExtendRange(changes->map.changed,
XkbModifierMapMask,maxKC, XkbModifierMapMask, maxKC,
&changes->map.first_modmap_key, &changes->map.first_modmap_key,
&changes->map.num_modmap_keys); &changes->map.num_modmap_keys);
} }
} }
} }
if (xkb->server) { if (xkb->server) {
if (xkb->server->behaviors) { if (xkb->server->behaviors) {
XkbBehavior *prev_behaviors = xkb->server->behaviors; XkbBehavior *prev_behaviors = xkb->server->behaviors;
xkb->server->behaviors=_XkbTypedRealloc(xkb->server->behaviors, xkb->server->behaviors =
(maxKC+1),XkbBehavior); _XkbTypedRealloc(xkb->server->behaviors, (maxKC + 1),
if (!xkb->server->behaviors) { XkbBehavior);
_XkbFree(prev_behaviors); if (!xkb->server->behaviors) {
return BadAlloc; _XkbFree(prev_behaviors);
} return BadAlloc;
}
#ifdef NXAGENT_SERVER #ifdef NXAGENT_SERVER
bzero((char *)&xkb->server->behaviors[xkb->max_key_code+1], bzero((char *) &xkb->server->behaviors[xkb->max_key_code + 1],
tmp*sizeof(XkbBehavior)); tmp * sizeof(XkbBehavior));
#else #else
bzero((char *)&xkb->server->behaviors[xkb->max_key_code], bzero((char *) &xkb->server->behaviors[xkb->max_key_code],
tmp*sizeof(XkbBehavior)); tmp * sizeof(XkbBehavior));
#endif #endif
if (changes) { if (changes) {
changes->map.changed= _ExtendRange(changes->map.changed, changes->map.changed = _ExtendRange(changes->map.changed,
XkbKeyBehaviorsMask,maxKC, XkbKeyBehaviorsMask, maxKC,
&changes->map.first_key_behavior, &changes->map.first_key_behavior,
&changes->map.num_key_behaviors); &changes->map.num_key_behaviors);
} }
} }
if (xkb->server->key_acts) { if (xkb->server->key_acts) {
unsigned short *prev_key_acts = xkb->server->key_acts; unsigned short *prev_key_acts = xkb->server->key_acts;
xkb->server->key_acts= _XkbTypedRealloc(xkb->server->key_acts, xkb->server->key_acts = _XkbTypedRealloc(xkb->server->key_acts,
(maxKC+1),unsigned short); (maxKC + 1), unsigned short);
if (!xkb->server->key_acts) { if (!xkb->server->key_acts) {
_XkbFree(prev_key_acts); _XkbFree(prev_key_acts);
return BadAlloc; return BadAlloc;
} }
#ifdef NXAGENT_SERVER #ifdef NXAGENT_SERVER
bzero((char *)&xkb->server->key_acts[xkb->max_key_code+1], bzero((char *) &xkb->server->key_acts[xkb->max_key_code + 1],
tmp*sizeof(unsigned short)); tmp * sizeof(unsigned short));
#else #else
bzero((char *)&xkb->server->key_acts[xkb->max_key_code], bzero((char *) &xkb->server->key_acts[xkb->max_key_code],
tmp*sizeof(unsigned short)); tmp * sizeof(unsigned short));
#endif #endif
if (changes) { if (changes) {
changes->map.changed= _ExtendRange(changes->map.changed, changes->map.changed = _ExtendRange(changes->map.changed,
XkbKeyActionsMask,maxKC, XkbKeyActionsMask, maxKC,
&changes->map.first_key_act, &changes->map.first_key_act,
&changes->map.num_key_acts); &changes->map.num_key_acts);
} }
} }
if (xkb->server->vmodmap) { if (xkb->server->vmodmap) {
unsigned short *prev_vmodmap = xkb->server->vmodmap; unsigned short *prev_vmodmap = xkb->server->vmodmap;
xkb->server->vmodmap= _XkbTypedRealloc(xkb->server->vmodmap, xkb->server->vmodmap = _XkbTypedRealloc(xkb->server->vmodmap,
(maxKC+1),unsigned short); (maxKC + 1), unsigned short);
if (!xkb->server->vmodmap) { if (!xkb->server->vmodmap) {
_XkbFree(prev_vmodmap); _XkbFree(prev_vmodmap);
return BadAlloc; return BadAlloc;
} }
#ifdef NXAGENT_SERVER #ifdef NXAGENT_SERVER
bzero((char *)&xkb->server->vmodmap[xkb->max_key_code+1], bzero((char *) &xkb->server->vmodmap[xkb->max_key_code + 1],
tmp*sizeof(unsigned short)); tmp * sizeof(unsigned short));
#else #else
bzero((char *)&xkb->server->vmodmap[xkb->max_key_code], bzero((char *) &xkb->server->vmodmap[xkb->max_key_code],
tmp*sizeof(unsigned short)); tmp * sizeof(unsigned short));
#endif #endif
if (changes) { if (changes) {
changes->map.changed= _ExtendRange(changes->map.changed, changes->map.changed = _ExtendRange(changes->map.changed,
XkbVirtualModMapMask,maxKC, XkbVirtualModMapMask, maxKC,
&changes->map.first_modmap_key, &changes->map.first_modmap_key,
&changes->map.num_vmodmap_keys); &changes->map.num_vmodmap_keys);
} }
} }
} }
if ((xkb->names)&&(xkb->names->keys)) { if ((xkb->names) && (xkb->names->keys)) {
XkbKeyNameRec *prev_keys = xkb->names->keys; XkbKeyNameRec *prev_keys = xkb->names->keys;
xkb->names->keys= _XkbTypedRealloc(xkb->names->keys, xkb->names->keys = _XkbTypedRealloc(xkb->names->keys,
(maxKC+1),XkbKeyNameRec); (maxKC + 1), XkbKeyNameRec);
if (!xkb->names->keys) { if (!xkb->names->keys) {
_XkbFree(prev_keys); _XkbFree(prev_keys);
return BadAlloc; return BadAlloc;
} }
#ifdef NXAGENT_SERVER #ifdef NXAGENT_SERVER
bzero((char *)&xkb->names->keys[xkb->max_key_code+1], bzero((char *) &xkb->names->keys[xkb->max_key_code + 1],
tmp*sizeof(XkbKeyNameRec)); tmp * sizeof(XkbKeyNameRec));
#else #else
bzero((char *)&xkb->names->keys[xkb->max_key_code], bzero((char *) &xkb->names->keys[xkb->max_key_code],
tmp*sizeof(XkbKeyNameRec)); tmp * sizeof(XkbKeyNameRec));
#endif #endif
if (changes) { if (changes) {
changes->names.changed= _ExtendRange(changes->names.changed, changes->names.changed = _ExtendRange(changes->names.changed,
XkbKeyNamesMask,maxKC, XkbKeyNamesMask, maxKC,
&changes->names.first_key, &changes->names.first_key,
&changes->names.num_keys); &changes->names.num_keys);
} }
} }
xkb->max_key_code= maxKC; xkb->max_key_code = maxKC;
} }
return Success; return Success;
} }
XkbAction * XkbAction *
XkbResizeKeyActions(XkbDescPtr xkb,int key,int needed) XkbResizeKeyActions(XkbDescPtr xkb, int key, int needed)
{ {
register int i,nActs; register int i, nActs;
XkbAction *newActs; XkbAction *newActs;
if (needed==0) { if (needed == 0) {
xkb->server->key_acts[key]= 0; xkb->server->key_acts[key] = 0;
return NULL; return NULL;
} }
if (XkbKeyHasActions(xkb,key)&&(XkbKeyNumSyms(xkb,key)>=(unsigned)needed)) if (XkbKeyHasActions(xkb, key) &&
return XkbKeyActionsPtr(xkb,key); (XkbKeyNumSyms(xkb, key) >= (unsigned) needed))
if (xkb->server->size_acts-xkb->server->num_acts>=(unsigned)needed) { return XkbKeyActionsPtr(xkb, key);
xkb->server->key_acts[key]= xkb->server->num_acts; if (xkb->server->size_acts - xkb->server->num_acts >= (unsigned) needed) {
xkb->server->num_acts+= needed; xkb->server->key_acts[key] = xkb->server->num_acts;
return &xkb->server->acts[xkb->server->key_acts[key]]; xkb->server->num_acts += needed;
} return &xkb->server->acts[xkb->server->key_acts[key]];
xkb->server->size_acts= xkb->server->num_acts+needed+8; }
newActs = _XkbTypedCalloc(xkb->server->size_acts,XkbAction); xkb->server->size_acts = xkb->server->num_acts + needed + 8;
if (newActs==NULL) newActs = _XkbTypedCalloc(xkb->server->size_acts, XkbAction);
return NULL; if (newActs == NULL)
return NULL;
newActs[0].type = XkbSA_NoAction; newActs[0].type = XkbSA_NoAction;
nActs = 1; nActs = 1;
for (i=xkb->min_key_code;i<=(int)xkb->max_key_code;i++) { for (i = xkb->min_key_code; i <= (int) xkb->max_key_code; i++) {
int nKeyActs,nCopy; int nKeyActs, nCopy;
if ((xkb->server->key_acts[i]==0)&&(i!=key)) if ((xkb->server->key_acts[i] == 0) && (i != key))
continue; continue;
nCopy= nKeyActs= XkbKeyNumActions(xkb,i); nCopy = nKeyActs = XkbKeyNumActions(xkb, i);
if (i==key) { if (i == key) {
nKeyActs= needed; nKeyActs = needed;
if (needed<nCopy) if (needed < nCopy)
nCopy= needed; nCopy = needed;
} }
if (nCopy>0) if (nCopy > 0)
memcpy(&newActs[nActs],XkbKeyActionsPtr(xkb,i), memcpy(&newActs[nActs], XkbKeyActionsPtr(xkb, i),
nCopy*sizeof(XkbAction)); nCopy * sizeof(XkbAction));
if (nCopy<nKeyActs) if (nCopy < nKeyActs)
bzero(&newActs[nActs+nCopy],(nKeyActs-nCopy)*sizeof(XkbAction)); bzero(&newActs[nActs + nCopy],
xkb->server->key_acts[i]= nActs; (nKeyActs - nCopy) * sizeof(XkbAction));
nActs+= nKeyActs; xkb->server->key_acts[i] = nActs;
nActs += nKeyActs;
} }
_XkbFree(xkb->server->acts); _XkbFree(xkb->server->acts);
xkb->server->acts = newActs; xkb->server->acts = newActs;
xkb->server->num_acts= nActs; xkb->server->num_acts = nActs;
return &xkb->server->acts[xkb->server->key_acts[key]]; return &xkb->server->acts[xkb->server->key_acts[key]];
} }
void void
XkbFreeClientMap(XkbDescPtr xkb,unsigned what,Bool freeMap) XkbFreeClientMap(XkbDescPtr xkb, unsigned what, Bool freeMap)
{ {
XkbClientMapPtr map; XkbClientMapPtr map;
if ((xkb==NULL)||(xkb->map==NULL)) if ((xkb == NULL) || (xkb->map == NULL))
return; return;
if (freeMap) if (freeMap)
what= XkbAllClientInfoMask; what = XkbAllClientInfoMask;
map= xkb->map; map = xkb->map;
if (what&XkbKeyTypesMask) { if (what & XkbKeyTypesMask) {
if (map->types!=NULL) { if (map->types != NULL) {
if (map->num_types>0) { if (map->num_types > 0) {
register int i; register int i;
XkbKeyTypePtr type; XkbKeyTypePtr type;
for (i=0,type=map->types;i<map->num_types;i++,type++) {
if (type->map!=NULL) { for (i = 0, type = map->types; i < map->num_types; i++, type++) {
_XkbFree(type->map); if (type->map != NULL) {
type->map= NULL; _XkbFree(type->map);
} type->map = NULL;
if (type->preserve!=NULL) { }
_XkbFree(type->preserve); if (type->preserve != NULL) {
type->preserve= NULL; _XkbFree(type->preserve);
} type->preserve = NULL;
type->map_count= 0; }
if (type->level_names!=NULL) { type->map_count = 0;
_XkbFree(type->level_names); if (type->level_names != NULL) {
type->level_names= NULL; _XkbFree(type->level_names);
} type->level_names = NULL;
} }
} }
_XkbFree(map->types); }
map->num_types= map->size_types= 0; _XkbFree(map->types);
map->types= NULL; map->num_types = map->size_types = 0;
} map->types = NULL;
} }
if (what&XkbKeySymsMask) { }
if (map->key_sym_map!=NULL) { if (what & XkbKeySymsMask) {
_XkbFree(map->key_sym_map); if (map->key_sym_map != NULL) {
map->key_sym_map= NULL; _XkbFree(map->key_sym_map);
} map->key_sym_map = NULL;
if (map->syms!=NULL) { }
_XkbFree(map->syms); if (map->syms != NULL) {
map->size_syms= map->num_syms= 0; _XkbFree(map->syms);
map->syms= NULL; map->size_syms = map->num_syms = 0;
} map->syms = NULL;
} }
if ((what&XkbModifierMapMask)&&(map->modmap!=NULL)) { }
_XkbFree(map->modmap); if ((what & XkbModifierMapMask) && (map->modmap != NULL)) {
map->modmap= NULL; _XkbFree(map->modmap);
map->modmap = NULL;
} }
if (freeMap) { if (freeMap) {
_XkbFree(xkb->map); _XkbFree(xkb->map);
xkb->map= NULL; xkb->map = NULL;
} }
return; return;
} }
void void
XkbFreeServerMap(XkbDescPtr xkb,unsigned what,Bool freeMap) XkbFreeServerMap(XkbDescPtr xkb, unsigned what, Bool freeMap)
{ {
XkbServerMapPtr map; XkbServerMapPtr map;
if ((xkb==NULL)||(xkb->server==NULL)) if ((xkb == NULL) || (xkb->server == NULL))
return; return;
if (freeMap) if (freeMap)
what= XkbAllServerInfoMask; what = XkbAllServerInfoMask;
map= xkb->server; map = xkb->server;
if ((what&XkbExplicitComponentsMask)&&(map->explicit!=NULL)) { if ((what & XkbExplicitComponentsMask) && (map->explicit != NULL)) {
_XkbFree(map->explicit); _XkbFree(map->explicit);
map->explicit= NULL; map->explicit = NULL;
} }
if (what&XkbKeyActionsMask) { if (what & XkbKeyActionsMask) {
if (map->key_acts!=NULL) { if (map->key_acts != NULL) {
_XkbFree(map->key_acts); _XkbFree(map->key_acts);
map->key_acts= NULL; map->key_acts = NULL;
} }
if (map->acts!=NULL) { if (map->acts != NULL) {
_XkbFree(map->acts); _XkbFree(map->acts);
map->num_acts= map->size_acts= 0; map->num_acts = map->size_acts = 0;
map->acts= NULL; map->acts = NULL;
} }
} }
if ((what&XkbKeyBehaviorsMask)&&(map->behaviors!=NULL)) { if ((what & XkbKeyBehaviorsMask) && (map->behaviors != NULL)) {
_XkbFree(map->behaviors); _XkbFree(map->behaviors);
map->behaviors= NULL; map->behaviors = NULL;
} }
if ((what&XkbVirtualModMapMask)&&(map->vmodmap!=NULL)) { if ((what & XkbVirtualModMapMask) && (map->vmodmap != NULL)) {
_XkbFree(map->vmodmap); _XkbFree(map->vmodmap);
map->vmodmap= NULL; map->vmodmap = NULL;
} }
if (freeMap) { if (freeMap) {
_XkbFree(xkb->server); _XkbFree(xkb->server);
xkb->server= NULL; xkb->server = NULL;
} }
return; return;
} }
...@@ -41,94 +41,97 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. ...@@ -41,94 +41,97 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
/***====================================================================***/ /***====================================================================***/
#define mapSize(m) (sizeof(m)/sizeof(XkbKTMapEntryRec)) #define mapSize(m) (sizeof(m)/sizeof(XkbKTMapEntryRec))
static XkbKTMapEntryRec map2Level[]= { static XkbKTMapEntryRec map2Level[] = {
{ True, ShiftMask, {1, ShiftMask, 0} } { True, ShiftMask, {1, ShiftMask, 0} }
}; };
static XkbKTMapEntryRec mapAlpha[]= { static XkbKTMapEntryRec mapAlpha[] = {
{ True, ShiftMask, { 1, ShiftMask, 0 } }, { True, ShiftMask, {1, ShiftMask, 0} },
{ True, LockMask, { 0, LockMask, 0 } } { True, LockMask, {0, LockMask, 0} }
}; };
static XkbModsRec preAlpha[]= { static XkbModsRec preAlpha[] = {
{ 0, 0, 0 }, { 0, 0, 0 },
{ LockMask, LockMask, 0 } { LockMask, LockMask, 0 }
}; };
#define NL_VMOD_MASK 0 #define NL_VMOD_MASK 0
static XkbKTMapEntryRec mapKeypad[]= { static XkbKTMapEntryRec mapKeypad[] = {
{ True, ShiftMask, { 1, ShiftMask, 0 } }, { True, ShiftMask, { 1, ShiftMask, 0 } },
{ False, 0, { 1, 0, NL_VMOD_MASK } } { False, 0, { 1, 0, NL_VMOD_MASK } }
}; };
static XkbKeyTypeRec canonicalTypes[XkbNumRequiredTypes] = { static XkbKeyTypeRec canonicalTypes[XkbNumRequiredTypes] = {
{ { 0, 0, 0 }, { { 0, 0, 0 },
1, /* num_levels */ 1, /* num_levels */
0, /* map_count */ 0, /* map_count */
NULL, NULL, NULL, NULL,
None, NULL None, NULL
}, },
{ { ShiftMask, ShiftMask, 0 }, { { ShiftMask, ShiftMask, 0 },
2, /* num_levels */ 2, /* num_levels */
mapSize(map2Level), /* map_count */ mapSize(map2Level), /* map_count */
map2Level, NULL, map2Level, NULL,
None, NULL None, NULL
}, },
{ { ShiftMask|LockMask, ShiftMask|LockMask, 0 }, { { ShiftMask|LockMask, ShiftMask|LockMask, 0 },
2, /* num_levels */ 2, /* num_levels */
mapSize(mapAlpha), /* map_count */ mapSize(mapAlpha), /* map_count */
mapAlpha, preAlpha, mapAlpha, preAlpha,
None, NULL None, NULL
}, },
{ { ShiftMask, ShiftMask, NL_VMOD_MASK }, { { ShiftMask, ShiftMask, NL_VMOD_MASK },
2, /* num_levels */ 2, /* num_levels */
mapSize(mapKeypad), /* map_count */ mapSize(mapKeypad), /* map_count */
mapKeypad, NULL, mapKeypad, NULL,
None, NULL None, NULL
} }
}; };
Status Status
XkbInitCanonicalKeyTypes(XkbDescPtr xkb,unsigned which,int keypadVMod) XkbInitCanonicalKeyTypes(XkbDescPtr xkb, unsigned which, int keypadVMod)
{ {
XkbClientMapPtr map; XkbClientMapPtr map;
XkbKeyTypePtr from,to; XkbKeyTypePtr from, to;
Status rtrn; Status rtrn;
if (!xkb) if (!xkb)
return BadMatch; return BadMatch;
rtrn= XkbAllocClientMap(xkb,XkbKeyTypesMask,XkbNumRequiredTypes); rtrn = XkbAllocClientMap(xkb, XkbKeyTypesMask, XkbNumRequiredTypes);
if (rtrn!=Success) if (rtrn != Success)
return rtrn; return rtrn;
map= xkb->map; map = xkb->map;
if ((which&XkbAllRequiredTypes)==0) if ((which & XkbAllRequiredTypes) == 0)
return Success; return Success;
rtrn= Success; rtrn = Success;
from= canonicalTypes; from = canonicalTypes;
to= map->types; to = map->types;
if (which&XkbOneLevelMask) if (which & XkbOneLevelMask)
rtrn= XkbCopyKeyType(&from[XkbOneLevelIndex],&to[XkbOneLevelIndex]); rtrn = XkbCopyKeyType(&from[XkbOneLevelIndex], &to[XkbOneLevelIndex]);
if ((which&XkbTwoLevelMask)&&(rtrn==Success)) if ((which & XkbTwoLevelMask) && (rtrn == Success))
rtrn= XkbCopyKeyType(&from[XkbTwoLevelIndex],&to[XkbTwoLevelIndex]); rtrn = XkbCopyKeyType(&from[XkbTwoLevelIndex], &to[XkbTwoLevelIndex]);
if ((which&XkbAlphabeticMask)&&(rtrn==Success)) if ((which & XkbAlphabeticMask) && (rtrn == Success))
rtrn= XkbCopyKeyType(&from[XkbAlphabeticIndex],&to[XkbAlphabeticIndex]); rtrn =
if ((which&XkbKeypadMask)&&(rtrn==Success)) { XkbCopyKeyType(&from[XkbAlphabeticIndex], &to[XkbAlphabeticIndex]);
XkbKeyTypePtr type; if ((which & XkbKeypadMask) && (rtrn == Success)) {
rtrn= XkbCopyKeyType(&from[XkbKeypadIndex],&to[XkbKeypadIndex]); XkbKeyTypePtr type;
type= &to[XkbKeypadIndex];
if ((keypadVMod>=0)&&(keypadVMod<XkbNumVirtualMods)&&(rtrn==Success)) { rtrn = XkbCopyKeyType(&from[XkbKeypadIndex], &to[XkbKeypadIndex]);
type->mods.vmods= (1<<keypadVMod); type = &to[XkbKeypadIndex];
type->map[0].active= True; if ((keypadVMod >= 0) && (keypadVMod < XkbNumVirtualMods) &&
type->map[0].mods.mask= ShiftMask; (rtrn == Success)) {
type->map[0].mods.real_mods= ShiftMask; type->mods.vmods = (1 << keypadVMod);
type->map[0].mods.vmods= 0; type->map[0].active = True;
type->map[0].level= 1; type->map[0].mods.mask = ShiftMask;
type->map[1].active= False; type->map[0].mods.real_mods = ShiftMask;
type->map[1].mods.mask= 0; type->map[0].mods.vmods = 0;
type->map[1].mods.real_mods= 0; type->map[0].level = 1;
type->map[1].mods.vmods= (1<<keypadVMod); type->map[1].active = False;
type->map[1].level= 1; type->map[1].mods.mask = 0;
} type->map[1].mods.real_mods = 0;
type->map[1].mods.vmods = (1 << keypadVMod);
type->map[1].level = 1;
}
} }
return Success; return Success;
} }
...@@ -139,264 +142,283 @@ Status rtrn; ...@@ -139,264 +142,283 @@ Status rtrn;
#define XKB_OFFSET(g,l) (((g)*groupsWidth)+(l)) #define XKB_OFFSET(g,l) (((g)*groupsWidth)+(l))
int int
XkbKeyTypesForCoreSymbols( XkbDescPtr xkb, XkbKeyTypesForCoreSymbols(XkbDescPtr xkb,
int map_width, int map_width,
KeySym * core_syms, KeySym *core_syms,
unsigned int protected, unsigned int protected,
int * types_inout, int *types_inout,
KeySym * xkb_syms_rtrn) KeySym *xkb_syms_rtrn)
{ {
register int i; register int i;
unsigned int empty; unsigned int empty;
int nSyms[XkbNumKbdGroups]; int nSyms[XkbNumKbdGroups];
int nGroups,tmp,groupsWidth; int nGroups, tmp, groupsWidth;
/* Section 12.2 of the protocol describes this process in more detail */ /* Section 12.2 of the protocol describes this process in more detail */
/* Step 1: find the # of symbols in the core mapping per group */ /* Step 1: find the # of symbols in the core mapping per group */
groupsWidth= 2; groupsWidth = 2;
for (i=0;i<XkbNumKbdGroups;i++) { for (i = 0; i < XkbNumKbdGroups; i++) {
if ((protected&(1<<i))&&(types_inout[i]<xkb->map->num_types)) { if ((protected & (1 << i)) && (types_inout[i] < xkb->map->num_types)) {
nSyms[i]= xkb->map->types[types_inout[i]].num_levels; nSyms[i] = xkb->map->types[types_inout[i]].num_levels;
if (nSyms[i]>groupsWidth) if (nSyms[i] > groupsWidth)
groupsWidth= nSyms[i]; groupsWidth = nSyms[i];
} }
else { else {
types_inout[i]= XkbTwoLevelIndex; /* don't really know, yet */ types_inout[i] = XkbTwoLevelIndex; /* don't really know, yet */
nSyms[i]= 2; nSyms[i] = 2;
} }
} }
if (nSyms[XkbGroup1Index]<2) if (nSyms[XkbGroup1Index] < 2)
nSyms[XkbGroup1Index]= 2; nSyms[XkbGroup1Index] = 2;
if (nSyms[XkbGroup2Index]<2) if (nSyms[XkbGroup2Index] < 2)
nSyms[XkbGroup2Index]= 2; nSyms[XkbGroup2Index] = 2;
/* Step 2: Copy the symbols from the core ordering to XKB ordering */ /* Step 2: Copy the symbols from the core ordering to XKB ordering */
/* symbols in the core are in the order: */ /* symbols in the core are in the order: */
/* G1L1 G1L2 G2L1 G2L2 [G1L[3-n]] [G2L[3-n]] [G3L*] [G3L*] */ /* G1L1 G1L2 G2L1 G2L2 [G1L[3-n]] [G2L[3-n]] [G3L*] [G3L*] */
xkb_syms_rtrn[XKB_OFFSET(XkbGroup1Index,0)]= CORE_SYM(0); xkb_syms_rtrn[XKB_OFFSET(XkbGroup1Index, 0)] = CORE_SYM(0);
xkb_syms_rtrn[XKB_OFFSET(XkbGroup1Index,1)]= CORE_SYM(1); xkb_syms_rtrn[XKB_OFFSET(XkbGroup1Index, 1)] = CORE_SYM(1);
for (i=2;i<nSyms[XkbGroup1Index];i++) { for (i = 2; i < nSyms[XkbGroup1Index]; i++) {
xkb_syms_rtrn[XKB_OFFSET(XkbGroup1Index,i)]= CORE_SYM(2+i); xkb_syms_rtrn[XKB_OFFSET(XkbGroup1Index, i)] = CORE_SYM(2 + i);
} }
xkb_syms_rtrn[XKB_OFFSET(XkbGroup2Index,0)]= CORE_SYM(2); xkb_syms_rtrn[XKB_OFFSET(XkbGroup2Index, 0)] = CORE_SYM(2);
xkb_syms_rtrn[XKB_OFFSET(XkbGroup2Index,1)]= CORE_SYM(3); xkb_syms_rtrn[XKB_OFFSET(XkbGroup2Index, 1)] = CORE_SYM(3);
tmp= 2+(nSyms[XkbGroup1Index]-2); /* offset to extra group2 syms */ tmp = 2 + (nSyms[XkbGroup1Index] - 2); /* offset to extra group2 syms */
for (i=2;i<nSyms[XkbGroup2Index];i++) { for (i = 2; i < nSyms[XkbGroup2Index]; i++) {
xkb_syms_rtrn[XKB_OFFSET(XkbGroup2Index,i)]= CORE_SYM(tmp+i); xkb_syms_rtrn[XKB_OFFSET(XkbGroup2Index, i)] = CORE_SYM(tmp + i);
} }
tmp= nSyms[XkbGroup1Index]+nSyms[XkbGroup2Index]; tmp = nSyms[XkbGroup1Index] + nSyms[XkbGroup2Index];
if ((tmp>=map_width)&& if ((tmp >= map_width) &&
((protected&(XkbExplicitKeyType3Mask|XkbExplicitKeyType4Mask))==0)) { ((protected & (XkbExplicitKeyType3Mask | XkbExplicitKeyType4Mask)) ==
nSyms[XkbGroup3Index]= 0; 0)) {
nSyms[XkbGroup4Index]= 0; nSyms[XkbGroup3Index] = 0;
nGroups= 2; nSyms[XkbGroup4Index] = 0;
nGroups = 2;
} }
else { else {
nGroups= 3; nGroups = 3;
for (i=0;i<nSyms[XkbGroup3Index];i++,tmp++) { for (i = 0; i < nSyms[XkbGroup3Index]; i++, tmp++) {
xkb_syms_rtrn[XKB_OFFSET(XkbGroup3Index,i)]= CORE_SYM(tmp); xkb_syms_rtrn[XKB_OFFSET(XkbGroup3Index, i)] = CORE_SYM(tmp);
} }
if ((tmp<map_width)||(protected&XkbExplicitKeyType4Mask)) { if ((tmp < map_width) || (protected & XkbExplicitKeyType4Mask)) {
nGroups= 4; nGroups = 4;
for (i=0;i<nSyms[XkbGroup4Index];i++,tmp++) { for (i = 0; i < nSyms[XkbGroup4Index]; i++, tmp++) {
xkb_syms_rtrn[XKB_OFFSET(XkbGroup4Index,i)]= CORE_SYM(tmp); xkb_syms_rtrn[XKB_OFFSET(XkbGroup4Index, i)] = CORE_SYM(tmp);
} }
} }
else { else {
nSyms[XkbGroup4Index]= 0; nSyms[XkbGroup4Index] = 0;
} }
} }
/* steps 3&4: alphanumeric expansion, assign canonical types */ /* steps 3&4: alphanumeric expansion, assign canonical types */
empty= 0; empty = 0;
for (i=0;i<nGroups;i++) { for (i = 0; i < nGroups; i++) {
KeySym *syms; KeySym *syms;
syms= &xkb_syms_rtrn[XKB_OFFSET(i,0)];
if ((nSyms[i]>1)&&(syms[1]==NoSymbol)&&(syms[0]!=NoSymbol)) { syms = &xkb_syms_rtrn[XKB_OFFSET(i, 0)];
KeySym upper,lower; if ((nSyms[i] > 1) && (syms[1] == NoSymbol) && (syms[0] != NoSymbol)) {
XConvertCase(syms[0],&lower,&upper); KeySym upper, lower;
if (upper!=lower) {
xkb_syms_rtrn[XKB_OFFSET(i,0)]= lower; XConvertCase(syms[0], &lower, &upper);
xkb_syms_rtrn[XKB_OFFSET(i,1)]= upper; if (upper != lower) {
if ((protected&(1<<i))==0) xkb_syms_rtrn[XKB_OFFSET(i, 0)] = lower;
types_inout[i]= XkbAlphabeticIndex; xkb_syms_rtrn[XKB_OFFSET(i, 1)] = upper;
} if ((protected & (1 << i)) == 0)
else if ((protected&(1<<i))==0) { types_inout[i] = XkbAlphabeticIndex;
types_inout[i]= XkbOneLevelIndex; }
/* nSyms[i]= 1;*/ else if ((protected & (1 << i)) == 0) {
} types_inout[i] = XkbOneLevelIndex;
} /* nSyms[i]= 1; */
if (((protected&(1<<i))==0)&&(types_inout[i]==XkbTwoLevelIndex)) { }
if (IsKeypadKey(syms[0])||IsKeypadKey(syms[1])) }
types_inout[i]= XkbKeypadIndex; if (((protected & (1 << i)) == 0) &&
else { (types_inout[i] == XkbTwoLevelIndex)) {
KeySym upper,lower; if (IsKeypadKey(syms[0]) || IsKeypadKey(syms[1]))
XConvertCase(syms[0],&lower,&upper); types_inout[i] = XkbKeypadIndex;
if ((syms[0]==lower)&&(syms[1]==upper)) else {
types_inout[i]= XkbAlphabeticIndex; KeySym upper, lower;
}
} XConvertCase(syms[0], &lower, &upper);
if (syms[0]==NoSymbol) { if ((syms[0] == lower) && (syms[1] == upper))
register int n; types_inout[i] = XkbAlphabeticIndex;
Bool found; }
for (n=1,found=False;(!found)&&(n<nSyms[i]);n++) { }
found= (syms[n]!=NoSymbol); if (syms[0] == NoSymbol) {
} register int n;
if (!found) Bool found;
empty|= (1<<i);
} for (n = 1, found = False; (!found) && (n < nSyms[i]); n++) {
found = (syms[n] != NoSymbol);
}
if (!found)
empty |= (1 << i);
}
} }
/* step 5: squoosh out empty groups */ /* step 5: squoosh out empty groups */
if (empty) { if (empty) {
for (i=nGroups-1;i>=0;i--) { for (i = nGroups - 1; i >= 0; i--) {
if (((empty&(1<<i))==0)||(protected&(1<<i))) if (((empty & (1 << i)) == 0) || (protected & (1 << i)))
break; break;
nGroups--; nGroups--;
} }
} }
if (nGroups<1) if (nGroups < 1)
return 0; return 0;
/* step 6: replicate group 1 into group two, if necessary */ /* step 6: replicate group 1 into group two, if necessary */
if ((nGroups>1)&&((empty&(XkbGroup1Mask|XkbGroup2Mask))==XkbGroup2Mask)) { if ((nGroups > 1) &&
if ((protected&(XkbExplicitKeyType1Mask|XkbExplicitKeyType2Mask))==0) { ((empty & (XkbGroup1Mask | XkbGroup2Mask)) == XkbGroup2Mask)) {
nSyms[XkbGroup2Index]= nSyms[XkbGroup1Index]; if ((protected & (XkbExplicitKeyType1Mask | XkbExplicitKeyType2Mask)) ==
types_inout[XkbGroup2Index]= types_inout[XkbGroup1Index]; 0) {
memcpy((char *)&xkb_syms_rtrn[2],(char *)xkb_syms_rtrn, nSyms[XkbGroup2Index] = nSyms[XkbGroup1Index];
2*sizeof(KeySym)); types_inout[XkbGroup2Index] = types_inout[XkbGroup1Index];
} memcpy((char *) &xkb_syms_rtrn[2], (char *) xkb_syms_rtrn,
else if (types_inout[XkbGroup1Index]==types_inout[XkbGroup2Index]) { 2 * sizeof(KeySym));
memcpy((char *)&xkb_syms_rtrn[nSyms[XkbGroup1Index]], }
(char *)xkb_syms_rtrn, else if (types_inout[XkbGroup1Index] == types_inout[XkbGroup2Index]) {
nSyms[XkbGroup1Index]*sizeof(KeySym)); memcpy((char *) &xkb_syms_rtrn[nSyms[XkbGroup1Index]],
} (char *) xkb_syms_rtrn,
nSyms[XkbGroup1Index] * sizeof(KeySym));
}
} }
/* step 7: check for all groups identical or all width 1 */ /* step 7: check for all groups identical or all width 1 */
if (nGroups>1) { if (nGroups > 1) {
Bool sameType,allOneLevel; Bool sameType, allOneLevel;
allOneLevel= (xkb->map->types[types_inout[0]].num_levels==1);
for (i=1,sameType=True;(allOneLevel||sameType)&&(i<nGroups);i++) { allOneLevel = (xkb->map->types[types_inout[0]].num_levels == 1);
sameType=(sameType&&(types_inout[i]==types_inout[XkbGroup1Index])); for (i = 1, sameType = True; (allOneLevel || sameType) && (i < nGroups);
if (allOneLevel) i++) {
allOneLevel= (xkb->map->types[types_inout[i]].num_levels==1); sameType = (sameType &&
} (types_inout[i] == types_inout[XkbGroup1Index]));
if ((sameType)&& if (allOneLevel)
(!(protected&(XkbExplicitKeyTypesMask&~XkbExplicitKeyType1Mask)))){ allOneLevel = (xkb->map->types[types_inout[i]].num_levels == 1);
register int s; }
Bool identical; if ((sameType) &&
for (i=1,identical=True;identical&&(i<nGroups);i++) { (!(protected &
KeySym *syms; (XkbExplicitKeyTypesMask & ~XkbExplicitKeyType1Mask)))) {
syms= &xkb_syms_rtrn[XKB_OFFSET(i,0)]; register int s;
for (s=0;identical&&(s<nSyms[i]);s++) { Bool identical;
if (syms[s]!=xkb_syms_rtrn[s])
identical= False; for (i = 1, identical = True; identical && (i < nGroups); i++) {
} KeySym *syms;
}
if (identical) syms = &xkb_syms_rtrn[XKB_OFFSET(i, 0)];
nGroups= 1; for (s = 0; identical && (s < nSyms[i]); s++) {
} if (syms[s] != xkb_syms_rtrn[s])
if (allOneLevel && (nGroups>1)) { identical = False;
KeySym *syms; }
syms= &xkb_syms_rtrn[nSyms[XkbGroup1Index]]; }
nSyms[XkbGroup1Index]= 1; if (identical)
for (i=1;i<nGroups;i++) { nGroups = 1;
xkb_syms_rtrn[i]= syms[0]; }
syms+= nSyms[i]; if (allOneLevel && (nGroups > 1)) {
nSyms[i]= 1; KeySym *syms;
}
} syms = &xkb_syms_rtrn[nSyms[XkbGroup1Index]];
nSyms[XkbGroup1Index] = 1;
for (i = 1; i < nGroups; i++) {
xkb_syms_rtrn[i] = syms[0];
syms += nSyms[i];
nSyms[i] = 1;
}
}
} }
return nGroups; return nGroups;
} }
static XkbSymInterpretPtr static XkbSymInterpretPtr
_XkbFindMatchingInterp( XkbDescPtr xkb, _XkbFindMatchingInterp(XkbDescPtr xkb,
KeySym sym, KeySym sym,
unsigned int real_mods, unsigned int real_mods,
unsigned int level) unsigned int level)
{ {
register unsigned i; register unsigned i;
XkbSymInterpretPtr interp,rtrn; XkbSymInterpretPtr interp, rtrn;
CARD8 mods; CARD8 mods;
rtrn= NULL; rtrn = NULL;
interp= xkb->compat->sym_interpret; interp = xkb->compat->sym_interpret;
for (i=0;i<xkb->compat->num_si;i++,interp++) { for (i = 0; i < xkb->compat->num_si; i++, interp++) {
if ((interp->sym==NoSymbol)||(sym==interp->sym)) { if ((interp->sym == NoSymbol) || (sym == interp->sym)) {
int match; int match;
if ((level==0)||((interp->match&XkbSI_LevelOneOnly)==0))
mods= real_mods; if ((level == 0) || ((interp->match & XkbSI_LevelOneOnly) == 0))
else mods= 0; mods = real_mods;
switch (interp->match&XkbSI_OpMask) { else
case XkbSI_NoneOf: mods = 0;
match= ((interp->mods&mods)==0); switch (interp->match & XkbSI_OpMask) {
break; case XkbSI_NoneOf:
case XkbSI_AnyOfOrNone: match = ((interp->mods & mods) == 0);
match= ((mods==0)||((interp->mods&mods)!=0)); break;
break; case XkbSI_AnyOfOrNone:
case XkbSI_AnyOf: match = ((mods == 0) || ((interp->mods & mods) != 0));
match= ((interp->mods&mods)!=0); break;
break; case XkbSI_AnyOf:
case XkbSI_AllOf: match = ((interp->mods & mods) != 0);
match= ((interp->mods&mods)==interp->mods); break;
break; case XkbSI_AllOf:
case XkbSI_Exactly: match = ((interp->mods & mods) == interp->mods);
match= (interp->mods==mods); break;
break; case XkbSI_Exactly:
default: match = (interp->mods == mods);
match= 0; break;
break; default:
} match = 0;
if (match) { break;
if (interp->sym!=NoSymbol) { }
return interp; if (match) {
} if (interp->sym != NoSymbol) {
else if (rtrn==NULL) { return interp;
rtrn= interp; }
} else if (rtrn == NULL) {
} rtrn = interp;
} }
}
}
} }
return rtrn; return rtrn;
} }
static void static void
_XkbAddKeyChange(KeyCode *pFirst,unsigned char *pNum,KeyCode newKey) _XkbAddKeyChange(KeyCode *pFirst, unsigned char *pNum, KeyCode newKey)
{ {
KeyCode last; KeyCode last;
last= (*pFirst)+(*pNum); last = (*pFirst) + (*pNum);
if (newKey<*pFirst) { if (newKey < *pFirst) {
*pFirst= newKey; *pFirst = newKey;
*pNum= (last-newKey)+1; *pNum = (last - newKey) + 1;
} }
else if (newKey>last) { else if (newKey > last) {
*pNum= (last-*pFirst)+1; *pNum = (last - *pFirst) + 1;
} }
return; return;
} }
static void static void
_XkbSetActionKeyMods(XkbDescPtr xkb,XkbAction *act,unsigned mods) _XkbSetActionKeyMods(XkbDescPtr xkb, XkbAction *act, unsigned mods)
{ {
unsigned tmp; unsigned tmp;
switch (act->type) { switch (act->type) {
case XkbSA_SetMods: case XkbSA_LatchMods: case XkbSA_LockMods: case XkbSA_SetMods:
if (act->mods.flags&XkbSA_UseModMapMods) case XkbSA_LatchMods:
act->mods.real_mods= act->mods.mask= mods; case XkbSA_LockMods:
if ((tmp= XkbModActionVMods(&act->mods))!=0) { if (act->mods.flags & XkbSA_UseModMapMods)
XkbVirtualModsToReal(xkb,tmp,&tmp); act->mods.real_mods = act->mods.mask = mods;
act->mods.mask|= tmp; if ((tmp = XkbModActionVMods(&act->mods)) != 0) {
} XkbVirtualModsToReal(xkb, tmp, &tmp);
break; act->mods.mask |= tmp;
case XkbSA_ISOLock: }
if (act->iso.flags&XkbSA_UseModMapMods) break;
act->iso.real_mods= act->iso.mask= mods; case XkbSA_ISOLock:
if ((tmp= XkbModActionVMods(&act->iso))!=0) { if (act->iso.flags & XkbSA_UseModMapMods)
XkbVirtualModsToReal(xkb,tmp,&tmp); act->iso.real_mods = act->iso.mask = mods;
act->iso.mask|= tmp; if ((tmp = XkbModActionVMods(&act->iso)) != 0) {
} XkbVirtualModsToReal(xkb, tmp, &tmp);
break; act->iso.mask |= tmp;
}
break;
} }
return; return;
} }
...@@ -404,357 +426,374 @@ unsigned tmp; ...@@ -404,357 +426,374 @@ unsigned tmp;
#define IBUF_SIZE 8 #define IBUF_SIZE 8
Bool Bool
XkbApplyCompatMapToKey(XkbDescPtr xkb,KeyCode key,XkbChangesPtr changes) XkbApplyCompatMapToKey(XkbDescPtr xkb, KeyCode key, XkbChangesPtr changes)
{ {
KeySym * syms; KeySym *syms;
unsigned char explicit,mods; unsigned char explicit, mods;
XkbSymInterpretPtr *interps,ibuf[IBUF_SIZE]; XkbSymInterpretPtr *interps, ibuf[IBUF_SIZE];
int n,nSyms,found; int n, nSyms, found;
unsigned changed,tmp; unsigned changed, tmp;
if ((!xkb)||(!xkb->map)||(!xkb->map->key_sym_map)|| if ((!xkb) || (!xkb->map) || (!xkb->map->key_sym_map) ||
(!xkb->compat)||(!xkb->compat->sym_interpret)|| (!xkb->compat) || (!xkb->compat->sym_interpret) ||
(key<xkb->min_key_code)||(key>xkb->max_key_code)) { (key < xkb->min_key_code) || (key > xkb->max_key_code)) {
return False; return False;
} }
if (((!xkb->server)||(!xkb->server->key_acts))&& if (((!xkb->server) || (!xkb->server->key_acts)) &&
(XkbAllocServerMap(xkb,XkbAllServerInfoMask,0)!=Success)) { (XkbAllocServerMap(xkb, XkbAllServerInfoMask, 0) != Success)) {
return False; return False;
} }
changed= 0; /* keeps track of what has changed in _this_ call */ changed = 0; /* keeps track of what has changed in _this_ call */
explicit= xkb->server->explicit[key]; explicit = xkb->server->explicit[key];
if (explicit&XkbExplicitInterpretMask) /* nothing to do */ if (explicit & XkbExplicitInterpretMask) /* nothing to do */
return True; return True;
mods= (xkb->map->modmap?xkb->map->modmap[key]:0); mods = (xkb->map->modmap ? xkb->map->modmap[key] : 0);
nSyms= XkbKeyNumSyms(xkb,key); nSyms = XkbKeyNumSyms(xkb, key);
syms= XkbKeySymsPtr(xkb,key); syms = XkbKeySymsPtr(xkb, key);
if (nSyms>IBUF_SIZE) { if (nSyms > IBUF_SIZE) {
interps= _XkbTypedCalloc(nSyms,XkbSymInterpretPtr); interps = _XkbTypedCalloc(nSyms, XkbSymInterpretPtr);
if (interps==NULL) { if (interps == NULL) {
interps= ibuf; interps = ibuf;
nSyms= IBUF_SIZE; nSyms = IBUF_SIZE;
} }
} }
else { else {
interps= ibuf; interps = ibuf;
} }
found= 0; found = 0;
for (n=0;n<nSyms;n++) { for (n = 0; n < nSyms; n++) {
unsigned level= (n%XkbKeyGroupsWidth(xkb,key)); unsigned level = (n % XkbKeyGroupsWidth(xkb, key));
interps[n]= NULL;
if (syms[n]!=NoSymbol) { interps[n] = NULL;
interps[n]= _XkbFindMatchingInterp(xkb,syms[n],mods,level); if (syms[n] != NoSymbol) {
if (interps[n]&&interps[n]->act.type!=XkbSA_NoAction) interps[n] = _XkbFindMatchingInterp(xkb, syms[n], mods, level);
found++; if (interps[n] && interps[n]->act.type != XkbSA_NoAction)
else interps[n]= NULL; found++;
} else
interps[n] = NULL;
}
} }
/* 1/28/96 (ef) -- XXX! WORKING HERE */ /* 1/28/96 (ef) -- XXX! WORKING HERE */
if (!found) { if (!found) {
if (xkb->server->key_acts[key]!=0) { if (xkb->server->key_acts[key] != 0) {
xkb->server->key_acts[key]= 0; xkb->server->key_acts[key] = 0;
changed|= XkbKeyActionsMask; changed |= XkbKeyActionsMask;
} }
} }
else { else {
XkbAction *pActs; XkbAction *pActs;
unsigned int new_vmodmask; unsigned int new_vmodmask;
changed|= XkbKeyActionsMask;
pActs= XkbResizeKeyActions(xkb,key,nSyms); changed |= XkbKeyActionsMask;
if (!pActs) { pActs = XkbResizeKeyActions(xkb, key, nSyms);
if (!pActs) {
if (nSyms > IBUF_SIZE) if (nSyms > IBUF_SIZE)
Xfree(interps); Xfree(interps);
return False; return False;
} }
new_vmodmask= 0; new_vmodmask = 0;
for (n=0;n<nSyms;n++) { for (n = 0; n < nSyms; n++) {
if (interps[n]) { if (interps[n]) {
unsigned effMods; unsigned effMods;
pActs[n]= *((XkbAction *)&interps[n]->act); pActs[n] = *((XkbAction *) &interps[n]->act);
if ((n==0)||((interps[n]->match&XkbSI_LevelOneOnly)==0)) { if ((n == 0) || ((interps[n]->match & XkbSI_LevelOneOnly) == 0)) {
effMods= mods; effMods = mods;
if (interps[n]->virtual_mod!=XkbNoModifier) if (interps[n]->virtual_mod != XkbNoModifier)
new_vmodmask|= (1<<interps[n]->virtual_mod); new_vmodmask |= (1 << interps[n]->virtual_mod);
} }
else effMods= 0; else
_XkbSetActionKeyMods(xkb,&pActs[n],effMods); effMods = 0;
} _XkbSetActionKeyMods(xkb, &pActs[n], effMods);
else pActs[n].type= XkbSA_NoAction; }
} else
if (((explicit&XkbExplicitVModMapMask)==0)&& pActs[n].type = XkbSA_NoAction;
(xkb->server->vmodmap[key]!=new_vmodmask)) { }
changed|= XkbVirtualModMapMask; if (((explicit & XkbExplicitVModMapMask) == 0) &&
xkb->server->vmodmap[key]= new_vmodmask; (xkb->server->vmodmap[key] != new_vmodmask)) {
} changed |= XkbVirtualModMapMask;
if (interps[0]) { xkb->server->vmodmap[key] = new_vmodmask;
if ((interps[0]->flags&XkbSI_LockingKey)&& }
((explicit&XkbExplicitBehaviorMask)==0)) { if (interps[0]) {
xkb->server->behaviors[key].type= XkbKB_Lock; if ((interps[0]->flags & XkbSI_LockingKey) &&
changed|= XkbKeyBehaviorsMask; ((explicit & XkbExplicitBehaviorMask) == 0)) {
} xkb->server->behaviors[key].type = XkbKB_Lock;
if (((explicit&XkbExplicitAutoRepeatMask)==0)&&(xkb->ctrls)) { changed |= XkbKeyBehaviorsMask;
CARD8 old; }
old= xkb->ctrls->per_key_repeat[key/8]; if (((explicit & XkbExplicitAutoRepeatMask) == 0) && (xkb->ctrls)) {
if (interps[0]->flags&XkbSI_AutoRepeat) CARD8 old;
xkb->ctrls->per_key_repeat[key/8]|= (1<<(key%8));
else xkb->ctrls->per_key_repeat[key/8]&= ~(1<<(key%8)); old = xkb->ctrls->per_key_repeat[key / 8];
if (changes && (old!=xkb->ctrls->per_key_repeat[key/8])) if (interps[0]->flags & XkbSI_AutoRepeat)
changes->ctrls.changed_ctrls|= XkbPerKeyRepeatMask; xkb->ctrls->per_key_repeat[key / 8] |= (1 << (key % 8));
} else
} xkb->ctrls->per_key_repeat[key / 8] &= ~(1 << (key % 8));
} if (changes && (old != xkb->ctrls->per_key_repeat[key / 8]))
if ((!found)||(interps[0]==NULL)) { changes->ctrls.changed_ctrls |= XkbPerKeyRepeatMask;
if (((explicit&XkbExplicitAutoRepeatMask)==0)&&(xkb->ctrls)) { }
CARD8 old; }
old= xkb->ctrls->per_key_repeat[key/8]; }
if ((!found) || (interps[0] == NULL)) {
if (((explicit & XkbExplicitAutoRepeatMask) == 0) && (xkb->ctrls)) {
CARD8 old;
old = xkb->ctrls->per_key_repeat[key / 8];
#ifdef RETURN_SHOULD_REPEAT #ifdef RETURN_SHOULD_REPEAT
if (*XkbKeySymsPtr(xkb,key) != XK_Return) if (*XkbKeySymsPtr(xkb, key) != XK_Return)
#endif #endif
xkb->ctrls->per_key_repeat[key/8]|= (1<<(key%8)); xkb->ctrls->per_key_repeat[key / 8] |= (1 << (key % 8));
if (changes && (old!=xkb->ctrls->per_key_repeat[key/8])) if (changes && (old != xkb->ctrls->per_key_repeat[key / 8]))
changes->ctrls.changed_ctrls|= XkbPerKeyRepeatMask; changes->ctrls.changed_ctrls |= XkbPerKeyRepeatMask;
} }
if (((explicit&XkbExplicitBehaviorMask)==0)&& if (((explicit & XkbExplicitBehaviorMask) == 0) &&
(xkb->server->behaviors[key].type==XkbKB_Lock)) { (xkb->server->behaviors[key].type == XkbKB_Lock)) {
xkb->server->behaviors[key].type= XkbKB_Default; xkb->server->behaviors[key].type = XkbKB_Default;
changed|= XkbKeyBehaviorsMask; changed |= XkbKeyBehaviorsMask;
} }
} }
if (changes) { if (changes) {
XkbMapChangesPtr mc; XkbMapChangesPtr mc;
mc= &changes->map;
tmp= (changed&mc->changed); mc = &changes->map;
if (tmp&XkbKeyActionsMask) tmp = (changed & mc->changed);
_XkbAddKeyChange(&mc->first_key_act,&mc->num_key_acts,key); if (tmp & XkbKeyActionsMask)
else if (changed&XkbKeyActionsMask) { _XkbAddKeyChange(&mc->first_key_act, &mc->num_key_acts, key);
mc->changed|= XkbKeyActionsMask; else if (changed & XkbKeyActionsMask) {
mc->first_key_act= key; mc->changed |= XkbKeyActionsMask;
mc->num_key_acts= 1; mc->first_key_act = key;
} mc->num_key_acts = 1;
if (tmp&XkbKeyBehaviorsMask) { }
_XkbAddKeyChange(&mc->first_key_behavior,&mc->num_key_behaviors, if (tmp & XkbKeyBehaviorsMask) {
key); _XkbAddKeyChange(&mc->first_key_behavior, &mc->num_key_behaviors,
} key);
else if (changed&XkbKeyBehaviorsMask) { }
mc->changed|= XkbKeyBehaviorsMask; else if (changed & XkbKeyBehaviorsMask) {
mc->first_key_behavior= key; mc->changed |= XkbKeyBehaviorsMask;
mc->num_key_behaviors= 1; mc->first_key_behavior = key;
} mc->num_key_behaviors = 1;
if (tmp&XkbVirtualModMapMask) }
_XkbAddKeyChange(&mc->first_vmodmap_key,&mc->num_vmodmap_keys,key); if (tmp & XkbVirtualModMapMask)
else if (changed&XkbVirtualModMapMask) { _XkbAddKeyChange(&mc->first_vmodmap_key, &mc->num_vmodmap_keys,
mc->changed|= XkbVirtualModMapMask; key);
mc->first_vmodmap_key= key; else if (changed & XkbVirtualModMapMask) {
mc->num_vmodmap_keys= 1; mc->changed |= XkbVirtualModMapMask;
} mc->first_vmodmap_key = key;
mc->changed|= changed; mc->num_vmodmap_keys = 1;
} }
if (interps!=ibuf) mc->changed |= changed;
_XkbFree(interps); }
if (interps != ibuf)
_XkbFree(interps);
return True; return True;
} }
Bool Bool
XkbUpdateMapFromCore( XkbDescPtr xkb, XkbUpdateMapFromCore(XkbDescPtr xkb,
KeyCode first_key, KeyCode first_key,
int num_keys, int num_keys,
int map_width, int map_width,
KeySym * core_keysyms, KeySym *core_keysyms,
XkbChangesPtr changes) XkbChangesPtr changes)
{ {
register int key,last_key; register int key, last_key;
KeySym * syms; KeySym *syms;
syms= &core_keysyms[(first_key-xkb->min_key_code)*map_width]; syms = &core_keysyms[(first_key - xkb->min_key_code) * map_width];
if (changes) { if (changes) {
if (changes->map.changed&XkbKeySymsMask) { if (changes->map.changed & XkbKeySymsMask) {
_XkbAddKeyChange(&changes->map.first_key_sym, _XkbAddKeyChange(&changes->map.first_key_sym,
&changes->map.num_key_syms,first_key); &changes->map.num_key_syms, first_key);
if (num_keys>1) { if (num_keys > 1) {
_XkbAddKeyChange(&changes->map.first_key_sym, _XkbAddKeyChange(&changes->map.first_key_sym,
&changes->map.num_key_syms, &changes->map.num_key_syms,
first_key+num_keys-1); first_key + num_keys - 1);
} }
} }
else { else {
changes->map.changed|= XkbKeySymsMask; changes->map.changed |= XkbKeySymsMask;
changes->map.first_key_sym= first_key; changes->map.first_key_sym = first_key;
changes->map.num_key_syms= num_keys; changes->map.num_key_syms = num_keys;
} }
} }
last_key= first_key+num_keys-1; last_key = first_key + num_keys - 1;
for (key=first_key;key<=last_key;key++,syms+= map_width) { for (key = first_key; key <= last_key; key++, syms += map_width) {
XkbMapChangesPtr mc; XkbMapChangesPtr mc;
unsigned explicit; unsigned explicit;
KeySym tsyms[XkbMaxSymsPerKey]; KeySym tsyms[XkbMaxSymsPerKey];
int types[XkbNumKbdGroups]; int types[XkbNumKbdGroups];
int nG; int nG;
explicit= xkb->server->explicit[key]&XkbExplicitKeyTypesMask; explicit = xkb->server->explicit[key] & XkbExplicitKeyTypesMask;
types[XkbGroup1Index]= XkbKeyKeyTypeIndex(xkb,key,XkbGroup1Index); types[XkbGroup1Index] = XkbKeyKeyTypeIndex(xkb, key, XkbGroup1Index);
types[XkbGroup2Index]= XkbKeyKeyTypeIndex(xkb,key,XkbGroup2Index); types[XkbGroup2Index] = XkbKeyKeyTypeIndex(xkb, key, XkbGroup2Index);
types[XkbGroup3Index]= XkbKeyKeyTypeIndex(xkb,key,XkbGroup3Index); types[XkbGroup3Index] = XkbKeyKeyTypeIndex(xkb, key, XkbGroup3Index);
types[XkbGroup4Index]= XkbKeyKeyTypeIndex(xkb,key,XkbGroup4Index); types[XkbGroup4Index] = XkbKeyKeyTypeIndex(xkb, key, XkbGroup4Index);
nG= XkbKeyTypesForCoreSymbols(xkb,map_width,syms,explicit,types,tsyms); nG = XkbKeyTypesForCoreSymbols(xkb, map_width, syms, explicit, types,
if (changes) tsyms);
mc= &changes->map; if (changes)
else mc= NULL; mc = &changes->map;
XkbChangeTypesOfKey(xkb,key,nG,XkbAllGroupsMask,types,mc); else
memcpy((char *)XkbKeySymsPtr(xkb,key),(char *)tsyms, mc = NULL;
XkbKeyNumSyms(xkb,key)*sizeof(KeySym)); XkbChangeTypesOfKey(xkb, key, nG, XkbAllGroupsMask, types, mc);
XkbApplyCompatMapToKey(xkb,key,changes); memcpy((char *) XkbKeySymsPtr(xkb, key), (char *) tsyms,
} XkbKeyNumSyms(xkb, key) * sizeof(KeySym));
XkbApplyCompatMapToKey(xkb, key, changes);
if ((xkb->map->modmap!=NULL)&&(changes)&& }
(changes->map.changed&(XkbVirtualModMapMask|XkbModifierMapMask))) {
unsigned char newVMods[XkbNumVirtualMods]; if ((xkb->map->modmap != NULL) && (changes) &&
register unsigned bit,i; (changes->map.changed & (XkbVirtualModMapMask | XkbModifierMapMask))) {
unsigned present; unsigned char newVMods[XkbNumVirtualMods];
register unsigned bit, i;
bzero(newVMods,XkbNumVirtualMods); unsigned present;
present= 0;
for (key=xkb->min_key_code;key<=xkb->max_key_code;key++) { bzero(newVMods, XkbNumVirtualMods);
if (xkb->server->vmodmap[key]==0) present = 0;
continue; for (key = xkb->min_key_code; key <= xkb->max_key_code; key++) {
for (i=0,bit=1;i<XkbNumVirtualMods;i++,bit<<=1) { if (xkb->server->vmodmap[key] == 0)
if (bit&xkb->server->vmodmap[key]) { continue;
present|= bit; for (i = 0, bit = 1; i < XkbNumVirtualMods; i++, bit <<= 1) {
newVMods[i]|= xkb->map->modmap[key]; if (bit & xkb->server->vmodmap[key]) {
} present |= bit;
} newVMods[i] |= xkb->map->modmap[key];
} }
for (i=0,bit=1;i<XkbNumVirtualMods;i++,bit<<=1) { }
if ((bit&present)&&(newVMods[i]!=xkb->server->vmods[i])) { }
changes->map.changed|= XkbVirtualModsMask; for (i = 0, bit = 1; i < XkbNumVirtualMods; i++, bit <<= 1) {
changes->map.vmods|= bit; if ((bit & present) && (newVMods[i] != xkb->server->vmods[i])) {
xkb->server->vmods[i]= newVMods[i]; changes->map.changed |= XkbVirtualModsMask;
} changes->map.vmods |= bit;
} xkb->server->vmods[i] = newVMods[i];
} }
if (changes && (changes->map.changed&XkbVirtualModsMask)) }
XkbApplyVirtualModChanges(xkb,changes->map.vmods,changes); }
if (changes && (changes->map.changed & XkbVirtualModsMask))
XkbApplyVirtualModChanges(xkb, changes->map.vmods, changes);
return True; return True;
} }
Status Status
XkbChangeTypesOfKey( XkbDescPtr xkb, XkbChangeTypesOfKey(XkbDescPtr xkb,
int key, int key,
int nGroups, int nGroups,
unsigned groups, unsigned groups,
int * newTypesIn, int *newTypesIn,
XkbMapChangesPtr changes) XkbMapChangesPtr changes)
{ {
XkbKeyTypePtr pOldType,pNewType; XkbKeyTypePtr pOldType, pNewType;
register int i; register int i;
int width,nOldGroups,oldWidth,newTypes[XkbNumKbdGroups]; int width, nOldGroups, oldWidth, newTypes[XkbNumKbdGroups];
if ((!xkb) || (!XkbKeycodeInRange(xkb,key)) || (!xkb->map) || if ((!xkb) || (!XkbKeycodeInRange(xkb, key)) || (!xkb->map) ||
(!xkb->map->types)||((groups&XkbAllGroupsMask)==0)|| (!xkb->map->types) || ((groups & XkbAllGroupsMask) == 0) ||
(nGroups>XkbNumKbdGroups)) { (nGroups > XkbNumKbdGroups)) {
return BadMatch; return BadMatch;
} }
if (nGroups==0) { if (nGroups == 0) {
for (i=0;i<XkbNumKbdGroups;i++) { for (i = 0; i < XkbNumKbdGroups; i++) {
xkb->map->key_sym_map[key].kt_index[i]= XkbOneLevelIndex; xkb->map->key_sym_map[key].kt_index[i] = XkbOneLevelIndex;
} }
i= xkb->map->key_sym_map[key].group_info; i = xkb->map->key_sym_map[key].group_info;
i= XkbSetNumGroups(i,0); i = XkbSetNumGroups(i, 0);
xkb->map->key_sym_map[key].group_info= i; xkb->map->key_sym_map[key].group_info = i;
XkbResizeKeySyms(xkb,key,0); XkbResizeKeySyms(xkb, key, 0);
return Success; return Success;
} }
nOldGroups= XkbKeyNumGroups(xkb,key); nOldGroups = XkbKeyNumGroups(xkb, key);
oldWidth= XkbKeyGroupsWidth(xkb,key); oldWidth = XkbKeyGroupsWidth(xkb, key);
for (width=i=0;i<nGroups;i++) { for (width = i = 0; i < nGroups; i++) {
if (groups&(1<<i)) if (groups & (1 << i))
newTypes[i]= newTypesIn[i]; newTypes[i] = newTypesIn[i];
else if (i<nOldGroups) else if (i < nOldGroups)
newTypes[i]= XkbKeyKeyTypeIndex(xkb,key,i); newTypes[i] = XkbKeyKeyTypeIndex(xkb, key, i);
else if (nOldGroups>0) else if (nOldGroups > 0)
newTypes[i]= XkbKeyKeyTypeIndex(xkb,key,XkbGroup1Index); newTypes[i] = XkbKeyKeyTypeIndex(xkb, key, XkbGroup1Index);
else newTypes[i]= XkbTwoLevelIndex; else
if (newTypes[i]>xkb->map->num_types) newTypes[i] = XkbTwoLevelIndex;
return BadMatch; if (newTypes[i] > xkb->map->num_types)
pNewType= &xkb->map->types[newTypes[i]]; return BadMatch;
if (pNewType->num_levels>width) pNewType = &xkb->map->types[newTypes[i]];
width= pNewType->num_levels; if (pNewType->num_levels > width)
} width = pNewType->num_levels;
if ((xkb->ctrls)&&(nGroups>xkb->ctrls->num_groups)) }
xkb->ctrls->num_groups= nGroups; if ((xkb->ctrls) && (nGroups > xkb->ctrls->num_groups))
if ((width!=oldWidth)||(nGroups!=nOldGroups)) { xkb->ctrls->num_groups = nGroups;
KeySym oldSyms[XkbMaxSymsPerKey],*pSyms; if ((width != oldWidth) || (nGroups != nOldGroups)) {
int nCopy; KeySym oldSyms[XkbMaxSymsPerKey], *pSyms;
int nCopy;
if (nOldGroups==0) {
pSyms= XkbResizeKeySyms(xkb,key,width*nGroups); if (nOldGroups == 0) {
if (pSyms!=NULL) { pSyms = XkbResizeKeySyms(xkb, key, width * nGroups);
i= xkb->map->key_sym_map[key].group_info; if (pSyms != NULL) {
i= XkbSetNumGroups(i,nGroups); i = xkb->map->key_sym_map[key].group_info;
xkb->map->key_sym_map[key].group_info= i; i = XkbSetNumGroups(i, nGroups);
xkb->map->key_sym_map[key].width= width; xkb->map->key_sym_map[key].group_info = i;
for (i=0;i<nGroups;i++) { xkb->map->key_sym_map[key].width = width;
xkb->map->key_sym_map[key].kt_index[i]= newTypes[i]; for (i = 0; i < nGroups; i++) {
} xkb->map->key_sym_map[key].kt_index[i] = newTypes[i];
return Success; }
} return Success;
return BadAlloc; }
} return BadAlloc;
pSyms= XkbKeySymsPtr(xkb,key); }
memcpy(oldSyms,pSyms,XkbKeyNumSyms(xkb,key)*sizeof(KeySym)); pSyms = XkbKeySymsPtr(xkb, key);
pSyms= XkbResizeKeySyms(xkb,key,width*nGroups); memcpy(oldSyms, pSyms, XkbKeyNumSyms(xkb, key) * sizeof(KeySym));
if (pSyms==NULL) pSyms = XkbResizeKeySyms(xkb, key, width * nGroups);
return BadAlloc; if (pSyms == NULL)
bzero(pSyms,width*nGroups*sizeof(KeySym)); return BadAlloc;
for (i=0;(i<nGroups)&&(i<nOldGroups);i++) { bzero(pSyms, width * nGroups * sizeof(KeySym));
pOldType= XkbKeyKeyType(xkb,key,i); for (i = 0; (i < nGroups) && (i < nOldGroups); i++) {
pNewType= &xkb->map->types[newTypes[i]]; pOldType = XkbKeyKeyType(xkb, key, i);
if (pNewType->num_levels>pOldType->num_levels) pNewType = &xkb->map->types[newTypes[i]];
nCopy= pOldType->num_levels; if (pNewType->num_levels > pOldType->num_levels)
else nCopy= pNewType->num_levels; nCopy = pOldType->num_levels;
memcpy(&pSyms[i*width],&oldSyms[i*oldWidth],nCopy*sizeof(KeySym)); else
} nCopy = pNewType->num_levels;
if (XkbKeyHasActions(xkb,key)) { memcpy(&pSyms[i * width], &oldSyms[i * oldWidth],
XkbAction oldActs[XkbMaxSymsPerKey],*pActs; nCopy * sizeof(KeySym));
pActs= XkbKeyActionsPtr(xkb,key); }
memcpy(oldActs,pActs,XkbKeyNumSyms(xkb,key)*sizeof(XkbAction)); if (XkbKeyHasActions(xkb, key)) {
pActs= XkbResizeKeyActions(xkb,key,width*nGroups); XkbAction oldActs[XkbMaxSymsPerKey], *pActs;
if (pActs==NULL)
return BadAlloc; pActs = XkbKeyActionsPtr(xkb, key);
bzero(pActs,width*nGroups*sizeof(XkbAction)); memcpy(oldActs, pActs, XkbKeyNumSyms(xkb, key) * sizeof(XkbAction));
for (i=0;(i<nGroups)&&(i<nOldGroups);i++) { pActs = XkbResizeKeyActions(xkb, key, width * nGroups);
pOldType= XkbKeyKeyType(xkb,key,i); if (pActs == NULL)
pNewType= &xkb->map->types[newTypes[i]]; return BadAlloc;
if (pNewType->num_levels>pOldType->num_levels) bzero(pActs, width * nGroups * sizeof(XkbAction));
nCopy= pOldType->num_levels; for (i = 0; (i < nGroups) && (i < nOldGroups); i++) {
else nCopy= pNewType->num_levels; pOldType = XkbKeyKeyType(xkb, key, i);
memcpy(&pActs[i*width],&oldActs[i*oldWidth], pNewType = &xkb->map->types[newTypes[i]];
nCopy*sizeof(XkbAction)); if (pNewType->num_levels > pOldType->num_levels)
} nCopy = pOldType->num_levels;
} else
i= xkb->map->key_sym_map[key].group_info; nCopy = pNewType->num_levels;
i= XkbSetNumGroups(i,nGroups); memcpy(&pActs[i * width], &oldActs[i * oldWidth],
xkb->map->key_sym_map[key].group_info= i; nCopy * sizeof(XkbAction));
xkb->map->key_sym_map[key].width= width; }
} }
width= 0; i = xkb->map->key_sym_map[key].group_info;
for (i=0;i<nGroups;i++) { i = XkbSetNumGroups(i, nGroups);
xkb->map->key_sym_map[key].kt_index[i]= newTypes[i]; xkb->map->key_sym_map[key].group_info = i;
if (xkb->map->types[newTypes[i]].num_levels>width) xkb->map->key_sym_map[key].width = width;
width= xkb->map->types[newTypes[i]].num_levels; }
} width = 0;
xkb->map->key_sym_map[key].width= width; for (i = 0; i < nGroups; i++) {
if (changes!=NULL) { xkb->map->key_sym_map[key].kt_index[i] = newTypes[i];
if (changes->changed&XkbKeySymsMask) { if (xkb->map->types[newTypes[i]].num_levels > width)
_XkbAddKeyChange(&changes->first_key_sym,&changes->num_key_syms, width = xkb->map->types[newTypes[i]].num_levels;
key); }
} xkb->map->key_sym_map[key].width = width;
else { if (changes != NULL) {
changes->changed|= XkbKeySymsMask; if (changes->changed & XkbKeySymsMask) {
changes->first_key_sym= key; _XkbAddKeyChange(&changes->first_key_sym, &changes->num_key_syms,
changes->num_key_syms= 1; key);
} }
else {
changes->changed |= XkbKeySymsMask;
changes->first_key_sym = key;
changes->num_key_syms = 1;
}
} }
return Success; return Success;
} }
...@@ -762,204 +801,223 @@ int width,nOldGroups,oldWidth,newTypes[XkbNumKbdGroups]; ...@@ -762,204 +801,223 @@ int width,nOldGroups,oldWidth,newTypes[XkbNumKbdGroups];
/***====================================================================***/ /***====================================================================***/
Bool Bool
XkbVirtualModsToReal(XkbDescPtr xkb,unsigned virtual_mask,unsigned *mask_rtrn) XkbVirtualModsToReal(XkbDescPtr xkb, unsigned virtual_mask, unsigned *mask_rtrn)
{ {
register int i,bit; register int i, bit;
register unsigned mask; register unsigned mask;
if (xkb==NULL) if (xkb == NULL)
return False; return False;
if (virtual_mask==0) { if (virtual_mask == 0) {
*mask_rtrn= 0; *mask_rtrn = 0;
return True; return True;
} }
if (xkb->server==NULL) if (xkb->server == NULL)
return False; return False;
for (i=mask=0,bit=1;i<XkbNumVirtualMods;i++,bit<<=1) { for (i = mask = 0, bit = 1; i < XkbNumVirtualMods; i++, bit <<= 1) {
if (virtual_mask&bit) if (virtual_mask & bit)
mask|= xkb->server->vmods[i]; mask |= xkb->server->vmods[i];
} }
*mask_rtrn= mask; *mask_rtrn = mask;
return True; return True;
} }
/***====================================================================***/ /***====================================================================***/
Bool Bool
XkbUpdateActionVirtualMods(XkbDescPtr xkb,XkbAction *act,unsigned changed) XkbUpdateActionVirtualMods(XkbDescPtr xkb, XkbAction *act, unsigned changed)
{ {
unsigned int tmp; unsigned int tmp;
switch (act->type) { switch (act->type) {
case XkbSA_SetMods: case XkbSA_LatchMods: case XkbSA_LockMods: case XkbSA_SetMods:
if (((tmp= XkbModActionVMods(&act->mods))&changed)!=0) { case XkbSA_LatchMods:
XkbVirtualModsToReal(xkb,tmp,&tmp); case XkbSA_LockMods:
act->mods.mask= act->mods.real_mods; if (((tmp = XkbModActionVMods(&act->mods)) & changed) != 0) {
act->mods.mask|= tmp; XkbVirtualModsToReal(xkb, tmp, &tmp);
return True; act->mods.mask = act->mods.real_mods;
} act->mods.mask |= tmp;
break; return True;
case XkbSA_ISOLock: }
if ((((tmp= XkbModActionVMods(&act->iso))!=0)&changed)!=0) { break;
XkbVirtualModsToReal(xkb,tmp,&tmp); case XkbSA_ISOLock:
act->iso.mask= act->iso.real_mods; if ((((tmp = XkbModActionVMods(&act->iso)) != 0) & changed) != 0) {
act->iso.mask|= tmp; XkbVirtualModsToReal(xkb, tmp, &tmp);
return True; act->iso.mask = act->iso.real_mods;
} act->iso.mask |= tmp;
break; return True;
}
break;
} }
return False; return False;
} }
void void
XkbUpdateKeyTypeVirtualMods( XkbDescPtr xkb, XkbUpdateKeyTypeVirtualMods(XkbDescPtr xkb,
XkbKeyTypePtr type, XkbKeyTypePtr type,
unsigned int changed, unsigned int changed,
XkbChangesPtr changes) XkbChangesPtr changes)
{ {
register unsigned int i; register unsigned int i;
unsigned int mask = 0; unsigned int mask = 0;
XkbVirtualModsToReal(xkb,type->mods.vmods,&mask); XkbVirtualModsToReal(xkb, type->mods.vmods, &mask);
type->mods.mask= type->mods.real_mods|mask; type->mods.mask = type->mods.real_mods | mask;
if ((type->map_count>0)&&(type->mods.vmods!=0)) { if ((type->map_count > 0) && (type->mods.vmods != 0)) {
XkbKTMapEntryPtr entry; XkbKTMapEntryPtr entry;
for (i=0,entry=type->map;i<type->map_count;i++,entry++) {
if (entry->mods.vmods!=0) { for (i = 0, entry = type->map; i < type->map_count; i++, entry++) {
XkbVirtualModsToReal(xkb,entry->mods.vmods,&mask); if (entry->mods.vmods != 0) {
entry->mods.mask=entry->mods.real_mods|mask; XkbVirtualModsToReal(xkb, entry->mods.vmods, &mask);
/* entry is active if vmods are bound*/ entry->mods.mask = entry->mods.real_mods | mask;
entry->active= (mask!=0); /* entry is active if vmods are bound */
} entry->active = (mask != 0);
else entry->active= 1; }
} else
entry->active = 1;
}
} }
if (changes) { if (changes) {
int type_ndx; int type_ndx;
type_ndx= type-xkb->map->types;
if ((type_ndx<0)||(type_ndx>xkb->map->num_types)) type_ndx = type - xkb->map->types;
return; if ((type_ndx < 0) || (type_ndx > xkb->map->num_types))
if (changes->map.changed&XkbKeyTypesMask) { return;
int last; if (changes->map.changed & XkbKeyTypesMask) {
last= changes->map.first_type+changes->map.num_types-1; int last;
if (type_ndx<changes->map.first_type) {
changes->map.first_type= type_ndx; last = changes->map.first_type + changes->map.num_types - 1;
changes->map.num_types= (last-type_ndx)+1; if (type_ndx < changes->map.first_type) {
} changes->map.first_type = type_ndx;
else if (type_ndx>last) { changes->map.num_types = (last - type_ndx) + 1;
changes->map.num_types= (type_ndx-changes->map.first_type)+1; }
} else if (type_ndx > last) {
} changes->map.num_types =
else { (type_ndx - changes->map.first_type) + 1;
changes->map.changed|= XkbKeyTypesMask; }
changes->map.first_type= type_ndx; }
changes->map.num_types= 1; else {
} changes->map.changed |= XkbKeyTypesMask;
changes->map.first_type = type_ndx;
changes->map.num_types = 1;
}
} }
return; return;
} }
Bool Bool
XkbApplyVirtualModChanges(XkbDescPtr xkb,unsigned changed,XkbChangesPtr changes) XkbApplyVirtualModChanges(XkbDescPtr xkb,
unsigned changed,
XkbChangesPtr changes)
{ {
register int i; register int i;
unsigned int checkState = 0; unsigned int checkState = 0;
if ((!xkb) || (!xkb->map) || (changed==0)) if ((!xkb) || (!xkb->map) || (changed == 0))
return False; return False;
for (i=0;i<xkb->map->num_types;i++) { for (i = 0; i < xkb->map->num_types; i++) {
if (xkb->map->types[i].mods.vmods & changed) if (xkb->map->types[i].mods.vmods & changed)
XkbUpdateKeyTypeVirtualMods(xkb,&xkb->map->types[i],changed,changes); XkbUpdateKeyTypeVirtualMods(xkb, &xkb->map->types[i], changed,
} changes);
if (changed&xkb->ctrls->internal.vmods) { }
unsigned int newMask = 0; if (changed & xkb->ctrls->internal.vmods) {
XkbVirtualModsToReal(xkb,xkb->ctrls->internal.vmods,&newMask); unsigned int newMask = 0;
newMask|= xkb->ctrls->internal.real_mods;
if (xkb->ctrls->internal.mask!=newMask) { XkbVirtualModsToReal(xkb, xkb->ctrls->internal.vmods, &newMask);
xkb->ctrls->internal.mask= newMask; newMask |= xkb->ctrls->internal.real_mods;
if (changes) { if (xkb->ctrls->internal.mask != newMask) {
changes->ctrls.changed_ctrls|= XkbInternalModsMask; xkb->ctrls->internal.mask = newMask;
checkState= True; if (changes) {
} changes->ctrls.changed_ctrls |= XkbInternalModsMask;
} checkState = True;
} }
if (changed&xkb->ctrls->ignore_lock.vmods) { }
unsigned int newMask = 0; }
XkbVirtualModsToReal(xkb,xkb->ctrls->ignore_lock.vmods,&newMask); if (changed & xkb->ctrls->ignore_lock.vmods) {
newMask|= xkb->ctrls->ignore_lock.real_mods; unsigned int newMask = 0;
if (xkb->ctrls->ignore_lock.mask!=newMask) {
xkb->ctrls->ignore_lock.mask= newMask; XkbVirtualModsToReal(xkb, xkb->ctrls->ignore_lock.vmods, &newMask);
if (changes) { newMask |= xkb->ctrls->ignore_lock.real_mods;
changes->ctrls.changed_ctrls|= XkbIgnoreLockModsMask; if (xkb->ctrls->ignore_lock.mask != newMask) {
checkState= True; xkb->ctrls->ignore_lock.mask = newMask;
} if (changes) {
} changes->ctrls.changed_ctrls |= XkbIgnoreLockModsMask;
} checkState = True;
if (xkb->indicators!=NULL) { }
XkbIndicatorMapPtr map; }
map= &xkb->indicators->maps[0]; }
for (i=0;i<XkbNumIndicators;i++,map++) { if (xkb->indicators != NULL) {
if (map->mods.vmods&changed) { XkbIndicatorMapPtr map;
unsigned int newMask = 0;
XkbVirtualModsToReal(xkb,map->mods.vmods,&newMask); map = &xkb->indicators->maps[0];
newMask|= map->mods.real_mods; for (i = 0; i < XkbNumIndicators; i++, map++) {
if (newMask!=map->mods.mask) { if (map->mods.vmods & changed) {
map->mods.mask= newMask; unsigned int newMask = 0;
if (changes) {
changes->indicators.map_changes|= (1<<i); XkbVirtualModsToReal(xkb, map->mods.vmods, &newMask);
checkState= True; newMask |= map->mods.real_mods;
} if (newMask != map->mods.mask) {
} map->mods.mask = newMask;
} if (changes) {
} changes->indicators.map_changes |= (1 << i);
} checkState = True;
if (xkb->compat!=NULL) { }
XkbCompatMapPtr compat; }
compat= xkb->compat; }
for (i=0;i<XkbNumKbdGroups;i++) { }
unsigned int newMask = 0; }
XkbVirtualModsToReal(xkb,compat->groups[i].vmods,&newMask); if (xkb->compat != NULL) {
newMask|= compat->groups[i].real_mods; XkbCompatMapPtr compat;
if (compat->groups[i].mask!=newMask) {
compat->groups[i].mask= newMask; compat = xkb->compat;
if (changes) { for (i = 0; i < XkbNumKbdGroups; i++) {
changes->compat.changed_groups|= (1<<i); unsigned int newMask = 0;
checkState= True;
} XkbVirtualModsToReal(xkb, compat->groups[i].vmods, &newMask);
} newMask |= compat->groups[i].real_mods;
} if (compat->groups[i].mask != newMask) {
compat->groups[i].mask = newMask;
if (changes) {
changes->compat.changed_groups |= (1 << i);
checkState = True;
}
}
}
} }
if (xkb->map && xkb->server) { if (xkb->map && xkb->server) {
int highChange = 0, lowChange = -1; int highChange = 0, lowChange = -1;
for (i=xkb->min_key_code;i<=xkb->max_key_code;i++) {
if (XkbKeyHasActions(xkb,i)) { for (i = xkb->min_key_code; i <= xkb->max_key_code; i++) {
register XkbAction *pAct; if (XkbKeyHasActions(xkb, i)) {
register int n; register XkbAction *pAct;
register int n;
pAct= XkbKeyActionsPtr(xkb,i);
for (n=XkbKeyNumActions(xkb,i);n>0;n--,pAct++) { pAct = XkbKeyActionsPtr(xkb, i);
if ((pAct->type!=XkbSA_NoAction)&& for (n = XkbKeyNumActions(xkb, i); n > 0; n--, pAct++) {
XkbUpdateActionVirtualMods(xkb,pAct,changed)) { if ((pAct->type != XkbSA_NoAction) &&
if (lowChange<0) XkbUpdateActionVirtualMods(xkb, pAct, changed)) {
lowChange= i; if (lowChange < 0)
highChange= i; lowChange = i;
} highChange = i;
} }
} }
} }
if (changes && (lowChange>0)) { /* something changed */ }
if (changes->map.changed&XkbKeyActionsMask) { if (changes && (lowChange > 0)) { /* something changed */
int last; if (changes->map.changed & XkbKeyActionsMask) {
if (changes->map.first_key_act<lowChange) int last;
lowChange= changes->map.first_key_act;
last= changes->map.first_key_act+changes->map.num_key_acts-1; if (changes->map.first_key_act < lowChange)
if (last>highChange) lowChange = changes->map.first_key_act;
highChange= last; last =
} changes->map.first_key_act + changes->map.num_key_acts - 1;
changes->map.changed|= XkbKeyActionsMask; if (last > highChange)
changes->map.first_key_act= lowChange; highChange = last;
changes->map.num_key_acts= (highChange-lowChange)+1; }
} changes->map.changed |= XkbKeyActionsMask;
changes->map.first_key_act = lowChange;
changes->map.num_key_acts = (highChange - lowChange) + 1;
}
} }
return checkState; return checkState;
} }
...@@ -34,234 +34,240 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. ...@@ -34,234 +34,240 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
static Status static Status
_XkbReadAtoms( XkbReadBufferPtr buf, _XkbReadAtoms(XkbReadBufferPtr buf,
Atom * atoms, Atom *atoms,
int maxAtoms, int maxAtoms,
CARD32 present) CARD32 present)
{ {
register int i,bit; register int i, bit;
for (i=0,bit=1;(i<maxAtoms)&&(present);i++,bit<<=1) { for (i = 0, bit = 1; (i < maxAtoms) && (present); i++, bit <<= 1) {
if (present&bit) { if (present & bit) {
if (!_XkbReadBufferCopy32(buf,(long *)&atoms[i],1)) if (!_XkbReadBufferCopy32(buf, (long *) &atoms[i], 1))
return BadLength; return BadLength;
present&= ~bit; present &= ~bit;
} }
} }
return Success; return Success;
} }
Status Status
_XkbReadGetNamesReply( Display * dpy, _XkbReadGetNamesReply(Display *dpy,
xkbGetNamesReply * rep, xkbGetNamesReply *rep,
XkbDescPtr xkb, XkbDescPtr xkb,
int * nread_rtrn) int *nread_rtrn)
{ {
int i,len; int i, len;
XkbReadBufferRec buf; XkbReadBufferRec buf;
register XkbNamesPtr names; register XkbNamesPtr names;
if ( xkb->device_spec == XkbUseCoreKbd ) if (xkb->device_spec == XkbUseCoreKbd)
xkb->device_spec = rep->deviceID; xkb->device_spec = rep->deviceID;
if ((xkb->names==NULL)&& if ((xkb->names == NULL) &&
(XkbAllocNames(xkb,rep->which, (XkbAllocNames(xkb, rep->which,
rep->nRadioGroups,rep->nKeyAliases)!=Success)) { rep->nRadioGroups, rep->nKeyAliases) != Success)) {
return BadAlloc; return BadAlloc;
} }
names= xkb->names; names = xkb->names;
if (rep->length==0) if (rep->length == 0)
return Success; return Success;
if (!_XkbInitReadBuffer(dpy,&buf,(int)rep->length*4)) if (!_XkbInitReadBuffer(dpy, &buf, (int) rep->length * 4))
return BadAlloc; return BadAlloc;
if (nread_rtrn) if (nread_rtrn)
*nread_rtrn= (int)rep->length*4; *nread_rtrn = (int) rep->length * 4;
if ((rep->which&XkbKeycodesNameMask)&& if ((rep->which & XkbKeycodesNameMask) &&
(!_XkbReadBufferCopy32(&buf,(long *)&names->keycodes,1))) (!_XkbReadBufferCopy32(&buf, (long *) &names->keycodes, 1)))
goto BAILOUT; goto BAILOUT;
if ((rep->which&XkbGeometryNameMask)&& if ((rep->which & XkbGeometryNameMask) &&
(!_XkbReadBufferCopy32(&buf,(long *)&names->geometry,1))) (!_XkbReadBufferCopy32(&buf, (long *) &names->geometry, 1)))
goto BAILOUT; goto BAILOUT;
if ((rep->which&XkbSymbolsNameMask)&& if ((rep->which & XkbSymbolsNameMask) &&
(!_XkbReadBufferCopy32(&buf,(long *)&names->symbols,1))) (!_XkbReadBufferCopy32(&buf, (long *) &names->symbols, 1)))
goto BAILOUT; goto BAILOUT;
if ((rep->which&XkbPhysSymbolsNameMask)&& if ((rep->which & XkbPhysSymbolsNameMask) &&
(!_XkbReadBufferCopy32(&buf,(long *)&names->phys_symbols,1))) (!_XkbReadBufferCopy32(&buf, (long *) &names->phys_symbols, 1)))
goto BAILOUT; goto BAILOUT;
if ((rep->which&XkbTypesNameMask)&& if ((rep->which & XkbTypesNameMask) &&
(!_XkbReadBufferCopy32(&buf,(long *)&names->types,1))) (!_XkbReadBufferCopy32(&buf, (long *) &names->types, 1)))
goto BAILOUT; goto BAILOUT;
if ((rep->which&XkbCompatNameMask)&& if ((rep->which & XkbCompatNameMask) &&
(!_XkbReadBufferCopy32(&buf,(long *)&names->compat,1))) (!_XkbReadBufferCopy32(&buf, (long *) &names->compat, 1)))
goto BAILOUT; goto BAILOUT;
if ( rep->which & XkbKeyTypeNamesMask ) { if (rep->which & XkbKeyTypeNamesMask) {
XkbClientMapPtr map= xkb->map; XkbClientMapPtr map = xkb->map;
XkbKeyTypePtr type; XkbKeyTypePtr type;
len= rep->nTypes*4; len = rep->nTypes * 4;
if (map!=NULL) { if (map != NULL) {
type= map->types; type = map->types;
for (i=0;(i<map->num_types)&&(i<rep->nTypes);i++,type++) { for (i = 0; (i < map->num_types) && (i < rep->nTypes); i++, type++) {
if (!_XkbReadBufferCopy32(&buf,(long *)&type->name,1)) if (!_XkbReadBufferCopy32(&buf, (long *) &type->name, 1))
goto BAILOUT; goto BAILOUT;
len-= 4; len -= 4;
} }
} }
if ((len>0)&&(!_XkbSkipReadBufferData(&buf,len))) if ((len > 0) && (!_XkbSkipReadBufferData(&buf, len)))
goto BAILOUT; goto BAILOUT;
} }
if ( rep->which&XkbKTLevelNamesMask ) { if (rep->which & XkbKTLevelNamesMask) {
CARD8 *nLevels; CARD8 *nLevels;
XkbClientMapPtr map= xkb->map; XkbClientMapPtr map = xkb->map;
XkbKeyTypePtr type; XkbKeyTypePtr type;
nLevels=(CARD8*)_XkbGetReadBufferPtr(&buf,XkbPaddedSize(rep->nTypes)); nLevels =
if (nLevels==NULL) (CARD8 *) _XkbGetReadBufferPtr(&buf, XkbPaddedSize(rep->nTypes));
goto BAILOUT; if (nLevels == NULL)
if (map!=NULL) { goto BAILOUT;
type= map->types; if (map != NULL) {
for (i=0;i<(int)rep->nTypes;i++,type++) { type = map->types;
if (i>=map->num_types) { for (i = 0; i < (int) rep->nTypes; i++, type++) {
if (!_XkbSkipReadBufferData(&buf,nLevels[i]*4)) if (i >= map->num_types) {
goto BAILOUT; if (!_XkbSkipReadBufferData(&buf, nLevels[i] * 4))
continue; goto BAILOUT;
} continue;
if ((nLevels[i]>0)&&(nLevels[i]!=type->num_levels)) { }
goto BAILOUT; if ((nLevels[i] > 0) && (nLevels[i] != type->num_levels)) {
} goto BAILOUT;
if (type->level_names!=NULL) }
Xfree(type->level_names); if (type->level_names != NULL)
if (nLevels[i]==0) { Xfree(type->level_names);
type->level_names= NULL; if (nLevels[i] == 0) {
continue; type->level_names = NULL;
} continue;
type->level_names= _XkbTypedCalloc(nLevels[i],Atom); }
if (type->level_names!=NULL) { type->level_names = _XkbTypedCalloc(nLevels[i], Atom);
if (!_XkbReadBufferCopy32(&buf,(long *)type->level_names, if (type->level_names != NULL) {
nLevels[i])) if (!_XkbReadBufferCopy32(&buf, (long *) type->level_names,
goto BAILOUT; nLevels[i]))
} goto BAILOUT;
else { }
_XkbSkipReadBufferData(&buf,nLevels[i]*4); else {
} _XkbSkipReadBufferData(&buf, nLevels[i] * 4);
} }
} }
else { }
for (i=0;i<(int)rep->nTypes;i++) { else {
_XkbSkipReadBufferData(&buf,nLevels[i]*4); for (i = 0; i < (int) rep->nTypes; i++) {
} _XkbSkipReadBufferData(&buf, nLevels[i] * 4);
} }
}
} }
if (rep->which & XkbIndicatorNamesMask) { if (rep->which & XkbIndicatorNamesMask) {
if (_XkbReadAtoms(&buf,names->indicators,XkbNumIndicators, if (_XkbReadAtoms(&buf, names->indicators, XkbNumIndicators,
rep->indicators)!=Success) rep->indicators) != Success)
goto BAILOUT; goto BAILOUT;
} }
if ( rep->which&XkbVirtualModNamesMask ) { if (rep->which & XkbVirtualModNamesMask) {
if (_XkbReadAtoms(&buf,names->vmods,XkbNumVirtualMods, if (_XkbReadAtoms(&buf, names->vmods, XkbNumVirtualMods,
(CARD32)rep->virtualMods)!=Success) (CARD32) rep->virtualMods) != Success)
goto BAILOUT; goto BAILOUT;
} }
if ( rep->which&XkbGroupNamesMask ) { if (rep->which & XkbGroupNamesMask) {
if (_XkbReadAtoms(&buf,names->groups,XkbNumKbdGroups, if (_XkbReadAtoms(&buf, names->groups, XkbNumKbdGroups,
(CARD32)rep->groupNames)!=Success) (CARD32) rep->groupNames) != Success)
goto BAILOUT; goto BAILOUT;
} }
if ( rep->which&XkbKeyNamesMask ) { if (rep->which & XkbKeyNamesMask) {
if (names->keys==NULL) { if (names->keys == NULL) {
int nKeys; int nKeys;
if (xkb->max_key_code==0) {
xkb->min_key_code= rep->minKeyCode; if (xkb->max_key_code == 0) {
xkb->max_key_code= rep->maxKeyCode; xkb->min_key_code = rep->minKeyCode;
} xkb->max_key_code = rep->maxKeyCode;
nKeys= xkb->max_key_code+1; }
names->keys= _XkbTypedCalloc(nKeys,XkbKeyNameRec); nKeys = xkb->max_key_code + 1;
} names->keys = _XkbTypedCalloc(nKeys, XkbKeyNameRec);
if ( ((int)rep->firstKey + rep->nKeys) > xkb->max_key_code + 1) }
goto BAILOUT; if (((int) rep->firstKey + rep->nKeys) > xkb->max_key_code + 1)
if (names->keys!=NULL) { goto BAILOUT;
if (!_XkbCopyFromReadBuffer(&buf, if (names->keys != NULL) {
(char *)&names->keys[rep->firstKey], if (!_XkbCopyFromReadBuffer(&buf,
rep->nKeys*XkbKeyNameLength)) (char *) &names->keys[rep->firstKey],
goto BAILOUT; rep->nKeys * XkbKeyNameLength))
} goto BAILOUT;
else _XkbSkipReadBufferData(&buf,rep->nKeys*XkbKeyNameLength); }
} else
if ( rep->which&XkbKeyAliasesMask && (rep->nKeyAliases>0) ) { _XkbSkipReadBufferData(&buf, rep->nKeys * XkbKeyNameLength);
if (XkbAllocNames(xkb,XkbKeyAliasesMask,0,rep->nKeyAliases)!=Success) }
goto BAILOUT; if (rep->which & XkbKeyAliasesMask && (rep->nKeyAliases > 0)) {
if (!_XkbCopyFromReadBuffer(&buf,(char *)names->key_aliases, if (XkbAllocNames(xkb, XkbKeyAliasesMask, 0, rep->nKeyAliases) !=
rep->nKeyAliases*XkbKeyNameLength*2)) Success)
goto BAILOUT; goto BAILOUT;
} if (!_XkbCopyFromReadBuffer(&buf, (char *) names->key_aliases,
if ( rep->which&XkbRGNamesMask ) { rep->nKeyAliases * XkbKeyNameLength * 2))
if (rep->nRadioGroups>0) { goto BAILOUT;
Atom *rgNames; }
if (rep->which & XkbRGNamesMask) {
if (names->radio_groups==NULL) if (rep->nRadioGroups > 0) {
names->radio_groups = _XkbTypedCalloc(rep->nRadioGroups,Atom); Atom *rgNames;
else if (names->num_rg<rep->nRadioGroups) {
names->radio_groups = _XkbTypedRealloc(names->radio_groups, if (names->radio_groups == NULL)
rep->nRadioGroups, names->radio_groups = _XkbTypedCalloc(rep->nRadioGroups, Atom);
Atom); else if (names->num_rg < rep->nRadioGroups) {
} names->radio_groups = _XkbTypedRealloc(names->radio_groups,
rgNames= names->radio_groups; rep->nRadioGroups, Atom);
if (!rgNames) { }
goto BAILOUT; rgNames = names->radio_groups;
} if (!rgNames) {
if (!_XkbReadBufferCopy32(&buf,(long *)rgNames,rep->nRadioGroups)) goto BAILOUT;
goto BAILOUT; }
names->num_rg= rep->nRadioGroups; if (!_XkbReadBufferCopy32
} (&buf, (long *) rgNames, rep->nRadioGroups))
else if (names->num_rg>0) { goto BAILOUT;
names->num_rg= 0; names->num_rg = rep->nRadioGroups;
Xfree(names->radio_groups); }
} else if (names->num_rg > 0) {
} names->num_rg = 0;
len= _XkbFreeReadBuffer(&buf); Xfree(names->radio_groups);
if (len!=0) return BadLength; }
else return Success; }
BAILOUT: len = _XkbFreeReadBuffer(&buf);
if (len != 0)
return BadLength;
else
return Success;
BAILOUT:
_XkbFreeReadBuffer(&buf); _XkbFreeReadBuffer(&buf);
return BadLength; return BadLength;
} }
Status Status
XkbGetNames(Display *dpy,unsigned which,XkbDescPtr xkb) XkbGetNames(Display *dpy, unsigned which, XkbDescPtr xkb)
{ {
register xkbGetNamesReq *req; register xkbGetNamesReq *req;
xkbGetNamesReply rep; xkbGetNamesReply rep;
Status status; Status status;
XkbInfoPtr xkbi; XkbInfoPtr xkbi;
if ((dpy->flags & XlibDisplayNoXkb) || if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return BadAccess; return BadAccess;
LockDisplay(dpy); LockDisplay(dpy);
xkbi = dpy->xkb_info; xkbi = dpy->xkb_info;
if (!xkb->names) { if (!xkb->names) {
xkb->names = _XkbTypedCalloc(1,XkbNamesRec); xkb->names = _XkbTypedCalloc(1, XkbNamesRec);
if (!xkb->names) { if (!xkb->names) {
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
return BadAlloc; return BadAlloc;
} }
} }
GetReq(kbGetNames, req); GetReq(kbGetNames, req);
req->reqType = xkbi->codes->major_opcode; req->reqType = xkbi->codes->major_opcode;
req->xkbReqType = X_kbGetNames; req->xkbReqType = X_kbGetNames;
req->deviceSpec = xkb->device_spec; req->deviceSpec = xkb->device_spec;
req->which = which; req->which = which;
if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) {
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
return BadImplementation; return BadImplementation;
} }
status = _XkbReadGetNamesReply(dpy,&rep,xkb,NULL); status = _XkbReadGetNamesReply(dpy, &rep, xkb, NULL);
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
return status; return status;
...@@ -270,12 +276,12 @@ XkbGetNames(Display *dpy,unsigned which,XkbDescPtr xkb) ...@@ -270,12 +276,12 @@ XkbGetNames(Display *dpy,unsigned which,XkbDescPtr xkb)
/***====================================================================***/ /***====================================================================***/
static int static int
_XkbCountBits(int nBitsMax,unsigned long mask) _XkbCountBits(int nBitsMax, unsigned long mask)
{ {
register unsigned long y, nBits; register unsigned long y, nBits;
y = (mask >> 1) &033333333333; y = (mask >> 1) & 033333333333;
y = mask - y - ((y >>1) & 033333333333); y = mask - y - ((y >> 1) & 033333333333);
nBits = ((unsigned int) (((y + (y >> 3)) & 030707070707) % 077)); nBits = ((unsigned int) (((y + (y >> 3)) & 030707070707) % 077));
/* nBitsMax really means max+1 */ /* nBitsMax really means max+1 */
...@@ -283,85 +289,87 @@ register unsigned long y, nBits; ...@@ -283,85 +289,87 @@ register unsigned long y, nBits;
} }
static CARD32 static CARD32
_XkbCountAtoms(Atom *atoms,int maxAtoms,int *count) _XkbCountAtoms(Atom *atoms, int maxAtoms, int *count)
{ {
register unsigned int i,bit,nAtoms; register unsigned int i, bit, nAtoms;
register CARD32 atomsPresent; register CARD32 atomsPresent;
for (i=nAtoms=atomsPresent=0,bit=1;i<maxAtoms;i++,bit<<=1) { for (i = nAtoms = atomsPresent = 0, bit = 1; i < maxAtoms; i++, bit <<= 1) {
if (atoms[i]!=None) { if (atoms[i] != None) {
atomsPresent|= bit; atomsPresent |= bit;
nAtoms++; nAtoms++;
} }
} }
if (count) if (count)
*count= nAtoms; *count = nAtoms;
return atomsPresent; return atomsPresent;
} }
static void static void
_XkbCopyAtoms(Display *dpy,Atom *atoms,CARD32 mask,int maxAtoms) _XkbCopyAtoms(Display *dpy, Atom *atoms, CARD32 mask, int maxAtoms)
{ {
register unsigned int i,bit; register unsigned int i, bit;
for (i=0,bit=1;i<maxAtoms;i++,bit<<=1) { for (i = 0, bit = 1; i < maxAtoms; i++, bit <<= 1) {
if (mask&bit) if (mask & bit)
Data32(dpy,&atoms[i],4); Data32(dpy, &atoms[i], 4);
} }
return; return;
} }
Bool Bool
XkbSetNames( Display * dpy, XkbSetNames(Display *dpy,
unsigned int which, unsigned int which,
unsigned int firstType, unsigned int firstType,
unsigned int nTypes, unsigned int nTypes,
XkbDescPtr xkb) XkbDescPtr xkb)
{ {
register xkbSetNamesReq *req; register xkbSetNamesReq *req;
int nLvlNames = 0; int nLvlNames = 0;
XkbInfoPtr xkbi; XkbInfoPtr xkbi;
XkbNamesPtr names; XkbNamesPtr names;
unsigned firstLvlType,nLvlTypes; unsigned firstLvlType, nLvlTypes;
int nVMods,nLEDs,nRG,nKA,nGroups; int nVMods, nLEDs, nRG, nKA, nGroups;
int nKeys=0,firstKey=0,nAtoms; int nKeys = 0, firstKey = 0, nAtoms;
CARD32 leds,vmods,groups; CARD32 leds, vmods, groups;
if ((dpy->flags & XlibDisplayNoXkb) || if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return False; return False;
if ((!xkb)||(!xkb->names)) if ((!xkb) || (!xkb->names))
return False; return False;
firstLvlType= firstType; firstLvlType = firstType;
nLvlTypes= nTypes; nLvlTypes = nTypes;
if (nTypes<1) if (nTypes < 1)
which&= ~(XkbKTLevelNamesMask|XkbKeyTypeNamesMask); which &= ~(XkbKTLevelNamesMask | XkbKeyTypeNamesMask);
else if (firstType<=XkbLastRequiredType) { else if (firstType <= XkbLastRequiredType) {
int adjust; int adjust;
adjust= XkbLastRequiredType-firstType+1;
firstType+= adjust; adjust = XkbLastRequiredType - firstType + 1;
nTypes-= adjust; firstType += adjust;
if (nTypes<1) nTypes -= adjust;
which&= ~XkbKeyTypeNamesMask; if (nTypes < 1)
} which &= ~XkbKeyTypeNamesMask;
names= xkb->names; }
if (which&(XkbKTLevelNamesMask|XkbKeyTypeNamesMask)) { names = xkb->names;
register int i; if (which & (XkbKTLevelNamesMask | XkbKeyTypeNamesMask)) {
XkbKeyTypePtr type; register int i;
if((xkb->map==NULL)||(xkb->map->types==NULL)||(nTypes==0)|| XkbKeyTypePtr type;
(firstType+nTypes>xkb->map->num_types)||
(firstLvlType+nLvlTypes>xkb->map->num_types)) if ((xkb->map == NULL) || (xkb->map->types == NULL) || (nTypes == 0) ||
return False; (firstType + nTypes > xkb->map->num_types) ||
if (which&XkbKTLevelNamesMask) { (firstLvlType + nLvlTypes > xkb->map->num_types))
type= &xkb->map->types[firstLvlType]; return False;
for (i=nLvlNames=0;i<nLvlTypes;i++,type++) { if (which & XkbKTLevelNamesMask) {
if (type->level_names!=NULL) type = &xkb->map->types[firstLvlType];
nLvlNames+= type->num_levels; for (i = nLvlNames = 0; i < nLvlTypes; i++, type++) {
} if (type->level_names != NULL)
} nLvlNames += type->num_levels;
} }
}
nVMods= nLEDs= nRG= nKA= nAtoms= nGroups= 0; }
nVMods = nLEDs = nRG = nKA = nAtoms = nGroups = 0;
LockDisplay(dpy); LockDisplay(dpy);
xkbi = dpy->xkb_info; xkbi = dpy->xkb_info;
GetReq(kbSetNames, req); GetReq(kbSetNames, req);
...@@ -371,138 +379,149 @@ XkbSetNames( Display * dpy, ...@@ -371,138 +379,149 @@ XkbSetNames( Display * dpy,
req->firstType = firstType; req->firstType = firstType;
req->nTypes = nTypes; req->nTypes = nTypes;
req->firstKey = xkb->min_key_code; req->firstKey = xkb->min_key_code;
req->nKeys = xkb->max_key_code-xkb->min_key_code+1; req->nKeys = xkb->max_key_code - xkb->min_key_code + 1;
if (which&XkbKeycodesNameMask) if (which & XkbKeycodesNameMask)
nAtoms++; nAtoms++;
if (which&XkbGeometryNameMask) if (which & XkbGeometryNameMask)
nAtoms++; nAtoms++;
if (which&XkbSymbolsNameMask) if (which & XkbSymbolsNameMask)
nAtoms++; nAtoms++;
if (which&XkbPhysSymbolsNameMask) if (which & XkbPhysSymbolsNameMask)
nAtoms++; nAtoms++;
if (which&XkbTypesNameMask) if (which & XkbTypesNameMask)
nAtoms++; nAtoms++;
if (which&XkbCompatNameMask) if (which & XkbCompatNameMask)
nAtoms++; nAtoms++;
if (which&XkbKeyTypeNamesMask) if (which & XkbKeyTypeNamesMask)
nAtoms+= nTypes; nAtoms += nTypes;
if (which&XkbKTLevelNamesMask) { if (which & XkbKTLevelNamesMask) {
req->firstKTLevel= firstLvlType; req->firstKTLevel = firstLvlType;
req->nKTLevels= nLvlTypes; req->nKTLevels = nLvlTypes;
req->length+= XkbPaddedSize(nLvlTypes)/4; /* room for group widths */ req->length += XkbPaddedSize(nLvlTypes) / 4; /* room for group widths */
nAtoms+= nLvlNames; nAtoms += nLvlNames;
} }
else req->firstKTLevel= req->nKTLevels= 0; else
req->firstKTLevel = req->nKTLevels = 0;
if (which&XkbIndicatorNamesMask) {
req->indicators= leds= if (which & XkbIndicatorNamesMask) {
_XkbCountAtoms(names->indicators,XkbNumIndicators,&nLEDs); req->indicators = leds =
if (nLEDs>0) _XkbCountAtoms(names->indicators, XkbNumIndicators, &nLEDs);
nAtoms+= nLEDs; if (nLEDs > 0)
else which&= ~XkbIndicatorNamesMask; nAtoms += nLEDs;
} else
else req->indicators= leds= 0; which &= ~XkbIndicatorNamesMask;
}
if (which&XkbVirtualModNamesMask) { else
vmods= req->virtualMods= (CARD16) req->indicators = leds = 0;
_XkbCountAtoms(names->vmods,XkbNumVirtualMods,&nVMods);
if (nVMods>0) if (which & XkbVirtualModNamesMask) {
nAtoms+= nVMods; vmods = req->virtualMods = (CARD16)
else which&= ~XkbVirtualModNamesMask; _XkbCountAtoms(names->vmods, XkbNumVirtualMods, &nVMods);
} if (nVMods > 0)
else vmods= req->virtualMods= 0; nAtoms += nVMods;
else
if (which&XkbGroupNamesMask) { which &= ~XkbVirtualModNamesMask;
groups= req->groupNames= (CARD8) }
_XkbCountAtoms(names->groups,XkbNumKbdGroups,&nGroups); else
if (nGroups>0) vmods = req->virtualMods = 0;
nAtoms+= nGroups;
else which&= ~XkbGroupNamesMask; if (which & XkbGroupNamesMask) {
} groups = req->groupNames = (CARD8)
else groups= req->groupNames= 0; _XkbCountAtoms(names->groups, XkbNumKbdGroups, &nGroups);
if (nGroups > 0)
if ((which&XkbKeyNamesMask)&&(names->keys!=NULL)) { nAtoms += nGroups;
firstKey= req->firstKey; else
nKeys= req->nKeys; which &= ~XkbGroupNamesMask;
nAtoms+= nKeys; /* technically not atoms, but 4 bytes wide */ }
} else
else which&= ~XkbKeyNamesMask; groups = req->groupNames = 0;
if (which&XkbKeyAliasesMask) { if ((which & XkbKeyNamesMask) && (names->keys != NULL)) {
nKA= ((names->key_aliases!=NULL)?names->num_key_aliases:0); firstKey = req->firstKey;
if (nKA>0) { nKeys = req->nKeys;
req->nKeyAliases= nKA; nAtoms += nKeys; /* technically not atoms, but 4 bytes wide */
nAtoms+= nKA*2; /* not atoms, but 8 bytes on the wire */ }
} else
else { which &= ~XkbKeyNamesMask;
which&= ~XkbKeyAliasesMask;
req->nKeyAliases = 0; if (which & XkbKeyAliasesMask) {
} nKA = ((names->key_aliases != NULL) ? names->num_key_aliases : 0);
} if (nKA > 0) {
else req->nKeyAliases= 0; req->nKeyAliases = nKA;
nAtoms += nKA * 2; /* not atoms, but 8 bytes on the wire */
if (which&XkbRGNamesMask) { }
nRG= names->num_rg; else {
if (nRG>0) which &= ~XkbKeyAliasesMask;
nAtoms+= nRG; req->nKeyAliases = 0;
else which&= ~XkbRGNamesMask; }
} }
else
req->which= which; req->nKeyAliases = 0;
req->nRadioGroups= nRG;
req->length+= (nAtoms*4)/4; if (which & XkbRGNamesMask) {
nRG = names->num_rg;
if (which&XkbKeycodesNameMask) if (nRG > 0)
Data32(dpy,(long *)&names->keycodes,4); nAtoms += nRG;
if (which&XkbGeometryNameMask) else
Data32(dpy,(long *)&names->geometry,4); which &= ~XkbRGNamesMask;
if (which&XkbSymbolsNameMask) }
Data32(dpy,(long *)&names->symbols,4);
if (which&XkbPhysSymbolsNameMask) req->which = which;
Data32(dpy,(long *)&names->phys_symbols,4); req->nRadioGroups = nRG;
if (which&XkbTypesNameMask) req->length += (nAtoms * 4) / 4;
Data32(dpy,(long *)&names->types,4);
if (which&XkbCompatNameMask) if (which & XkbKeycodesNameMask)
Data32(dpy,(long *)&names->compat,4); Data32(dpy, (long *) &names->keycodes, 4);
if (which&XkbKeyTypeNamesMask) { if (which & XkbGeometryNameMask)
register int i; Data32(dpy, (long *) &names->geometry, 4);
register XkbKeyTypePtr type; if (which & XkbSymbolsNameMask)
type= &xkb->map->types[firstType]; Data32(dpy, (long *) &names->symbols, 4);
for (i=0;i<nTypes;i++,type++) { if (which & XkbPhysSymbolsNameMask)
Data32(dpy,(long *)&type->name,4); Data32(dpy, (long *) &names->phys_symbols, 4);
} if (which & XkbTypesNameMask)
} Data32(dpy, (long *) &names->types, 4);
if (which&XkbKTLevelNamesMask) { if (which & XkbCompatNameMask)
XkbKeyTypePtr type; Data32(dpy, (long *) &names->compat, 4);
int i; if (which & XkbKeyTypeNamesMask) {
char *tmp; register int i;
register XkbKeyTypePtr type;
BufAlloc(char *,tmp,XkbPaddedSize(nLvlTypes));
type = &xkb->map->types[firstLvlType]; type = &xkb->map->types[firstType];
for (i=0;i<nLvlTypes;i++,type++) { for (i = 0; i < nTypes; i++, type++) {
*tmp++ = type->num_levels; Data32(dpy, (long *) &type->name, 4);
} }
type = &xkb->map->types[firstLvlType]; }
for (i=0;i<nLvlTypes;i++,type++) { if (which & XkbKTLevelNamesMask) {
if (type->level_names!=NULL) XkbKeyTypePtr type;
Data32(dpy,(long *)type->level_names,type->num_levels*4); int i;
} char *tmp;
}
if (which&XkbIndicatorNamesMask) BufAlloc(char *, tmp, XkbPaddedSize(nLvlTypes));
_XkbCopyAtoms(dpy,names->indicators,leds,XkbNumIndicators); type = &xkb->map->types[firstLvlType];
if (which&XkbVirtualModNamesMask) for (i = 0; i < nLvlTypes; i++, type++) {
_XkbCopyAtoms(dpy,names->vmods,vmods,XkbNumVirtualMods); *tmp++ = type->num_levels;
if (which&XkbGroupNamesMask) }
_XkbCopyAtoms(dpy,names->groups,groups,XkbNumKbdGroups); type = &xkb->map->types[firstLvlType];
if (which&XkbKeyNamesMask) { for (i = 0; i < nLvlTypes; i++, type++) {
Data(dpy,(char *)&names->keys[firstKey],nKeys*XkbKeyNameLength); if (type->level_names != NULL)
} Data32(dpy, (long *) type->level_names, type->num_levels * 4);
if (which&XkbKeyAliasesMask) { }
Data(dpy,(char *)names->key_aliases,nKA*XkbKeyNameLength*2); }
} if (which & XkbIndicatorNamesMask)
if (which&XkbRGNamesMask) { _XkbCopyAtoms(dpy, names->indicators, leds, XkbNumIndicators);
Data32(dpy,(long *)names->radio_groups,nRG*4); if (which & XkbVirtualModNamesMask)
_XkbCopyAtoms(dpy, names->vmods, vmods, XkbNumVirtualMods);
if (which & XkbGroupNamesMask)
_XkbCopyAtoms(dpy, names->groups, groups, XkbNumKbdGroups);
if (which & XkbKeyNamesMask) {
Data(dpy, (char *) &names->keys[firstKey], nKeys * XkbKeyNameLength);
}
if (which & XkbKeyAliasesMask) {
Data(dpy, (char *) names->key_aliases, nKA * XkbKeyNameLength * 2);
}
if (which & XkbRGNamesMask) {
Data32(dpy, (long *) names->radio_groups, nRG * 4);
} }
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
...@@ -510,90 +529,94 @@ XkbSetNames( Display * dpy, ...@@ -510,90 +529,94 @@ XkbSetNames( Display * dpy,
} }
Bool Bool
XkbChangeNames(Display *dpy,XkbDescPtr xkb,XkbNameChangesPtr changes) XkbChangeNames(Display *dpy, XkbDescPtr xkb, XkbNameChangesPtr changes)
{ {
register xkbSetNamesReq *req; register xkbSetNamesReq *req;
int nLvlNames = 0; int nLvlNames = 0;
XkbInfoPtr xkbi; XkbInfoPtr xkbi;
XkbNamesPtr names; XkbNamesPtr names;
unsigned which,firstType,nTypes; unsigned which, firstType, nTypes;
unsigned firstLvlType,nLvlTypes; unsigned firstLvlType, nLvlTypes;
int nVMods,nLEDs,nRG,nKA,nGroups; int nVMods, nLEDs, nRG, nKA, nGroups;
int nKeys=0,firstKey=0,nAtoms; int nKeys = 0, firstKey = 0, nAtoms;
CARD32 leds=0,vmods=0,groups=0; CARD32 leds = 0, vmods = 0, groups = 0;
if ((dpy->flags & XlibDisplayNoXkb) || if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return False; return False;
if ((!xkb)||(!xkb->names)||(!changes)) if ((!xkb) || (!xkb->names) || (!changes))
return False; return False;
which= changes->changed; which = changes->changed;
firstType= changes->first_type; firstType = changes->first_type;
nTypes= changes->num_types; nTypes = changes->num_types;
firstLvlType= changes->first_lvl;; firstLvlType = changes->first_lvl;;
nLvlTypes= changes->num_lvls; nLvlTypes = changes->num_lvls;
if (which&XkbKeyTypeNamesMask) { if (which & XkbKeyTypeNamesMask) {
if (nTypes<1) if (nTypes < 1)
which&= ~XkbKeyTypeNamesMask; which &= ~XkbKeyTypeNamesMask;
else if (firstType<=XkbLastRequiredType) { else if (firstType <= XkbLastRequiredType) {
int adjust; int adjust;
adjust= XkbLastRequiredType-firstType+1;
firstType+= adjust; adjust = XkbLastRequiredType - firstType + 1;
nTypes-= adjust; firstType += adjust;
if (nTypes<1) nTypes -= adjust;
which&= ~XkbKeyTypeNamesMask; if (nTypes < 1)
} which &= ~XkbKeyTypeNamesMask;
} }
else firstType= nTypes= 0; }
else
if (which&XkbKTLevelNamesMask) { firstType = nTypes = 0;
if (nLvlTypes<1)
which&= ~XkbKTLevelNamesMask; if (which & XkbKTLevelNamesMask) {
} if (nLvlTypes < 1)
else firstLvlType= nLvlTypes= 0; which &= ~XkbKTLevelNamesMask;
}
names= xkb->names; else
if (which&(XkbKTLevelNamesMask|XkbKeyTypeNamesMask)) { firstLvlType = nLvlTypes = 0;
register int i;
XkbKeyTypePtr type; names = xkb->names;
if((xkb->map==NULL)||(xkb->map->types==NULL)||(nTypes==0)|| if (which & (XkbKTLevelNamesMask | XkbKeyTypeNamesMask)) {
(firstType+nTypes>xkb->map->num_types)|| register int i;
(firstLvlType+nLvlTypes>xkb->map->num_types)) XkbKeyTypePtr type;
return False;
if (which&XkbKTLevelNamesMask) { if ((xkb->map == NULL) || (xkb->map->types == NULL) || (nTypes == 0) ||
type= &xkb->map->types[firstLvlType]; (firstType + nTypes > xkb->map->num_types) ||
for (i=nLvlNames=0;i<nLvlTypes;i++,type++) { (firstLvlType + nLvlTypes > xkb->map->num_types))
if (type->level_names!=NULL) return False;
nLvlNames+= type->num_levels; if (which & XkbKTLevelNamesMask) {
} type = &xkb->map->types[firstLvlType];
} for (i = nLvlNames = 0; i < nLvlTypes; i++, type++) {
} if (type->level_names != NULL)
nLvlNames += type->num_levels;
if (changes->num_keys<1) }
which&= ~XkbKeyNamesMask; }
if ((which&XkbKeyNamesMask)==0) }
changes->first_key= changes->num_keys= 0;
else if ((changes->first_key<xkb->min_key_code)|| if (changes->num_keys < 1)
(changes->first_key+changes->num_keys>xkb->max_key_code)) { which &= ~XkbKeyNamesMask;
return False; if ((which & XkbKeyNamesMask) == 0)
} changes->first_key = changes->num_keys = 0;
else if ((changes->first_key < xkb->min_key_code) ||
if ((which&XkbVirtualModNamesMask)==0) (changes->first_key + changes->num_keys > xkb->max_key_code)) {
changes->changed_vmods= 0; return False;
else if (changes->changed_vmods==0) }
which&= ~XkbVirtualModNamesMask;
if ((which & XkbVirtualModNamesMask) == 0)
if ((which&XkbIndicatorNamesMask)==0) changes->changed_vmods = 0;
changes->changed_indicators= 0; else if (changes->changed_vmods == 0)
else if (changes->changed_indicators==0) which &= ~XkbVirtualModNamesMask;
which&= ~XkbIndicatorNamesMask;
if ((which & XkbIndicatorNamesMask) == 0)
if ((which&XkbGroupNamesMask)==0) changes->changed_indicators = 0;
changes->changed_groups= 0; else if (changes->changed_indicators == 0)
else if (changes->changed_groups==0) which &= ~XkbIndicatorNamesMask;
which&= ~XkbGroupNamesMask;
if ((which & XkbGroupNamesMask) == 0)
nVMods= nLEDs= nRG= nKA= nAtoms= nGroups= 0; changes->changed_groups = 0;
else if (changes->changed_groups == 0)
which &= ~XkbGroupNamesMask;
nVMods = nLEDs = nRG = nKA = nAtoms = nGroups = 0;
LockDisplay(dpy); LockDisplay(dpy);
xkbi = dpy->xkb_info; xkbi = dpy->xkb_info;
GetReq(kbSetNames, req); GetReq(kbSetNames, req);
...@@ -605,132 +628,143 @@ XkbChangeNames(Display *dpy,XkbDescPtr xkb,XkbNameChangesPtr changes) ...@@ -605,132 +628,143 @@ XkbChangeNames(Display *dpy,XkbDescPtr xkb,XkbNameChangesPtr changes)
req->firstKey = changes->first_key; req->firstKey = changes->first_key;
req->nKeys = changes->num_keys; req->nKeys = changes->num_keys;
if (which&XkbKeycodesNameMask) if (which & XkbKeycodesNameMask)
nAtoms++; nAtoms++;
if (which&XkbGeometryNameMask) if (which & XkbGeometryNameMask)
nAtoms++; nAtoms++;
if (which&XkbSymbolsNameMask) if (which & XkbSymbolsNameMask)
nAtoms++; nAtoms++;
if (which&XkbPhysSymbolsNameMask) if (which & XkbPhysSymbolsNameMask)
nAtoms++; nAtoms++;
if (which&XkbTypesNameMask) if (which & XkbTypesNameMask)
nAtoms++; nAtoms++;
if (which&XkbCompatNameMask) if (which & XkbCompatNameMask)
nAtoms++; nAtoms++;
if (which&XkbKeyTypeNamesMask) if (which & XkbKeyTypeNamesMask)
nAtoms+= nTypes; nAtoms += nTypes;
if (which&XkbKTLevelNamesMask) { if (which & XkbKTLevelNamesMask) {
req->firstKTLevel= firstLvlType; req->firstKTLevel = firstLvlType;
req->nKTLevels= nLvlTypes; req->nKTLevels = nLvlTypes;
req->length+= XkbPaddedSize(nLvlTypes)/4; /* room for group widths */ req->length += XkbPaddedSize(nLvlTypes) / 4; /* room for group widths */
nAtoms+= nLvlNames; nAtoms += nLvlNames;
} }
else req->firstKTLevel= req->nKTLevels= 0; else
req->firstKTLevel = req->nKTLevels = 0;
if (which&XkbIndicatorNamesMask) {
leds= req->indicators= (CARD32)changes->changed_indicators; if (which & XkbIndicatorNamesMask) {
nLEDs= _XkbCountBits(XkbNumIndicators,changes->changed_indicators); leds = req->indicators = (CARD32) changes->changed_indicators;
if (nLEDs>0) nLEDs = _XkbCountBits(XkbNumIndicators, changes->changed_indicators);
nAtoms+= nLEDs; if (nLEDs > 0)
else which&= ~XkbIndicatorNamesMask; nAtoms += nLEDs;
} else
else req->indicators= 0; which &= ~XkbIndicatorNamesMask;
}
if (which&XkbVirtualModNamesMask) { else
vmods= req->virtualMods= changes->changed_vmods; req->indicators = 0;
nVMods= _XkbCountBits(XkbNumVirtualMods,
(unsigned long)changes->changed_vmods); if (which & XkbVirtualModNamesMask) {
if (nVMods>0) vmods = req->virtualMods = changes->changed_vmods;
nAtoms+= nVMods; nVMods = _XkbCountBits(XkbNumVirtualMods,
else which&= ~XkbVirtualModNamesMask; (unsigned long) changes->changed_vmods);
} if (nVMods > 0)
else req->virtualMods= 0; nAtoms += nVMods;
else
if (which&XkbGroupNamesMask) { which &= ~XkbVirtualModNamesMask;
groups= req->groupNames= changes->changed_groups; }
nGroups= _XkbCountBits(XkbNumKbdGroups, else
(unsigned long)changes->changed_groups); req->virtualMods = 0;
if (nGroups>0)
nAtoms+= nGroups; if (which & XkbGroupNamesMask) {
else which&= ~XkbGroupNamesMask; groups = req->groupNames = changes->changed_groups;
} nGroups = _XkbCountBits(XkbNumKbdGroups,
else req->groupNames= 0; (unsigned long) changes->changed_groups);
if (nGroups > 0)
if ((which&XkbKeyNamesMask)&&(names->keys!=NULL)) { nAtoms += nGroups;
firstKey= req->firstKey; else
nKeys= req->nKeys; which &= ~XkbGroupNamesMask;
nAtoms+= nKeys; /* technically not atoms, but 4 bytes wide */ }
} else
else which&= ~XkbKeyNamesMask; req->groupNames = 0;
if (which&XkbKeyAliasesMask) { if ((which & XkbKeyNamesMask) && (names->keys != NULL)) {
nKA= ((names->key_aliases!=NULL)?names->num_key_aliases:0); firstKey = req->firstKey;
if (nKA>0) nKeys = req->nKeys;
nAtoms+= nKA*2; /* not atoms, but 8 bytes on the wire */ nAtoms += nKeys; /* technically not atoms, but 4 bytes wide */
else which&= ~XkbKeyAliasesMask; }
} else
which &= ~XkbKeyNamesMask;
if (which&XkbRGNamesMask) {
nRG= names->num_rg; if (which & XkbKeyAliasesMask) {
if (nRG>0) nKA = ((names->key_aliases != NULL) ? names->num_key_aliases : 0);
nAtoms+= nRG; if (nKA > 0)
else which&= ~XkbRGNamesMask; nAtoms += nKA * 2; /* not atoms, but 8 bytes on the wire */
} else
which &= ~XkbKeyAliasesMask;
req->which= which; }
req->nRadioGroups= nRG;
req->length+= (nAtoms*4)/4; if (which & XkbRGNamesMask) {
nRG = names->num_rg;
if (which&XkbKeycodesNameMask) if (nRG > 0)
Data32(dpy,(long *)&names->keycodes,4); nAtoms += nRG;
if (which&XkbGeometryNameMask) else
Data32(dpy,(long *)&names->geometry,4); which &= ~XkbRGNamesMask;
if (which&XkbSymbolsNameMask) }
Data32(dpy,(long *)&names->symbols,4);
if (which&XkbPhysSymbolsNameMask) req->which = which;
Data32(dpy,(long *)&names->phys_symbols,4); req->nRadioGroups = nRG;
if (which&XkbTypesNameMask) req->length += (nAtoms * 4) / 4;
Data32(dpy,(long *)&names->types,4);
if (which&XkbCompatNameMask) if (which & XkbKeycodesNameMask)
Data32(dpy,(long *)&names->compat,4); Data32(dpy, (long *) &names->keycodes, 4);
if (which&XkbKeyTypeNamesMask) { if (which & XkbGeometryNameMask)
register int i; Data32(dpy, (long *) &names->geometry, 4);
register XkbKeyTypePtr type; if (which & XkbSymbolsNameMask)
type= &xkb->map->types[firstType]; Data32(dpy, (long *) &names->symbols, 4);
for (i=0;i<nTypes;i++,type++) { if (which & XkbPhysSymbolsNameMask)
Data32(dpy,(long *)&type->name,4); Data32(dpy, (long *) &names->phys_symbols, 4);
} if (which & XkbTypesNameMask)
} Data32(dpy, (long *) &names->types, 4);
if (which&XkbKTLevelNamesMask) { if (which & XkbCompatNameMask)
XkbKeyTypePtr type; Data32(dpy, (long *) &names->compat, 4);
int i; if (which & XkbKeyTypeNamesMask) {
char *tmp; register int i;
register XkbKeyTypePtr type;
BufAlloc(char *,tmp,XkbPaddedSize(nLvlTypes));
type = &xkb->map->types[firstLvlType]; type = &xkb->map->types[firstType];
for (i=0;i<nLvlTypes;i++,type++) { for (i = 0; i < nTypes; i++, type++) {
*tmp++ = type->num_levels; Data32(dpy, (long *) &type->name, 4);
} }
type = &xkb->map->types[firstLvlType]; }
for (i=0;i<nLvlTypes;i++,type++) { if (which & XkbKTLevelNamesMask) {
if (type->level_names!=NULL) XkbKeyTypePtr type;
Data32(dpy,(long *)type->level_names,type->num_levels*4); int i;
} char *tmp;
}
if (which&XkbIndicatorNamesMask) BufAlloc(char *, tmp, XkbPaddedSize(nLvlTypes));
_XkbCopyAtoms(dpy,names->indicators,leds,XkbNumIndicators); type = &xkb->map->types[firstLvlType];
if (which&XkbVirtualModNamesMask) for (i = 0; i < nLvlTypes; i++, type++) {
_XkbCopyAtoms(dpy,names->vmods,vmods,XkbNumVirtualMods); *tmp++ = type->num_levels;
if (which&XkbGroupNamesMask) }
_XkbCopyAtoms(dpy,names->groups,groups,XkbNumKbdGroups); type = &xkb->map->types[firstLvlType];
if (which&XkbKeyNamesMask) { for (i = 0; i < nLvlTypes; i++, type++) {
Data(dpy,(char *)&names->keys[firstKey],nKeys*XkbKeyNameLength); if (type->level_names != NULL)
} Data32(dpy, (long *) type->level_names, type->num_levels * 4);
if (which&XkbKeyAliasesMask) { }
Data(dpy,(char *)names->key_aliases,nKA*XkbKeyNameLength*2); }
} if (which & XkbIndicatorNamesMask)
if (which&XkbRGNamesMask) { _XkbCopyAtoms(dpy, names->indicators, leds, XkbNumIndicators);
Data32(dpy,(long *)names->radio_groups,nRG*4); if (which & XkbVirtualModNamesMask)
_XkbCopyAtoms(dpy, names->vmods, vmods, XkbNumVirtualMods);
if (which & XkbGroupNamesMask)
_XkbCopyAtoms(dpy, names->groups, groups, XkbNumKbdGroups);
if (which & XkbKeyNamesMask) {
Data(dpy, (char *) &names->keys[firstKey], nKeys * XkbKeyNameLength);
}
if (which & XkbKeyAliasesMask) {
Data(dpy, (char *) names->key_aliases, nKA * XkbKeyNameLength * 2);
}
if (which & XkbRGNamesMask) {
Data32(dpy, (long *) names->radio_groups, nRG * 4);
} }
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
...@@ -738,96 +772,103 @@ XkbChangeNames(Display *dpy,XkbDescPtr xkb,XkbNameChangesPtr changes) ...@@ -738,96 +772,103 @@ XkbChangeNames(Display *dpy,XkbDescPtr xkb,XkbNameChangesPtr changes)
} }
void void
XkbNoteNameChanges( XkbNameChangesPtr old, XkbNoteNameChanges(XkbNameChangesPtr old,
XkbNamesNotifyEvent * new, XkbNamesNotifyEvent *new,
unsigned int wanted) unsigned int wanted)
{ {
int first,last,old_last,new_last; int first, last, old_last, new_last;
wanted&= new->changed; wanted &= new->changed;
if ((old==NULL)||(new==NULL)||(wanted==0)) if ((old == NULL) || (new == NULL) || (wanted == 0))
return; return;
if (wanted&XkbKeyTypeNamesMask) { if (wanted & XkbKeyTypeNamesMask) {
if (old->changed&XkbKeyTypeNamesMask) { if (old->changed & XkbKeyTypeNamesMask) {
new_last= (new->first_type+new->num_types-1); new_last = (new->first_type + new->num_types - 1);
old_last= (old->first_type+old->num_types-1); old_last = (old->first_type + old->num_types - 1);
if (new->first_type<old->first_type) if (new->first_type < old->first_type)
first= new->first_type; first = new->first_type;
else first= old->first_type; else
first = old->first_type;
if (old_last>new_last)
last= old_last; if (old_last > new_last)
else last= new_last; last = old_last;
else
old->first_type= first; last = new_last;
old->num_types= (last-first)+1;
} old->first_type = first;
else { old->num_types = (last - first) + 1;
old->first_type= new->first_type; }
old->num_types= new->num_types; else {
} old->first_type = new->first_type;
} old->num_types = new->num_types;
if (wanted&XkbKTLevelNamesMask) { }
if (old->changed&XkbKTLevelNamesMask) { }
new_last= (new->first_lvl+new->num_lvls-1); if (wanted & XkbKTLevelNamesMask) {
old_last= (old->first_lvl+old->num_lvls-1); if (old->changed & XkbKTLevelNamesMask) {
new_last = (new->first_lvl + new->num_lvls - 1);
if (new->first_lvl<old->first_lvl) old_last = (old->first_lvl + old->num_lvls - 1);
first= new->first_lvl;
else first= old->first_lvl; if (new->first_lvl < old->first_lvl)
first = new->first_lvl;
if (old_last>new_last) else
last= old_last; first = old->first_lvl;
else last= new_last;
if (old_last > new_last)
old->first_lvl= first; last = old_last;
old->num_lvls= (last-first)+1; else
} last = new_last;
else {
old->first_lvl= new->first_lvl; old->first_lvl = first;
old->num_lvls= new->num_lvls; old->num_lvls = (last - first) + 1;
} }
} else {
if (wanted&XkbIndicatorNamesMask) { old->first_lvl = new->first_lvl;
if (old->changed&XkbIndicatorNamesMask) old->num_lvls = new->num_lvls;
old->changed_indicators|= new->changed_indicators; }
else old->changed_indicators= new->changed_indicators; }
} if (wanted & XkbIndicatorNamesMask) {
if (wanted&XkbKeyNamesMask) { if (old->changed & XkbIndicatorNamesMask)
if (old->changed&XkbKeyNamesMask) { old->changed_indicators |= new->changed_indicators;
new_last= (new->first_key+new->num_keys-1); else
old_last= (old->first_key+old->num_keys-1); old->changed_indicators = new->changed_indicators;
}
first= old->first_key; if (wanted & XkbKeyNamesMask) {
if (old->changed & XkbKeyNamesMask) {
if (new->first_key<old->first_key) new_last = (new->first_key + new->num_keys - 1);
first= new->first_key; old_last = (old->first_key + old->num_keys - 1);
if (old_last>new_last)
new_last= old_last; first = old->first_key;
old->first_key= first; if (new->first_key < old->first_key)
old->num_keys= (new_last-first)+1; first = new->first_key;
} if (old_last > new_last)
else { new_last = old_last;
old->first_key= new->first_key;
old->num_keys= new->num_keys; old->first_key = first;
} old->num_keys = (new_last - first) + 1;
} }
if (wanted&XkbVirtualModNamesMask) { else {
if (old->changed&XkbVirtualModNamesMask) old->first_key = new->first_key;
old->changed_vmods|= new->changed_vmods; old->num_keys = new->num_keys;
else old->changed_vmods= new->changed_vmods; }
} }
if (wanted&XkbGroupNamesMask) { if (wanted & XkbVirtualModNamesMask) {
if (old->changed&XkbGroupNamesMask) if (old->changed & XkbVirtualModNamesMask)
old->changed_groups|= new->changed_groups; old->changed_vmods |= new->changed_vmods;
else old->changed_groups= new->changed_groups; else
} old->changed_vmods = new->changed_vmods;
if (wanted&XkbRGNamesMask) }
old->num_rg= new->num_radio_groups; if (wanted & XkbGroupNamesMask) {
if (wanted&XkbKeyAliasesMask) if (old->changed & XkbGroupNamesMask)
old->num_aliases= new->num_aliases; old->changed_groups |= new->changed_groups;
old->changed|= wanted; else
old->changed_groups = new->changed_groups;
}
if (wanted & XkbRGNamesMask)
old->num_rg = new->num_radio_groups;
if (wanted & XkbKeyAliasesMask)
old->num_aliases = new->num_aliases;
old->changed |= wanted;
return; return;
} }
...@@ -35,16 +35,16 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. ...@@ -35,16 +35,16 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
/***====================================================================***/ /***====================================================================***/
int int
_XkbInitReadBuffer(Display *dpy,XkbReadBufferPtr buf,int size) _XkbInitReadBuffer(Display *dpy, XkbReadBufferPtr buf, int size)
{ {
if ((dpy!=NULL) && (buf!=NULL) && (size>0)) { if ((dpy != NULL) && (buf != NULL) && (size > 0)) {
buf->error= 0; buf->error = 0;
buf->size= size; buf->size = size;
buf->start= buf->data= _XkbAlloc(size); buf->start = buf->data = _XkbAlloc(size);
if (buf->start) { if (buf->start) {
_XRead(dpy, buf->start, size); _XRead(dpy, buf->start, size);
return 1; return 1;
} }
} }
return 0; return 0;
} }
...@@ -52,56 +52,55 @@ _XkbInitReadBuffer(Display *dpy,XkbReadBufferPtr buf,int size) ...@@ -52,56 +52,55 @@ _XkbInitReadBuffer(Display *dpy,XkbReadBufferPtr buf,int size)
#define _XkbReadBufferDataLeft(b) (((b)->size)-((b)->data-(b)->start)) #define _XkbReadBufferDataLeft(b) (((b)->size)-((b)->data-(b)->start))
int int
_XkbSkipReadBufferData(XkbReadBufferPtr from,int size) _XkbSkipReadBufferData(XkbReadBufferPtr from, int size)
{ {
if (size==0) if (size == 0)
return 1; return 1;
if ((from==NULL)||(from->error)||(size<1)|| if ((from == NULL) || (from->error) || (size < 1) ||
(_XkbReadBufferDataLeft(from)<size)) (_XkbReadBufferDataLeft(from) < size))
return 0; return 0;
from->data+= size; from->data += size;
return 1; return 1;
} }
int int
_XkbCopyFromReadBuffer(XkbReadBufferPtr from,char *to,int size) _XkbCopyFromReadBuffer(XkbReadBufferPtr from, char *to, int size)
{ {
if (size==0) if (size == 0)
return 1; return 1;
if ((from==NULL)||(from->error)||(to==NULL)||(size<1)|| if ((from == NULL) || (from->error) || (to == NULL) || (size < 1) ||
(_XkbReadBufferDataLeft(from)<size)) (_XkbReadBufferDataLeft(from) < size))
return 0; return 0;
memcpy(to,from->data,size); memcpy(to, from->data, size);
from->data+= size; from->data += size;
return 1; return 1;
} }
#ifdef XKB_FORCE_INT_KEYSYM #ifdef XKB_FORCE_INT_KEYSYM
int int
_XkbReadCopyKeySyms(int *wire,KeySym *to,int num_words) _XkbReadCopyKeySyms(int *wire, KeySym * to, int num_words)
{ {
while (num_words-->0) { while (num_words-- > 0) {
*to++= *wire++; *to++ = *wire++;
} }
return 1; return 1;
} }
int int
_XkbReadBufferCopyKeySyms(XkbReadBufferPtr from,KeySym *to,int num_words) _XkbReadBufferCopyKeySyms(XkbReadBufferPtr from, KeySym * to, int num_words)
{ {
if ((unsigned)(num_words*4)>_XkbReadBufferDataLeft(from)) if ((unsigned) (num_words * 4) > _XkbReadBufferDataLeft(from))
return 0; return 0;
_XkbReadCopyKeySyms((int *)from->data,to,num_words); _XkbReadCopyKeySyms((int *) from->data, to, num_words);
from->data+= (4*num_words); from->data += (4 * num_words);
return True; return True;
} }
int int
_XkbWriteCopyKeySyms (register KeySym *from,CARD32 *to,int len) _XkbWriteCopyKeySyms(register KeySym * from, CARD32 *to, int len)
{ {
while (len-- > 0) {
while (len-->0) { *to++ = (CARD32) *from++;
*to++= (CARD32)*from++;
} }
return True; return True;
} }
...@@ -109,54 +108,54 @@ _XkbWriteCopyKeySyms (register KeySym *from,CARD32 *to,int len) ...@@ -109,54 +108,54 @@ _XkbWriteCopyKeySyms (register KeySym *from,CARD32 *to,int len)
#ifdef LONG64 #ifdef LONG64
int int
_XkbReadCopyData32(int *wire,long *to,int num_words) _XkbReadCopyData32(int *wire, long *to, int num_words)
{ {
while (num_words-->0) { while (num_words-- > 0) {
*to++= *wire++; *to++ = *wire++;
} }
return 1; return 1;
} }
int int
_XkbReadBufferCopy32(XkbReadBufferPtr from,long *to,int num_words) _XkbReadBufferCopy32(XkbReadBufferPtr from, long *to, int num_words)
{ {
if ((unsigned)(num_words*4)>_XkbReadBufferDataLeft(from)) if ((unsigned) (num_words * 4) > _XkbReadBufferDataLeft(from))
return 0; return 0;
_XkbReadCopyData32((int *)from->data,to,num_words); _XkbReadCopyData32((int *) from->data, to, num_words);
from->data+= (4*num_words); from->data += (4 * num_words);
return True; return True;
} }
int int
_XkbWriteCopyData32 (register unsigned long *from,CARD32 *to,int len) _XkbWriteCopyData32(register unsigned long *from, CARD32 *to, int len)
{ {
while (len-- > 0) {
while (len-->0) { *to++ = (CARD32) *from++;
*to++= (CARD32)*from++;
} }
return True; return True;
} }
#endif /* LONG64 */ #endif /* LONG64 */
char * char *
_XkbPeekAtReadBuffer(XkbReadBufferPtr from,int size) _XkbPeekAtReadBuffer(XkbReadBufferPtr from, int size)
{ {
if ((from==NULL)||(from->error)||(size<1)|| if ((from == NULL) || (from->error) || (size < 1) ||
(_XkbReadBufferDataLeft(from)<size)) (_XkbReadBufferDataLeft(from) < size))
return NULL; return NULL;
return from->data; return from->data;
} }
char * char *
_XkbGetReadBufferPtr(XkbReadBufferPtr from,int size) _XkbGetReadBufferPtr(XkbReadBufferPtr from, int size)
{ {
char *ptr; char *ptr;
if ((from==NULL)||(from->error)||(size<1)||
(_XkbReadBufferDataLeft(from)<size)) if ((from == NULL) || (from->error) || (size < 1) ||
return NULL; (_XkbReadBufferDataLeft(from) < size))
ptr= from->data; return NULL;
from->data+= size; ptr = from->data;
from->data += size;
return ptr; return ptr;
} }
...@@ -164,39 +163,41 @@ char *ptr; ...@@ -164,39 +163,41 @@ char *ptr;
int int
_XkbFreeReadBuffer(XkbReadBufferPtr buf) _XkbFreeReadBuffer(XkbReadBufferPtr buf)
{ {
if ((buf!=NULL) && (buf->start!=NULL)) { if ((buf != NULL) && (buf->start != NULL)) {
int left; int left;
left= (int)_XkbReadBufferDataLeft(buf);
if (buf->start!=NULL) left = (int) _XkbReadBufferDataLeft(buf);
Xfree(buf->start); if (buf->start != NULL)
buf->size= 0; Xfree(buf->start);
buf->start= buf->data= NULL; buf->size = 0;
return left; buf->start = buf->data = NULL;
return left;
} }
return 0; return 0;
} }
Bool Bool
_XkbGetReadBufferCountedString(XkbReadBufferPtr buf,char **rtrn) _XkbGetReadBufferCountedString(XkbReadBufferPtr buf, char **rtrn)
{ {
CARD16 len,*pLen; CARD16 len, *pLen;
int left; int left;
char * str = NULL; char *str = NULL;
if ((buf==NULL)||(buf->error)||((left=(int)_XkbReadBufferDataLeft(buf))<4)) if ((buf == NULL) || (buf->error) ||
return False; ((left = (int) _XkbReadBufferDataLeft(buf)) < 4))
pLen= (CARD16 *)buf->data; return False;
len= *pLen; pLen = (CARD16 *) buf->data;
if (len>0) { len = *pLen;
if (XkbPaddedSize(len+2)>left) if (len > 0) {
return False; if (XkbPaddedSize(len + 2) > left)
str= _XkbAlloc(len+1); return False;
if (str) { str = _XkbAlloc(len + 1);
memcpy(str,&buf->data[2],len); if (str) {
str[len]= '\0'; memcpy(str, &buf->data[2], len);
} str[len] = '\0';
}
} }
buf->data+= XkbPaddedSize(len+2); buf->data += XkbPaddedSize(len + 2);
*rtrn= str; *rtrn = str;
return True; return True;
} }
...@@ -48,28 +48,29 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. ...@@ -48,28 +48,29 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
#define _SizeCountedString(s) ((s)?XkbPaddedSize(2+strlen(s)):4) #define _SizeCountedString(s) ((s)?XkbPaddedSize(2+strlen(s)):4)
static char * static char *
_WriteCountedString(char *wire,char *str) _WriteCountedString(char *wire, char *str)
{ {
CARD16 len,*pLen; CARD16 len, *pLen;
len= (str?strlen(str):0); len = (str ? strlen(str) : 0);
pLen= (CARD16 *)wire; pLen = (CARD16 *) wire;
*pLen= len; *pLen = len;
if (len && str) if (len && str)
memcpy(&wire[2],str,len); memcpy(&wire[2], str, len);
wire+= XkbPaddedSize(len+2); wire += XkbPaddedSize(len + 2);
return wire; return wire;
} }
static int static int
_SizeGeomProperties(XkbGeometryPtr geom) _SizeGeomProperties(XkbGeometryPtr geom)
{ {
register int i,size; register int i, size;
XkbPropertyPtr prop; XkbPropertyPtr prop;
for (size=i=0,prop=geom->properties;i<geom->num_properties;i++,prop++) { for (size = i = 0, prop = geom->properties; i < geom->num_properties;
size+= _SizeCountedString(prop->name); i++, prop++) {
size+= _SizeCountedString(prop->value); size += _SizeCountedString(prop->name);
size += _SizeCountedString(prop->value);
} }
return size; return size;
} }
...@@ -77,11 +78,11 @@ XkbPropertyPtr prop; ...@@ -77,11 +78,11 @@ XkbPropertyPtr prop;
static int static int
_SizeGeomColors(XkbGeometryPtr geom) _SizeGeomColors(XkbGeometryPtr geom)
{ {
register int i,size; register int i, size;
register XkbColorPtr color; register XkbColorPtr color;
for (i=size=0,color=geom->colors;i<geom->num_colors;i++,color++) { for (i = size = 0, color = geom->colors; i < geom->num_colors; i++, color++) {
size+= _SizeCountedString(color->spec); size += _SizeCountedString(color->spec);
} }
return size; return size;
} }
...@@ -89,35 +90,36 @@ register XkbColorPtr color; ...@@ -89,35 +90,36 @@ register XkbColorPtr color;
static int static int
_SizeGeomShapes(XkbGeometryPtr geom) _SizeGeomShapes(XkbGeometryPtr geom)
{ {
register int i,size; register int i, size;
register XkbShapePtr shape; register XkbShapePtr shape;
for (i=size=0,shape=geom->shapes;i<geom->num_shapes;i++,shape++) { for (i = size = 0, shape = geom->shapes; i < geom->num_shapes; i++, shape++) {
register int n; register int n;
register XkbOutlinePtr ol; register XkbOutlinePtr ol;
size+= SIZEOF(xkbShapeWireDesc);
for (n=0,ol=shape->outlines;n<shape->num_outlines;n++,ol++) { size += SIZEOF(xkbShapeWireDesc);
size+= SIZEOF(xkbOutlineWireDesc); for (n = 0, ol = shape->outlines; n < shape->num_outlines; n++, ol++) {
size+= ol->num_points*SIZEOF(xkbPointWireDesc); size += SIZEOF(xkbOutlineWireDesc);
} size += ol->num_points * SIZEOF(xkbPointWireDesc);
}
} }
return size; return size;
} }
static int static int
_SizeGeomDoodads(int num_doodads,XkbDoodadPtr doodad) _SizeGeomDoodads(int num_doodads, XkbDoodadPtr doodad)
{ {
register int i,size; register int i, size;
for (i=size=0;i<num_doodads;i++,doodad++) { for (i = size = 0; i < num_doodads; i++, doodad++) {
size+= SIZEOF(xkbAnyDoodadWireDesc); size += SIZEOF(xkbAnyDoodadWireDesc);
if (doodad->any.type==XkbTextDoodad) { if (doodad->any.type == XkbTextDoodad) {
size+= _SizeCountedString(doodad->text.text); size += _SizeCountedString(doodad->text.text);
size+= _SizeCountedString(doodad->text.font); size += _SizeCountedString(doodad->text.font);
} }
else if (doodad->any.type==XkbLogoDoodad) { else if (doodad->any.type == XkbLogoDoodad) {
size+= _SizeCountedString(doodad->logo.logo_name); size += _SizeCountedString(doodad->logo.logo_name);
} }
} }
return size; return size;
} }
...@@ -125,34 +127,39 @@ register int i,size; ...@@ -125,34 +127,39 @@ register int i,size;
static int static int
_SizeGeomSections(XkbGeometryPtr geom) _SizeGeomSections(XkbGeometryPtr geom)
{ {
register int i,size; register int i, size;
XkbSectionPtr section; XkbSectionPtr section;
for (i=size=0,section=geom->sections;i<geom->num_sections;i++,section++) { for (i = size = 0, section = geom->sections; i < geom->num_sections;
size+= SIZEOF(xkbSectionWireDesc); i++, section++) {
if (section->rows) { size += SIZEOF(xkbSectionWireDesc);
int r; if (section->rows) {
XkbRowPtr row; int r;
for (r=0,row=section->rows;r<section->num_rows;row++,r++) { XkbRowPtr row;
size+= SIZEOF(xkbRowWireDesc);
size+= row->num_keys*SIZEOF(xkbKeyWireDesc); for (r = 0, row = section->rows; r < section->num_rows; row++, r++) {
} size += SIZEOF(xkbRowWireDesc);
} size += row->num_keys * SIZEOF(xkbKeyWireDesc);
if (section->doodads) }
size+= _SizeGeomDoodads(section->num_doodads,section->doodads); }
if (section->overlays) { if (section->doodads)
int o; size += _SizeGeomDoodads(section->num_doodads, section->doodads);
XkbOverlayPtr ol; if (section->overlays) {
for (o=0,ol=section->overlays;o<section->num_overlays;o++,ol++) { int o;
int r; XkbOverlayPtr ol;
XkbOverlayRowPtr row;
size+= SIZEOF(xkbOverlayWireDesc); for (o = 0, ol = section->overlays; o < section->num_overlays;
for (r=0,row=ol->rows;r<ol->num_rows;r++,row++) { o++, ol++) {
size+= SIZEOF(xkbOverlayRowWireDesc); int r;
size+= row->num_keys*SIZEOF(xkbOverlayKeyWireDesc); XkbOverlayRowPtr row;
}
} size += SIZEOF(xkbOverlayWireDesc);
} for (r = 0, row = ol->rows; r < ol->num_rows; r++, row++) {
size += SIZEOF(xkbOverlayRowWireDesc);
size += row->num_keys * SIZEOF(xkbOverlayKeyWireDesc);
}
}
}
} }
return size; return size;
} }
...@@ -160,224 +167,234 @@ XkbSectionPtr section; ...@@ -160,224 +167,234 @@ XkbSectionPtr section;
static int static int
_SizeGeomKeyAliases(XkbGeometryPtr geom) _SizeGeomKeyAliases(XkbGeometryPtr geom)
{ {
return geom->num_key_aliases*(2*XkbKeyNameLength); return geom->num_key_aliases * (2 * XkbKeyNameLength);
} }
/***====================================================================***/ /***====================================================================***/
static char * static char *
_WriteGeomProperties(char *wire,XkbGeometryPtr geom) _WriteGeomProperties(char *wire, XkbGeometryPtr geom)
{ {
register int i; register int i;
register XkbPropertyPtr prop; register XkbPropertyPtr prop;
for (i=0,prop=geom->properties;i<geom->num_properties;i++,prop++) { for (i = 0, prop = geom->properties; i < geom->num_properties; i++, prop++) {
wire= _WriteCountedString(wire,prop->name); wire = _WriteCountedString(wire, prop->name);
wire= _WriteCountedString(wire,prop->value); wire = _WriteCountedString(wire, prop->value);
} }
return wire; return wire;
} }
static char * static char *
_WriteGeomColors(char *wire,XkbGeometryPtr geom) _WriteGeomColors(char *wire, XkbGeometryPtr geom)
{ {
register int i; register int i;
register XkbColorPtr color; register XkbColorPtr color;
for (i=0,color=geom->colors;i<geom->num_colors;i++,color++) { for (i = 0, color = geom->colors; i < geom->num_colors; i++, color++) {
wire= _WriteCountedString(wire,color->spec); wire = _WriteCountedString(wire, color->spec);
} }
return wire; return wire;
} }
static char * static char *
_WriteGeomShapes(char *wire,XkbGeometryPtr geom) _WriteGeomShapes(char *wire, XkbGeometryPtr geom)
{ {
int i; int i;
XkbShapePtr shape; XkbShapePtr shape;
xkbShapeWireDesc * shapeWire; xkbShapeWireDesc *shapeWire;
for (i=0,shape=geom->shapes;i<geom->num_shapes;i++,shape++) { for (i = 0, shape = geom->shapes; i < geom->num_shapes; i++, shape++) {
register int o; register int o;
XkbOutlinePtr ol; XkbOutlinePtr ol;
xkbOutlineWireDesc * olWire; xkbOutlineWireDesc *olWire;
shapeWire= (xkbShapeWireDesc *)wire;
shapeWire->name= shape->name; shapeWire = (xkbShapeWireDesc *) wire;
shapeWire->nOutlines= shape->num_outlines; shapeWire->name = shape->name;
if (shape->primary!=NULL) shapeWire->nOutlines = shape->num_outlines;
shapeWire->primaryNdx= XkbOutlineIndex(shape,shape->primary); if (shape->primary != NULL)
else shapeWire->primaryNdx= XkbNoShape; shapeWire->primaryNdx = XkbOutlineIndex(shape, shape->primary);
if (shape->approx!=NULL) else
shapeWire->approxNdx= XkbOutlineIndex(shape,shape->approx); shapeWire->primaryNdx = XkbNoShape;
else shapeWire->approxNdx= XkbNoShape; if (shape->approx != NULL)
wire= (char *)&shapeWire[1]; shapeWire->approxNdx = XkbOutlineIndex(shape, shape->approx);
for (o=0,ol=shape->outlines;o<shape->num_outlines;o++,ol++) { else
register int p; shapeWire->approxNdx = XkbNoShape;
XkbPointPtr pt; wire = (char *) &shapeWire[1];
xkbPointWireDesc * ptWire; for (o = 0, ol = shape->outlines; o < shape->num_outlines; o++, ol++) {
olWire= (xkbOutlineWireDesc *)wire; register int p;
olWire->nPoints= ol->num_points; XkbPointPtr pt;
olWire->cornerRadius= ol->corner_radius; xkbPointWireDesc *ptWire;
wire= (char *)&olWire[1];
ptWire= (xkbPointWireDesc *)wire; olWire = (xkbOutlineWireDesc *) wire;
for (p=0,pt=ol->points;p<ol->num_points;p++,pt++) { olWire->nPoints = ol->num_points;
ptWire[p].x= pt->x; olWire->cornerRadius = ol->corner_radius;
ptWire[p].y= pt->y; wire = (char *) &olWire[1];
} ptWire = (xkbPointWireDesc *) wire;
wire= (char *)&ptWire[ol->num_points]; for (p = 0, pt = ol->points; p < ol->num_points; p++, pt++) {
} ptWire[p].x = pt->x;
ptWire[p].y = pt->y;
}
wire = (char *) &ptWire[ol->num_points];
}
} }
return wire; return wire;
} }
static char * static char *
_WriteGeomDoodads(char *wire,int num_doodads,XkbDoodadPtr doodad) _WriteGeomDoodads(char *wire, int num_doodads, XkbDoodadPtr doodad)
{ {
register int i; register int i;
xkbDoodadWireDesc * doodadWire; xkbDoodadWireDesc *doodadWire;
for (i=0;i<num_doodads;i++,doodad++) { for (i = 0; i < num_doodads; i++, doodad++) {
doodadWire= (xkbDoodadWireDesc *)wire; doodadWire = (xkbDoodadWireDesc *) wire;
wire= (char *)&doodadWire[1]; wire = (char *) &doodadWire[1];
bzero(doodadWire,SIZEOF(xkbDoodadWireDesc)); bzero(doodadWire, SIZEOF(xkbDoodadWireDesc));
doodadWire->any.name= doodad->any.name; doodadWire->any.name = doodad->any.name;
doodadWire->any.type= doodad->any.type; doodadWire->any.type = doodad->any.type;
doodadWire->any.priority= doodad->any.priority; doodadWire->any.priority = doodad->any.priority;
doodadWire->any.top= doodad->any.top; doodadWire->any.top = doodad->any.top;
doodadWire->any.left= doodad->any.left; doodadWire->any.left = doodad->any.left;
doodadWire->any.angle= doodad->any.angle; doodadWire->any.angle = doodad->any.angle;
switch (doodad->any.type) { switch (doodad->any.type) {
case XkbOutlineDoodad: case XkbOutlineDoodad:
case XkbSolidDoodad: case XkbSolidDoodad:
doodadWire->shape.colorNdx= doodad->shape.color_ndx; doodadWire->shape.colorNdx = doodad->shape.color_ndx;
doodadWire->shape.shapeNdx= doodad->shape.shape_ndx; doodadWire->shape.shapeNdx = doodad->shape.shape_ndx;
break; break;
case XkbTextDoodad: case XkbTextDoodad:
doodadWire->text.width= doodad->text.width; doodadWire->text.width = doodad->text.width;
doodadWire->text.height= doodad->text.height; doodadWire->text.height = doodad->text.height;
doodadWire->text.colorNdx= doodad->text.color_ndx; doodadWire->text.colorNdx = doodad->text.color_ndx;
wire= _WriteCountedString(wire,doodad->text.text); wire = _WriteCountedString(wire, doodad->text.text);
wire= _WriteCountedString(wire,doodad->text.font); wire = _WriteCountedString(wire, doodad->text.font);
break; break;
case XkbIndicatorDoodad: case XkbIndicatorDoodad:
doodadWire->indicator.shapeNdx= doodad->indicator.shape_ndx; doodadWire->indicator.shapeNdx = doodad->indicator.shape_ndx;
doodadWire->indicator.onColorNdx=doodad->indicator.on_color_ndx; doodadWire->indicator.onColorNdx = doodad->indicator.on_color_ndx;
doodadWire->indicator.offColorNdx= doodadWire->indicator.offColorNdx = doodad->indicator.off_color_ndx;
doodad->indicator.off_color_ndx; break;
break; case XkbLogoDoodad:
case XkbLogoDoodad: doodadWire->logo.colorNdx = doodad->logo.color_ndx;
doodadWire->logo.colorNdx= doodad->logo.color_ndx; doodadWire->logo.shapeNdx = doodad->logo.shape_ndx;
doodadWire->logo.shapeNdx= doodad->logo.shape_ndx; wire = _WriteCountedString(wire, doodad->logo.logo_name);
wire= _WriteCountedString(wire,doodad->logo.logo_name); break;
break; default:
default: break;
break; }
}
} }
return wire; return wire;
} }
static char * static char *
_WriteGeomOverlay(char *wire,XkbOverlayPtr ol) _WriteGeomOverlay(char *wire, XkbOverlayPtr ol)
{ {
register int r; register int r;
XkbOverlayRowPtr row; XkbOverlayRowPtr row;
xkbOverlayWireDesc * olWire; xkbOverlayWireDesc *olWire;
olWire= (xkbOverlayWireDesc *)wire; olWire = (xkbOverlayWireDesc *) wire;
olWire->name= ol->name; olWire->name = ol->name;
olWire->nRows= ol->num_rows; olWire->nRows = ol->num_rows;
wire= (char *)&olWire[1]; wire = (char *) &olWire[1];
for (r=0,row=ol->rows;r<ol->num_rows;r++,row++) { for (r = 0, row = ol->rows; r < ol->num_rows; r++, row++) {
unsigned int k; unsigned int k;
XkbOverlayKeyPtr key; XkbOverlayKeyPtr key;
xkbOverlayRowWireDesc * rowWire; xkbOverlayRowWireDesc *rowWire;
rowWire= (xkbOverlayRowWireDesc *)wire;
rowWire->rowUnder= row->row_under; rowWire = (xkbOverlayRowWireDesc *) wire;
rowWire->nKeys= row->num_keys; rowWire->rowUnder = row->row_under;
wire= (char *)&rowWire[1]; rowWire->nKeys = row->num_keys;
for (k=0,key=row->keys;k<row->num_keys;k++,key++) { wire = (char *) &rowWire[1];
xkbOverlayKeyWireDesc * keyWire; for (k = 0, key = row->keys; k < row->num_keys; k++, key++) {
keyWire= (xkbOverlayKeyWireDesc *)wire; xkbOverlayKeyWireDesc *keyWire;
memcpy(keyWire->over,key->over.name,XkbKeyNameLength);
memcpy(keyWire->under,key->under.name,XkbKeyNameLength); keyWire = (xkbOverlayKeyWireDesc *) wire;
wire= (char *)&keyWire[1]; memcpy(keyWire->over, key->over.name, XkbKeyNameLength);
} memcpy(keyWire->under, key->under.name, XkbKeyNameLength);
} wire = (char *) &keyWire[1];
return wire; }
}
return wire;
} }
static char * static char *
_WriteGeomSections(char *wire,XkbGeometryPtr geom) _WriteGeomSections(char *wire, XkbGeometryPtr geom)
{ {
register int i; register int i;
XkbSectionPtr section; XkbSectionPtr section;
xkbSectionWireDesc * sectionWire; xkbSectionWireDesc *sectionWire;
for (i=0,section=geom->sections;i<geom->num_sections;i++,section++) { for (i = 0, section = geom->sections; i < geom->num_sections;
sectionWire= (xkbSectionWireDesc *)wire; i++, section++) {
sectionWire->name= section->name; sectionWire = (xkbSectionWireDesc *) wire;
sectionWire->top= section->top; sectionWire->name = section->name;
sectionWire->left= section->left; sectionWire->top = section->top;
sectionWire->width= section->width; sectionWire->left = section->left;
sectionWire->height= section->height; sectionWire->width = section->width;
sectionWire->angle= section->angle; sectionWire->height = section->height;
sectionWire->priority= section->priority; sectionWire->angle = section->angle;
sectionWire->nRows= section->num_rows; sectionWire->priority = section->priority;
sectionWire->nDoodads= section->num_doodads; sectionWire->nRows = section->num_rows;
sectionWire->nOverlays= section->num_overlays; sectionWire->nDoodads = section->num_doodads;
sectionWire->pad= 0; sectionWire->nOverlays = section->num_overlays;
wire= (char *)&sectionWire[1]; sectionWire->pad = 0;
if (section->rows) { wire = (char *) &sectionWire[1];
int r; if (section->rows) {
XkbRowPtr row; int r;
xkbRowWireDesc * rowWire; XkbRowPtr row;
for (r=0,row=section->rows;r<section->num_rows;r++,row++) { xkbRowWireDesc *rowWire;
rowWire= (xkbRowWireDesc *)wire;
rowWire->top= row->top; for (r = 0, row = section->rows; r < section->num_rows; r++, row++) {
rowWire->left= row->left; rowWire = (xkbRowWireDesc *) wire;
rowWire->nKeys= row->num_keys; rowWire->top = row->top;
rowWire->vertical= row->vertical; rowWire->left = row->left;
rowWire->pad= 0; rowWire->nKeys = row->num_keys;
wire= (char *)&rowWire[1]; rowWire->vertical = row->vertical;
if (row->keys) { rowWire->pad = 0;
int k; wire = (char *) &rowWire[1];
XkbKeyPtr key; if (row->keys) {
xkbKeyWireDesc * keyWire; int k;
keyWire= (xkbKeyWireDesc *)wire; XkbKeyPtr key;
for (k=0,key=row->keys;k<row->num_keys;k++,key++) { xkbKeyWireDesc *keyWire;
memcpy(keyWire[k].name,key->name.name,XkbKeyNameLength);
keyWire[k].gap= key->gap; keyWire = (xkbKeyWireDesc *) wire;
keyWire[k].shapeNdx= key->shape_ndx; for (k = 0, key = row->keys; k < row->num_keys; k++, key++) {
keyWire[k].colorNdx= key->color_ndx; memcpy(keyWire[k].name, key->name.name,
} XkbKeyNameLength);
wire= (char *)&keyWire[row->num_keys]; keyWire[k].gap = key->gap;
} keyWire[k].shapeNdx = key->shape_ndx;
} keyWire[k].colorNdx = key->color_ndx;
} }
if (section->doodads) { wire = (char *) &keyWire[row->num_keys];
wire= _WriteGeomDoodads(wire, }
section->num_doodads,section->doodads); }
} }
if (section->overlays) { if (section->doodads) {
register int o; wire = _WriteGeomDoodads(wire,
for (o=0;o<section->num_overlays;o++) { section->num_doodads, section->doodads);
wire= _WriteGeomOverlay(wire,&section->overlays[o]); }
} if (section->overlays) {
} register int o;
for (o = 0; o < section->num_overlays; o++) {
wire = _WriteGeomOverlay(wire, &section->overlays[o]);
}
}
} }
return wire; return wire;
} }
static char * static char *
_WriteGeomKeyAliases(char *wire,XkbGeometryPtr geom) _WriteGeomKeyAliases(char *wire, XkbGeometryPtr geom)
{ {
register int sz; register int sz;
sz= geom->num_key_aliases*(XkbKeyNameLength*2); sz = geom->num_key_aliases * (XkbKeyNameLength * 2);
if (sz>0) { if (sz > 0) {
memcpy(wire,(char *)geom->key_aliases,sz); memcpy(wire, (char *) geom->key_aliases, sz);
wire+= sz; wire += sz;
} }
return wire; return wire;
} }
...@@ -385,46 +402,46 @@ register int sz; ...@@ -385,46 +402,46 @@ register int sz;
/***====================================================================***/ /***====================================================================***/
static Status static Status
_SendSetGeometry(Display *dpy,XkbGeometryPtr geom,xkbSetGeometryReq *req) _SendSetGeometry(Display *dpy, XkbGeometryPtr geom, xkbSetGeometryReq *req)
{ {
int sz; int sz;
char * wire,*tbuf; char *wire, *tbuf;
sz= 0; sz = 0;
sz+= _SizeCountedString(geom->label_font); sz += _SizeCountedString(geom->label_font);
sz+= _SizeGeomProperties(geom); sz += _SizeGeomProperties(geom);
sz+= _SizeGeomColors(geom); sz += _SizeGeomColors(geom);
sz+= _SizeGeomShapes(geom); sz += _SizeGeomShapes(geom);
sz+= _SizeGeomSections(geom); sz += _SizeGeomSections(geom);
sz+= _SizeGeomDoodads(geom->num_doodads,geom->doodads); sz += _SizeGeomDoodads(geom->num_doodads, geom->doodads);
sz+= _SizeGeomKeyAliases(geom); sz += _SizeGeomKeyAliases(geom);
req->length+= (sz/4); req->length += (sz / 4);
if (sz < (dpy->bufmax - dpy->buffer)) { if (sz < (dpy->bufmax - dpy->buffer)) {
BufAlloc(char *,wire,sz); BufAlloc(char *, wire, sz);
tbuf= NULL; tbuf = NULL;
} }
else { else {
tbuf= _XAllocTemp(dpy,sz); tbuf = _XAllocTemp(dpy, sz);
if (!tbuf) if (!tbuf)
return BadAlloc; return BadAlloc;
wire= tbuf; wire = tbuf;
} }
wire= _WriteCountedString(wire,geom->label_font); wire = _WriteCountedString(wire, geom->label_font);
if (geom->num_properties>0) if (geom->num_properties > 0)
wire= _WriteGeomProperties(wire,geom); wire = _WriteGeomProperties(wire, geom);
if (geom->num_colors>0) if (geom->num_colors > 0)
wire= _WriteGeomColors(wire,geom); wire = _WriteGeomColors(wire, geom);
if (geom->num_shapes>0) if (geom->num_shapes > 0)
wire= _WriteGeomShapes(wire,geom); wire = _WriteGeomShapes(wire, geom);
if (geom->num_sections>0) if (geom->num_sections > 0)
wire= _WriteGeomSections(wire,geom); wire = _WriteGeomSections(wire, geom);
if (geom->num_doodads>0) if (geom->num_doodads > 0)
wire= _WriteGeomDoodads(wire,geom->num_doodads,geom->doodads); wire = _WriteGeomDoodads(wire, geom->num_doodads, geom->doodads);
if (geom->num_key_aliases>0) if (geom->num_key_aliases > 0)
wire= _WriteGeomKeyAliases(wire,geom); wire = _WriteGeomKeyAliases(wire, geom);
if (tbuf!=NULL) { if (tbuf != NULL) {
Data(dpy,tbuf,sz); Data(dpy, tbuf, sz);
_XFreeTemp(dpy,tbuf,sz); _XFreeTemp(dpy, tbuf, sz);
} }
return Success; return Success;
} }
...@@ -432,35 +449,34 @@ char * wire,*tbuf; ...@@ -432,35 +449,34 @@ char * wire,*tbuf;
/***====================================================================***/ /***====================================================================***/
Status Status
XkbSetGeometry(Display *dpy,unsigned deviceSpec,XkbGeometryPtr geom) XkbSetGeometry(Display *dpy, unsigned deviceSpec, XkbGeometryPtr geom)
{ {
xkbSetGeometryReq *req; xkbSetGeometryReq *req;
Status ret; Status ret;
if ( (!geom) || (dpy->flags & XlibDisplayNoXkb) || if ((!geom) || (dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return BadAccess; return BadAccess;
LockDisplay(dpy); LockDisplay(dpy);
GetReq(kbSetGeometry, req); GetReq(kbSetGeometry, req);
req->reqType = dpy->xkb_info->codes->major_opcode; req->reqType = dpy->xkb_info->codes->major_opcode;
req->xkbReqType = X_kbSetGeometry; req->xkbReqType = X_kbSetGeometry;
req->deviceSpec = deviceSpec; req->deviceSpec = deviceSpec;
req->nShapes= geom->num_shapes; req->nShapes = geom->num_shapes;
req->nSections= geom->num_sections; req->nSections = geom->num_sections;
req->name= geom->name; req->name = geom->name;
req->widthMM= geom->width_mm; req->widthMM = geom->width_mm;
req->heightMM= geom->height_mm; req->heightMM = geom->height_mm;
req->nProperties= geom->num_properties; req->nProperties = geom->num_properties;
req->nColors= geom->num_colors; req->nColors = geom->num_colors;
req->nDoodads= geom->num_doodads; req->nDoodads = geom->num_doodads;
req->nKeyAliases= geom->num_key_aliases; req->nKeyAliases = geom->num_key_aliases;
req->baseColorNdx= (geom->base_color-geom->colors); req->baseColorNdx = (geom->base_color - geom->colors);
req->labelColorNdx= (geom->label_color-geom->colors); req->labelColorNdx = (geom->label_color - geom->colors);
ret = _SendSetGeometry(dpy,geom,req); ret = _SendSetGeometry(dpy, geom, req);
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
return ret; return ret;
} }
...@@ -33,221 +33,224 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. ...@@ -33,221 +33,224 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "XKBlibint.h" #include "XKBlibint.h"
static int static int
_XkbSizeKeyTypes(XkbDescPtr xkb,xkbSetMapReq *req) _XkbSizeKeyTypes(XkbDescPtr xkb, xkbSetMapReq *req)
{ {
XkbKeyTypePtr map; XkbKeyTypePtr map;
int i,len; int i, len;
if (((req->present&XkbKeyTypesMask)==0)||(req->nTypes==0)) { if (((req->present & XkbKeyTypesMask) == 0) || (req->nTypes == 0)) {
req->present&= ~XkbKeyTypesMask; req->present &= ~XkbKeyTypesMask;
req->firstType= req->nTypes= 0; req->firstType = req->nTypes = 0;
return 0; return 0;
} }
len= 0; len = 0;
map= &xkb->map->types[req->firstType]; map = &xkb->map->types[req->firstType];
for (i=0;i<req->nTypes;i++,map++){ for (i = 0; i < req->nTypes; i++, map++) {
len+= SIZEOF(xkbKeyTypeWireDesc); len += SIZEOF(xkbKeyTypeWireDesc);
len+= map->map_count*SIZEOF(xkbKTSetMapEntryWireDesc); len += map->map_count * SIZEOF(xkbKTSetMapEntryWireDesc);
if (map->preserve) if (map->preserve)
len+= map->map_count*SIZEOF(xkbModsWireDesc); len += map->map_count * SIZEOF(xkbModsWireDesc);
} }
return len; return len;
} }
static void static void
_XkbWriteKeyTypes(Display *dpy,XkbDescPtr xkb,xkbSetMapReq *req) _XkbWriteKeyTypes(Display *dpy, XkbDescPtr xkb, xkbSetMapReq *req)
{ {
char * buf; char *buf;
XkbKeyTypePtr type; XkbKeyTypePtr type;
int i,n,sz; int i, n, sz;
xkbKeyTypeWireDesc *desc; xkbKeyTypeWireDesc *desc;
if ((req->present&XkbKeyTypesMask)==0) if ((req->present & XkbKeyTypesMask) == 0)
return; return;
type= &xkb->map->types[req->firstType]; type = &xkb->map->types[req->firstType];
for (i=0;i<req->nTypes;i++,type++) { for (i = 0; i < req->nTypes; i++, type++) {
sz= SIZEOF(xkbKeyTypeWireDesc); sz = SIZEOF(xkbKeyTypeWireDesc);
sz+= type->map_count*SIZEOF(xkbKTSetMapEntryWireDesc); sz += type->map_count * SIZEOF(xkbKTSetMapEntryWireDesc);
if (type->preserve) if (type->preserve)
sz+= type->map_count*SIZEOF(xkbModsWireDesc); sz += type->map_count * SIZEOF(xkbModsWireDesc);
BufAlloc(xkbKeyTypeWireDesc *,desc,sz); BufAlloc(xkbKeyTypeWireDesc *, desc, sz);
desc->mask = type->mods.mask; desc->mask = type->mods.mask;
desc->realMods = type->mods.real_mods; desc->realMods = type->mods.real_mods;
desc->virtualMods = type->mods.vmods; desc->virtualMods = type->mods.vmods;
desc->numLevels = type->num_levels; desc->numLevels = type->num_levels;
desc->nMapEntries = type->map_count; desc->nMapEntries = type->map_count;
desc->preserve = (type->preserve!=NULL); desc->preserve = (type->preserve != NULL);
buf= (char *)&desc[1]; buf = (char *) &desc[1];
if (desc->nMapEntries>0) { if (desc->nMapEntries > 0) {
xkbKTSetMapEntryWireDesc *wire; xkbKTSetMapEntryWireDesc *wire;
wire= (xkbKTSetMapEntryWireDesc *)buf;
for (n=0;n<type->map_count;n++,wire++) { wire = (xkbKTSetMapEntryWireDesc *) buf;
wire->level= type->map[n].level; for (n = 0; n < type->map_count; n++, wire++) {
wire->realMods= type->map[n].mods.real_mods; wire->level = type->map[n].level;
wire->virtualMods= type->map[n].mods.vmods; wire->realMods = type->map[n].mods.real_mods;
} wire->virtualMods = type->map[n].mods.vmods;
buf= (char *)wire; }
if (type->preserve) { buf = (char *) wire;
xkbModsWireDesc *pwire; if (type->preserve) {
pwire= (xkbModsWireDesc *)buf; xkbModsWireDesc *pwire;
for (n=0;n<type->map_count;n++,pwire++) {
pwire->realMods= type->preserve[n].real_mods; pwire = (xkbModsWireDesc *) buf;
pwire->virtualMods= type->preserve[n].vmods; for (n = 0; n < type->map_count; n++, pwire++) {
} pwire->realMods = type->preserve[n].real_mods;
} pwire->virtualMods = type->preserve[n].vmods;
} }
}
}
} }
return; return;
} }
static int static int
_XkbSizeKeySyms(XkbDescPtr xkb,xkbSetMapReq *req) _XkbSizeKeySyms(XkbDescPtr xkb, xkbSetMapReq *req)
{ {
int i,len; int i, len;
unsigned nSyms; unsigned nSyms;
if (((req->present&XkbKeySymsMask)==0)||(req->nKeySyms==0)) { if (((req->present & XkbKeySymsMask) == 0) || (req->nKeySyms == 0)) {
req->present&= ~XkbKeySymsMask; req->present &= ~XkbKeySymsMask;
req->firstKeySym= req->nKeySyms= 0; req->firstKeySym = req->nKeySyms = 0;
req->totalSyms= 0; req->totalSyms = 0;
return 0; return 0;
} }
len= (int)(req->nKeySyms*sizeof(XkbSymMapRec)); len = (int) (req->nKeySyms * sizeof(XkbSymMapRec));
for (i=nSyms=0;i<req->nKeySyms;i++) { for (i = nSyms = 0; i < req->nKeySyms; i++) {
nSyms+= XkbKeyNumSyms(xkb,i+req->firstKeySym); nSyms += XkbKeyNumSyms(xkb, i + req->firstKeySym);
} }
len+= nSyms*sizeof(CARD32); len += nSyms * sizeof(CARD32);
req->totalSyms= nSyms; req->totalSyms = nSyms;
return len; return len;
} }
static void static void
_XkbWriteKeySyms(Display *dpy,XkbDescPtr xkb,xkbSetMapReq *req) _XkbWriteKeySyms(Display *dpy, XkbDescPtr xkb, xkbSetMapReq *req)
{ {
register KeySym * pSym; register KeySym *pSym;
CARD32 * outSym; CARD32 *outSym;
XkbSymMapPtr symMap; XkbSymMapPtr symMap;
xkbSymMapWireDesc *desc; xkbSymMapWireDesc *desc;
register int i; register int i;
if ((req->present&XkbKeySymsMask)==0) if ((req->present & XkbKeySymsMask) == 0)
return; return;
symMap = &xkb->map->key_sym_map[req->firstKeySym]; symMap = &xkb->map->key_sym_map[req->firstKeySym];
for (i=0;i<req->nKeySyms;i++,symMap++) { for (i = 0; i < req->nKeySyms; i++, symMap++) {
BufAlloc(xkbSymMapWireDesc *,desc, BufAlloc(xkbSymMapWireDesc *, desc,
SIZEOF(xkbSymMapWireDesc)+ SIZEOF(xkbSymMapWireDesc) +
(XkbKeyNumSyms(xkb,i+req->firstKeySym)*sizeof(CARD32))); (XkbKeyNumSyms(xkb, i + req->firstKeySym) * sizeof(CARD32)));
desc->ktIndex[0] = symMap->kt_index[0]; desc->ktIndex[0] = symMap->kt_index[0];
desc->ktIndex[1] = symMap->kt_index[1]; desc->ktIndex[1] = symMap->kt_index[1];
desc->ktIndex[2] = symMap->kt_index[2]; desc->ktIndex[2] = symMap->kt_index[2];
desc->ktIndex[3] = symMap->kt_index[3]; desc->ktIndex[3] = symMap->kt_index[3];
desc->groupInfo = symMap->group_info; desc->groupInfo = symMap->group_info;
desc->width = symMap->width; desc->width = symMap->width;
desc->nSyms = XkbKeyNumSyms(xkb,i+req->firstKeySym); desc->nSyms = XkbKeyNumSyms(xkb, i + req->firstKeySym);
outSym = (CARD32 *)&desc[1]; outSym = (CARD32 *) &desc[1];
if (desc->nSyms>0) { if (desc->nSyms > 0) {
pSym = XkbKeySymsPtr(xkb,i+req->firstKeySym); pSym = XkbKeySymsPtr(xkb, i + req->firstKeySym);
_XkbWriteCopyKeySyms(pSym,outSym,desc->nSyms); _XkbWriteCopyKeySyms(pSym, outSym, desc->nSyms);
} }
} }
return; return;
} }
static int static int
_XkbSizeKeyActions(XkbDescPtr xkb,xkbSetMapReq *req) _XkbSizeKeyActions(XkbDescPtr xkb, xkbSetMapReq *req)
{ {
int i,len,nActs; int i, len, nActs;
if (((req->present&XkbKeyActionsMask)==0)||(req->nKeyActs==0)) { if (((req->present & XkbKeyActionsMask) == 0) || (req->nKeyActs == 0)) {
req->present&= ~XkbKeyActionsMask; req->present &= ~XkbKeyActionsMask;
req->firstKeyAct= req->nKeyActs= 0; req->firstKeyAct = req->nKeyActs = 0;
req->totalActs= 0; req->totalActs = 0;
return 0; return 0;
} }
for (nActs=i=0;i<req->nKeyActs;i++) { for (nActs = i = 0; i < req->nKeyActs; i++) {
if (xkb->server->key_acts[i+req->firstKeyAct]!=0) if (xkb->server->key_acts[i + req->firstKeyAct] != 0)
nActs+= XkbKeyNumActions(xkb,i+req->firstKeyAct); nActs += XkbKeyNumActions(xkb, i + req->firstKeyAct);
} }
len= XkbPaddedSize(req->nKeyActs)+(nActs*SIZEOF(xkbActionWireDesc)); len = XkbPaddedSize(req->nKeyActs) + (nActs * SIZEOF(xkbActionWireDesc));
req->totalActs= nActs; req->totalActs = nActs;
return len; return len;
} }
static void static void
_XkbWriteKeyActions(Display *dpy,XkbDescPtr xkb,xkbSetMapReq *req) _XkbWriteKeyActions(Display *dpy, XkbDescPtr xkb, xkbSetMapReq *req)
{ {
register int i; register int i;
int n; int n;
CARD8 *numDesc; CARD8 *numDesc;
XkbAction *actDesc; XkbAction *actDesc;
if ((req->present&XkbKeyActionsMask)==0) if ((req->present & XkbKeyActionsMask) == 0)
return; return;
n = XkbPaddedSize(req->nKeyActs); n = XkbPaddedSize(req->nKeyActs);
n+= (req->totalActs*SIZEOF(xkbActionWireDesc)); n += (req->totalActs * SIZEOF(xkbActionWireDesc));
BufAlloc(CARD8 *,numDesc,n); BufAlloc(CARD8 *, numDesc, n);
for (i=0;i<req->nKeyActs;i++) { for (i = 0; i < req->nKeyActs; i++) {
if (xkb->server->key_acts[i+req->firstKeyAct]==0) if (xkb->server->key_acts[i + req->firstKeyAct] == 0)
numDesc[i] = 0; numDesc[i] = 0;
else numDesc[i] = XkbKeyNumActions(xkb,(i+req->firstKeyAct)); else
numDesc[i] = XkbKeyNumActions(xkb, (i + req->firstKeyAct));
} }
actDesc = (XkbAction *)&numDesc[XkbPaddedSize(req->nKeyActs)]; actDesc = (XkbAction *) &numDesc[XkbPaddedSize(req->nKeyActs)];
for (i=0;i<req->nKeyActs;i++) { for (i = 0; i < req->nKeyActs; i++) {
if (xkb->server->key_acts[i+req->firstKeyAct]!=0) { if (xkb->server->key_acts[i + req->firstKeyAct] != 0) {
n = XkbKeyNumActions(xkb,(i+req->firstKeyAct)); n = XkbKeyNumActions(xkb, (i + req->firstKeyAct));
memcpy(actDesc,XkbKeyActionsPtr(xkb,(i+req->firstKeyAct)), memcpy(actDesc, XkbKeyActionsPtr(xkb, (i + req->firstKeyAct)),
n*SIZEOF(xkbActionWireDesc)); n * SIZEOF(xkbActionWireDesc));
actDesc+= n; actDesc += n;
} }
} }
return; return;
} }
static int static int
_XkbSizeKeyBehaviors(XkbDescPtr xkb,xkbSetMapReq *req) _XkbSizeKeyBehaviors(XkbDescPtr xkb, xkbSetMapReq *req)
{ {
register int i,first,last,nFound; register int i, first, last, nFound;
if (((req->present&XkbKeyBehaviorsMask)==0)||(req->nKeyBehaviors<1)) { if (((req->present & XkbKeyBehaviorsMask) == 0) || (req->nKeyBehaviors < 1)) {
req->present&= ~XkbKeyBehaviorsMask; req->present &= ~XkbKeyBehaviorsMask;
req->firstKeyBehavior= req->nKeyBehaviors= 0; req->firstKeyBehavior = req->nKeyBehaviors = 0;
req->totalKeyBehaviors= 0; req->totalKeyBehaviors = 0;
return 0; return 0;
} }
first= req->firstKeyBehavior; first = req->firstKeyBehavior;
last= first+req->nKeyBehaviors-1; last = first + req->nKeyBehaviors - 1;
for (i=first,nFound=0;i<=last;i++) { for (i = first, nFound = 0; i <= last; i++) {
if (xkb->server->behaviors[i].type!=XkbKB_Default) if (xkb->server->behaviors[i].type != XkbKB_Default)
nFound++; nFound++;
} }
req->totalKeyBehaviors= nFound; req->totalKeyBehaviors = nFound;
return (nFound*SIZEOF(xkbBehaviorWireDesc)); return (nFound * SIZEOF(xkbBehaviorWireDesc));
} }
static void static void
_XkbWriteKeyBehaviors(Display *dpy,XkbDescPtr xkb,xkbSetMapReq *req) _XkbWriteKeyBehaviors(Display *dpy, XkbDescPtr xkb, xkbSetMapReq *req)
{ {
register int i,first,last; register int i, first, last;
xkbBehaviorWireDesc * wire; xkbBehaviorWireDesc *wire;
char * buf; char *buf;
if ((req->present&XkbKeyBehaviorsMask)==0) if ((req->present & XkbKeyBehaviorsMask) == 0)
return; return;
first= req->firstKeyBehavior; first = req->firstKeyBehavior;
last= first+req->nKeyBehaviors-1; last = first + req->nKeyBehaviors - 1;
i= req->totalKeyBehaviors*SIZEOF(xkbBehaviorWireDesc); i = req->totalKeyBehaviors * SIZEOF(xkbBehaviorWireDesc);
BufAlloc(char *,buf,i); BufAlloc(char *, buf, i);
wire= (xkbBehaviorWireDesc *)buf; wire = (xkbBehaviorWireDesc *) buf;
for (i=first;i<=last;i++) { for (i = first; i <= last; i++) {
if (xkb->server->behaviors[i].type!=XkbKB_Default) { if (xkb->server->behaviors[i].type != XkbKB_Default) {
wire->key= i; wire->key = i;
wire->type= xkb->server->behaviors[i].type; wire->type = xkb->server->behaviors[i].type;
wire->data= xkb->server->behaviors[i].data; wire->data = xkb->server->behaviors[i].data;
buf+= SIZEOF(xkbBehaviorWireDesc); buf += SIZEOF(xkbBehaviorWireDesc);
wire= (xkbBehaviorWireDesc *)buf; wire = (xkbBehaviorWireDesc *) buf;
} }
} }
return; return;
} }
...@@ -255,236 +258,239 @@ char * buf; ...@@ -255,236 +258,239 @@ char * buf;
static unsigned static unsigned
_XkbSizeVirtualMods(xkbSetMapReq *req) _XkbSizeVirtualMods(xkbSetMapReq *req)
{ {
register int i,bit,nMods; register int i, bit, nMods;
if (((req->present&XkbVirtualModsMask)==0)||(req->virtualMods==0)) { if (((req->present & XkbVirtualModsMask) == 0) || (req->virtualMods == 0)) {
req->present&= ~XkbVirtualModsMask; req->present &= ~XkbVirtualModsMask;
req->virtualMods= 0; req->virtualMods = 0;
return 0; return 0;
} }
for (i=nMods=0,bit=1;i<XkbNumVirtualMods;i++,bit<<=1) { for (i = nMods = 0, bit = 1; i < XkbNumVirtualMods; i++, bit <<= 1) {
if (req->virtualMods&bit) if (req->virtualMods & bit)
nMods++; nMods++;
} }
return XkbPaddedSize(nMods); return XkbPaddedSize(nMods);
} }
static void static void
_XkbWriteVirtualMods( Display * dpy, _XkbWriteVirtualMods(Display *dpy,
XkbDescPtr xkb, XkbDescPtr xkb,
xkbSetMapReq * req, xkbSetMapReq *req,
unsigned size) unsigned size)
{ {
register int i,bit; register int i, bit;
CARD8 *vmods; CARD8 *vmods;
/* This was req->present&XkbVirtualModsMask==0, and '==' beats '&' */ /* This was req->present&XkbVirtualModsMask==0, and '==' beats '&' */
if (((req->present & XkbVirtualModsMask) == 0) || (size < 1)) if (((req->present & XkbVirtualModsMask) == 0) || (size < 1))
return; return;
BufAlloc(CARD8 *,vmods,size); BufAlloc(CARD8 *, vmods, size);
for (i=0,bit=1;i<XkbNumVirtualMods;i++,bit<<=1) { for (i = 0, bit = 1; i < XkbNumVirtualMods; i++, bit <<= 1) {
if (req->virtualMods&bit) if (req->virtualMods & bit)
*vmods++= xkb->server->vmods[i]; *vmods++ = xkb->server->vmods[i];
} }
return; return;
} }
static int static int
_XkbSizeKeyExplicit(XkbDescPtr xkb,xkbSetMapReq *req) _XkbSizeKeyExplicit(XkbDescPtr xkb, xkbSetMapReq *req)
{ {
register int i,first,last,nFound; register int i, first, last, nFound;
if (((req->present&XkbExplicitComponentsMask)==0)||(req->nKeyExplicit==0)) { if (((req->present & XkbExplicitComponentsMask) == 0) ||
req->present&= ~XkbExplicitComponentsMask; (req->nKeyExplicit == 0)) {
req->firstKeyExplicit= req->nKeyExplicit= 0; req->present &= ~XkbExplicitComponentsMask;
req->totalKeyExplicit= 0; req->firstKeyExplicit = req->nKeyExplicit = 0;
return 0; req->totalKeyExplicit = 0;
return 0;
} }
first= req->firstKeyExplicit; first = req->firstKeyExplicit;
last= first+req->nKeyExplicit-1; last = first + req->nKeyExplicit - 1;
for (i=first,nFound=0;i<=last;i++) { for (i = first, nFound = 0; i <= last; i++) {
if (xkb->server->explicit[i]!=0) if (xkb->server->explicit[i] != 0)
nFound++; nFound++;
} }
req->totalKeyExplicit= nFound; req->totalKeyExplicit = nFound;
return XkbPaddedSize((nFound*2)); return XkbPaddedSize((nFound * 2));
} }
static void static void
_XkbWriteKeyExplicit(Display *dpy,XkbDescPtr xkb,xkbSetMapReq *req) _XkbWriteKeyExplicit(Display *dpy, XkbDescPtr xkb, xkbSetMapReq *req)
{ {
register int i,first,last; register int i, first, last;
CARD8 * wire; CARD8 *wire;
if ((req->present&XkbExplicitComponentsMask)==0) if ((req->present & XkbExplicitComponentsMask) == 0)
return; return;
first= req->firstKeyExplicit; first = req->firstKeyExplicit;
last= first+req->nKeyExplicit - 1; last = first + req->nKeyExplicit - 1;
i= XkbPaddedSize((req->totalKeyExplicit*2)); i = XkbPaddedSize((req->totalKeyExplicit * 2));
BufAlloc(CARD8 *,wire,i); BufAlloc(CARD8 *, wire, i);
for (i=first;i<=last;i++) { for (i = first; i <= last; i++) {
if (xkb->server->explicit[i]!=0) { if (xkb->server->explicit[i] != 0) {
wire[0]= i; wire[0] = i;
wire[1]= xkb->server->explicit[i]; wire[1] = xkb->server->explicit[i];
wire+= 2; wire += 2;
} }
} }
return; return;
} }
static int static int
_XkbSizeModifierMap(XkbDescPtr xkb,xkbSetMapReq *req) _XkbSizeModifierMap(XkbDescPtr xkb, xkbSetMapReq *req)
{ {
register int i,first,last,nFound; register int i, first, last, nFound;
if (((req->present&XkbModifierMapMask)==0)||(req->nModMapKeys==0)) { if (((req->present & XkbModifierMapMask) == 0) || (req->nModMapKeys == 0)) {
req->present&= ~XkbModifierMapMask; req->present &= ~XkbModifierMapMask;
req->firstModMapKey= req->nModMapKeys= 0; req->firstModMapKey = req->nModMapKeys = 0;
req->totalModMapKeys= 0; req->totalModMapKeys = 0;
return 0; return 0;
} }
first= req->firstModMapKey; first = req->firstModMapKey;
last= first+req->nModMapKeys-1; last = first + req->nModMapKeys - 1;
for (i=first,nFound=0;i<=last;i++) { for (i = first, nFound = 0; i <= last; i++) {
if (xkb->map->modmap[i]!=0) if (xkb->map->modmap[i] != 0)
nFound++; nFound++;
} }
req->totalModMapKeys= nFound; req->totalModMapKeys = nFound;
return XkbPaddedSize((nFound*2)); return XkbPaddedSize((nFound * 2));
} }
static void static void
_XkbWriteModifierMap(Display *dpy,XkbDescPtr xkb,xkbSetMapReq *req) _XkbWriteModifierMap(Display *dpy, XkbDescPtr xkb, xkbSetMapReq *req)
{ {
register int i,first,last; register int i, first, last;
CARD8 * wire; CARD8 *wire;
if ((req->present&XkbModifierMapMask)==0) if ((req->present & XkbModifierMapMask) == 0)
return; return;
first= req->firstModMapKey; first = req->firstModMapKey;
last= first+req->nModMapKeys-1; last = first + req->nModMapKeys - 1;
if (req->totalModMapKeys>0) { if (req->totalModMapKeys > 0) {
i= XkbPaddedSize((req->totalModMapKeys*2)); i = XkbPaddedSize((req->totalModMapKeys * 2));
BufAlloc(CARD8 *,wire,i); BufAlloc(CARD8 *, wire, i);
for (i=first;i<=last;i++) {
if (xkb->map->modmap[i]!=0) { for (i = first; i <= last; i++) {
wire[0]= i; if (xkb->map->modmap[i] != 0) {
wire[1]= xkb->map->modmap[i]; wire[0] = i;
wire+= 2; wire[1] = xkb->map->modmap[i];
} wire += 2;
} }
}
} }
return; return;
} }
static int static int
_XkbSizeVirtualModMap(XkbDescPtr xkb,xkbSetMapReq *req) _XkbSizeVirtualModMap(XkbDescPtr xkb, xkbSetMapReq *req)
{ {
register int i,first,last,nFound; register int i, first, last, nFound;
if (((req->present&XkbVirtualModMapMask)==0)||(req->nVModMapKeys==0)) { if (((req->present & XkbVirtualModMapMask) == 0) ||
req->present&= ~XkbVirtualModMapMask; (req->nVModMapKeys == 0)) {
req->firstVModMapKey= req->nVModMapKeys= 0; req->present &= ~XkbVirtualModMapMask;
req->totalVModMapKeys= 0; req->firstVModMapKey = req->nVModMapKeys = 0;
return 0; req->totalVModMapKeys = 0;
return 0;
} }
first= req->firstVModMapKey; first = req->firstVModMapKey;
last= first+req->nVModMapKeys-1; last = first + req->nVModMapKeys - 1;
for (i=first,nFound=0;i<=last;i++) { for (i = first, nFound = 0; i <= last; i++) {
if (xkb->server->vmodmap[i]!=0) if (xkb->server->vmodmap[i] != 0)
nFound++; nFound++;
} }
req->totalVModMapKeys= nFound; req->totalVModMapKeys = nFound;
return nFound*SIZEOF(xkbVModMapWireDesc); return nFound * SIZEOF(xkbVModMapWireDesc);
} }
static void static void
_XkbWriteVirtualModMap(Display *dpy,XkbDescPtr xkb,xkbSetMapReq *req) _XkbWriteVirtualModMap(Display *dpy, XkbDescPtr xkb, xkbSetMapReq *req)
{ {
register int i,first,last; register int i, first, last;
xkbVModMapWireDesc * wire; xkbVModMapWireDesc *wire;
if ((req->present&XkbVirtualModMapMask)==0) if ((req->present & XkbVirtualModMapMask) == 0)
return; return;
first= req->firstVModMapKey; first = req->firstVModMapKey;
last= first+req->nVModMapKeys-1; last = first + req->nVModMapKeys - 1;
if (req->totalVModMapKeys>0) { if (req->totalVModMapKeys > 0) {
i= req->totalVModMapKeys*SIZEOF(xkbVModMapWireDesc); i = req->totalVModMapKeys * SIZEOF(xkbVModMapWireDesc);
BufAlloc(xkbVModMapWireDesc *,wire,i); BufAlloc(xkbVModMapWireDesc *, wire, i);
for (i=first;i<=last;i++) { for (i = first; i <= last; i++) {
if (xkb->server->vmodmap[i]!=0) { if (xkb->server->vmodmap[i] != 0) {
wire->key= i; wire->key = i;
wire->vmods= xkb->server->vmodmap[i]; wire->vmods = xkb->server->vmodmap[i];
wire++; wire++;
} }
} }
} }
return; return;
} }
static void static void
SendSetMap(Display *dpy,XkbDescPtr xkb,xkbSetMapReq *req) SendSetMap(Display *dpy, XkbDescPtr xkb, xkbSetMapReq *req)
{ {
xkbSetMapReq tmp; xkbSetMapReq tmp;
unsigned szMods; unsigned szMods;
req->length+= _XkbSizeKeyTypes(xkb,req)/4; req->length += _XkbSizeKeyTypes(xkb, req) / 4;
req->length+= _XkbSizeKeySyms(xkb,req)/4; req->length += _XkbSizeKeySyms(xkb, req) / 4;
req->length+= _XkbSizeKeyActions(xkb,req)/4; req->length += _XkbSizeKeyActions(xkb, req) / 4;
req->length+= _XkbSizeKeyBehaviors(xkb,req)/4; req->length += _XkbSizeKeyBehaviors(xkb, req) / 4;
szMods= _XkbSizeVirtualMods(req); szMods = _XkbSizeVirtualMods(req);
req->length+= szMods/4; req->length += szMods / 4;
req->length+= _XkbSizeKeyExplicit(xkb,req)/4; req->length += _XkbSizeKeyExplicit(xkb, req) / 4;
req->length+= _XkbSizeModifierMap(xkb,req)/4; req->length += _XkbSizeModifierMap(xkb, req) / 4;
req->length+= _XkbSizeVirtualModMap(xkb,req)/4; req->length += _XkbSizeVirtualModMap(xkb, req) / 4;
tmp= *req; tmp = *req;
if ( tmp.nTypes>0 ) if (tmp.nTypes > 0)
_XkbWriteKeyTypes(dpy,xkb,&tmp); _XkbWriteKeyTypes(dpy, xkb, &tmp);
if ( tmp.nKeySyms>0 ) if (tmp.nKeySyms > 0)
_XkbWriteKeySyms(dpy,xkb,&tmp); _XkbWriteKeySyms(dpy, xkb, &tmp);
if ( tmp.nKeyActs ) if (tmp.nKeyActs)
_XkbWriteKeyActions(dpy,xkb,&tmp); _XkbWriteKeyActions(dpy, xkb, &tmp);
if ( tmp.totalKeyBehaviors>0 ) if (tmp.totalKeyBehaviors > 0)
_XkbWriteKeyBehaviors(dpy,xkb,&tmp); _XkbWriteKeyBehaviors(dpy, xkb, &tmp);
if ( tmp.virtualMods ) if (tmp.virtualMods)
_XkbWriteVirtualMods(dpy,xkb,&tmp,szMods); _XkbWriteVirtualMods(dpy, xkb, &tmp, szMods);
if ( tmp.totalKeyExplicit>0) if (tmp.totalKeyExplicit > 0)
_XkbWriteKeyExplicit(dpy,xkb,&tmp); _XkbWriteKeyExplicit(dpy, xkb, &tmp);
if ( tmp.totalModMapKeys>0) if (tmp.totalModMapKeys > 0)
_XkbWriteModifierMap(dpy,xkb,&tmp); _XkbWriteModifierMap(dpy, xkb, &tmp);
if ( tmp.totalVModMapKeys>0) if (tmp.totalVModMapKeys > 0)
_XkbWriteVirtualModMap(dpy,xkb,&tmp); _XkbWriteVirtualModMap(dpy, xkb, &tmp);
return; return;
} }
Bool Bool
XkbSetMap(Display *dpy,unsigned which,XkbDescPtr xkb) XkbSetMap(Display *dpy, unsigned which, XkbDescPtr xkb)
{ {
register xkbSetMapReq * req; register xkbSetMapReq *req;
XkbInfoPtr xkbi; XkbInfoPtr xkbi;
XkbServerMapPtr srv; XkbServerMapPtr srv;
XkbClientMapPtr map; XkbClientMapPtr map;
if ((dpy->flags & XlibDisplayNoXkb) || if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))|| (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)) || (!xkb))
(!xkb)) return False;
return False; map = xkb->map;
map= xkb->map; srv = xkb->server;
srv= xkb->server;
if (((which & XkbKeyTypesMask) && ((!map) || (!map->types))) ||
if (((which&XkbKeyTypesMask)&&((!map)||(!map->types)))|| ((which & XkbKeySymsMask) &&
((which&XkbKeySymsMask)&&((!map)||(!map->syms)||(!map->key_sym_map)))|| ((!map) || (!map->syms) || (!map->key_sym_map))) ||
((which&XkbKeyActionsMask)&&((!srv)||(!srv->key_acts)))|| ((which & XkbKeyActionsMask) && ((!srv) || (!srv->key_acts))) ||
((which&XkbKeyBehaviorsMask)&&((!srv)||(!srv->behaviors)))|| ((which & XkbKeyBehaviorsMask) && ((!srv) || (!srv->behaviors))) ||
((which&XkbVirtualModsMask)&&(!srv))|| ((which & XkbVirtualModsMask) && (!srv)) ||
((which&XkbExplicitComponentsMask)&&((!srv)||(!srv->explicit)))|| ((which & XkbExplicitComponentsMask) && ((!srv) || (!srv->explicit))) ||
((which&XkbModifierMapMask)&&((!map)||(!map->modmap)))|| ((which & XkbModifierMapMask) && ((!map) || (!map->modmap))) ||
((which&XkbVirtualModMapMask)&&((!srv)||(!srv->vmodmap)))) ((which & XkbVirtualModMapMask) && ((!srv) || (!srv->vmodmap))))
return False; return False;
LockDisplay(dpy); LockDisplay(dpy);
xkbi = dpy->xkb_info; xkbi = dpy->xkb_info;
...@@ -494,69 +500,73 @@ XkbClientMapPtr map; ...@@ -494,69 +500,73 @@ XkbClientMapPtr map;
req->deviceSpec = xkb->device_spec; req->deviceSpec = xkb->device_spec;
req->present = which; req->present = which;
req->flags = XkbSetMapAllFlags; req->flags = XkbSetMapAllFlags;
req->minKeyCode= xkb->min_key_code; req->minKeyCode = xkb->min_key_code;
req->maxKeyCode= xkb->max_key_code; req->maxKeyCode = xkb->max_key_code;
req->firstType = 0; req->firstType = 0;
if (which&XkbKeyTypesMask) req->nTypes = map->num_types; if (which & XkbKeyTypesMask)
else req->nTypes = 0; req->nTypes = map->num_types;
if (which&XkbKeySymsMask) { else
req->firstKeySym = xkb->min_key_code; req->nTypes = 0;
req->nKeySyms = XkbNumKeys(xkb); if (which & XkbKeySymsMask) {
req->firstKeySym = xkb->min_key_code;
req->nKeySyms = XkbNumKeys(xkb);
} }
if (which&XkbKeyActionsMask) { if (which & XkbKeyActionsMask) {
req->firstKeyAct = xkb->min_key_code; req->firstKeyAct = xkb->min_key_code;
req->nKeyActs = XkbNumKeys(xkb); req->nKeyActs = XkbNumKeys(xkb);
} }
if (which&XkbKeyBehaviorsMask) { if (which & XkbKeyBehaviorsMask) {
req->firstKeyBehavior = xkb->min_key_code; req->firstKeyBehavior = xkb->min_key_code;
req->nKeyBehaviors = XkbNumKeys(xkb); req->nKeyBehaviors = XkbNumKeys(xkb);
} }
if (which&XkbVirtualModsMask) if (which & XkbVirtualModsMask)
req->virtualMods= ~0; req->virtualMods = ~0;
if (which&XkbExplicitComponentsMask) { if (which & XkbExplicitComponentsMask) {
req->firstKeyExplicit= xkb->min_key_code; req->firstKeyExplicit = xkb->min_key_code;
req->nKeyExplicit = XkbNumKeys(xkb); req->nKeyExplicit = XkbNumKeys(xkb);
} }
if (which&XkbModifierMapMask) { if (which & XkbModifierMapMask) {
req->firstModMapKey= xkb->min_key_code; req->firstModMapKey = xkb->min_key_code;
req->nModMapKeys = XkbNumKeys(xkb); req->nModMapKeys = XkbNumKeys(xkb);
} }
if (which&XkbVirtualModMapMask) { if (which & XkbVirtualModMapMask) {
req->firstVModMapKey= xkb->min_key_code; req->firstVModMapKey = xkb->min_key_code;
req->nVModMapKeys = XkbNumKeys(xkb); req->nVModMapKeys = XkbNumKeys(xkb);
} }
SendSetMap(dpy,xkb,req); SendSetMap(dpy, xkb, req);
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
return True; return True;
} }
Bool Bool
XkbChangeMap(Display *dpy,XkbDescPtr xkb,XkbMapChangesPtr changes) XkbChangeMap(Display *dpy, XkbDescPtr xkb, XkbMapChangesPtr changes)
{ {
register xkbSetMapReq * req; register xkbSetMapReq *req;
XkbInfoPtr xkbi; XkbInfoPtr xkbi;
XkbServerMapPtr srv; XkbServerMapPtr srv;
XkbClientMapPtr map; XkbClientMapPtr map;
if ((dpy->flags & XlibDisplayNoXkb) || if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))|| (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)) ||
(!xkb)||(!changes)) (!xkb) || (!changes))
return False; return False;
srv= xkb->server; srv = xkb->server;
map= xkb->map; map = xkb->map;
if (((changes->changed&XkbKeyTypesMask)&&((!map)||(!map->types)))|| if (((changes->changed & XkbKeyTypesMask) && ((!map) || (!map->types))) ||
((changes->changed&XkbKeySymsMask)&&((!map)||(!map->syms)|| ((changes->changed & XkbKeySymsMask) && ((!map) || (!map->syms) ||
(!map->key_sym_map)))|| (!map->key_sym_map))) ||
((changes->changed&XkbKeyActionsMask)&&((!srv)||(!srv->key_acts)))|| ((changes->changed & XkbKeyActionsMask) && ((!srv) || (!srv->key_acts)))
((changes->changed&XkbKeyBehaviorsMask)&&((!srv)||(!srv->behaviors)))|| || ((changes->changed & XkbKeyBehaviorsMask) &&
((changes->changed&XkbVirtualModsMask)&&(!srv))|| ((!srv) || (!srv->behaviors))) ||
((changes->changed&XkbExplicitComponentsMask)&& ((changes->changed & XkbVirtualModsMask) && (!srv)) ||
((!srv)||(!srv->explicit)))|| ((changes->changed & XkbExplicitComponentsMask) &&
((changes->changed&XkbModifierMapMask)&&((!map)||(!map->modmap)))|| ((!srv) || (!srv->explicit))) ||
((changes->changed&XkbVirtualModMapMask)&&((!srv)||(!srv->vmodmap)))) ((changes->changed & XkbModifierMapMask) && ((!map) || (!map->modmap)))
return False; || ((changes->changed & XkbVirtualModMapMask) &&
((!srv) || (!srv->vmodmap))))
return False;
LockDisplay(dpy); LockDisplay(dpy);
xkbi = dpy->xkb_info; xkbi = dpy->xkb_info;
...@@ -566,8 +576,8 @@ XkbClientMapPtr map; ...@@ -566,8 +576,8 @@ XkbClientMapPtr map;
req->deviceSpec = xkb->device_spec; req->deviceSpec = xkb->device_spec;
req->present = changes->changed; req->present = changes->changed;
req->flags = XkbSetMapRecomputeActions; req->flags = XkbSetMapRecomputeActions;
req->minKeyCode= xkb->min_key_code; req->minKeyCode = xkb->min_key_code;
req->maxKeyCode= xkb->max_key_code; req->maxKeyCode = xkb->max_key_code;
req->firstType = changes->first_type; req->firstType = changes->first_type;
req->nTypes = changes->num_types; req->nTypes = changes->num_types;
req->firstKeySym = changes->first_key_sym; req->firstKeySym = changes->first_key_sym;
...@@ -583,9 +593,8 @@ XkbClientMapPtr map; ...@@ -583,9 +593,8 @@ XkbClientMapPtr map;
req->nModMapKeys = changes->num_modmap_keys; req->nModMapKeys = changes->num_modmap_keys;
req->firstVModMapKey = changes->first_vmodmap_key; req->firstVModMapKey = changes->first_vmodmap_key;
req->nVModMapKeys = changes->num_vmodmap_keys; req->nVModMapKeys = changes->num_vmodmap_keys;
SendSetMap(dpy,xkb,req); SendSetMap(dpy, xkb, req);
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
return True; return True;
} }
...@@ -33,558 +33,562 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. ...@@ -33,558 +33,562 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <nx-X11/extensions/XKBproto.h> #include <nx-X11/extensions/XKBproto.h>
#include "XKBlibint.h" #include "XKBlibint.h"
static Bool _XkbIgnoreExtension = False; static Bool _XkbIgnoreExtension = False;
void void
XkbNoteMapChanges(XkbMapChangesPtr old,XkbMapNotifyEvent *new,unsigned wanted) XkbNoteMapChanges(XkbMapChangesPtr old,
XkbMapNotifyEvent *new,
unsigned wanted)
{ {
int first,oldLast,newLast; int first, oldLast, newLast;
wanted&= new->changed;
wanted &= new->changed;
if (wanted&XkbKeyTypesMask) {
if (old->changed&XkbKeyTypesMask) { if (wanted & XkbKeyTypesMask) {
first = old->first_type; if (old->changed & XkbKeyTypesMask) {
oldLast = old->first_type+old->num_types-1; first = old->first_type;
newLast = new->first_type+new->num_types-1; oldLast = old->first_type + old->num_types - 1;
newLast = new->first_type + new->num_types - 1;
if (new->first_type<first)
first = new->first_type; if (new->first_type < first)
if (oldLast>newLast) first = new->first_type;
newLast= oldLast; if (oldLast > newLast)
old->first_type = first; newLast = oldLast;
old->num_types = newLast-first+1; old->first_type = first;
} old->num_types = newLast - first + 1;
else { }
old->first_type= new->first_type; else {
old->num_types = new->num_types; old->first_type = new->first_type;
} old->num_types = new->num_types;
} }
if (wanted&XkbKeySymsMask) { }
if (old->changed&XkbKeySymsMask) { if (wanted & XkbKeySymsMask) {
first = old->first_key_sym; if (old->changed & XkbKeySymsMask) {
oldLast = old->first_key_sym+old->num_key_syms-1; first = old->first_key_sym;
newLast = new->first_key_sym+new->num_key_syms-1; oldLast = old->first_key_sym + old->num_key_syms - 1;
newLast = new->first_key_sym + new->num_key_syms - 1;
if (new->first_key_sym<first)
first = new->first_key_sym; if (new->first_key_sym < first)
if (oldLast>newLast) first = new->first_key_sym;
newLast= oldLast; if (oldLast > newLast)
old->first_key_sym = first; newLast = oldLast;
old->num_key_syms = newLast-first+1; old->first_key_sym = first;
} old->num_key_syms = newLast - first + 1;
else { }
old->first_key_sym = new->first_key_sym; else {
old->num_key_syms = new->num_key_syms; old->first_key_sym = new->first_key_sym;
} old->num_key_syms = new->num_key_syms;
} }
if (wanted&XkbKeyActionsMask) { }
if (old->changed&XkbKeyActionsMask) { if (wanted & XkbKeyActionsMask) {
first = old->first_key_act; if (old->changed & XkbKeyActionsMask) {
oldLast = old->first_key_act+old->num_key_acts-1; first = old->first_key_act;
newLast = new->first_key_act+new->num_key_acts-1; oldLast = old->first_key_act + old->num_key_acts - 1;
newLast = new->first_key_act + new->num_key_acts - 1;
if (new->first_key_act<first)
first = new->first_key_act; if (new->first_key_act < first)
if (oldLast>newLast) first = new->first_key_act;
newLast= oldLast; if (oldLast > newLast)
old->first_key_act = first; newLast = oldLast;
old->num_key_acts = newLast-first+1; old->first_key_act = first;
} old->num_key_acts = newLast - first + 1;
else { }
old->first_key_act = new->first_key_act; else {
old->num_key_acts = new->num_key_acts; old->first_key_act = new->first_key_act;
} old->num_key_acts = new->num_key_acts;
} }
if (wanted&XkbKeyBehaviorsMask) { }
if (old->changed&XkbKeyBehaviorsMask) { if (wanted & XkbKeyBehaviorsMask) {
first = old->first_key_behavior; if (old->changed & XkbKeyBehaviorsMask) {
oldLast = old->first_key_behavior+old->num_key_behaviors-1; first = old->first_key_behavior;
newLast = new->first_key_behavior+new->num_key_behaviors-1; oldLast = old->first_key_behavior + old->num_key_behaviors - 1;
newLast = new->first_key_behavior + new->num_key_behaviors - 1;
if (new->first_key_behavior<first)
first = new->first_key_behavior; if (new->first_key_behavior < first)
if (oldLast>newLast) first = new->first_key_behavior;
newLast= oldLast; if (oldLast > newLast)
old->first_key_behavior = first; newLast = oldLast;
old->num_key_behaviors = newLast-first+1; old->first_key_behavior = first;
} old->num_key_behaviors = newLast - first + 1;
else { }
old->first_key_behavior = new->first_key_behavior; else {
old->num_key_behaviors = new->num_key_behaviors; old->first_key_behavior = new->first_key_behavior;
} old->num_key_behaviors = new->num_key_behaviors;
} }
if (wanted&XkbVirtualModsMask) { }
old->vmods|= new->vmods; if (wanted & XkbVirtualModsMask) {
} old->vmods |= new->vmods;
if (wanted&XkbExplicitComponentsMask) { }
if (old->changed&XkbExplicitComponentsMask) { if (wanted & XkbExplicitComponentsMask) {
first = old->first_key_explicit; if (old->changed & XkbExplicitComponentsMask) {
oldLast = old->first_key_explicit+old->num_key_explicit-1; first = old->first_key_explicit;
newLast = new->first_key_explicit+new->num_key_explicit-1; oldLast = old->first_key_explicit + old->num_key_explicit - 1;
newLast = new->first_key_explicit + new->num_key_explicit - 1;
if (new->first_key_explicit<first)
first = new->first_key_explicit; if (new->first_key_explicit < first)
if (oldLast>newLast) first = new->first_key_explicit;
newLast= oldLast; if (oldLast > newLast)
old->first_key_explicit = first; newLast = oldLast;
old->num_key_explicit = newLast-first+1; old->first_key_explicit = first;
} old->num_key_explicit = newLast - first + 1;
else { }
old->first_key_explicit = new->first_key_explicit; else {
old->num_key_explicit = new->num_key_explicit; old->first_key_explicit = new->first_key_explicit;
} old->num_key_explicit = new->num_key_explicit;
} }
if (wanted&XkbModifierMapMask) { }
if (old->changed&XkbModifierMapMask) { if (wanted & XkbModifierMapMask) {
first = old->first_modmap_key; if (old->changed & XkbModifierMapMask) {
oldLast = old->first_modmap_key+old->num_modmap_keys-1; first = old->first_modmap_key;
newLast = new->first_modmap_key+new->num_modmap_keys-1; oldLast = old->first_modmap_key + old->num_modmap_keys - 1;
newLast = new->first_modmap_key + new->num_modmap_keys - 1;
if (new->first_modmap_key<first)
first = new->first_modmap_key; if (new->first_modmap_key < first)
if (oldLast>newLast) first = new->first_modmap_key;
newLast= oldLast; if (oldLast > newLast)
old->first_modmap_key = first; newLast = oldLast;
old->num_modmap_keys = newLast-first+1; old->first_modmap_key = first;
} old->num_modmap_keys = newLast - first + 1;
else { }
old->first_modmap_key = new->first_modmap_key; else {
old->num_modmap_keys = new->num_modmap_keys; old->first_modmap_key = new->first_modmap_key;
} old->num_modmap_keys = new->num_modmap_keys;
} }
if (wanted&XkbVirtualModMapMask) { }
if (old->changed&XkbVirtualModMapMask) { if (wanted & XkbVirtualModMapMask) {
first = old->first_vmodmap_key; if (old->changed & XkbVirtualModMapMask) {
oldLast = old->first_vmodmap_key+old->num_vmodmap_keys-1; first = old->first_vmodmap_key;
newLast = new->first_vmodmap_key+new->num_vmodmap_keys-1; oldLast = old->first_vmodmap_key + old->num_vmodmap_keys - 1;
newLast = new->first_vmodmap_key + new->num_vmodmap_keys - 1;
if (new->first_vmodmap_key<first)
first = new->first_vmodmap_key; if (new->first_vmodmap_key < first)
if (oldLast>newLast) first = new->first_vmodmap_key;
newLast= oldLast; if (oldLast > newLast)
old->first_vmodmap_key = first; newLast = oldLast;
old->num_vmodmap_keys = newLast-first+1; old->first_vmodmap_key = first;
} old->num_vmodmap_keys = newLast - first + 1;
else { }
old->first_vmodmap_key = new->first_vmodmap_key; else {
old->num_vmodmap_keys = new->num_vmodmap_keys; old->first_vmodmap_key = new->first_vmodmap_key;
} old->num_vmodmap_keys = new->num_vmodmap_keys;
} }
old->changed|= wanted; }
old->changed |= wanted;
return; return;
} }
void void
_XkbNoteCoreMapChanges( XkbMapChangesPtr old, _XkbNoteCoreMapChanges(XkbMapChangesPtr old,
XMappingEvent * new, XMappingEvent *new,
unsigned int wanted) unsigned int wanted)
{ {
int first,oldLast,newLast; int first, oldLast, newLast;
if ((new->request==MappingKeyboard)&&(wanted&XkbKeySymsMask)) { if ((new->request == MappingKeyboard) && (wanted & XkbKeySymsMask)) {
if (old->changed&XkbKeySymsMask) { if (old->changed & XkbKeySymsMask) {
first = old->first_key_sym; first = old->first_key_sym;
oldLast = old->first_key_sym+old->num_key_syms-1; oldLast = old->first_key_sym + old->num_key_syms - 1;
newLast = new->first_keycode+new->count-1; newLast = new->first_keycode + new->count - 1;
if (new->first_keycode<first) if (new->first_keycode < first)
first = new->first_keycode; first = new->first_keycode;
if (oldLast>newLast) if (oldLast > newLast)
newLast= oldLast; newLast = oldLast;
old->first_key_sym = first; old->first_key_sym = first;
old->num_key_syms = newLast-first+1; old->num_key_syms = newLast - first + 1;
} }
else { else {
old->changed|= XkbKeySymsMask; old->changed |= XkbKeySymsMask;
old->first_key_sym = new->first_keycode; old->first_key_sym = new->first_keycode;
old->num_key_syms = new->count; old->num_key_syms = new->count;
} }
} }
return; return;
} }
static Bool static Bool
wire_to_event(Display *dpy,XEvent *re,xEvent *event) wire_to_event(Display *dpy, XEvent *re, xEvent *event)
{ {
xkbEvent *xkbevent= (xkbEvent *)event; xkbEvent *xkbevent = (xkbEvent *) event;
XkbInfoPtr xkbi; XkbInfoPtr xkbi;
if ((dpy->flags & XlibDisplayNoXkb) || if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return False; return False;
xkbi = dpy->xkb_info; xkbi = dpy->xkb_info;
if (((event->u.u.type&0x7f)-xkbi->codes->first_event)!=XkbEventCode) if (((event->u.u.type & 0x7f) - xkbi->codes->first_event) != XkbEventCode)
return False; return False;
switch (xkbevent->u.any.xkbType) { switch (xkbevent->u.any.xkbType) {
case XkbStateNotify: case XkbStateNotify:
{ {
xkbStateNotify *sn = (xkbStateNotify *)event; xkbStateNotify *sn = (xkbStateNotify *) event;
if ( xkbi->selected_events&XkbStateNotifyMask ) {
XkbStateNotifyEvent *sev=(XkbStateNotifyEvent *)re; if (xkbi->selected_events & XkbStateNotifyMask) {
sev->type = XkbEventCode+xkbi->codes->first_event; XkbStateNotifyEvent *sev = (XkbStateNotifyEvent *) re;
sev->xkb_type = XkbStateNotify;
sev->serial = _XSetLastRequestRead(dpy, sev->type = XkbEventCode + xkbi->codes->first_event;
(xGenericReply *)event); sev->xkb_type = XkbStateNotify;
sev->send_event = ((event->u.u.type & 0x80) != 0); sev->serial = _XSetLastRequestRead(dpy, (xGenericReply *) event);
sev->display = dpy; sev->send_event = ((event->u.u.type & 0x80) != 0);
sev->time = sn->time; sev->display = dpy;
sev->device = sn->deviceID; sev->time = sn->time;
sev->keycode = sn->keycode; sev->device = sn->deviceID;
sev->event_type = sn->eventType; sev->keycode = sn->keycode;
sev->req_major = sn->requestMajor; sev->event_type = sn->eventType;
sev->req_minor = sn->requestMinor; sev->req_major = sn->requestMajor;
sev->changed = sn->changed; sev->req_minor = sn->requestMinor;
sev->group = sn->group; sev->changed = sn->changed;
sev->base_group = sn->baseGroup; sev->group = sn->group;
sev->latched_group = sn->latchedGroup; sev->base_group = sn->baseGroup;
sev->locked_group = sn->lockedGroup; sev->latched_group = sn->latchedGroup;
sev->mods = sn->mods; sev->locked_group = sn->lockedGroup;
sev->base_mods = sn->baseMods; sev->mods = sn->mods;
sev->latched_mods = sn->latchedMods; sev->base_mods = sn->baseMods;
sev->locked_mods = sn->lockedMods; sev->latched_mods = sn->latchedMods;
sev->compat_state = sn->compatState; sev->locked_mods = sn->lockedMods;
sev->grab_mods = sn->grabMods; sev->compat_state = sn->compatState;
sev->compat_grab_mods = sn->compatGrabMods; sev->grab_mods = sn->grabMods;
sev->lookup_mods = sn->lookupMods; sev->compat_grab_mods = sn->compatGrabMods;
sev->compat_lookup_mods = sn->compatLookupMods; sev->lookup_mods = sn->lookupMods;
sev->ptr_buttons = sn->ptrBtnState; sev->compat_lookup_mods = sn->compatLookupMods;
return True; sev->ptr_buttons = sn->ptrBtnState;
} return True;
} }
break; }
case XkbMapNotify: break;
{ case XkbMapNotify:
xkbMapNotify *mn = (xkbMapNotify *)event; {
if ((xkbi->selected_events&XkbMapNotifyMask)&& xkbMapNotify *mn = (xkbMapNotify *) event;
(xkbi->selected_map_details&mn->changed)) {
XkbMapNotifyEvent *mev; if ((xkbi->selected_events & XkbMapNotifyMask) &&
mev =(XkbMapNotifyEvent *)re; (xkbi->selected_map_details & mn->changed)) {
mev->type = XkbEventCode+xkbi->codes->first_event; XkbMapNotifyEvent *mev;
mev->xkb_type = XkbMapNotify;
mev->serial = _XSetLastRequestRead(dpy, mev = (XkbMapNotifyEvent *) re;
(xGenericReply *)event); mev->type = XkbEventCode + xkbi->codes->first_event;
mev->send_event = ((event->u.u.type&0x80)!=0); mev->xkb_type = XkbMapNotify;
mev->display = dpy; mev->serial = _XSetLastRequestRead(dpy, (xGenericReply *) event);
mev->time = mn->time; mev->send_event = ((event->u.u.type & 0x80) != 0);
mev->device = mn->deviceID; mev->display = dpy;
mev->changed = mn->changed; mev->time = mn->time;
mev->min_key_code = mn->minKeyCode; mev->device = mn->deviceID;
mev->max_key_code = mn->maxKeyCode; mev->changed = mn->changed;
mev->first_type = mn->firstType; mev->min_key_code = mn->minKeyCode;
mev->num_types = mn->nTypes; mev->max_key_code = mn->maxKeyCode;
mev->first_key_sym = mn->firstKeySym; mev->first_type = mn->firstType;
mev->num_key_syms = mn->nKeySyms; mev->num_types = mn->nTypes;
mev->first_key_act = mn->firstKeyAct; mev->first_key_sym = mn->firstKeySym;
mev->num_key_acts = mn->nKeyActs; mev->num_key_syms = mn->nKeySyms;
mev->first_key_behavior = mn->firstKeyBehavior; mev->first_key_act = mn->firstKeyAct;
mev->num_key_behaviors = mn->nKeyBehaviors; mev->num_key_acts = mn->nKeyActs;
mev->vmods = mn->virtualMods; mev->first_key_behavior = mn->firstKeyBehavior;
mev->first_key_explicit = mn->firstKeyExplicit; mev->num_key_behaviors = mn->nKeyBehaviors;
mev->num_key_explicit = mn->nKeyExplicit; mev->vmods = mn->virtualMods;
mev->first_modmap_key = mn->firstModMapKey; mev->first_key_explicit = mn->firstKeyExplicit;
mev->num_modmap_keys = mn->nModMapKeys; mev->num_key_explicit = mn->nKeyExplicit;
mev->first_vmodmap_key = mn->firstVModMapKey; mev->first_modmap_key = mn->firstModMapKey;
mev->num_vmodmap_keys = mn->nVModMapKeys; mev->num_modmap_keys = mn->nModMapKeys;
XkbNoteMapChanges(&xkbi->changes,mev,XKB_XLIB_MAP_MASK); mev->first_vmodmap_key = mn->firstVModMapKey;
if (xkbi->changes.changed) mev->num_vmodmap_keys = mn->nVModMapKeys;
xkbi->flags|= XkbMapPending; XkbNoteMapChanges(&xkbi->changes, mev, XKB_XLIB_MAP_MASK);
return True; if (xkbi->changes.changed)
} xkbi->flags |= XkbMapPending;
else if (mn->nKeySyms>0) { return True;
register XMappingEvent *ev = (XMappingEvent *)re; }
ev->type = MappingNotify; else if (mn->nKeySyms > 0) {
ev->serial = _XSetLastRequestRead(dpy, register XMappingEvent *ev = (XMappingEvent *) re;
(xGenericReply *)event);
ev->send_event = ((event->u.u.type&0x80)!=0); ev->type = MappingNotify;
ev->display = dpy; ev->serial = _XSetLastRequestRead(dpy, (xGenericReply *) event);
ev->window = 0; ev->send_event = ((event->u.u.type & 0x80) != 0);
ev->first_keycode = mn->firstKeySym; ev->display = dpy;
ev->request = MappingKeyboard; ev->window = 0;
ev->count = mn->nKeySyms; ev->first_keycode = mn->firstKeySym;
_XkbNoteCoreMapChanges(&xkbi->changes,ev,XKB_XLIB_MAP_MASK); ev->request = MappingKeyboard;
if (xkbi->changes.changed) ev->count = mn->nKeySyms;
xkbi->flags|= XkbMapPending; _XkbNoteCoreMapChanges(&xkbi->changes, ev, XKB_XLIB_MAP_MASK);
return True; if (xkbi->changes.changed)
} xkbi->flags |= XkbMapPending;
} return True;
break; }
case XkbControlsNotify: }
{ break;
if (xkbi->selected_events&XkbControlsNotifyMask) { case XkbControlsNotify:
xkbControlsNotify *cn =(xkbControlsNotify *)event; {
XkbControlsNotifyEvent *cev; if (xkbi->selected_events & XkbControlsNotifyMask) {
cev =(XkbControlsNotifyEvent *)re; xkbControlsNotify *cn = (xkbControlsNotify *) event;
cev->type = XkbEventCode+xkbi->codes->first_event; XkbControlsNotifyEvent *cev;
cev->xkb_type = XkbControlsNotify;
cev->serial = _XSetLastRequestRead(dpy, cev = (XkbControlsNotifyEvent *) re;
(xGenericReply *)event); cev->type = XkbEventCode + xkbi->codes->first_event;
cev->send_event = ((event->u.u.type&0x80)!=0); cev->xkb_type = XkbControlsNotify;
cev->display = dpy; cev->serial = _XSetLastRequestRead(dpy, (xGenericReply *) event);
cev->time = cn->time; cev->send_event = ((event->u.u.type & 0x80) != 0);
cev->device = cn->deviceID; cev->display = dpy;
cev->changed_ctrls = cn->changedControls; cev->time = cn->time;
cev->enabled_ctrls = cn->enabledControls; cev->device = cn->deviceID;
cev->enabled_ctrl_changes = cn->enabledControlChanges; cev->changed_ctrls = cn->changedControls;
cev->keycode = cn->keycode; cev->enabled_ctrls = cn->enabledControls;
cev->num_groups = cn->numGroups; cev->enabled_ctrl_changes = cn->enabledControlChanges;
cev->event_type = cn->eventType; cev->keycode = cn->keycode;
cev->req_major = cn->requestMajor; cev->num_groups = cn->numGroups;
cev->req_minor = cn->requestMinor; cev->event_type = cn->eventType;
return True; cev->req_major = cn->requestMajor;
} cev->req_minor = cn->requestMinor;
} return True;
break; }
case XkbIndicatorMapNotify: }
{ break;
if (xkbi->selected_events&XkbIndicatorMapNotifyMask) { case XkbIndicatorMapNotify:
xkbIndicatorNotify *in =(xkbIndicatorNotify *)event; {
XkbIndicatorNotifyEvent *iev; if (xkbi->selected_events & XkbIndicatorMapNotifyMask) {
iev =(XkbIndicatorNotifyEvent *)re; xkbIndicatorNotify *in = (xkbIndicatorNotify *) event;
iev->type = XkbEventCode+xkbi->codes->first_event; XkbIndicatorNotifyEvent *iev;
iev->xkb_type = XkbIndicatorMapNotify;
iev->serial = _XSetLastRequestRead(dpy, iev = (XkbIndicatorNotifyEvent *) re;
(xGenericReply *)event); iev->type = XkbEventCode + xkbi->codes->first_event;
iev->send_event = ((event->u.u.type&0x80)!=0); iev->xkb_type = XkbIndicatorMapNotify;
iev->display = dpy; iev->serial = _XSetLastRequestRead(dpy, (xGenericReply *) event);
iev->time = in->time; iev->send_event = ((event->u.u.type & 0x80) != 0);
iev->device = in->deviceID; iev->display = dpy;
iev->changed = in->changed; iev->time = in->time;
iev->state= in->state; iev->device = in->deviceID;
return True; iev->changed = in->changed;
} iev->state = in->state;
} return True;
break; }
case XkbIndicatorStateNotify: }
{ break;
if (xkbi->selected_events&XkbIndicatorStateNotifyMask) { case XkbIndicatorStateNotify:
xkbIndicatorNotify *in =(xkbIndicatorNotify *)event; {
XkbIndicatorNotifyEvent *iev; if (xkbi->selected_events & XkbIndicatorStateNotifyMask) {
iev =(XkbIndicatorNotifyEvent *)re; xkbIndicatorNotify *in = (xkbIndicatorNotify *) event;
iev->type = XkbEventCode+xkbi->codes->first_event; XkbIndicatorNotifyEvent *iev;
iev->xkb_type = XkbIndicatorStateNotify;
iev->serial = _XSetLastRequestRead(dpy, iev = (XkbIndicatorNotifyEvent *) re;
(xGenericReply *)event); iev->type = XkbEventCode + xkbi->codes->first_event;
iev->send_event = ((event->u.u.type&0x80)!=0); iev->xkb_type = XkbIndicatorStateNotify;
iev->display = dpy; iev->serial = _XSetLastRequestRead(dpy, (xGenericReply *) event);
iev->time = in->time; iev->send_event = ((event->u.u.type & 0x80) != 0);
iev->device = in->deviceID; iev->display = dpy;
iev->changed = in->changed; iev->time = in->time;
iev->state= in->state; iev->device = in->deviceID;
return True; iev->changed = in->changed;
} iev->state = in->state;
} return True;
break; }
case XkbBellNotify: }
{ break;
if (xkbi->selected_events&XkbBellNotifyMask) { case XkbBellNotify:
xkbBellNotify *bn =(xkbBellNotify *)event; {
XkbBellNotifyEvent *bev; if (xkbi->selected_events & XkbBellNotifyMask) {
bev =(XkbBellNotifyEvent *)re; xkbBellNotify *bn = (xkbBellNotify *) event;
bev->type = XkbEventCode+xkbi->codes->first_event; XkbBellNotifyEvent *bev;
bev->xkb_type = XkbBellNotify;
bev->serial = _XSetLastRequestRead(dpy, bev = (XkbBellNotifyEvent *) re;
(xGenericReply *)event); bev->type = XkbEventCode + xkbi->codes->first_event;
bev->send_event = ((event->u.u.type&0x80)!=0); bev->xkb_type = XkbBellNotify;
bev->display = dpy; bev->serial = _XSetLastRequestRead(dpy, (xGenericReply *) event);
bev->time = bn->time; bev->send_event = ((event->u.u.type & 0x80) != 0);
bev->device = bn->deviceID; bev->display = dpy;
bev->percent = bn->percent; bev->time = bn->time;
bev->pitch = bn->pitch; bev->device = bn->deviceID;
bev->duration = bn->duration; bev->percent = bn->percent;
bev->bell_class = bn->bellClass; bev->pitch = bn->pitch;
bev->bell_id = bn->bellID; bev->duration = bn->duration;
bev->name = bn->name; bev->bell_class = bn->bellClass;
bev->window = bn->window; bev->bell_id = bn->bellID;
bev->event_only = bn->eventOnly; bev->name = bn->name;
return True; bev->window = bn->window;
} bev->event_only = bn->eventOnly;
} return True;
break; }
case XkbAccessXNotify: }
{ break;
if (xkbi->selected_events&XkbAccessXNotifyMask) { case XkbAccessXNotify:
xkbAccessXNotify *axn =(xkbAccessXNotify *)event; {
XkbAccessXNotifyEvent *axev; if (xkbi->selected_events & XkbAccessXNotifyMask) {
axev =(XkbAccessXNotifyEvent *)re; xkbAccessXNotify *axn = (xkbAccessXNotify *) event;
axev->type = XkbEventCode+xkbi->codes->first_event; XkbAccessXNotifyEvent *axev;
axev->xkb_type = XkbAccessXNotify;
axev->serial = _XSetLastRequestRead(dpy, axev = (XkbAccessXNotifyEvent *) re;
(xGenericReply *)event); axev->type = XkbEventCode + xkbi->codes->first_event;
axev->send_event = ((event->u.u.type&0x80)!=0); axev->xkb_type = XkbAccessXNotify;
axev->display = dpy; axev->serial = _XSetLastRequestRead(dpy, (xGenericReply *) event);
axev->time = axn->time; axev->send_event = ((event->u.u.type & 0x80) != 0);
axev->device = axn->deviceID; axev->display = dpy;
axev->detail = axn->detail; axev->time = axn->time;
axev->keycode = axn->keycode; axev->device = axn->deviceID;
axev->sk_delay = axn->slowKeysDelay; axev->detail = axn->detail;
axev->debounce_delay = axn->debounceDelay; axev->keycode = axn->keycode;
return True; axev->sk_delay = axn->slowKeysDelay;
} axev->debounce_delay = axn->debounceDelay;
} return True;
break; }
case XkbNamesNotify: }
{ break;
if (xkbi->selected_events&XkbNamesNotifyMask) { case XkbNamesNotify:
xkbNamesNotify *nn =(xkbNamesNotify *)event; {
XkbNamesNotifyEvent *nev; if (xkbi->selected_events & XkbNamesNotifyMask) {
nev =(XkbNamesNotifyEvent *)re; xkbNamesNotify *nn = (xkbNamesNotify *) event;
nev->type = XkbEventCode+xkbi->codes->first_event; XkbNamesNotifyEvent *nev;
nev->xkb_type = XkbNamesNotify;
nev->serial = _XSetLastRequestRead(dpy, nev = (XkbNamesNotifyEvent *) re;
(xGenericReply *)event); nev->type = XkbEventCode + xkbi->codes->first_event;
nev->send_event = ((event->u.u.type&0x80)!=0); nev->xkb_type = XkbNamesNotify;
nev->display = dpy; nev->serial = _XSetLastRequestRead(dpy, (xGenericReply *) event);
nev->time = nn->time; nev->send_event = ((event->u.u.type & 0x80) != 0);
nev->device = nn->deviceID; nev->display = dpy;
nev->changed = nn->changed; nev->time = nn->time;
nev->first_type = nn->firstType; nev->device = nn->deviceID;
nev->num_types = nn->nTypes; nev->changed = nn->changed;
nev->first_lvl = nn->firstLevelName; nev->first_type = nn->firstType;
nev->num_lvls = nn->nLevelNames; nev->num_types = nn->nTypes;
nev->num_aliases = nn->nAliases; nev->first_lvl = nn->firstLevelName;
nev->num_radio_groups = nn->nRadioGroups; nev->num_lvls = nn->nLevelNames;
nev->changed_vmods = nn->changedVirtualMods; nev->num_aliases = nn->nAliases;
nev->changed_groups = nn->changedGroupNames; nev->num_radio_groups = nn->nRadioGroups;
nev->changed_indicators = nn->changedIndicators; nev->changed_vmods = nn->changedVirtualMods;
nev->first_key = nn->firstKey; nev->changed_groups = nn->changedGroupNames;
nev->num_keys = nn->nKeys; nev->changed_indicators = nn->changedIndicators;
return True; nev->first_key = nn->firstKey;
} nev->num_keys = nn->nKeys;
} return True;
break; }
case XkbCompatMapNotify: }
{ break;
if (xkbi->selected_events&XkbCompatMapNotifyMask) { case XkbCompatMapNotify:
xkbCompatMapNotify *cmn =(xkbCompatMapNotify *)event; {
XkbCompatMapNotifyEvent *cmev; if (xkbi->selected_events & XkbCompatMapNotifyMask) {
cmev =(XkbCompatMapNotifyEvent *)re; xkbCompatMapNotify *cmn = (xkbCompatMapNotify *) event;
cmev->type = XkbEventCode+xkbi->codes->first_event; XkbCompatMapNotifyEvent *cmev;
cmev->xkb_type = XkbCompatMapNotify;
cmev->serial = _XSetLastRequestRead(dpy, cmev = (XkbCompatMapNotifyEvent *) re;
(xGenericReply *)event); cmev->type = XkbEventCode + xkbi->codes->first_event;
cmev->send_event = ((event->u.u.type&0x80)!=0); cmev->xkb_type = XkbCompatMapNotify;
cmev->display = dpy; cmev->serial = _XSetLastRequestRead(dpy, (xGenericReply *) event);
cmev->time = cmn->time; cmev->send_event = ((event->u.u.type & 0x80) != 0);
cmev->device = cmn->deviceID; cmev->display = dpy;
cmev->changed_groups = cmn->changedGroups; cmev->time = cmn->time;
cmev->first_si = cmn->firstSI; cmev->device = cmn->deviceID;
cmev->num_si = cmn->nSI; cmev->changed_groups = cmn->changedGroups;
cmev->num_total_si = cmn->nTotalSI; cmev->first_si = cmn->firstSI;
return True; cmev->num_si = cmn->nSI;
} cmev->num_total_si = cmn->nTotalSI;
} return True;
break; }
case XkbActionMessage: }
{ break;
if (xkbi->selected_events&XkbActionMessageMask) { case XkbActionMessage:
xkbActionMessage *am= (xkbActionMessage *)event; {
XkbActionMessageEvent *amev; if (xkbi->selected_events & XkbActionMessageMask) {
amev= (XkbActionMessageEvent *)re; xkbActionMessage *am = (xkbActionMessage *) event;
amev->type = XkbEventCode+xkbi->codes->first_event; XkbActionMessageEvent *amev;
amev->xkb_type = XkbActionMessage;
amev->serial = _XSetLastRequestRead(dpy, amev = (XkbActionMessageEvent *) re;
(xGenericReply *)event); amev->type = XkbEventCode + xkbi->codes->first_event;
amev->send_event = ((event->u.u.type&0x80)!=0); amev->xkb_type = XkbActionMessage;
amev->display = dpy; amev->serial = _XSetLastRequestRead(dpy, (xGenericReply *) event);
amev->time = am->time; amev->send_event = ((event->u.u.type & 0x80) != 0);
amev->device = am->deviceID; amev->display = dpy;
amev->keycode = am->keycode; amev->time = am->time;
amev->press = am->press; amev->device = am->deviceID;
amev->key_event_follows = am->keyEventFollows; amev->keycode = am->keycode;
amev->group = am->group; amev->press = am->press;
amev->mods = am->mods; amev->key_event_follows = am->keyEventFollows;
memcpy(amev->message,am->message,XkbActionMessageLength); amev->group = am->group;
amev->message[XkbActionMessageLength]= '\0'; amev->mods = am->mods;
return True; memcpy(amev->message, am->message, XkbActionMessageLength);
} amev->message[XkbActionMessageLength] = '\0';
} return True;
break; }
case XkbExtensionDeviceNotify: }
{ break;
if (xkbi->selected_events&XkbExtensionDeviceNotifyMask) { case XkbExtensionDeviceNotify:
xkbExtensionDeviceNotify *ed= {
(xkbExtensionDeviceNotify *)event; if (xkbi->selected_events & XkbExtensionDeviceNotifyMask) {
XkbExtensionDeviceNotifyEvent *edev; xkbExtensionDeviceNotify *ed = (xkbExtensionDeviceNotify *) event;
edev= (XkbExtensionDeviceNotifyEvent *)re; XkbExtensionDeviceNotifyEvent *edev;
edev->type= XkbEventCode+xkbi->codes->first_event;
edev->xkb_type= XkbExtensionDeviceNotify; edev = (XkbExtensionDeviceNotifyEvent *) re;
edev->serial= _XSetLastRequestRead(dpy, edev->type = XkbEventCode + xkbi->codes->first_event;
(xGenericReply *)event); edev->xkb_type = XkbExtensionDeviceNotify;
edev->send_event= ((event->u.u.type&0x80)!=0); edev->serial = _XSetLastRequestRead(dpy, (xGenericReply *) event);
edev->display= dpy; edev->send_event = ((event->u.u.type & 0x80) != 0);
edev->time= ed->time; edev->display = dpy;
edev->device= ed->deviceID; edev->time = ed->time;
edev->led_class= ed->ledClass; edev->device = ed->deviceID;
edev->led_id= ed->ledID; edev->led_class = ed->ledClass;
edev->reason= ed->reason; edev->led_id = ed->ledID;
edev->supported= ed->supported; edev->reason = ed->reason;
edev->leds_defined= ed->ledsDefined; edev->supported = ed->supported;
edev->led_state= ed->ledState; edev->leds_defined = ed->ledsDefined;
edev->first_btn= ed->firstBtn; edev->led_state = ed->ledState;
edev->num_btns= ed->nBtns; edev->first_btn = ed->firstBtn;
edev->unsupported= ed->unsupported; edev->num_btns = ed->nBtns;
return True; edev->unsupported = ed->unsupported;
} return True;
} }
break; }
case XkbNewKeyboardNotify: break;
{ case XkbNewKeyboardNotify:
xkbNewKeyboardNotify *nkn = (xkbNewKeyboardNotify *)event; {
if ((xkbi->selected_events&XkbNewKeyboardNotifyMask)&& xkbNewKeyboardNotify *nkn = (xkbNewKeyboardNotify *) event;
(xkbi->selected_nkn_details&nkn->changed)) {
XkbNewKeyboardNotifyEvent *nkev; if ((xkbi->selected_events & XkbNewKeyboardNotifyMask) &&
nkev =(XkbNewKeyboardNotifyEvent *)re; (xkbi->selected_nkn_details & nkn->changed)) {
nkev->type = XkbEventCode+xkbi->codes->first_event; XkbNewKeyboardNotifyEvent *nkev;
nkev->xkb_type = XkbNewKeyboardNotify;
nkev->serial = _XSetLastRequestRead(dpy, nkev = (XkbNewKeyboardNotifyEvent *) re;
(xGenericReply *)event); nkev->type = XkbEventCode + xkbi->codes->first_event;
nkev->send_event = ((event->u.u.type&0x80)!=0); nkev->xkb_type = XkbNewKeyboardNotify;
nkev->display = dpy; nkev->serial = _XSetLastRequestRead(dpy, (xGenericReply *) event);
nkev->time = nkn->time; nkev->send_event = ((event->u.u.type & 0x80) != 0);
nkev->device = nkn->deviceID; nkev->display = dpy;
nkev->old_device = nkn->oldDeviceID; nkev->time = nkn->time;
nkev->min_key_code = nkn->minKeyCode; nkev->device = nkn->deviceID;
nkev->max_key_code = nkn->maxKeyCode; nkev->old_device = nkn->oldDeviceID;
nkev->old_min_key_code = nkn->oldMinKeyCode; nkev->min_key_code = nkn->minKeyCode;
nkev->old_max_key_code = nkn->oldMaxKeyCode; nkev->max_key_code = nkn->maxKeyCode;
nkev->req_major = nkn->requestMajor; nkev->old_min_key_code = nkn->oldMinKeyCode;
nkev->req_minor = nkn->requestMinor; nkev->old_max_key_code = nkn->oldMaxKeyCode;
nkev->changed = nkn->changed; nkev->req_major = nkn->requestMajor;
if ((xkbi->desc)&&(nkev->send_event==0)&& nkev->req_minor = nkn->requestMinor;
((xkbi->desc->device_spec==nkev->old_device)|| nkev->changed = nkn->changed;
(nkev->device!=nkev->old_device))) { if ((xkbi->desc) && (nkev->send_event == 0) &&
xkbi->flags= XkbMapPending|XkbXlibNewKeyboard; ((xkbi->desc->device_spec == nkev->old_device) ||
} (nkev->device != nkev->old_device))) {
return True; xkbi->flags = XkbMapPending | XkbXlibNewKeyboard;
} }
else if(nkn->changed&(XkbNKN_KeycodesMask|XkbNKN_DeviceIDMask)){ return True;
register XMappingEvent *ev = (XMappingEvent *)re; }
ev->type = MappingNotify; else if (nkn->changed & (XkbNKN_KeycodesMask | XkbNKN_DeviceIDMask)) {
ev->serial = _XSetLastRequestRead(dpy, register XMappingEvent *ev = (XMappingEvent *) re;
(xGenericReply *)event);
ev->send_event = ((event->u.u.type&0x80)!=0); ev->type = MappingNotify;
ev->display = dpy; ev->serial = _XSetLastRequestRead(dpy, (xGenericReply *) event);
ev->window = 0; ev->send_event = ((event->u.u.type & 0x80) != 0);
ev->first_keycode = dpy->min_keycode; ev->display = dpy;
ev->request = MappingKeyboard; ev->window = 0;
ev->count = (dpy->max_keycode-dpy->min_keycode)+1; ev->first_keycode = dpy->min_keycode;
if ((xkbi->desc)&&(ev->send_event==0)&& ev->request = MappingKeyboard;
((xkbi->desc->device_spec==nkn->oldDeviceID)|| ev->count = (dpy->max_keycode - dpy->min_keycode) + 1;
(nkn->deviceID!=nkn->oldDeviceID))) { if ((xkbi->desc) && (ev->send_event == 0) &&
xkbi->flags|= XkbMapPending|XkbXlibNewKeyboard; ((xkbi->desc->device_spec == nkn->oldDeviceID) ||
} (nkn->deviceID != nkn->oldDeviceID))) {
return True; xkbi->flags |= XkbMapPending | XkbXlibNewKeyboard;
} }
} return True;
break; }
default: }
break;
default:
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr,"Got unknown XKEYBOARD event (%d, base=%d)\n", fprintf(stderr, "Got unknown XKEYBOARD event (%d, base=%d)\n",
re->type, re->type, xkbi->codes->first_event);
xkbi->codes->first_event);
#endif #endif
break; break;
} }
return False; return False;
} }
...@@ -592,15 +596,17 @@ wire_to_event(Display *dpy,XEvent *re,xEvent *event) ...@@ -592,15 +596,17 @@ wire_to_event(Display *dpy,XEvent *re,xEvent *event)
Bool Bool
XkbIgnoreExtension(Bool ignore) XkbIgnoreExtension(Bool ignore)
{ {
if (getenv("XKB_FORCE")!=NULL) { if (getenv("XKB_FORCE") != NULL) {
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr,"Forcing use of XKEYBOARD (overriding an IgnoreExtensions)\n"); fprintf(stderr,
"Forcing use of XKEYBOARD (overriding an IgnoreExtensions)\n");
#endif #endif
return False; return False;
} }
#ifdef DEBUG #ifdef DEBUG
else if (getenv("XKB_DEBUG")!=NULL) { else if (getenv("XKB_DEBUG") != NULL) {
fprintf(stderr,"Explicitly %signoring XKEYBOARD\n",ignore?"":"not "); fprintf(stderr, "Explicitly %signoring XKEYBOARD\n",
ignore ? "" : "not ");
} }
#endif #endif
_XkbIgnoreExtension = ignore; _XkbIgnoreExtension = ignore;
...@@ -611,126 +617,142 @@ static void ...@@ -611,126 +617,142 @@ static void
_XkbFreeInfo(Display *dpy) _XkbFreeInfo(Display *dpy)
{ {
XkbInfoPtr xkbi = dpy->xkb_info; XkbInfoPtr xkbi = dpy->xkb_info;
if (xkbi) { if (xkbi) {
if (xkbi->desc) if (xkbi->desc)
XkbFreeKeyboard(xkbi->desc,XkbAllComponentsMask,True); XkbFreeKeyboard(xkbi->desc, XkbAllComponentsMask, True);
Xfree(xkbi); Xfree(xkbi);
} }
} }
Bool Bool
XkbUseExtension(Display *dpy,int *major_rtrn,int *minor_rtrn) XkbUseExtension(Display *dpy, int *major_rtrn, int *minor_rtrn)
{ {
xkbUseExtensionReply rep; xkbUseExtensionReply rep;
register xkbUseExtensionReq *req; register xkbUseExtensionReq *req;
XExtCodes *codes; XExtCodes *codes;
int ev_base,forceIgnore; int ev_base, forceIgnore;
XkbInfoPtr xkbi; XkbInfoPtr xkbi;
char * str; char *str;
static int debugMsg; static int debugMsg;
static int been_here= 0; static int been_here = 0;
if ( dpy->xkb_info && !(dpy->flags & XlibDisplayNoXkb)) { if (dpy->xkb_info && !(dpy->flags & XlibDisplayNoXkb)) {
if (major_rtrn) *major_rtrn= dpy->xkb_info->srv_major; if (major_rtrn)
if (minor_rtrn) *minor_rtrn= dpy->xkb_info->srv_minor; *major_rtrn = dpy->xkb_info->srv_major;
return True; if (minor_rtrn)
*minor_rtrn = dpy->xkb_info->srv_minor;
return True;
} }
if (!been_here) { if (!been_here) {
debugMsg= (getenv("XKB_DEBUG")!=NULL); debugMsg = (getenv("XKB_DEBUG") != NULL);
been_here= 1; been_here = 1;
} }
if (major_rtrn) *major_rtrn= 0; if (major_rtrn)
if (minor_rtrn) *minor_rtrn= 0; *major_rtrn = 0;
if (minor_rtrn)
*minor_rtrn = 0;
if (!dpy->xkb_info) { if (!dpy->xkb_info) {
xkbi = _XkbTypedCalloc(1, XkbInfoRec); xkbi = _XkbTypedCalloc(1, XkbInfoRec);
if ( !xkbi ) if (!xkbi)
return False; return False;
dpy->xkb_info = xkbi; dpy->xkb_info = xkbi;
dpy->free_funcs->xkb = _XkbFreeInfo; dpy->free_funcs->xkb = _XkbFreeInfo;
xkbi->xlib_ctrls|= (XkbLC_ControlFallback|XkbLC_ConsumeLookupMods); xkbi->xlib_ctrls |= (XkbLC_ControlFallback | XkbLC_ConsumeLookupMods);
if ((str=getenv("_XKB_OPTIONS_ENABLE"))!=NULL) { if ((str = getenv("_XKB_OPTIONS_ENABLE")) != NULL) {
if ((str=getenv("_XKB_LATIN1_LOOKUP"))!=NULL) { if ((str = getenv("_XKB_LATIN1_LOOKUP")) != NULL) {
if ((strcmp(str,"off")==0)||(strcmp(str,"0")==0)) if ((strcmp(str, "off") == 0) || (strcmp(str, "0") == 0))
xkbi->xlib_ctrls&= ~XkbLC_ForceLatin1Lookup; xkbi->xlib_ctrls &= ~XkbLC_ForceLatin1Lookup;
else xkbi->xlib_ctrls|= XkbLC_ForceLatin1Lookup; else
} xkbi->xlib_ctrls |= XkbLC_ForceLatin1Lookup;
if ((str=getenv("_XKB_CONSUME_LOOKUP_MODS"))!=NULL) { }
if ((strcmp(str,"off")==0)||(strcmp(str,"0")==0)) if ((str = getenv("_XKB_CONSUME_LOOKUP_MODS")) != NULL) {
xkbi->xlib_ctrls&= ~XkbLC_ConsumeLookupMods; if ((strcmp(str, "off") == 0) || (strcmp(str, "0") == 0))
else xkbi->xlib_ctrls|= XkbLC_ConsumeLookupMods; xkbi->xlib_ctrls &= ~XkbLC_ConsumeLookupMods;
} else
if ((str=getenv("_XKB_CONSUME_SHIFT_AND_LOCK"))!=NULL) { xkbi->xlib_ctrls |= XkbLC_ConsumeLookupMods;
if ((strcmp(str,"off")==0)||(strcmp(str,"0")==0)) }
xkbi->xlib_ctrls&= ~XkbLC_AlwaysConsumeShiftAndLock; if ((str = getenv("_XKB_CONSUME_SHIFT_AND_LOCK")) != NULL) {
else xkbi->xlib_ctrls|= XkbLC_AlwaysConsumeShiftAndLock; if ((strcmp(str, "off") == 0) || (strcmp(str, "0") == 0))
} xkbi->xlib_ctrls &= ~XkbLC_AlwaysConsumeShiftAndLock;
if ((str=getenv("_XKB_IGNORE_NEW_KEYBOARDS"))!=NULL) { else
if ((strcmp(str,"off")==0)||(strcmp(str,"0")==0)) xkbi->xlib_ctrls |= XkbLC_AlwaysConsumeShiftAndLock;
xkbi->xlib_ctrls&= ~XkbLC_IgnoreNewKeyboards; }
else xkbi->xlib_ctrls|= XkbLC_IgnoreNewKeyboards; if ((str = getenv("_XKB_IGNORE_NEW_KEYBOARDS")) != NULL) {
} if ((strcmp(str, "off") == 0) || (strcmp(str, "0") == 0))
if ((str=getenv("_XKB_CONTROL_FALLBACK"))!=NULL) { xkbi->xlib_ctrls &= ~XkbLC_IgnoreNewKeyboards;
if ((strcmp(str,"off")==0)||(strcmp(str,"0")==0)) else
xkbi->xlib_ctrls&= ~XkbLC_ControlFallback; xkbi->xlib_ctrls |= XkbLC_IgnoreNewKeyboards;
else xkbi->xlib_ctrls|= XkbLC_ControlFallback; }
} if ((str = getenv("_XKB_CONTROL_FALLBACK")) != NULL) {
if ((str=getenv("_XKB_COMP_LED"))!=NULL) { if ((strcmp(str, "off") == 0) || (strcmp(str, "0") == 0))
if ((strcmp(str,"off")==0)||(strcmp(str,"0")==0)) xkbi->xlib_ctrls &= ~XkbLC_ControlFallback;
xkbi->xlib_ctrls&= ~XkbLC_ComposeLED; else
else { xkbi->xlib_ctrls |= XkbLC_ControlFallback;
xkbi->xlib_ctrls|= XkbLC_ComposeLED; }
if (strlen(str)>0) if ((str = getenv("_XKB_COMP_LED")) != NULL) {
xkbi->composeLED= XInternAtom(dpy,str,False); if ((strcmp(str, "off") == 0) || (strcmp(str, "0") == 0))
} xkbi->xlib_ctrls &= ~XkbLC_ComposeLED;
} else {
if ((str=getenv("_XKB_COMP_FAIL_BEEP"))!=NULL) { xkbi->xlib_ctrls |= XkbLC_ComposeLED;
if ((strcmp(str,"off")==0)||(strcmp(str,"0")==0)) if (strlen(str) > 0)
xkbi->xlib_ctrls&= ~XkbLC_BeepOnComposeFail; xkbi->composeLED = XInternAtom(dpy, str, False);
else xkbi->xlib_ctrls|= XkbLC_BeepOnComposeFail; }
} }
} if ((str = getenv("_XKB_COMP_FAIL_BEEP")) != NULL) {
if ((xkbi->composeLED==None)&&((xkbi->xlib_ctrls&XkbLC_ComposeLED)!=0)) if ((strcmp(str, "off") == 0) || (strcmp(str, "0") == 0))
xkbi->composeLED= XInternAtom(dpy,"Compose",False); xkbi->xlib_ctrls &= ~XkbLC_BeepOnComposeFail;
else
xkbi->xlib_ctrls |= XkbLC_BeepOnComposeFail;
}
}
if ((xkbi->composeLED == None) &&
((xkbi->xlib_ctrls & XkbLC_ComposeLED) != 0))
xkbi->composeLED = XInternAtom(dpy, "Compose", False);
#ifdef DEBUG #ifdef DEBUG
if (debugMsg) { if (debugMsg) {
register unsigned c= xkbi->xlib_ctrls; register unsigned c = xkbi->xlib_ctrls;
fprintf(stderr,"XKEYBOARD compose: beep on failure is %s, LED is %s\n",
((c&XkbLC_BeepOnComposeFail)?"on":"off"), fprintf(stderr,
((c&XkbLC_ComposeLED)?"on":"off")); "XKEYBOARD compose: beep on failure is %s, LED is %s\n",
fprintf(stderr,"XKEYBOARD XLookupString: %slatin-1, %s lookup modifiers\n", ((c & XkbLC_BeepOnComposeFail) ? "on" : "off"),
((c&XkbLC_ForceLatin1Lookup)?"allow non-":"force "), ((c & XkbLC_ComposeLED) ? "on" : "off"));
((c&XkbLC_ConsumeLookupMods)?"consume":"re-use")); fprintf(stderr,
fprintf(stderr, "XKEYBOARD XLookupString: %slatin-1, %s lookup modifiers\n",
"XKEYBOARD XLookupString: %sconsume shift and lock, %scontrol fallback\n", ((c & XkbLC_ForceLatin1Lookup) ? "allow non-" : "force "),
((c&XkbLC_AlwaysConsumeShiftAndLock)?"always ":"don't "), ((c & XkbLC_ConsumeLookupMods) ? "consume" : "re-use"));
((c&XkbLC_ControlFallback)?"":"no ")); fprintf(stderr,
"XKEYBOARD XLookupString: %sconsume shift and lock, %scontrol fallback\n",
((c & XkbLC_AlwaysConsumeShiftAndLock) ? "always " :
"don't "), ((c & XkbLC_ControlFallback) ? "" : "no "));
} }
#endif #endif
} else }
else
xkbi = dpy->xkb_info; xkbi = dpy->xkb_info;
forceIgnore= (dpy->flags&XlibDisplayNoXkb)||dpy->keysyms; forceIgnore = (dpy->flags & XlibDisplayNoXkb) || dpy->keysyms;
forceIgnore= forceIgnore&&(major_rtrn==NULL)&&(minor_rtrn==NULL); forceIgnore = forceIgnore && (major_rtrn == NULL) && (minor_rtrn == NULL);
if ( forceIgnore || _XkbIgnoreExtension || getenv("XKB_DISABLE")) { if (forceIgnore || _XkbIgnoreExtension || getenv("XKB_DISABLE")) {
LockDisplay(dpy); LockDisplay(dpy);
dpy->flags |= XlibDisplayNoXkb; dpy->flags |= XlibDisplayNoXkb;
UnlockDisplay(dpy); UnlockDisplay(dpy);
if (debugMsg) if (debugMsg)
fprintf(stderr,"XKEYBOARD extension disabled or missing\n"); fprintf(stderr, "XKEYBOARD extension disabled or missing\n");
return False; return False;
} }
if ( (codes=XInitExtension(dpy,XkbName))==NULL ) { if ((codes = XInitExtension(dpy, XkbName)) == NULL) {
LockDisplay(dpy); LockDisplay(dpy);
dpy->flags |= XlibDisplayNoXkb; dpy->flags |= XlibDisplayNoXkb;
UnlockDisplay(dpy); UnlockDisplay(dpy);
if (debugMsg) if (debugMsg)
fprintf(stderr,"XKEYBOARD extension not present\n"); fprintf(stderr, "XKEYBOARD extension not present\n");
return False; return False;
} }
xkbi->codes = codes; xkbi->codes = codes;
LockDisplay(dpy); LockDisplay(dpy);
...@@ -740,58 +762,64 @@ XkbUseExtension(Display *dpy,int *major_rtrn,int *minor_rtrn) ...@@ -740,58 +762,64 @@ XkbUseExtension(Display *dpy,int *major_rtrn,int *minor_rtrn)
req->xkbReqType = X_kbUseExtension; req->xkbReqType = X_kbUseExtension;
req->wantedMajor = XkbMajorVersion; req->wantedMajor = XkbMajorVersion;
req->wantedMinor = XkbMinorVersion; req->wantedMinor = XkbMinorVersion;
if (!_XReply(dpy, (xReply *)&rep, 0, xFalse) || !rep.supported ) { if (!_XReply(dpy, (xReply *) &rep, 0, xFalse) || !rep.supported) {
Bool fail; Bool fail;
fail= True;
if (debugMsg) fail = True;
fprintf(stderr, if (debugMsg)
"XKEYBOARD version mismatch (want %d.%02d, got %d.%02d)\n", fprintf(stderr,
XkbMajorVersion,XkbMinorVersion, "XKEYBOARD version mismatch (want %d.%02d, got %d.%02d)\n",
rep.serverMajor, rep.serverMinor); XkbMajorVersion, XkbMinorVersion,
rep.serverMajor, rep.serverMinor);
/* pre-release 0.65 is very close to 1.00 */
if ((rep.serverMajor==0)&&(rep.serverMinor==65)) { /* pre-release 0.65 is very close to 1.00 */
if (debugMsg) if ((rep.serverMajor == 0) && (rep.serverMinor == 65)) {
fprintf(stderr,"Trying to fall back to version 0.65..."); if (debugMsg)
GetReq(kbUseExtension, req); fprintf(stderr, "Trying to fall back to version 0.65...");
req->reqType = xkbi->codes->major_opcode; GetReq(kbUseExtension, req);
req->xkbReqType = X_kbUseExtension; req->reqType = xkbi->codes->major_opcode;
req->wantedMajor = 0; req->xkbReqType = X_kbUseExtension;
req->wantedMinor = 65; req->wantedMajor = 0;
if ( _XReply(dpy, (xReply *)&rep, 0, xFalse) && rep.supported ) { req->wantedMinor = 65;
if (debugMsg) if (_XReply(dpy, (xReply *) &rep, 0, xFalse) && rep.supported) {
fprintf(stderr,"succeeded\n"); if (debugMsg)
fail= False; fprintf(stderr, "succeeded\n");
} fail = False;
else if (debugMsg) fprintf(stderr,"failed\n"); }
} else if (debugMsg)
if (fail) { fprintf(stderr, "failed\n");
dpy->flags |= XlibDisplayNoXkb; }
UnlockDisplay(dpy); if (fail) {
SyncHandle(); dpy->flags |= XlibDisplayNoXkb;
if (major_rtrn) *major_rtrn= rep.serverMajor; UnlockDisplay(dpy);
if (minor_rtrn) *minor_rtrn= rep.serverMinor; SyncHandle();
return False; if (major_rtrn)
} *major_rtrn = rep.serverMajor;
if (minor_rtrn)
*minor_rtrn = rep.serverMinor;
return False;
}
} }
#ifdef DEBUG #ifdef DEBUG
else if ( forceIgnore ) { else if (forceIgnore) {
fprintf(stderr,"Internal Error! XkbUseExtension succeeded with forceIgnore set\n"); fprintf(stderr,
"Internal Error! XkbUseExtension succeeded with forceIgnore set\n");
} }
#endif #endif
UnlockDisplay(dpy); UnlockDisplay(dpy);
xkbi->srv_major= rep.serverMajor; xkbi->srv_major = rep.serverMajor;
xkbi->srv_minor= rep.serverMinor; xkbi->srv_minor = rep.serverMinor;
if (major_rtrn) *major_rtrn= rep.serverMajor; if (major_rtrn)
if (minor_rtrn) *minor_rtrn= rep.serverMinor; *major_rtrn = rep.serverMajor;
if (minor_rtrn)
*minor_rtrn = rep.serverMinor;
if (debugMsg) if (debugMsg)
fprintf(stderr,"XKEYBOARD (version %d.%02d/%d.%02d) OK!\n", fprintf(stderr, "XKEYBOARD (version %d.%02d/%d.%02d) OK!\n",
XkbMajorVersion,XkbMinorVersion, XkbMajorVersion, XkbMinorVersion,
rep.serverMajor,rep.serverMinor); rep.serverMajor, rep.serverMinor);
ev_base = codes->first_event; ev_base = codes->first_event;
XESetWireToEvent(dpy,ev_base+XkbEventCode,wire_to_event); XESetWireToEvent(dpy, ev_base + XkbEventCode, wire_to_event);
SyncHandle(); SyncHandle();
return True; return True;
} }
...@@ -33,159 +33,163 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. ...@@ -33,159 +33,163 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "XKBlibint.h" #include "XKBlibint.h"
Status Status
XkbGetIndicatorState(Display *dpy,unsigned deviceSpec,unsigned *pStateRtrn) XkbGetIndicatorState(Display *dpy, unsigned deviceSpec, unsigned *pStateRtrn)
{ {
register xkbGetIndicatorStateReq *req; register xkbGetIndicatorStateReq *req;
xkbGetIndicatorStateReply rep; xkbGetIndicatorStateReply rep;
XkbInfoPtr xkbi; XkbInfoPtr xkbi;
Bool ok; Bool ok;
if ((dpy->flags & XlibDisplayNoXkb) || if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return BadAccess; return BadAccess;
LockDisplay(dpy); LockDisplay(dpy);
xkbi = dpy->xkb_info; xkbi = dpy->xkb_info;
GetReq(kbGetIndicatorState, req); GetReq(kbGetIndicatorState, req);
req->reqType = xkbi->codes->major_opcode; req->reqType = xkbi->codes->major_opcode;
req->xkbReqType = X_kbGetIndicatorState; req->xkbReqType = X_kbGetIndicatorState;
req->deviceSpec = deviceSpec; req->deviceSpec = deviceSpec;
ok=_XReply(dpy, (xReply *)&rep, 0, xFalse); ok = _XReply(dpy, (xReply *) &rep, 0, xFalse);
if (ok && (pStateRtrn!=NULL)) if (ok && (pStateRtrn != NULL))
*pStateRtrn= rep.state; *pStateRtrn = rep.state;
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
return (ok?Success:BadImplementation); return (ok ? Success : BadImplementation);
} }
Status Status
_XkbReadGetIndicatorMapReply( Display * dpy, _XkbReadGetIndicatorMapReply(Display *dpy,
xkbGetIndicatorMapReply * rep, xkbGetIndicatorMapReply *rep,
XkbDescPtr xkb, XkbDescPtr xkb,
int * nread_rtrn) int *nread_rtrn)
{ {
XkbIndicatorPtr leds; XkbIndicatorPtr leds;
XkbReadBufferRec buf; XkbReadBufferRec buf;
if ((!xkb->indicators)&&(XkbAllocIndicatorMaps(xkb)!=Success)) if ((!xkb->indicators) && (XkbAllocIndicatorMaps(xkb) != Success))
return BadAlloc; return BadAlloc;
leds= xkb->indicators; leds = xkb->indicators;
leds->phys_indicators = rep->realIndicators; leds->phys_indicators = rep->realIndicators;
if (rep->length>0) { if (rep->length > 0) {
register int left; register int left;
if (!_XkbInitReadBuffer(dpy,&buf,(int)rep->length*4))
return BadAlloc; if (!_XkbInitReadBuffer(dpy, &buf, (int) rep->length * 4))
if (nread_rtrn) return BadAlloc;
*nread_rtrn= (int)rep->length*4; if (nread_rtrn)
if (rep->which) { *nread_rtrn = (int) rep->length * 4;
register int i,bit; if (rep->which) {
left= (int)rep->which; register int i, bit;
for (i=0,bit=1;(i<XkbNumIndicators)&&(left);i++,bit<<=1) {
if (left&bit) { left = (int) rep->which;
xkbIndicatorMapWireDesc *wire; for (i = 0, bit = 1; (i < XkbNumIndicators) && (left);
wire= (xkbIndicatorMapWireDesc *) i++, bit <<= 1) {
_XkbGetReadBufferPtr(&buf, if (left & bit) {
SIZEOF(xkbIndicatorMapWireDesc)); xkbIndicatorMapWireDesc *wire;
if (wire==NULL) {
_XkbFreeReadBuffer(&buf); wire = (xkbIndicatorMapWireDesc *)
return BadAlloc; _XkbGetReadBufferPtr(&buf,
} SIZEOF(xkbIndicatorMapWireDesc));
leds->maps[i].flags= wire->flags; if (wire == NULL) {
leds->maps[i].which_groups= wire->whichGroups; _XkbFreeReadBuffer(&buf);
leds->maps[i].groups= wire->groups; return BadAlloc;
leds->maps[i].which_mods= wire->whichMods; }
leds->maps[i].mods.mask= wire->mods; leds->maps[i].flags = wire->flags;
leds->maps[i].mods.real_mods= wire->realMods; leds->maps[i].which_groups = wire->whichGroups;
leds->maps[i].mods.vmods= wire->virtualMods; leds->maps[i].groups = wire->groups;
leds->maps[i].ctrls= wire->ctrls; leds->maps[i].which_mods = wire->whichMods;
left&= ~bit; leds->maps[i].mods.mask = wire->mods;
} leds->maps[i].mods.real_mods = wire->realMods;
} leds->maps[i].mods.vmods = wire->virtualMods;
} leds->maps[i].ctrls = wire->ctrls;
left= _XkbFreeReadBuffer(&buf); left &= ~bit;
}
}
}
left = _XkbFreeReadBuffer(&buf);
} }
return Success; return Success;
} }
Bool Bool
XkbGetIndicatorMap(Display *dpy,unsigned long which,XkbDescPtr xkb) XkbGetIndicatorMap(Display *dpy, unsigned long which, XkbDescPtr xkb)
{ {
register xkbGetIndicatorMapReq * req; register xkbGetIndicatorMapReq *req;
xkbGetIndicatorMapReply rep; xkbGetIndicatorMapReply rep;
XkbInfoPtr xkbi; XkbInfoPtr xkbi;
Status status; Status status;
if ((dpy->flags & XlibDisplayNoXkb) || if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return BadAccess; return BadAccess;
if ((!which)||(!xkb)) if ((!which) || (!xkb))
return BadValue; return BadValue;
LockDisplay(dpy); LockDisplay(dpy);
xkbi = dpy->xkb_info; xkbi = dpy->xkb_info;
if (!xkb->indicators) { if (!xkb->indicators) {
xkb->indicators = _XkbTypedCalloc(1,XkbIndicatorRec); xkb->indicators = _XkbTypedCalloc(1, XkbIndicatorRec);
if (!xkb->indicators) { if (!xkb->indicators) {
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
return BadAlloc; return BadAlloc;
} }
} }
GetReq(kbGetIndicatorMap, req); GetReq(kbGetIndicatorMap, req);
req->reqType = xkbi->codes->major_opcode; req->reqType = xkbi->codes->major_opcode;
req->xkbReqType = X_kbGetIndicatorMap; req->xkbReqType = X_kbGetIndicatorMap;
req->deviceSpec = xkb->device_spec; req->deviceSpec = xkb->device_spec;
req->which = (CARD32)which; req->which = (CARD32) which;
if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) {
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
return BadValue; return BadValue;
} }
status= _XkbReadGetIndicatorMapReply(dpy,&rep,xkb,NULL); status = _XkbReadGetIndicatorMapReply(dpy, &rep, xkb, NULL);
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
return status; return status;
} }
Bool Bool
XkbSetIndicatorMap(Display *dpy,unsigned long which,XkbDescPtr xkb) XkbSetIndicatorMap(Display *dpy, unsigned long which, XkbDescPtr xkb)
{ {
register xkbSetIndicatorMapReq *req; register xkbSetIndicatorMapReq *req;
register int i,bit; register int i, bit;
int nMaps; int nMaps;
xkbIndicatorMapWireDesc *wire; xkbIndicatorMapWireDesc *wire;
XkbInfoPtr xkbi; XkbInfoPtr xkbi;
if ((dpy->flags & XlibDisplayNoXkb) || if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return False; return False;
if ((!xkb)||(!which)||(!xkb->indicators)) if ((!xkb) || (!which) || (!xkb->indicators))
return False; return False;
LockDisplay(dpy); LockDisplay(dpy);
xkbi = dpy->xkb_info; xkbi = dpy->xkb_info;
GetReq(kbSetIndicatorMap, req); GetReq(kbSetIndicatorMap, req);
req->reqType = xkbi->codes->major_opcode; req->reqType = xkbi->codes->major_opcode;
req->xkbReqType = X_kbSetIndicatorMap; req->xkbReqType = X_kbSetIndicatorMap;
req->deviceSpec = xkb->device_spec; req->deviceSpec = xkb->device_spec;
req->which = (CARD32)which; req->which = (CARD32) which;
for (i=nMaps=0,bit=1;i<32;i++,bit<<=1) { for (i = nMaps = 0, bit = 1; i < 32; i++, bit <<= 1) {
if (which&bit) if (which & bit)
nMaps++; nMaps++;
} }
req->length+= (nMaps*sizeof(XkbIndicatorMapRec))/4; req->length += (nMaps * sizeof(XkbIndicatorMapRec)) / 4;
BufAlloc(xkbIndicatorMapWireDesc *,wire, BufAlloc(xkbIndicatorMapWireDesc *, wire,
(nMaps*SIZEOF(xkbIndicatorMapWireDesc))); (nMaps * SIZEOF(xkbIndicatorMapWireDesc)));
for (i=0,bit=1;i<32;i++,bit<<=1) { for (i = 0, bit = 1; i < 32; i++, bit <<= 1) {
if (which&bit) { if (which & bit) {
wire->flags= xkb->indicators->maps[i].flags; wire->flags = xkb->indicators->maps[i].flags;
wire->whichGroups= xkb->indicators->maps[i].which_groups; wire->whichGroups = xkb->indicators->maps[i].which_groups;
wire->groups= xkb->indicators->maps[i].groups; wire->groups = xkb->indicators->maps[i].groups;
wire->whichMods= xkb->indicators->maps[i].which_mods; wire->whichMods = xkb->indicators->maps[i].which_mods;
wire->mods= xkb->indicators->maps[i].mods.real_mods; wire->mods = xkb->indicators->maps[i].mods.real_mods;
wire->virtualMods= xkb->indicators->maps[i].mods.vmods; wire->virtualMods = xkb->indicators->maps[i].mods.vmods;
wire->ctrls= xkb->indicators->maps[i].ctrls; wire->ctrls = xkb->indicators->maps[i].ctrls;
wire++; wire++;
} }
} }
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
...@@ -193,23 +197,23 @@ XkbSetIndicatorMap(Display *dpy,unsigned long which,XkbDescPtr xkb) ...@@ -193,23 +197,23 @@ XkbSetIndicatorMap(Display *dpy,unsigned long which,XkbDescPtr xkb)
} }
Bool Bool
XkbGetNamedDeviceIndicator( Display * dpy, XkbGetNamedDeviceIndicator(Display *dpy,
unsigned device, unsigned device,
unsigned class, unsigned class,
unsigned id, unsigned id,
Atom name, Atom name,
int * pNdxRtrn, int *pNdxRtrn,
Bool * pStateRtrn, Bool *pStateRtrn,
XkbIndicatorMapPtr pMapRtrn, XkbIndicatorMapPtr pMapRtrn,
Bool * pRealRtrn) Bool *pRealRtrn)
{ {
register xkbGetNamedIndicatorReq *req; register xkbGetNamedIndicatorReq *req;
xkbGetNamedIndicatorReply rep; xkbGetNamedIndicatorReply rep;
XkbInfoPtr xkbi; XkbInfoPtr xkbi;
if ((dpy->flags & XlibDisplayNoXkb) || (name==None) || if ((dpy->flags & XlibDisplayNoXkb) || (name == None) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return False; return False;
LockDisplay(dpy); LockDisplay(dpy);
xkbi = dpy->xkb_info; xkbi = dpy->xkb_info;
GetReq(kbGetNamedIndicator, req); GetReq(kbGetNamedIndicator, req);
...@@ -218,66 +222,66 @@ XkbGetNamedDeviceIndicator( Display * dpy, ...@@ -218,66 +222,66 @@ XkbGetNamedDeviceIndicator( Display * dpy,
req->deviceSpec = device; req->deviceSpec = device;
req->ledClass = class; req->ledClass = class;
req->ledID = id; req->ledID = id;
req->indicator = (CARD32)name; req->indicator = (CARD32) name;
if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) {
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
return False; return False;
} }
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
if ((!rep.found)||(!rep.supported)) if ((!rep.found) || (!rep.supported))
return False; return False;
if (pNdxRtrn!=NULL) if (pNdxRtrn != NULL)
*pNdxRtrn= rep.ndx; *pNdxRtrn = rep.ndx;
if (pStateRtrn!=NULL) if (pStateRtrn != NULL)
*pStateRtrn= rep.on; *pStateRtrn = rep.on;
if (pMapRtrn!=NULL) { if (pMapRtrn != NULL) {
pMapRtrn->flags= rep.flags; pMapRtrn->flags = rep.flags;
pMapRtrn->which_groups= rep.whichGroups; pMapRtrn->which_groups = rep.whichGroups;
pMapRtrn->groups= rep.groups; pMapRtrn->groups = rep.groups;
pMapRtrn->which_mods= rep.whichMods; pMapRtrn->which_mods = rep.whichMods;
pMapRtrn->mods.mask= rep.mods; pMapRtrn->mods.mask = rep.mods;
pMapRtrn->mods.real_mods= rep.realMods; pMapRtrn->mods.real_mods = rep.realMods;
pMapRtrn->mods.vmods= rep.virtualMods; pMapRtrn->mods.vmods = rep.virtualMods;
pMapRtrn->ctrls= rep.ctrls; pMapRtrn->ctrls = rep.ctrls;
} }
if (pRealRtrn!=NULL) if (pRealRtrn != NULL)
*pRealRtrn= rep.realIndicator; *pRealRtrn = rep.realIndicator;
return True; return True;
} }
Bool Bool
XkbGetNamedIndicator( Display * dpy, XkbGetNamedIndicator(Display *dpy,
Atom name, Atom name,
int * pNdxRtrn, int *pNdxRtrn,
Bool * pStateRtrn, Bool *pStateRtrn,
XkbIndicatorMapPtr pMapRtrn, XkbIndicatorMapPtr pMapRtrn,
Bool * pRealRtrn) Bool *pRealRtrn)
{ {
return XkbGetNamedDeviceIndicator(dpy,XkbUseCoreKbd, return XkbGetNamedDeviceIndicator(dpy, XkbUseCoreKbd,
XkbDfltXIClass,XkbDfltXIId, XkbDfltXIClass, XkbDfltXIId,
name,pNdxRtrn,pStateRtrn, name, pNdxRtrn, pStateRtrn,
pMapRtrn,pRealRtrn); pMapRtrn, pRealRtrn);
} }
Bool Bool
XkbSetNamedDeviceIndicator( Display * dpy, XkbSetNamedDeviceIndicator(Display *dpy,
unsigned device, unsigned device,
unsigned class, unsigned class,
unsigned id, unsigned id,
Atom name, Atom name,
Bool changeState, Bool changeState,
Bool state, Bool state,
Bool createNewMap, Bool createNewMap,
XkbIndicatorMapPtr pMap) XkbIndicatorMapPtr pMap)
{ {
register xkbSetNamedIndicatorReq *req; register xkbSetNamedIndicatorReq *req;
XkbInfoPtr xkbi; XkbInfoPtr xkbi;
if ((dpy->flags & XlibDisplayNoXkb) || (name==None) || if ((dpy->flags & XlibDisplayNoXkb) || (name == None) ||
(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return False; return False;
LockDisplay(dpy); LockDisplay(dpy);
xkbi = dpy->xkb_info; xkbi = dpy->xkb_info;
GetReq(kbSetNamedIndicator, req); GetReq(kbSetNamedIndicator, req);
...@@ -286,32 +290,33 @@ XkbSetNamedDeviceIndicator( Display * dpy, ...@@ -286,32 +290,33 @@ XkbSetNamedDeviceIndicator( Display * dpy,
req->deviceSpec = device; req->deviceSpec = device;
req->ledClass = class; req->ledClass = class;
req->ledID = id; req->ledID = id;
req->indicator= (CARD32)name; req->indicator = (CARD32) name;
req->setState= changeState; req->setState = changeState;
if (req->setState) if (req->setState)
req->on= state; req->on = state;
else req->on= False; else
if (pMap!=NULL) { req->on = False;
req->setMap= True; if (pMap != NULL) {
req->createMap= createNewMap; req->setMap = True;
req->flags= pMap->flags; req->createMap = createNewMap;
req->whichGroups= pMap->which_groups; req->flags = pMap->flags;
req->groups= pMap->groups; req->whichGroups = pMap->which_groups;
req->whichMods= pMap->which_mods; req->groups = pMap->groups;
req->realMods= pMap->mods.real_mods; req->whichMods = pMap->which_mods;
req->virtualMods= pMap->mods.vmods; req->realMods = pMap->mods.real_mods;
req->ctrls= pMap->ctrls; req->virtualMods = pMap->mods.vmods;
req->ctrls = pMap->ctrls;
} }
else { else {
req->setMap= False; req->setMap = False;
req->createMap= False; req->createMap = False;
req->flags= 0; req->flags = 0;
req->whichGroups= 0; req->whichGroups = 0;
req->groups= 0; req->groups = 0;
req->whichMods= 0; req->whichMods = 0;
req->realMods= 0; req->realMods = 0;
req->virtualMods= 0; req->virtualMods = 0;
req->ctrls= 0; req->ctrls = 0;
} }
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
...@@ -319,15 +324,15 @@ XkbSetNamedDeviceIndicator( Display * dpy, ...@@ -319,15 +324,15 @@ XkbSetNamedDeviceIndicator( Display * dpy,
} }
Bool Bool
XkbSetNamedIndicator( Display * dpy, XkbSetNamedIndicator(Display *dpy,
Atom name, Atom name,
Bool changeState, Bool changeState,
Bool state, Bool state,
Bool createNewMap, Bool createNewMap,
XkbIndicatorMapPtr pMap) XkbIndicatorMapPtr pMap)
{ {
return XkbSetNamedDeviceIndicator(dpy,XkbUseCoreKbd, return XkbSetNamedDeviceIndicator(dpy, XkbUseCoreKbd,
XkbDfltXIClass,XkbDfltXIId, XkbDfltXIClass, XkbDfltXIId,
name,changeState,state, name, changeState, state,
createNewMap,pMap); createNewMap, pMap);
} }
...@@ -25,210 +25,210 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. ...@@ -25,210 +25,210 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
********************************************************/ ********************************************************/
#ifndef _XKBLIBINT_H_ #ifndef _XKBLIBINT_H_
#define _XKBLIBINT_H_ #define _XKBLIBINT_H_
#include <nx-X11/Xutil.h> #include <nx-X11/Xutil.h>
#include <nx-X11/XKBlib.h> #include <nx-X11/XKBlib.h>
#define XkbMapPending (1<<0) #define XkbMapPending (1<<0)
#define XkbXlibNewKeyboard (1<<1) #define XkbXlibNewKeyboard (1<<1)
typedef int (*XkbKSToMBFunc)( typedef int (*XkbKSToMBFunc)(
XPointer /* priv */, XPointer /* priv */,
KeySym /* sym */, KeySym /* sym */,
char * /* buf */, char * /* buf */,
int /* len */, int /* len */,
int * /* extra_rtrn */ int * /* extra_rtrn */
); );
typedef KeySym (*XkbMBToKSFunc)( typedef KeySym (*XkbMBToKSFunc)(
XPointer /* priv */, XPointer /* priv */,
char * /* buf */, char * /* buf */,
int /* len */, int /* len */,
Status * /* status */ Status * /* status */
); );
typedef KeySym (*XkbToUpperFunc)( typedef KeySym (*XkbToUpperFunc)(
KeySym /* sym */ KeySym /* sym */
); );
typedef struct _XkbConverters { typedef struct _XkbConverters {
XkbKSToMBFunc KSToMB; XkbKSToMBFunc KSToMB;
XPointer KSToMBPriv; XPointer KSToMBPriv;
XkbMBToKSFunc MBToKS; XkbMBToKSFunc MBToKS;
XPointer MBToKSPriv; XPointer MBToKSPriv;
XkbToUpperFunc KSToUpper; XkbToUpperFunc KSToUpper;
} XkbConverters; } XkbConverters;
extern XkbInternAtomFunc _XkbInternAtomFunc; extern XkbInternAtomFunc _XkbInternAtomFunc;
extern XkbGetAtomNameFunc _XkbGetAtomNameFunc; extern XkbGetAtomNameFunc _XkbGetAtomNameFunc;
typedef struct _XkbInfoRec { typedef struct _XkbInfoRec {
unsigned flags; unsigned flags;
unsigned xlib_ctrls; unsigned xlib_ctrls;
XExtCodes *codes; XExtCodes *codes;
int srv_major; int srv_major;
int srv_minor; int srv_minor;
unsigned selected_events; unsigned selected_events;
unsigned short selected_nkn_details; unsigned short selected_nkn_details;
unsigned short selected_map_details; unsigned short selected_map_details;
XkbDescRec *desc; XkbDescRec *desc;
XkbMapChangesRec changes; XkbMapChangesRec changes;
Atom composeLED; Atom composeLED;
XkbConverters cvt; XkbConverters cvt;
XkbConverters latin1cvt; XkbConverters latin1cvt;
} XkbInfoRec, *XkbInfoPtr; } XkbInfoRec, *XkbInfoPtr;
#define _XkbUnavailable(d) \ #define _XkbUnavailable(d) \
(((d)->flags&XlibDisplayNoXkb) ||\ (((d)->flags&XlibDisplayNoXkb) || \
((!(d)->xkb_info || (!(d)->xkb_info->desc)) && !_XkbLoadDpy(d))) ((!(d)->xkb_info || (!(d)->xkb_info->desc)) && !_XkbLoadDpy(d)))
#define _XkbCheckPendingRefresh(d,xi) {\ #define _XkbCheckPendingRefresh(d,xi) { \
if ((xi)->flags&XkbXlibNewKeyboard)\ if ((xi)->flags&XkbXlibNewKeyboard) \
_XkbReloadDpy((d));\ _XkbReloadDpy((d)); \
else if ((xi)->flags&XkbMapPending) {\ else if ((xi)->flags&XkbMapPending) { \
if (XkbGetMapChanges((d),(xi)->desc, &(xi)->changes)==Success) {\ if (XkbGetMapChanges((d),(xi)->desc, &(xi)->changes)==Success) { \
LockDisplay((d));\ LockDisplay((d)); \
(xi)->changes.changed= 0;\ (xi)->changes.changed= 0; \
UnlockDisplay((d));\ UnlockDisplay((d)); \
}\ } \
}\ } \
} }
#define _XkbNeedModmap(i) ((!(i)->desc->map)||(!(i)->desc->map->modmap)) #define _XkbNeedModmap(i) ((!(i)->desc->map)||(!(i)->desc->map->modmap))
/* /*
* mask of the events that the "invisible" XKB support in Xlib needs * mask of the events that the "invisible" XKB support in Xlib needs
*/ */
#define XKB_XLIB_MAP_MASK (XkbAllClientInfoMask) #define XKB_XLIB_MAP_MASK (XkbAllClientInfoMask)
/* /*
* Handy helper macros * Handy helper macros
*/ */
typedef struct _XkbReadBuffer { typedef struct _XkbReadBuffer {
int error; int error;
int size; int size;
char *start; char *start;
char *data; char *data;
} XkbReadBufferRec,*XkbReadBufferPtr; } XkbReadBufferRec, *XkbReadBufferPtr;
#define _XkbAlloc(s) Xmalloc((s)) #define _XkbAlloc(s) Xmalloc((s))
#define _XkbCalloc(n,s) Xcalloc((n),(s)) #define _XkbCalloc(n,s) Xcalloc((n),(s))
#define _XkbRealloc(o,s) Xrealloc((o),(s)) #define _XkbRealloc(o,s) Xrealloc((o),(s))
#define _XkbTypedAlloc(t) ((t *)Xmalloc(sizeof(t))) #define _XkbTypedAlloc(t) ((t *)Xmalloc(sizeof(t)))
#define _XkbTypedCalloc(n,t) ((t *)Xcalloc((n),sizeof(t))) #define _XkbTypedCalloc(n,t) ((t *)Xcalloc((n),sizeof(t)))
#define _XkbTypedRealloc(o,n,t) \ #define _XkbTypedRealloc(o,n,t) \
((o)?(t *)Xrealloc((o),(n)*sizeof(t)):_XkbTypedCalloc(n,t)) ((o) ? (t *)Xrealloc((o), (n)*sizeof(t)) : _XkbTypedCalloc(n,t))
#define _XkbClearElems(a,f,l,t) bzero(&(a)[f],((l)-(f)+1)*sizeof(t)) #define _XkbClearElems(a,f,l,t) bzero(&(a)[f], ((l)-(f)+1) * sizeof(t))
#define _XkbFree(p) Xfree(p) #define _XkbFree(p) Xfree(p)
_XFUNCPROTOBEGIN _XFUNCPROTOBEGIN
extern void _XkbReloadDpy( extern void _XkbReloadDpy(
Display * /* dpy */ Display * /* dpy */
); );
extern KeySym _XKeycodeToKeysym( extern KeySym _XKeycodeToKeysym(
Display* /* display */, Display * /* display */,
#if NeedWidePrototypes #if NeedWidePrototypes
unsigned int /* keycode */, unsigned int /* keycode */,
#else #else
KeyCode /* keycode */, KeyCode /* keycode */,
#endif #endif
int /* index */ int /* index */
); );
extern KeyCode _XKeysymToKeycode( extern KeyCode _XKeysymToKeycode(
Display* /* display */, Display * /* display */,
KeySym /* keysym */ KeySym /* keysym */
); );
extern KeySym _XLookupKeysym( extern KeySym _XLookupKeysym(
XKeyEvent* /* key_event */, XKeyEvent * /* key_event */,
int /* index */ int /* index */
); );
extern int _XRefreshKeyboardMapping( extern int _XRefreshKeyboardMapping(
XMappingEvent* /* event_map */ XMappingEvent * /* event_map */
); );
extern unsigned _XKeysymToModifiers( extern unsigned _XKeysymToModifiers(
Display * /* dpy */, Display * /* dpy */,
KeySym /* ks */ KeySym /* ks */
); );
extern int _XTranslateKey( extern int _XTranslateKey(
register Display * /* dpy */, register Display * /* dpy */,
KeyCode /* keycode */, KeyCode /* keycode */,
register unsigned int /* modifiers */, register unsigned int /* modifiers */,
unsigned int * /* modifiers_return */, unsigned int * /* modifiers_return */,
KeySym * /* keysym_return */ KeySym * /* keysym_return */
); );
extern int _XTranslateKeySym( extern int _XTranslateKeySym(
Display * /* dpy */, Display * /* dpy */,
register KeySym /* symbol */, register KeySym /* symbol */,
unsigned int /* modifiers */, unsigned int /* modifiers */,
char * /* buffer */, char * /* buffer */,
int /* nbytes */ int /* nbytes */
); );
extern int _XLookupString( extern int _XLookupString(
register XKeyEvent * /* event */, register XKeyEvent * /* event */,
char * /* buffer */, char * /* buffer */,
int /* nbytes */, int /* nbytes */,
KeySym * /* keysym */, KeySym * /* keysym */,
XComposeStatus * /* status */ XComposeStatus * /* status */
); );
extern void _XkbNoteCoreMapChanges( extern void _XkbNoteCoreMapChanges(
XkbMapChangesRec * /* old */, XkbMapChangesRec * /* old */,
XMappingEvent * /* new */, XMappingEvent * /* new */,
unsigned int /* wanted */ unsigned int /* wanted */
); );
extern int _XkbInitReadBuffer( extern int _XkbInitReadBuffer(
Display * /* dpy */, Display * /* dpy */,
XkbReadBufferPtr /* buf */, XkbReadBufferPtr /* buf */,
int /* size */ int /* size */
); );
extern int _XkbSkipReadBufferData( extern int _XkbSkipReadBufferData(
XkbReadBufferPtr /* from */, XkbReadBufferPtr /* from */,
int /* size */ int /* size */
); );
extern int _XkbCopyFromReadBuffer( extern int _XkbCopyFromReadBuffer(
XkbReadBufferPtr /* from */, XkbReadBufferPtr /* from */,
char * /* to */, char * /* to */,
int /* size */ int /* size */
); );
#ifdef LONG64 #ifdef LONG64
extern int _XkbReadCopyData32( extern int _XkbReadCopyData32(
int * /* from */, int * /* from */,
long * /* to */, long * /* to */,
int /* num_words */ int /* num_words */
); );
extern int _XkbWriteCopyData32( extern int _XkbWriteCopyData32(
unsigned long * /* from */, unsigned long * /* from */,
CARD32 * /* to */, CARD32 * /* to */,
int /* num_words */ int /* num_words */
); );
extern int _XkbReadBufferCopy32( extern int _XkbReadBufferCopy32(
XkbReadBufferPtr /* from */, XkbReadBufferPtr /* from */,
long * /* to */, long * /* to */,
int /* size */ int /* size */
); );
#else #else
#define _XkbReadCopyData32(f,t,s) memcpy((char *)(t),(char *)(f),(s)*4) #define _XkbReadCopyData32(f,t,s) memcpy((char *)(t), (char *)(f), (s)*4)
#define _XkbWriteCopyData32(f,t,s) memcpy((char *)(t),(char *)(f),(s)*4) #define _XkbWriteCopyData32(f,t,s) memcpy((char *)(t), (char *)(f), (s)*4)
#define _XkbReadBufferCopy32(f,t,s) _XkbCopyFromReadBuffer(f,(char *)t,(s)*4) #define _XkbReadBufferCopy32(f,t,s) _XkbCopyFromReadBuffer(f, (char *)t, (s)*4)
#endif #endif
#ifndef NO_DEC_BINARY_COMPATIBILITY #ifndef NO_DEC_BINARY_COMPATIBILITY
...@@ -237,97 +237,97 @@ extern int _XkbReadBufferCopy32( ...@@ -237,97 +237,97 @@ extern int _XkbReadBufferCopy32(
#ifdef XKB_FORCE_INT_KEYSYM #ifdef XKB_FORCE_INT_KEYSYM
extern int _XkbReadCopyKeySyms( extern int _XkbReadCopyKeySyms(
int * /* from */, int * /* from */,
KeySym * /* to */, KeySym * /* to */,
int /* num_words */ int /* num_words */
); );
extern int _XkbWriteCopyKeySyms( extern int _XkbWriteCopyKeySyms(
KeySym * /* from */, KeySym * /* from */,
CARD32 * /* to */, CARD32 * /* to */,
int /* num_words */ int /* num_words */
); );
extern int _XkbReadBufferCopyKeySyms( extern int _XkbReadBufferCopyKeySyms(
XkbReadBufferPtr /* from */, XkbReadBufferPtr /* from */,
#ifndef NO_DEC_BUG_FIX #ifndef NO_DEC_BUG_FIX
KeySym * /* to */, KeySym * /* to */,
#else #else
long * /* to */, long * /* to */,
#endif #endif
int /* size */ int /* size */
); );
#else #else
#define _XkbReadCopyKeySyms(f,t,n) _XkbReadCopyData32(f,t,n) #define _XkbReadCopyKeySyms(f,t,n) _XkbReadCopyData32(f,t,n)
#define _XkbWriteCopyKeySyms(f,t,n) _XkbWriteCopyData32(f,t,n) #define _XkbWriteCopyKeySyms(f,t,n) _XkbWriteCopyData32(f,t,n)
#define _XkbReadBufferCopyKeySyms(f,t,s) _XkbReadBufferCopy32(f,t,s) #define _XkbReadBufferCopyKeySyms(f,t,s) _XkbReadBufferCopy32(f,t,s)
#endif #endif
extern char *_XkbPeekAtReadBuffer( extern char *_XkbPeekAtReadBuffer(
XkbReadBufferPtr /* from */, XkbReadBufferPtr /* from */,
int /* size */ int /* size */
); );
extern char *_XkbGetReadBufferPtr( extern char *_XkbGetReadBufferPtr(
XkbReadBufferPtr /* from */, XkbReadBufferPtr /* from */,
int /* size */ int /* size */
); );
#define _XkbGetTypedRdBufPtr(b,n,t) ((t *)_XkbGetReadBufferPtr(b,(n)*SIZEOF(t))) #define _XkbGetTypedRdBufPtr(b,n,t) ((t *)_XkbGetReadBufferPtr(b,(n)*SIZEOF(t)))
extern int _XkbFreeReadBuffer( extern int _XkbFreeReadBuffer(
XkbReadBufferPtr /* buf */ XkbReadBufferPtr /* buf */
); );
extern Bool extern Bool
_XkbGetReadBufferCountedString( _XkbGetReadBufferCountedString(
XkbReadBufferPtr /* buf */, XkbReadBufferPtr /* buf */,
char ** /* rtrn */ char ** /* rtrn */
); );
extern char *_XkbGetCharset( extern char *_XkbGetCharset(
void void
); );
extern int _XkbGetConverters( extern int _XkbGetConverters(
const char * /* encoding_name */, const char * /* encoding_name */,
XkbConverters * /* cvt_rtrn */ XkbConverters * /* cvt_rtrn */
); );
#ifdef NEED_MAP_READERS #ifdef NEED_MAP_READERS
extern Status _XkbReadGetMapReply( extern Status _XkbReadGetMapReply(
Display * /* dpy */, Display * /* dpy */,
xkbGetMapReply * /* rep */, xkbGetMapReply * /* rep */,
XkbDescRec * /* xkb */, XkbDescRec * /* xkb */,
int * /* nread_rtrn */ int * /* nread_rtrn */
); );
extern Status _XkbReadGetCompatMapReply( extern Status _XkbReadGetCompatMapReply(
Display * /* dpy */, Display * /* dpy */,
xkbGetCompatMapReply * /* rep */, xkbGetCompatMapReply * /* rep */,
XkbDescPtr /* xkb */, XkbDescPtr /* xkb */,
int * /* nread_rtrn */ int * /* nread_rtrn */
); );
extern Status _XkbReadGetIndicatorMapReply( extern Status _XkbReadGetIndicatorMapReply(
Display * /* dpy */, Display * /* dpy */,
xkbGetIndicatorMapReply * /* rep */, xkbGetIndicatorMapReply * /* rep */,
XkbDescPtr /* xkb */, XkbDescPtr /* xkb */,
int * /* nread_rtrn */ int * /* nread_rtrn */
); );
extern Status _XkbReadGetNamesReply( extern Status _XkbReadGetNamesReply(
Display * /* dpy */, Display * /* dpy */,
xkbGetNamesReply * /* rep */, xkbGetNamesReply * /* rep */,
XkbDescPtr /* xkb */, XkbDescPtr /* xkb */,
int * /* nread_rtrn */ int * /* nread_rtrn */
); );
extern Status _XkbReadGetGeometryReply( extern Status _XkbReadGetGeometryReply(
Display * /* dpy */, Display * /* dpy */,
xkbGetGeometryReply * /* rep */, xkbGetGeometryReply * /* rep */,
XkbDescPtr /* xkb */, XkbDescPtr /* xkb */,
int * /* nread_rtrn */ int * /* nread_rtrn */
); );
#endif #endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment