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); }
unsigned int GnomeGrabber::Impl::grabAccelerator(char const* accelerator, unsigned int flags) { CompAction action; action.keyFromString(accelerator); if (action.key().toString().empty()) { CompString prefixed = "XF86" + CompString(accelerator); LOG_DEBUG(logger) << "Can't grab \"" << accelerator << "\", trying \"" << prefixed << "\""; action.keyFromString(prefixed); } else { LOG_DEBUG(logger) << "grabAccelerator \"" << accelerator << "\""; } if (!isActionPostponed(action)) { action.setState(CompAction::StateInitKey); action.setInitiate([this](CompAction* action, CompAction::State state, CompOption::Vector& options) { LOG_DEBUG(logger) << "pressed \"" << action->keyToString() << "\""; activateAction(action, 0); return true; }); } else { action.setState(CompAction::StateInitKey | CompAction::StateTermKey); action.setTerminate([this](CompAction* action, CompAction::State state, CompOption::Vector& options) { auto key = action->keyToString(); LOG_DEBUG(logger) << "released \"" << key << "\""; if (state & CompAction::StateTermTapped) { LOG_DEBUG(logger) << "tapped \"" << key << "\""; activateAction(action, 0); return true; } return false; }); } return addAction(action, false); }