]> git.tdb.fi Git - ext/subsurface.git/commitdiff
Make icon file name OS helper function
authorDirk Hohndel <dirk@hohndel.org>
Wed, 28 Dec 2011 23:57:36 +0000 (15:57 -0800)
committerDirk Hohndel <dirk@hohndel.org>
Wed, 28 Dec 2011 23:57:36 +0000 (15:57 -0800)
This way we can load the correct icon on the Mac without ugly hacks in the
OS independent code.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
display-gtk.h
gtk-gui.c
linux.c
macos.c
windows.c

index b20495731e50036b2b4b774d953675e8950af9e1..23fea912a9098af2fea81995601382cc023f4b75 100644 (file)
@@ -33,6 +33,7 @@ extern const void *subsurface_get_conf(char *name, pref_type_t type);
 extern void subsurface_close_conf(void);
 
 extern const char *subsurface_USB_name(void);
+extern const char *subsurface_icon_name(void);
 
 extern visible_cols_t visible_cols;
 
index 41e862eb9ca553a200cdc4c092c788b2280ba930..acaa9c4f6a2510d3a57d265550fcb77b6a296d37 100644 (file)
--- a/gtk-gui.c
+++ b/gtk-gui.c
@@ -523,11 +523,7 @@ static void about_dialog(GtkWidget *w, gpointer data)
        GdkPixbuf *logo = NULL;
 
        if (need_icon) {
-#if defined __linux__ || defined __APPLE__
-               GtkWidget *image = gtk_image_new_from_file("subsurface.svg");
-#elif defined WIN32
-               GtkWidget *image = gtk_image_new_from_file("subsurface.ico");
-#endif
+               GtkWidget *image = gtk_image_new_from_file(subsurface_icon_name());
 
                if (image) {
                        logo = gtk_image_get_pixbuf(GTK_IMAGE(image));
@@ -703,11 +699,7 @@ void init_ui(int *argcp, char ***argvp)
                }
        }
        if (need_icon)
-#if defined __linux__ || defined __APPLE__
-               gtk_window_set_icon_from_file(GTK_WINDOW(win), "subsurface.svg", NULL);
-#elif defined WIN32
-               gtk_window_set_icon_from_file(GTK_WINDOW(win), "subsurface.ico", NULL);
-#endif
+               gtk_window_set_icon_from_file(GTK_WINDOW(win), subsurface_icon_name(), NULL);
        g_signal_connect(G_OBJECT(win), "delete-event", G_CALLBACK(on_delete), NULL);
        g_signal_connect(G_OBJECT(win), "destroy", G_CALLBACK(on_destroy), NULL);
        main_window = win;
diff --git a/linux.c b/linux.c
index ac5cf55f938b778afef9bd99ddf70b5f5ffd5551..d2a92596ebbcde791bc8008206ebbef8c2b35ceb 100644 (file)
--- a/linux.c
+++ b/linux.c
@@ -51,3 +51,8 @@ const char *subsurface_USB_name()
 {
        return "/dev/ttyUSB0";
 }
+
+const char *subsurface_icon_name()
+{
+       return "subsurface.svg";
+}
diff --git a/macos.c b/macos.c
index 25f946c81db9a52abad2547286e3f12c3b75e5ad..4c856ce03717b652d9a7ae54cfe17809d07c05f5 100644 (file)
--- a/macos.c
+++ b/macos.c
@@ -2,6 +2,7 @@
 /* implements Mac OS X specific functions */
 #include "display-gtk.h"
 #include <CoreFoundation/CoreFoundation.h>
+#include <mach-o/dyld.h>
 
 static CFURLRef fileURL;
 static CFPropertyListRef propertyList;
@@ -94,3 +95,23 @@ const char *subsurface_USB_name()
 {
        return "/dev/tty.SLAB_USBtoUART";
 }
+
+#define REL_ICON_PATH "Resources/Subsurface.icns"
+const char *subsurface_icon_name()
+{
+       static char path[1024];
+       char *ptr1, *ptr2;
+       uint32_t size = sizeof(path); /* need extra space to copy icon path */
+       if (_NSGetExecutablePath(path, &size) == 0) {
+               ptr1 = strcasestr(path,"MacOS/subsurface");
+               ptr2 = strcasestr(path,"Contents");
+               if (ptr1 && ptr2) {
+                       /* we are running as installed app from a bundle */
+                       if (ptr1 - path < size - strlen(REL_ICON_PATH)) {
+                               strcpy(ptr1,REL_ICON_PATH);
+                               return path;
+                       }
+               }
+       }
+       return "packaging/macosx/Subsurface.icns";
+}
index 8a81737b039082ea4b551534b6072e740abb4b8d..beb775aa627a71c3e6acf54a15cc650f217f6f4d 100644 (file)
--- a/windows.c
+++ b/windows.c
@@ -83,3 +83,8 @@ const char *subsurface_USB_name()
 {
        return "COM3";
 }
+
+const char *subsurface_icon_name()
+{
+       return "subsurface.ico";
+}