Add gtk mac integration
authorAndy Spencer <andy753421@gmail.com>
Mon, 2 Jan 2012 00:07:41 +0000 (00:07 +0000)
committerAndy Spencer <andy753421@gmail.com>
Mon, 2 Jan 2012 00:07:41 +0000 (00:07 +0000)
- Move the menu bar to the top of the screen

configure.ac
src/Makefile.am
src/main.c

index b2bddd8..dab9baa 100644 (file)
@@ -32,6 +32,11 @@ AM_CONDITIONAL([SYS_WIN], test "$SYS" = "WIN")
 AM_CONDITIONAL([SYS_MAC], test "$SYS" = "MAC")
 AM_CONDITIONAL([SYS_X11], test "$SYS" = "X11")
 
+# Check for Mac OX
+if test "$SYS" = "MAC"; then
+       PKG_CHECK_MODULES(MAC, gtk-mac-integration)
+fi
+
 # Check for relative build
 AC_ARG_ENABLE(relative, [AS_HELP_STRING([--enable-relative],
        [enable runtime search paths @<:@default=no@:>@])],
index fb3d4f6..ec7fb21 100644 (file)
@@ -34,6 +34,11 @@ aweather_dbg_CPPFLAGS = $(aweather_CPPFLAGS)
 aweather_dbg_LDADD    = $(aweather_LDADD)
 endif
 
+if SYS_MAC
+aweather_CPPFLAGS    += $(MAC_CFLAGS)
+aweather_LDADD       += $(MAC_LIBS)
+endif
+
 .rc.o: ../data/icons/48x48/aweather.ico
        $(RC) -o $@ $<
 
index 55d0ad9..a8bc426 100644 (file)
 #include <gtk/gtk.h>
 #include <glib/gstdio.h>
 
+#ifdef MAC_INTEGRATION
+#include <gtkosxapplication.h>
+#endif
+
 #include <grits.h>
 
 #include "aweather-gui.h"
@@ -87,6 +91,19 @@ static void set_toggle_action(AWeatherGui *gui, const char *action, gboolean ena
        gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(object), enabled);
 }
 
+static void setup_mac(AWeatherGui *gui)
+{
+#ifdef MAC_INTEGRATION
+       GtkWidget *menu = aweather_gui_get_widget(gui, "main_menu");
+       GtkOSXApplication *app = g_object_new(GTK_TYPE_OSX_APPLICATION, NULL);
+       gtk_widget_hide(menu);
+       gtk_osxapplication_set_menu_bar(app, GTK_MENU_SHELL(menu));
+       gtk_osxapplication_set_use_quartz_accelerators(app, TRUE);
+       gtk_osxapplication_ready(app);
+       //gtk_osxapplication_sync_menubar(app)
+#endif
+}
+
 /********
  * Main *
  ********/
@@ -173,6 +190,7 @@ int main(int argc, char *argv[])
        /* Done with init, show gui */
        gtk_widget_show_all(GTK_WIDGET(gui));
        set_toggle_action(gui, "fullscreen", fullscreen); // Resest widget hiding
+       setup_mac(gui); // done after show_all
        gtk_main();
        gdk_threads_leave();
        gdk_display_close(gdk_display_get_default());