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. Note that while the rest of the facilities in GTK-OSX can be used by advanced users with strong unix admin skills, the ige-mac-integration library requires good programming skills and some understanding of the GTK+ libraries.
The library is work in progress and is not API stable yet.
Documentation
The integration library has 3 components:
- Menu: Helps integrates the application's menus onto the Mac Menubar, move the About, Preference, and Quit menu items to the Application menu, and mutate some of the keyboard shortcuts from Control-Foo to Command-Foo.
- Bundle: Wraps the CoreFoundation? bundle functions in gtk-style functions so that paths to resources can be located when running from an application bundle.
- Dock: Provides a few Dock integration functions, for example bouncing the application's icon in the Dock when the application needs attention.
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.
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
Theme Engine
The gtk-quartz-engine provides a more mac-like appearance to your applications windows, but it still has some major holes in what it renders. Use it with care. Fortunately, it's very easy to turn on or off: You just change the Resources/etc/gtk-2.0/gtkrc file in your bundle.
Building
There's already a module for it, so just
$ jhbuild buildone gtk-quartz-engine
Installation
Add something like this to your bundle file (see Bundling?):
<binary> ${prefix}/lib/gtk-2.0/${pkg:gtk+-2.0:gtk_binary_version}/engines/*.so </binary> <data> ${prefix}/share/themes </data> <data dest='${bundle}/Contents/Resources/etc/gtk-2.0/gtkrc'> ${prefix}/share/themes/Quartz/gtk-2.0/gtkrc </data>
Everything will be copied into the right places.
If you're not going to bundle the application, you can just copy the gtkrc above to ~/.gtkrc.