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); }
bool GnomeGrabber::Impl::isActionPostponed(CompAction const& action) const { int keycode = action.key().keycode(); return keycode == 0 || modHandler->keycodeToModifiers(keycode) != 0; }