Ejemplo n.º 1
0
bool
CKeyMap::keysToRestoreModifiers(const KeyItem& keyItem, SInt32,
				ModifierToKeys& activeModifiers,
				KeyModifierMask& currentState,
				const ModifierToKeys& desiredModifiers,
				Keystrokes& keystrokes) const
{
	// XXX -- we're not considering modified modifiers here

	ModifierToKeys oldModifiers = activeModifiers;

	// get the pressed modifier buttons before and after
	ButtonToKeyMap oldKeys, newKeys;
	collectButtons(oldModifiers, oldKeys);
	collectButtons(desiredModifiers, newKeys);

	// release unwanted keys
	for (ModifierToKeys::const_iterator i = oldModifiers.begin();
								i != oldModifiers.end(); ++i) {
		KeyButton button = i->second.m_button;
		if (button != keyItem.m_button && newKeys.count(button) == 0) {
			EKeystroke type = kKeystrokeRelease;
			if (i->second.m_lock) {
				type = kKeystrokeUnmodify;
			}
			addKeystrokes(type, i->second,
								activeModifiers, currentState, keystrokes);
		}
	}

	// press wanted keys
	for (ModifierToKeys::const_iterator i = desiredModifiers.begin();
								i != desiredModifiers.end(); ++i) {
		KeyButton button = i->second.m_button;
		if (button != keyItem.m_button && oldKeys.count(button) == 0) {
			EKeystroke type = kKeystrokePress;
			if (i->second.m_lock) {
				type = kKeystrokeModify;
			}
			addKeystrokes(type, i->second,
								activeModifiers, currentState, keystrokes);
		}
	}

	return true;
}
Ejemplo n.º 2
0
void
CKeyMap::collectButtons(const ModifierToKeys& mods, ButtonToKeyMap& keys)
{
	keys.clear();
	for (ModifierToKeys::const_iterator i = mods.begin();
								i != mods.end(); ++i) {
		keys.insert(std::make_pair(i->second.m_button, &i->second));
	}
}
Ejemplo n.º 3
0
void
CKeyState::updateModifierKeyState(KeyButton button,
				const ModifierToKeys& oldModifiers,
				const ModifierToKeys& newModifiers)
{
	// get the pressed modifier buttons before and after
	CKeyMap::ButtonToKeyMap oldKeys, newKeys;
	for (ModifierToKeys::const_iterator i = oldModifiers.begin();
								i != oldModifiers.end(); ++i) {
		oldKeys.insert(std::make_pair(i->second.m_button, &i->second));
	}
	for (ModifierToKeys::const_iterator i = newModifiers.begin();
								i != newModifiers.end(); ++i) {
		newKeys.insert(std::make_pair(i->second.m_button, &i->second));
	}

	// get the modifier buttons that were pressed or released
	CKeyMap::ButtonToKeyMap pressed, released;
	std::set_difference(oldKeys.begin(), oldKeys.end(),
						newKeys.begin(), newKeys.end(),
						std::inserter(released, released.end()),
						ButtonToKeyLess());
	std::set_difference(newKeys.begin(), newKeys.end(),
						oldKeys.begin(), oldKeys.end(),
						std::inserter(pressed, pressed.end()),
						ButtonToKeyLess());

	// update state
	for (CKeyMap::ButtonToKeyMap::const_iterator i = released.begin();
								i != released.end(); ++i) {
		if (i->first != button) {
			m_keys[i->first]          = 0;
			m_syntheticKeys[i->first] = 0;
		}
	}
	for (CKeyMap::ButtonToKeyMap::const_iterator i = pressed.begin();
								i != pressed.end(); ++i) {
		if (i->first != button) {
			m_keys[i->first]          = 1;
			m_syntheticKeys[i->first] = 1;
			m_keyClientData[i->first] = i->second->m_client;
		}
	}
}