action: s/hndlrType/handler_type
[platform/upstream/libxkbcommon.git] / src / xkbcomp / action.c
index 1ef9498..22762c6 100644 (file)
  *
  ********************************************************/
 
+/*
+ * Copyright © 2012 Intel Corporation
+ * Copyright © 2012 Ran Benita <ran234@gmail.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Author: Daniel Stone <daniel@fooishbar.org>
+ *         Ran Benita <ran234@gmail.com>
+ */
+
 #include "xkbcomp-priv.h"
 #include "text.h"
 #include "expr.h"
@@ -80,14 +107,12 @@ NewActionsInfo(void)
     if (!info)
         return NULL;
 
-    /* This includes PrivateAction. */
-    for (type = 0; type < ACTION_TYPE_LAST; type++)
+    for (type = 0; type < _ACTION_TYPE_NUM_ENTRIES; type++)
         info->actions[type].type = type;
 
     /* Apply some "factory defaults". */
 
     /* Increment default button. */
-    info->actions[ACTION_TYPE_PTR_DEFAULT].dflt.affect = XkbSA_AffectDfltBtn;
     info->actions[ACTION_TYPE_PTR_DEFAULT].dflt.flags = 0;
     info->actions[ACTION_TYPE_PTR_DEFAULT].dflt.value = 1;
 
