Skip to content

Some tweaks to make build work with GCC on macOS #2112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/lib/common/basic_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@

#pragma once

#ifdef __cpluplus
#include <cstdint>
#endif

//
// make typedefs
Expand Down
5 changes: 5 additions & 0 deletions src/lib/platform/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,9 @@ endif()
if (APPLE)
find_library(COCOA_LIBRARY Cocoa)
target_link_libraries(platform ${COCOA_LIBRARY})
target_compile_options(platform PRIVATE
$<$<COMPILE_LANGUAGE:C>:-fobjc-exceptions>
$<$<COMPILE_LANGUAGE:C>:-xobjective-c>
$<$<COMPILE_LANGUAGE:CXX>:-fobjc-exceptions>
)
endif()
40 changes: 20 additions & 20 deletions src/lib/platform/OSXScreen.mm
Original file line number Diff line number Diff line change
Expand Up @@ -324,14 +324,14 @@
return 0;
}

// choose hotkey id
UInt32 id;
// choose hotkey kid
UInt32 kid;
if (!m_oldHotKeyIDs.empty()) {
id = m_oldHotKeyIDs.back();
kid = m_oldHotKeyIDs.back();
m_oldHotKeyIDs.pop_back();
}
else {
id = m_hotKeys.size() + 1;
kid = m_hotKeys.size() + 1;
}

// if this hot key has modifiers only then we'll handle it specially
Expand All @@ -343,37 +343,37 @@
okay = false;
}
else {
m_modifierHotKeys[mask] = id;
m_modifierHotKeys[mask] = kid;
okay = true;
}
}
else {
EventHotKeyID hkid = { 'SNRG', (UInt32)id };
EventHotKeyID hkid = { 'SNRG', (UInt32)kid };
OSStatus status = RegisterEventHotKey(macKey, macMask, hkid,
GetApplicationEventTarget(), 0,
&ref);
okay = (status == noErr);
m_hotKeyToIDMap[HotKeyItem(macKey, macMask)] = id;
m_hotKeyToIDMap[HotKeyItem(macKey, macMask)] = kid;
}

if (!okay) {
m_oldHotKeyIDs.push_back(id);
m_oldHotKeyIDs.push_back(kid);
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));
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));
return 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 kid;
}

void
OSXScreen::unregisterHotKey(UInt32 id)
OSXScreen::unregisterHotKey(UInt32 kid)
{
// look up hotkey
HotKeyMap::iterator i = m_hotKeys.find(id);
HotKeyMap::iterator i = m_hotKeys.find(kid);
if (i == m_hotKeys.end()) {
return;
}
Expand All @@ -388,25 +388,25 @@
// XXX -- this is inefficient
for (ModifierHotKeyMap::iterator j = m_modifierHotKeys.begin();
j != m_modifierHotKeys.end(); ++j) {
if (j->second == id) {
if (j->second == kid) {
m_modifierHotKeys.erase(j);
okay = true;
break;
}
}
}
if (!okay) {
LOG((CLOG_WARN "failed to unregister hotkey id=%d", id));
LOG((CLOG_WARN "failed to unregister hotkey id=%d", kid));
}
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
m_hotKeyToIDMap.erase(i->second);
m_hotKeys.erase(i);
m_oldHotKeyIDs.push_back(id);
if (m_activeModifierHotKey == id) {
m_oldHotKeyIDs.push_back(kid);
if (m_activeModifierHotKey == kid) {
m_activeModifierHotKey = 0;
m_activeModifierHotKeyMask = 0;
}
Expand Down Expand Up @@ -1445,8 +1445,8 @@
kCFPreferencesCurrentUser,
kCFPreferencesAnyHost);
if (pref != NULL) {
CFTypeID id = CFGetTypeID(pref);
if (id == CFNumberGetTypeID()) {
CFTypeID tid = CFGetTypeID(pref);
if (tid == CFNumberGetTypeID()) {
CFNumberRef value = static_cast<CFNumberRef>(pref);
if (CFNumberGetValue(value, kCFNumberDoubleType, &scaling)) {
if (scaling < 0.0) {
Expand Down
Loading