From 4067bd81444736ddd7047210e2afdaaf9eaeaf40 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 9 Jan 2015 20:05:06 +0000 Subject: Fix OSX integration. git-svn-id: http://svn.drobilla.net/lad/trunk/patchage@5504 a436a847-0d15-0410-975c-d299462d15a1 --- src/Patchage.cpp | 10 +++++----- src/UIFile.hpp | 7 ++----- src/binary_location.h | 19 ++++++++++--------- src/main.cpp | 38 ++++++-------------------------------- 4 files changed, 23 insertions(+), 51 deletions(-) (limited to 'src') diff --git a/src/Patchage.cpp b/src/Patchage.cpp index 85a3bdf..d561feb 100644 --- a/src/Patchage.cpp +++ b/src/Patchage.cpp @@ -295,15 +295,15 @@ Patchage::Patchage(int argc, char** argv) #ifdef PATCHAGE_GTK_OSX // Set up Mac menu bar - GtkOSXApplication* osxapp; - gtk_osxapplication_ready(osxapp); - + GtkosxApplication* osxapp = (GtkosxApplication*)g_object_new( + GTKOSX_TYPE_APPLICATION, NULL); _menubar->hide(); - gtk_osxapplication_set_menu_bar(osxapp, GTK_MENU_SHELL(_menubar->gobj())); - gtk_osxapplication_insert_app_menu_item( + gtkosx_application_set_menu_bar(osxapp, GTK_MENU_SHELL(_menubar->gobj())); + gtkosx_application_insert_app_menu_item( osxapp, GTK_WIDGET(_menu_help_about->gobj()), 0); g_signal_connect(_menubar->gobj(), "can-activate-accel", G_CALLBACK(can_activate_cb), NULL); + gtkosx_application_ready(osxapp); #endif } diff --git a/src/UIFile.hpp b/src/UIFile.hpp index a9ff0d5..561cb0f 100644 --- a/src/UIFile.hpp +++ b/src/UIFile.hpp @@ -40,14 +40,11 @@ public: static Glib::RefPtr open(const std::string& base_name) { std::string ui_filename; - char* loc = NULL; #ifdef PATCHAGE_BINLOC - loc = binary_location(); - if (loc) { - std::string bundle = loc; + std::string bundle = binary_location(); + if (!bundle.empty()) { bundle = bundle.substr(0, bundle.find_last_of("/")); ui_filename = bundle + "/" + base_name + ".ui"; - free(loc); if (is_readable(ui_filename)) { std::cout << "Loading UI file " << ui_filename << std::endl; return Gtk::Builder::create_from_file(ui_filename); diff --git a/src/binary_location.h b/src/binary_location.h index 995f17f..91e8b29 100644 --- a/src/binary_location.h +++ b/src/binary_location.h @@ -23,20 +23,21 @@ #include #include -/** Return the absolute path of the binary. - * Returned value must be freed by caller. - */ -static char* +#include + +/** Return the absolute path of the binary. */ +static std::string binary_location() { - Dl_info dli; + Dl_info dli; + std::string loc; const int ret = dladdr((void*)&binary_location, &dli); if (ret) { char* const bin_loc = (char*)calloc(PATH_MAX, 1); - if (!realpath(dli.dli_fname, bin_loc)) { - return NULL; + if (realpath(dli.dli_fname, bin_loc)) { + loc = bin_loc; } - return bin_loc; + free(bin_loc); } - return NULL; + return loc; } diff --git a/src/main.cpp b/src/main.cpp index b9e0bb3..0e870b9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -28,42 +28,16 @@ #include "Patchage.hpp" -#ifdef __APPLE__ -void -set_bundle_environment() -{ - char* binloc_c = binary_location(); - std::string binloc(binloc_c); - free(binloc_c); - - const std::string bundle_path = binloc.substr(0, binloc.find_last_of('/')); - - const std::string lib_path(bundle_path + "/lib"); - setenv("GTK_PATH", lib_path.c_str(), 1); - setenv("DYLD_LIBRARY_PATH", lib_path.c_str(), 1); - - chdir(bundle_path.c_str()); - const std::string pangorc_path(bundle_path + "/Resources/pangorc"); - setenv("PANGO_RC_FILE", pangorc_path.c_str(), 1); - - const std::string fonts_conf_path(bundle_path + "/Resources/fonts.conf"); - setenv("FONTCONFIG_FILE", fonts_conf_path.c_str(), 1); - - const char* path_c = getenv("PATH"); - std::string path = "/opt/local/bin"; - if (path_c) - path += std::string(":") + path_c; - setenv("PATH", path.c_str(), 1); - - gtk_rc_parse((bundle_path + "/Resources/gtkrc").c_str()); -} -#endif - int main(int argc, char** argv) { #ifdef __APPLE__ - set_bundle_environment(); + const std::string binary = binary_location(); + const std::string bundle = binary.substr(0, binary.find_last_of('/')); + const std::string gtkrc_path = bundle + "/Resources/gtkrc"; + if (Glib::file_test(gtkrc_path, Glib::FILE_TEST_EXISTS)) { + gtk_rc_parse(gtkrc_path.c_str()); + } #endif try { -- cgit v1.2.1