New Project Home

GTK+OSX is now consolidated at http://gtk-osx.sourceforge.net/, where you'll find up-to-date information about building, bundling, and integrating GTK+ applications on Mac OSX. There is a forum, a mailing list, and a tracker there. The following is deprecated! The current information is at http://sourceforge.net/apps/trac/gtk-osx/wiki/Integrate

Integration

Even though regular GTK+ applications work on the Mac, it is nice to be able to integrate with the native desktop and make it feel more like a Mac application. The integration library provided here will help you with that.

Status

The library is work in progress and is not API stable yet.

Get it

The code is available on github: http://github.com/jralls/ige-mac-integration/tree/master, but it's installed as part of gtk-osx-build, and it doesn't make a lot of sense to use it outside of that environment.

Documentation

Here is a simple example for setting up the menu bar:

 gtk_widget_hide (menubar);
 ige_mac_menu_set_menu_bar (GTK_MENU_SHELL (menubar));

This connects the application menubar to the mac menu bar (the one across the top of the screen). So long as you don't hide top-level menus in the menubar, changes to your menus in GTK will automatically be reflected in your Mac menus.

If you do hide and show top level menu items, then you need to call

  ige_mac_menu_sync(GTK_MENU_SHELL (menubar));

every time you hide or unhide a top-level menu item.

To make the menu structure feel more native, you can rearrange menu items a bit:

 ige_mac_menu_set_quit_menu_item (GTK_MENU_ITEM (quit_item));

 group = ige_mac_menu_add_app_menu_group ();
 ige_mac_menu_add_app_menu_item  (group,
                                   GTK_MENU_ITEM (quit_item),
                                   NULL);
 
ige_mac_menu_add_app_menu_item  (group,
                                   GTK_MENU_ITEM (about_item),
                                   NULL);

 group = ige_mac_menu_add_app_menu_group ();
 ige_mac_menu_add_app_menu_item  (group,
                                   GTK_MENU_ITEM (preferences_item),
                                   NULL);

This moves the Quit, About, and Preferences items to the application menu, where most Mac applications put those.

If for some reason you're writing code that's going to run in a non-quartz environment, you may find it useful to wrap the above code with

 #ifdef MAC_INTEGRATION
 ...
 #endif //MAC_INTEGRATION

and to include something like

### --------------------------------------------------------------------------
### Check to see if GDK uses the quartz backend and if we can use 
### MacOSX integration
_gdk_tgt=`$PKG_CONFIG --variable=target gdk-2.0`
AM_CONDITIONAL([GDK_TARGET_QUARTZ], [test x$_gdk_tgt = xquartz])
if test "x$_gdk_tgt" = xquartz; then 
   PKG_CHECK_MODULES(IGE_MAC, ige-mac-integration)
   AC_SUBST(IGE_MAC_LIBS)
   AC_SUBST(IGE_MAC_CFLAGS)
fi

in your configure.ac and mention ${IGE_MAC_CFLAGS} and ${IGE_MAC_LIBS} in the appropriate locations of the appropriate Makefile.am

For more examples, see the code in the source, test-integration.c. In addition the the menu bar integration, the API currently contains some hooks for the dock, and application bundles.

GStreamer

There is also a video sink that works with GTK+ on OS X available on github: http://github.com/rhult/ige-mac-video-sink/tree/master

GTK+/OSX/Integration (last edited 2009-07-03 21:03:03 by jralls)