OSX support for 'OpenFile' system message (aka open vimix when selecting

session file in finder).
This commit is contained in:
brunoherbelin
2020-11-02 20:55:38 +01:00
parent 88d4e3d9d5
commit bab0e9b710
6 changed files with 97 additions and 24 deletions

View File

@@ -13,10 +13,10 @@ if(UNIX)
# the RPATH to be used when installing
set(CMAKE_SKIP_RPATH TRUE)
set(OpenGL_DIR /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/)
set(CMAKE_OSX_ARCHITECTURES x86_64)
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.13")
# set(CMAKE_OSX_DEPLOYMENT_TARGET "10.13" CACHE STRING "Minimum OS X version to target for deployment")
else()
add_definitions(-DLINUX)
@@ -283,6 +283,7 @@ set(VMIX_SRCS
ActionManager.cpp
)
set(VMIX_RSC_FILES
./rsc/shaders/simple.fs
./rsc/shaders/simple.vs
@@ -370,6 +371,7 @@ IF(APPLE)
# create the application
add_executable(${VMIX_BINARY} MACOSX_BUNDLE
${VMIX_SRCS}
./osx/CustomDelegate.m
${IMGUITEXTEDIT_SRC}
${MACOSX_BUNDLE_ICON_FILE}
)
@@ -378,6 +380,11 @@ IF(APPLE)
set(MACOSX_BUNDLE_PLIST_FILE ${CMAKE_SOURCE_DIR}/osx/Info.plist)
set_target_properties(${VMIX_BINARY} PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${MACOSX_BUNDLE_PLIST_FILE})
set(PLATFORM_LIBS
"-framework CoreFoundation"
"-framework Appkit"
)
ELSE(APPLE)
add_executable(${VMIX_BINARY}
@@ -385,6 +392,9 @@ ELSE(APPLE)
${IMGUITEXTEDIT_SRC}
)
set(PLATFORM_LIBS ""
)
ENDIF(APPLE)
@@ -421,6 +431,7 @@ target_link_libraries(${VMIX_BINARY} LINK_PRIVATE
IMGUI
OSCPACK
vmix::rc
${PLATFORM_LIBS}
)
macro_display_feature_log()
@@ -434,7 +445,7 @@ SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/README.md")
SET(CPACK_PACKAGE_CONTACT "bruno.herbelin@gmail.com")
SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/COPYING.txt")
SET(CPACK_PACKAGE_VERSION_MAJOR "0")
SET(CPACK_PACKAGE_VERSION_MINOR "3")
SET(CPACK_PACKAGE_VERSION_MINOR "4")
SET(CPACK_PACKAGE_VENDOR "Bruno Herbelin")
SET(CPACK_SOURCE_IGNORE_FILES
"/\\\\.git/"
@@ -471,7 +482,7 @@ IF(APPLE)
### TODO configure auto to find installation dir of gst
# intall the gst-plugin-scanner program (used by plugins at load time)
install(FILES "/usr/local/Cellar/gstreamer/1.18.0/libexec/gstreamer-1.0/gst-plugin-scanner"
install(FILES "/usr/local/Cellar/gstreamer/1.18.1/libexec/gstreamer-1.0/gst-plugin-scanner"
DESTINATION "${plugin_dest_dir}"
PERMISSIONS OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
COMPONENT Runtime
@@ -482,11 +493,11 @@ IF(APPLE)
# Install the gst-plugins (all those installed with brew )
install(DIRECTORY "${PKG_GSTREAMER_PLUGIN_DIR}" DESTINATION "${plugin_dest_dir}" COMPONENT Runtime)
install(DIRECTORY "/usr/local/Cellar/gst-plugins-base/1.18.0/lib/gstreamer-1.0" DESTINATION "${plugin_dest_dir}" COMPONENT Runtime)
install(DIRECTORY "/usr/local/Cellar/gst-plugins-good/1.18.0/lib/gstreamer-1.0" DESTINATION "${plugin_dest_dir}" COMPONENT Runtime)
# install(DIRECTORY "/usr/local/Cellar/gst-plugins-bad/1.18.0/lib/gstreamer-1.0" DESTINATION "${plugin_dest_dir}" COMPONENT Runtime)
install(DIRECTORY "/usr/local/Cellar/gst-plugins-ugly/1.18.0/lib/gstreamer-1.0" DESTINATION "${plugin_dest_dir}" COMPONENT Runtime)
install(DIRECTORY "/usr/local/Cellar/gst-libav/1.18.0/lib/gstreamer-1.0" DESTINATION "${plugin_dest_dir}" COMPONENT Runtime)
install(DIRECTORY "/usr/local/Cellar/gst-plugins-base/1.18.1/lib/gstreamer-1.0" DESTINATION "${plugin_dest_dir}" COMPONENT Runtime)
install(DIRECTORY "/usr/local/Cellar/gst-plugins-good/1.18.1/lib/gstreamer-1.0" DESTINATION "${plugin_dest_dir}" COMPONENT Runtime)
# install(DIRECTORY "/usr/local/Cellar/gst-plugins-bad/1.18.1/lib/gstreamer-1.0" DESTINATION "${plugin_dest_dir}" COMPONENT Runtime)
install(DIRECTORY "/usr/local/Cellar/gst-plugins-ugly/1.18.1/lib/gstreamer-1.0" DESTINATION "${plugin_dest_dir}" COMPONENT Runtime)
install(DIRECTORY "/usr/local/Cellar/gst-libav/1.18.1/lib/gstreamer-1.0" DESTINATION "${plugin_dest_dir}" COMPONENT Runtime)
# install locally recompiled gst-plugins-bad
install(FILES "/Users/herbelin/Development/gst/gst-plugins-bad-1.18.0/build/ext/libde265/libgstde265.dylib" DESTINATION "${plugin_dest_dir}/gstreamer-1.0" COMPONENT Runtime)

View File

@@ -31,13 +31,20 @@
#include "Connection.h"
#if defined(APPLE)
extern "C"{
void forward_load_message(const char * filename){
Settings::application.argument_file = std::string(filename);
}
}
#endif
void drawScene()
{
Mixer::manager().draw();
}
int main(int argc, char *argv[])
{
// one extra argument is given

View File

@@ -11,4 +11,4 @@ void * get_current_nsopengl_context();
};
#endif // COCOA_TOOLKIT_H
#endif // COCOA_TOOLKIT_H

10
osx/CustomDelegate.h Normal file
View File

@@ -0,0 +1,10 @@
#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface GLFWCustomDelegate : NSObject
+ (void)load; // load is called before even main() is run (as part of objc class registration)
@end
NS_ASSUME_NONNULL_END

49
osx/CustomDelegate.m Normal file
View File

@@ -0,0 +1,49 @@
#import "CustomDelegate.h"
#import <objc/runtime.h>
// part of your application
extern void forward_load_message(const char * filename);
@implementation GLFWCustomDelegate
+ (void)load{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Class class = objc_getClass("GLFWApplicationDelegate");
[GLFWCustomDelegate swizzle:class src:@selector(application:openFile:) tgt:@selector(swz_application:openFile:)];
[GLFWCustomDelegate swizzle:class src:@selector(application:openFiles:) tgt:@selector(swz_application:openFiles:)];
});
}
+ (void) swizzle:(Class) original_c src:(SEL)original_s tgt:(SEL)target_s{
Class target_c = [GLFWCustomDelegate class];
Method originalMethod = class_getInstanceMethod(original_c, original_s);
Method swizzledMethod = class_getInstanceMethod(target_c, target_s);
BOOL didAddMethod =
class_addMethod(original_c,
original_s,
method_getImplementation(swizzledMethod),
method_getTypeEncoding(swizzledMethod));
if (didAddMethod) {
class_replaceMethod(original_c,
target_s,
method_getImplementation(originalMethod),
method_getTypeEncoding(originalMethod));
} else {
method_exchangeImplementations(originalMethod, swizzledMethod);
}
}
- (BOOL)swz_application:(NSApplication *)sender openFile:(NSString *)filename{
forward_load_message(filename.UTF8String);
return YES;
}
- (void)swz_application:(NSApplication *)sender openFiles:(NSArray<NSString *> *)filenames{
forward_load_message(filenames.firstObject.UTF8String);
}
@end

View File

@@ -9,22 +9,18 @@
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>mix</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>vimix.icns</string>
<key>CFBundleTypeName</key>
<string>GLMixer Session</string>
<key>CFBundleTypeOSTypes</key>
<array>
<string>MIX </string>
</array>
<string>vimix session</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSIsAppleDefaultForType</key>
<true/>
<key>LSIsAppleDefaultForType</key>
<true/>
<key>LSHandlerRank</key>
<string>Owner</string>
<key>LSItemContentTypes</key>
<array>
<string>com.bhbn.mix</string>
</array>
</dict>
</array>
<key>CFBundleExecutable</key>