OSXScreen.mm: do not use reserved id for variables

This commit is contained in:
Sergey Fedorov 2024-12-07 20:21:49 +08:00
parent fe46de9053
commit 8c43a3dd9a
1 changed files with 20 additions and 20 deletions

View File

@ -324,14 +324,14 @@ OSXScreen::registerHotKey(KeyID key, KeyModifierMask mask)
return 0; return 0;
} }
// choose hotkey id // choose hotkey kid
UInt32 id; UInt32 kid;
if (!m_oldHotKeyIDs.empty()) { if (!m_oldHotKeyIDs.empty()) {
id = m_oldHotKeyIDs.back(); kid = m_oldHotKeyIDs.back();
m_oldHotKeyIDs.pop_back(); m_oldHotKeyIDs.pop_back();
} }
else { else {
id = m_hotKeys.size() + 1; kid = m_hotKeys.size() + 1;
} }
// if this hot key has modifiers only then we'll handle it specially // if this hot key has modifiers only then we'll handle it specially
@ -343,37 +343,37 @@ OSXScreen::registerHotKey(KeyID key, KeyModifierMask mask)
okay = false; okay = false;
} }
else { else {
m_modifierHotKeys[mask] = id; m_modifierHotKeys[mask] = kid;
okay = true; okay = true;
} }
} }
else { else {
EventHotKeyID hkid = { 'SNRG', (UInt32)id }; EventHotKeyID hkid = { 'SNRG', (UInt32)kid };
OSStatus status = RegisterEventHotKey(macKey, macMask, hkid, OSStatus status = RegisterEventHotKey(macKey, macMask, hkid,
GetApplicationEventTarget(), 0, GetApplicationEventTarget(), 0,
&ref); &ref);
okay = (status == noErr); okay = (status == noErr);
m_hotKeyToIDMap[HotKeyItem(macKey, macMask)] = id; m_hotKeyToIDMap[HotKeyItem(macKey, macMask)] = kid;
} }
if (!okay) { if (!okay) {
m_oldHotKeyIDs.push_back(id); m_oldHotKeyIDs.push_back(kid);
m_hotKeyToIDMap.erase(HotKeyItem(macKey, macMask)); m_hotKeyToIDMap.erase(HotKeyItem(macKey, macMask));
LOG((CLOG_WARN "failed to register hotkey %s (id=%04x mask=%04x)", barrier::KeyMap::formatKey(key, mask).c_str(), key, mask)); LOG((CLOG_WARN "failed to register hotkey %s (id=%04x mask=%04x)", barrier::KeyMap::formatKey(key, mask).c_str(), key, mask));
return 0; return 0;
} }
m_hotKeys.insert(std::make_pair(id, HotKeyItem(ref, macKey, macMask))); m_hotKeys.insert(std::make_pair(kid, HotKeyItem(ref, macKey, macMask)));
LOG((CLOG_DEBUG "registered hotkey %s (id=%04x mask=%04x) as id=%d", barrier::KeyMap::formatKey(key, mask).c_str(), key, mask, id)); LOG((CLOG_DEBUG "registered hotkey %s (id=%04x mask=%04x) as id=%d", barrier::KeyMap::formatKey(key, mask).c_str(), key, mask, kid));
return id; return kid;
} }
void void
OSXScreen::unregisterHotKey(UInt32 id) OSXScreen::unregisterHotKey(UInt32 kid)
{ {
// look up hotkey // look up hotkey
HotKeyMap::iterator i = m_hotKeys.find(id); HotKeyMap::iterator i = m_hotKeys.find(kid);
if (i == m_hotKeys.end()) { if (i == m_hotKeys.end()) {
return; return;
} }
@ -388,7 +388,7 @@ OSXScreen::unregisterHotKey(UInt32 id)
// XXX -- this is inefficient // XXX -- this is inefficient
for (ModifierHotKeyMap::iterator j = m_modifierHotKeys.begin(); for (ModifierHotKeyMap::iterator j = m_modifierHotKeys.begin();
j != m_modifierHotKeys.end(); ++j) { j != m_modifierHotKeys.end(); ++j) {
if (j->second == id) { if (j->second == kid) {
m_modifierHotKeys.erase(j); m_modifierHotKeys.erase(j);
okay = true; okay = true;
break; break;
@ -396,17 +396,17 @@ OSXScreen::unregisterHotKey(UInt32 id)
} }
} }
if (!okay) { if (!okay) {
LOG((CLOG_WARN "failed to unregister hotkey id=%d", id)); LOG((CLOG_WARN "failed to unregister hotkey id=%d", kid));
} }
else { else {
LOG((CLOG_DEBUG "unregistered hotkey id=%d", id)); LOG((CLOG_DEBUG "unregistered hotkey id=%d", kid));
} }
// discard hot key from map and record old id for reuse // discard hot key from map and record old id for reuse
m_hotKeyToIDMap.erase(i->second); m_hotKeyToIDMap.erase(i->second);
m_hotKeys.erase(i); m_hotKeys.erase(i);
m_oldHotKeyIDs.push_back(id); m_oldHotKeyIDs.push_back(kid);
if (m_activeModifierHotKey == id) { if (m_activeModifierHotKey == kid) {
m_activeModifierHotKey = 0; m_activeModifierHotKey = 0;
m_activeModifierHotKeyMask = 0; m_activeModifierHotKeyMask = 0;
} }
@ -1445,8 +1445,8 @@ OSXScreen::getScrollSpeed() const
kCFPreferencesCurrentUser, kCFPreferencesCurrentUser,
kCFPreferencesAnyHost); kCFPreferencesAnyHost);
if (pref != NULL) { if (pref != NULL) {
CFTypeID id = CFGetTypeID(pref); CFTypeID tid = CFGetTypeID(pref);
if (id == CFNumberGetTypeID()) { if (tid == CFNumberGetTypeID()) {
CFNumberRef value = static_cast<CFNumberRef>(pref); CFNumberRef value = static_cast<CFNumberRef>(pref);
if (CFNumberGetValue(value, kCFNumberDoubleType, &scaling)) { if (CFNumberGetValue(value, kCFNumberDoubleType, &scaling)) {
if (scaling < 0.0) { if (scaling < 0.0) {