Subject: [PATCH] OSXScreen: drop the last Objective-C dependency OSXScreen.mm was Objective-C++ solely because of a single message send, [NSEvent doubleClickInterval]. Everything else in its ~1800 lines is plain C++, and the .mm extension pulls the whole translation unit into the Objective-C++ front end -- which is GCC's weakest and most divergent one. Among other things it is why 'id' could not be used as a variable name there. Move that one call behind a C wrapper, following the same pattern as the existing OSXScreenSaverUtil/OSXPasteboardPeeker helpers, and rename the file to .cpp. libplatform now has no Objective-C++ translation units at all -- only C++ and (renameable) Objective-C ones. OSXPasteboardPeeker.h switches from #import to #include because it is now reached from a C++ translation unit, where GCC warns that #import is a deprecated extension. CoreFoundation.h is include-guarded, so this is a no-op otherwise. The CMake globs in src/lib/platform/CMakeLists.txt already cover OSX*.cpp and OSX*.mm, so no build system change is needed. diff --git a/src/lib/platform/OSXEventUtil.h b/src/lib/platform/OSXEventUtil.h new file mode 100644 index 00000000..9fc61f09 --- /dev/null +++ b/src/lib/platform/OSXEventUtil.h @@ -0,0 +1,32 @@ +/* + * barrier -- mouse and keyboard sharing utility + * Copyright (C) 2012-2016 Symless Ltd. + * + * This package is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * found in the file LICENSE that should have accompanied this file. + * + * This package is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include "common/common.h" + +#if defined(__cplusplus) +extern "C" { +#endif + +// The system-wide double click interval, in seconds. This lives behind a C +// wrapper so that OSXScreen can remain plain C++ rather than Objective-C++. +double getDoubleClickInterval(); + +#if defined(__cplusplus) +} +#endif diff --git a/src/lib/platform/OSXEventUtil.mm b/src/lib/platform/OSXEventUtil.mm new file mode 100644 index 00000000..247dc88c --- /dev/null +++ b/src/lib/platform/OSXEventUtil.mm @@ -0,0 +1,26 @@ +/* + * barrier -- mouse and keyboard sharing utility + * Copyright (C) 2012-2016 Symless Ltd. + * + * This package is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * found in the file LICENSE that should have accompanied this file. + * + * This package is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "platform/OSXEventUtil.h" + +#import + +double +getDoubleClickInterval() +{ + return [NSEvent doubleClickInterval]; +} diff --git a/src/lib/platform/OSXPasteboardPeeker.h b/src/lib/platform/OSXPasteboardPeeker.h index b69dba82..d3201274 100644 --- a/src/lib/platform/OSXPasteboardPeeker.h +++ b/src/lib/platform/OSXPasteboardPeeker.h @@ -19,7 +19,7 @@ #include "common/common.h" -#import +#include #if defined(__cplusplus) extern "C" { diff --git a/src/lib/platform/OSXScreen.mm b/src/lib/platform/OSXScreen.cpp similarity index 99% rename from src/lib/platform/OSXScreen.mm rename to src/lib/platform/OSXScreen.cpp index d41e321b..a52cb9ce 100644 --- a/src/lib/platform/OSXScreen.cpp +++ b/src/lib/platform/OSXScreen.cpp @@ -27,6 +27,7 @@ #include "platform/OSXDragSimulator.h" #include "platform/OSXMediaKeySupport.h" #include "platform/OSXPasteboardPeeker.h" +#include "platform/OSXEventUtil.h" #include "barrier/Clipboard.h" #include "barrier/KeyMap.h" #include "barrier/ClientApp.h" @@ -43,7 +44,6 @@ #include #include #include -#include // This isn't in any Apple SDK that I know of as of yet. enum { @@ -532,7 +532,7 @@ OSXScreen::fakeMouseButton(ButtonID id, bool press) // we define our own defaults. const double maxDiff = sqrt(2) + 0.0001; - double clickTime = [NSEvent doubleClickInterval]; + double clickTime = getDoubleClickInterval(); // As long as the click is within the time window and distance window // increase clickState (double click, triple click, etc)