From 1805dd7900067d8fd9e39ba1ba05d355e5396afa Mon Sep 17 00:00:00 2001 From: jerry Date: Mon, 15 Sep 2014 13:04:43 +0000 Subject: [PATCH] issue #575 - Cannot build x86_64 or ppc64 on Mac OS X applied patch by Jake Petroules --- CMakeLists.txt | 10 ++--- ext/toolchain/commands1.py | 20 ++++++++- src/lib/common/basic_types.h | 4 ++ src/lib/platform/OSXScreen.cpp | 65 +++++++++++++++++------------ src/lib/platform/OSXScreenSaver.cpp | 6 +-- src/lib/synergy/DaemonApp.cpp | 4 +- 6 files changed, 71 insertions(+), 38 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4dca34f3..d2959b40 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -164,14 +164,14 @@ if (UNIX) exec_program(uname ARGS -v OUTPUT_VARIABLE DARWIN_VERSION) string(REGEX MATCH "[0-9]+" DARWIN_VERSION ${DARWIN_VERSION}) message(STATUS "DARWIN_VERSION=${DARWIN_VERSION}") + # patch by Jake Petroules for issue 575 if (DARWIN_VERSION LESS 9) - # 10.4: universal (32-bit intel and power pc) - set(CMAKE_OSX_ARCHITECTURES "ppc;i386" + # 10.4: Universal (32-bit and 64-bit Intel and PowerPC) + set(CMAKE_OSX_ARCHITECTURES "ppc;ppc64;i386:x86_64" CACHE STRING "" FORCE) else() - # 10.5+: 32-bit only -- missing funcs in 64-bit os libs - # such as GetGlobalMouse. - set(CMAKE_OSX_ARCHITECTURES "i386" + # 10.5+: Intel only + set(CMAKE_OSX_ARCHITECTURES "i386;x86_64" CACHE STRING "" FORCE) endif() diff --git a/ext/toolchain/commands1.py b/ext/toolchain/commands1.py index ef492f2b..53ab4f67 100644 --- a/ext/toolchain/commands1.py +++ b/ext/toolchain/commands1.py @@ -554,7 +554,25 @@ class InternalCommands: return (major, minor, rev) def getMacSdkDir(self): - return "/Developer/SDKs/MacOSX" + self.macSdk + ".sdk" + # patch by Jake Petroules for issue 575 + sdkName = "macosx" + self.macSdk + + # Ideally we'll use xcrun (which is influenced by $DEVELOPER_DIR), then try a couple + # fallbacks to known paths if xcrun is not available + sdkPath = commands.getoutput("xcrun --show-sdk-path --sdk " + sdkName) + if sdkPath: + return sdkPath + + developerDir = os.getenv("DEVELOPER_DIR") + if not developerDir: + developerDir = "/Applications/Xcode.app/Contents/Developer" + + sdkDirName = sdkName.replace("macosx", "MacOSX") + sdkPath = developerDir + "/Platforms/MacOSX.platform/Developer/SDKs/" + sdkDirName + ".sdk" + if os.path.exists(sdkPath): + return sdkPath + + return "/Developer/SDKs/" + sdkDirName + ".sdk" # http://tinyurl.com/cs2rxxb def fixCmakeEclipseBug(self): diff --git a/src/lib/common/basic_types.h b/src/lib/common/basic_types.h index 7f20cb5a..0d4c68a6 100644 --- a/src/lib/common/basic_types.h +++ b/src/lib/common/basic_types.h @@ -72,6 +72,9 @@ // Added this because it doesn't compile on OS X 10.6 because they are already defined in Carbon #if !defined(__MACTYPES__) +#if defined(__APPLE__) +#include +#else typedef signed TYPE_OF_SIZE_1 SInt8; typedef signed TYPE_OF_SIZE_2 SInt16; typedef signed TYPE_OF_SIZE_4 SInt32; @@ -79,6 +82,7 @@ typedef unsigned TYPE_OF_SIZE_1 UInt8; typedef unsigned TYPE_OF_SIZE_2 UInt16; typedef unsigned TYPE_OF_SIZE_4 UInt32; #endif +#endif // // clean up // diff --git a/src/lib/platform/OSXScreen.cpp b/src/lib/platform/OSXScreen.cpp index cf58aaa2..f628ce11 100644 --- a/src/lib/platform/OSXScreen.cpp +++ b/src/lib/platform/OSXScreen.cpp @@ -292,13 +292,15 @@ COSXScreen::getShape(SInt32& x, SInt32& y, SInt32& w, SInt32& h) const void COSXScreen::getCursorPos(SInt32& x, SInt32& y) const { - Point mouse; - GetGlobalMouse(&mouse); - x = mouse.h; - y = mouse.v; + // patch by Jake Petroules for issue 575 + CGEventRef event = CGEventCreate(NULL); + CGPoint mouse = CGEventGetLocation(event); + x = mouse.x; + y = mouse.y; m_cursorPosValid = true; - m_xCursor = x; - m_yCursor = y; + m_xCursor = x; + m_yCursor = y; + CFRelease(event); } void @@ -690,21 +692,24 @@ COSXScreen::fakeMouseMove(SInt32 x, SInt32 y) void COSXScreen::fakeMouseRelativeMove(SInt32 dx, SInt32 dy) const { + // patch by Jake Petroules for issue 575 + // OS X does not appear to have a fake relative mouse move function. // simulate it by getting the current mouse position and adding to // that. this can yield the wrong answer but there's not much else // we can do. // get current position - Point oldPos; - GetGlobalMouse(&oldPos); + CGEventRef event = CGEventCreate(NULL); + CGPoint oldPos = CGEventGetLocation(event); + CFRelease(event); // synthesize event CGPoint pos; - m_xCursor = static_cast(oldPos.h); - m_yCursor = static_cast(oldPos.v); - pos.x = oldPos.h + dx; - pos.y = oldPos.v + dy; + m_xCursor = static_cast(oldPos.x); + m_yCursor = static_cast(oldPos.y); + pos.x = oldPos.x + dx; + pos.y = oldPos.y + dy; postMouseEvent(pos); // we now assume we don't know the current cursor position @@ -1052,7 +1057,7 @@ COSXScreen::handleSystemEvent(const CEvent& event, void*) // get scroll amount r = GetEventParameter(*carbonEvent, kSynergyMouseScrollAxisX, - typeLongInteger, + typeSInt32, NULL, sizeof(xScroll), NULL, @@ -1062,7 +1067,7 @@ COSXScreen::handleSystemEvent(const CEvent& event, void*) } r = GetEventParameter(*carbonEvent, kSynergyMouseScrollAxisY, - typeLongInteger, + typeSInt32, NULL, sizeof(yScroll), NULL, @@ -1090,7 +1095,11 @@ COSXScreen::handleSystemEvent(const CEvent& event, void*) break; case kEventClassWindow: - SendEventToWindow(*carbonEvent, m_userInputWindow); + // patch by Jake Petroules for issue 575 + // 2nd param was formerly GetWindowEventTarget(m_userInputWindow) which is 32-bit only, + // however as m_userInputWindow is never initialized to anything we can take advantage of + // the fact that GetWindowEventTarget(NULL) == NULL + SendEventToEventTarget(*carbonEvent, NULL); switch (GetEventKind(*carbonEvent)) { case kEventWindowActivated: LOG((CLOG_DEBUG1 "window activated")); @@ -1514,15 +1523,17 @@ COSXScreen::getScrollSpeedFactor() const void COSXScreen::enableDragTimer(bool enable) { - UInt32 modifiers; - MouseTrackingResult res; - if (enable && m_dragTimer == NULL) { m_dragTimer = m_events->newTimer(0.01, NULL); m_events->adoptHandler(CEvent::kTimer, m_dragTimer, new TMethodEventJob(this, &COSXScreen::handleDrag)); - TrackMouseLocationWithOptions(NULL, 0, 0, &m_dragLastPoint, &modifiers, &res); + // patch by Jake Petroules for issue 575 + CGEventRef event = CGEventCreate(NULL); + CGPoint mouse = CGEventGetLocation(event); + m_dragLastPoint.h = (short)mouse.x; + m_dragLastPoint.v = (short)mouse.y; + CFRelease(event); } else if (!enable && m_dragTimer != NULL) { m_events->removeHandler(CEvent::kTimer, m_dragTimer); @@ -1534,15 +1545,15 @@ COSXScreen::enableDragTimer(bool enable) void COSXScreen::handleDrag(const CEvent&, void*) { - Point p; - UInt32 modifiers; - MouseTrackingResult res; + // patch by Jake Petroules for issue 575 + CGEventRef event = CGEventCreate(NULL); + CGPoint p = CGEventGetLocation(event); + CFRelease(event); - TrackMouseLocationWithOptions(NULL, 0, 0, &p, &modifiers, &res); - - if (res != kMouseTrackingTimedOut && (p.h != m_dragLastPoint.h || p.v != m_dragLastPoint.v)) { - m_dragLastPoint = p; - onMouseMove((SInt32)p.h, (SInt32)p.v); + if ((short)p.x != m_dragLastPoint.h || (short)p.y != m_dragLastPoint.v) { + m_dragLastPoint.h = (short)p.x; + m_dragLastPoint.v = (short)p.y; + onMouseMove((SInt32)p.x, (SInt32)p.y); } } diff --git a/src/lib/platform/OSXScreenSaver.cpp b/src/lib/platform/OSXScreenSaver.cpp index 8ae9dc5c..01955713 100644 --- a/src/lib/platform/OSXScreenSaver.cpp +++ b/src/lib/platform/OSXScreenSaver.cpp @@ -140,9 +140,9 @@ COSXScreenSaver::launchTerminationCallback( EventRef theEvent, void* userData) { OSStatus result; - ProcessSerialNumber psn; - EventParamType actualType; - UInt32 actualSize; + ProcessSerialNumber psn; + EventParamType actualType; + ByteCount actualSize; result = GetEventParameter(theEvent, kEventParamProcessID, typeProcessSerialNumber, &actualType, diff --git a/src/lib/synergy/DaemonApp.cpp b/src/lib/synergy/DaemonApp.cpp index e8e8007b..aa03ee32 100644 --- a/src/lib/synergy/DaemonApp.cpp +++ b/src/lib/synergy/DaemonApp.cpp @@ -302,9 +302,9 @@ CDaemonApp::handleIpcMessage(const CEvent& e, void*) LOG((CLOG_DEBUG "new command, elevate=%d command=%s", cm->elevate(), command.c_str())); CString debugArg("--debug"); - UInt32 debugArgPos = static_cast(command.find(debugArg)); + size_t debugArgPos = command.find(debugArg); if (debugArgPos != CString::npos) { - UInt32 from = debugArgPos + static_cast(debugArg.size()) + 1; + UInt32 from = static_cast(debugArgPos) + static_cast(debugArg.size()) + 1; UInt32 nextSpace = static_cast(command.find(" ", from)); CString logLevel(command.substr(from, nextSpace - from));