コード例 #1
0
ファイル: option.cpp プロジェクト: CannedFish/deepin-compiz
TEST (CompOption, AssignDefaultActionValueToUnsetTypeClearsOldStateKeepsInfo)
{
    /* Value is unset at this point */
    CompOption        option ("testing", CompOption::TypeKey);
    CompAction        action;

    /* We need to set up the state here as
     * the CompOption::Value constructor makes
     * a copy of the action */
    action.setState (CompAction::StateInitKey);
    action.setButton (CompAction::ButtonBinding (1,
						 1 << 1));

    CompOption::Value value (action);

    ASSERT_EQ (value.action ().state (), CompAction::StateInitKey);

    /* Actually set the action value, this will
     * overwrite the internal value */
    option.set (value);

    /* We don't care about the old action's state, so get
     * rid of it */
    ASSERT_EQ (option.value ().action ().state (), 0);

    /* We do want to keep the non-stateful data which is
     * pure info */
    ASSERT_EQ (option.value ().action ().button ().button (), 1);
    ASSERT_EQ (option.value ().action ().button ().modifiers (), 1 << 1);
}
コード例 #2
0
ファイル: option.cpp プロジェクト: squarehimself/XMoniz
static void
finiOptionValue (CompOption::Value &v,
		 CompOption::Type  type)
{
    switch (type) {
	case CompOption::TypeAction:
	case CompOption::TypeKey:
	case CompOption::TypeButton:
	case CompOption::TypeEdge:
	case CompOption::TypeBell:
	    if (v.action ().state () & CompAction::StateAutoGrab && screen)
		screen->removeAction (&v.action ());
	    break;

	case CompOption::TypeList:
	    foreach (CompOption::Value &val, v.list ())
		finiOptionValue (val, v.listType ());
	    break;

	default:
	    break;
    }
}
コード例 #3
0
ファイル: option.cpp プロジェクト: squarehimself/XMoniz
bool
CompOption::set (CompOption::Value &val)
{
    if (isAction () && priv->type != CompOption::TypeAction)
	val.action ().copyState (priv->value.action ());

    if (priv->type != val.type () &&
	(!isAction () || !checkIsAction (val.type ())))
    {
	compLogMessage ("core", CompLogLevelWarn,
			"Can't set Value with type %d to "
			"option \"%s\" with type %d",
			val.type (), priv->name.c_str (), priv->type);
	return false;
    }

    if (priv->value == val)
	return false;

    if (isAction () &&
        priv->value.action ().state () & CompAction::StateAutoGrab && screen)
    {
	if (!screen->addAction (&val.action ()))
	    return false;
	else
	    screen->removeAction (&priv->value.action ());
    }

    switch (priv->type)
    {
	case CompOption::TypeInt:
	    if (!priv->rest.inRange (val.i ()))
		return false;
	    break;

	case CompOption::TypeFloat:
	{
	    float v, p;
	    int sign = (val.f () < 0 ? -1 : 1);

	    if (!priv->rest.inRange (val.f ()))
		return false;

	    p = 1.0f / priv->rest.fPrecision ();
	    v = ((int) (val.f () * p + sign * 0.5f)) / p;

	    priv->value.set (v);
	    return true;
	}

	case CompOption::TypeAction:
	    return false;

	case CompOption::TypeKey:
	    if (val.action ().type () == value().action ().type () && 
		!(val.action ().type () & CompAction::BindingTypeKey))
		return false;
	    break;

	case CompOption::TypeButton:
	    if (val.action ().type () == value().action ().type () && 
		!(val.action ().type () & (CompAction::BindingTypeButton |
					   CompAction::BindingTypeEdgeButton)))
		return false;
	    break;

	default:
	    break;
    }

    priv->value = val;

    return true;
}