@@ -213,15 +238,15 @@ HandleNoAction(struct xkb_keymap *keymap, union xkb_action *action,
 static bool
 CheckLatchLockFlags(struct xkb_keymap *keymap, enum xkb_action_type action,
                     enum action_field field, const ExprDef * value,
-                    unsigned *flags_inout)
+                    enum xkb_action_flags *flags_inout)
 {
-    unsigned tmp;
+    enum xkb_action_flags tmp;
     bool result;
 
     if (field == ACTION_FIELD_CLEAR_LOCKS)
-        tmp = XkbSA_ClearLocks;
+        tmp = ACTION_LOCK_CLEAR;
     else if (field == ACTION_FIELD_LATCH_TO_LOCK)
-        tmp = XkbSA_LatchToLock;
+        tmp = ACTION_LATCH_TO_LOCK;
     else
         return false;           /* WSGO! */
 
@@ -238,7 +263,7 @@ CheckLatchLockFlags(struct xkb_keymap *keymap, enum xkb_action_type action,
 
 static bool
 CheckModifierField(struct xkb_keymap *keymap, enum xkb_action_type action,
-                   const ExprDef *value, unsigned *flags_inout,
+                   const ExprDef *value, enum xkb_action_flags *flags_inout,
                    xkb_mod_mask_t *mods_rtrn)
 {
     if (value->op == EXPR_IDENT) {
@@ -248,16 +273,16 @@ CheckModifierField(struct xkb_keymap *keymap, enum xkb_action_type action,
                        istreq(valStr, "modmapmods"))) {
 
             *mods_rtrn = 0;
-            *flags_inout |= XkbSA_UseModMapMods;
+            *flags_inout |= ACTION_MODS_LOOKUP_MODMAP;
             return true;
         }
     }
 
-    if (!ExprResolveVModMask(keymap, value, mods_rtrn))
+    if (!ExprResolveModMask(keymap, value, MOD_BOTH, mods_rtrn))
         return ReportMismatch(keymap, action,
                               ACTION_FIELD_MODIFIERS, "modifier mask");
 
-    *flags_inout &= ~XkbSA_UseModMapMods;
+    *flags_inout &= ~ACTION_MODS_LOOKUP_MODMAP;
     return true;
 }
 
@@ -267,8 +292,7 @@ HandleSetLatchMods(struct xkb_keymap *keymap, union xkb_action *action,
                    const ExprDef *value)
 {
     struct xkb_mod_action *act = &action->mods;
-    unsigned rtrn;
-    unsigned t1;
+    enum xkb_action_flags rtrn, t1;
     xkb_mod_mask_t t2;
 
     if (array_ndx != NULL) {
@@ -314,7 +338,7 @@ HandleLockMods(struct xkb_keymap *keymap, union xkb_action *action,
                const ExprDef *value)
 {
     struct xkb_mod_action *act = &action->mods;
-    unsigned t1;
+    enum xkb_action_flags t1;
     xkb_mod_mask_t t2;
 
     if (array_ndx && field == ACTION_FIELD_MODIFIERS)
@@ -339,17 +363,17 @@ HandleLockMods(struct xkb_keymap *keymap, union xkb_action *action,
 
 static bool
 CheckGroupField(struct xkb_keymap *keymap, unsigned action,
-                const ExprDef *value, unsigned *flags_inout,
-                xkb_group_index_t *grp_rtrn)
+                const ExprDef *value, enum xkb_action_flags *flags_inout,
+                xkb_layout_index_t *grp_rtrn)
 {
     const ExprDef *spec;
 
     if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) {
-        *flags_inout &= ~XkbSA_GroupAbsolute;
+        *flags_inout &= ~ACTION_ABSOLUTE_SWITCH;
         spec = value->value.child;
     }
     else {
-        *flags_inout |= XkbSA_GroupAbsolute;
+        *flags_inout |= ACTION_ABSOLUTE_SWITCH;
         spec = value;
     }
 
@@ -371,9 +395,8 @@ HandleSetLatchGroup(struct xkb_keymap *keymap, union xkb_action *action,
                     const ExprDef *value)
 {
     struct xkb_group_action *act = &action->group;
-    unsigned rtrn;
-    unsigned t1;
-    xkb_group_index_t t2;
+    enum xkb_action_flags rtrn, t1;
+    xkb_layout_index_t t2;
 
     if (array_ndx != NULL) {
         switch (field) {
@@ -419,8 +442,8 @@ HandleLockGroup(struct xkb_keymap *keymap, union xkb_action *action,
                 const ExprDef *value)
 {
     struct xkb_group_action *act = &action->group;
-    unsigned t1;
-    xkb_group_index_t t2;
+    enum xkb_action_flags t1;
+    xkb_layout_index_t t2;
 
     if ((array_ndx != NULL) && (field == ACTION_FIELD_GROUP))
         return ReportActionNotArray(keymap, action->type, field);
@@ -460,12 +483,12 @@ HandleMovePtr(struct xkb_keymap *keymap, union xkb_action *action,
 
         if (field == ACTION_FIELD_X) {
             if (absolute)
-                act->flags |= XkbSA_MoveAbsoluteX;
+                act->flags |= ACTION_ABSOLUTE_X;
             act->x = val;
         }
         else {
             if (absolute)
-                act->flags |= XkbSA_MoveAbsoluteY;
+                act->flags |= ACTION_ABSOLUTE_Y;
             act->y = val;
         }
 
@@ -478,9 +501,9 @@ HandleMovePtr(struct xkb_keymap *keymap, union xkb_action *action,
             return ReportMismatch(keymap, action->type, field, "boolean");
 
         if (set)
-            act->flags &= ~XkbSA_NoAcceleration;
+            act->flags &= ~ACTION_NO_ACCEL;
         else
-            act->flags |= XkbSA_NoAcceleration;
+            act->flags |= ACTION_NO_ACCEL;
     }
 
     return ReportIllegal(keymap, action->type, field);
@@ -488,9 +511,9 @@ HandleMovePtr(struct xkb_keymap *keymap, union xkb_action *action,
 
 static const LookupEntry lockWhich[] = {
     { "both", 0 },
-    { "lock", XkbSA_LockNoUnlock },
-    { "neither", (XkbSA_LockNoLock | XkbSA_LockNoUnlock) },
-    { "unlock", XkbSA_LockNoLock },
+    { "lock", ACTION_LOCK_NO_UNLOCK },
+    { "neither", (ACTION_LOCK_NO_LOCK | ACTION_LOCK_NO_UNLOCK) },
+    { "unlock", ACTION_LOCK_NO_LOCK },
     { NULL, 0 }
 };
 
@@ -523,7 +546,7 @@ HandlePtrBtn(struct xkb_keymap *keymap, union xkb_action *action,
     }
     else if (action->type == ACTION_TYPE_PTR_LOCK &&
              field == ACTION_FIELD_AFFECT) {
-        unsigned int val;
+        enum xkb_action_flags val;
 
         if (array_ndx)
             return ReportActionNotArray(keymap, action->type, field);
@@ -532,7 +555,7 @@ HandlePtrBtn(struct xkb_keymap *keymap, union xkb_action *action,
             return ReportMismatch(keymap, action->type, field,
                                   "lock or unlock");
 
-        act->flags &= ~(XkbSA_LockNoLock | XkbSA_LockNoUnlock);
+        act->flags &= ~(ACTION_LOCK_NO_LOCK | ACTION_LOCK_NO_UNLOCK);
         act->flags |= val;
         return true;
     }
@@ -560,9 +583,9 @@ HandlePtrBtn(struct xkb_keymap *keymap, union xkb_action *action,
 }
 
 static const LookupEntry ptrDflts[] = {
-    { "dfltbtn", XkbSA_AffectDfltBtn },
-    { "defaultbutton", XkbSA_AffectDfltBtn },
-    { "button", XkbSA_AffectDfltBtn },
+    { "dfltbtn", 1 },
+    { "defaultbutton", 1 },
+    { "button", 1 },
     { NULL, 0 }
 };
 
@@ -582,7 +605,6 @@ HandleSetPtrDflt(struct xkb_keymap *keymap, union xkb_action *action,
         if (!ExprResolveEnum(keymap->ctx, value, &val, ptrDflts))
             return ReportMismatch(keymap, action->type, field,
                                   "pointer component");
-        act->affect = val;
         return true;
     }
     else if (field == ACTION_FIELD_BUTTON || field == ACTION_FIELD_VALUE) {
@@ -593,11 +615,11 @@ HandleSetPtrDflt(struct xkb_keymap *keymap, union xkb_action *action,
             return ReportActionNotArray(keymap, action->type, field);
 
         if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) {
-            act->flags &= ~XkbSA_DfltBtnAbsolute;
+            act->flags &= ~ACTION_ABSOLUTE_SWITCH;
             button = value->value.child;
         }
         else {
-            act->flags |= XkbSA_DfltBtnAbsolute;
+            act->flags |= ACTION_ABSOLUTE_SWITCH;
             button = value;
         }
 
@@ -640,11 +662,11 @@ HandleSwitchScreen(struct xkb_keymap *keymap, union xkb_action *action,
             return ReportActionNotArray(keymap, action->type, field);
 
         if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) {
-            act->flags &= ~XkbSA_SwitchAbsolute;
+            act->flags &= ~ACTION_ABSOLUTE_SWITCH;
             scrn = value->value.child;
         }
         else {
-            act->flags |= XkbSA_SwitchAbsolute;
+            act->flags |= ACTION_ABSOLUTE_SWITCH;
             scrn = value;
         }
 
@@ -672,9 +694,9 @@ HandleSwitchScreen(struct xkb_keymap *keymap, union xkb_action *action,
             return ReportMismatch(keymap, action->type, field, "boolean");
 
         if (set)
-            act->flags &= ~XkbSA_SwitchApplication;
+            act->flags &= ~ACTION_SAME_SCREEN;
         else
-            act->flags |= XkbSA_SwitchApplication;
+            act->flags |= ACTION_SAME_SCREEN;
 
         return true;
     }
@@ -726,7 +748,26 @@ HandlePrivate(struct xkb_keymap *keymap, union xkb_action *action,
             return false;
         }
 
-        act->type = (uint8_t) type;
+        /*
+         * It's possible for someone to write something like this:
+         *      actions = [ Private(type=3,data[0]=1,data[1]=3,data[2]=3) ]
+         * where the type refers to some existing action type, e.g. LockMods.
+         * This assumes that this action's struct is layed out in memory
+         * exactly as described in the XKB specification and libraries.
+         * We, however, have changed these structs in various ways, so this
+         * assumption is no longer true. Since this is a lousy "feature", we
+         * make actions like these no-ops for now.
+         */
+        if (type < ACTION_TYPE_PRIVATE) {
+            log_info(keymap->ctx,
+                     "Private actions of type %s are not supported; Ignored\n",
+                     ActionTypeText(type));
+            act->type = ACTION_TYPE_NONE;
+        }
+        else {
+            act->type = (enum xkb_action_type) type;
+        }
+
         return true;
     }
     else if (field == ACTION_FIELD_DATA) {
@@ -762,9 +803,9 @@ HandlePrivate(struct xkb_keymap *keymap, union xkb_action *action,
 
             if (ndx < 0 || ndx >= sizeof(act->data)) {
                 log_err(keymap->ctx,
-                        "The data for a private action is %zu bytes long; "
+                        "The data for a private action is %lu bytes long; "
                         "Attempt to use data[%d] ignored\n",
-                        sizeof(act->data), ndx);
+                        (unsigned long) sizeof(act->data), ndx);
                 return false;
             }
 
@@ -792,7 +833,7 @@ typedef bool (*actionHandler)(struct xkb_keymap *keymap,
                               const ExprDef *array_ndx,
                               const ExprDef *value);
 
-static const actionHandler handleAction[ACTION_TYPE_LAST] = {
+static const actionHandler handleAction[_ACTION_TYPE_NUM_ENTRIES] = {
     [ACTION_TYPE_NONE] = HandleNoAction,
     [ACTION_TYPE_MOD_SET] = HandleSetLatchMods,
     [ACTION_TYPE_MOD_LATCH] = HandleSetLatchMods,
@@ -819,7 +860,7 @@ HandleActionDef(ExprDef *def, struct xkb_keymap *keymap,
 {
     ExprDef *arg;
     const char *str;
-    unsigned hndlrType;
+    unsigned handler_type;
 
     if (def->op != EXPR_ACTION_DECL) {
         log_err(keymap->ctx, "Expected an action definition, found %s\n",
@@ -828,7 +869,7 @@ HandleActionDef(ExprDef *def, struct xkb_keymap *keymap,
     }
 
     str = xkb_atom_text(keymap->ctx, def->value.action.name);
-    if (!stringToAction(str, &hndlrType)) {
+    if (!stringToAction(str, &handler_type)) {
         log_err(keymap->ctx, "Unknown action %s\n", str);
         return false;
     }
@@ -838,7 +879,7 @@ HandleActionDef(ExprDef *def, struct xkb_keymap *keymap,
      * statements such as:
      *     latchMods.clearLocks = True;
      */
-    *action = info->actions[hndlrType];
+    *action = info->actions[handler_type];
 
     /*
      * Now change the action properties as specified for this
@@ -882,8 +923,8 @@ HandleActionDef(ExprDef *def, struct xkb_keymap *keymap,
             return false;
         }
 
-        if (!handleAction[hndlrType](keymap, action, fieldNdx, arrayRtrn,
-                                     value))
+        if (!handleAction[handler_type](keymap, action, fieldNdx, arrayRtrn,
+                                        value))
             return false;
     }