Add action datatypes as defined in the server
authorDan Nicholson <dbn.lists@gmail.com>
Sun, 5 Apr 2009 22:15:20 +0000 (15:15 -0700)
committerDan Nicholson <dbn.lists@gmail.com>
Sun, 5 Apr 2009 22:15:20 +0000 (15:15 -0700)
Some of the XkbAction types are defined differently in the server, so we
add those to XKBcommon.h and use them here like XkbcDescPtr. We'll have
to deal with the impedance mismatch on the client side later.

include/X11/extensions/XKBcommon.h
src/malloc.c
src/xkbcomp/action.c
src/xkbcomp/symbols.c
src/xkbcomp/vmod.c

index f7700f5..21f8908 100644 (file)
@@ -36,6 +36,82 @@ authorization from the authors.
 #include <X11/extensions/XKBgeomcommon.h>
 #include <X11/extensions/XKBrulescommon.h>
 
+/* Action structures used in the server */
+typedef struct _XkbcModAction {
+    unsigned char   type;
+    unsigned char   flags;
+    unsigned char   mask;
+    unsigned char   real_mods;
+    unsigned int    vmods;
+} XkbcModAction;
+
+typedef struct _XkbcISOAction {
+    unsigned char   type;
+    unsigned char   flags;
+    unsigned char   mask;
+    unsigned char   real_mods;
+    /* FIXME: Make this an int. */
+    char            group_XXX;
+    unsigned char   affect;
+    unsigned int    vmods;
+} XkbcISOAction;
+
+typedef struct _XkbcPtrAction {
+    unsigned char   type;
+    unsigned char   flags;
+    int             x;
+    int             y;
+} XkbcPtrAction;
+
+typedef struct _XkbcCtrlsAction {
+    unsigned char   type;
+    unsigned char   flags;
+    unsigned long   ctrls;
+} XkbcCtrlsAction;
+
+typedef struct  _XkbcRedirectKeyAction {
+    unsigned char   type;
+    unsigned char   new_key;
+    unsigned char   mods_mask;
+    unsigned char   mods;
+    unsigned int    vmods_mask;
+    unsigned int    vmods;
+} XkbcRedirectKeyAction;
+
+typedef union _XkbcAction {
+    XkbAnyAction            any;
+    XkbcModAction           mods;
+    XkbGroupAction          group;
+    XkbcISOAction           iso;
+    XkbcPtrAction           ptr;
+    XkbPtrBtnAction         btn;
+    XkbPtrDfltAction        dflt;
+    XkbSwitchScreenAction   screen;
+    XkbcCtrlsAction         ctrls;
+    XkbMessageAction        msg;
+    XkbcRedirectKeyAction   redirect;
+    XkbDeviceBtnAction      devbtn;
+    XkbDeviceValuatorAction devval;
+    unsigned char           type;
+} XkbcAction;
+
+typedef struct _XkbcServerMapRec {
+    unsigned short      num_acts;
+    unsigned short      size_acts;
+    XkbcAction *        acts;
+
+    XkbBehavior *       behaviors;
+    unsigned short *    key_acts;
+#if defined(__cplusplus) || defined(c_plusplus)
+    /* explicit is a C++ reserved word */
+    unsigned char *     c_explicit;
+#else
+    unsigned char *     explicit;
+#endif
+    unsigned char       vmods[XkbNumVirtualMods];
+    unsigned short *    vmodmap;
+} XkbcServerMapRec, *XkbcServerMapPtr;
+
 /* Common keyboard description structure */
 typedef struct _XkbcDesc {
     unsigned int        defined;
@@ -45,7 +121,7 @@ typedef struct _XkbcDesc {
     KeyCode             max_key_code;
 
     XkbControlsPtr      ctrls;
-    XkbServerMapPtr     server;
+    XkbcServerMapPtr    server;
     XkbClientMapPtr     map;
     XkbIndicatorPtr     indicators;
     XkbNamesPtr         names;
@@ -130,7 +206,7 @@ extern int
 XkbcChangeKeycodeRange(XkbcDescPtr xkb, int minKC, int maxKC,
                        XkbChangesPtr changes);
 
-extern XkbAction *
+extern XkbcAction *
 XkbcResizeKeyActions(XkbcDescPtr xkb, int key, int needed);
 
 extern void
index df601f6..cf5103f 100644 (file)
@@ -125,13 +125,13 @@ int
 XkbcAllocServerMap(XkbcDescPtr xkb, unsigned which, unsigned nNewActions)
 {
     int i;
-    XkbServerMapPtr map;
+    XkbcServerMapPtr map;
 
     if (!xkb)
         return BadMatch;
 
     if (!xkb->server) {
-        map = _XkbTypedCalloc(1, XkbServerMapRec);
+        map = _XkbTypedCalloc(1, XkbcServerMapRec);
         if (!map)
             return BadAlloc;
 
@@ -167,7 +167,7 @@ XkbcAllocServerMap(XkbcDescPtr xkb, unsigned which, unsigned nNewActions)
             nNewActions = 1;
 
         if (!map->acts) {
-            map->acts = _XkbTypedCalloc(nNewActions + 1, XkbAction);
+            map->acts = _XkbTypedCalloc(nNewActions + 1, XkbcAction);
             if (!map->acts)
                 return BadAlloc;
             map->num_acts = 1;
@@ -175,10 +175,10 @@ XkbcAllocServerMap(XkbcDescPtr xkb, unsigned which, unsigned nNewActions)
         }
         else if ((map->size_acts - map->num_acts) < nNewActions) {
             unsigned need;
-            XkbAction *prev_acts = map->acts;
+            XkbcAction *prev_acts = map->acts;
 
             need = map->num_acts + nNewActions;
-            map->acts = _XkbTypedRealloc(map->acts, need, XkbAction);
+            map->acts = _XkbTypedRealloc(map->acts, need, XkbcAction);
             if (!map->acts) {
                 _XkbFree(prev_acts);
                 map->num_acts = map->size_acts = 0;
@@ -187,7 +187,7 @@ XkbcAllocServerMap(XkbcDescPtr xkb, unsigned which, unsigned nNewActions)
 
             map->size_acts = need;
             bzero(&map->acts[map->num_acts],
-                  (map->size_acts - map->num_acts) * sizeof(XkbAction));
+                  (map->size_acts - map->num_acts) * sizeof(XkbcAction));
         }
 
         if (!map->key_acts) {
@@ -814,11 +814,11 @@ XkbcChangeKeycodeRange(XkbcDescPtr xkb, int minKC, int maxKC,
     return Success;
 }
 
-XkbAction *
+XkbcAction *
 XkbcResizeKeyActions(XkbcDescPtr xkb, int key, int needed)
 {
     int i, nActs;
-    XkbAction *newActs;
+    XkbcAction *newActs;
 
     if (needed == 0) {
         xkb->server->key_acts[key] = 0;
@@ -829,7 +829,7 @@ XkbcResizeKeyActions(XkbcDescPtr xkb, int key, int needed)
         (XkbKeyNumSyms(xkb, key) >= (unsigned)needed))
         return XkbKeyActionsPtr(xkb, key);
 
-    if (xkb->server->size_acts-xkb->server->num_acts >= (unsigned)needed) {
+    if (xkb->server->size_acts - xkb->server->num_acts >= (unsigned)needed) {
         xkb->server->key_acts[key] = xkb->server->num_acts;
         xkb->server->num_acts += needed;
 
@@ -837,7 +837,7 @@ XkbcResizeKeyActions(XkbcDescPtr xkb, int key, int needed)
     }
 
     xkb->server->size_acts = xkb->server->num_acts + needed + 8;
-    newActs = _XkbTypedCalloc(xkb->server->size_acts, XkbAction);
+    newActs = _XkbTypedCalloc(xkb->server->size_acts, XkbcAction);
     if (!newActs)
         return NULL;
     newActs[0].type = XkbSA_NoAction;
@@ -858,10 +858,10 @@ XkbcResizeKeyActions(XkbcDescPtr xkb, int key, int needed)
 
         if (nCopy > 0)
             memcpy(&newActs[nActs], XkbKeyActionsPtr(xkb, i),
-                   nCopy * sizeof(XkbAction));
+                   nCopy * sizeof(XkbcAction));
         if (nCopy < nKeyActs)
-            bzero(&newActs[nActs+nCopy],
-                  (nKeyActs - nCopy) * sizeof(XkbAction));
+            bzero(&newActs[nActs + nCopy],
+                  (nKeyActs - nCopy) * sizeof(XkbcAction));
 
         xkb->server->key_acts[i] = nActs;
         nActs += nKeyActs;
@@ -940,7 +940,7 @@ XkbcFreeClientMap(XkbcDescPtr xkb, unsigned what, Bool freeMap)
 void
 XkbcFreeServerMap(XkbcDescPtr xkb, unsigned what, Bool freeMap)
 {
-    XkbServerMapPtr map;
+    XkbcServerMapPtr map;
 
     if (!xkb || !xkb->server)
         return;
index f44e5b8..ca9c44e 100644 (file)
@@ -394,11 +394,11 @@ HandleSetLatchMods(XkbcDescPtr xkb,
                    XkbAnyAction * action,
                    unsigned field, ExprDef * array_ndx, ExprDef * value)
 {
-    XkbModAction *act;
+    XkbcModAction *act;
     unsigned rtrn;
     unsigned t1, t2;
 
-    act = (XkbModAction *) action;
+    act = (XkbcModAction *) action;
     if (array_ndx != NULL)
     {
         switch (field)
@@ -426,8 +426,7 @@ HandleSetLatchMods(XkbcDescPtr xkb,
         {
             act->flags = t1;
             act->real_mods = act->mask = (t2 & 0xff);
-            t2 = (t2 >> 8) & 0xffff;
-            XkbSetModActionVMods(act, t2);
+            act->vmods = (t2 >> 8) & 0xffff;
             return True;
         }
         return False;
@@ -440,10 +439,10 @@ HandleLockMods(XkbcDescPtr xkb,
                XkbAnyAction * action,
                unsigned field, ExprDef * array_ndx, ExprDef * value)
 {
-    XkbModAction *act;
+    XkbcModAction *act;
     unsigned t1, t2;
 
-    act = (XkbModAction *) action;
+    act = (XkbcModAction *) action;
     if ((array_ndx != NULL) && (field == F_Modifiers))
         return ReportActionNotArray(action->type, field);
     switch (field)
@@ -454,8 +453,7 @@ HandleLockMods(XkbcDescPtr xkb,
         {
             act->flags = t1;
             act->real_mods = act->mask = (t2 & 0xff);
-            t2 = (t2 >> 8) & 0xffff;
-            XkbSetModActionVMods(act, t2);
+            act->vmods = (t2 >> 8) & 0xffff;
             return True;
         }
         return False;
@@ -588,10 +586,10 @@ HandleMovePtr(XkbcDescPtr xkb,
               unsigned field, ExprDef * array_ndx, ExprDef * value)
 {
     ExprResult rtrn;
-    XkbPtrAction *act;
+    XkbcPtrAction *act;
     Bool absolute;
 
-    act = (XkbPtrAction *) action;
+    act = (XkbcPtrAction *) action;
     if ((array_ndx != NULL) && ((field == F_X) || (field == F_Y)))
         return ReportActionNotArray(action->type, field);
 
@@ -607,13 +605,13 @@ HandleMovePtr(XkbcDescPtr xkb,
         {
             if (absolute)
                 act->flags |= XkbSA_MoveAbsoluteX;
-            XkbSetPtrActionX(act, rtrn.ival);
+            act->x = rtrn.ival;
         }
         else
         {
             if (absolute)
                 act->flags |= XkbSA_MoveAbsoluteY;
-            XkbSetPtrActionY(act, rtrn.ival);
+            act->y = rtrn.ival;
         }
         return True;
     }
@@ -788,11 +786,11 @@ HandleISOLock(XkbcDescPtr xkb,
               unsigned field, ExprDef * array_ndx, ExprDef * value)
 {
     ExprResult rtrn;
-    XkbISOAction *act;
+    XkbcISOAction *act;
     unsigned flags, mods;
     int group;
 
-    act = (XkbISOAction *) action;
+    act = (XkbcISOAction *) action;
     switch (field)
     {
     case F_Modifiers:
@@ -803,8 +801,7 @@ HandleISOLock(XkbcDescPtr xkb,
         {
             act->flags = flags & (~XkbSA_ISODfltIsGroup);
             act->real_mods = mods & 0xff;
-            mods = (mods >> 8) & 0xff;
-            XkbSetModActionVMods(act, mods);
+            act->vmods = (mods >> 8) & 0xff;
             return True;
         }
         return False;
@@ -928,9 +925,9 @@ HandleSetLockControls(XkbcDescPtr xkb,
                       unsigned field, ExprDef * array_ndx, ExprDef * value)
 {
     ExprResult rtrn;
-    XkbCtrlsAction *act;
+    XkbcCtrlsAction *act;
 
-    act = (XkbCtrlsAction *) action;
+    act = (XkbcCtrlsAction *) action;
     if (field == F_Controls)
     {
         if (array_ndx != NULL)
@@ -938,7 +935,7 @@ HandleSetLockControls(XkbcDescPtr xkb,
         if (!ExprResolveMask
             (value, &rtrn, SimpleLookup, (char *) ctrlNames))
             return ReportMismatch(action->type, field, "controls mask");
-        XkbActionSetCtrls(act, rtrn.uval);
+        act->ctrls = rtrn.uval;
         return True;
     }
     return ReportIllegal(action->type, field);
@@ -1038,14 +1035,14 @@ HandleRedirectKey(XkbcDescPtr xkb,
                   unsigned field, ExprDef * array_ndx, ExprDef * value)
 {
     ExprResult rtrn;
-    XkbRedirectKeyAction *act;
-    unsigned t1, t2, vmods, vmask;
+    XkbcRedirectKeyAction *act;
+    unsigned t1, t2;
     unsigned long tmp;
 
     if (array_ndx != NULL)
         return ReportActionNotArray(action->type, field);
 
-    act = (XkbRedirectKeyAction *) action;
+    act = (XkbcRedirectKeyAction *) action;
     switch (field)
     {
     case F_Keycode:
@@ -1071,15 +1068,11 @@ HandleRedirectKey(XkbcDescPtr xkb,
                 act->mods &= ~(t2 & 0xff);
 
             t2 = (t2 >> 8) & 0xffff;
-            vmods = XkbSARedirectVMods(act);
-            vmask = XkbSARedirectVModsMask(act);
-            vmask |= t2;
+            act->vmods_mask |= t2;
             if (field == F_Modifiers)
-                vmods |= t2;
+                act->vmods |= t2;
             else
-                vmods &= ~t2;
-            XkbSARedirectSetVMods(act, vmods);
-            XkbSARedirectSetVModsMask(act, vmask);
+                act->vmods &= ~t2;
             return True;
         }
         return True;
@@ -1276,7 +1269,7 @@ static actionHandler handleAction[XkbSA_NumActions + 1] = {
 /***====================================================================***/
 
 static void
-ApplyActionFactoryDefaults(XkbAction * action)
+ApplyActionFactoryDefaults(XkbcAction * action)
 {
     if (action->type == XkbSA_SetPtrDflt)
     {                           /* increment default button */
@@ -1324,7 +1317,7 @@ HandleActionDef(ExprDef * def,
     action->type = hndlrType = tmp;
     if (action->type != XkbSA_NoAction)
     {
-        ApplyActionFactoryDefaults((XkbAction *) action);
+        ApplyActionFactoryDefaults((XkbcAction *) action);
         while (info)
         {
             if ((info->action == XkbSA_NoAction)
index b067764..49d912a 100644 (file)
@@ -67,7 +67,7 @@ typedef struct _KeyInfo
     unsigned char actsDefined;
     short numLevels[XkbNumKbdGroups];
     KeySym *syms[XkbNumKbdGroups];
-    XkbAction *acts[XkbNumKbdGroups];
+    XkbcAction *acts[XkbNumKbdGroups];
     Atom types[XkbNumKbdGroups];
     unsigned repeat;
     XkbBehavior behavior;
@@ -186,14 +186,14 @@ CopyKeyInfo(KeyInfo * old, KeyInfo * new, Bool clearOld)
             }
             if (old->acts[i] != NULL)
             {
-                new->acts[i] = uTypedCalloc(width, XkbAction);
+                new->acts[i] = uTypedCalloc(width, XkbcAction);
                 if (!new->acts[i])
                 {
                     new->acts[i] = NULL;
                     return False;
                 }
                 memcpy((char *) new->acts[i], (char *) old->acts[i],
-                       width * sizeof(XkbAction));
+                       width * sizeof(XkbcAction));
             }
         }
     }
@@ -320,7 +320,7 @@ ResizeKeyGroup(KeyInfo * key,
     {
         key->acts[group] = uTypedRecalloc(key->acts[group],
                                           key->numLevels[group], newWidth,
-                                          XkbAction);
+                                          XkbcAction);
         if (!key->acts[group])
             return False;
     }
@@ -333,7 +333,7 @@ MergeKeyGroups(SymbolsInfo * info,
                KeyInfo * into, KeyInfo * from, unsigned group)
 {
     KeySym *resultSyms;
-    XkbAction *resultActs;
+    XkbcAction *resultActs;
     int resultWidth;
     register int i;
     Bool report, clobber;
@@ -366,7 +366,7 @@ MergeKeyGroups(SymbolsInfo * info,
     }
     if ((resultActs == NULL) && (into->acts[group] || from->acts[group]))
     {
-        resultActs = uTypedCalloc(resultWidth, XkbAction);
+        resultActs = uTypedCalloc(resultWidth, XkbcAction);
         if (!resultActs)
         {
             WSGO("Could not allocate actions for group merge\n");
@@ -415,7 +415,7 @@ MergeKeyGroups(SymbolsInfo * info,
         }
         if (resultActs != NULL)
         {
-            XkbAction *fromAct, *toAct;
+            XkbcAction *fromAct, *toAct;
             fromAct = (from->acts[group] ? &from->acts[group][i] : NULL);
             toAct = (into->acts[group] ? &into->acts[group][i] : NULL);
             if (((fromAct == NULL) || (fromAct->type == XkbSA_NoAction))
@@ -430,7 +430,7 @@ MergeKeyGroups(SymbolsInfo * info,
             }
             else
             {
-                XkbAction *use, *ignore;
+                XkbcAction *use, *ignore;
                 if (clobber)
                 {
                     use = fromAct;
@@ -1541,7 +1541,7 @@ SetExplicitGroup(SymbolsInfo * info, KeyInfo * key)
             key->syms[i] = (KeySym *) NULL;
             if (key->acts[i] != NULL)
                 uFree(key->acts[i]);
-            key->acts[i] = (XkbAction *) NULL;
+            key->acts[i] = (XkbcAction *) NULL;
             key->types[i] = (Atom) 0;
         }
     }
@@ -1552,7 +1552,7 @@ SetExplicitGroup(SymbolsInfo * info, KeyInfo * key)
     key->syms[group] = key->syms[0];
     key->syms[0] = (KeySym *) NULL;
     key->acts[group] = key->acts[0];
-    key->acts[0] = (XkbAction *) NULL;
+    key->acts[0] = (XkbcAction *) NULL;
     key->types[group] = key->types[0];
     key->types[0] = (Atom) 0;
     return True;
@@ -1849,11 +1849,11 @@ PrepareKeyDef(KeyInfo * key)
         }
         if ((key->actsDefined & 1) && key->acts[0])
         {
-            key->acts[i] = uTypedCalloc(width, XkbAction);
+            key->acts[i] = uTypedCalloc(width, XkbcAction);
             if (key->acts[i] == NULL)
                 continue;
             memcpy((void *) key->acts[i], (void *) key->acts[0],
-                   width * sizeof(XkbAction));
+                   width * sizeof(XkbcAction));
             key->actsDefined |= 1 << i;
         }
         if ((key->symsDefined & 1) && key->syms[0])
@@ -1892,7 +1892,7 @@ PrepareKeyDef(KeyInfo * key)
         if ((key->acts[i] != key->acts[0]) &&
             (key->acts[i] == NULL || key->acts[0] == NULL ||
              memcmp((void *) key->acts[i], (void *) key->acts[0],
-                    sizeof(XkbAction) * key->numLevels[0])))
+                    sizeof(XkbcAction) * key->numLevels[0])))
         {
             identical = False;
             break;
@@ -1908,7 +1908,7 @@ PrepareKeyDef(KeyInfo * key)
             key->syms[i] = (KeySym *) NULL;
             if (key->acts[i] != NULL)
                 uFree(key->acts[i]);
-            key->acts[i] = (XkbAction *) NULL;
+            key->acts[i] = (XkbcAction *) NULL;
             key->types[i] = (Atom) 0;
         }
         key->symsDefined &= 1;
@@ -1931,7 +1931,7 @@ CopySymbolsDef(XkbcDescPtr xkb, KeyInfo *key, int start_from)
     XkbKeyTypePtr type;
     Bool haveActions, autoType, useAlias;
     KeySym *outSyms;
-    XkbAction *outActs;
+    XkbcAction *outActs;
     unsigned types[XkbNumKbdGroups];
 
     useAlias = (start_from == 0);
index bbcad35..3faa46a 100644 (file)
@@ -82,7 +82,7 @@ HandleVModDef(VModDef * stmt, unsigned mergeMode, VModInfo * info)
 {
     register int i, bit, nextFree;
     ExprResult mod;
-    XkbServerMapPtr srv;
+    XkbcServerMapPtr srv;
     XkbNamesPtr names;
     Atom stmtName;