action: add a common CheckBooleanFlag function
[platform/upstream/libxkbcommon.git] / src / xkbcomp / action.c
index ad7f43f..dbb57a9 100644 (file)
@@ -118,6 +118,7 @@ NewActionsInfo(void)
     /* Increment default button. */
     info->actions[ACTION_TYPE_PTR_DEFAULT].dflt.flags = 0;
     info->actions[ACTION_TYPE_PTR_DEFAULT].dflt.value = 1;
+    info->actions[ACTION_TYPE_PTR_MOVE].ptr.flags = ACTION_ACCEL;
     info->actions[ACTION_TYPE_SWITCH_VT].screen.flags = ACTION_SAME_SCREEN;
 
     return info;
@@ -229,30 +230,23 @@ HandleNoAction(struct xkb_keymap *keymap, union xkb_action *action,
 }
 
 static bool
-CheckLatchLockFlags(struct xkb_context *ctx, enum xkb_action_type action,
-                    enum action_field field, const ExprDef *array_ndx,
-                    const ExprDef *value, enum xkb_action_flags *flags_inout)
+CheckBooleanFlag(struct xkb_context *ctx, enum xkb_action_type action,
+                 enum action_field field, enum xkb_action_flags flag,
+                 const ExprDef *array_ndx, const ExprDef *value,
+                 enum xkb_action_flags *flags_inout)
 {
-    enum xkb_action_flags tmp;
-    bool result;
+    bool set;
 
     if (array_ndx)
         return ReportActionNotArray(ctx, action, field);
 
-    if (field == ACTION_FIELD_CLEAR_LOCKS)
-        tmp = ACTION_LOCK_CLEAR;
-    else if (field == ACTION_FIELD_LATCH_TO_LOCK)
-        tmp = ACTION_LATCH_TO_LOCK;
-    else
-        return false;           /* WSGO! */
-
-    if (!ExprResolveBoolean(ctx, value, &result))
+    if (!ExprResolveBoolean(ctx, value, &set))
         return ReportMismatch(ctx, action, field, "boolean");
 
-    if (result)
-        *flags_inout |= tmp;
+    if (set)
+        *flags_inout |= flag;
     else
-        *flags_inout &= ~tmp;
+        *flags_inout &= ~flag;
 
     return true;
 }
@@ -291,11 +285,15 @@ HandleSetLatchMods(struct xkb_keymap *keymap, union xkb_action *action,
 {
     struct xkb_mod_action *act = &action->mods;
 
-    if (field == ACTION_FIELD_CLEAR_LOCKS ||
-        field == ACTION_FIELD_LATCH_TO_LOCK)
-        return CheckLatchLockFlags(keymap->ctx, action->type, field, array_ndx,
-                                   value, &act->flags);
-    else if (field == ACTION_FIELD_MODIFIERS)
+    if (field == ACTION_FIELD_CLEAR_LOCKS)
+        return CheckBooleanFlag(keymap->ctx, action->type, field,
+                                ACTION_LOCK_CLEAR, array_ndx, value,
+                                &act->flags);
+    if (field == ACTION_FIELD_LATCH_TO_LOCK)
+        return CheckBooleanFlag(keymap->ctx, action->type, field,
+                                ACTION_LATCH_TO_LOCK, array_ndx, value,
+                                &act->flags);
+    if (field == ACTION_FIELD_MODIFIERS)
         return CheckModifierField(keymap, action->type, array_ndx, value,
                                   &act->flags, &act->mods.mods);
 
@@ -391,11 +389,15 @@ HandleSetLatchGroup(struct xkb_keymap *keymap, union xkb_action *action,
 {
     struct xkb_group_action *act = &action->group;
 
-    if (field == ACTION_FIELD_CLEAR_LOCKS ||
-        field == ACTION_FIELD_LATCH_TO_LOCK)
-        return CheckLatchLockFlags(keymap->ctx, action->type, field, array_ndx,
-                                   value, &act->flags);
-    else if (field == ACTION_FIELD_GROUP)
+    if (field == ACTION_FIELD_CLEAR_LOCKS)
+        return CheckBooleanFlag(keymap->ctx, action->type, field,
+                                ACTION_LOCK_CLEAR, array_ndx, value,
+                                &act->flags);
+    if (field == ACTION_FIELD_LATCH_TO_LOCK)
+        return CheckBooleanFlag(keymap->ctx, action->type, field,
+                                ACTION_LATCH_TO_LOCK, array_ndx, value,
+                                &act->flags);
+    if (field == ACTION_FIELD_GROUP)
         return CheckGroupField(keymap->ctx, action->type, array_ndx, value,
                                &act->flags, &act->group);
 
@@ -457,18 +459,8 @@ HandleMovePtr(struct xkb_keymap *keymap, union xkb_action *action,
         return true;
     }
     else if (field == ACTION_FIELD_ACCEL) {
-        bool set;
-
-        if (array_ndx)
-            return ReportActionNotArray(keymap->ctx, action->type, field);
-
-        if (!ExprResolveBoolean(keymap->ctx, value, &set))
-            return ReportMismatch(keymap->ctx, action->type, field, "boolean");
-
-        if (set)
-            act->flags &= ~ACTION_NO_ACCEL;
-        else
-            act->flags |= ACTION_NO_ACCEL;
+        return CheckBooleanFlag(keymap->ctx, action->type, field,
+                                ACTION_ACCEL, array_ndx, value, &act->flags);
     }
 
     return ReportIllegal(keymap->ctx, action->type, field);
@@ -634,20 +626,9 @@ HandleSwitchScreen(struct xkb_keymap *keymap, union xkb_action *action,
         return true;
     }
     else if (field == ACTION_FIELD_SAME) {
-        bool set;
-
-        if (array_ndx)
-            return ReportActionNotArray(keymap->ctx, action->type, field);
-
-        if (!ExprResolveBoolean(keymap->ctx, value, &set))
-            return ReportMismatch(keymap->ctx, action->type, field, "boolean");
-
-        if (set)
-            act->flags |= ACTION_SAME_SCREEN;
-        else
-            act->flags &= ~ACTION_SAME_SCREEN;
-
-        return true;
+        return CheckBooleanFlag(keymap->ctx, action->type, field,
+                                ACTION_SAME_SCREEN, array_ndx, value,
+                                &act->flags);
     }
 
     return ReportIllegal(keymap->ctx, action->type, field);